Subject: Re: [PATCH 04/33] mm: vmstat: Prepare to protect against concurrent isolated cpuset change

From: Marc Zyngier <[email-masked]>
Date: Mon, 23 Feb 2026 16:09:01 +0000

On Mon, 23 Feb 2026 16:01:03 +0000,
David Lechner <[email-masked]> wrote:
> 
> On 1/1/26 4:13 PM, Frederic Weisbecker wrote:
> > The HK_TYPE_DOMAIN housekeeping cpumask will soon be made modifiable at
> > runtime. In order to synchronize against vmstat workqueue to make sure
> > that no asynchronous vmstat work is pending or executing on a newly made
> > isolated CPU, target and queue a vmstat work under the same RCU read
> > side critical section.
> > 
> > Whenever housekeeping will update the HK_TYPE_DOMAIN cpumask, a vmstat
> > workqueue flush will also be issued in a further change to make sure
> > that no work remains pending after a CPU has been made isolated.
> > 
> > Signed-off-by: Frederic Weisbecker <[email-masked]>
> > ---
> >  mm/vmstat.c | 10 ++++++----
> >  1 file changed, 6 insertions(+), 4 deletions(-)
> > 
> > diff --git a/mm/vmstat.c b/mm/vmstat.c
> > index 65de88cdf40e..ed19c0d42de6 100644
> > --- a/mm/vmstat.c
> > +++ b/mm/vmstat.c
> > @@ -2144,11 +2144,13 @@ static void vmstat_shepherd(struct work_struct *w)
> >  		 * infrastructure ever noticing. Skip regular flushing from vmstat_shepherd
> >  		 * for all isolated CPUs to avoid interference with the isolated workload.
> >  		 */
> > -		if (cpu_is_isolated(cpu))
> > -			continue;
> > +		scoped_guard(rcu) {
> > +			if (cpu_is_isolated(cpu))
> > +				continue;
> 
> I think this might have introduced a bug - or at least an
> unintentional change in the program flow.
> 
> scoped_guard() is implemented using a for loop. Now this continue
> statement will only exit the scoped_guard() scope rather than
> continuing the outer for loop. This means that cond_resched() will
> be called when it previously was not.

Yup, I've been bitten by that once before. It lead to very subtle
breakage that took me a while to figure out. I've now mentally
banished the use of scoped_guard() inside any form of loop, but that's
a pretty brittle strategy...

	M.

-- 
Without deviation from the norm, progress is not possible.