linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 01/15] cpu: Add new {add,remove}_cpu() functions
       [not found] <20200223192942.18420-1-qais.yousef@arm.com>
@ 2020-02-23 19:29 ` Qais Yousef
  2020-02-23 19:29 ` [PATCH v3 02/15] smp: Create a new function to shutdown nonboot cpus Qais Yousef
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 22+ messages in thread
From: Qais Yousef @ 2020-02-23 19:29 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Paul E . McKenney, Qais Yousef, Helge Deller, Michael Ellerman,
	David S. Miller, Juergen Gross, Mark Rutland, Lorenzo Pieralisi,
	xen-devel, linux-parisc, sparclinux, linuxppc-dev,
	linux-arm-kernel, x86, linux-kernel

The new functions use device_{online,offline}() which are userspace
safe.

This is in preparation to move cpu_{up, down} kernel users to use
a safer interface that is not racy with userspace.

Suggested-by: "Paul E. McKenney" <paulmck@kernel.org>
Signed-off-by: Qais Yousef <qais.yousef@arm.com>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: "Paul E. McKenney" <paulmck@kernel.org>
CC: Helge Deller <deller@gmx.de>
CC: Michael Ellerman <mpe@ellerman.id.au>
CC: "David S. Miller" <davem@davemloft.net>
CC: Juergen Gross <jgross@suse.com>
CC: Mark Rutland <mark.rutland@arm.com>
CC: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
CC: xen-devel@lists.xenproject.org
CC: linux-parisc@vger.kernel.org
CC: sparclinux@vger.kernel.org
CC: linuxppc-dev@lists.ozlabs.org
CC: linux-arm-kernel@lists.infradead.org
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
---
 include/linux/cpu.h |  2 ++
 kernel/cpu.c        | 24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/include/linux/cpu.h b/include/linux/cpu.h
index 1ca2baf817ed..cf8cf38dca43 100644
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -89,6 +89,7 @@ extern ssize_t arch_cpu_release(const char *, size_t);
 #ifdef CONFIG_SMP
 extern bool cpuhp_tasks_frozen;
 int cpu_up(unsigned int cpu);
+int add_cpu(unsigned int cpu);
 void notify_cpu_starting(unsigned int cpu);
 extern void cpu_maps_update_begin(void);
 extern void cpu_maps_update_done(void);
@@ -118,6 +119,7 @@ extern void cpu_hotplug_disable(void);
 extern void cpu_hotplug_enable(void);
 void clear_tasks_mm_cpumask(int cpu);
 int cpu_down(unsigned int cpu);
+int remove_cpu(unsigned int cpu);
 
 #else /* CONFIG_HOTPLUG_CPU */
 
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 9c706af713fb..069802f7010f 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -1057,6 +1057,18 @@ int cpu_down(unsigned int cpu)
 }
 EXPORT_SYMBOL(cpu_down);
 
+int remove_cpu(unsigned int cpu)
+{
+	int ret;
+
+	lock_device_hotplug();
+	ret = device_offline(get_cpu_device(cpu));
+	unlock_device_hotplug();
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(remove_cpu);
+
 #else
 #define takedown_cpu		NULL
 #endif /*CONFIG_HOTPLUG_CPU*/
@@ -1209,6 +1221,18 @@ int cpu_up(unsigned int cpu)
 }
 EXPORT_SYMBOL_GPL(cpu_up);
 
