Ilya Leoshkevich <iii@xxxxxxxxxxxxx> writes: > BPF_ATOMIC_OP() macro documentation states that "BPF_ADD | BPF_FETCH" > should be the same as atomic_fetch_add(), which is currently not the > case on s390x: the serialization instruction "bcr 14,0" is missing. > This applies to "and", "or" and "xor" variants too. > > s390x is allowed to reorder stores with subsequent fetches from > different addresses, so code relying on BPF_FETCH acting as a barrier, > for example: > > stw [%r0], 1 > afadd [%r1], %r2 > ldxw %r3, [%r4] > > may be broken. Fix it by emitting "bcr 14,0". > > Note that a separate serialization instruction is not needed for > BPF_XCHG and BPF_CMPXCHG, because COMPARE AND SWAP performs > serialization itself. > > Fixes: ba3b86b9cef0 ("s390/bpf: Implement new atomic ops") > Reported-by: Puranjay Mohan <puranjay12@xxxxxxxxx> > Closes: https://lore.kernel.org/bpf/mb61p34qvq3wf.fsf@xxxxxxxxxx/ > Signed-off-by: Ilya Leoshkevich <iii@xxxxxxxxxxxxx> Reviewed-by: Puranjay Mohan <puranjay@xxxxxxxxxx> Thanks, Puranjay