]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
smr: Fix synchronization in smr_enter()
authorMark Johnston <markj@FreeBSD.org>
Sat, 24 Sep 2022 13:18:04 +0000 (09:18 -0400)
committerMark Johnston <markj@FreeBSD.org>
Sat, 24 Sep 2022 13:18:04 +0000 (09:18 -0400)
commit8694fd333556addb97acfff1feca6a1e389201ce
tree3ed63c0f8f18f4b1ae211ab83fc5e0f0abbc96ac
parentc2d27b0ec7000d28b4f31148005ccfe371f47db3
smr: Fix synchronization in smr_enter()

smr_enter() must publish its observed read sequence number before
issuing any subsequent memory operations.  The ordering provided by
atomic_add_acq_int() is insufficient on some platforms, at least on
arm64, because it permits reordering of subsequent loads with the store
to c_seq.

Thus, use atomic_thread_fence_seq_cst() to issue a store-load barrier
after publishing the read sequence number.

On x86, take advantage of the fact that memory operations are not
reordered with locked instructions to improve code density: we can store
the observed read sequence and provide a store-load barrier with a
single operation.

Based on a patch from Pierre Habouzit <pierre@habouzit.net>.

PR: 265974
Reviewed by: alc
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D36370
sys/sys/smr.h