Re: [PATCH 4/7] virt: steal_governor: serialize sampling against CPU hotplug

From: Shrikanth Hegde

Date: Fri Nov 20 2026 - 03:40:08 EST




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?

Fixes: 27d47ebce4d6 ("virt/steal_governor: Implement steal_governor policy loop")
Signed-off-by: Yury Norov <ynorov@xxxxxxxxxx>