Re: [PATCH v5 07/10] platform/x86/intel/ifs: Add scan test support

From: Peter Zijlstra
Date: Thu May 05 2022 - 04:29:13 EST


On Thu, May 05, 2022 at 01:15:07AM +0200, Thomas Gleixner wrote:
> We don't have stomp_cpumask() today, but that's trivial enough to
> implement.

I don't think we want to gift people a random cpumask stop_machine(),
but here's one that stops a core. It runs the @fn on every cpu since I
thought to have understood that was the requirement for this muck.

*completely* untestededed.

diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
index 6da7b91af353..2e7324e44e38 100644
--- a/kernel/stop_machine.c
+++ b/kernel/stop_machine.c
@@ -631,6 +631,34 @@ int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus)
}
EXPORT_SYMBOL_GPL(stop_machine);

+/*
+ * stop_core_cpuslocked - stop_machine a core
+ * @cpu: any cpu in the targeted core
+ * @fn: the function to run
+ * @data: the data ptr for @fn()
+ *
+ * RETURNS:
+ * 0 if all executions of @fn returned 0, any non zero return value if any
+ * returned non zero.
+ */
+int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data)
+{
+ const struct cpumask *smt_mask = cpu_smt_mask(cpu);
+
+ struct multi_stop_data msdata = {
+ .fn = fn,
+ .data = data,
+ .num_threads = cpumask_weight(smt_mask);
+ .active_cpus = smt_mask,
+ };
+
+ lockdep_assert_cpus_held();
+
+ /* Set the initial state and stop all online cpus. */
+ set_state(&msdata, MULTI_STOP_PREPARE);
+ return stop_cpus(smt_mask, multi_cpu_stop, &msdata);
+}
+
/**
* stop_machine_from_inactive_cpu - stop_machine() from inactive CPU
* @fn: the function to run