[PATCH 5/7] virt: steal_governor: warn on unexpected preferred mask states

From: Yury Norov

Date: Fri Nov 13 2026 - 14:58:57 EST


Now that preferred cpumask access is properly serialized, and CPU
hotplug restores all remaining active CPUs as preferred when the
last preferred CPU gets offlined, the corresponding logic in the
driver is redundant.

Instead of removing it completely, add WARN_ON()s in the corresponding
paths to harden the preferred CPUs mask management and highlight that
this condition is not expected during normal operation.

Signed-off-by: Yury Norov <ynorov@xxxxxxxxxx>
---
drivers/virt/steal_governor.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/virt/steal_governor.c b/drivers/virt/steal_governor.c
index 8cd5c0f3e3ef..c34d91267ec1 100644
--- a/drivers/virt/steal_governor.c
+++ b/drivers/virt/steal_governor.c
@@ -142,6 +142,11 @@ static void decrease_preferred_cpus(void)

lockdep_assert_cpus_held();
lockdep_assert_held(&cpu_preferred_mutex);
+
+ /* We can't end up with no preferred CPUs under normal conditions. */
+ if (WARN_ON(cpumask_empty(cpu_preferred_mask)))
+ return;
+
cpu = cpumask_first_and(housekeeping_cpumask(HK_TYPE_KERNEL_NOISE),
cpu_preferred_mask);
if (cpu >= nr_cpu_ids)
@@ -150,8 +155,6 @@ static void decrease_preferred_cpus(void)
/* Always leave first housekeeping core as preferred. */
first_hk_core = topology_sibling_cpumask(cpu);
cpu = cpumask_last(cpu_preferred_mask);
- if (cpu >= nr_cpu_ids)
- return;

/* Find the last CPU which doesn't belong to that first hk_core. */
if (!cpumask_test_cpu(cpu, first_hk_core)) {
@@ -246,7 +249,7 @@ static void steal_governor_loop(struct work_struct *work)
* else: steal ratio is within bounds. Still do design checks so that
* module restores to active if CPU hotplug breaks those assumptions.
*/
- if (!preferred_cpus_valid()) {
+ if (WARN_ON(!preferred_cpus_valid())) {
reset_preferred_cpumask();
return;
}
--
2.53.0