summaryrefslogtreecommitdiffstats
path: root/arch/powerpc
diff options
context:
space:
mode:
authorGautham R. Shenoy <ego@linux.vnet.ibm.com>2015-09-02 12:18:58 -0400
committerPaul Mackerras <paulus@samba.org>2015-09-03 02:07:42 -0400
commit7f23532866f931be626e69ff55caf39e54516047 (patch)
treeed81d64702e8c84f3744d9176a6d8b67188e062a /arch/powerpc
parente3dbc572fe11a5231568e106fa3dcedd1d1bec0f (diff)
KVM: PPC: Book3S HV: Fix race in starting secondary threads
The current dynamic micro-threading code has a race due to which a secondary thread naps when it is supposed to be running a vcpu. As a side effect of this, on a guest exit, the primary thread in kvmppc_wait_for_nap() finds that this secondary thread hasn't cleared its vcore pointer. This results in "CPU X seems to be stuck!" warnings. The race is possible since the primary thread on exiting the guests only waits for all the secondaries to clear its vcore pointer. It subsequently expects the secondary threads to enter nap while it unsplits the core. A secondary thread which hasn't yet entered the nap will loop in kvm_no_guest until its vcore pointer and the do_nap flag are unset. Once the core has been unsplit, a new vcpu thread can grab the core and set the do_nap flag *before* setting the vcore pointers of the secondary. As a result, the secondary thread will now enter nap via kvm_unsplit_nap instead of running the guest vcpu. Fix this by setting the do_nap flag after setting the vcore pointer in the PACA of the secondary in kvmppc_run_core. Also, ensure that a secondary thread doesn't nap in kvm_unsplit_nap when the vcore pointer in its PACA struct is set. Fixes: b4deba5c41e9 Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc')
-rw-r--r--arch/powerpc/kvm/book3s_hv.c10
-rw-r--r--arch/powerpc/kvm/book3s_hv_rmhandlers.S8
2 files changed, 17 insertions, 1 deletions
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index fad52f226c12..c5edf1719314 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -2411,7 +2411,6 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
2411 break; 2411 break;
2412 cpu_relax(); 2412 cpu_relax();
2413 } 2413 }
2414 split_info.do_nap = 1; /* ask secondaries to nap when done */
2415 } 2414 }
2416 2415
2417 /* Start all the threads */ 2416 /* Start all the threads */
@@ -2440,6 +2439,15 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
2440 thr += pvc->num_threads; 2439 thr += pvc->num_threads;
2441 } 2440 }
2442 } 2441 }
2442
2443 /*
2444 * Ensure that split_info.do_nap is set after setting
2445 * the vcore pointer in the PACA of the secondaries.
2446 */
2447 smp_mb();
2448 if (cmd_bit)
2449 split_info.do_nap = 1; /* ask secondaries to nap when done */
2450
2443 /* 2451 /*
2444 * When doing micro-threading, poke the inactive threads as well. 2452 * When doing micro-threading, poke the inactive threads as well.
2445 * This gets them to the nap instruction after kvm_do_nap, 2453 * This gets them to the nap instruction after kvm_do_nap,
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index 472680f47d09..b07f04550969 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -421,6 +421,14 @@ kvm_no_guest:
421 * whole-core mode, so we need to nap. 421 * whole-core mode, so we need to nap.
422 */ 422 */
423kvm_unsplit_nap: 423kvm_unsplit_nap:
424 /*
425 * Ensure that secondary doesn't nap when it has
426 * its vcore pointer set.
427 */
428 sync /* matches smp_mb() before setting split_info.do_nap */
429 ld r0, HSTATE_KVM_VCORE(r13)
430 cmpdi r0, 0
431 bne kvm_no_guest
424 /* clear any pending message */ 432 /* clear any pending message */
425BEGIN_FTR_SECTION 433BEGIN_FTR_SECTION
426 lis r6, (PPC_DBELL_SERVER << (63-36))@h 434 lis r6, (PPC_DBELL_SERVER << (63-36))@h