[PATCH 3/4] scftorture: Protect the initial affinity check from hotplug
From: Joel Fernandes
Date: Sun Nov 08 2026 - 18:47:54 EST
An invoker binds to its target CPU, sleeps for the holdoff interval, and
then warns if it is running elsewhere. CPU hotplug can offline the target
during that sleep and legitimately move the invoker. A built-in test with
matching worker and hotplug holdoffs reproduces this warning.
Check the initial binding while holding cpus_read_lock(), before sleeping.
If the target is already offline, let the existing offline/rebind path
handle it instead of warning about an impossible initial binding. Release
the read lock before the holdoff and test loop so hotplug remains tested.
Signed-off-by: Joel Fernandes <joelagnelf@xxxxxxxxxx>
---
kernel/scftorture.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/kernel/scftorture.c b/kernel/scftorture.c
index ff9a8271a464..64ee2c5cf51c 100644
--- a/kernel/scftorture.c
+++ b/kernel/scftorture.c
@@ -479,19 +479,24 @@ static int scftorture_invoker(void *arg)
VERBOSE_SCFTORTOUT("scftorture_invoker %d: task started", scfp->cpu);
cpu = scfp->cpu % nr_cpu_ids;
- WARN_ON_ONCE(set_cpus_allowed_ptr(current, cpumask_of(cpu)));
+ cpus_read_lock();
+ if (cpu_online(cpu)) {
+ WARN_ON_ONCE(set_cpus_allowed_ptr(current, cpumask_of(cpu)));
+ /* Check affinity before hotplug can move this task away. */
+ curcpu = raw_smp_processor_id();
+ WARN_ONCE(curcpu != cpu,
+ "%s: Wanted CPU %d, running on %d, nr_cpu_ids = %d\n",
+ __func__, scfp->cpu, curcpu, nr_cpu_ids);
+ } else {
+ was_offline = true;
+ }
+ cpus_read_unlock();
set_user_nice(current, MAX_NICE);
if (holdoff)
schedule_timeout_interruptible(holdoff * HZ);
VERBOSE_SCFTORTOUT("scftorture_invoker %d: Waiting for all SCF torturers from cpu %d", scfp->cpu, raw_smp_processor_id());
- // Make sure that the CPU is affinitized appropriately during testing.
- curcpu = raw_smp_processor_id();
- WARN_ONCE(curcpu != cpu,
- "%s: Wanted CPU %d, running on %d, nr_cpu_ids = %d\n",
- __func__, scfp->cpu, curcpu, nr_cpu_ids);
-
if (atomic_dec_return(&n_started))
while (atomic_read_acquire(&n_started)) {
if (torture_must_stop()) {
--
2.54.0