Re: [PATCH] rcutorture: Fix rcu_torture_pipe_update_one()/rcu_torture_writer() data race and concurrency bug

From: Steven Rostedt
Date: Wed Mar 06 2024 - 13:18:30 EST


On Wed, 6 Mar 2024 10:09:48 -0800
"Paul E. McKenney" <paulmck@xxxxxxxxxx> wrote:

> > Perhaps we need a way to annotate them, like we have with __rcu. "__shared"?
> >
> > Then all accesses to that variable must be wrapped with a READ_ONCE() or
> > WRITE_ONCE()? I mean, if this can cause legitimate bugs, we should probably
> > address it like we do with locking and RCU.
>
> If we want that, just mark the field "volatile", as in "jiffies".

I already know Linus's view on "volatile" variables ;-)

>
> And one of the strengths of READ_ONCE() and WRITE_ONCE() is that they
> allow non-volatile access where it is safe. For example, if you hold the
> lock protecting all stores to that variable, you still need WRITE_ONCE()
> but not READ_ONCE(). In initialization and cleanup code, you don't
> need either.

I guess the current static analyzers just look to see where READ_ONCE() or
WRITE_ONCE() is used and checks to see if other places have them properly
used. I'm guessing that's where the OP patch came from.

Sounds like we just need a ADD_ONCE() or INC_ONCE() then. Because I am not
taking a

WRITE_ONCE(a, READ_ONCE(a) + 1);

patch that replaces a simple "a++".

-- Steve