Skip to content

Commit 23dfeae

Browse files
committed
Merge tag 'smp-urgent-2023-09-02' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull CPU hotplug fix from Ingo Molnar: "Fix a CPU hotplug related deadlock between the task which initiates and controls a CPU hot-unplug operation vs. the CFS bandwidth timer" * tag 'smp-urgent-2023-09-02' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: cpu/hotplug: Prevent self deadlock on CPU hot-unplug
2 parents c39cbc5 + 2b8272f commit 23dfeae

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

kernel/cpu.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1487,8 +1487,22 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
14871487
return ret;
14881488
}
14891489

1490+
struct cpu_down_work {
1491+
unsigned int cpu;
1492+
enum cpuhp_state target;
1493+
};
1494+
1495+
static long __cpu_down_maps_locked(void *arg)
1496+
{
1497+
struct cpu_down_work *work = arg;
1498+
1499+
return _cpu_down(work->cpu, 0, work->target);
1500+
}
1501+
14901502
static int cpu_down_maps_locked(unsigned int cpu, enum cpuhp_state target)
14911503
{
1504+
struct cpu_down_work work = { .cpu = cpu, .target = target, };
1505+
14921506
/*
14931507
* If the platform does not support hotplug, report it explicitly to
14941508
* differentiate it from a transient offlining failure.
@@ -1497,7 +1511,15 @@ static int cpu_down_maps_locked(unsigned int cpu, enum cpuhp_state target)
14971511
return -EOPNOTSUPP;
14981512
if (cpu_hotplug_disabled)
14991513
return -EBUSY;
1500-
return _cpu_down(cpu, 0, target);
1514+
1515+
/*
1516+
* Ensure that the control task does not run on the to be offlined
1517+
* CPU to prevent a deadlock against cfs_b->period_timer.
1518+
*/
1519+
cpu = cpumask_any_but(cpu_online_mask, cpu);
1520+
if (cpu >= nr_cpu_ids)
1521+
return -EBUSY;
1522+
return work_on_cpu(cpu, __cpu_down_maps_locked, &work);
15011523
}
15021524

15031525
static int cpu_down(unsigned int cpu, enum cpuhp_state target)

0 commit comments

Comments
 (0)