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

Alan Stern
2023-01-24T02:18:20Z

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.

Alan