Skip to contentSkip to conversation

rculist: Add brackets around cond argument in __list_check_rcu macro

PATCH Applied Amol Grover 3 participants 3 messages Jan 18, 2020 – Jan 21, 2020 RCU

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rculist: Add brackets around cond argument in __list_check_rcu macro

Passing a complex lockdep condition to __list_check_rcu results in false positive lockdep splat due to incorrect expression evaluation.

For example, a lockdep check condition cond1 || cond2 is evaluated as !cond1 || cond2 && !rcu_read_lock_any_held() which, according to operator precedence, evaluates to !cond1 || (cond2 && !rcu_read_lock_any_held()). This would result in a lockdep splat when cond1 is false and cond2 is true which is logically incorrect.

---
 include/linux/rculist.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/rculist.h +2 -2
index 4158b7212936..dce491f0b354 100644
@@ -50,9 +50,9 @@ static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
 #define __list_check_rcu(dummy, cond, extra...)				\
 	({								\
 	check_arg_count_one(extra);					\
-	RCU_LOCKDEP_WARN(!cond && !rcu_read_lock_any_held(),		\
+	RCU_LOCKDEP_WARN(!(cond) && !rcu_read_lock_any_held(),		\
 			 "RCU-list traversed in non-reader section!");	\
-	 })
+	})
 #else
 #define __list_check_rcu(dummy, cond, extra...)				\
 	({ check_arg_count_one(extra); })
Signature · 1 line
2.24.1
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Amol Grover

Passing a complex lockdep condition to __list_check_rcu results in false positive lockdep splat due to incorrect expression evaluation.

Quoted 8 lines

For example, a lockdep check condition cond1 || cond2 is evaluated as !cond1 || cond2 && !rcu_read_lock_any_held() which, according to operator precedence, evaluates to !cond1 || (cond2 && !rcu_read_lock_any_held()). This would result in a lockdep splat when cond1 is false and cond2 is true which is logically incorrect.

Good catch!

thanks,

- Joel

Quoted 23 lines
---
 include/linux/rculist.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/rculist.h +2 -2
index 4158b7212936..dce491f0b354 100644
@@ -50,9 +50,9 @@ static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
 #define __list_check_rcu(dummy, cond, extra...)				\
 	({								\
 	check_arg_count_one(extra);					\
-	RCU_LOCKDEP_WARN(!cond && !rcu_read_lock_any_held(),		\
+	RCU_LOCKDEP_WARN(!(cond) && !rcu_read_lock_any_held(),		\
 			 "RCU-list traversed in non-reader section!");	\
-	 })
+	})
 #else
 #define __list_check_rcu(dummy, cond, extra...)				\
 	({ check_arg_count_one(extra); })
Signature · 1 line
2.24.1
maintainer Applied
#2 lore raw
Quoted 12 lines · Joel Fernandes
Quoted 11 lines · Amol Grover

Passing a complex lockdep condition to __list_check_rcu results in false positive lockdep splat due to incorrect expression evaluation.

For example, a lockdep check condition cond1 || cond2 is evaluated as !cond1 || cond2 && !rcu_read_lock_any_held() which, according to operator precedence, evaluates to !cond1 || (cond2 && !rcu_read_lock_any_held()). This would result in a lockdep splat when cond1 is false and cond2 is true which is logically incorrect.

Quoted 5 lines
Quoted 1 line

Good catch!

Queued for v5.7, thank you both!

Thanx, Paul

Quoted 28 lines

thanks,

- Joel

Quoted 23 lines
---
 include/linux/rculist.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/rculist.h +2 -2
index 4158b7212936..dce491f0b354 100644
@@ -50,9 +50,9 @@ static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
 #define __list_check_rcu(dummy, cond, extra...)				\
 	({								\
 	check_arg_count_one(extra);					\
-	RCU_LOCKDEP_WARN(!cond && !rcu_read_lock_any_held(),		\
+	RCU_LOCKDEP_WARN(!(cond) && !rcu_read_lock_any_held(),		\
 			 "RCU-list traversed in non-reader section!");	\
-	 })
+	})
 #else
 #define __list_check_rcu(dummy, cond, extra...)				\
 	({ check_arg_count_one(extra); })
Signature · 1 line
2.24.1