Linux filesystem development
 help / color / mirror / Atom feed
* [PATCH 0/8] mm: introduce for_each_process_rcu and for_each_thread_rcu
@ 2026-09-04  8:29 Ye Liu
  2026-09-04  8:29 ` [PATCH 6/8] fs: convert process/thread iterators to for_each_*_rcu Ye Liu
  0 siblings, 1 reply; 10+ messages in thread
From: Ye Liu @ 2026-09-04  8:29 UTC (permalink / raw)
  To: Andrew Morton, Michal Hocko, Peter Zijlstra, Paul E. McKenney,
	Ingo Molnar, Steven Rostedt, Josh Poimboeuf,
	Mickaël Salaün
  Cc: Ye Liu, David Hildenbrand, Miaohe Lin, Naoya Horiguchi,
	Rafael J. Wysocki, linux-mm, linux-kernel, linux-pm, rcu,
	linux-trace-kernel, linux-fsdevel, linux-security-module,
	Günther Noack

From: Ye Liu <liuye@kylinos.cn>

Introduce for_each_process_rcu(), for_each_thread_rcu() and
for_each_process_thread_rcu() macros that combine the existing
iteration macros with scoped_guard(rcu), so that the RCU read lock
is automatically acquired before iteration and released when the
loop exits — including via break, goto, or return.

The rest of the series converts manual rcu_read_lock()/
rcu_read_unlock() and guard(rcu)() pairs across mm/, kernel/, fs/,
lib/ and security/ to use the new macros.

Patch 1 may trigger checkpatch "Macros with complex values should be
enclosed in parentheses" errors.  These are false positives — the
scoped_guard() pattern is a control-flow construct, not a multi-
statement macro, and the same idiom is used elsewhere in the kernel.

Suggested by Michal Hocko for the oom_kill path [1].

[1] https://lore.kernel.org/all/20260813092933.562028-1-ye.liu@linux.dev/

Ye Liu (8):
  mm: introduce for_each_process_rcu and for_each_thread_rcu
  mm/oom_kill: convert process/thread iterators to for_each_*_rcu
  mm/ksm: convert process iterator to for_each_process_rcu
  mm/memory-failure: convert process iterator to for_each_process_rcu
  kernel: convert process/thread iterators to for_each_*_rcu
  fs: convert process/thread iterators to for_each_*_rcu
  lib: convert process iterator to for_each_process_rcu
  security/landlock: convert thread iterator to for_each_thread_rcu

 fs/proc/base.c               |  4 +---
 fs/resctrl/rdtgroup.c        |  8 ++------
 include/linux/sched/signal.h | 19 +++++++++++++++++++
 kernel/cpu.c                 |  4 +---
 kernel/freezer.c             |  4 +---
 kernel/hung_task.c           |  7 ++-----
 kernel/locking/lockdep.c     |  4 +---
 kernel/rcu/update.c          |  4 +---
 kernel/sched/core.c          |  3 +--
 kernel/sched/debug.c         |  4 +---
 kernel/trace/fgraph.c        |  8 ++------
 kernel/unwind/deferred.c     |  3 +--
 lib/is_single_threaded.c     |  5 +----
 mm/ksm.c                     |  4 +---
 mm/memory-failure.c          | 16 ++++------------
 mm/oom_kill.c                | 20 +++++---------------
 security/landlock/tsync.c    |  8 ++------
 17 files changed, 46 insertions(+), 79 deletions(-)

Signed-off-by: Ye Liu <liuye@kylinos.cn>

--
2.25.1

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 6/8] fs: convert process/thread iterators to for_each_*_rcu
  2026-09-04  8:29 [PATCH 0/8] mm: introduce for_each_process_rcu and for_each_thread_rcu Ye Liu
@ 2026-09-04  8:29 ` Ye Liu
  2026-09-04  9:05   ` Oleg Nesterov
                     ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Ye Liu @ 2026-09-04  8:29 UTC (permalink / raw)
  To: Tony Luck, Reinette Chatre, x86, Christian Brauner, Andrew Morton,
	Jann Horn, David Hildenbrand (arm), Mike Rapoport (Microsoft),
	Alexey Dobriyan, Lorenzo Stoakes, Oleg Nesterov
  Cc: Ye Liu, Dave Martin, James Morse, Babu Moger, linux-kernel,
	linux-fsdevel

From: Ye Liu <liuye@kylinos.cn>

Replace the manual rcu_read_lock()/rcu_read_unlock() pairs combined
with for_each_process() and for_each_process_thread() loops in fs/
with the for_each_*_rcu() macros.

No functional change.

Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
 fs/proc/base.c        | 4 +---
 fs/resctrl/rdtgroup.c | 8 ++------
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 6a39de424f62..da36ba73dc17 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1160,8 +1160,7 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
 	if (mm) {
 		struct task_struct *p;
 
-		rcu_read_lock();
-		for_each_process(p) {
+		for_each_process_rcu(p) {
 			if (same_thread_group(task, p))
 				continue;
 
@@ -1177,7 +1176,6 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
 			}
 			task_unlock(p);
 		}
-		rcu_read_unlock();
 		mmdrop(mm);
 	}
 err_unlock:
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 5dcbb0a964e8..3f96d21b84ab 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -709,14 +709,12 @@ int rdtgroup_tasks_assigned(struct rdtgroup *r)
 
 	lockdep_assert_held(&rdtgroup_mutex);
 
-	rcu_read_lock();
-	for_each_process_thread(p, t) {
+	for_each_process_thread_rcu(p, t) {
 		if (is_closid_match(t, r) || is_rmid_match(t, r)) {
 			ret = 1;
 			break;
 		}
 	}
-	rcu_read_unlock();
 
 	return ret;
 }
@@ -826,15 +824,13 @@ static void show_rdt_tasks(struct rdtgroup *r, struct seq_file *s)
 	struct task_struct *p, *t;
 	pid_t pid;
 
-	rcu_read_lock();
-	for_each_process_thread(p, t) {
+	for_each_process_thread_rcu(p, t) {
 		if (is_closid_match(t, r) || is_rmid_match(t, r)) {
 			pid = task_pid_vnr(t);
 			if (pid)
 				seq_printf(s, "%d\n", pid);
 		}
 	}
-	rcu_read_unlock();
 }
 
 static int rdtgroup_tasks_show(struct kernfs_open_file *of,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 6/8] fs: convert process/thread iterators to for_each_*_rcu
  2026-09-04  8:29 ` [PATCH 6/8] fs: convert process/thread iterators to for_each_*_rcu Ye Liu