+int add_cpu(unsigned int cpu)
+{
+	int ret;
+
+	lock_device_hotplug();
+	ret = device_online(get_cpu_device(cpu));
+	unlock_device_hotplug();
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(add_cpu);
+
 #ifdef CONFIG_PM_SLEEP_SMP
 static cpumask_var_t frozen_cpus;
 
-- 
2.17.1


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

* [PATCH v3 02/15] smp: Create a new function to shutdown nonboot cpus
       [not found] <20200223192942.18420-1-qais.yousef@arm.com>
  2020-02-23 19:29 ` [PATCH v3 01/15] cpu: Add new {add,remove}_cpu() functions Qais Yousef
@ 2020-02-23 19:29 ` Qais Yousef
  2020-02-23 19:29 ` [PATCH v3 03/15] ia64: Replace cpu_down with smp_shutdown_nonboot_cpus() Qais Yousef
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 22+ messages in thread
From: Qais Yousef @ 2020-02-23 19:29 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Paul E . McKenney, Qais Yousef, Josh Poimboeuf,
	Peter Zijlstra (Intel),
	Jiri Kosina, Nicholas Piggin, Daniel Lezcano, Ingo Molnar,
	Eiichi Tsukata, Zhenzhong Duan, Nadav Amit, Greg Kroah-Hartman,
	Rafael J. Wysocki, Tony Luck, Fenghua Yu, Russell King,
	Catalin Marinas, Will Deacon, linux-arm-kernel, linux-ia64,
	linux-kernel

This function will be used later in machine_shutdown() for some archs.

disable_nonboot_cpus() is not safe to use when doing machine_down(),
because it relies on freeze_secondary_cpus() which in turn is
a suspend/resume related freeze and could abort if the logic detects any
pending activities that can prevent finishing the offlining process.

Signed-off-by: Qais Yousef <qais.yousef@arm.com>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Josh Poimboeuf <jpoimboe@redhat.com>
CC: "Peter Zijlstra (Intel)" <peterz@infradead.org>
CC: Jiri Kosina <jkosina@suse.cz>
CC: Nicholas Piggin <npiggin@gmail.com>
CC: Daniel Lezcano <daniel.lezcano@linaro.org>
CC: Ingo Molnar <mingo@kernel.org>
CC: Eiichi Tsukata <devel@etsukata.com>
CC: Zhenzhong Duan <zhenzhong.duan@oracle.com>
CC: Nadav Amit <namit@vmware.com>
CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
CC: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
CC: Tony Luck <tony.luck@intel.com>
CC: Fenghua Yu <fenghua.yu@intel.com>
CC: Russell King <linux@armlinux.org.uk>
CC: Catalin Marinas <catalin.marinas@arm.com>
CC: Will Deacon <will@kernel.org>
CC: linux-arm-kernel@lists.infradead.org
CC: linux-ia64@vger.kernel.org
CC: linux-kernel@vger.kernel.org
---
 include/linux/cpu.h |  2 ++
 kernel/cpu.c        | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/include/linux/cpu.h b/include/linux/cpu.h
index cf8cf38dca43..64a246e9c8db 100644
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -120,6 +120,7 @@ extern void cpu_hotplug_enable(void);
 void clear_tasks_mm_cpumask(int cpu);
 int cpu_down(unsigned int cpu);
 int remove_cpu(unsigned int cpu);
+extern void smp_shutdown_nonboot_cpus(unsigned int primary_cpu);
 
 #else /* CONFIG_HOTPLUG_CPU */
 
@@ -131,6 +132,7 @@ static inline int  cpus_read_trylock(void) { return true; }
 static inline void lockdep_assert_cpus_held(void) { }
 static inline void cpu_hotplug_disable(void) { }
 static inline void cpu_hotplug_enable(void) { }
+static inline void smp_shutdown_nonboot_cpus(unsigned int primary_cpu) { }
 #endif	/* !CONFIG_HOTPLUG_CPU */
 
 /* Wrappers which go away once all code is converted */
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 069802f7010f..03c727195b65 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -1069,6 +1069,48 @@ int remove_cpu(unsigned int cpu)
 }
 EXPORT_SYMBOL_GPL(remove_cpu);
 
+void smp_shutdown_nonboot_cpus(unsigned int primary_cpu)
+{
+	unsigned int cpu;
+	int error;
+
+	cpu_maps_update_begin();
+
+	/*
+	 * Make certain the cpu I'm about to reboot on is online.
+	 *
+	 * This is inline to what migrate_to_reboot_cpu() already do.
+	 */
+	if (!cpu_online(primary_cpu))
+		primary_cpu = cpumask_first(cpu_online_mask);
+
+	for_each_online_cpu(cpu) {
+		if (cpu == primary_cpu)
+			continue;
+
+		error = cpu_down_maps_locked(cpu, CPUHP_OFFLINE);
+		if (error) {
+			pr_err("Failed to offline CPU%d - error=%d",
+				cpu, error);
+			break;
+		}
+	}
+
+	/*
+	 * Ensure all but the reboot CPU are offline.
+	 */
+	BUG_ON(num_online_cpus() > 1);
+
+	/*
+	 * Make sure the CPUs won't be enabled by someone else after this
+	 * point. Kexec will reboot to a new kernel shortly resetting
+	 * everything along the way.
+	 */
+	cpu_hotplug_disabled++;
+
+	cpu_maps_update_done();
+}
+
 #else
 #define takedown_cpu		NULL
 #endif /*CONFIG_HOTPLUG_CPU*/
-- 
2.17.1


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

* [PATCH v3 03/15] ia64: Replace cpu_down with smp_shutdown_nonboot_cpus()
       [not found] <20200223192942.18420-1-qais.yousef@arm.com>
  2020-02-23 19:29 ` [PATCH v3 01/15] cpu: Add new {add,remove}_cpu() functions Qais Yousef
  2020-02-23 19:29 ` [PATCH v3 02/15] smp: Create a new function to shutdown nonboot cpus Qais Yousef
@ 2020-02-23 19:29 ` Qais Yousef
  2020-02-23 19:29 ` [PATCH v3 04/15] arm: Don't use disable_nonboot_cpus() Qais Yousef
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 22+ messages in thread
From: Qais Yousef @ 2020-02-23 19:29 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Paul E . McKenney, Qais Yousef, Tony Luck, Fenghua Yu,
	linux-ia64, linux-kernel

Use the new smp_shutdown_nonboot_cpus() instead of open coding using
cpu_down() directly.

Use reboot_cpu instead of hardcoding the boot CPU to 0.

This also prepares to make cpu_up/down a private interface for anything
but the cpu subsystem.

Signed-off-by: Qais Yousef <qais.yousef@arm.com>
CC: Tony Luck <tony.luck@intel.com>
CC: Fenghua Yu <fenghua.yu@intel.com>
CC: linux-ia64@vger.kernel.org
CC: linux-kernel@vger.kernel.org
---
 arch/ia64/kernel/process.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c
index 968b5f33e725..bf4c0cdb7a25 100644
--- a/arch/ia64/kernel/process.c
+++ b/arch/ia64/kernel/process.c
@@ -646,14 +646,8 @@ cpu_halt (void)
 
 void machine_shutdown(void)
 {
-#ifdef CONFIG_HOTPLUG_CPU
-	int cpu;
+	smp_shutdown_nonboot_cpus(reboot_cpu);
 
-	for_each_online_cpu(cpu) {
-		if (cpu != smp_processor_id())
-			cpu_down(cpu);
-	}
-#endif
 #ifdef CONFIG_KEXEC
 	kexec_disable_iosapic();
 #endif
-- 
2.17.1


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

* [PATCH v3 04/15] arm: Don't use disable_nonboot_cpus()
       [not found] <20200223192942.18420-1-qais.yousef@arm.com>
                   ` (2 preceding siblings ...)
  2020-02-23 19:29 ` [PATCH v3 03/15] ia64: Replace cpu_down with smp_shutdown_nonboot_cpus() Qais Yousef
@ 2020-02-23 19:29 ` Qais Yousef
  2020-03-20 11:04   ` Qais Yousef
  2020-02-23 19:29 ` [PATCH v3 05/15] arm64: " Qais Yousef
                   ` (10 subsequent siblings)
  14 siblings, 1 reply; 22+ messages in thread
From: Qais Yousef @ 2020-02-23 19:29 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Paul E . McKenney, Qais Yousef, Russell King, linux-arm-kernel,
	linux-kernel

disable_nonboot_cpus() is not safe to use when doing machine_down(),
because it relies on freeze_secondary_cpus() which in turn is
a suspend/resume related freeze and could abort if the logic detects any
pending activities that can prevent finishing the offlining process.

Beside disable_nonboot_cpus() is dependent on CONFIG_PM_SLEEP_SMP which
is an othogonal config to rely on to ensure this function works
correctly.

Use `reboot_cpu` variable instead of hardcoding 0 as the reboot cpu.

Signed-off-by: Qais Yousef <qais.yousef@arm.com>
CC: Russell King <linux@armlinux.org.uk>
CC: linux-arm-kernel@lists.infradead.org
CC: linux-kernel@vger.kernel.org
---
 arch/arm/kernel/reboot.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/kernel/reboot.c b/arch/arm/kernel/reboot.c
index bb18ed0539f4..0ce388f15422 100644
--- a/arch/arm/kernel/reboot.c
+++ b/arch/arm/kernel/reboot.c
@@ -88,11 +88,11 @@ void soft_restart(unsigned long addr)
  * 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.
+ * functionality embodied in smp_shutdown_nonboot_cpus() to achieve this.
  */
 void machine_shutdown(void)
 {
-	disable_nonboot_cpus();
+	smp_shutdown_nonboot_cpus(reboot_cpu);
 }
 
 /*
-- 
2.17.1


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

* [PATCH v3 05/15] arm64: Don't use disable_nonboot_cpus()
       [not found] <20200223192942.18420-1-qais.yousef@arm.com>
                   ` (3 preceding siblings ...)
  2020-02-23 19:29 ` [PATCH v3 04/15] arm: Don't use disable_nonboot_cpus() Qais Yousef
@ 2020-02-23 19:29 ` Qais Yousef
  2020-03-17 11:21   ` Catalin Marinas
  2020-02-23 19:29 ` [PATCH v3 06/15] arm64: hibernate.c: Create a new function to handle cpu_up(sleep_cpu) Qais Yousef
                   ` (9 subsequent siblings)
  14 siblings, 1 reply; 22+ messages in thread
From: Qais Yousef @ 2020-02-23 19:29 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Paul E . McKenney, Qais Yousef, Catalin Marinas, Will Deacon,
	linux-arm-kernel, linux-kernel

disable_nonboot_cpus() is not safe to use when doing machine_down(),
because it relies on freeze_secondary_cpus() which in turn is
a suspend/resume related freeze and could abort if the logic detects any
pending activities that can prevent finishing the offlining process.

Beside disable_nonboot_cpus() is dependent on CONFIG_PM_SLEEP_SMP which
is an othogonal config to rely on to ensure this function works
correctly.

Use `reboot_cpu` variable instead of hardcoding 0 as the reboot cpu.

Signed-off-by: Qais Yousef <qais.yousef@arm.com>
CC: Catalin Marinas <catalin.marinas@arm.com>
CC: Will Deacon <will@kernel.org>
CC: linux-arm-kernel@lists.infradead.org
CC: linux-kernel@vger.kernel.org
---
 arch/arm64/kernel/process.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index bbb0f0c145f6..b33b415fb32e 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -141,11 +141,11 @@ void arch_cpu_idle_dead(void)
  * 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.
+ * functionality embodied in smpt_shutdown_nonboot_cpus() to achieve this.
  */
 void machine_shutdown(void)
 {
-	disable_nonboot_cpus();
+	smp_shutdown_nonboot_cpus(reboot_cpu);
 }
 
 /*
-- 
2.17.1


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

* [PATCH v3 06/15] arm64: hibernate.c: Create a new function to handle cpu_up(sleep_cpu)
       [not found] <20200223192942.18420-1-qais.yousef@arm.com>
                   ` (4 preceding siblings ...)
  2020-02-23 19:29 ` [PATCH v3 05/15] arm64: " Qais Yousef
@ 2020-02-23 19:29 ` Qais Yousef
  2020-03-17 11:21   ` Catalin Marinas
  2020-02-23 19:29 ` [PATCH v3 07/15] x86: Replace cpu_up/down with add/remove_cpu Qais Yousef
                   ` (8 subsequent siblings)
  14 siblings, 1 reply; 22+ messages in thread
From: Qais Yousef @ 2020-02-23 19:29 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Paul E . McKenney, Qais Yousef, Catalin Marinas, Will Deacon,
	Steve Capper, Richard Fontana, James Morse, Mark Rutland,
	Josh Poimboeuf, Ingo Molnar, Peter Zijlstra (Intel),
	Nicholas Piggin, Daniel Lezcano, Jiri Kosina, Pavankumar Kondeti,
	Zhenzhong Duan, linux-arm-kernel, linux-kernel

In preparation to make cpu_up/down private - move the user in arm64
hibernate.c to use a new generic function that provides what arm64
needs.

Signed-off-by: Qais Yousef <qais.yousef@arm.com>
CC: Catalin Marinas <catalin.marinas@arm.com>
CC: Will Deacon <will@kernel.org>
CC: Steve Capper <steve.capper@arm.com>
CC: Richard Fontana <rfontana@redhat.com>
CC: James Morse <james.morse@arm.com>
CC: Mark Rutland <mark.rutland@arm.com>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Josh Poimboeuf <jpoimboe@redhat.com>
CC: Ingo Molnar <mingo@kernel.org>
CC: "Peter Zijlstra (Intel)" <peterz@infradead.org>
CC: Nicholas Piggin <npiggin@gmail.com>
CC: Daniel Lezcano <daniel.lezcano@linaro.org>
CC: Jiri Kosina <jkosina@suse.cz>
CC: Pavankumar Kondeti <pkondeti@codeaurora.org>
CC: Zhenzhong Duan <zhenzhong.duan@oracle.com>
CC: linux-arm-kernel@lists.infradead.org
CC: linux-kernel@vger.kernel.org
---
 arch/arm64/kernel/hibernate.c | 13 +++++--------
 include/linux/cpu.h           |  1 +
 kernel/cpu.c                  | 24 ++++++++++++++++++++++++
 3 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c
index 590963c9c609..5b73e92c99e3 100644
--- a/arch/arm64/kernel/hibernate.c
+++ b/arch/arm64/kernel/hibernate.c
@@ -166,14 +166,11 @@ int arch_hibernation_header_restore(void *addr)
 		sleep_cpu = -EINVAL;
 		return -EINVAL;
 	}
-	if (!cpu_online(sleep_cpu)) {
-		pr_info("Hibernated on a CPU that is offline! Bringing CPU up.\n");
-		ret = cpu_up(sleep_cpu);
-		if (ret) {
-			pr_err("Failed to bring hibernate-CPU up!\n");
-			sleep_cpu = -EINVAL;
-			return ret;
-		}
+
+	ret = bringup_hibernate_cpu(sleep_cpu);
+	if (ret) {
+		sleep_cpu = -EINVAL;
+		return ret;
 	}
 
 	resume_hdr = *hdr;
diff --git a/include/linux/cpu.h b/include/linux/cpu.h
index 64a246e9c8db..aebe8186cb07 100644
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -93,6 +93,7 @@ int add_cpu(unsigned int cpu);
 void notify_cpu_starting(unsigned int cpu);
 extern void cpu_maps_update_begin(void);
 extern void cpu_maps_update_done(void);
+extern int bringup_hibernate_cpu(unsigned int sleep_cpu);
 
 #else	/* CONFIG_SMP */
 #define cpuhp_tasks_frozen	0
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 03c727195b65..bf39c5bfb6d9 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -1275,6 +1275,30 @@ int add_cpu(unsigned int cpu)
 }
 EXPORT_SYMBOL_GPL(add_cpu);
 
+/**
+ * bringup_hibernate_cpu - Bring up the CPU that we hibernated on
+ * @sleep_cpu: The cpu we hibernated on and should be brought up.
+ *
+ * On some archs like arm64, we can hibernate on any CPU, but on wake up the
+ * CPU we hibernated on might be offline as a side effect of using maxcpus= for
+ * example.
+ */
+int bringup_hibernate_cpu(unsigned int sleep_cpu)
+{
+	int ret;
+
+	if (!cpu_online(sleep_cpu)) {
+		pr_info("Hibernated on a CPU that is offline! Bringing CPU up.\n");
+		ret = cpu_up(sleep_cpu);
+		if (ret) {
+			pr_err("Failed to bring hibernate-CPU up!\n");
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
 #ifdef CONFIG_PM_SLEEP_SMP
 static cpumask_var_t frozen_cpus;
 
-- 
2.17.1


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

* [PATCH v3 07/15] x86: Replace cpu_up/down with add/remove_cpu
       [not found] <20200223192942.18420-1-qais.yousef@arm.com>
                   ` (5 preceding siblings ...)
  2020-02-23 19:29 ` [PATCH v3 06/15] arm64: hibernate.c: Create a new function to handle cpu_up(sleep_cpu) Qais Yousef
@ 2020-02-23 19:29 ` Qais Yousef
  2020-02-23 19:29 ` [PATCH v3 08/15] powerpc: " Qais Yousef
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 22+ messages in thread
From: Qais Yousef @ 2020-02-23 19:29 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Paul E . McKenney, Qais Yousef, Ingo Molnar, Borislav Petkov,
	H. Peter Anvin, x86, linux-kernel

The core device API performs extra housekeeping bits that are missing
from directly calling cpu_up/down.

See commit a6717c01ddc2 ("powerpc/rtas: use device model APIs and
serialization during LPM") for an example description of what might go
wrong.

This also prepares to make cpu_up/down a private interface for anything
but the cpu subsystem.

Signed-off-by: Qais Yousef <qais.yousef@arm.com>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Ingo Molnar <mingo@redhat.com>
CC: Borislav Petkov <bp@alien8.de>
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
---
 arch/x86/kernel/topology.c | 22 ++++++----------------
 arch/x86/mm/mmio-mod.c     |  4 ++--
 arch/x86/xen/smp.c         |  2 +-
 3 files changed, 9 insertions(+), 19 deletions(-)

diff --git a/arch/x86/kernel/topology.c b/arch/x86/kernel/topology.c
index be5bc2e47c71..b8810ebbc8ae 100644
--- a/arch/x86/kernel/topology.c
+++ b/arch/x86/kernel/topology.c
@@ -59,39 +59,29 @@ __setup("cpu0_hotplug", enable_cpu0_hotplug);
  */
 int _debug_hotplug_cpu(int cpu, int action)
 {
-	struct device *dev = get_cpu_device(cpu);
 	int ret;
 
 	if (!cpu_is_hotpluggable(cpu))
 		return -EINVAL;
 
-	lock_device_hotplug();
-
 	switch (action) {
 	case 0:
-		ret = cpu_down(cpu);
-		if (!ret) {
+		ret = remove_cpu(cpu);
+		if (!ret)
 			pr_info("DEBUG_HOTPLUG_CPU0: CPU %u is now offline\n", cpu);
-			dev->offline = true;
-			kobject_uevent(&dev->kobj, KOBJ_OFFLINE);
-		} else
+		else
 			pr_debug("Can't offline CPU%d.\n", cpu);
 		break;
 	case 1:
-		ret = cpu_up(cpu);
-		if (!ret) {
-			dev->offline = false;
-			kobject_uevent(&dev->kobj, KOBJ_ONLINE);
-		} else {
+		ret = add_cpu(cpu);
+		if (ret)
 			pr_debug("Can't online CPU%d.\n", cpu);
-		}
+
 		break;
 	default:
 		ret = -EINVAL;
 	}
 
-	unlock_device_hotplug();
-
 	return ret;
 }
 
diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
index 673de6063345..109325d77b3e 100644
--- a/arch/x86/mm/mmio-mod.c
+++ b/arch/x86/mm/mmio-mod.c
@@ -386,7 +386,7 @@ static void enter_uniprocessor(void)
 	put_online_cpus();
 
 	for_each_cpu(cpu, downed_cpus) {
-		err = cpu_down(cpu);
+		err = remove_cpu(cpu);
 		if (!err)
 			pr_info("CPU%d is down.\n", cpu);
 		else
@@ -406,7 +406,7 @@ static void leave_uniprocessor(void)
 		return;
 	pr_notice("Re-enabling CPUs...\n");
 	for_each_cpu(cpu, downed_cpus) {
-		err = cpu_up(cpu);
+		err = add_cpu(cpu);
 		if (!err)
 			pr_info("enabled CPU%d.\n", cpu);
 		else
diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
index 7a43b2ae19f1..2097fa0ebdb5 100644
--- a/arch/x86/xen/smp.c
+++ b/arch/x86/xen/smp.c
@@ -132,7 +132,7 @@ void __init xen_smp_cpus_done(unsigned int max_cpus)
 		if (xen_vcpu_nr(cpu) < MAX_VIRT_CPUS)
 			continue;
 
-		rc = cpu_down(cpu);
+		rc = remove_cpu(cpu);
 
 		if (rc == 0) {
 			/*
-- 
2.17.1


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

* [PATCH v3 08/15] powerpc: Replace cpu_up/down with add/remove_cpu
       [not found] <20200223192942.18420-1-qais.yousef@arm.com>
                   ` (6 preceding siblings ...)
  2020-02-23 19:29 ` [PATCH v3 07/15] x86: Replace cpu_up/down with add/remove_cpu Qais Yousef
@ 2020-02-23 19:29 ` Qais Yousef
  2020-02-23 19:29 ` [PATCH v3 09/15] sparc: " Qais Yousef
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 22+ messages in thread
From: Qais Yousef @ 2020-02-23 19:29 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Paul E . McKenney, Qais Yousef, Benjamin Herrenschmidt,
	Paul Mackerras, Michael Ellerman, Enrico Weigelt, Ram Pai,
	Nicholas Piggin, Thiago Jung Bauermann, Christophe Leroy,
	linuxppc-dev, linux-kernel

The core device API performs extra housekeeping bits that are missing
from directly calling cpu_up/down.

See commit a6717c01ddc2 ("powerpc/rtas: use device model APIs and
serialization during LPM") for an example description of what might go
wrong.

This also prepares to make cpu_up/down a private interface for anything
but the cpu subsystem.

Acked-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Qais Yousef <qais.yousef@arm.com>
CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
CC: Paul Mackerras <paulus@samba.org>
CC: Michael Ellerman <mpe@ellerman.id.au>
CC: Enrico Weigelt <info@metux.net>
CC: Ram Pai <linuxram@us.ibm.com>
CC: Nicholas Piggin <npiggin@gmail.com>
CC: Thiago Jung Bauermann <bauerman@linux.ibm.com>
CC: Christophe Leroy <christophe.leroy@c-s.fr>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: linuxppc-dev@lists.ozlabs.org
CC: linux-kernel@vger.kernel.org
---

Michael, this now uses add_cpu() which you should be CCed on. I wasn't sure if
I can keep your Ack or remove it in this case. Please let me know if you need
more clarification.

 arch/powerpc/kexec/core_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kexec/core_64.c b/arch/powerpc/kexec/core_64.c
index 04a7cba58eff..b4184092172a 100644
--- a/arch/powerpc/kexec/core_64.c
+++ b/arch/powerpc/kexec/core_64.c
@@ -212,7 +212,7 @@ static void wake_offline_cpus(void)
 		if (!cpu_online(cpu)) {
 			printk(KERN_INFO "kexec: Waking offline cpu %d.\n",
 			       cpu);
-			WARN_ON(cpu_up(cpu));
+			WARN_ON(add_cpu(cpu));
 		}
 	}
 }
-- 
2.17.1


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

* [PATCH v3 09/15] sparc: Replace cpu_up/down with add/remove_cpu
       [not found] <20200223192942.18420-1-qais.yousef@arm.com>
                   ` (7 preceding siblings ...)
  2020-02-23 19:29 ` [PATCH v3 08/15] powerpc: " Qais Yousef
@ 2020-02-23 19:29 ` Qais Yousef
  2020-02-23 19:29 ` [PATCH v3 10/15] parisc: " Qais Yousef
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 22+ messages in thread
From: Qais Yousef @ 2020-02-23 19:29 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Paul E . McKenney, Qais Yousef, David S. Miller, Bjorn Helgaas,
	Rafael J. Wysocki, Greg Kroah-Hartman, Sakari Ailus, sparclinux,
	linux-kernel

The core device API performs extra housekeeping bits that are missing
from directly calling cpu_up/down.

See commit a6717c01ddc2 ("powerpc/rtas: use device model APIs and
serialization during LPM") for an example description of what might go
wrong.

This also prepares to make cpu_up/down a private interface for anything
but the cpu subsystem.

Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Qais Yousef <qais.yousef@arm.com>
CC: "David S. Miller" <davem@davemloft.net>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Bjorn Helgaas <bhelgaas@google.com>
CC: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
CC: Sakari Ailus <sakari.ailus@linux.intel.com>
CC: sparclinux@vger.kernel.org
CC: linux-kernel@vger.kernel.org
---

David, this now uses add/remove_cpu() which you should be CCed on. I wasn't
sure if I can keep your Ack or remove it in this case. Please let me know if
you need more clarification.

 arch/sparc/kernel/ds.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/sparc/kernel/ds.c b/arch/sparc/kernel/ds.c
index bbf59b3b4af8..75232cbd58bf 100644
--- a/arch/sparc/kernel/ds.c
+++ b/arch/sparc/kernel/ds.c
@@ -555,7 +555,7 @@ static int dr_cpu_configure(struct ds_info *dp, struct ds_cap_state *cp,
 
 		printk(KERN_INFO "ds-%llu: Starting cpu %d...\n",
 		       dp->id, cpu);
-		err = cpu_up(cpu);
+		err = add_cpu(cpu);
 		if (err) {
 			__u32 res = DR_CPU_RES_FAILURE;
 			__u32 stat = DR_CPU_STAT_UNCONFIGURED;
@@ -611,7 +611,7 @@ static int dr_cpu_unconfigure(struct ds_info *dp,
 
 		printk(KERN_INFO "ds-%llu: Shutting down cpu %d...\n",
 		       dp->id, cpu);
-		err = cpu_down(cpu);
+		err = remove_cpu(cpu);
 		if (err)
 			dr_cpu_mark(resp, cpu, ncpus,
 				    DR_CPU_RES_FAILURE,
-- 
2.17.1


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

* [PATCH v3 10/15] parisc: Replace cpu_up/down with add/remove_cpu
       [not found] <20200223192942.18420-1-qais.yousef@arm.com>
                   ` (8 preceding siblings ...)
  2020-02-23 19:29 ` [PATCH v3 09/15] sparc: " Qais Yousef
@ 2020-02-23 19:29 ` Qais Yousef
  2020-02-23 19:29 ` [PATCH v3 11/15] driver: xen: Replace cpu_up/down with device_online/offline Qais Yousef
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 22+ messages in thread
From: Qais Yousef @ 2020-02-23 19:29 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Paul E . McKenney, Qais Yousef, James E.J. Bottomley,
	Helge Deller, Richard Fontana, Armijn Hemel, Greg Kroah-Hartman,
	linux-parisc, linux-kernel

The core device API performs extra housekeeping bits that are missing
from directly calling cpu_up/down.

See commit a6717c01ddc2 ("powerpc/rtas: use device model APIs and
serialization during LPM") for an example description of what might go
wrong.

This also prepares to make cpu_up/down a private interface for anything
but the cpu subsystem.

Acked-by: Helge Deller <deller@gmx.de>
Signed-off-by: Qais Yousef <qais.yousef@arm.com>
CC: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
CC: Helge Deller <deller@gmx.de>
CC: Richard Fontana <rfontana@redhat.com>
CC: Armijn Hemel <armijn@tjaldur.nl>
CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: linux-parisc@vger.kernel.org
CC: linux-kernel@vger.kernel.org
---

Helge, this now uses add_cpu() which you should be CCed on. I wasn't sure if
I can keep your Ack or remove it in this case. Please let me know if you need
more clarification.

 arch/parisc/kernel/processor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/parisc/kernel/processor.c b/arch/parisc/kernel/processor.c
index 13f771f74ee3..7f2d0c0ecc80 100644
--- a/arch/parisc/kernel/processor.c
+++ b/arch/parisc/kernel/processor.c
@@ -212,7 +212,7 @@ static int __init processor_probe(struct parisc_device *dev)
 #ifdef CONFIG_SMP
 	if (cpuid) {
 		set_cpu_present(cpuid, true);
-		cpu_up(cpuid);
+		add_cpu(cpuid);
 	}
 #endif
 
-- 
2.17.1


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

* [PATCH v3 11/15] driver: xen: Replace cpu_up/down with device_online/offline
       [not found] <20200223192942.18420-1-qais.yousef@arm.com>
                   ` (9 preceding siblings ...)
  2020-02-23 19:29 ` [PATCH v3 10/15] parisc: " Qais Yousef
@ 2020-02-23 19:29 ` Qais Yousef
  2020-02-23 19:29 ` [PATCH v3 12/15] firmware: psci: Replace cpu_up/down with add/remove_cpu Qais Yousef
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 22+ messages in thread
From: Qais Yousef @ 2020-02-23 19:29 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Paul E . McKenney, Qais Yousef, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, xen-devel, linux-kernel

The core device API performs extra housekeeping bits that are missing
from directly calling cpu_up/down.

See commit a6717c01ddc2 ("powerpc/rtas: use device model APIs and
serialization during LPM") for an example description of what might go
wrong.

This also prepares to make cpu_up/down a private interface for anything
but the cpu subsystem.

Reviewed-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Qais Yousef <qais.yousef@arm.com>
CC: Boris Ostrovsky <boris.ostrovsky@oracle.com>
CC: Juergen Gross <jgross@suse.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: xen-devel@lists.xenproject.org
CC: linux-kernel@vger.kernel.org
---

Juergen, there's a new add_cpu() which you should be CCed on. I wasn't sure if
I could safely convert this to use it since I couldn't find whether the
notifier already hold the lock or not. If you think remove_cpu() is safe, let
me know and I can send an updated patch.

 drivers/xen/cpu_hotplug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/xen/cpu_hotplug.c b/drivers/xen/cpu_hotplug.c
index f192b6f42da9..ec975decb5de 100644
--- a/drivers/xen/cpu_hotplug.c
+++ b/drivers/xen/cpu_hotplug.c
@@ -94,7 +94,7 @@ static int setup_cpu_watcher(struct notifier_block *notifier,
 
 	for_each_possible_cpu(cpu) {
 		if (vcpu_online(cpu) == 0) {
-			(void)cpu_down(cpu);
+			device_offline(get_cpu_device(cpu));
 			set_cpu_present(cpu, false);
 		}
 	}
-- 
2.17.1


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

* [PATCH v3 12/15] firmware: psci: Replace cpu_up/down with add/remove_cpu
       [not found] <20200223192942.18420-1-qais.yousef@arm.com>
                   ` (10 preceding siblings ...)
  2020-02-23 19:29 ` [PATCH v3 11/15] driver: xen: Replace cpu_up/down with device_online/offline Qais Yousef
@ 2020-02-23 19:29 ` Qais Yousef
  2020-02-23 19:29 ` [PATCH v3 13/15] torture: " Qais Yousef
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 22+ messages in thread
From: Qais Yousef @ 2020-02-23 19:29 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Paul E . McKenney, Qais Yousef, Mark Rutland, Lorenzo Pieralisi,
	linux-arm-kernel, linux-kernel

The core device API performs extra housekeeping bits that are missing
from directly calling cpu_up/down.

See commit a6717c01ddc2 ("powerpc/rtas: use device model APIs and
serialization during LPM") for an example description of what might go
wrong.

This also prepares to make cpu_up/down a private interface for anything
but the cpu subsystem.

Signed-off-by: Qais Yousef <qais.yousef@arm.com>
CC: Mark Rutland <mark.rutland@arm.com>
CC: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
CC: linux-arm-kernel@lists.infradead.org
CC: linux-kernel@vger.kernel.org
---
 drivers/firmware/psci/psci_checker.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/psci/psci_checker.c b/drivers/firmware/psci/psci_checker.c
index 6a445397771c..873841af8d57 100644
--- a/drivers/firmware/psci/psci_checker.c
+++ b/drivers/firmware/psci/psci_checker.c
@@ -84,7 +84,7 @@ static unsigned int down_and_up_cpus(const struct cpumask *cpus,
 
 	/* Try to power down all CPUs in the mask. */
 	for_each_cpu(cpu, cpus) {
-		int ret = cpu_down(cpu);
+		int ret = remove_cpu(cpu);
 
 		/*
 		 * cpu_down() checks the number of online CPUs before the TOS
@@ -116,7 +116,7 @@ static unsigned int down_and_up_cpus(const struct cpumask *cpus,
 
 	/* Try to power up all the CPUs that have been offlined. */
 	for_each_cpu(cpu, offlined_cpus) {
-		int ret = cpu_up(cpu);
+		int ret = add_cpu(cpu);
 
 		if (ret != 0) {
 			pr_err("Error occurred (%d) while trying "
-- 
2.17.1


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

* [PATCH v3 13/15] torture: Replace cpu_up/down with add/remove_cpu
       [not found] <20200223192942.18420-1-qais.yousef@arm.com>
                   ` (11 preceding siblings ...)
  2020-02-23 19:29 ` [PATCH v3 12/15] firmware: psci: Replace cpu_up/down with add/remove_cpu Qais Yousef
@ 2020-02-23 19:29 ` Qais Yousef
  2020-02-24  2:53   ` Paul E. McKenney
  2020-02-23 19:29 ` [PATCH v3 14/15] smp: Create a new function to bringup nonboot cpus online Qais Yousef
  2020-02-23 19:29 ` [PATCH v3 15/15] cpu: Hide cpu_up/down Qais Yousef
  14 siblings, 1 reply; 22+ messages in thread
From: Qais Yousef @ 2020-02-23 19:29 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Paul E . McKenney, Qais Yousef, Davidlohr Bueso, Josh Triplett,
	linux-kernel

The core device API performs extra housekeeping bits that are missing
from directly calling cpu_up/down.

See commit a6717c01ddc2 ("powerpc/rtas: use device model APIs and
serialization during LPM") for an example description of what might go
wrong.

This also prepares to make cpu_up/down a private interface for anything
but the cpu subsystem.

Signed-off-by: Qais Yousef <qais.yousef@arm.com>
CC: Davidlohr Bueso <dave@stgolabs.net>
CC: "Paul E. McKenney" <paulmck@kernel.org>
CC: Josh Triplett <josh@joshtriplett.org>
CC: linux-kernel@vger.kernel.org
---
 kernel/torture.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/kernel/torture.c b/kernel/torture.c
index 7c13f5558b71..a479689eac73 100644
--- a/kernel/torture.c
+++ b/kernel/torture.c
@@ -97,7 +97,7 @@ bool torture_offline(int cpu, long *n_offl_attempts, long *n_offl_successes,
 			 torture_type, cpu);
 	starttime = jiffies;
 	(*n_offl_attempts)++;
-	ret = cpu_down(cpu);
+	ret = remove_cpu(cpu);
 	if (ret) {
 		if (verbose)
 			pr_alert("%s" TORTURE_FLAG
@@ -148,7 +148,7 @@ bool torture_online(int cpu, long *n_onl_attempts, long *n_onl_successes,
 			 torture_type, cpu);
 	starttime = jiffies;
 	(*n_onl_attempts)++;
-	ret = cpu_up(cpu);
+	ret = add_cpu(cpu);
 	if (ret) {
 		if (verbose)
 			pr_alert("%s" TORTURE_FLAG
@@ -192,17 +192,18 @@ torture_onoff(void *arg)
 	for_each_online_cpu(cpu)
 		maxcpu = cpu;
 	WARN_ON(maxcpu < 0);
-	if (!IS_MODULE(CONFIG_TORTURE_TEST))
+	if (!IS_MODULE(CONFIG_TORTURE_TEST)) {
 		for_each_possible_cpu(cpu) {
 			if (cpu_online(cpu))
 				continue;
-			ret = cpu_up(cpu);
+			ret = add_cpu(cpu);
 			if (ret && verbose) {
 				pr_alert("%s" TORTURE_FLAG
 					 "%s: Initial online %d: errno %d\n",
 					 __func__, torture_type, cpu, ret);
 			}
 		}
+	}
 
 	if (maxcpu == 0) {
 		VERBOSE_TOROUT_STRING("Only one CPU, so CPU-hotplug testing is disabled");
-- 
2.17.1


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

* [PATCH v3 14/15] smp: Create a new function to bringup nonboot cpus online
       [not found] <20200223192942.18420-1-qais.yousef@arm.com>
                   ` (12 preceding siblings ...)
  2020-02-23 19:29 ` [PATCH v3 13/15] torture: " Qais Yousef
@ 2020-02-23 19:29 ` Qais Yousef
  2020-02-23 19:29 ` [PATCH v3 15/15] cpu: Hide cpu_up/down Qais Yousef
  14 siblings, 0 replies; 22+ messages in thread
From: Qais Yousef @ 2020-02-23 19:29 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Paul E . McKenney, Qais Yousef, Josh Poimboeuf,
	Peter Zijlstra (Intel),
	Jiri Kosina, Nicholas Piggin, Daniel Lezcano, Ingo Molnar,
	Eiichi Tsukata, Zhenzhong Duan, Nadav Amit, Greg Kroah-Hartman,
	Rafael J. Wysocki, linux-kernel

This is the last direct user of cpu_up() before we can hide it now as
internal implementation detail of the cpu subsystem.

Signed-off-by: Qais Yousef <qais.yousef@arm.com>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Josh Poimboeuf <jpoimboe@redhat.com>
CC: "Peter Zijlstra (Intel)" <peterz@infradead.org>
CC: Jiri Kosina <jkosina@suse.cz>
CC: Nicholas Piggin <npiggin@gmail.com>
CC: Daniel Lezcano <daniel.lezcano@linaro.org>
CC: Ingo Molnar <mingo@kernel.org>
CC: Eiichi Tsukata <devel@etsukata.com>
CC: Zhenzhong Duan <zhenzhong.duan@oracle.com>
CC: Nadav Amit <namit@vmware.com>
CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
CC: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
CC: linux-kernel@vger.kernel.org
---
 include/linux/cpu.h |  1 +
 kernel/cpu.c        | 12 ++++++++++++
 kernel/smp.c        |  9 +--------
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/include/linux/cpu.h b/include/linux/cpu.h
index aebe8186cb07..3d3caecef395 100644
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -94,6 +94,7 @@ void notify_cpu_starting(unsigned int cpu);
 extern void cpu_maps_update_begin(void);
 extern void cpu_maps_update_done(void);
 extern int bringup_hibernate_cpu(unsigned int sleep_cpu);
+extern void smp_bringup_nonboot_cpus(unsigned int setup_max_cpus);
 
 #else	/* CONFIG_SMP */
 #define cpuhp_tasks_frozen	0
diff --git a/kernel/cpu.c b/kernel/cpu.c
index bf39c5bfb6d9..7c6aa427a3a3 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -1299,6 +1299,18 @@ int bringup_hibernate_cpu(unsigned int sleep_cpu)
 	return 0;
 }
 
+void smp_bringup_nonboot_cpus(unsigned int setup_max_cpus)
+{
+	unsigned int cpu;
+
+	for_each_present_cpu(cpu) {
+		if (num_online_cpus() >= setup_max_cpus)
+			break;
+		if (!cpu_online(cpu))
+			cpu_up(cpu);
+	}
+}
+
 #ifdef CONFIG_PM_SLEEP_SMP
 static cpumask_var_t frozen_cpus;
 
diff --git a/kernel/smp.c b/kernel/smp.c
index d0ada39eb4d4..9e793cfd6128 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -589,20 +589,13 @@ void __init setup_nr_cpu_ids(void)
 void __init smp_init(void)
 {
 	int num_nodes, num_cpus;
-	unsigned int cpu;
 
 	idle_threads_init();
 	cpuhp_threads_init();
 
 	pr_info("Bringing up secondary CPUs ...\n");
 
-	/* FIXME: This should be done in userspace --RR */
-	for_each_present_cpu(cpu) {
-		if (num_online_cpus() >= setup_max_cpus)
-			break;
-		if (!cpu_online(cpu))
-			cpu_up(cpu);
-	}
+	smp_bringup_nonboot_cpus(setup_max_cpus);
 
 	num_nodes = num_online_nodes();
 	num_cpus  = num_online_cpus();
-- 
2.17.1


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

* [PATCH v3 15/15] cpu: Hide cpu_up/down
       [not found] <20200223192942.18420-1-qais.yousef@arm.com>
                   ` (13 preceding siblings ...)
  2020-02-23 19:29 ` [PATCH v3 14/15] smp: Create a new function to bringup nonboot cpus online Qais Yousef
@ 2020-02-23 19:29 ` Qais Yousef
  14 siblings, 0 replies; 22+ messages in thread
From: Qais Yousef @ 2020-02-23 19:29 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Paul E . McKenney, Qais Yousef, Greg Kroah-Hartman,
	Rafael J. Wysocki, Josh Poimboeuf, Nicholas Piggin,
	Peter Zijlstra (Intel),
	Jiri Kosina, Daniel Lezcano, Eiichi Tsukata, Zhenzhong Duan,
	Ingo Molnar, Pavankumar Kondeti, linux-kernel

Provide a special exported function for the device core to bring a cpu
up/down and hide the real cpu_up/down as they are treated as private
functions. cpu_up/down are lower level API and users outside the cpu
subsystem should use add/remove_cpu() which will take care of extra
housekeeping work like keeping sysfs in sync.

Signed-off-by: Qais Yousef <qais.yousef@arm.com>
CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
CC: "Rafael J. Wysocki" <rafael@kernel.org>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Josh Poimboeuf <jpoimboe@redhat.com>
CC: Nicholas Piggin <npiggin@gmail.com>
CC: "Peter Zijlstra (Intel)" <peterz@infradead.org>
CC: Jiri Kosina <jkosina@suse.cz>
CC: Daniel Lezcano <daniel.lezcano@linaro.org>
CC: Eiichi Tsukata <devel@etsukata.com>
CC: Zhenzhong Duan <zhenzhong.duan@oracle.com>
CC: Ingo Molnar <mingo@kernel.org>
CC: Pavankumar Kondeti <pkondeti@codeaurora.org>
CC: linux-kernel@vger.kernel.org
---
 drivers/base/cpu.c  |  4 ++--
 include/linux/cpu.h |  4 ++--
 kernel/cpu.c        | 32 ++++++++++++++++++++++++++++----
 3 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 6265871a4af2..9a134cd362ee 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -55,7 +55,7 @@ static int cpu_subsys_online(struct device *dev)
 	if (from_nid == NUMA_NO_NODE)
 		return -ENODEV;
 
-	ret = cpu_up(cpuid);
+	ret = cpu_subsys_up(dev);
 	/*
 	 * When hot adding memory to memoryless node and enabling a cpu
 	 * on the node, node number of the cpu may internally change.
@@ -69,7 +69,7 @@ static int cpu_subsys_online(struct device *dev)
 
 static int cpu_subsys_offline(struct device *dev)
 {
-	return cpu_down(dev->id);
+	return cpu_subsys_down(dev);
 }
 
 void unregister_cpu(struct cpu *cpu)
diff --git a/include/linux/cpu.h b/include/linux/cpu.h
index 3d3caecef395..e1bbd8d6ecec 100644
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -88,8 +88,8 @@ extern ssize_t arch_cpu_release(const char *, size_t);
 
 #ifdef CONFIG_SMP
 extern bool cpuhp_tasks_frozen;
-int cpu_up(unsigned int cpu);
 int add_cpu(unsigned int cpu);
+int cpu_subsys_up(struct device *dev);
 void notify_cpu_starting(unsigned int cpu);
 extern void cpu_maps_update_begin(void);
 extern void cpu_maps_update_done(void);
@@ -120,8 +120,8 @@ extern void lockdep_assert_cpus_held(void);
 extern void cpu_hotplug_disable(void);
 extern void cpu_hotplug_enable(void);
 void clear_tasks_mm_cpumask(int cpu);
-int cpu_down(unsigned int cpu);
 int remove_cpu(unsigned int cpu);
+int cpu_subsys_down(struct device *dev);
 extern void smp_shutdown_nonboot_cpus(unsigned int primary_cpu);
 
 #else /* CONFIG_HOTPLUG_CPU */
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 7c6aa427a3a3..017e16dfcccd 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -1051,11 +1051,23 @@ static int do_cpu_down(unsigned int cpu, enum cpuhp_state target)
 	return err;
 }
 
