Skip to content

Commit 3c6b0c1

Browse files
Sebastian Andrzej Siewiorneeraju
authored andcommitted
srcu: Use try-lock lockdep annotation for NMI-safe access.
It is claimed that srcu_read_lock_nmisafe() NMI-safe. However it triggers a lockdep if used from NMI because lockdep expects a deadlock since nothing disables NMIs while the lock is acquired. This is because commit f0f4475 ("rcu: Annotate SRCU's update-side lockdep dependencies") annotates synchronize_srcu() as a write lock usage. This helps to detect a deadlocks such as srcu_read_lock(); synchronize_srcu(); srcu_read_unlock(); The side effect is that the lock srcu_struct now has a USED usage in normal contexts, so it conflicts with a USED_READ usage in NMI. But this shouldn't cause a real deadlock because the write lock usage from synchronize_srcu() is a fake one and only used for read/write deadlock detection. Use a try-lock annotation for srcu_read_lock_nmisafe() to avoid lockdep complains if used from NMI. Fixes: f0f4475 ("rcu: Annotate SRCU's update-side lockdep dependencies") Link: https://lore.kernel.org/r/20230927160231.XRCDDSK4@linutronix.de Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Paul E. McKenney <paulmck@kernel.org> Signed-off-by: Neeraj Upadhyay (AMD) <neeraj.iitr10@gmail.com>
1 parent c21357e commit 3c6b0c1

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

include/linux/rcupdate.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ static inline void rcu_lock_acquire(struct lockdep_map *map)
301301
lock_acquire(map, 0, 0, 2, 0, NULL, _THIS_IP_);
302302
}
303303

304+
static inline void rcu_try_lock_acquire(struct lockdep_map *map)
305+
{
306+
lock_acquire(map, 0, 1, 2, 0, NULL, _THIS_IP_);
307+
}
308+
304309
static inline void rcu_lock_release(struct lockdep_map *map)
305310
{
306311
lock_release(map, _THIS_IP_);
@@ -315,6 +320,7 @@ int rcu_read_lock_any_held(void);
315320
#else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
316321

317322
# define rcu_lock_acquire(a) do { } while (0)
323+
# define rcu_try_lock_acquire(a) do { } while (0)
318324
# define rcu_lock_release(a) do { } while (0)
319325

320326
static inline int rcu_read_lock_held(void)

include/linux/srcu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ static inline int srcu_read_lock_nmisafe(struct srcu_struct *ssp) __acquires(ssp
229229

230230
srcu_check_nmi_safety(ssp, true);
231231
retval = __srcu_read_lock_nmisafe(ssp);
232-
rcu_lock_acquire(&ssp->dep_map);
232+
rcu_try_lock_acquire(&ssp->dep_map);
233233
return retval;
234234
}
235235

0 commit comments

Comments
 (0)