HomeFreeBSD

smr: Fix synchronization in smr_enter()

Description

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

Details

Provenance
markjAuthored on Sep 24 2022, 1:18 PM
Reviewer
alc
Differential Revision
D36370: smr: Fix synchronization in smr_enter()
Parents
rGc2d27b0ec700: sched_4bsd: Fix a racy thread state modification
Branches
Unknown
Tags
Unknown