seqlock: Require WRITE_ONCE surrounding raw_seqcount_barrier
authorMarco Elver <elver@google.com>
Thu, 14 Nov 2019 18:03:00 +0000 (19:03 +0100)
committerPaul E. McKenney <paulmck@kernel.org>
Sat, 16 Nov 2019 15:23:15 +0000 (07:23 -0800)
commitbf07132f96d426bcbf2098227fb680915cf44498
treef39448c1c0e68b6f607d21ea3506915273822ba2
parent88ecd153be9519f259b87a9f6f4c8383a8b3bbf1
seqlock: Require WRITE_ONCE surrounding raw_seqcount_barrier

This patch proposes to require marked atomic accesses surrounding
raw_write_seqcount_barrier. We reason that otherwise there is no way to
guarantee propagation nor atomicity of writes before/after the barrier
[1]. For example, consider the compiler tears stores either before or
after the barrier; in this case, readers may observe a partial value,
and because readers are unaware that writes are going on (writes are not
in a seq-writer critical section), will complete the seq-reader critical
section while having observed some partial state.
[1] https://lwn.net/Articles/793253/

This came up when designing and implementing KCSAN, because KCSAN would
flag these accesses as data-races. After careful analysis, our reasoning
as above led us to conclude that the best thing to do is to propose an
amendment to the raw_seqcount_barrier usage.

Signed-off-by: Marco Elver <elver@google.com>
Acked-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
include/linux/seqlock.h