@ 2026-09-04  9:05   ` Oleg Nesterov
  2026-09-04  9:22   ` Lorenzo Stoakes (ARM)
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Oleg Nesterov @ 2026-09-04  9:05 UTC (permalink / raw)
  To: Ye Liu
  Cc: Tony Luck, Reinette Chatre, x86, Christian Brauner, Andrew Morton,
	Jann Horn, David Hildenbrand (arm), Mike Rapoport (Microsoft),
	Alexey Dobriyan, Lorenzo Stoakes, Ye Liu, Dave Martin,
	James Morse, Babu Moger, linux-kernel, linux-fsdevel

On 09/04, Ye Liu wrote:
>
> @@ -1160,8 +1160,7 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
>  	if (mm) {
>  		struct task_struct *p;
>
> -		rcu_read_lock();
> -		for_each_process(p) {
> +		for_each_process_rcu(p) {
>  			if (same_thread_group(task, p))
>  				continue;

Hmm... I am not aware of for_each_process_rcu(), but looking at this
change I guess it includes something like scope_guard(rcu) ?

Perhaps makes sense, but the naming looks sligthly confusing to me.
I mean, to for_each_process_rcu() looks like (say) list_for_each_entry_rcu()
where _rcu has another meaning...

Oleg.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 6/8] fs: convert process/thread iterators to for_each_*_rcu
  2026-09-04  8:29 ` [PATCH 6/8] fs: convert process/thread iterators to for_each_*_rcu Ye Liu
  2026-09-04  9:05   ` Oleg Nesterov
@ 2026-09-04  9:22   ` Lorenzo Stoakes (ARM)
  2026-09-04 11:06   ` Michal Hocko
  2026-09-08 16:45   ` Alexey Dobriyan
  3 siblings, 0 replies; 10+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-09-04  9:22 UTC (permalink / raw)
  To: Ye Liu
  Cc: Tony Luck, Reinette Chatre, x86, Christian Brauner, Andrew Morton,
	Jann Horn, David Hildenbrand (arm), Mike Rapoport (Microsoft),
	Alexey Dobriyan, Oleg Nesterov, Ye Liu, Dave Martin, James Morse,
	Babu Moger, linux-kernel, linux-fsdevel

Please cc everybody on every patch in the series :) it makes it incredible hard
for me to see context otherwise.

I can already see a comment I'd like to leave on another patch in the series but
it's a total pain for me go retrieve that to do it.

And I worry about acking one bit only to find out a horrible flaw in another
part :P

Can you please make sure to do that on any respin?...

On Fri, Sep 04, 2026 at 04:29:58PM +0800, Ye Liu wrote:
> From: Ye Liu <liuye@kylinos.cn>
>
> Replace the manual rcu_read_lock()/rcu_read_unlock() pairs combined
> with for_each_process() and for_each_process_thread() loops in fs/
> with the for_each_*_rcu() macros.

Probably worth mentioning that they hold the RCU lock in a scoped guard over the
operation.

>
> No functional change.
>
> Signed-off-by: Ye Liu <liuye@kylinos.cn>

In general it looks reasonable to me, but I wonder if you're correctly including
linux/cleanup.h to have the scope guard available...

Anyway can check that on respin with the right cc ;)

> ---
>  fs/proc/base.c        | 4 +---
>  fs/resctrl/rdtgroup.c | 8 ++------
>  2 files changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/fs/proc/base.c b/fs/proc/base.c
> index 6a39de424f62..da36ba73dc17 100644
> --- a/fs/proc/base.c
> +++ b/fs/proc/base.c
> @@ -1160,8 +1160,7 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)

Side-note - I wonder if this really belongs in mm/oom_kill.c? Seems really odd
to have it here.

>  	if (mm) {
>  		struct task_struct *p;
>
> -		rcu_read_lock();
> -		for_each_process(p) {
> +		for_each_process_rcu(p) {
>  			if (same_thread_group(task, p))
>  				continue;
>
> @@ -1177,7 +1176,6 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
>  			}
>  			task_unlock(p);
>  		}
> -		rcu_read_unlock();
>  		mmdrop(mm);
>  	}
>  err_unlock:
> diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
> index 5dcbb0a964e8..3f96d21b84ab 100644
> --- a/fs/resctrl/rdtgroup.c
> +++ b/fs/resctrl/rdtgroup.c
> @@ -709,14 +709,12 @@ int rdtgroup_tasks_assigned(struct rdtgroup *r)
>
>  	lockdep_assert_held(&rdtgroup_mutex);
>
> -	rcu_read_lock();
> -	for_each_process_thread(p, t) {
> +	for_each_process_thread_rcu(p, t) {
>  		if (is_closid_match(t, r) || is_rmid_match(t, r)) {
>  			ret = 1;
>  			break;
>  		}
>  	}
> -	rcu_read_unlock();
>
>  	return ret;
>  }
> @@ -826,15 +824,13 @@ static void show_rdt_tasks(struct rdtgroup *r, struct seq_file *s)
>  	struct task_struct *p, *t;
>  	pid_t pid;
>
> -	rcu_read_lock();
> -	for_each_process_thread(p, t) {
> +	for_each_process_thread_rcu(p, t) {
>  		if (is_closid_match(t, r) || is_rmid_match(t, r)) {
>  			pid = task_pid_vnr(t);
>  			if (pid)
>  				seq_printf(s, "%d\n", pid);
>  		}
>  	}
> -	rcu_read_unlock();
>  }
>
>  static int rdtgroup_tasks_show(struct kernfs_open_file *of,
> --
> 2.25.1
>

--
Cheers, Lorenzo

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 6/8] fs: convert process/thread iterators to for_each_*_rcu
  2026-09-04  8:29 ` [PATCH 6/8] fs: convert process/thread iterators to for_each_*_rcu Ye Liu
  2026-09-04  9:05   ` Oleg Nesterov
  2026-09-04  9:22   ` Lorenzo Stoakes (ARM)
@ 2026-09-04 11:06   ` Michal Hocko
  2026-09-08 16:45   ` Alexey Dobriyan
  3 siblings, 0 replies; 10+ messages in thread
From: Michal Hocko @ 2026-09-04 11:06 UTC (permalink / raw)
  To: Ye Liu
  Cc: Tony Luck, Reinette Chatre, x86, Christian Brauner, Andrew Morton,
	Jann Horn, David Hildenbrand (arm), Mike Rapoport (Microsoft),
	Alexey Dobriyan, Lorenzo Stoakes, Oleg Nesterov, Ye Liu,
	Dave Martin, James Morse, Babu Moger, linux-kernel, linux-fsdevel

On Fri 04-09-26 16:29:58, Ye Liu wrote:
> From: Ye Liu <liuye@kylinos.cn>
> 
> Replace the manual rcu_read_lock()/rcu_read_unlock() pairs combined
> with for_each_process() and for_each_process_thread() loops in fs/
> with the for_each_*_rcu() macros.
> 
> No functional change.
> 
> Signed-off-by: Ye Liu <liuye@kylinos.cn>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  fs/proc/base.c        | 4 +---
>  fs/resctrl/rdtgroup.c | 8 ++------
>  2 files changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/fs/proc/base.c b/fs/proc/base.c
> index 6a39de424f62..da36ba73dc17 100644
> --- a/fs/proc/base.c
> +++ b/fs/proc/base.c
> @@ -1160,8 +1160,7 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
>  	if (mm) {
>  		struct task_struct *p;
>  
> -		rcu_read_lock();
> -		for_each_process(p) {
> +		for_each_process_rcu(p) {
>  			if (same_thread_group(task, p))
>  				continue;
>  
> @@ -1177,7 +1176,6 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
>  			}
>  			task_unlock(p);
>  		}
> -		rcu_read_unlock();
>  		mmdrop(mm);
>  	}
>  err_unlock:
> diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
> index 5dcbb0a964e8..3f96d21b84ab 100644
> --- a/fs/resctrl/rdtgroup.c
> +++ b/fs/resctrl/rdtgroup.c
> @@ -709,14 +709,12 @@ int rdtgroup_tasks_assigned(struct rdtgroup *r)
>  
>  	lockdep_assert_held(&rdtgroup_mutex);
>  
> -	rcu_read_lock();
> -	for_each_process_thread(p, t) {
> +	for_each_process_thread_rcu(p, t) {
>  		if (is_closid_match(t, r) || is_rmid_match(t, r)) {
>  			ret = 1;
>  			break;
>  		}
>  	}
> -	rcu_read_unlock();
>  
>  	return ret;
>  }
> @@ -826,15 +824,13 @@ static void show_rdt_tasks(struct rdtgroup *r, struct seq_file *s)
>  	struct task_struct *p, *t;
>  	pid_t pid;
>  
> -	rcu_read_lock();
> -	for_each_process_thread(p, t) {
> +	for_each_process_thread_rcu(p, t) {
>  		if (is_closid_match(t, r) || is_rmid_match(t, r)) {
>  			pid = task_pid_vnr(t);
>  			if (pid)
>  				seq_printf(s, "%d\n", pid);
>  		}
>  	}
> -	rcu_read_unlock();
>  }
>  
>  static int rdtgroup_tasks_show(struct kernfs_open_file *of,
> -- 
> 2.25.1
> 

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 6/8] fs: convert process/thread iterators to for_each_*_rcu
  2026-09-04  8:29 ` [PATCH 6/8] fs: convert process/thread iterators to for_each_*_rcu Ye Liu
                     ` (2 preceding siblings ...)
  2026-09-04 11:06   ` Michal Hocko
@ 2026-09-08 16:45   ` Alexey Dobriyan
  2026-09-08 17:10     ` Lorenzo Stoakes (ARM)
  2026-09-08 17:12     ` Oleg Nesterov
  3 siblings, 2 replies; 10+ messages in thread
From: Alexey Dobriyan @ 2026-09-08 16:45 UTC (permalink / raw)
  To: Ye Liu
  Cc: Tony Luck, Reinette Chatre, x86, Christian Brauner, Andrew Morton,
	Jann Horn, David Hildenbrand (arm), Mike Rapoport (Microsoft),
	Lorenzo Stoakes, Oleg Nesterov, Ye Liu, Dave Martin, James Morse,
	Babu Moger, linux-kernel, linux-fsdevel

On Fri, Sep 04, 2026 at 04:29:58PM +0800, Ye Liu wrote:
> --- a/fs/proc/base.c
> +++ b/fs/proc/base.c
> @@ -1160,8 +1160,7 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
>  	if (mm) {
>  		struct task_struct *p;
>  
> -		rcu_read_lock();
> -		for_each_process(p) {
> +		for_each_process_rcu(p) {
>  			if (same_thread_group(task, p))
>  				continue;
>  
> @@ -1177,7 +1176,6 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
>  			}
>  			task_unlock(p);
>  		}
> -		rcu_read_unlock();
>  		mmdrop(mm);
>  	}
>  err_unlock:

What's going on here?
Now it's RCU unlock after mmdrop().

These scoped guards kind of suck unless you allow infinite line length.

	A

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 6/8] fs: convert process/thread iterators to for_each_*_rcu
  2026-09-08 16:45   ` Alexey Dobriyan
@ 2026-09-08 17:10     ` Lorenzo Stoakes (ARM)
  2026-09-08 17:26       ` Alexey Dobriyan
  2026-09-08 17:12     ` Oleg Nesterov
  1 sibling, 1 reply; 10+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-09-08 17:10 UTC (permalink / raw)
  To: Alexey Dobriyan
  Cc: Ye Liu, Tony Luck, Reinette Chatre, x86, Christian Brauner,
	Andrew Morton, Jann Horn, David Hildenbrand (arm),
	Mike Rapoport (Microsoft), Oleg Nesterov, Ye Liu, Dave Martin,
	James Morse, Babu Moger, linux-kernel, linux-fsdevel

On Tue, Sep 08, 2026 at 07:45:15PM +0300, Alexey Dobriyan wrote:
> On Fri, Sep 04, 2026 at 04:29:58PM +0800, Ye Liu wrote:
> > --- a/fs/proc/base.c
> > +++ b/fs/proc/base.c
> > @@ -1160,8 +1160,7 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
> >  	if (mm) {
> >  		struct task_struct *p;
> >
> > -		rcu_read_lock();
> > -		for_each_process(p) {
> > +		for_each_process_rcu(p) {
> >  			if (same_thread_group(task, p))
> >  				continue;
> >
> > @@ -1177,7 +1176,6 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
> >  			}
> >  			task_unlock(p);
> >  		}
> > -		rcu_read_unlock();
> >  		mmdrop(mm);
> >  	}
> >  err_unlock:
>
> What's going on here?
> Now it's RCU unlock after mmdrop().

No it's not, scoped_guard() is scoped to the for_each_process_rcu() block which
ends before mmdrop(), i.e. the exact same scope as before.

That closing '}' is attached to the if (mm).

>
> These scoped guards kind of suck unless you allow infinite line length.
>
> 	A

--
Cheers, Lorenzo

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 6/8] fs: convert process/thread iterators to for_each_*_rcu
  2026-09-08 16:45   ` Alexey Dobriyan
  2026-09-08 17:10     ` Lorenzo Stoakes (ARM)
