From 166485c3d38dd51a1a9a35edb7b2d3c1054a2418 Mon Sep 17 00:00:00 2001 From: Sebastian Andrzej Siewior Date: Tue, 19 Nov 2019 09:25:04 +0100 Subject: [PATCH 228/323] locking: Make spinlock_t and rwlock_t a RCU section on RT Origin: https://www.kernel.org/pub/linux/kernel/projects/rt/5.10/older/patches-5.10.204-rt100.tar.xz On !RT a locked spinlock_t and rwlock_t disables preemption which implies a RCU read section. There is code that relies on that behaviour. Add an explicit RCU read section on RT while a sleeping lock (a lock which would disables preemption on !RT) acquired. Signed-off-by: Sebastian Andrzej Siewior --- kernel/locking/rtmutex.c | 6 ++++++ kernel/locking/rwlock-rt.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c index 2fe178651254..31b374d36d04 100644 --- a/kernel/locking/rtmutex.c +++ b/kernel/locking/rtmutex.c @@ -1136,6 +1136,7 @@ void __lockfunc rt_spin_lock(spinlock_t *lock) { spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock); + rcu_read_lock(); migrate_disable(); } EXPORT_SYMBOL(rt_spin_lock); @@ -1150,6 +1151,7 @@ void __lockfunc rt_spin_lock_nested(spinlock_t *lock, int subclass) { spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_); rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock); + rcu_read_lock(); migrate_disable(); } EXPORT_SYMBOL(rt_spin_lock_nested); @@ -1159,6 +1161,7 @@ void __lockfunc rt_spin_lock_nest_lock(spinlock_t *lock, { spin_acquire_nest(&lock->dep_map, 0, 0, nest_lock, _RET_IP_); rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock); + rcu_read_lock(); migrate_disable(); } EXPORT_SYMBOL(rt_spin_lock_nest_lock); @@ -1169,6 +1172,7 @@ void __lockfunc rt_spin_unlock(spinlock_t *lock) /* NOTE: we always pass in '1' for nested, for simplicity */ spin_release(&lock->dep_map, _RET_IP_); migrate_enable(); + rcu_read_unlock(); rt_spin_lock_fastunlock(&lock->lock, rt_spin_lock_slowunlock); } EXPORT_SYMBOL(rt_spin_unlock); @@ -1198,6 +1202,7 @@ int __lockfunc rt_spin_trylock(spinlock_t *lock) ret = __rt_mutex_trylock(&lock->lock); if (ret) { spin_acquire(&lock->dep_map, 0, 1, _RET_IP_); + rcu_read_lock(); migrate_disable(); } return ret; @@ -1212,6 +1217,7 @@ int __lockfunc rt_spin_trylock_bh(spinlock_t *lock) ret = __rt_mutex_trylock(&lock->lock); if (ret) { spin_acquire(&lock->dep_map, 0, 1, _RET_IP_); + rcu_read_lock(); migrate_disable(); } else { local_bh_enable(); diff --git a/kernel/locking/rwlock-rt.c b/kernel/locking/rwlock-rt.c index 16be7111aae7..3d2d1f14b513 100644 --- a/kernel/locking/rwlock-rt.c +++ b/kernel/locking/rwlock-rt.c @@ -270,6 +270,7 @@ int __lockfunc rt_read_trylock(rwlock_t *rwlock) ret = __read_rt_trylock(rwlock); if (ret) { rwlock_acquire_read(&rwlock->dep_map, 0, 1, _RET_IP_); + rcu_read_lock(); migrate_disable(); } return ret; @@ -283,6 +284,7 @@ int __lockfunc rt_write_trylock(rwlock_t *rwlock) ret = __write_rt_trylock(rwlock); if (ret) { rwlock_acquire(&rwlock->dep_map, 0, 1, _RET_IP_); + rcu_read_lock(); migrate_disable(); } return ret; @@ -293,6 +295,7 @@ void __lockfunc rt_read_lock(rwlock_t *rwlock) { rwlock_acquire_read(&rwlock->dep_map, 0, 0, _RET_IP_); __read_rt_lock(rwlock); + rcu_read_lock(); migrate_disable(); } EXPORT_SYMBOL(rt_read_lock); @@ -301,6 +304,7 @@ void __lockfunc rt_write_lock(rwlock_t *rwlock) { rwlock_acquire(&rwlock->dep_map, 0, 0, _RET_IP_); __write_rt_lock(rwlock); + rcu_read_lock(); migrate_disable(); } EXPORT_SYMBOL(rt_write_lock); @@ -309,6 +313,7 @@ void __lockfunc rt_read_unlock(rwlock_t *rwlock) { rwlock_release(&rwlock->dep_map, _RET_IP_); migrate_enable(); + rcu_read_unlock(); __read_rt_unlock(rwlock); } EXPORT_SYMBOL(rt_read_unlock); @@ -317,6 +322,7 @@ void __lockfunc rt_write_unlock(rwlock_t *rwlock) { rwlock_release(&rwlock->dep_map, _RET_IP_); migrate_enable(); + rcu_read_unlock(); __write_rt_unlock(rwlock); } EXPORT_SYMBOL(rt_write_unlock); -- 2.43.0