[PATCH v4 14/15] lib: convert process iterator to for_each_process_rculock

Oleg Nesterov oleg at redhat.com
Mon Sep 21 20:12:32 UTC 2026


On 09/21, Ye Liu wrote:
>
> diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
> index 8c98b20bfc41..4e7fe85454ab 100644
> --- a/lib/is_single_threaded.c
> +++ b/lib/is_single_threaded.c
> @@ -26,8 +26,7 @@ bool current_is_single_threaded(void)
>  		return true;
>
>  	ret = false;
> -	rcu_read_lock();
> -	for_each_process(p) {
> +	for_each_process_rculock(p) {
>  		if (unlikely(p->flags & PF_KTHREAD))
>  			continue;
>  		if (unlikely(p == task->group_leader))
> @@ -48,7 +47,5 @@ bool current_is_single_threaded(void)
>  	}
>  	ret = true;
>  found:
> -	rcu_read_unlock();
> -

Reviewed-by: Oleg Nesterov <oleg at redhat.com>



but I think that the "found" label and "int ret" can now be removed,
the for_each_thread() loop can just do

	...
	if (unlikely(t->mm == mm))
		return false;

and current_is_single_threaded() can simply return true after
the main for_each_process_rculock() loop.

But again, I agree with this patch, it looks simple and "obviously correct".
Even if I am right, the simplifications above need a separate change.

Oleg.




More information about the Linux-security-module-archive mailing list