Re: [PATCH] kernel: fix data race in put_pid

From: Oleg Nesterov
Date: Fri Sep 18 2015 - 09:47:56 EST


On 09/18, Peter Zijlstra wrote:
>
> Provide atomic_read_ctrl() to mirror READ_ONCE_CTRL(), such that we can
> more conveniently use atomics in control dependencies.
>
> Since we can assume atomic_read() implies a READ_ONCE(), we must only
> emit an extra smp_read_barrier_depends() in order to upgrade to
> READ_ONCE_CTRL() semantics.

...

> +static inline int atomic_read_ctrl(atomic_t *v)
> +{
> + int val = atomic_read(v);
> + smp_read_barrier_depends(); /* Enforce control dependency. */
> + return val;
> +}

Help. I am starting to think that the control dependencies is even more
hard to understand that memory barriers...

So I assume that if we have

int X = 0;
atomic_t Y = ATOMIC_INIT(0);

void w(void)
{
X = 1;
atomic_inc_return(&Y);
}

then

void r(void)
{
if (atomic_read_ctrl(&Y))
BUG_ON(X == 0);
}

should be correct? Why?

If not then I am even more confused.

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/