Re: Litmus test for question from Al Viro

From: joel
Date: Sat Oct 03 2020 - 12:12:08 EST


On Sat, Oct 03, 2020 at 12:08:46PM -0400, joel@xxxxxxxxxxxxxxxxx wrote:
[...]
> static void code0(struct v_struct* v,spinlock_t* l,int* out_0_r1) {
>
> struct v_struct *r1; /* to_free */
>
> r1 = NULL;
> spin_lock(l);
> if (!smp_load_acquire(&v->b))
> r1 = v;
> v->a = 0;
> spin_unlock(l);
>
> *out_0_r1 = !!r1;
> }
>
> static void code1(struct v_struct* v,spinlock_t* l,int* out_1_r1) {
>
> struct v_struct *r1; /* to_free */
>
> r1 = v;
> if (READ_ONCE(v->a)) {
> spin_lock(l);
> if (v->a)
> r1 = NULL;
> smp_store_release(&v->b, 0);
> spin_unlock(l);
> }
>
> *out_1_r1 = !!r1;
> }
>
> Results on both arm64 and x86:
>
> Histogram (2 states)
> 19080852:>0:r1=1; 1:r1=0;
> 20919148:>0:r1=0; 1:r1=1;
> No
>
> Witnesses
> Positive: 0, Negative: 40000000
> Condition exists (0:r1=1 /\ 1:r1=1) is NOT validated
> Hash=4a8c15603ffb5ab464195ea39ccd6382
> Observation AL+test Never 0 40000000
> Time AL+test 6.24
>
> I guess I could do an alloc and free of v_struct. However, I just checked for
> whether the to_free in Al's example could ever be NULL for both threads.

Sorry, here I meant "ever be non-NULL".

So basically I was trying to experimentally confirm that to_free could never
be non-NULL in both code0 and code1 threads.