From: Yury Norov <ynorov@nvidia.com>
To: Shrikanth Hegde <sshegde@linux.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Thomas Gleixner <tglx@kernel.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Yury Norov <yury.norov@gmail.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Andrea Righi <arighi@nvidia.com>, Ben Segall <bsegall@google.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Danilo Krummrich <dakr@kernel.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Heiko Carstens <hca@linux.ibm.com>,
Ilya Leoshkevich <iii@linux.ibm.com>,
Johan Hovold <johan@kernel.org>, Jonathan Corbet <corbet@lwn.net>,
K Prateek Nayak <kprateek.nayak@amd.com>,
Maxim Kuvyrkov <maxim.kuvyrkov@grdncc.com>,
Mel Gorman <mgorman@suse.de>, Mete Durlu <meted@linux.ibm.com>,
Randy Dunlap <rdunlap@infradead.org>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Shuah Khan <skhan@linuxfoundation.org>,
Steven Rostedt <rostedt@goodmis.org>,
Sven Schnelle <svens@linux.ibm.com>,
Valentin Schneider <vschneid@redhat.com>,
Vasily Gorbik <gor@linux.ibm.com>,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
driver-core@lists.linux.dev, linux-s390@vger.kernel.org
Subject: Re: [PATCH 4/7] virt: steal_governor: serialize sampling against CPU hotplug
Date: Fri, 20 Nov 2026 10:35:01 -0500 [thread overview]
Message-ID: <awBopXdhgUatAU9d@yury> (raw)
In-Reply-To: <38f8999a-f3e1-486f-870b-25710462308e@linux.ibm.com>
On Fri, Nov 20, 2026 at 02:08:59PM +0530, Shrikanth Hegde wrote:
>
>
> On 11/19/26 10:20 PM, Yury Norov wrote:
> > On Thu, Nov 19, 2026 at 11:52:19AM +0530, Shrikanth Hegde wrote:
> > >
> > >
> > > On 11/14/26 12:12 AM, Yury Norov wrote:
> > > > Steal governor is not safe against a concurrent CPU hotplug operation
> > > > because it can change active and preferred cpumasks during the governor
> > > > sampling.
> > > >
> > > > To address the race, the governor would take the cpus_write_lock(). But
> > > > that may be impractical for the loadable module.
> > > >
> > > > Instead, implement the following locking policy:
> > > >
> > > > - if the code takes cpus_write_lock(), it's enough to write-access
> > > > the preferred cpumask;
> > > > - if the code takes cpus_read_lock(), it must also take
> > > > cpu_preferred_mutex in order to modify the preferred mask.
> > > >
> > > > The core scheduler and hotplug paths already modify the preferred cpumask
> > > > under the cpus_write_lock(), so no change in core logic is required.
> > > >
> > > > This provides a common update protocol for multiple policy drivers
> > > > without requiring writers to take the broader CPU hotplug write lock.
> > > >
> > >
> > > This is also necessary if there are multiple writers outside of core hotplug No?
> > > So should it go with the write interface series?
> >
> > The race is real, and it's already there, so this is the fix for an
> > existing functionality.
>
> At current, if there is hotplug, core takes cpus_write_lock to modify
> active/preferred which makes governor to wait.
>
> If the governor is modifying the preferred mask it is taking the read lock
> which makes the hotplug core to wait before modifying active/preferred masks.
>
> And there are no other infra modifying the preferred mask.
> Could you please explain where is race currently?
Initially, both masks contain CPUs {0,1}. No cpus_read_lock() held.
Steal ratio is within thresholds, so neither update helper runs.
Governor worker CPU hotplug
--------------- -----------
preferred_cpus_valid():
cpumask_empty(cpu_preferred_mask)
-> false
cpumask_subset(cpu_preferred_mask,
cpu_active_mask):
load preferred word -> {0,1}
cpus_write_lock()
sched_cpu_deactivate(1):
set_cpu_preferred(1, false)
/* preferred={0} */
set_cpu_active(1, false)
/* active={0} */
cpus_write_unlock()
load active word -> {0}
/* {0,1} is not a subset of {0} */
return false
/* Useless and misleading */
restore_preferred_to_active();
/* Skips schedule_delayed_work(). */
return
next prev parent reply other threads:[~2026-11-20 15:35 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 18:42 [PATCH 0/7] Harden preferred CPUs management Yury Norov
2026-11-13 18:42 ` [PATCH 1/7] cpumask: add reset_preferred_cpumask() helper Yury Norov
2026-11-13 18:55 ` sashiko-bot
2026-11-13 18:42 ` [PATCH 2/7] sched: restore preferred CPUs when hotplug removes the last one Yury Norov
2026-11-13 19:12 ` sashiko-bot
2026-11-19 6:13 ` Shrikanth Hegde
2026-11-19 16:46 ` Yury Norov
2026-11-13 18:42 ` [PATCH 3/7] virt: steal_governor: remove the minimum elapsed-time check Yury Norov
2026-11-13 18:56 ` sashiko-bot
2026-11-13 18:42 ` [PATCH 4/7] virt: steal_governor: serialize sampling against CPU hotplug Yury Norov
2026-11-13 19:03 ` sashiko-bot
2026-11-19 6:22 ` Shrikanth Hegde
2026-11-19 16:50 ` Yury Norov
2026-11-20 8:38 ` Shrikanth Hegde
2026-11-20 15:35 ` Yury Norov [this message]
2026-11-13 18:42 ` [PATCH 5/7] virt: steal_governor: warn on unexpected preferred mask states Yury Norov
2026-11-13 19:06 ` sashiko-bot
2026-11-13 18:42 ` [PATCH 6/7] virt: steal_governor: restart sampling immediately after CPU hotplug Yury Norov
2026-11-13 19:21 ` sashiko-bot
2026-11-16 2:13 ` Yury Norov
2026-11-19 6:06 ` Shrikanth Hegde
2026-11-19 17:39 ` Yury Norov
2026-11-20 8:50 ` Shrikanth Hegde
2026-11-20 15:36 ` Yury Norov
2026-11-13 18:42 ` [PATCH 7/7] cpu: make preferred CPU policy writers mutually exclusive Yury Norov
2026-11-13 19:25 ` sashiko-bot
2026-11-19 6:10 ` Shrikanth Hegde
2026-11-19 17:47 ` Yury Norov
2026-11-20 15:38 ` Peter Zijlstra
2026-11-20 15:59 ` Yury Norov
2026-11-20 16:09 ` Peter Zijlstra
2026-11-20 16:25 ` Yury Norov
2026-11-20 16:26 ` Yury Norov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=awBopXdhgUatAU9d@yury \
--to=ynorov@nvidia.com \
--cc=agordeev@linux.ibm.com \
--cc=arighi@nvidia.com \
--cc=borntraeger@linux.ibm.com \
--cc=bsegall@google.com \
--cc=corbet@lwn.net \
--cc=dakr@kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=driver-core@lists.linux.dev \
--cc=gor@linux.ibm.com \
--cc=gregkh@linuxfoundation.org \
--cc=hca@linux.ibm.com \
--cc=iii@linux.ibm.com \
--cc=johan@kernel.org \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=maxim.kuvyrkov@grdncc.com \
--cc=meted@linux.ibm.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rafael@kernel.org \
--cc=rdunlap@infradead.org \
--cc=rostedt@goodmis.org \
--cc=skhan@linuxfoundation.org \
--cc=sshegde@linux.ibm.com \
--cc=svens@linux.ibm.com \
--cc=tglx@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.