@ 2026-09-08 17:12     ` Oleg Nesterov
  1 sibling, 0 replies; 10+ messages in thread
From: Oleg Nesterov @ 2026-09-08 17:12 UTC (permalink / raw)
  To: Alexey Dobriyan
  Cc: Ye Liu, Tony Luck, Reinette Chatre, x86, Christian Brauner,
	Andrew Morton, Jann Horn, David Hildenbrand (arm),
	Mike Rapoport (Microsoft), Lorenzo Stoakes, Ye Liu, Dave Martin,
	James Morse, Babu Moger, linux-kernel, linux-fsdevel

On 09/08, Alexey Dobriyan wrote:
>
> On Fri, Sep 04, 2026 at 04:29:58PM +0800, Ye Liu wrote:
> > --- a/fs/proc/base.c
> > +++ b/fs/proc/base.c
> > @@ -1160,8 +1160,7 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
> >  	if (mm) {
> >  		struct task_struct *p;
> >
> > -		rcu_read_lock();
> > -		for_each_process(p) {
> > +		for_each_process_rcu(p) {
> >  			if (same_thread_group(task, p))
> >  				continue;
> >
> > @@ -1177,7 +1176,6 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
> >  			}
> >  			task_unlock(p);
> >  		}
> > -		rcu_read_unlock();
> >  		mmdrop(mm);
> >  	}
> >  err_unlock:
>
> What's going on here?
> Now it's RCU unlock after mmdrop().

Confused... Why do you think so?

I think mmdrop() is called after rcu_read_unlock(), with or without this change.

No?

Oleg.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 6/8] fs: convert process/thread iterators to for_each_*_rcu
  2026-09-08 17:10     ` Lorenzo Stoakes (ARM)
