Subject: Re: [PATCH] Avoid unpaired stwcx. on some processors

From: Olof Johansson <[email-masked]>
Date: Fri, 9 Nov 2007 17:19:27 -0600

On Fri, Nov 09, 2007 at 04:08:06PM -0600, Becky Bruce wrote:
> The context switch code in the kernel issues a dummy stwcx. to clear the
> reservation, as recommended by the architecture. However, some processors
> can have issues if this stwcx to address A occurs while the reservation
> is already held to a different address B.  To avoid this problem, the dummy
> stwcx. needs to be paired with a dummy lwarx to the same address.
> 
> This patch adds the dummy lwarx, and creates a cpu feature bit to indicate
> which cpus are affected. Tested on mpc8641_hpcn_defconfig in arch/powerpc;
> build tested in arch/ppc.

You're still exposed even with this patch. The stwcx is there to protect
from the cases where process 1 does lwarx and get context switched
out to process 2 that by pure random chance does a stwcx. to the same
reservation granule and succeeds, in spite of not having done the lwarx
(on this side of the context switch).

In exactly that case, process 2 will instead of doing a store to a
reservation it didn't take on it's own, do a dangling stwcx, which is
your erratum. Right?

Seems like a "better" (but still ugly) workaround would be to create a
_new_ reservation to a RA that's unavailable to any userspace process,
so that they could never do a successful store to it. That way you would
have stray reservations, but never dangling stwcx:es. No?

-Olof