All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/2] arm64: Fix machine_shutdown() definition
@ 2014-05-07  1:41 arunks.linux at gmail.com
  2014-05-07  1:41 ` [PATCH v1 2/2] arm64: Fix deadlock scenario with smp_send_stop() arunks.linux at gmail.com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: arunks.linux at gmail.com @ 2014-05-07  1:41 UTC (permalink / raw)
  To: linux-arm-kernel

From: Arun KS <arun.linux@gmail.com>

This patch ports most of commit 19ab428f4b79 "ARM: 7759/1: decouple CPU
offlining from reboot/shutdown" by Stephen Warren from arch/arm to
arch/arm64.

machine_shutdown() is a hook for kexec. Add a comment saying so, since
it isn't obvious from the function name.

Halt, power-off, and restart have different requirements re: stopping
secondary CPUs than kexec has. The former simply require the secondary
CPUs to be quiesced somehow, whereas kexec requires them to be
completely non-operational, so that no matter where the kexec target
images are written in RAM, they won't influence operation of the
secondary CPUS,which could happen if the CPUs were still executing some
kind of pin loop. To this end, modify machine_halt, power_off, and
restart to call smp_send_stop() directly, rather than calling
machine_shutdown().

In machine_shutdown(), replace the call to smp_send_stop() with a call
to disable_nonboot_cpus(). This completely disables all but one CPU,
thus satisfying the kexec requirements a couple paragraphs above.

Signed-off-by: Arun KS <getarunks@gmail.com>
---
 arch/arm64/kernel/process.c |   41 +++++++++++++++++++++++++++++++++++------
 1 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 6391485..2d43614 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -113,29 +113,58 @@ void arch_cpu_idle_dead(void)
 }
 #endif
 
+/*
+ * Called by kexec, immediately prior to machine_kexec().
+ *
+ * This must completely disable all secondary CPUs; simply causing those CPUs
+ * to execute e.g. a RAM-based pin loop is not sufficient. This allows the
+ * kexec'd kernel to use any and all RAM as it sees fit, without having to
+ * avoid any code or data used by any SW CPU pin loop. The CPU hotplug
+ * functionality embodied in disable_nonboot_cpus() to achieve this.
+ */
 void machine_shutdown(void)
 {
-#ifdef CONFIG_SMP
-	smp_send_stop();
-#endif
+	disable_nonboot_cpus();
 }
 
+/*
+ * Halting simply requires that the secondary CPUs stop performing any
+ * activity (executing tasks, handling interrupts). smp_send_stop()
+ * achieves this.
+ */
 void machine_halt(void)
 {
-	machine_shutdown();
+	smp_send_stop();
 	while (1);
 }
 
+/*
+ * Power-off simply requires that the secondary CPUs stop performing any
+ * activity (executing tasks, handling interrupts). smp_send_stop()
+ * achieves this. When the system power is turned off, it will take all CPUs
+ * with it.
+ */
 void machine_power_off(void)
 {
-	machine_shutdown();
+	smp_send_stop();
 	if (pm_power_off)
 		pm_power_off();
 }
 
+/*
+ * Restart requires that the secondary CPUs stop performing any activity
+ * while the primary CPU resets the system. Systems with a single CPU can
+ * use soft_restart() as their machine descriptor's .restart hook, since that
+ * will cause the only available CPU to reset. Systems with multiple CPUs must
+ * provide a HW restart implementation, to ensure that all CPUs reset at once.
+ * This is required so that any code running after reset on the primary CPU
+ * doesn't have to co-ordinate with other CPUs to ensure they aren't still
+ * executing pre-reset code, and using RAM that the primary CPU's code wishes
+ * to use. Implementing such co-ordination would be essentially impossible.
+ */
 void machine_restart(char *cmd)
 {
-	machine_shutdown();
+	smp_send_stop();
 
 	/* Disable interrupts first */
 	local_irq_disable();
-- 
1.7.6

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v1 2/2] arm64: Fix deadlock scenario with smp_send_stop()
  2014-05-07  1:41 [PATCH v1 1/2] arm64: Fix machine_shutdown() definition arunks.linux at gmail.com
@ 2014-05-07  1:41 ` arunks.linux at gmail.com
  2014-05-07 15:43 ` [PATCH v1 1/2] arm64: Fix machine_shutdown() definition Stephen Warren
  2014-05-16 17:20 ` Catalin Marinas
  2 siblings, 0 replies; 4+ messages in thread
From: arunks.linux at gmail.com @ 2014-05-07  1:41 UTC (permalink / raw)
  To: linux-arm-kernel

