Skip to contentSkip to conversation

sched: Assert for_each_thread() is properly locked

PATCH Applied Matthew Wilcox (Oracle) 3 participants 3 messages Aug 21, 2023 – Sep 15, 2023 RCU

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched: Assert for_each_thread() is properly locked

list_for_each_entry_rcu() takes an optional fourth argument which allows RCU to assert that the correct lock is held. Several callers of for_each_thread() rely on their caller to be holding the appropriate lock, so this is a useful assertion to include.

---
 include/linux/sched/signal.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/sched/signal.h +2 -1
index 669e8cff40c7..f1eae7f53be9 100644
@@ -659,7 +659,8 @@ extern bool current_is_single_threaded(void);
 	while ((t = next_thread(t)) != g)
 
 #define __for_each_thread(signal, t)	\
-	list_for_each_entry_rcu(t, &(signal)->thread_head, thread_node)
+	list_for_each_entry_rcu(t, &(signal)->thread_head, thread_node, \
+		lockdep_is_held(&tasklist_lock))
 
 #define for_each_thread(p, t)		\
 	__for_each_thread((p)->signal, t)
Signature · 1 line
2.40.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Matthew Wilcox (Oracle)

list_for_each_entry_rcu() takes an optional fourth argument which allows RCU to assert that the correct lock is held. Several callers of for_each_thread() rely on their caller to be holding the appropriate lock, so this is a useful assertion to include.

thanks,

- Joel

Quoted 21 lines
---
 include/linux/sched/signal.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/sched/signal.h +2 -1
index 669e8cff40c7..f1eae7f53be9 100644
@@ -659,7 +659,8 @@ extern bool current_is_single_threaded(void);
 	while ((t = next_thread(t)) != g)
 
 #define __for_each_thread(signal, t)	\
-	list_for_each_entry_rcu(t, &(signal)->thread_head, thread_node)
+	list_for_each_entry_rcu(t, &(signal)->thread_head, thread_node, \
+		lockdep_is_held(&tasklist_lock))
 
 #define for_each_thread(p, t)		\
 	__for_each_thread((p)->signal, t)
Signature · 1 line
2.40.1
#2 lore raw
In reply to Matthew Wilcox (Oracle)
The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     4de7b17fd05d03fa919e8c47fc66122bd24d7b6c
Gitweb:        https://git.kernel.org/tip/4de7b17fd05d03fa919e8c47fc66122bd24d7b6c
Author:        Matthew Wilcox (Oracle) <[email protected]>
AuthorDate:    Mon, 21 Aug 2023 14:44:28 +01:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 15 Sep 2023 10:33:29 +02:00

sched: Assert for_each_thread() is properly locked

list_for_each_entry_rcu() takes an optional fourth argument which allows RCU to assert that the correct lock is held. Several callers of for_each_thread() rely on their caller to be holding the appropriate lock, so this is a useful assertion to include.

---
 include/linux/sched/signal.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/sched/signal.h +2 -1
index 0014d3a..9610bad 100644
@@ -656,7 +656,8 @@ extern bool current_is_single_threaded(void);
 	while ((t = next_thread(t)) != g)
 
 #define __for_each_thread(signal, t)	\
-	list_for_each_entry_rcu(t, &(signal)->thread_head, thread_node)
+	list_for_each_entry_rcu(t, &(signal)->thread_head, thread_node, \
+		lockdep_is_held(&tasklist_lock))
 
 #define for_each_thread(p, t)		\
 	__for_each_thread((p)->signal, t)