-int cpu_down(unsigned int cpu)
+static int cpu_down(unsigned int cpu)
 {
 	return do_cpu_down(cpu, CPUHP_OFFLINE);
 }
-EXPORT_SYMBOL(cpu_down);
+
+/**
+ * cpu_subsys_down - Bring down a cpu device
+ * @dev: Pointer to the cpu device to offline
+ *
+ * This function is meant to be used by device core cpu subsystem only.
+ *
+ * Other subsystems should use remove_cpu() instead.
+ */
+int cpu_subsys_down(struct device *dev)
+{
+	return cpu_down(dev->id);
+}
 
 int remove_cpu(unsigned int cpu)
 {
@@ -1257,11 +1269,23 @@ static int do_cpu_up(unsigned int cpu, enum cpuhp_state target)
 	return err;
 }
 
-int cpu_up(unsigned int cpu)
+static int cpu_up(unsigned int cpu)
 {
 	return do_cpu_up(cpu, CPUHP_ONLINE);
 }
-EXPORT_SYMBOL_GPL(cpu_up);
+
+/**
+ * cpu_subsys_up - Bring up a cpu device
+ * @dev: Pointer to the cpu device to online
+ *
+ * This function is meant to be used by device core cpu subsystem only.
+ *
+ * Other subsystems should use add_cpu() instead.
+ */
+int cpu_subsys_up(struct device *dev)
+{
+	return cpu_up(dev->id);
+}
 
 int add_cpu(unsigned int cpu)
 {
-- 
2.17.1


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

* Re: [PATCH v3 13/15] torture: Replace cpu_up/down with add/remove_cpu
  2020-02-23 19:29 ` [PATCH v3 13/15] torture: " Qais Yousef
@ 2020-02-24  2:53   ` Paul E. McKenney
  0 siblings, 0 replies; 22+ messages in thread
From: Paul E. McKenney @ 2020-02-24  2:53 UTC (permalink / raw)
  To: Qais Yousef; +Cc: Thomas Gleixner, Davidlohr Bueso, Josh Triplett, linux-kernel

On Sun, Feb 23, 2020 at 07:29:40PM +0000, Qais Yousef wrote:
> The core device API performs extra housekeeping bits that are missing
> from directly calling cpu_up/down.
> 
> See commit a6717c01ddc2 ("powerpc/rtas: use device model APIs and
> serialization during LPM") for an example description of what might go
> wrong.
> 
> This also prepares to make cpu_up/down a private interface for anything
> but the cpu subsystem.
> 
> Signed-off-by: Qais Yousef <qais.yousef@arm.com>
> CC: Davidlohr Bueso <dave@stgolabs.net>
> CC: "Paul E. McKenney" <paulmck@kernel.org>
> CC: Josh Triplett <josh@joshtriplett.org>
> CC: linux-kernel@vger.kernel.org

From a torture-test perspective:

Acked-by: Paul E. McKenney <paulmck@kernel.org>

> ---
>  kernel/torture.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/torture.c b/kernel/torture.c
> index 7c13f5558b71..a479689eac73 100644
> --- a/kernel/torture.c
> +++ b/kernel/torture.c
> @@ -97,7 +97,7 @@ bool torture_offline(int cpu, long *n_offl_attempts, long *n_offl_successes,
>  			 torture_type, cpu);
>  	starttime = jiffies;
>  	(*n_offl_attempts)++;
> -	ret = cpu_down(cpu);
> +	ret = remove_cpu(cpu);
>  	if (ret) {
>  		if (verbose)
>  			pr_alert("%s" TORTURE_FLAG
> @@ -148,7 +148,7 @@ bool torture_online(int cpu, long *n_onl_attempts, long *n_onl_successes,
>  			 torture_type, cpu);
>  	starttime = jiffies;
>  	(*n_onl_attempts)++;
> -	ret = cpu_up(cpu);
> +	ret = add_cpu(cpu);
>  	if (ret) {
>  		if (verbose)
>  			pr_alert("%s" TORTURE_FLAG
> @@ -192,17 +192,18 @@ torture_onoff(void *arg)
>  	for_each_online_cpu(cpu)
>  		maxcpu = cpu;
>  	WARN_ON(maxcpu < 0);
> -	if (!IS_MODULE(CONFIG_TORTURE_TEST))
> +	if (!IS_MODULE(CONFIG_TORTURE_TEST)) {
>  		for_each_possible_cpu(cpu) {
>  			if (cpu_online(cpu))
>  				continue;
> -			ret = cpu_up(cpu);
> +			ret = add_cpu(cpu);
>  			if (ret && verbose) {
>  				pr_alert("%s" TORTURE_FLAG
>  					 "%s: Initial online %d: errno %d\n",
>  					 __func__, torture_type, cpu, ret);
>  			}
>  		}
> +	}
>  
>  	if (maxcpu == 0) {
>  		VERBOSE_TOROUT_STRING("Only one CPU, so CPU-hotplug testing is disabled");
> -- 
> 2.17.1
> 

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

* Re: [PATCH v3 05/15] arm64: Don't use disable_nonboot_cpus()
  2020-02-23 19:29 ` [PATCH v3 05/15] arm64: " Qais Yousef
@ 2020-03-17 11:21   ` Catalin Marinas
  2020-03-20 14:07     ` Qais Yousef
  0 siblings, 1 reply; 22+ messages in thread
From: Catalin Marinas @ 2020-03-17 11:21 UTC (permalink / raw)
  To: Qais Yousef
  Cc: Thomas Gleixner, Paul E . McKenney, Will Deacon,
	linux-arm-kernel, linux-kernel

On Sun, Feb 23, 2020 at 07:29:32PM +0000, Qais Yousef wrote:
> disable_nonboot_cpus() is not safe to use when doing machine_down(),
> because it relies on freeze_secondary_cpus() which in turn is
> a suspend/resume related freeze and could abort if the logic detects any
> pending activities that can prevent finishing the offlining process.
> 
> Beside disable_nonboot_cpus() is dependent on CONFIG_PM_SLEEP_SMP which
> is an othogonal config to rely on to ensure this function works
> correctly.
> 
> Use `reboot_cpu` variable instead of hardcoding 0 as the reboot cpu.
> 
> Signed-off-by: Qais Yousef <qais.yousef@arm.com>
> CC: Catalin Marinas <catalin.marinas@arm.com>
> CC: Will Deacon <will@kernel.org>
> CC: linux-arm-kernel@lists.infradead.org
> CC: linux-kernel@vger.kernel.org

I'm not sure whether these patches have been queued already (still
unread in my inbox), so here it is:

Acked-by: Catalin Marinas <catalin.marinas@arm.com>

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

* Re: [PATCH v3 06/15] arm64: hibernate.c: Create a new function to handle cpu_up(sleep_cpu)
  2020-02-23 19:29 ` [PATCH v3 06/15] arm64: hibernate.c: Create a new function to handle cpu_up(sleep_cpu) Qais Yousef
@ 2020-03-17 11:21   ` Catalin Marinas
  0 siblings, 0 replies; 22+ messages in thread
From: Catalin Marinas @ 2020-03-17 11:21 UTC (permalink / raw)
  To: Qais Yousef
  Cc: Thomas Gleixner, Paul E . McKenney, Will Deacon, Steve Capper,
	Richard Fontana, James Morse, Mark Rutland, Josh Poimboeuf,
	Ingo Molnar, Peter Zijlstra (Intel),
	Nicholas Piggin, Daniel Lezcano, Jiri Kosina, Pavankumar Kondeti,
	Zhenzhong Duan, linux-arm-kernel, linux-kernel

On Sun, Feb 23, 2020 at 07:29:33PM +0000, Qais Yousef wrote:
> In preparation to make cpu_up/down private - move the user in arm64
> hibernate.c to use a new generic function that provides what arm64
> needs.
> 
> Signed-off-by: Qais Yousef <qais.yousef@arm.com>
> CC: Catalin Marinas <catalin.marinas@arm.com>
> CC: Will Deacon <will@kernel.org>
> CC: Steve Capper <steve.capper@arm.com>
> CC: Richard Fontana <rfontana@redhat.com>
> CC: James Morse <james.morse@arm.com>
> CC: Mark Rutland <mark.rutland@arm.com>
> CC: Thomas Gleixner <tglx@linutronix.de>
> CC: Josh Poimboeuf <jpoimboe@redhat.com>
> CC: Ingo Molnar <mingo@kernel.org>
> CC: "Peter Zijlstra (Intel)" <peterz@infradead.org>
> CC: Nicholas Piggin <npiggin@gmail.com>
> CC: Daniel Lezcano <daniel.lezcano@linaro.org>
> CC: Jiri Kosina <jkosina@suse.cz>
> CC: Pavankumar Kondeti <pkondeti@codeaurora.org>
> CC: Zhenzhong Duan <zhenzhong.duan@oracle.com>
> CC: linux-arm-kernel@lists.infradead.org
> CC: linux-kernel@vger.kernel.org

Acked-by: Catalin Marinas <catalin.marinas@arm.com>

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

* Re: [PATCH v3 04/15] arm: Don't use disable_nonboot_cpus()
  2020-02-23 19:29 ` [PATCH v3 04/15] arm: Don't use disable_nonboot_cpus() Qais Yousef
@ 2020-03-20 11:04   ` Qais Yousef
  2020-03-20 13:07     ` Russell King - ARM Linux admin
  0 siblings, 1 reply; 22+ messages in thread
From: Qais Yousef @ 2020-03-20 11:04 UTC (permalink / raw)
  To: Russell King
  Cc: Paul E . McKenney, linux-arm-kernel, linux-kernel, Thomas Gleixner

On 02/23/20 19:29, Qais Yousef wrote:
> disable_nonboot_cpus() is not safe to use when doing machine_down(),
> because it relies on freeze_secondary_cpus() which in turn is
> a suspend/resume related freeze and could abort if the logic detects any
> pending activities that can prevent finishing the offlining process.
> 
> Beside disable_nonboot_cpus() is dependent on CONFIG_PM_SLEEP_SMP which
> is an othogonal config to rely on to ensure this function works
> correctly.
> 
> Use `reboot_cpu` variable instead of hardcoding 0 as the reboot cpu.
> 
> Signed-off-by: Qais Yousef <qais.yousef@arm.com>
> CC: Russell King <linux@armlinux.org.uk>
> CC: linux-arm-kernel@lists.infradead.org
> CC: linux-kernel@vger.kernel.org
> ---

Hi Russel

Does the updated version look good to you now?

Thanks

--
Qais Yousef

>  arch/arm/kernel/reboot.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm/kernel/reboot.c b/arch/arm/kernel/reboot.c
> index bb18ed0539f4..0ce388f15422 100644
> --- a/arch/arm/kernel/reboot.c
> +++ b/arch/arm/kernel/reboot.c
> @@ -88,11 +88,11 @@ void soft_restart(unsigned long addr)
>   * 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.
> + * functionality embodied in smp_shutdown_nonboot_cpus() to achieve this.
>   */
>  void machine_shutdown(void)
>  {
> -	disable_nonboot_cpus();
> +	smp_shutdown_nonboot_cpus(reboot_cpu);
>  }
>  
>  /*
> -- 
> 2.17.1
> 

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

* Re: [PATCH v3 04/15] arm: Don't use disable_nonboot_cpus()
  2020-03-20 11:04   ` Qais Yousef
@ 2020-03-20 13:07     ` Russell King - ARM Linux admin
  2020-03-20 13:41       ` Qais Yousef
  0 siblings, 1 reply; 22+ messages in thread
From: Russell King - ARM Linux admin @ 2020-03-20 13:07 UTC (permalink / raw)
  To: Qais Yousef
  Cc: Paul E . McKenney, linux-arm-kernel, linux-kernel, Thomas Gleixner

On Fri, Mar 20, 2020 at 11:04:31AM +0000, Qais Yousef wrote:
> On 02/23/20 19:29, Qais Yousef wrote:
> > disable_nonboot_cpus() is not safe to use when doing machine_down(),
> > because it relies on freeze_secondary_cpus() which in turn is
> > a suspend/resume related freeze and could abort if the logic detects any
> > pending activities that can prevent finishing the offlining process.
> > 
> > Beside disable_nonboot_cpus() is dependent on CONFIG_PM_SLEEP_SMP which
> > is an othogonal config to rely on to ensure this function works
> > correctly.
> > 
> > Use `reboot_cpu` variable instead of hardcoding 0 as the reboot cpu.

I think that should be a separate change - you have two separate
changes in this patch:

1. to switch to using the new helper.
2. to change the CPU that we potentially use for the final steps of
   shutdown

These should be two seperate changes, so if (2) causes a regression
it can be reverted independently of (1).

> > 
> > Signed-off-by: Qais Yousef <qais.yousef@arm.com>
> > CC: Russell King <linux@armlinux.org.uk>
> > CC: linux-arm-kernel@lists.infradead.org
> > CC: linux-kernel@vger.kernel.org
> > ---
> 
> Hi Russel
> 
> Does the updated version look good to you now?
> 
> Thanks
> 
> --
> Qais Yousef
> 
> >  arch/arm/kernel/reboot.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/arm/kernel/reboot.c b/arch/arm/kernel/reboot.c
> > index bb18ed0539f4..0ce388f15422 100644
> > --- a/arch/arm/kernel/reboot.c
> > +++ b/arch/arm/kernel/reboot.c
> > @@ -88,11 +88,11 @@ void soft_restart(unsigned long addr)
> >   * 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.
> > + * functionality embodied in smp_shutdown_nonboot_cpus() to achieve this.
> >   */
> >  void machine_shutdown(void)
> >  {
> > -	disable_nonboot_cpus();
> > +	smp_shutdown_nonboot_cpus(reboot_cpu);
> >  }
> >  
> >  /*
> > -- 
> > 2.17.1
> > 
> 

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 10.2Mbps down 587kbps up

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

* Re: [PATCH v3 04/15] arm: Don't use disable_nonboot_cpus()
  2020-03-20 13:07     ` Russell King - ARM Linux admin
@ 2020-03-20 13:41       ` Qais Yousef
  0 siblings, 0 replies; 22+ messages in thread
From: Qais Yousef @ 2020-03-20 13:41 UTC (permalink / raw)
  To: Russell King - ARM Linux admin
  Cc: Paul E . McKenney, linux-arm-kernel, linux-kernel, Thomas Gleixner

On 03/20/20 13:07, Russell King - ARM Linux admin wrote:
> On Fri, Mar 20, 2020 at 11:04:31AM +0000, Qais Yousef wrote:
> > On 02/23/20 19:29, Qais Yousef wrote:
> > > disable_nonboot_cpus() is not safe to use when doing machine_down(),
> > > because it relies on freeze_secondary_cpus() which in turn is
> > > a suspend/resume related freeze and could abort if the logic detects any
> > > pending activities that can prevent finishing the offlining process.
> > > 
> > > Beside disable_nonboot_cpus() is dependent on CONFIG_PM_SLEEP_SMP which
> > > is an othogonal config to rely on to ensure this function works
> > > correctly.
> > > 
> > > Use `reboot_cpu` variable instead of hardcoding 0 as the reboot cpu.
> 
> I think that should be a separate change - you have two separate
> changes in this patch:
> 
> 1. to switch to using the new helper.
> 2. to change the CPU that we potentially use for the final steps of
>    shutdown
> 
> These should be two seperate changes, so if (2) causes a regression
> it can be reverted independently of (1).

Okay will do.

Thanks

--
Qais Yousef

> 
> > > 
> > > Signed-off-by: Qais Yousef <qais.yousef@arm.com>
> > > CC: Russell King <linux@armlinux.org.uk>
> > > CC: linux-arm-kernel@lists.infradead.org
> > > CC: linux-kernel@vger.kernel.org
> > > ---
> > 
> > Hi Russel
> > 
> > Does the updated version look good to you now?
> > 
> > Thanks
> > 
> > --
> > Qais Yousef
> > 
> > >  arch/arm/kernel/reboot.c | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/arch/arm/kernel/reboot.c b/arch/arm/kernel/reboot.c
> > > index bb18ed0539f4..0ce388f15422 100644
> > > --- a/arch/arm/kernel/reboot.c
> > > +++ b/arch/arm/kernel/reboot.c
> > > @@ -88,11 +88,11 @@ void soft_restart(unsigned long addr)
> > >   * 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.
> > > + * functionality embodied in smp_shutdown_nonboot_cpus() to achieve this.
> > >   */
> > >  void machine_shutdown(void)
> > >  {
> > > -	disable_nonboot_cpus();
> > > +	smp_shutdown_nonboot_cpus(reboot_cpu);
> > >  }
> > >  
> > >  /*
> > > -- 
> > > 2.17.1
> > > 
> > 
> 
> -- 
> RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
> FTTC broadband for 0.8mile line in suburbia: sync at 10.2Mbps down 587kbps up

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

* Re: [PATCH v3 05/15] arm64: Don't use disable_nonboot_cpus()
  2020-03-17 11:21   ` Catalin Marinas
@ 2020-03-20 14:07     ` Qais Yousef
  0 siblings, 0 replies; 22+ messages in thread
From: Qais Yousef @ 2020-03-20 14:07 UTC (permalink / raw)
  To: Catalin Marinas
  Cc: Thomas Gleixner, Paul E . McKenney, Will Deacon,
	linux-arm-kernel, linux-kernel

On 03/17/20 11:21, Catalin Marinas wrote:
> On Sun, Feb 23, 2020 at 07:29:32PM +0000, Qais Yousef wrote:
> > disable_nonboot_cpus() is not safe to use when doing machine_down(),
> > because it relies on freeze_secondary_cpus() which in turn is
> > a suspend/resume related freeze and could abort if the logic detects any
> > pending activities that can prevent finishing the offlining process.
> > 
> > Beside disable_nonboot_cpus() is dependent on CONFIG_PM_SLEEP_SMP which
> > is an othogonal config to rely on to ensure this function works
> > correctly.
> > 
> > Use `reboot_cpu` variable instead of hardcoding 0 as the reboot cpu.
> > 
> > Signed-off-by: Qais Yousef <qais.yousef@arm.com>
> > CC: Catalin Marinas <catalin.marinas@arm.com>
> > CC: Will Deacon <will@kernel.org>
> > CC: linux-arm-kernel@lists.infradead.org
> > CC: linux-kernel@vger.kernel.org
> 
> I'm not sure whether these patches have been queued already (still
> unread in my inbox), so here it is:
> 
> Acked-by: Catalin Marinas <catalin.marinas@arm.com>

Thanks Catalin!

Russel has requested to split the arm patch into 2 so that the change to
use reboot_cpu is in a separate patch. I'll do the same for arm64 to stay
consistent. I'll add your Acked-by to both patches if that's okay.

Please shout if you have any objection.

Thanks

--
Qais Yousef

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

end of thread, other threads:[~2020-03-20 14:07 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200223192942.18420-1-qais.yousef@arm.com>
2020-02-23 19:29 ` [PATCH v3 01/15] cpu: Add new {add,remove}_cpu() functions Qais Yousef
2020-02-23 19:29 ` [PATCH v3 02/15] smp: Create a new function to shutdown nonboot cpus Qais Yousef
2020-02-23 19:29 ` [PATCH v3 03/15] ia64: Replace cpu_down with smp_shutdown_nonboot_cpus() Qais Yousef
2020-02-23 19:29 ` [PATCH v3 04/15] arm: Don't use disable_nonboot_cpus() Qais Yousef
2020-03-20 11:04   ` Qais Yousef
2020-03-20 13:07     ` Russell King - ARM Linux admin
2020-03-20 13:41       ` Qais Yousef
2020-02-23 19:29 ` [PATCH v3 05/15] arm64: " Qais Yousef
2020-03-17 11:21   ` Catalin Marinas
2020-03-20 14:07     ` Qais Yousef
2020-02-23 19:29 ` [PATCH v3 06/15] arm64: hibernate.c: Create a new function to handle cpu_up(sleep_cpu) Qais Yousef
2020-03-17 11:21   ` Catalin Marinas
2020-02-23 19:29 ` [PATCH v3 07/15] x86: Replace cpu_up/down with add/remove_cpu Qais Yousef
2020-02-23 19:29 ` [PATCH v3 08/15] powerpc: " Qais Yousef
2020-02-23 19:29 ` [PATCH v3 09/15] sparc: " Qais Yousef
2020-02-23 19:29 ` [PATCH v3 10/15] parisc: " Qais Yousef
2020-02-23 19:29 ` [PATCH v3 11/15] driver: xen: Replace cpu_up/down with device_online/offline Qais Yousef
2020-02-23 19:29 ` [PATCH v3 12/15] firmware: psci: Replace cpu_up/down with add/remove_cpu Qais Yousef
2020-02-23 19:29 ` [PATCH v3 13/15] torture: " Qais Yousef
2020-02-24  2:53   ` Paul E. McKenney
2020-02-23 19:29 ` [PATCH v3 14/15] smp: Create a new function to bringup nonboot cpus online Qais Yousef
2020-02-23 19:29 ` [PATCH v3 15/15] cpu: Hide cpu_up/down Qais Yousef

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).