Skip to content

Commit b87943f

Browse files
paulusmackgregkh
authored andcommitted
KVM: PPC: Book3S HV: Fix trap number return from __kvmppc_vcore_entry
commit a8b48a4 upstream. This fixes a bug where the trap number that is returned by __kvmppc_vcore_entry gets corrupted. The effect of the corruption is that IPIs get ignored on POWER9 systems when the IPI is sent via a doorbell interrupt to a CPU which is executing in a KVM guest. The effect of the IPI being ignored is often that another CPU locks up inside smp_call_function_many() (and if that CPU is holding a spinlock, other CPUs then lock up inside raw_spin_lock()). The trap number is currently held in register r12 for most of the assembly-language part of the guest exit path. In that path, we call kvmppc_subcore_exit_guest(), which is a C function, without restoring r12 afterwards. Depending on the kernel config and the compiler, it may modify r12 or it may not, so some config/compiler combinations see the bug and others don't. To fix this, we arrange for the trap number to be stored on the stack from the 'guest_bypass:' label until the end of the function, then the trap number is loaded and returned in r12 as before. Cc: stable@vger.kernel.org # v4.8+ Fixes: fd7bacb ("KVM: PPC: Book3S HV: Fix TB corruption in guest exit path on HMI interrupt") Signed-off-by: Paul Mackerras <paulus@ozlabs.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 57d6410 commit b87943f

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

arch/powerpc/kvm/book3s_hv_rmhandlers.S

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ kvm_novcpu_exit:
299299
stw r12, STACK_SLOT_TRAP(r1)
300300
bl kvmhv_commence_exit
301301
nop
302-
lwz r12, STACK_SLOT_TRAP(r1)
303302
b kvmhv_switch_to_host
304303

305304
/*
@@ -1023,6 +1022,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
10231022

10241023
secondary_too_late:
10251024
li r12, 0
1025+
stw r12, STACK_SLOT_TRAP(r1)
10261026
cmpdi r4, 0
10271027
beq 11f
10281028
stw r12, VCPU_TRAP(r4)
@@ -1266,12 +1266,12 @@ mc_cont:
12661266
bl kvmhv_accumulate_time
12671267
#endif
12681268

1269+
stw r12, STACK_SLOT_TRAP(r1)
12691270
mr r3, r12
12701271
/* Increment exit count, poke other threads to exit */
12711272
bl kvmhv_commence_exit
12721273
nop
12731274
ld r9, HSTATE_KVM_VCPU(r13)
1274-
lwz r12, VCPU_TRAP(r9)
12751275

12761276
/* Stop others sending VCPU interrupts to this physical CPU */
12771277
li r0, -1
@@ -1549,6 +1549,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
15491549
* POWER7/POWER8 guest -> host partition switch code.
15501550
* We don't have to lock against tlbies but we do
15511551
* have to coordinate the hardware threads.
1552+
* Here STACK_SLOT_TRAP(r1) contains the trap number.
15521553
*/
15531554
kvmhv_switch_to_host:
15541555
/* Secondary threads wait for primary to do partition switch */
@@ -1599,11 +1600,11 @@ BEGIN_FTR_SECTION
15991600
END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
16001601

16011602
/* If HMI, call kvmppc_realmode_hmi_handler() */
1603+
lwz r12, STACK_SLOT_TRAP(r1)
16021604
cmpwi r12, BOOK3S_INTERRUPT_HMI
16031605
bne 27f
16041606
bl kvmppc_realmode_hmi_handler
16051607
nop
1606-
li r12, BOOK3S_INTERRUPT_HMI
16071608
/*
16081609
* At this point kvmppc_realmode_hmi_handler would have resync-ed
16091610
* the TB. Hence it is not required to subtract guest timebase
@@ -1678,6 +1679,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
16781679
li r0, KVM_GUEST_MODE_NONE
16791680
stb r0, HSTATE_IN_GUEST(r13)
16801681

1682+
lwz r12, STACK_SLOT_TRAP(r1) /* return trap # in r12 */
16811683
ld r0, SFS+PPC_LR_STKOFF(r1)
16821684
addi r1, r1, SFS
16831685
mtlr r0

0 commit comments

Comments
 (0)