rcu: Create transitive rnp->lock acquisition functions
Providing RCU's memory-ordering guarantees requires that the rcu_node tree's locking provide transitive memory ordering, which the Linux kernel's spinlocks currently do not provide unless smp_mb__after_unlock_lock() is used. Having a separate smp_mb__after_unlock_lock() after each and every lock acquisition is error-prone, hard to read, and a bit annoying, so this commit provides wrapper functions that pull in the smp_mb__after_unlock_lock() invocations. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
This commit is contained in:

committed by
Paul E. McKenney

parent
1ec218373b
commit
2a67e741bb
@@ -664,3 +664,42 @@ static inline void rcu_nocb_q_lengths(struct rcu_data *rdp, long *ql, long *qll)
|
||||
#else /* #ifdef CONFIG_PPC */
|
||||
#define smp_mb__after_unlock_lock() do { } while (0)
|
||||
#endif /* #else #ifdef CONFIG_PPC */
|
||||
|
||||
/*
|
||||
* Wrappers for the rcu_node::lock acquire.
|
||||
*
|
||||
* Because the rcu_nodes form a tree, the tree traversal locking will observe
|
||||
* different lock values, this in turn means that an UNLOCK of one level
|
||||
* followed by a LOCK of another level does not imply a full memory barrier;
|
||||
* and most importantly transitivity is lost.
|
||||
*
|
||||
* In order to restore full ordering between tree levels, augment the regular
|
||||
* lock acquire functions with smp_mb__after_unlock_lock().
|
||||
*/
|
||||
static inline void raw_spin_lock_rcu_node(struct rcu_node *rnp)
|
||||
{
|
||||
raw_spin_lock(&rnp->lock);
|
||||
smp_mb__after_unlock_lock();
|
||||
}
|
||||
|
||||
static inline void raw_spin_lock_irq_rcu_node(struct rcu_node *rnp)
|
||||
{
|
||||
raw_spin_lock_irq(&rnp->lock);
|
||||
smp_mb__after_unlock_lock();
|
||||
}
|
||||
|
||||
#define raw_spin_lock_irqsave_rcu_node(rnp, flags) \
|
||||
do { \
|
||||
typecheck(unsigned long, flags); \
|
||||
raw_spin_lock_irqsave(&(rnp)->lock, flags); \
|
||||
smp_mb__after_unlock_lock(); \
|
||||
} while (0)
|
||||
|
||||
static inline bool raw_spin_trylock_rcu_node(struct rcu_node *rnp)
|
||||
{
|
||||
bool locked = raw_spin_trylock(&rnp->lock);
|
||||
|
||||
if (locked)
|
||||
smp_mb__after_unlock_lock();
|
||||
return locked;
|
||||
}
|
||||
|
Reference in New Issue
Block a user