[PATCH 1/1] hotplug-cpu.c: show 'last online CPU' error in dlpar_cpu_remove()

Daniel Henrique Barboza danielhb413 at gmail.com
Sat Mar 6 04:38:45 AEDT 2021


Of all the reasons that dlpar_cpu_remove() can fail, the 'last online
CPU' is one that can be caused directly by the user offlining CPUs
in a partition/virtual machine that has hotplugged CPUs. Trying to
reclaim a hotplugged CPU can fail if the CPU is now the last online in
the system. This is easily reproduced using QEMU [1].

Throwing a more specific error message for this case, instead of just
"Failed to offline CPU", makes it clearer that the error is in fact a
known error situation instead of other generic/unknown cause.

[1] https://bugzilla.redhat.com/1911414

Signed-off-by: Daniel Henrique Barboza <danielhb413 at gmail.com>
---
 arch/powerpc/platforms/pseries/hotplug-cpu.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c b/arch/powerpc/platforms/pseries/hotplug-cpu.c
index 12cbffd3c2e3..134f393f09e1 100644
--- a/arch/powerpc/platforms/pseries/hotplug-cpu.c
+++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c
@@ -514,7 +514,17 @@ static ssize_t dlpar_cpu_remove(struct device_node *dn, u32 drc_index)
 
 	rc = dlpar_offline_cpu(dn);
 	if (rc) {
-		pr_warn("Failed to offline CPU %pOFn, rc: %d\n", dn, rc);
+		/* dlpar_offline_cpu will return -EBUSY from cpu_down() (via
+		 * device_offline()) in 2 cases: cpu_hotplug_disable is true or
+		 * there is only one CPU left. Warn the user about the second
+		 * since this can happen with user offlining CPUs and then
+		 * attempting hotunplugs.
+		 */
+		if (rc == -EBUSY && num_online_cpus() == 1)
+			pr_warn("Unable to remove last online CPU %pOFn\n", dn);
+		else
+			pr_warn("Failed to offline CPU %pOFn, rc: %d\n", dn, rc);
+
 		return -EINVAL;
 	}
 
-- 
2.29.2



More information about the Linuxppc-dev mailing list