Skip to contentSkip to conversation

kernel/cpu.c: Move the CPU_DYING notifiers

PATCH Applied Manfred Spraul 4 participants 7 messages Aug 31, 2008 – Sep 13, 2008 CPU hotplug

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel/cpu.c: Move the CPU_DYING notifiers

When a cpu is taken offline, the CPU_DYING notifiers are called on the dying cpu. According to <linux/notifiers.h>, the cpu should be "not running any task, not handling interrupts, soon dead".

For the current implementation, this is not true:
- __cpu_disable can fail. If it fails, then the cpu will remain alive and happy.
- At least on x86, __cpu_disable() briefly enables the local interrupts to handle any outstanding interrupts.

What about moving CPU_DYING down a few lines, behind the __cpu_disable() line?
There are only two CPU_DYING handlers in the kernel right now: one in kvm, one in the scheduler. Both should work with the patch applied [and: I'm not sure if either one handles a failing __cpu_disable()]

The patch survives simple offlining a cpu. kvm untested due to lack of a test setup.

---
 kernel/cpu.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
kernel/cpu.c +3 -2
index e202a68..5b7c88f 100644
@@ -199,13 +199,14 @@ static int __ref take_cpu_down(void *_param)
 	struct take_cpu_down_param *param = _param;
 	int err;
 
-	raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod,
-				param->hcpu);
 	/* Ensure this CPU doesn't handle any more interrupts. */
 	err = __cpu_disable();
 	if (err < 0)
 		return err;
 
+	raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod,
+				param->hcpu);
+
 	/* Force idle task to run as soon as we yield: it should
 	   immediately notice cpu is offline and die quickly. */
 	sched_idle_next();
Signature · 1 line
1.5.5.1
#1 lore raw
Quoted 10 lines · Manfred Spraul

When a cpu is taken offline, the CPU_DYING notifiers are called on the dying cpu. According to <linux/notifiers.h>, the cpu should be "not running any task, not handling interrupts, soon dead".

For the current implementation, this is not true:
- __cpu_disable can fail. If it fails, then the cpu will remain alive and happy.
- At least on x86, __cpu_disable() briefly enables the local interrupts to handle any outstanding interrupts.

Quoted 8 lines

What about moving CPU_DYING down a few lines, behind the __cpu_disable() line?
There are only two CPU_DYING handlers in the kernel right now: one in kvm, one in the scheduler. Both should work with the patch applied [and: I'm not sure if either one handles a failing __cpu_disable()]

The patch survives simple offlining a cpu. kvm untested due to lack of a test setup.

Several architectures re-enable interrupts in __cpu_disable() or in functions called from __cpu_disable(), which happens after CPU_DYING, if I understand correctly. :-(

Thanx, Paul

Quoted 29 lines
---
 kernel/cpu.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
kernel/cpu.c +3 -2
index e202a68..5b7c88f 100644
@@ -199,13 +199,14 @@ static int __ref take_cpu_down(void *_param)
 	struct take_cpu_down_param *param = _param;
 	int err;
 
-	raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod,
-				param->hcpu);
 	/* Ensure this CPU doesn't handle any more interrupts. */
 	err = __cpu_disable();
 	if (err < 0)
 		return err;
 
+	raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod,
+				param->hcpu);
+
 	/* Force idle task to run as soon as we yield: it should
 	   immediately notice cpu is offline and die quickly. */
 	sched_idle_next();
Signature · 1 line
1.5.5.1
#2 lore raw
Quoted 17 lines · Paul E. McKenney
Quoted 16 lines · Manfred Spraul

When a cpu is taken offline, the CPU_DYING notifiers are called on the dying cpu. According to <linux/notifiers.h>, the cpu should be "not running any task, not handling interrupts, soon dead".

For the current implementation, this is not true:
- __cpu_disable can fail. If it fails, then the cpu will remain alive and happy.
- At least on x86, __cpu_disable() briefly enables the local interrupts to handle any outstanding interrupts.

