From b5f7ac95d834576294f91bd00e5a01c18f397327 Mon Sep 17 00:00:00 2001 From: Tobias Huschle Date: Tue, 16 Jan 2024 13:12:45 +0100 Subject: [PATCH] cpuplugd: adjust to CPU 0 being no longer hotpluggable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With kernel commit 496bb034f4ff ("s390/smp: disallow CPU hotplug of CPU 0") it is no longer possible to hotplug CPU 0. As a side effect, the sysfs handle /sys/devices/system/cpu/cpu0/online does no longer exist. Since cpuplugd relies on checking all online handles of all CPUs, this change causes cpuplugd to fail as it interprets a non existing online file as an indicator that no other CPUs with higher IDs exist as well. This leads to cpuplugd assuming that there are no CPUs available. Instead of checking for the online file, it is preferable to check for the existence of the parent folder to verify the existence of a CPU. As a consequence, all other checks for non-existing online files must now imply that the CPU is online, but not hotpluggable. Signed-off-by: Tobias Huschle Tested-by: Mete Durlu Reviewed-by: Gerald Schaefer Signed-off-by: Jan Höppner --- cpuplugd/cpu.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cpuplugd/cpu.c b/cpuplugd/cpu.c index eda09776..03f48ab1 100644 --- a/cpuplugd/cpu.c +++ b/cpuplugd/cpu.c @@ -25,7 +25,7 @@ int get_numcpus() for (i = 0; ; i++) { /* check whether file exists and is readable */ - sprintf(path, "/sys/devices/system/cpu/cpu%d/online", i); + sprintf(path, "/sys/devices/system/cpu/cpu%d", i); if (access(path, R_OK) == 0) number++; else @@ -45,11 +45,13 @@ int get_num_online_cpus() int status = 0; int value_of_onlinefile, rc; - for (i = 0; i <= get_numcpus(); i++) { + for (i = 0; i < get_numcpus(); i++) { /* check wether file exists and is readable */ sprintf(path, "/sys/devices/system/cpu/cpu%d/online", i); - if (access(path, R_OK) != 0) + if (access(path, R_OK) != 0) { + status++; continue; + } filp = fopen(path, "r"); if (!filp) cpuplugd_exit("Cannot open cpu online file: " @@ -101,10 +103,8 @@ int hotplug(int cpuid) cpuid); return -1; } - } else { - cpuplugd_error("hotplugging cpu with id %d failed\n", cpuid); - return -1; } + cpuplugd_debug("cpu with id %d cannot be hotplugged\n", cpuid); return -1; } @@ -135,9 +135,8 @@ int hotunplug(int cpuid) fclose(filp); if (state == 0) return 1; - } else { - cpuplugd_error("unplugging cpu with id %d failed\n", cpuid); } + cpuplugd_debug("cpu with id %d cannot be hotunplugged\n", cpuid); return retval; } @@ -163,6 +162,8 @@ int is_online(int cpuid) retval = 0; } fclose(filp); + } else { + retval = 1; } return retval; }