Skip to content

Commit f05eda1

Browse files
yanzhao56sean-jc
authored andcommitted
srcu: Add an API for a memory barrier after SRCU read lock
To avoid redundant memory barriers, add smp_mb__after_srcu_read_lock() to pair with smp_mb__after_srcu_read_unlock() for use in paths that need to emit a memory barrier, but already do srcu_read_lock(), which includes a full memory barrier. Provide an API, e.g. as opposed to having callers document the behavior via a comment, as the full memory barrier provided by srcu_read_lock() is an implementation detail that shouldn't bleed into random subsystems. KVM will use smp_mb__after_srcu_read_lock() in it's VM-Exit path to ensure a memory barrier is emitted, which is necessary to ensure correctness of mixed memory types on CPUs that support self-snoop. Cc: Paolo Bonzini <[email protected]> Cc: Sean Christopherson <[email protected]> Cc: Kevin Tian <[email protected]> Signed-off-by: Yan Zhao <[email protected]> [sean: massage changelog] Tested-by: Xiangfei Ma <[email protected]> Tested-by: Yongwei Ma <[email protected]> Reviewed-by: Paul E. McKenney <[email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent e154808 commit f05eda1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

include/linux/srcu.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,20 @@ static inline void smp_mb__after_srcu_read_unlock(void)
343343
/* __srcu_read_unlock has smp_mb() internally so nothing to do here. */
344344
}
345345

346+
/**
347+
* smp_mb__after_srcu_read_lock - ensure full ordering after srcu_read_lock
348+
*
349+
* Converts the preceding srcu_read_lock into a two-way memory barrier.
350+
*
351+
* Call this after srcu_read_lock, to guarantee that all memory operations
352+
* that occur after smp_mb__after_srcu_read_lock will appear to happen after
353+
* the preceding srcu_read_lock.
354+
*/
355+
static inline void smp_mb__after_srcu_read_lock(void)
356+
{
357+
/* __srcu_read_lock has smp_mb() internally so nothing to do here. */
358+
}
359+
346360
DEFINE_LOCK_GUARD_1(srcu, struct srcu_struct,
347361
_T->idx = srcu_read_lock(_T->lock),
348362
srcu_read_unlock(_T->lock, _T->idx),

0 commit comments

Comments
 (0)