Lockdep-RCU updates for v5.11
Subsystems (5)
Paul E. McKenney
maintainercover Lockdep-RCU updates for v5.11
Hello!
This series simplifies use of the lockdep-RCU API, all courtesy of Jakub Kicinski:
1. Un-hide lockdep_tasklist_lock_is_held() for !LOCKDEP.
2. Un-hide RCU lockdep maps for !LOCKDEP.
3. Un-hide networking lockdep_sock_is_held() for !LOCKDEP.
4. Remove broken definitions in sched and un-hide for !LOCKDEP.
5. Use a more appropriate lockdep helper in SRCU.
6. Provide dummy forward declaration of *_is_held() helpers.
7. Prevent RCU_LOCKDEP_WARN() from swallowing the condition.
Thanx, Paul
------------------------------------------------------------------------
include/linux/lockdep.h | 6 ++++++ include/linux/rcupdate.h | 11 ++++++----- include/linux/rcupdate_trace.h | 4 ++-- include/linux/sched/task.h | 2 -- include/net/sch_generic.h | 12 ------------ include/net/sock.h | 2 -- kernel/rcu/srcutree.c | 2 +- 7 files changed, 15 insertions(+), 24 deletions(-)
[email protected]
maintainerPATCH 1/7 sched: Un-hide lockdep_tasklist_lock_is_held() for !LOCKDEP
From: Jakub Kicinski <[email protected]>
Currently, variables used only within lockdep expressions are flagged as unused, requiring that these variables' declarations be decorated with either #ifdef or __maybe_unused. This results in ugly code. This commit therefore causes the lockdep_tasklist_lock_is_held() function to be visible even when lockdep is not enabled, thus removing the need for these decorations. This approach further relies on dead-code elimination to remove any references to functions or variables that are not available in non-lockdep kernels.
--- include/linux/sched/task.h | 2 -- 1 file changed, 2 deletions(-)
include/linux/sched/task.h +0 -2
@@ -47,9 +47,7 @@ extern spinlock_t mmlist_lock;extern union thread_union init_thread_union;extern struct task_struct init_task; -#ifdef CONFIG_PROVE_RCU extern int lockdep_tasklist_lock_is_held (void ); -#endif /* #ifdef CONFIG_PROVE_RCU */ extern asmlinkage void schedule_tail(struct task_struct *prev);extern void init_idle (struct task_struct *idle,int cpu);
Signature · 1 line
2.9.5
[email protected]
maintainerPATCH 2/7 rcu: Un-hide lockdep maps for !LOCKDEP
In reply to Paul E. McKenneyFrom: Jakub Kicinski <[email protected]>
Currently, variables used only within lockdep expressions are flagged as unused, requiring that these variables' declarations be decorated with either #ifdef or __maybe_unused. This results in ugly code. This commit therefore causes the RCU lock maps to be visible even when lockdep is not enabled, thus removing the need for these decorations. This approach further relies on dead-code elimination to remove any references to functions or variables that are not available in non-lockdep kernels.
--- include/linux/rcupdate.h | 9 +++++---- include/linux/rcupdate_trace.h | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-)
include/linux/rcupdate.h +5 -4
@@ -241,6 +241,11 @@ bool rcu_lockdep_current_cpu_online(void);static inline bool rcu_lockdep_current_cpu_online (void ) {return true; }#endif /* #else #if defined(CONFIG_HOTPLUG_CPU) && defined(CONFIG_PROVE_RCU) */ +extern struct lockdep_map rcu_lock_map; +extern struct lockdep_map rcu_bh_lock_map; +extern struct lockdep_map rcu_sched_lock_map; +extern struct lockdep_map rcu_callback_map; +#ifdef CONFIG_DEBUG_LOCK_ALLOC static inline void rcu_lock_acquire (struct lockdep_map *map)
@@ -253,10 +258,6 @@ static inline void rcu_lock_release(struct lockdep_map *map)lock_release (map, _THIS_IP_); } -extern struct lockdep_map rcu_lock_map; -extern struct lockdep_map rcu_bh_lock_map; -extern struct lockdep_map rcu_sched_lock_map; -extern struct lockdep_map rcu_callback_map;int debug_lockdep_rcu_enabled (void );int rcu_read_lock_held (void );int rcu_read_lock_bh_held (void );
include/linux/rcupdate_trace.h +2 -2
@@ -11,10 +11,10 @@#include <linux/sched.h> #include <linux/rcupdate.h> -#ifdef CONFIG_DEBUG_LOCK_ALLOC -extern struct lockdep_map rcu_trace_lock_map; +#ifdef CONFIG_DEBUG_LOCK_ALLOC +static inline int rcu_read_lock_trace_held (void ) {return lock_is_held (&rcu_trace_lock_map);
Signature · 1 line
2.9.5
[email protected]
maintainerPATCH 3/7 net: Un-hide lockdep_sock_is_held() for !LOCKDEP
In reply to Paul E. McKenneyFrom: Jakub Kicinski <[email protected]>
Currently, variables used only within lockdep expressions are flagged as unused, requiring that these variables' declarations be decorated with either #ifdef or __maybe_unused. This results in ugly code. This commit therefore causes the lockdep_sock_is_held() function to be visible even when lockdep is not enabled, thus removing the need for these decorations. This approach further relies on dead-code elimination to remove any references to functions or variables that are not available in non-lockdep kernels.
--- include/net/sock.h | 2 -- 1 file changed, 2 deletions(-)
include/net/sock.h +0 -2
@@ -1566,13 +1566,11 @@ do { \lockdep_init_map (&(sk)->sk_lock.dep_map, (name), (key),0 ); \ }while (0 ) -#ifdef CONFIG_LOCKDEP static inline bool lockdep_sock_is_held(const struct sock *sk) {return lockdep_is_held (&sk->sk_lock) ||lockdep_is_held (&sk->sk_lock.slock); } -#endif void lock_sock_nested (struct sock *sk,int subclass);
Signature · 1 line
2.9.5
[email protected]
maintainerPATCH 4/7 net: sched: Remove broken definitions and un-hide for !LOCKDEP
In reply to Paul E. McKenneyFrom: Jakub Kicinski <[email protected]>
Currently, variables used only within lockdep expressions are flagged as unused, requiring that these variables' declarations be decorated with either #ifdef or __maybe_unused. This results in ugly code. This commit therefore causes the full definitions of the lockdep_tcf_chain_is_locked() and lockdep_tcf_proto_is_locked() functions to be visible even when lockdep is not enabled, thus removing the need for the previous empty functions that were provided in non-lockdep kernels. This approach further relies on dead-code elimination to remove any references to functions or variables that are not available in non-lockdep kernels.
--
--- include/net/sch_generic.h | 12 ------------ 1 file changed, 12 deletions(-)
include/net/sch_generic.h +0 -12
@@ -435,7 +435,6 @@ struct tcf_block {struct mutex proto_destroy_lock;/* Lock for proto_destroy hashtable. */ }; -#ifdef CONFIG_PROVE_LOCKING static inline bool lockdep_tcf_chain_is_locked (struct tcf_chain *chain) {return lockdep_is_held (&chain->filter_chain_lock);
@@ -445,17 +444,6 @@ static inline bool lockdep_tcf_proto_is_locked(struct tcf_proto *tp) {return lockdep_is_held (&tp->lock); } -#else -static inline bool lockdep_tcf_chain_is_locked (struct tcf_block *chain) -{ -return true; -} - -static inline bool lockdep_tcf_proto_is_locked (struct tcf_proto *tp) -{ -return true; -} -#endif /* #ifdef CONFIG_PROVE_LOCKING */ #define tcf_chain_dereference (p, chain) \ rcu_dereference_protected(p, lockdep_tcf_chain_is_locked(chain))
Signature · 1 line
2.9.5
[email protected]
maintainerPATCH 5/7 srcu: Use a more appropriate lockdep helper
In reply to Paul E. McKenneyFrom: Jakub Kicinski <[email protected]>
The lockdep_is_held() macro is defined as:
#define lockdep_is_held(lock) lock_is_held(&(lock)->dep_map)
This hides away the dereference, so that builds with !LOCKDEP don't break. This works in current kernels because the RCU_LOCKDEP_WARN() eliminates its condition at preprocessor time in !LOCKDEP kernels. However, later patches in this series will cause the compiler to see this condition even in !LOCKDEP kernels. This commit prepares for this upcoming change by switching from lock_is_held() to lockdep_is_held().
--
--- kernel/rcu/srcutree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/srcutree.c +1 -1
@@ -906,7 +906,7 @@ static void __synchronize_srcu(struct srcu_struct *ssp, bool do_norm) {struct rcu_synchronize rcu; - RCU_LOCKDEP_WARN(lock_is_held(&ssp->dep_map) || + RCU_LOCKDEP_WARN(lockdep_is_held(ssp) || lock_is_held(&rcu_bh_lock_map) || lock_is_held(&rcu_lock_map) || lock_is_held(&rcu_sched_lock_map),
Signature · 1 line
2.9.5
[email protected]
maintainerPATCH 6/7 lockdep: Provide dummy forward declaration of *_is_held() helpers
In reply to Paul E. McKenneyFrom: Jakub Kicinski <[email protected]>
When CONFIG_LOCKDEP is not set, lock_is_held() and lockdep_is_held() are not declared or defined. This forces all callers to use #ifdefs around these checks.
Recent RCU changes added a lot of lockdep_is_held() calls inside rcu_dereference_protected(). This macro hides its argument on !LOCKDEP builds, which can lead to false-positive unused-variable warnings.
This commit therefore provides forward declarations of lock_is_held() and lockdep_is_held() but without defining them. This way callers (including those internal to RCU) can keep them visible to the compiler on !LOCKDEP builds and instead depend on dead code elimination to remove the references, which in turn prevents the linker from complaining about the lack of the corresponding function definitions.
--
--- include/linux/lockdep.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/linux/lockdep.h +6 -0
@@ -375,6 +375,12 @@ static inline void lockdep_unregister_key(struct lock_class_key *key)#define lockdep_depth (tsk) (0) +/* +* Dummy forward declarations, allow users to write less ifdef-y code +* and depend on dead code elimination. +*/ +extern int lock_is_held (const void *); +extern int lockdep_is_held (const void *);#define lockdep_is_held_type (l, r) (1)#define lockdep_assert_held (l) do { (void)(l); } while (0)
Signature · 1 line
2.9.5
[email protected]
maintainerPATCH 7/7 rcu: Prevent RCU_LOCKDEP_WARN() from swallowing the condition
In reply to Paul E. McKenneyFrom: Jakub Kicinski <[email protected]>
We run into a unused variable warning in bridge code when variable is only used inside the condition of rcu_dereference_protected().
#define mlock_dereference(X, br) \ rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock))
Since on builds with CONFIG_PROVE_RCU=n rcu_dereference_protected() compiles to nothing the compiler doesn't see the variable use.
This commit therefore prevents this warning by adding the condition as dead code.
--
--- include/linux/rcupdate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/rcupdate.h +1 -1
@@ -328,7 +328,7 @@ static inline void rcu_preempt_sleep_check(void) { }#else /* #ifdef CONFIG_PROVE_RCU */ -#define RCU_LOCKDEP_WARN (c, s) do { } while (0) +#define RCU_LOCKDEP_WARN (c, s) do { } while (0 && (c))#define rcu_sleep_check () do { } while (0)#endif /* #else #ifdef CONFIG_PROVE_RCU */
Signature · 1 line
2.9.5