What about moving CPU_DYING down a few lines, behind the __cpu_disable() line?
There are only two CPU_DYING handlers in the kernel right now: one in kvm, one in the scheduler. Both should work with the patch applied [and: I'm not sure if either one handles a failing __cpu_disable()]

Quoted 6 lines
Quoted 2 lines

The patch survives simple offlining a cpu. kvm untested due to lack of a test setup.

Several architectures re-enable interrupts in __cpu_disable() or in functions called from __cpu_disable(), which happens after CPU_DYING, if I understand correctly. :-(

Never mind -- you are moving CPU_DYING after __cpu_disable(). :-/

Thanx, Paul

Quoted 29 lines
Quoted 29 lines
---
 kernel/cpu.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
kernel/cpu.c +3 -2
index e202a68..5b7c88f 100644
@@ -199,13 +199,14 @@ static int __ref take_cpu_down(void *_param)
 	struct take_cpu_down_param *param = _param;
 	int err;
 
-	raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod,
-				param->hcpu);
 	/* Ensure this CPU doesn't handle any more interrupts. */
 	err = __cpu_disable();
 	if (err < 0)
 		return err;
 
+	raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod,
+				param->hcpu);
+
 	/* Force idle task to run as soon as we yield: it should
 	   immediately notice cpu is offline and die quickly. */
 	sched_idle_next();
Signature · 1 line
1.5.5.1
#3 lore raw
In reply to Manfred Spraul

kernel/cpu.c static int __ref take_cpu_down(void *_param) · line 208

Quoted 9 lines · Manfred Spraul
kernel/cpu.c +2 -2
-	raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod,
-				param->hcpu);
 	/* Ensure this CPU doesn't handle any more interrupts. */
 	err = __cpu_disable();
 	if (err < 0)
 		return err;
 
+	raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod,
+				param->hcpu);

hm, doesnt this break things like CPU cross-calls done in CPU_DYING callbacks?

Ingo

#4 lore raw
Quoted 9 lines · Ingo Molnar
Quoted 7 lines · Manfred Spraul
kernel/cpu.c +0 -2
-	raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod,
-				param->hcpu);
 	/* Ensure this CPU doesn't handle any more interrupts. */
 	err = __cpu_disable();
 	if (err < 0)
 		return err;
Quoted 6 lines

kernel/cpu.c static int __ref take_cpu_down(void *_param) · line 208

Quoted 3 lines
kernel/cpu.c +2 -0
+	raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod,
+				param->hcpu);

hm, doesnt this break things like CPU cross-calls done in CPU_DYING callbacks?

We are within stop_machine(). No other cpu is running. As fas as I can see no cross-calls are possible.

Which scenario do you think about?

--
Manfred

Applied
#5 lore raw
Quoted 17 lines · Manfred Spraul
Quoted 15 lines · Ingo Molnar

kernel/cpu.c static int __ref take_cpu_down(void *_param) · line 208

Quoted 9 lines · Manfred Spraul
kernel/cpu.c +1 -2
-	raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod,
-				param->hcpu);
 	/* Ensure this CPU doesn't handle any more interrupts. */
 	err = __cpu_disable();
 	if (err < 0)
 		return err;
 +	raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod,
+				param->hcpu);

hm, doesnt this break things like CPU cross-calls done in CPU_DYING callbacks?

Quoted 2 lines

We are within stop_machine(). No other cpu is running. As fas as I can see no cross-calls are possible.

ah, ok - my bad. I was confusing it with the much more common CPU_DOWN_PREPARE type of callbacks which do use various cross-CPU APIs.

applied to tip/sched/devel, thanks Manfred!

Ingo

#6 lore raw
In reply to Manfred Spraul
Quoted 10 lines · Manfred Spraul

When a cpu is taken offline, the CPU_DYING notifiers are called on the dying cpu. According to <linux/notifiers.h>, the cpu should be "not running any task, not handling interrupts, soon dead".

For the current implementation, this is not true:
- __cpu_disable can fail. If it fails, then the cpu will remain alive and happy.
- At least on x86, __cpu_disable() briefly enables the local interrupts to handle any outstanding interrupts.

Quoted 10 lines

What about moving CPU_DYING down a few lines, behind the __cpu_disable() line?
There are only two CPU_DYING handlers in the kernel right now: one in kvm, one in the scheduler. Both should work with the patch applied [and: I'm not sure if either one handles a failing __cpu_disable()]

The patch survives simple offlining a cpu. kvm untested due to lack of a test setup.

kvm should work with this patch.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.