aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/kernel
diff options
context:
space:
mode:
authorPaul Mackerras <paulus@samba.org>2012-02-02 19:54:17 -0500
committerAvi Kivity <avi@redhat.com>2012-04-08 07:01:20 -0400
commitf0888f70151c7f53de2b45ee20ff1905837943e8 (patch)
tree80b7e133e681a2b4e4255a8fa747711da4c59211 /arch/powerpc/kernel
parentf6127716c346c73ab1513edee53231800188c5ba (diff)
KVM: PPC: Book3S HV: Make secondary threads more robust against stray IPIs
Currently on POWER7, if we are running the guest on a core and we don't need all the hardware threads, we do nothing to ensure that the unused threads aren't executing in the kernel (other than checking that they are offline). We just assume they're napping and we don't do anything to stop them trying to enter the kernel while the guest is running. This means that a stray IPI can wake up the hardware thread and it will then try to enter the kernel, but since the core is in guest context, it will execute code from the guest in hypervisor mode once it turns the MMU on, which tends to lead to crashes or hangs in the host. This fixes the problem by adding two new one-byte flags in the kvmppc_host_state structure in the PACA which are used to interlock between the primary thread and the unused secondary threads when entering the guest. With these flags, the primary thread can ensure that the unused secondaries are not already in kernel mode (i.e. handling a stray IPI) and then indicate that they should not try to enter the kernel if they do get woken for any reason. Instead they will go into KVM code, find that there is no vcpu to run, acknowledge and clear the IPI and go back to nap mode. Signed-off-by: Paul Mackerras <paulus@samba.org> Signed-off-by: Alexander Graf <agraf@suse.de> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/powerpc/kernel')
-rw-r--r--arch/powerpc/kernel/asm-offsets.c2
-rw-r--r--arch/powerpc/kernel/exceptions-64s.S12
-rw-r--r--arch/powerpc/kernel/idle_power7.S7
3 files changed, 16 insertions, 5 deletions
diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c
index bbede5882c5b..2abcf7d4b29c 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -540,6 +540,8 @@ int main(void)
540 HSTATE_FIELD(HSTATE_IN_GUEST, in_guest); 540 HSTATE_FIELD(HSTATE_IN_GUEST, in_guest);
541 HSTATE_FIELD(HSTATE_RESTORE_HID5, restore_hid5); 541 HSTATE_FIELD(HSTATE_RESTORE_HID5, restore_hid5);
542 HSTATE_FIELD(HSTATE_NAPPING, napping); 542 HSTATE_FIELD(HSTATE_NAPPING, napping);
543 HSTATE_FIELD(HSTATE_HWTHREAD_REQ, hwthread_req);
544 HSTATE_FIELD(HSTATE_HWTHREAD_STATE, hwthread_state);
543 545
544#ifdef CONFIG_KVM_BOOK3S_64_HV 546#ifdef CONFIG_KVM_BOOK3S_64_HV
545 HSTATE_FIELD(HSTATE_KVM_VCPU, kvm_vcpu); 547 HSTATE_FIELD(HSTATE_KVM_VCPU, kvm_vcpu);
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index cb705fdbb458..8829b1095f7f 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -63,11 +63,13 @@ BEGIN_FTR_SECTION
63 GET_PACA(r13) 63 GET_PACA(r13)
64 64
65#ifdef CONFIG_KVM_BOOK3S_64_HV 65#ifdef CONFIG_KVM_BOOK3S_64_HV
66 lbz r0,PACAPROCSTART(r13) 66 li r0,KVM_HWTHREAD_IN_KERNEL
67 cmpwi r0,0x80 67 stb r0,HSTATE_HWTHREAD_STATE(r13)
68 bne 1f 68 /* Order setting hwthread_state vs. testing hwthread_req */
69 li r0,1 69 sync
70 stb r0,PACAPROCSTART(r13) 70 lbz r0,HSTATE_HWTHREAD_REQ(r13)
71 cmpwi r0,0
72 beq 1f
71 b kvm_start_guest 73 b kvm_start_guest
721: 741:
73#endif 75#endif
diff --git a/arch/powerpc/kernel/idle_power7.S b/arch/powerpc/kernel/idle_power7.S
index 0cdc9a392839..7140d838339e 100644
--- a/arch/powerpc/kernel/idle_power7.S
+++ b/arch/powerpc/kernel/idle_power7.S
@@ -16,6 +16,7 @@
16#include <asm/asm-offsets.h> 16#include <asm/asm-offsets.h>
17#include <asm/ppc-opcode.h> 17#include <asm/ppc-opcode.h>
18#include <asm/hw_irq.h> 18#include <asm/hw_irq.h>
19#include <asm/kvm_book3s_asm.h>
19 20
20#undef DEBUG 21#undef DEBUG
21 22
@@ -81,6 +82,12 @@ _GLOBAL(power7_idle)
81 std r9,_MSR(r1) 82 std r9,_MSR(r1)
82 std r1,PACAR1(r13) 83 std r1,PACAR1(r13)
83 84
85#ifdef CONFIG_KVM_BOOK3S_64_HV
86 /* Tell KVM we're napping */
87 li r4,KVM_HWTHREAD_IN_NAP
88 stb r4,HSTATE_HWTHREAD_STATE(r13)
89#endif
90
84 /* Magic NAP mode enter sequence */ 91 /* Magic NAP mode enter sequence */
85 std r0,0(r1) 92 std r0,0(r1)
86 ptesync 93 ptesync