From e9b3f3045d25487fb1536538e1d25e6abb9cbedf Mon Sep 17 00:00:00 2001 From: Marcel Moolenaar Date: Sat, 4 Apr 2009 22:23:03 +0000 Subject: [PATCH] Perform a dummy stwcx. when we switch contexts. The context being switched out may hold a reservation. The stwcx. will clear the reservation. This is architecturally recommended. The scenario this addresses is as follows: 1. Thread 1 performs a lwarx and as such holds a reservation. 2. Thread 1 gets switched out (before doing the matching stwcx.) and thread 2 is switched in. 3. Thread 2 performs a stwcx. to the same reservation granule. This will succeed because the processor has the reservation even though thread 2 didn't do the lwarx. Note that on some processors the address given the stwcx. is not checked. On these processors the mere condition of having a reservation would cause the stwcx. to succeed, irrespective of whether the addresses are the same. The dummy stwcx. is especially important for those processors. --- sys/powerpc/aim/swtch.S | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sys/powerpc/aim/swtch.S b/sys/powerpc/aim/swtch.S index 672fe6b1161c..619bf8907624 100644 --- a/sys/powerpc/aim/swtch.S +++ b/sys/powerpc/aim/swtch.S @@ -155,6 +155,12 @@ cpu_switchin: mtsr USER_SR,%r5 isync lwz %r1,PCB_SP(%r3) /* Load the stack pointer */ + /* + * Perform a dummy stwcx. to clear any reservations we may have + * inherited from the previous thread. It doesn't matter if the + * stwcx succeeds or not. pcb_context[0] can be clobbered. + */ + stwcx. %r1, 0, %r3 blr /*