diff mbox series

sched: Assert for_each_thread() is properly locked

Message ID 20230821134428.2504912-1-willy@infradead.org (mailing list archive)
State Accepted
Commit 4de7b17fd05d03fa919e8c47fc66122bd24d7b6c
Headers show
Series sched: Assert for_each_thread() is properly locked | expand

Commit Message

Matthew Wilcox Aug. 21, 2023, 1:44 p.m. UTC
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.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/sched/signal.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Joel Fernandes Aug. 21, 2023, 5:55 p.m. UTC | #1
On Mon, Aug 21, 2023 at 02:44:28PM +0100, Matthew Wilcox (Oracle) wrote:
> 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.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>

Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>

thanks,

 - Joel


> ---
>  include/linux/sched/signal.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h
> index 669e8cff40c7..f1eae7f53be9 100644
> --- a/include/linux/sched/signal.h
> +++ b/include/linux/sched/signal.h
> @@ -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)
> -- 
> 2.40.1
>
diff mbox series

Patch

diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h
index 669e8cff40c7..f1eae7f53be9 100644
--- a/include/linux/sched/signal.h
+++ b/include/linux/sched/signal.h
@@ -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)