aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Mackerras <paulus@ozlabs.org>2018-03-07 06:17:20 -0500
committerPaul Mackerras <paulus@ozlabs.org>2018-03-14 00:10:50 -0400
commita8b48a4dccea77e29462e59f1dbf0d5aa1ff167c (patch)
tree2a61779bba28cfc36aa0c77d327e5e70d3130a99
parent45e3b4759d230b057832fa751af9a853495a17bd (diff)
KVM: PPC: Book3S HV: Fix trap number return from __kvmppc_vcore_entry
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: fd7bacbca47a ("KVM: PPC: Book3S HV: Fix TB corruption in guest exit path on HMI interrupt") Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
-rw-r--r--arch/powerpc/kvm/book3s_hv_rmhandlers.S10
1 files changed, 5 insertions, 5 deletions
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index f31f357b8c5a..d33264697a31 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -320,7 +320,6 @@ kvm_novcpu_exit:
320 stw r12, STACK_SLOT_TRAP(r1) 320 stw r12, STACK_SLOT_TRAP(r1)
321 bl kvmhv_commence_exit 321 bl kvmhv_commence_exit
322 nop 322 nop
323 lwz r12, STACK_SLOT_TRAP(r1)
324 b kvmhv_switch_to_host 323 b kvmhv_switch_to_host
325 324
326/* 325/*
@@ -1220,6 +1219,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
1220 1219
1221secondary_too_late: 1220secondary_too_late:
1222 li r12, 0 1221 li r12, 0
1222 stw r12, STACK_SLOT_TRAP(r1)
1223 cmpdi r4, 0 1223 cmpdi r4, 0
1224 beq 11f 1224 beq 11f
1225 stw r12, VCPU_TRAP(r4) 1225 stw r12, VCPU_TRAP(r4)
@@ -1558,12 +1558,12 @@ mc_cont:
15583: stw r5,VCPU_SLB_MAX(r9) 15583: stw r5,VCPU_SLB_MAX(r9)
1559 1559
1560guest_bypass: 1560guest_bypass:
1561 stw r12, STACK_SLOT_TRAP(r1)
1561 mr r3, r12 1562 mr r3, r12
1562 /* Increment exit count, poke other threads to exit */ 1563 /* Increment exit count, poke other threads to exit */
1563 bl kvmhv_commence_exit 1564 bl kvmhv_commence_exit
1564 nop 1565 nop
1565 ld r9, HSTATE_KVM_VCPU(r13) 1566 ld r9, HSTATE_KVM_VCPU(r13)
1566 lwz r12, VCPU_TRAP(r9)
1567 1567
1568 /* Stop others sending VCPU interrupts to this physical CPU */ 1568 /* Stop others sending VCPU interrupts to this physical CPU */
1569 li r0, -1 1569 li r0, -1
@@ -1898,6 +1898,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_POWER9_DD1)
1898 * POWER7/POWER8 guest -> host partition switch code. 1898 * POWER7/POWER8 guest -> host partition switch code.
1899 * We don't have to lock against tlbies but we do 1899 * We don't have to lock against tlbies but we do
1900 * have to coordinate the hardware threads. 1900 * have to coordinate the hardware threads.
1901 * Here STACK_SLOT_TRAP(r1) contains the trap number.
1901 */ 1902 */
1902kvmhv_switch_to_host: 1903kvmhv_switch_to_host:
1903 /* Secondary threads wait for primary to do partition switch */ 1904 /* Secondary threads wait for primary to do partition switch */
@@ -1950,12 +1951,12 @@ BEGIN_FTR_SECTION
1950END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) 1951END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
1951 1952
1952 /* If HMI, call kvmppc_realmode_hmi_handler() */ 1953 /* If HMI, call kvmppc_realmode_hmi_handler() */
1954 lwz r12, STACK_SLOT_TRAP(r1)
1953 cmpwi r12, BOOK3S_INTERRUPT_HMI 1955 cmpwi r12, BOOK3S_INTERRUPT_HMI
1954 bne 27f 1956 bne 27f
1955 bl kvmppc_realmode_hmi_handler 1957 bl kvmppc_realmode_hmi_handler
1956 nop 1958 nop
1957 cmpdi r3, 0 1959 cmpdi r3, 0
1958 li r12, BOOK3S_INTERRUPT_HMI
1959 /* 1960 /*
1960 * At this point kvmppc_realmode_hmi_handler may have resync-ed 1961 * At this point kvmppc_realmode_hmi_handler may have resync-ed
1961 * the TB, and if it has, we must not subtract the guest timebase 1962 * the TB, and if it has, we must not subtract the guest timebase
@@ -2008,10 +2009,8 @@ BEGIN_FTR_SECTION
2008 lwz r8, KVM_SPLIT_DO_RESTORE(r3) 2009 lwz r8, KVM_SPLIT_DO_RESTORE(r3)
2009 cmpwi r8, 0 2010 cmpwi r8, 0
2010 beq 47f 2011 beq 47f
2011 stw r12, STACK_SLOT_TRAP(r1)
2012 bl kvmhv_p9_restore_lpcr 2012 bl kvmhv_p9_restore_lpcr
2013 nop 2013 nop
2014 lwz r12, STACK_SLOT_TRAP(r1)
2015 b 48f 2014 b 48f
201647: 201547:
2017END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) 2016END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
@@ -2049,6 +2048,7 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_RADIX)
2049 li r0, KVM_GUEST_MODE_NONE 2048 li r0, KVM_GUEST_MODE_NONE
2050 stb r0, HSTATE_IN_GUEST(r13) 2049 stb r0, HSTATE_IN_GUEST(r13)
2051 2050
2051 lwz r12, STACK_SLOT_TRAP(r1) /* return trap # in r12 */
2052 ld r0, SFS+PPC_LR_STKOFF(r1) 2052 ld r0, SFS+PPC_LR_STKOFF(r1)
2053 addi r1, r1, SFS 2053 addi r1, r1, SFS
2054 mtlr r0 2054 mtlr r0