Re: Unlock-lock questions and the Linux Kernel Memory Model

From: Peter Zijlstra
Date: Tue Nov 28 2017 - 04:45:02 EST


On Mon, Nov 27, 2017 at 03:28:03PM -0800, Daniel Lustig wrote:
> On 11/27/2017 1:16 PM, Alan Stern wrote:> C rel-acq-write-ordering-3
> >
> > {}
> >
> > P0(int *x, int *s, int *y)
> > {
> > WRITE_ONCE(*x, 1);
> > smp_store_release(s, 1);
> > r1 = smp_load_acquire(s);
> > WRITE_ONCE(*y, 1);
> > }
> >
> > P1(int *x, int *y)
> > {
> > r2 = READ_ONCE(*y);
> > smp_rmb();
> > r3 = READ_ONCE(*x);
> > }
> >
> > exists (1:r2=1 /\ 1:r3=0)
> >
> <snip>
> >
> > And going to extremes...
>
> Sorry if I'm missing something obvious, but before going to extremes...
> what about this one?
>
> "SB+rel-acq" (or please rename if you have a different scheme)
>
> {}
>
> P0(int *x, int *s, int *y)
> {
> WRITE_ONCE(*x, 1);
> smp_store_release(s, 1);
> r1 = smp_load_acquire(s);
> r2 = READ_ONCE(*y);
> }

Yes, this one doesn't work on TSO and Power.

Ideally it would work for locks though, but that would mean mandating
RCsc lock implementations and currently Power is holding out on that.