Re: [RFC] WRITE_ONCE_INC() and friends

From: Petko Manolov
Date: Sun Apr 19 2020 - 14:30:05 EST


On 20-04-19 18:02:50, David Laight wrote:
> From: Petko Manolov
> > Sent: 19 April 2020 10:45
> > Recently I started reading up on KCSAN and at some point I ran into stuff like:
> >
> > WRITE_ONCE(ssp->srcu_lock_nesting[idx], ssp->srcu_lock_nesting[idx] + 1);
> > WRITE_ONCE(p->mm->numa_scan_seq, READ_ONCE(p->mm->numa_scan_seq) + 1);
>
> If all the accesses use READ/WRITE_ONCE() why not just mark the structure
> field 'volatile'?

This is a bit heavy. I guess you've read this one:

https://lwn.net/Articles/233479/

And no, i am not sure all accesses are through READ/WRITE_ONCE(). If, for
example, all others are from withing spin_lock/unlock pairs then we _may_ not
need READ/WRITE_ONCE().

I merely proposed the _INC() variant for better readability.


Petko