On Sun, Apr 25, 2021 at 06:50:48PM -0700, Bart Van Assche wrote: > On 4/25/21 5:49 PM, Ming Lei wrote: > > On Sun, Apr 25, 2021 at 01:42:59PM -0700, Bart Van Assche wrote: > >> Using cmpxchg() on set->tags[] is only safe if all other set->tags[] > >> accesses are changed into WRITE_ONCE() or READ_ONCE(). > > > > Why? > > > > Semantic of cmpxchg() is to modify value pointed by the address if its > > old value is same with passed 'rq'. That is exactly what we need. > > > > writting 'void *' is always atomic. if someone has touched > > '->rqs[tag]', cmpxchg() won't modify the value. > > WRITE_ONCE() supports data types that have the same size as char, short, > int, long and long long. That includes void *. If writes to these data > types would always be atomic then we wouldn't need the WRITE_ONCE() > macro. OK, then we don't need WRITE_ONCE(), since WRITE on tags->rqs[i] is always atomic. Thanks, Ming