[RFC PATCH 3/7] introduce _fail variants of stop_machine functions

From: Marcelo Tosatti
Date: Thu Sep 08 2022 - 15:57:23 EST


Introduce stop_machine_fail and stop_machine_cpuslocked_fail,
which check if any online CPU in the system is tagged as
a block interference CPU.

If so, returns an error.

Signed-off-by: Marcelo Tosatti <mtosatti@xxxxxxxxxx>

Index: linux-2.6/include/linux/stop_machine.h
===================================================================
--- linux-2.6.orig/include/linux/stop_machine.h
+++ linux-2.6/include/linux/stop_machine.h
@@ -113,6 +113,9 @@ static inline void print_stop_info(const
*/
int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus);

+
+int stop_machine_fail(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus);
+
/**
* stop_machine_cpuslocked: freeze the machine on all CPUs and run this function
* @fn: the function to run
@@ -124,6 +127,9 @@ int stop_machine(cpu_stop_fn_t fn, void
*/
int stop_machine_cpuslocked(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus);

+
+int stop_machine_cpuslocked_fail(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus);
+
/**
* stop_core_cpuslocked: - stop all threads on just one core
* @cpu: any cpu in the targeted core
Index: linux-2.6/kernel/stop_machine.c
===================================================================
--- linux-2.6.orig/kernel/stop_machine.c
+++ linux-2.6/kernel/stop_machine.c
@@ -22,6 +22,7 @@
#include <linux/atomic.h>
#include <linux/nmi.h>
#include <linux/sched/wake_q.h>
+#include <linux/sched/isolation.h>

/*
* Structure to determine completion condition and record errors. May
@@ -619,6 +620,17 @@ int stop_machine_cpuslocked(cpu_stop_fn_
return stop_cpus(cpu_online_mask, multi_cpu_stop, &msdata);
}

+int stop_machine_cpuslocked_fail(cpu_stop_fn_t fn, void *data,
+ const struct cpumask *cpus)
+{
+ block_interf_assert_held();
+
+ if (cpumask_intersects(block_interf_cpumask, cpu_online_mask))
+ return -EPERM;
+
+ return stop_machine_cpuslocked(fn, data, cpus);
+}
+
int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus)
{
int ret;
@@ -631,6 +643,19 @@ int stop_machine(cpu_stop_fn_t fn, void
}
EXPORT_SYMBOL_GPL(stop_machine);

+int stop_machine_fail(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus)
+{
+ int ret;
+
+ /* No CPUs can come up or down during this. */
+ cpus_read_lock();
+ ret = stop_machine_cpuslocked_fail(fn, data, cpus);
+ cpus_read_unlock();
+ return ret;
+}
+EXPORT_SYMBOL_GPL(stop_machine_fail);
+
+
#ifdef CONFIG_SCHED_SMT
int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data)
{