Advertisement
jintack

temp vtimer

Apr 4th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 24.57 KB | None | 0 0
  1. diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
  2. index 19c5004..b390a85 100644
  3. --- a/arch/arm/kvm/arm.c
  4. +++ b/arch/arm/kvm/arm.c
  5. @@ -27,6 +27,7 @@
  6.  #include <linux/mman.h>
  7.  #include <linux/sched.h>
  8.  #include <linux/kvm.h>
  9. +#include <linux/interrupt.h>
  10.  #include <trace/events/kvm.h>
  11.  
  12.  #define CREATE_TRACE_POINTS
  13. @@ -561,6 +562,10 @@ static int kvm_vcpu_initialized(struct kvm_vcpu *vcpu)
  14.  extern void inject_irq_l1(struct kvm_vcpu *vcpu);
  15.  extern bool L2_running(struct kvm_vcpu *vcpu);
  16.  extern void switch_vgic_vtimer(struct kvm_vcpu *vcpu, bool to_L2);
  17. +extern int irq_set_irqchip_state(unsigned int irq, enum irqchip_irq_state which,
  18. +                         bool val);
  19. +extern int irq_get_irqchip_state(unsigned int irq, enum irqchip_irq_state which,
  20. +                         bool *state);
  21.  #endif
  22.  /**
  23.   * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest code
  24. @@ -645,12 +650,32 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
  25.                 }
  26.  
  27.  #ifdef CONFIG_SUPPORT_EL1_HYP
  28. -               if (L2_running(vcpu))
  29. +               if (L2_running(vcpu)) {
  30.                         switch_vgic_vtimer(vcpu, true);
  31. +               }
  32. +
  33. +               {
  34. +                       bool state;
  35. +                       trace_printk("EXIT REASON is %d\n", run->exit_reason);
  36. +                       irq_get_irqchip_state(vcpu->arch.timer_cpu.map->irq,
  37. +                                       IRQCHIP_STATE_ACTIVE,
  38. +                                       &state);
  39. +                       bool state;
  40. +                       trace_printk("EXIT REASON is %d\n", run->exit_reason);
  41. +                       irq_get_irqchip_state(vcpu->arch.timer_cpu.map->irq,
  42. +                                       IRQCHIP_STATE_ACTIVE,
  43. +                                       &state);
  44. +                       trace_printk("exit to L0 irqchip state: %s\n", state?"active":"NOT active");
  45. +                       irq_get_irqchip_state(vcpu->arch.timer_cpu.map->irq,
  46. +                                       IRQCHIP_STATE_PENDING,
  47. +                                       &state);
  48. +                       trace_printk("exit to L0 irqchip state: %s\n", state?"pending":"NOT pending");
  49. +/*
  50. +                       irq_set_irqchip_state(vcpu->arch.timer_cpu.map->irq,
  51. +                                       IRQCHIP_STATE_ACTIVE,
  52. +                                       true);
  53. +*/
  54. +               }
  55.  #endif
  56.  
  57.                 kvm_arm_setup_debug(vcpu);
  58.  
  59. +               trace_printk("-------------------------ENTER-------------------\n");
  60.                 /**************************************************************
  61.                  * Enter the guest
  62.                  */
  63. @@ -665,6 +690,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
  64.                 /*
  65.                  * Back from guest
  66.                  *************************************************************/
  67. +               trace_printk("-------------------------EXIT-------------------\n");
  68.  
  69.                 kvm_arm_clear_debug(vcpu);
  70.  
  71. @@ -692,8 +718,14 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
  72.                 trace_kvm_exit(ret, kvm_vcpu_trap_get_class(vcpu), *vcpu_pc(vcpu));
  73.  
  74.  #ifdef CONFIG_SUPPORT_EL1_HYP
  75. -               if (L2_running(vcpu))
  76. +               if (L2_running(vcpu)) {
  77. +                       /* TODO: vcpu->kvm->arch.timer.cntvoff should be L2's */
  78. +                       /*
  79. +                       if (kvm_timer_should_fire(vcpu))
  80. +                               L2_pending_timer_irq = true;
  81. +                       */
  82.                         switch_vgic_vtimer(vcpu, false);
  83. +               }
  84.  #endif
  85.  
  86.                 /*
  87. diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c
  88. index fa7f6de..f169ca0 100644
  89. --- a/arch/arm64/kvm/handle_exit.c
  90. +++ b/arch/arm64/kvm/handle_exit.c
  91. @@ -283,6 +283,12 @@ static void restore_from_shadow_vgic(struct kvm_vcpu *vcpu)
  92.                 trace_printk("before restore, lr%d:  %x\n", i, cpu_if->vgic_lr[i]);
  93.                 cpu_if->vgic_lr[i] = vcpu_shadow_vgreg(vcpu, V_GICH_LR0 +i);
  94.                 trace_printk("restore %x to lr%d\n", cpu_if->vgic_lr[i], i);
  95. +               if ((0x3ff & cpu_if->vgic_lr[i]) == 27) {
  96. +                       cpu_if->vgic_lr[i] &= ~0xffc00;
  97. +                       cpu_if->vgic_lr[i] |=  0x07800;
  98. +                       trace_printk("change lr%d to %x\n", i, cpu_if->vgic_lr[i]);
  99. +               }
  100. +
  101.         }
  102.  }
  103.  
  104. @@ -313,11 +319,19 @@ static void save_to_shadow_vgic(struct kvm_vcpu *vcpu)
  105.         for (i = 0; i < nr_lr; i++) {
  106.                 vcpu_shadow_vgreg(vcpu, V_GICH_LR0 +i) = cpu_if->vgic_lr[i];
  107.                 trace_printk("save %x to shadow lr%d\n", cpu_if->vgic_lr[i], i);
  108. +               if ((0x3ff & cpu_if->vgic_lr[i]) == 27) {
  109. +                       cpu_if->vgic_lr[i] &=  ~0x10000000;
  110. +                       cpu_if->vgic_lr[i] &= ~0xffc00;
  111. +                       cpu_if->vgic_lr[i] |=  0x07800;
  112. +                       trace_printk("change lr%d to %x\n", i, cpu_if->vgic_lr[i]);
  113. +               }
  114. +
  115.         }
  116.  
  117.         memcpy (cpu_if, l1_vgic, sizeof(struct vgic_v2_cpu_if));
  118.  }
  119.  
  120. +u64 tmp_cntoff;
  121.  static void restore_from_shadow_vtimer(struct kvm_vcpu *vcpu) {
  122.  
  123.         struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;
  124. @@ -328,6 +342,7 @@ static void restore_from_shadow_vtimer(struct kvm_vcpu *vcpu) {
  125.  
  126.         timer->cntv_cval = vcpu_shadow_vtreg(vcpu, V_CNTV_CVAL_EL0);
  127.         timer->cntv_ctl = vcpu_shadow_vtreg(vcpu, V_CNTV_CTL_EL0);
  128. +       vcpu->kvm->arch.timer.cntvoff += vcpu_shadow_reg(vcpu, CNTVOFF_EL2);
  129.         trace_printk("restore %llx to cval\n", (u64)(timer->cntv_cval));
  130.         trace_printk("restore %llx to ctl\n", (u64)(timer->cntv_ctl));
  131.  }
  132. @@ -344,11 +359,14 @@ static void save_to_shadow_vtimer(struct kvm_vcpu *vcpu)
  133.  
  134.         timer->cntv_cval = l1_timer->cntv_cval;
  135.         timer->cntv_ctl = l1_timer->cntv_ctl;
  136. +       vcpu->kvm->arch.timer.cntvoff -= vcpu_shadow_reg(vcpu, CNTVOFF_EL2);
  137.  }
  138.  
  139.  /* switch vgic and vtimer registers */
  140.  void switch_vgic_vtimer(struct kvm_vcpu *vcpu, bool to_L2)
  141.  {
  142. +       trace_printk("---- start vgic vtimer switch to %s\n", to_L2?"L2": "L1");
  143. +       trace_printk("PC: %016lx, LR: %016lx\n", *vcpu_pc(vcpu), vcpu_get_reg(vcpu,30));
  144.         if (to_L2) {
  145.                 restore_from_shadow_vgic(vcpu);
  146.                 restore_from_shadow_vtimer(vcpu);
  147. @@ -356,6 +374,7 @@ void switch_vgic_vtimer(struct kvm_vcpu *vcpu, bool to_L2)
  148.                 save_to_shadow_vgic(vcpu);
  149.                 save_to_shadow_vtimer(vcpu);
  150.         }
  151. +       trace_printk("---- end vgic vtimer switch to %s\n", to_L2?"L2": "L1");
  152.  }
  153.  
  154.  static void switch_ctxt(struct kvm_vcpu *vcpu, bool to_low)
  155. @@ -538,11 +557,13 @@ static int emulate_dbg(struct kvm_vcpu *vcpu, u16 imm) {
  156.                 trace_printk("INTERRUPT L1 lowvisor gets interrupt\n");
  157.         }
  158.  
  159. +       if (imm == 0x7b00) {
  160. +               trace_printk("L2 ACK\n");
  161. +               BUG();
  162. +       }
  163.         if (imm == 0x7739) {
  164.                 trace_printk("INTERRUPT L2 guest gets interrupt, but it shouldn't\n");
  165.                 trace_printk("cpsr is %016lx. I bit is 0x80\n", *vcpu_cpsr(vcpu));
  166. -               BUG();
  167. -               return 0;
  168.         }
  169.  
  170.         return 1;
  171. @@ -607,9 +628,14 @@ static int emulate_vgic(struct kvm_vcpu *vcpu, u16 imm) {
  172.  
  173.         print_vgic(vcpu, imm, vregp, gpregp, gpreg_num);
  174.  
  175. -       if (is_write)
  176. +       if (is_write) {
  177.                 *vregp = *gpregp;
  178. -       else
  179. +/*
  180. +               if (is_vgic && (vreg_num == V_GICH_VMCR)) {
  181. +                       *vregp |= 0xf0000001;
  182. +               }
  183. +*/
  184. +       } else
  185.                 *gpregp = *vregp;
  186.         return 1;
  187.  }
  188. @@ -805,6 +831,7 @@ int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run,
  189.  
  190.         switch (exception_index) {
  191.         case ARM_EXCEPTION_IRQ:
  192. +               trace_printk("Exit because of IRQ\n");
  193.                 return 1;
  194.         case ARM_EXCEPTION_TRAP:
  195.                 /*
  196. diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
  197. index abf2ffa..0ea1fce 100644
  198. --- a/drivers/irqchip/irq-gic.c
  199. +++ b/drivers/irqchip/irq-gic.c
  200. @@ -176,8 +176,29 @@ static void gic_poke_irq(struct irq_data *d, u32 offset)
  201.  
  202. :
  203. @@ -538,11 +557,13 @@ static int emulate_dbg(struct kvm_vcpu *vcpu, u16 imm) {
  204.                 trace_printk("INTERRUPT L1 lowvisor gets interrupt\n");
  205.         }
  206.  
  207. +       if (imm == 0x7b00) {
  208. +               trace_printk("L2 ACK\n");
  209. +               BUG();
  210. +       }
  211.         if (imm == 0x7739) {
  212.                 trace_printk("INTERRUPT L2 guest gets interrupt, but it shouldn't\n");
  213.                 trace_printk("cpsr is %016lx. I bit is 0x80\n", *vcpu_cpsr(vcpu));
  214. -               BUG();
  215. -               return 0;
  216.         }
  217.  
  218.         return 1;
  219. @@ -607,9 +628,14 @@ static int emulate_vgic(struct kvm_vcpu *vcpu, u16 imm) {
  220.  
  221.         print_vgic(vcpu, imm, vregp, gpregp, gpreg_num);
  222.  
  223. -       if (is_write)
  224. +       if (is_write) {
  225.                 *vregp = *gpregp;
  226. -       else
  227. +/*
  228. +               if (is_vgic && (vreg_num == V_GICH_VMCR)) {
  229. +                       *vregp |= 0xf0000001;
  230. +               }
  231. +*/
  232. +       } else
  233.                 *gpregp = *vregp;
  234.         return 1;
  235.  }
  236. @@ -805,6 +831,7 @@ int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run,
  237.  
  238.         switch (exception_index) {
  239.         case ARM_EXCEPTION_IRQ:
  240. +               trace_printk("Exit because of IRQ\n");
  241.                 return 1;
  242.         case ARM_EXCEPTION_TRAP:
  243.                 /*
  244. diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
  245. index abf2ffa..0ea1fce 100644
  246. --- a/drivers/irqchip/irq-gic.c
  247. +++ b/drivers/irqchip/irq-gic.c
  248. @@ -176,8 +176,29 @@ static void gic_poke_irq(struct irq_data *d, u32 offset)
  249.  
  250.  static int gic_peek_irq(struct irq_data *d, u32 offset)
  251.  {
  252. +       int ret;
  253. +       int i = 0;
  254. +       int max = 1020%32 +1;
  255. +       char* reg;
  256. +       u32 ispend;
  257.         u32 mask = 1 << (gic_irq(d) % 32);
  258. -       return !!(readl_relaxed(gic_dist_base(d) + offset + (gic_irq(d) / 32) * 4) & mask);
  259. +       ret = !!(readl_relaxed(gic_dist_base(d) + offset + (gic_irq(d) / 32) * 4) & mask);
  260. +
  261. +       if (offset == GIC_DIST_PENDING_SET)
  262. +               reg = "GICD_ISPENDR";
  263. +       else if (offset == GIC_DIST_ACTIVE_SET)
  264. +               reg = "GICD_ISACTIVER";
  265. +       else
  266. +               reg ="GICD_ELSE";
  267. +
  268. +       trace_printk("%s\n", __func__);
  269. +       for (i = 0 ; i < max; i ++) {
  270. +               ispend = readl_relaxed(gic_dist_base(d) + offset + i*4);
  271. +               if (ispend)
  272. +                       trace_printk("%s %s%d %x\n", __func__, reg, i, ispend);
  273. +       }
  274. +
  275. +       return ret;
  276.  }
  277.  
  278.  static void gic_mask_irq(struct irq_data *d)
  279. @@ -335,7 +356,7 @@ static void __exception_irq_entry gic_handle_irq(struct pt_regs *regs)
  280.         do {
  281.                 irqstat = readl_relaxed(cpu_base + GIC_CPU_INTACK);
  282.                 irqnr = irqstat & GICC_IAR_INT_ID_MASK;
  283. -
  284. +
  285.                 if (likely(irqnr > 15 && irqnr < 1021)) {
  286.                         if (static_key_true(&supports_deactivate))
  287.                                 writel_relaxed(irqstat, cpu_base + GIC_CPU_EOI);
  288. diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
  289. index ad16809..ba9f689 100644
  290. --- a/include/linux/interrupt.h
  291. +++ b/include/linux/interrupt.h
  292. @@ -371,6 +371,7 @@ enum irqchip_irq_state {
  293.         IRQCHIP_STATE_ACTIVE,           /* Is interrupt in progress? */
  294.         IRQCHIP_STATE_MASKED,           /* Is interrupt masked? */
  295.         IRQCHIP_STATE_LINE_LEVEL,       /* Is IRQ line high? */
  296. +       IRQCHIP_STATE_PENDING_ALL,              /* Is any interrupt pending? */
  297.  };
  298.  
  299.  extern int irq_get_irqchip_state(unsigned int irq, enum irqchip_irq_state which,
  300.         if (to_L2) {
  301.                 restore_from_shadow_vgic(vcpu);
  302.                 restore_from_shadow_vtimer(vcpu);
  303. @@ -356,6 +374,7 @@ void switch_vgic_vtimer(struct kvm_vcpu *vcpu, bool to_L2)
  304.                 save_to_shadow_vgic(vcpu);
  305.                 save_to_shadow_vtimer(vcpu);
  306.         }
  307. +       trace_printk("---- end vgic vtimer switch to %s\n", to_L2?"L2": "L1");
  308.  }
  309.  
  310.  static void switch_ctxt(struct kvm_vcpu *vcpu, bool to_low)
  311. @@ -538,11 +557,13 @@ static int emulate_dbg(struct kvm_vcpu *vcpu, u16 imm) {
  312.                 trace_printk("INTERRUPT L1 lowvisor gets interrupt\n");
  313.         }
  314.  
  315. +       if (imm == 0x7b00) {
  316. +               trace_printk("L2 ACK\n");
  317. +               BUG();
  318. +       }
  319.         if (imm == 0x7739) {
  320.                 trace_printk("INTERRUPT L2 guest gets interrupt, but it shouldn't\n");
  321.                 trace_printk("cpsr is %016lx. I bit is 0x80\n", *vcpu_cpsr(vcpu));
  322. -               BUG();
  323. -               return 0;
  324.         }
  325.  
  326.         return 1;
  327. @@ -607,9 +628,14 @@ static int emulate_vgic(struct kvm_vcpu *vcpu, u16 imm) {
  328.  
  329.         print_vgic(vcpu, imm, vregp, gpregp, gpreg_num);
  330.  
  331. -       if (is_write)
  332. +       if (is_write) {
  333.                 *vregp = *gpregp;
  334. -       else
  335. +/*
  336. +               if (is_vgic && (vreg_num == V_GICH_VMCR)) {
  337. +                       *vregp |= 0xf0000001;
  338. +               }
  339. +*/
  340. +       } else
  341.                 *gpregp = *vregp;
  342.         return 1;
  343.  }
  344. @@ -805,6 +831,7 @@ int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run,
  345.  
  346. +*/
  347. +       } else
  348.                 *gpregp = *vregp;
  349.         return 1;
  350.  }
  351. @@ -805,6 +831,7 @@ int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run,
  352.  
  353.         switch (exception_index) {
  354.         case ARM_EXCEPTION_IRQ:
  355. +               trace_printk("Exit because of IRQ\n");
  356.                 return 1;
  357.         case ARM_EXCEPTION_TRAP:
  358.                 /*
  359. diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
  360. index abf2ffa..0ea1fce 100644
  361. --- a/drivers/irqchip/irq-gic.c
  362. +++ b/drivers/irqchip/irq-gic.c
  363. @@ -176,8 +176,29 @@ static void gic_poke_irq(struct irq_data *d, u32 offset)
  364.  
  365.  static int gic_peek_irq(struct irq_data *d, u32 offset)
  366.  {
  367. +       int ret;
  368. +       int i = 0;
  369. +       int max = 1020%32 +1;
  370. +       char* reg;
  371. +       u32 ispend;
  372.         u32 mask = 1 << (gic_irq(d) % 32);
  373. -       return !!(readl_relaxed(gic_dist_base(d) + offset + (gic_irq(d) / 32) * 4) & mask);
  374. +       ret = !!(readl_relaxed(gic_dist_base(d) + offset + (gic_irq(d) / 32) * 4) & mask);
  375. +
  376. +       if (offset == GIC_DIST_PENDING_SET)
  377. +               reg = "GICD_ISPENDR";
  378. +       else if (offset == GIC_DIST_ACTIVE_SET)
  379. +               reg = "GICD_ISACTIVER";
  380. +       else
  381. +               reg ="GICD_ELSE";
  382. +
  383. +       trace_printk("%s\n", __func__);
  384. +       for (i = 0 ; i < max; i ++) {
  385. +               ispend = readl_relaxed(gic_dist_base(d) + offset + i*4);
  386. +               if (ispend)
  387. +                       trace_printk("%s %s%d %x\n", __func__, reg, i, ispend);
  388. +       }
  389. +
  390. +       return ret;
  391.  }
  392.  
  393.  static void gic_mask_irq(struct irq_data *d)
  394. @@ -335,7 +356,7 @@ static void __exception_irq_entry gic_handle_irq(struct pt_regs *regs)
  395.         do {
  396.                 irqstat = readl_relaxed(cpu_base + GIC_CPU_INTACK);
  397.                 irqnr = irqstat & GICC_IAR_INT_ID_MASK;
  398. -
  399. +
  400.                 if (likely(irqnr > 15 && irqnr < 1021)) {
  401.                         if (static_key_true(&supports_deactivate))
  402.                                 writel_relaxed(irqstat, cpu_base + GIC_CPU_EOI);
  403. diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
  404. index ad16809..ba9f689 100644
  405. --- a/include/linux/interrupt.h
  406. +++ b/include/linux/interrupt.h
  407. @@ -371,6 +371,7 @@ enum irqchip_irq_state {
  408.         IRQCHIP_STATE_ACTIVE,           /* Is interrupt in progress? */
  409.         IRQCHIP_STATE_MASKED,           /* Is interrupt masked? */
  410.         IRQCHIP_STATE_LINE_LEVEL,       /* Is IRQ line high? */
  411. +       IRQCHIP_STATE_PENDING_ALL,              /* Is any interrupt pending? */
  412.  };
  413.  
  414.  extern int irq_get_irqchip_state(unsigned int irq, enum irqchip_irq_state which,
  415. diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c
  416. index ead0144..3060cba 100644
  417. --- a/virt/kvm/arm/arch_timer.c
  418. +++ b/virt/kvm/arm/arch_timer.c
  419. @@ -216,6 +216,7 @@ void kvm_timer_flush_hwstate(struct kvm_vcpu *vcpu)
  420.  {
  421.         struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;
  422.         bool phys_active;
  423. +       bool cur_phys_active;
  424.         int ret;
  425.  #ifdef CONFIG_EMUL_GUEST_GIC_TIMER
  426.         return;
  427. @@ -248,6 +249,16 @@ void kvm_timer_flush_hwstate(struct kvm_vcpu *vcpu)
  428.         else
  429.                 phys_active = false;
  430.  
  431. +       irq_get_irqchip_state(timer->map->irq,
  432. +                                   IRQCHIP_STATE_PENDING,
  433. +                                   &cur_phys_active);
  434. +       irq_get_irqchip_state(timer->map->irq,
  435. +                                   IRQCHIP_STATE_ACTIVE,
  436. +                                   &cur_phys_active);
  437. +       trace_printk("L0 -> L1 irq: %d irqchip state %s to %s\n",
  438. +               timer->map->irq,
  439. +               cur_phys_active?"active":"NOT active",
  440. +               phys_active?"active":"NOT active");
  441.         ret = irq_set_irqchip_state(timer->map->irq,
  442.                                     IRQCHIP_STATE_ACTIVE,
  443.                                     phys_active);
  444. @@ -498,4 +509,5 @@ void kvm_timer_enable(struct kvm *kvm)
  445.  void kvm_timer_init(struct kvm *kvm)
  446.  {
  447.         kvm->arch.timer.cntvoff = kvm_phys_timer_read();
  448. +        printk("%s L1 cntvoff_el2 is %llx\n", __func__, kvm->arch.timer.cntvoff);
  449.  }
  450. diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
  451. index 9daaf42..e148ff4 100644
  452. --- a/virt/kvm/arm/vgic.c
  453. +++ b/virt/kvm/arm/vgic.c
  454. @@ -1366,6 +1366,7 @@ static bool vgic_process_maintenance(struct kvm_vcpu *vcpu)
  455.         kvm_debug("STATUS = %08x\n", status);
  456.  
  457. [build-server ~/host]$git diff
  458. diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
  459. index 19c5004..b390a85 100644
  460. --- a/arch/arm/kvm/arm.c
  461. +++ b/arch/arm/kvm/arm.c
  462. @@ -27,6 +27,7 @@
  463.  #include <linux/mman.h>
  464.  #include <linux/sched.h>
  465.  #include <linux/kvm.h>
  466. +#include <linux/interrupt.h>
  467.  #include <trace/events/kvm.h>
  468.  
  469.  #define CREATE_TRACE_POINTS
  470. @@ -561,6 +562,10 @@ static int kvm_vcpu_initialized(struct kvm_vcpu *vcpu)
  471.  extern void inject_irq_l1(struct kvm_vcpu *vcpu);
  472.  extern bool L2_running(struct kvm_vcpu *vcpu);
  473.  extern void switch_vgic_vtimer(struct kvm_vcpu *vcpu, bool to_L2);
  474. +extern int irq_set_irqchip_state(unsigned int irq, enum irqchip_irq_state which,
  475. +                         bool val);
  476. +extern int irq_get_irqchip_state(unsigned int irq, enum irqchip_irq_state which,
  477. +                         bool *state);
  478.  #endif
  479.  /**
  480.   * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest code
  481. @@ -645,12 +650,32 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
  482.                 }
  483.  
  484.  #ifdef CONFIG_SUPPORT_EL1_HYP
  485. -               if (L2_running(vcpu))
  486. +               if (L2_running(vcpu)) {
  487.                         switch_vgic_vtimer(vcpu, true);
  488. +               }
  489. +
  490. +               {
  491. +                       bool state;
  492. +                       trace_printk("EXIT REASON is %d\n", run->exit_reason);
  493. +                       irq_get_irqchip_state(vcpu->arch.timer_cpu.map->irq,
  494. +                                       IRQCHIP_STATE_ACTIVE,
  495. +                                       &state);
  496. +                       trace_printk("exit to L0 irqchip state: %s\n", state?"active":"NOT active");
  497. +                       irq_get_irqchip_state(vcpu->arch.timer_cpu.map->irq,
  498. +                                       IRQCHIP_STATE_PENDING,
  499. +                                       &state);
  500. +                       trace_printk("exit to L0 irqchip state: %s\n", state?"pending":"NOT pending")
  501. +/*
  502. +                       irq_set_irqchip_state(vcpu->arch.timer_cpu.map->irq,
  503. +                                       IRQCHIP_STATE_ACTIVE,
  504. +                                       true);
  505. ...skipping...
  506.  #endif
  507.  
  508.                 kvm_arm_setup_debug(vcpu);
  509.  
  510. +               trace_printk("-------------------------ENTER-------------------\n");
  511.                 /**************************************************************
  512.                  * Enter the guest
  513.                  */
  514. @@ -665,6 +690,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
  515.                 /*
  516.                  * Back from guest
  517.                  *************************************************************/
  518. +               trace_printk("-------------------------EXIT-------------------\n");
  519.  
  520.                 kvm_arm_clear_debug(vcpu);
  521.  
  522. @@ -692,8 +718,14 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
  523.                 trace_kvm_exit(ret, kvm_vcpu_trap_get_class(vcpu), *vcpu_pc(vcpu));
  524.  
  525.  #ifdef CONFIG_SUPPORT_EL1_HYP
  526. -               if (L2_running(vcpu))
  527. +               if (L2_running(vcpu)) {
  528. +                       /* TODO: vcpu->kvm->arch.timer.cntvoff should be L2's */
  529. +                       /*
  530. +                       if (kvm_timer_should_fire(vcpu))
  531. +                               L2_pending_timer_irq = true;
  532. +                       */
  533.                         switch_vgic_vtimer(vcpu, false);
  534. +               }
  535.  #endif
  536.  
  537.                 /*
  538. diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c
  539. index fa7f6de..f169ca0 100644
  540. --- a/arch/arm64/kvm/handle_exit.c
  541. +++ b/arch/arm64/kvm/handle_exit.c
  542. @@ -283,6 +283,12 @@ static void restore_from_shadow_vgic(struct kvm_vcpu *vcpu)
  543.                 trace_printk("before restore, lr%d:  %x\n", i, cpu_if->vgic_lr[i]);
  544.                 cpu_if->vgic_lr[i] = vcpu_shadow_vgreg(vcpu, V_GICH_LR0 +i);
  545.                 trace_printk("restore %x to lr%d\n", cpu_if->vgic_lr[i], i);
  546. +               if ((0x3ff & cpu_if->vgic_lr[i]) == 27) {
  547. +                       cpu_if->vgic_lr[i] &= ~0xffc00;
  548. +                       cpu_if->vgic_lr[i] |=  0x07800;
  549. +                       trace_printk("change lr%d to %x\n", i, cpu_if->vgic_lr[i]);
  550. +               }
  551. +
  552.         }
  553.  }
  554.  
  555. @@ -313,11 +319,19 @@ static void save_to_shadow_vgic(struct kvm_vcpu *vcpu)
  556.         for (i = 0; i < nr_lr; i++) {
  557.                 vcpu_shadow_vgreg(vcpu, V_GICH_LR0 +i) = cpu_if->vgic_lr[i];
  558.                 trace_printk("save %x to shadow lr%d\n", cpu_if->vgic_lr[i], i);
  559. +               if ((0x3ff & cpu_if->vgic_lr[i]) == 27) {
  560. +                       cpu_if->vgic_lr[i] &=  ~0x10000000;
  561. +                       cpu_if->vgic_lr[i] &= ~0xffc00;
  562. +                       cpu_if->vgic_lr[i] |=  0x07800;
  563. +                       trace_printk("change lr%d to %x\n", i, cpu_if->vgic_lr[i]);
  564. +               }
  565. +
  566.         }
  567.  
  568.         memcpy (cpu_if, l1_vgic, sizeof(struct vgic_v2_cpu_if));
  569.  }
  570.  
  571. +u64 tmp_cntoff;
  572.  static void restore_from_shadow_vtimer(struct kvm_vcpu *vcpu) {
  573.  
  574.         struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;
  575. @@ -328,6 +342,7 @@ static void restore_from_shadow_vtimer(struct kvm_vcpu *vcpu) {
  576.  
  577.         timer->cntv_cval = vcpu_shadow_vtreg(vcpu, V_CNTV_CVAL_EL0);
  578.         timer->cntv_ctl = vcpu_shadow_vtreg(vcpu, V_CNTV_CTL_EL0);
  579. +       vcpu->kvm->arch.timer.cntvoff += vcpu_shadow_reg(vcpu, CNTVOFF_EL2);
  580.         trace_printk("restore %llx to cval\n", (u64)(timer->cntv_cval));
  581.         trace_printk("restore %llx to ctl\n", (u64)(timer->cntv_ctl));
  582.  }
  583. @@ -344,11 +359,14 @@ static void save_to_shadow_vtimer(struct kvm_vcpu *vcpu)
  584.  
  585.         timer->cntv_cval = l1_timer->cntv_cval;
  586.         timer->cntv_ctl = l1_timer->cntv_ctl;
  587. +       vcpu->kvm->arch.timer.cntvoff -= vcpu_shadow_reg(vcpu, CNTVOFF_EL2);
  588.  }
  589.  
  590.  /* switch vgic and vtimer registers */
  591.  void switch_vgic_vtimer(struct kvm_vcpu *vcpu, bool to_L2)
  592.  {
  593. +       trace_printk("---- start vgic vtimer switch to %s\n", to_L2?"L2": "L1");
  594. +       trace_printk("PC: %016lx, LR: %016lx\n", *vcpu_pc(vcpu), vcpu_get_reg(vcpu,30));
  595.         if (to_L2) {
  596.                 restore_from_shadow_vgic(vcpu);
  597.                 restore_from_shadow_vtimer(vcpu);
  598. @@ -356,6 +374,7 @@ void switch_vgic_vtimer(struct kvm_vcpu *vcpu, bool to_L2)
  599.                 save_to_shadow_vgic(vcpu);
  600.                 save_to_shadow_vtimer(vcpu);
  601.         }
  602. +       trace_printk("---- end vgic vtimer switch to %s\n", to_L2?"L2": "L1");
  603.  }
  604.  
  605.  static void switch_ctxt(struct kvm_vcpu *vcpu, bool to_low)
  606. @@ -538,11 +557,13 @@ static int emulate_dbg(struct kvm_vcpu *vcpu, u16 imm) {
  607.                 trace_printk("INTERRUPT L1 lowvisor gets interrupt\n");
  608.         }
  609.  
  610. +       if (imm == 0x7b00) {
  611. +               trace_printk("L2 ACK\n");
  612. +               BUG();
  613. +       }
  614.         if (imm == 0x7739) {
  615.                 trace_printk("INTERRUPT L2 guest gets interrupt, but it shouldn't\n");
  616.                 trace_printk("cpsr is %016lx. I bit is 0x80\n", *vcpu_cpsr(vcpu));
  617. -               BUG();
  618. -               return 0;
  619.         }
  620.  
  621.         return 1;
  622. @@ -607,9 +628,14 @@ static int emulate_vgic(struct kvm_vcpu *vcpu, u16 imm) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement