Skip to contentSkip to conversation

ARM: Fix deadlock scenario with smp_send_stop()

PATCH In review Stephen Boyd 1 participant 2 messages Sep 5, 2012 – Sep 11, 2012 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: Fix deadlock scenario with smp_send_stop()

If one process calls sys_reboot and that process then stops other CPUs while those CPUs are within a spin_lock() region we can potentially encounter a deadlock scenario like below.

CPU 0 CPU 1
----- -----
spin_lock(my_lock)
smp_send_stop()
send_IPI handle_IPI()

                         disable_preemption/irqs
                          while(1);

<PREEMPT>
spin_lock(my_lock) <--- Waits forever

We shouldn't attempt to run any other tasks after we send a stop IPI to a CPU so disable preemption so that the reboot task runs to completion.

---

Unfortunately this won't fix the other problem I mentioned two weeks ago where smp_send_stop races with other CPUs calling cpu_up().

 arch/arm/kernel/process.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm/kernel/process.c +1 -0
index 693b744..663a7a8 100644
@@ -239,6 +239,7 @@ __setup("reboot=", reboot_setup);
 
 void machine_shutdown(void)
 {
+	preempt_disable();
 #ifdef CONFIG_SMP
 	smp_send_stop();
 #endif
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
#1 lore raw
Quoted 18 lines · Stephen Boyd

If one process calls sys_reboot and that process then stops other CPUs while those CPUs are within a spin_lock() region we can potentially encounter a deadlock scenario like below.

CPU 0 CPU 1
----- -----
spin_lock(my_lock)
smp_send_stop()
send_IPI handle_IPI()

                         disable_preemption/irqs
                          while(1);

<PREEMPT>
spin_lock(my_lock) <--- Waits forever

We shouldn't attempt to run any other tasks after we send a stop IPI to a CPU so disable preemption so that the reboot task runs to completion.

Quoted 6 lines

---

Unfortunately this won't fix the other problem I mentioned two weeks ago where smp_send_stop races with other CPUs calling cpu_up().

Any comments?

Quoted 16 lines
 arch/arm/kernel/process.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm/kernel/process.c +1 -0
index 693b744..663a7a8 100644
@@ -239,6 +239,7 @@ __setup("reboot=", reboot_setup);
 
 void machine_shutdown(void)
 {
+	preempt_disable();
 #ifdef CONFIG_SMP
 	smp_send_stop();
 #endif
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation