Re: Internal vs. external barriers (was: Re: Interesting LKMM litmus test)

Paul E. McKenney
2023-01-24T04:07:36Z

On Mon, Jan 23, 2023 at 09:18:14PM -0500, Alan Stern wrote:
> On Mon, Jan 23, 2023 at 12:16:59PM -0800, Paul E. McKenney wrote:
> > One twist is that the design of both SRCU and RCU are stronger than LKMM
> > requires, as illustrated by the litmus test at the end of this email.
> >
> > I believe that your proof outline above also covers this case, but I
> > figure that I should ask.
>
> This test is full of typos, and I guess that one of them seriously
> affects the meaning, because as far as I can tell the corrected test is
> allowed.
>
> > C C-srcu-observed-2
> >
> > (*
> > * Result: Sometimes
> > *
> > * But please note that the Linux-kernel SRCU implementation is designed
> > * to provide Never.
> > *)
> >
> > {}
> >
> > P0(int *x, int *y, int *z, struct srcu_struct *s)
> > {
> > int r1;
> > int r2;
>
> r2 is never used.
>
> >
> > r1 = srcu_read_lock(s);
> > WRITE_ONCE(*y, 1);
> > WRITE_ONCE(*x, 1);
> > srcu_read_unlock(s, r3);
>
> There is no r3; this should be r1.
>
> > }
> >
> > P1(int *x, int *y, int *z, struct srcu_struct *s)
> > {
> > int r1;
> > int r2;
>
> r2 is never used.
>
> >
> > r1 = READ_ONCE(*y);
> > synchronize_srcu(s);
> > WRITE_ONCE(*z, 1);
> > }
> >
> > P2(int *x, int *y, int *z, struct srcu_struct *s)
> > {
> > int r1;
>
> r1 is never used; it should be r2.
>
> >
> > WRITE_ONCE(*z, 2);
> > smp_mb();
> > r2 = READ_ONCE(*x);
> > }
> >
> > exists (1:r1=1 /\ 1:r2=0 /\ z=1)
>
> 1:r2 is never used. Apparently this should 2:r2.
>
> Given those changes, the test can run as follows: P2 runs to completion,
> writing z=2 and reading x=0. Then P0 runs to completion, writing y=1
> and x=1. Then P1 runs to completion, reading y=1 and overwriting z=1.

All that and I also messed up by not having "z=2". :-/

Thank you for looking it over!

But the following one is forbidden, the Result comment below
notwithstanding. I could have sworn that there was some post-grace-period
write-to-write litmus test that LKMM allowed, but if so, this one is
not it.

------------------------------------------------------------------------

C C-srcu-observed-2

(*
* Result: Sometimes
*
* But please note that the Linux-kernel SRCU implementation is designed
* to provide Never.
*)

{}

P0(int *x, int *y, int *z, struct srcu_struct *s)
{
int r1;

r1 = srcu_read_lock(s);
WRITE_ONCE(*y, 1);
WRITE_ONCE(*x, 1);
srcu_read_unlock(s, r1);
}

P1(int *x, int *y, int *z, struct srcu_struct *s)
{
int r1;

r1 = READ_ONCE(*y);
synchronize_srcu(s);
WRITE_ONCE(*z, 1);
}

P2(int *x, int *y, int *z, struct srcu_struct *s)
{
int r1;

WRITE_ONCE(*z, 2);
smp_mb();
r1 = READ_ONCE(*x);
}

exists (1:r1=1 /\ 2:r1=0 /\ z=2)

------------------------------------------------------------------------

There is the one below, but I am (1) not sure that I have it right,
(2) not immediately certain that the Linux-kernel implementation would
forbid it, (3) not immediately sure that it should be forbidden.

In the meantime, thoughts?

Thanx, Paul

------------------------------------------------------------------------

C C-srcu-observed-3

(*
* Result: Sometimes
*)

{}

P0(int *x, int *y, int *z, struct srcu_struct *s)
{
int r1;

r1 = srcu_read_lock(s);
WRITE_ONCE(*y, 1);
WRITE_ONCE(*x, 1);
srcu_read_unlock(s, r1);
}

P1(int *x, int *y, int *z, struct srcu_struct *s)
{
int r1;

r1 = READ_ONCE(*y);
synchronize_srcu(s);
WRITE_ONCE(*z, 1);
}

P2(int *x, int *y, int *z, struct srcu_struct *s)
{
WRITE_ONCE(*z, 2);
smp_mb();
WRITE_ONCE(*x, 2);
}

exists (1:r1=1 /\ x=2 /\ z=2)