Skip to content

atomic: Fixes to smp_mb__{before,after}_atomic() and mips.

Peter Zijlstra lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest4 patches 8 repliesIn review
  2. v1 RFC5 patches 25 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4mips/atomic: Fix cmpxchg64 barriersarch/mips/include/asm/cmpxchg.h+5 -20 replies
2/4mips/atomic: Fix loongson_llsc_mb() wreckagearch/mips/include/asm/atomic.h arch/mips/include/asm/barrier.h arch/mips/include/asm/bitops.h +2 more+32 -160 replies
3/4mips/atomic: Fix smp_mb__{before,after}_atomic()arch/mips/include/asm/atomic.h arch/mips/include/asm/barrier.h arch/mips/include/asm/bitops.h +1 more+45 -290 replies
4/4x86/atomic: Fix smp_mb__{before,after}_atomic()Documentation/atomic_t.txt arch/x86/include/asm/atomic.h arch/x86/include/asm/atomic64_64.h +1 more+13 -101 reply

Reviews trailers per patch

1 of 4 patches has a Reviewed-by or Acked-by.

PatchWill Deacon
1/4
2/4
3/4
4/4A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

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

Hi,

This all started when Andrea Parri found a 'surprising' behaviour for x86:

http://lkml.kernel.org/r/20190418125412.GA10817@andrea

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:

	atomic_inc(u);
	*x = 1;
	smp_mb__after_atomic();
	r0 = *y;

Which the CPU is then allowed to re-order (under TSO rules) like:

	atomic_inc(u);
	r0 = *y;
	*x = 1;

And this very much was not intended.

This had me audit all the (strong) architectures that had weak smp_mb__{before,after}_atomic: ia64, mips, sparc, s390, x86, xtensa.

Of those, only x86 and mips were affected. Looking at MIPS to solve this, led to the other MIPS patches.

All these patches have been through 0day for quite a while.

Paul, how do you want to route the MIPS bits?