From: Arun KS <arunks.linux@gmail.com>

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 this task runs to
completion. We use local_irq_disable() here for cross-arch
consistency with x86.

Based-on-work-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Arun KS <getarunks@gmail.com>
---
 arch/arm64/kernel/process.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 2d43614..abe57e0 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -134,6 +134,7 @@ void machine_shutdown(void)
  */
 void machine_halt(void)
 {
+	local_irq_disable();
 	smp_send_stop();
 	while (1);
 }
@@ -146,6 +147,7 @@ void machine_halt(void)
  */
 void machine_power_off(void)
 {
+	local_irq_disable();
 	smp_send_stop();
 	if (pm_power_off)
 		pm_power_off();
@@ -164,10 +166,9 @@ void machine_power_off(void)
  */
 void machine_restart(char *cmd)
 {
-	smp_send_stop();
-
 	/* Disable interrupts first */
 	local_irq_disable();
+	smp_send_stop();
 
 	/* Now call the architecture specific reboot code. */
 	if (arm_pm_restart)
-- 
1.7.6

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v1 1/2] arm64: Fix machine_shutdown() definition
  2014-05-07  1:41 [PATCH v1 1/2] arm64: Fix machine_shutdown() definition arunks.linux at gmail.com
  2014-05-07  1:41 ` [PATCH v1 2/2] arm64: Fix deadlock scenario with smp_send_stop() arunks.linux at gmail.com
@ 2014-05-07 15:43 ` Stephen Warren
  2014-05-16 17:20 ` Catalin Marinas
  2 siblings, 0 replies; 4+ messages in thread
From: Stephen Warren @ 2014-05-07 15:43 UTC (permalink / raw)
  To: linux-arm-kernel

On 05/06/2014 07:41 PM, arunks.linux at gmail.com wrote:
> From: Arun KS <arun.linux@gmail.com>
> 
> This patch ports most of commit 19ab428f4b79 "ARM: 7759/1: decouple CPU
> offlining from reboot/shutdown" by Stephen Warren from arch/arm to
> arch/arm64.
> 
> machine_shutdown() is a hook for kexec. Add a comment saying so, since
> it isn't obvious from the function name.
> 
> Halt, power-off, and restart have different requirements re: stopping
> secondary CPUs than kexec has. The former simply require the secondary
> CPUs to be quiesced somehow, whereas kexec requires them to be
> completely non-operational, so that no matter where the kexec target
> images are written in RAM, they won't influence operation of the
> secondary CPUS,which could happen if the CPUs were still executing some
> kind of pin loop. To this end, modify machine_halt, power_off, and
> restart to call smp_send_stop() directly, rather than calling
> machine_shutdown().
> 
> In machine_shutdown(), replace the call to smp_send_stop() with a call
> to disable_nonboot_cpus(). This completely disables all but one CPU,
> thus satisfying the kexec requirements a couple paragraphs above.

I assume the code changes apply equally well to arm64 so,
Acked-by: Stephen Warren <swarren@nvidia.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v1 1/2] arm64: Fix machine_shutdown() definition
  2014-05-07  1:41 [PATCH v1 1/2] arm64: Fix machine_shutdown() definition arunks.linux at gmail.com
  2014-05-07  1:41 ` [PATCH v1 2/2] arm64: Fix deadlock scenario with smp_send_stop() arunks.linux at gmail.com
  2014-05-07 15:43 ` [PATCH v1 1/2] arm64: Fix machine_shutdown() definition Stephen Warren
@ 2014-05-16 17:20 ` Catalin Marinas
  2 siblings, 0 replies; 4+ messages in thread
From: Catalin Marinas @ 2014-05-16 17:20 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, May 07, 2014 at 02:41:22AM +0100, arunks.linux at gmail.com wrote:
> From: Arun KS <arun.linux@gmail.com>
> 
> This patch ports most of commit 19ab428f4b79 "ARM: 7759/1: decouple CPU
> offlining from reboot/shutdown" by Stephen Warren from arch/arm to
> arch/arm64.

Both patches applied. Thanks.

-- 
Catalin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-05-16 17:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-07  1:41 [PATCH v1 1/2] arm64: Fix machine_shutdown() definition arunks.linux at gmail.com
2014-05-07  1:41 ` [PATCH v1 2/2] arm64: Fix deadlock scenario with smp_send_stop() arunks.linux at gmail.com
2014-05-07 15:43 ` [PATCH v1 1/2] arm64: Fix machine_shutdown() definition Stephen Warren
2014-05-16 17:20 ` Catalin Marinas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.