[PATCH 1/7] cpumask: add reset_preferred_cpumask() helper

From: Yury Norov

Date: Fri Nov 13 2026 - 14:49:40 EST


This series adds more flexibility to control the 'preferred' status of
CPUs. As a preparation, move the steal governor's preferred mask reset
into cpumask.h to make it globally available.

While there, rename it to reset_preferred_cpumask().

Signed-off-by: Yury Norov <ynorov@xxxxxxxxxx>
---
drivers/virt/steal_governor.c | 16 +++++-----------
include/linux/cpumask.h | 13 +++++++++++++
2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/drivers/virt/steal_governor.c b/drivers/virt/steal_governor.c
index 81e5089ba824..99bebd3dee8c 100644
--- a/drivers/virt/steal_governor.c
+++ b/drivers/virt/steal_governor.c
@@ -50,15 +50,6 @@ static struct steal_governor sg_ctx = {
.low_threshold = 200, /* 2% */
};

-static void restore_preferred_to_active(void)
-{
- int cpu;
-
- guard(cpus_read_lock)();
- for_each_cpu(cpu, cpu_active_mask)
- set_cpu_preferred(cpu, true);
-}
-
static int param_set_interval_ms(const char *val, const struct kernel_param *kp)
{
unsigned int interval;
@@ -252,7 +243,9 @@ static void steal_governor_loop(struct work_struct *work)
* module restores to active if CPU hotplug breaks those assumptions.
*/
if (!preferred_cpus_valid()) {
- restore_preferred_to_active();
+ guard(cpus_read_lock)();
+
+ reset_preferred_cpumask();
return;
}

@@ -288,7 +281,8 @@ static int __init steal_governor_init(void)
static void __exit steal_governor_exit(void)
{
disable_delayed_work_sync(&sg_ctx.work);
- restore_preferred_to_active();
+ guard(cpus_read_lock)();
+ reset_preferred_cpumask();
pr_info("disabled\n");
}

diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index bf89bb3f30f6..b13d099474bc 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -1195,6 +1195,19 @@ void init_cpu_possible(const struct cpumask *src);
#define set_cpu_preferred(cpu, preferred) do { } while (0)
#endif

+/**
+ * reset_preferred_cpumask - reset preferred CPUs to the active mask.
+ *
+ * Callers must serialize against CPU hotplug and other preferred cpumask
+ * writers.
+ */
+static inline void reset_preferred_cpumask(void)
+{
+#ifdef CONFIG_PREFERRED_CPU
+ cpumask_copy(&__cpu_preferred_mask, cpu_active_mask);
+#endif
+}
+
void set_cpu_online(unsigned int cpu, bool online);
void set_cpu_possible(unsigned int cpu, bool possible);

--
2.53.0