@ 2026-09-08 17:26       ` Alexey Dobriyan
  2026-09-08 17:41         ` Lorenzo Stoakes (ARM)
  0 siblings, 1 reply; 10+ messages in thread
From: Alexey Dobriyan @ 2026-09-08 17:26 UTC (permalink / raw)
  To: Lorenzo Stoakes (ARM)
  Cc: Ye Liu, Tony Luck, Reinette Chatre, x86, Christian Brauner,
	Andrew Morton, Jann Horn, David Hildenbrand (arm),
	Mike Rapoport (Microsoft), Oleg Nesterov, Ye Liu, Dave Martin,
	James Morse, Babu Moger, linux-kernel, linux-fsdevel

On Tue, Sep 08, 2026 at 06:10:17PM +0100, Lorenzo Stoakes (ARM) wrote:
> On Tue, Sep 08, 2026 at 07:45:15PM +0300, Alexey Dobriyan wrote:
> > On Fri, Sep 04, 2026 at 04:29:58PM +0800, Ye Liu wrote:
> > > --- a/fs/proc/base.c
> > > +++ b/fs/proc/base.c
> > > @@ -1160,8 +1160,7 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
> > >  	if (mm) {
> > >  		struct task_struct *p;
> > >
> > > -		rcu_read_lock();
> > > -		for_each_process(p) {
> > > +		for_each_process_rcu(p) {
> > >  			if (same_thread_group(task, p))
> > >  				continue;
> > >
> > > @@ -1177,7 +1176,6 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
> > >  			}
> > >  			task_unlock(p);
> > >  		}
> > > -		rcu_read_unlock();
> > >  		mmdrop(mm);
> > >  	}
> > >  err_unlock:
> >
> > What's going on here?
> > Now it's RCU unlock after mmdrop().
> 
> No it's not, scoped_guard() is scoped to the for_each_process_rcu() block which
> ends before mmdrop(), i.e. the exact same scope as before.
> 
> That closing '}' is attached to the if (mm).

