Fix book3s-pr KVM with preemption
Subsystems (3)
cover Fix book3s-pr KVM with preemption
So far we got away with not implementing preemption properly. However, recently users emerged who wanted to run PREEMPT_xxx kernels, running into issues with KVM on there.
This patch set fixes all preempt issues I've found so far with Book3S PR KVM.
Alexander Graf (4):
KVM: PPC: Book3s: PR: Disable preemption in vcpu_run
KVM: PPC: Book3s: PR: No irq_disable in vcpu_run
KVM: PPC: Use get/set for to_svcpu to help preemption
KVM: PPC: align vcpu_kick with x86
arch/powerpc/include/asm/kvm_book3s.h | 76 +++++++++++++++++++++++------- arch/powerpc/include/asm/kvm_book3s_32.h | 6 ++- arch/powerpc/include/asm/kvm_book3s_64.h | 8 +++- arch/powerpc/kvm/book3s_32_mmu_host.c | 21 ++++++-- arch/powerpc/kvm/book3s_64_mmu_host.c | 66 +++++++++++++++++--------- arch/powerpc/kvm/book3s_emulate.c | 8 ++- arch/powerpc/kvm/book3s_pr.c | 71 +++++++++++++++++++--------- arch/powerpc/kvm/powerpc.c | 7 ++- arch/powerpc/kvm/trace.h | 5 ++- 9 files changed, 194 insertions(+), 74 deletions(-)
PATCH 1/4 KVM: PPC: Book3s: PR: Disable preemption in vcpu_run
When entering the guest, we want to make sure we're not getting preempted away, so let's disable preemption on entry, but enable it again while handling guest exits.
--- arch/powerpc/kvm/book3s_pr.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
arch/powerpc/kvm/book3s_pr.c +7 -0
@@ -519,6 +519,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, run->ready_for_interrupt_injection =1 ;trace_kvm_book3s_exit (exit_nr, vcpu); +preempt_enable ();kvm_resched (vcpu);switch (exit_nr) {case BOOK3S_INTERRUPT_INST_STORAGE :
@@ -763,6 +764,8 @@ program_interrupt: run->exit_reason =KVM_EXIT_INTR ; r = -EINTR ; }else { +preempt_disable (); +/* In case an interrupt came in that was triggered * from userspace (like DEC), we need to check what * to inject now! */
@@ -925,6 +928,8 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)#endif ulong ext_msr; +preempt_disable (); +/* Check if we can run the vcpu at all */ if (!vcpu->arch.sane) { kvm_run->exit_reason =KVM_EXIT_INTERNAL_ERROR ;
@@ -1006,6 +1011,8 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) current->thread.used_vsr = used_vsr;#endif +preempt_enable (); +return ret; }
Signature · 1 line
1.6.0.2
PATCH 2/4 KVM: PPC: Book3s: PR: No irq_disable in vcpu_run
In reply to Alexander GrafSomewhere during merges we ended up from
local_irq_enable() foo(); local_irq_disable()
to always keeping irqs enabled during that part. However, we now have the following code:
foo(); local_irq_disable()
which disables interrupts without the surrounding code enabling them again! So let's remove that disable and be happy.
--- arch/powerpc/kvm/book3s_pr.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
arch/powerpc/kvm/book3s_pr.c +0 -2
@@ -983,8 +983,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)kvm_guest_exit (); -local_irq_disable (); - current->thread.regs->msr = ext_msr;/* Make sure we save the guest FPU/Altivec/VSX state */
Signature · 1 line
1.6.0.2
PATCH 4/4 KVM: PPC: align vcpu_kick with x86
In reply to Alexander GrafOur vcpu kick implementation differs a bit from x86 which resulted in us not disabling preemption during the kick. Get it a bit closer to what x86 does.
--- arch/powerpc/kvm/powerpc.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
arch/powerpc/kvm/powerpc.c +6 -1
@@ -557,12 +557,17 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)void kvm_vcpu_kick (struct kvm_vcpu *vcpu) { +int me; +int cpu = vcpu->cpu; + + me =get_cpu ();if (waitqueue_active (&vcpu->wq)) {wake_up_interruptible (vcpu->arch.wqp); vcpu->stat.halt_wakeup++; - }else if (vcpu->cpu !=-1 ) { + }else if (cpu != me && cpu !=-1 ) {smp_send_reschedule (vcpu->cpu); } +put_cpu (); }int kvm_vcpu_ioctl_interrupt (struct kvm_vcpu *vcpu,struct kvm_interrupt *irq)
Signature · 1 line
1.6.0.2
PATCH 3/4 KVM: PPC: Use get/set for to_svcpu to help preemption
In reply to Alexander GrafWhen running the 64-bit Book3s PR code without CONFIG_PREEMPT_NONE, we were doing a few things wrong, most notably access to PACA fields without making sure that the pointers stay stable accross the access (preempt_disable()).
This patch moves to_svcpu towards a get/put model which allows us to disable preemption while accessing the shadow vcpu fields in the PACA. That way we can run preemptible and everyone's happy!
--- arch/powerpc/include/asm/kvm_book3s.h | 76 +++++++++++++++++++++++------- arch/powerpc/include/asm/kvm_book3s_32.h | 6 ++- arch/powerpc/include/asm/kvm_book3s_64.h | 8 +++- arch/powerpc/kvm/book3s_32_mmu_host.c | 21 ++++++-- arch/powerpc/kvm/book3s_64_mmu_host.c | 66 +++++++++++++++++--------- arch/powerpc/kvm/book3s_emulate.c | 8 ++- arch/powerpc/kvm/book3s_pr.c | 62 ++++++++++++++++-------- arch/powerpc/kvm/trace.h | 5 ++- 8 files changed, 181 insertions(+), 71 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +59 -17
@@ -185,7 +185,9 @@ static inline void kvmppc_update_int_pending(struct kvm_vcpu *vcpu,static inline void kvmppc_set_gpr (struct kvm_vcpu *vcpu,int num,ulong val) {if ( num <14 ) { -to_svcpu (vcpu)->gpr[num] = val; +struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); + svcpu->gpr[num] = val; +svcpu_put (svcpu);to_book3s (vcpu)->shadow_vcpu->gpr[num] = val; }else vcpu->arch.gpr[num] = val;
@@ -193,80 +195,120 @@ static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val)static inline ulong kvmppc_get_gpr (struct kvm_vcpu *vcpu,int num) { -if ( num <14 ) -return to_svcpu (vcpu)->gpr[num]; -else +if ( num <14 ) { +struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); +ulong r = svcpu->gpr[num]; +svcpu_put (svcpu); +return r; + }else return vcpu->arch.gpr[num]; }static inline void kvmppc_set_cr (struct kvm_vcpu *vcpu,u32 val) { -to_svcpu (vcpu)->cr = val; +struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); + svcpu->cr = val; +svcpu_put (svcpu);to_book3s (vcpu)->shadow_vcpu->cr = val; }static inline u32 kvmppc_get_cr (struct kvm_vcpu *vcpu) { -return to_svcpu (vcpu)->cr; +struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); +u32 r; + r = svcpu->cr; +svcpu_put (svcpu); +return r; }static inline void kvmppc_set_xer (struct kvm_vcpu *vcpu,u32 val) { -to_svcpu (vcpu)->xer = val; +struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); + svcpu->xer = val;to_book3s (vcpu)->shadow_vcpu->xer = val; +svcpu_put (svcpu); }static inline u32 kvmppc_get_xer (struct kvm_vcpu *vcpu) { -return to_svcpu (vcpu)->xer; +struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); +u32 r; + r = svcpu->xer; +svcpu_put (svcpu); +return r; }static inline void kvmppc_set_ctr (struct kvm_vcpu *vcpu,ulong val) { -to_svcpu (vcpu)->ctr = val; +struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); + svcpu->ctr = val; +svcpu_put (svcpu); }static inline ulong kvmppc_get_ctr (struct kvm_vcpu *vcpu) { -return to_svcpu (vcpu)->ctr; +struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); +ulong r; + r = svcpu->ctr; +svcpu_put (svcpu); +return r; }static inline void kvmppc_set_lr (struct kvm_vcpu *vcpu,ulong val) { -to_svcpu (vcpu)->lr = val; +struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); + svcpu->lr = val; +svcpu_put (svcpu); }static inline ulong kvmppc_get_lr (struct kvm_vcpu *vcpu) { -return to_svcpu (vcpu)->lr; +struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); +ulong r; + r = svcpu->lr; +svcpu_put (svcpu); +return r; }static inline void kvmppc_set_pc (struct kvm_vcpu *vcpu,ulong val) { -to_svcpu (vcpu)->pc = val; +struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); + svcpu->pc = val; +svcpu_put (svcpu); }static inline ulong kvmppc_get_pc (struct kvm_vcpu *vcpu) { -return to_svcpu (vcpu)->pc; +struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); +ulong r; + r = svcpu->pc; +svcpu_put (svcpu); +return r; }static inline u32 kvmppc_get_last_inst (struct kvm_vcpu *vcpu) {ulong pc =kvmppc_get_pc (vcpu); -struct kvmppc_book3s_shadow_vcpu *svcpu =to_svcpu (vcpu); +struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); +u32 r;/* Load the instruction manually if it failed to do so in the * exit path */ if (svcpu->last_inst ==KVM_INST_FETCH_FAILED )kvmppc_ld (vcpu, &pc,sizeof (u32), &svcpu->last_inst, false); -return svcpu->last_inst; + r = svcpu->last_inst; +svcpu_put (svcpu); +return r; }static inline ulong kvmppc_get_fault_dar (struct kvm_vcpu *vcpu) { -return to_svcpu (vcpu)->fault_dar; +struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); +ulong r; + r = svcpu->fault_dar; +svcpu_put (svcpu); +return r; }static inline bool kvmppc_critical_section (struct kvm_vcpu *vcpu)
arch/powerpc/include/asm/kvm_book3s_32.h +5 -1
@@ -20,11 +20,15 @@#ifndef __ASM_KVM_BOOK3S_32_H__#define __ASM_KVM_BOOK3S_32_H__ -static inline struct kvmppc_book3s_shadow_vcpu *to_svcpu (struct kvm_vcpu *vcpu) +static inline struct kvmppc_book3s_shadow_vcpu *svcpu_get (struct kvm_vcpu *vcpu) {return to_book3s (vcpu)->shadow_vcpu; } +static inline void svcpu_put (struct kvmppc_book3s_shadow_vcpu *svcpu) +{ +} +#define PTE_SIZE 12#define VSID_ALL 0#define SR_INVALID 0x00000001/* VSID 1 should always be unused */
arch/powerpc/include/asm/kvm_book3s_64.h +7 -1
@@ -21,10 +21,16 @@#define __ASM_KVM_BOOK3S_64_H__#ifdef CONFIG_KVM_BOOK3S_PR -static inline struct kvmppc_book3s_shadow_vcpu *to_svcpu (struct kvm_vcpu *vcpu) +static inline struct kvmppc_book3s_shadow_vcpu *svcpu_get (struct kvm_vcpu *vcpu) { +preempt_disable ();return &get_paca ()->shadow_vcpu; } + +static inline void svcpu_put (struct kvmppc_book3s_shadow_vcpu *svcpu) +{ +preempt_enable (); +}#endif #define SPAPR_TCE_SHIFT 12
arch/powerpc/kvm/book3s_32_mmu_host.c +15 -6
@@ -151,13 +151,15 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *orig_pte)bool primary = false;bool evict = false;struct hpte_cache *pte; +int r =0 ;/* Get host physical address for gpa */ hpaddr =kvmppc_gfn_to_pfn (vcpu, orig_pte->raddr >>PAGE_SHIFT );if (is_error_pfn (hpaddr)) {printk (KERN_INFO "Couldn't get guest page for gfn %lx!\n" , orig_pte->eaddr); -return -EINVAL ; + r = -EINVAL ; + goto out; } hpaddr <<=PAGE_SHIFT ;
@@ -249,7 +251,8 @@ next_pteg:kvmppc_mmu_hpte_cache_map (vcpu, pte); -return 0 ; +out: +return r; }static struct kvmppc_sid_map *create_sid_map (struct kvm_vcpu *vcpu,u64 gvsid)
@@ -297,12 +300,14 @@ int kvmppc_mmu_map_segment(struct kvm_vcpu *vcpu, ulong eaddr)u64 gvsid;u32 sr;struct kvmppc_sid_map *map; -struct kvmppc_book3s_shadow_vcpu *svcpu =to_svcpu (vcpu); +struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); +int r =0 ;if (vcpu->arch.mmu.esid_to_vsid (vcpu, esid, &gvsid)) {/* Invalidate an entry */ svcpu->sr[esid] =SR_INVALID ; -return -ENOENT ; + r = -ENOENT ; + goto out; } map =find_sid_vsid (vcpu, gvsid);
@@ -315,17 +320,21 @@ int kvmppc_mmu_map_segment(struct kvm_vcpu *vcpu, ulong eaddr)dprintk_sr ("MMU: mtsr %d, 0x%x\n" , esid, sr); -return 0 ; +out: +svcpu_put (svcpu); +return r; }void kvmppc_mmu_flush_segments (struct kvm_vcpu *vcpu) {int i; -struct kvmppc_book3s_shadow_vcpu *svcpu =to_svcpu (vcpu); +struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu);dprintk_sr ("MMU: flushing all segments (%d)\n" ,ARRAY_SIZE (svcpu->sr));for (i =0 ; i <ARRAY_SIZE (svcpu->sr); i++) svcpu->sr[i] =SR_INVALID ; + +svcpu_put (svcpu); }void kvmppc_mmu_destroy (struct kvm_vcpu *vcpu)
arch/powerpc/kvm/book3s_64_mmu_host.c +43 -23
150 lines not on this page · raw message
arch/powerpc/kvm/book3s_emulate.c +6 -2
@@ -230,9 +230,12 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, r =kvmppc_st (vcpu, &addr,32 , zeros, true);if ((r == -ENOENT ) || (r == -EPERM )) { +struct kvmppc_book3s_shadow_vcpu *svcpu; + + svcpu =svcpu_get (vcpu); *advance =0 ; vcpu->arch.shared->dar = vaddr; -to_svcpu (vcpu)->fault_dar = vaddr; + svcpu->fault_dar = vaddr; dsisr =DSISR_ISSTORE ;if (r == -ENOENT )
@@ -241,7 +244,8 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, dsisr |=DSISR_PROTFAULT ; vcpu->arch.shared->dsisr = dsisr; -to_svcpu (vcpu)->fault_dsisr = dsisr; + svcpu->fault_dsisr = dsisr; +svcpu_put (svcpu);kvmppc_book3s_queue_irqprio (vcpu,BOOK3S_INTERRUPT_DATA_STORAGE );
arch/powerpc/kvm/book3s_pr.c +42 -20
159 lines not on this page · raw message
arch/powerpc/kvm/trace.h +4 -1
@@ -118,11 +118,14 @@ TRACE_EVENT(kvm_book3s_exit, ),TP_fast_assign ( + struct kvmppc_book3s_shadow_vcpu *svcpu; __entry->exit_nr = exit_nr; __entry->pc =kvmppc_get_pc (vcpu); __entry->dar =kvmppc_get_fault_dar (vcpu); __entry->msr = vcpu->arch.shared->msr; - __entry->srr1 =to_svcpu (vcpu)->shadow_srr1; + svcpu =svcpu_get (vcpu); + __entry->srr1 = svcpu->shadow_srr1; +svcpu_put (svcpu); ), TP_printk("exit=0x%x | pc=0x%lx | msr=0x%lx | dar=0x%lx | srr1=0x%lx",
Signature · 1 line
1.6.0.2
Re: [PATCH 4/4] KVM: PPC: align vcpu_kick with x86
In reply to Alexander GrafQuoted 2 lines · Alexander Graf
Our vcpu kick implementation differs a bit from x86 which resulted in us not disabling preemption during the kick. Get it a bit closer to what x86 does.
Disabling preemption only matters due to the other bit of functionality you brought over -- avoiding kicking the current CPU.
Probably doesn't even matter all that much with it, since avoiding that is just an optimization, and any race that causes us to fail to reschedule a vcpu of a different thread means that thread just rescheduled anyway. Not something I feel any great need to rely on, though. :-)
Quoted 16 lines
Signed-off-by Alexander Graf <[email protected]>--- arch/powerpc/kvm/powerpc.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)arch/powerpc/kvm/powerpc.c +3
-0@@ -557,12 +557,17 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)void kvm_vcpu_kick (struct kvm_vcpu *vcpu) { +int me; +int cpu = vcpu->cpu; +
arch/powerpc/kvm/powerpc.c int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) · line 571
Quoted 10 lines
arch/powerpc/kvm/powerpc.c +3
-1+ me =get_cpu ();if (waitqueue_active (&vcpu->wq)) {wake_up_interruptible (vcpu->arch.wqp); vcpu->stat.halt_wakeup++; - }else if (vcpu->cpu !=-1 ) { + }else if (cpu != me && cpu !=-1 ) {smp_send_reschedule (vcpu->cpu); } +put_cpu (); }
Whitespace.
-Scott
Re: [PATCH 1/4] KVM: PPC: Book3s: PR: Disable preemption in vcpu_run
In reply to Alexander GrafQuoted 23 lines · Alexander Graf
When entering the guest, we want to make sure we're not getting preempted away, so let's disable preemption on entry, but enable it again while handling guest exits.
Reported-by Jörg Sommer <[email protected]>Signed-off-by Alexander Graf <[email protected]>--- arch/powerpc/kvm/book3s_pr.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)arch/powerpc/kvm/book3s_pr.c +1
-0@@ -519,6 +519,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, run->ready_for_interrupt_injection =1 ;trace_kvm_book3s_exit (exit_nr, vcpu); +preempt_enable ();kvm_resched (vcpu);switch (exit_nr) {case BOOK3S_INTERRUPT_INST_STORAGE :
arch/powerpc/kvm/book3s_pr.c program_interrupt: · line 771
Quoted 8 lines
arch/powerpc/kvm/book3s_pr.c +2
-0@@ -763,6 +764,8 @@ program_interrupt: run->exit_reason =KVM_EXIT_INTR ; r = -EINTR ; }else { +preempt_disable (); +/* In case an interrupt came in that was triggered * from userspace (like DEC), we need to check what * to inject now! */
Shouldn't you really have interrupts disabled here, as booke does?
Otherwise an interrupt (including an IPI kick) could send you a signal or guest exception after you check.
Likewise for other guest entry points.
-Scott
Re: [PATCH 4/4] KVM: PPC: align vcpu_kick with x86
In reply to Scott WoodQuoted 6 lines · Scott Wood
Quoted 2 lines · Alexander Graf
Our vcpu kick implementation differs a bit from x86 which resulted in us not disabling preemption during the kick. Get it a bit closer to what x86 does.
Disabling preemption only matters due to the other bit of functionality you brought over -- avoiding kicking the current CPU.
Nope, I had BUG_ON warnings in the kick code because preemption was on. get_cpu() disables preemption indirectly though, getting rid of the oops :)
Alex
Re: [PATCH 4/4] KVM: PPC: align vcpu_kick with x86
Quoted 11 lines · Alexander Graf
Quoted 6 lines · Scott Wood
Quoted 2 lines · Alexander Graf
Our vcpu kick implementation differs a bit from x86 which resulted in us not disabling preemption during the kick. Get it a bit closer to what x86 does.
Disabling preemption only matters due to the other bit of functionality you brought over -- avoiding kicking the current CPU.
Nope, I had
BUG_ONwarnings in the kick code because preemption was on.
Coming from where?
-Scott
Re: [PATCH 4/4] KVM: PPC: align vcpu_kick with x86
Quoted 8 lines · Scott Wood
Quoted 7 lines · Alexander Graf
Quoted 4 lines · Scott Wood
Quoted 2 lines · Alexander Graf
Our vcpu kick implementation differs a bit from x86 which resulted in us not disabling preemption during the kick. Get it a bit closer to what x86 does.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Disabling preemption only matters due to the other bit of functionality you brought over -- avoiding kicking the current CPU.
Nope, I had
BUG_ONwarnings in the kick code because preemption was on.Coming from where?
From here:
BUG: using smp_processor_id() in preemptible [00000000] code: qemu-system-ppc/17448 caller is .smp_mpic_message_pass+0x88/0x10c Call Trace: [c000000078d83600] [c000000000013e70] .show_stack+0x6c/0x16c (unreliable) [c000000078d836b0] [c00000000037b614] .debug_smp_processor_id+0xe4/0x11c [c000000078d83740] [c000000000048988] .smp_mpic_message_pass+0x88/0x10c [c000000078d837d0] [c00000000002f2b4] .smp_send_reschedule+0x4c/0x80 [c000000078d83850] [d000000005e68984] .kvm_vcpu_kick+0x5c/0x74 [kvm] [c000000078d838d0] [d000000005e689d8] .kvm_vcpu_ioctl_interrupt+0x3c/0x54 [kvm] [c000000078d83950] [d000000005e68a8c] .kvm_arch_vcpu_ioctl+0x9c/0x21c [kvm] [c000000078d83b60] [d000000005e64520] .kvm_vcpu_ioctl+0x7c/0x6b8 [kvm] [c000000078d83c20] [d000000005e64c2c] .kvm_vcpu_compat_ioctl+0xd0/0xfc [kvm] [c000000078d83cd0] [c0000000001be750] .compat_sys_ioctl+0x160/0x1864 [c000000078d83e30] [c00000000000988c] syscall_exit+0x0/0x40
Alex
Re: [PATCH 1/4] KVM: PPC: Book3s: PR: Disable preemption in vcpu_run
In reply to Scott WoodQuoted 18 lines · Scott Wood
Quoted 17 lines · Alexander Graf
When entering the guest, we want to make sure we're not getting preempted away, so let's disable preemption on entry, but enable it again while handling guest exits.
Reported-by Jörg Sommer <[email protected]>Signed-off-by Alexander Graf <[email protected]>---
arch/powerpc/kvm/book3s_pr.c| 7 +++++++1 files changed, 7 insertions(+), 0 deletions(-)arch/powerpc/kvm/book3s_pr.c +0
-0@@ -519,6 +519,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, run->ready_for_interrupt_injection =1 ;
Quoted 16 lines
Quoted 6 lines
arch/powerpc/kvm/book3s_pr.c +1
-0trace_kvm_book3s_exit (exit_nr, vcpu); +preempt_enable ();kvm_resched (vcpu);switch (exit_nr) {case BOOK3S_INTERRUPT_INST_STORAGE :arch/powerpc/kvm/book3s_pr.c program_interrupt: · line 771
Quoted 8 lines
arch/powerpc/kvm/book3s_pr.c +2
-0@@ -763,6 +764,8 @@ program_interrupt: run->exit_reason =KVM_EXIT_INTR ; r = -EINTR ; }else { +preempt_disable (); +/* In case an interrupt came in that was triggered * from userspace (like DEC), we need to check what * to inject now! */ Shouldn't you really have interrupts disabled here, as booke does?
Ah, thanks for the reminder. Yeah, we probably want to disable interrupts in parallel to checking for signals (basically from one signal check point to world switch). I'm just not 100% sure how to easily sync the C and asm code on the first entry though. Doing local_irq_disable in C and undoing it in asm could become ugly with lazy interrupt disabling.
Alex
Re: [PATCH 4/4] KVM: PPC: align vcpu_kick with x86
In reply to Alexander GrafQuoted 20 lines · Alexander Graf
Quoted 8 lines · Scott Wood
Quoted 7 lines · Alexander Graf
Quoted 4 lines · Scott Wood
Quoted 2 lines · Alexander Graf
Our vcpu kick implementation differs a bit from x86 which resulted in us not disabling preemption during the kick. Get it a bit closer to what x86 does.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Disabling preemption only matters due to the other bit of functionality you brought over -- avoiding kicking the current CPU.
Nope, I had
BUG_ONwarnings in the kick code because preemption was on.Coming from where?
From here:
Quoted 14 lines
BUG: using smp_processor_id() in preemptible [00000000] code: qemu-system-ppc/17448 caller is .smp_mpic_message_pass+0x88/0x10c Call Trace: [c000000078d83600] [c000000000013e70] .show_stack+0x6c/0x16c (unreliable) [c000000078d836b0] [c00000000037b614] .debug_smp_processor_id+0xe4/0x11c [c000000078d83740] [c000000000048988] .smp_mpic_message_pass+0x88/0x10c [c000000078d837d0] [c00000000002f2b4] .smp_send_reschedule+0x4c/0x80 [c000000078d83850] [d000000005e68984] .kvm_vcpu_kick+0x5c/0x74 [kvm] [c000000078d838d0] [d000000005e689d8] .kvm_vcpu_ioctl_interrupt+0x3c/0x54 [kvm] [c000000078d83950] [d000000005e68a8c] .kvm_arch_vcpu_ioctl+0x9c/0x21c [kvm] [c000000078d83b60] [d000000005e64520] .kvm_vcpu_ioctl+0x7c/0x6b8 [kvm] [c000000078d83c20] [d000000005e64c2c] .kvm_vcpu_compat_ioctl+0xd0/0xfc [kvm] [c000000078d83cd0] [c0000000001be750] .compat_sys_ioctl+0x160/0x1864 [c000000078d83e30] [c00000000000988c] syscall_exit+0x0/0x40
Hmm, unless smp_send_reschedule must be called with preemption disabled (doesn't seem like an obvious requirement, even if callers commonly have a reason to do so, and the only documentation of it I see is on the ia64 implementation), that seems like a bug in the MPIC IPI implementation.
It wouldn't be an issue (and would make the MPIC driver slightly faster, too) if the MPIC driver were to use the magic CPU region instead of manually indexing the non-magic array of per-CPU regions. Maybe it doesn't work on all hardware the driver supports?
Not that it matters much here -- we want this patch anyway, because we want to check that it's not the current CPU.
-Scott
Re: [PATCH 1/4] KVM: PPC: Book3s: PR: Disable preemption in vcpu_run
In reply to Alexander GrafQuoted 11 lines · Alexander Graf
Quoted 1 line · Scott Wood
Shouldn't you really have interrupts disabled here, as booke does?
Ah, thanks for the reminder. Yeah, we probably want to disable interrupts in parallel to checking for signals (basically from one signal check point to world switch). I'm just not 100% sure how to easily sync the C and asm code on the first entry though. Doing
local_irq_disablein C and undoing it in asm could become ugly with lazy interrupt disabling.
Lots of things get ugly with lazy interrupt disabling. :-(
There should be other examples of handling the lazy EE stuff in asm code. After you hard-disable, you should just need to poke the right fields in the PACA with the state you plan to end up in after the rfi, similar to exception return.
-Scott
Re: [PATCH 4/4] KVM: PPC: align vcpu_kick with x86
In reply to Scott WoodQuoted 41 lines · Scott Wood
Quoted 20 lines · Alexander Graf
Quoted 8 lines · Scott Wood
Quoted 7 lines · Alexander Graf
Quoted 4 lines · Scott Wood
Quoted 2 lines · Alexander Graf
Our vcpu kick implementation differs a bit from x86 which resulted in us not disabling preemption during the kick. Get it a bit closer to what x86 does.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Disabling preemption only matters due to the other bit of functionality you brought over -- avoiding kicking the current CPU.
Nope, I had
BUG_ONwarnings in the kick code because preemption was on.Coming from where?
From here:
Quoted 14 lines
BUG: using smp_processor_id() in preemptible [00000000] code: qemu-system-ppc/17448 caller is .smp_mpic_message_pass+0x88/0x10c Call Trace: [c000000078d83600] [c000000000013e70] .show_stack+0x6c/0x16c (unreliable) [c000000078d836b0] [c00000000037b614] .debug_smp_processor_id+0xe4/0x11c [c000000078d83740] [c000000000048988] .smp_mpic_message_pass+0x88/0x10c [c000000078d837d0] [c00000000002f2b4] .smp_send_reschedule+0x4c/0x80 [c000000078d83850] [d000000005e68984] .kvm_vcpu_kick+0x5c/0x74 [kvm] [c000000078d838d0] [d000000005e689d8] .kvm_vcpu_ioctl_interrupt+0x3c/0x54 [kvm] [c000000078d83950] [d000000005e68a8c] .kvm_arch_vcpu_ioctl+0x9c/0x21c [kvm] [c000000078d83b60] [d000000005e64520] .kvm_vcpu_ioctl+0x7c/0x6b8 [kvm] [c000000078d83c20] [d000000005e64c2c] .kvm_vcpu_compat_ioctl+0xd0/0xfc [kvm] [c000000078d83cd0] [c0000000001be750] .compat_sys_ioctl+0x160/0x1864 [c000000078d83e30] [c00000000000988c] syscall_exit+0x0/0x40Hmm, unless
smp_send_reschedulemust be called with preemption disabled (doesn't seem like an obvious requirement, even if callers commonly have a reason to do so, and the only documentation of it I see is on the ia64 implementation), that seems like a bug in the MPIC IPI implementation.
Quoted 4 lines
It wouldn't be an issue (and would make the MPIC driver slightly faster, too) if the MPIC driver were to use the magic CPU region instead of manually indexing the non-magic array of per-CPU regions. Maybe it doesn't work on all hardware the driver supports?
I'd say that's a question I'll redirect to Ben :).
Quoted 2 lines
Not that it matters much here -- we want this patch anyway, because we want to check that it's not the current CPU.
Yeah. Well - eventually we want the exact same vcpu_kick function across architectures. But this is a good step in the right direction.
Alex
Re: [PATCH 4/4] KVM: PPC: align vcpu_kick with x86
Quoted 9 lines · Alexander Graf
Quoted 9 lines
Hmm, unless
smp_send_reschedulemust be called with preemption disabled (doesn't seem like an obvious requirement, even if callers commonly have a reason to do so, and the only documentation of it I see is on the ia64 implementation), that seems like a bug in the MPIC IPI implementation.It wouldn't be an issue (and would make the MPIC driver slightly faster, too) if the MPIC driver were to use the magic CPU region instead of manually indexing the non-magic array of per-CPU regions. Maybe it doesn't work on all hardware the driver supports?
Right, the magic per-cpu region doesn't work on all HW.
Quoted 7 lines
I'd say that's a question I'll redirect to Ben :).
Quoted 2 lines
Not that it matters much here -- we want this patch anyway, because we want to check that it's not the current CPU.
Yeah. Well - eventually we want the exact same
vcpu_kickfunction across architectures. But this is a good step in the right direction.
Cheers,
Ben.