Re: [PATCH v2 0/4] atomic: Fixes to smp_mb__{before,after}_atomic() and mips.

From: David Howells
Date: Thu Jun 13 2019 - 11:07:16 EST


Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:

> Basically we fail for:
>
> *x = 1;
> atomic_inc(u);
> smp_mb__after_atomic();
> r0 = *y;
>
> Because, while the atomic_inc() implies memory order, it
> (surprisingly) does not provide a compiler barrier. This then allows
> the compiler to re-order like so:

To quote memory-barriers.txt:

(*) smp_mb__before_atomic();
(*) smp_mb__after_atomic();

These are for use with atomic (such as add, subtract, increment and
decrement) functions that don't return a value, especially when used for
reference counting. These functions do not imply memory barriers.

so it's entirely to be expected?

David