OK.

I think naming (and macro) are misguided:
* _rcu means "use under RCU section opened elsewhere",
  this one is "I open and close RCU section myself".

* not every 2 lines should be combined into new interface.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 6/8] fs: convert process/thread iterators to for_each_*_rcu
  2026-09-08 17:26       ` Alexey Dobriyan
@ 2026-09-08 17:41         ` Lorenzo Stoakes (ARM)
  0 siblings, 0 replies; 10+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-09-08 17:41 UTC (permalink / raw)
  To: Alexey Dobriyan
  Cc: Ye Liu, Tony Luck, Reinette Chatre, x86, Christian Brauner,
	Andrew Morton, Jann Horn, David Hildenbrand (arm),
	Mike Rapoport (Microsoft), Oleg Nesterov, Ye Liu, Dave Martin,
	James Morse, Babu Moger, linux-kernel, linux-fsdevel

On Tue, Sep 08, 2026 at 08:26:54PM +0300, Alexey Dobriyan wrote:
> On Tue, Sep 08, 2026 at 06:10:17PM +0100, Lorenzo Stoakes (ARM) wrote:
> > On Tue, Sep 08, 2026 at 07:45:15PM +0300, Alexey Dobriyan wrote:
> > > On Fri, Sep 04, 2026 at 04:29:58PM +0800, Ye Liu wrote:
> > > > --- a/fs/proc/base.c
> > > > +++ b/fs/proc/base.c
> > > > @@ -1160,8 +1160,7 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
> > > >  	if (mm) {
> > > >  		struct task_struct *p;
> > > >
> > > > -		rcu_read_lock();
> > > > -		for_each_process(p) {
> > > > +		for_each_process_rcu(p) {
> > > >  			if (same_thread_group(task, p))
> > > >  				continue;
> > > >
> > > > @@ -1177,7 +1176,6 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
> > > >  			}
> > > >  			task_unlock(p);
> > > >  		}
> > > > -		rcu_read_unlock();
> > > >  		mmdrop(mm);
> > > >  	}
> > > >  err_unlock:
> > >
> > > What's going on here?
> > > Now it's RCU unlock after mmdrop().
> >
> > No it's not, scoped_guard() is scoped to the for_each_process_rcu() block which
> > ends before mmdrop(), i.e. the exact same scope as before.
> >
> > That closing '}' is attached to the if (mm).
>
> OK.
>
> I think naming (and macro) are misguided:
> * _rcu means "use under RCU section opened elsewhere",
>   this one is "I open and close RCU section myself".

You're replying to a v1 of a series that has a v2 which changes the naming.

>
> * not every 2 lines should be combined into new interface.

Nobody is suggesting every 2 lines should be combined into a new interface.

They're suggesting that explicitly tying lock lifetime to block scope is a
really good idea.

And having debugged lots of locking issues, I agree.

Anyway the v2 is at:

https://lore.kernel.org/all/20260907081334.1152889-1-ye.liu@linux.dev/


--
Cheers, Lorenzo

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-09-08 17:41 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-04  8:29 [PATCH 0/8] mm: introduce for_each_process_rcu and for_each_thread_rcu Ye Liu
2026-09-04  8:29 ` [PATCH 6/8] fs: convert process/thread iterators to for_each_*_rcu Ye Liu
2026-09-04  9:05   ` Oleg Nesterov
2026-09-04  9:22   ` Lorenzo Stoakes (ARM)
2026-09-04 11:06   ` Michal Hocko
2026-09-08 16:45   ` Alexey Dobriyan
2026-09-08 17:10     ` Lorenzo Stoakes (ARM)
2026-09-08 17:26       ` Alexey Dobriyan
2026-09-08 17:41         ` Lorenzo Stoakes (ARM)
2026-09-08 17:12     ` Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox