Skip to contentSkip to conversation

s390/smp: Reflect (de)configured CPUs to cpu_enabled_mask

PATCH Applied Mete Durlu 4 participants 4 messages Jul 23 – Jul 29 s390

lore
Share & tools
lore

Mete Durlu

author
#0 lore raw

PATCH 1/1 s390/smp: Reflect (de)configured CPUs to cpu_enabled_mask

On s390, CPUs can be in a state where it is not possible to hotplug them online before certain prequisite steps. For example the CPUs which get introduced during runtime of a system can posses a "deconfigured" state which prevents them from being hotplugged online before they get configured. Another case is when users set the configured state of CPUs themselves via "chcpu" or sysfs attributes.

On s390 available CPUs are being registered as new devices via smp_add_core() either during boot or after a CPU rescan (for newly added CPUs during runtime). Registered CPUs are marked as enabled without considering the configure states. Add necessary checks to smp_add_core() and userspace configure attribute handler. Reflect the configured CPUs to cpu_enabled_mask to correctly represent which CPUs can be hotplugged online.

---
4e1a7df45480 ("cpumask: Add enabled cpumask for present CPUs that can be brought online") introduces a new cpumask to signify which CPUs can be hotplugged online at a given time.

Originally the concept is introduced to reflect CPUs which are being kept offline by firmware decisions. For s390 the configure state of the CPUs matches this concept. CPUs can assume configured or deconfigured state. When a CPU is in deconfigured state, it cannot be brought online util it is back in configured state.

On s390 available CPUs are being registered as new devices via smp_add_core() either during boot or after a CPU rescan (for newly added CPUs during runtime). Registered CPUs are marked as enabled without considering the configure states. Add necessary checks to smp_add_core() and userspace configure attribute handler. Reflect the configured CPUs to cpu_enabled_mask to correctly represent which CPUs can be hotplugged online.

---
 arch/s390/kernel/smp.c | 5 +++++
 1 file changed, 5 insertions(+)
arch/s390/kernel/smp.c +5 -0
index 0ba7f89b8161..e0c9480c7bd2 100644
@@ -1039,6 +1039,7 @@ static ssize_t cpu_configure_store(struct device *dev,
 			per_cpu(pcpu_devices, cpu + i).state = CPU_STATE_STANDBY;
 			smp_cpu_set_polarization(cpu + i,
 						 POLARIZATION_UNKNOWN);
+			set_cpu_enabled(cpu + i, false);
 		}
 		topology_expect_change();
 		break;
@@ -1054,6 +1055,7 @@ static ssize_t cpu_configure_store(struct device *dev,
 			per_cpu(pcpu_devices, cpu + i).state = CPU_STATE_CONFIGURED;
 			smp_cpu_set_polarization(cpu + i,
 						 POLARIZATION_UNKNOWN);
+			set_cpu_enabled(cpu + i, true);
 		}
 		topology_expect_change();
 		break;
@@ -1091,6 +1093,7 @@ bool arch_cpu_is_hotpluggable(int cpu)
 
 int arch_register_cpu(int cpu)
 {
+	struct pcpu *pcpu = per_cpu_ptr(&pcpu_devices, cpu);
 	struct cpu *c = per_cpu_ptr(&cpu_devices, cpu);
 	int rc;
 
@@ -1104,6 +1107,8 @@ int arch_register_cpu(int cpu)
 	rc = topology_cpu_init(c);
 	if (rc)
 		goto out_topology;
+	if (pcpu->state != CPU_STATE_CONFIGURED)
+		set_cpu_enabled(cpu, false);
 	return 0;
 
 out_topology:

---
base-commit: 1590cf0329716306e948a8fc29f1d3ee87d3989f
change-id: 20260721-enabled_cpus-426e53506c60

Best regards,

Signature · 1 line
Mete Durlu <[email protected]>
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Logical CPU ID fragmentation causes smp_get_base_cpu() to return incorrect siblings, leading to unsafe core deconfiguration. --

--- Patch [1]: [PATCH] s390/smp: Reflect (de)configured CPUs to cpu_enabled_mask --- commit d82385b96c4cbe6b55b4a0446d3eeb4e2c122fa2
Author: Mete Durlu <[email protected]>

s390/smp: Reflect (de)configured CPUs to cpu_enabled_mask

On s390, CPUs can be in a state where it is not possible to hotplug them online before certain prequisite steps. This commit adds necessary checks to smp_add_core() and userspace configure attribute handlers to reflect the configured CPUs to cpu_enabled_mask.

arch/s390/kernel/smp.c static ssize_t cpu_configure_store(struct device *dev, · line 1042

Quoted 9 lines
arch/s390/kernel/smp.c +1 -0
index 0ba7f89b81611..e0c9480c7bd24 100644
@@ -1039,6 +1039,7 @@ static ssize_t cpu_configure_store(struct device *dev,
 			per_cpu(pcpu_devices, cpu + i).state = CPU_STATE_STANDBY;
 			smp_cpu_set_polarization(cpu + i,
 						 POLARIZATION_UNKNOWN);
+			set_cpu_enabled(cpu + i, false);

[Severity: High]
This isn't a bug introduced by this patch, but does the base CPU calculation safely handle logical CPU ID fragmentation?

If arch_register_cpu() previously failed (e.g., due to memory allocation) for a thread during hotplug in smp_add_core(), cpu_present is cleared. Upon the next CPU rescan, __smp_rescan_cpus() repopulates the avail mask with this unaligned hole.

When a new core is added, it will consume this hole and subsequent bits for its threads, resulting in unaligned logical CPU IDs. However, smp_get_base_cpu() mathematically assumes rigid alignment:

arch/s390/include/asm/smp.h:smp_get_base_cpu() {
	return cpu - (cpu % (smp_cpu_mtid + 1));
}

If a fragmented core is configured or deconfigured via sysfs, this misalignment causes cpu_configure_store() to compute the wrong base CPU.

Could this lead to checking cpu_online() on unrelated CPUs, deconfiguring the wrong hardware address via sclp_core_deconfigure(), and corrupting the state and cpu_enabled_mask for unrelated CPUs?

Quoted 3 lines
arch/s390/kernel/smp.c +0 -0
 		}
 		topology_expect_change();
 		break;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Mete Durlu
Quoted 15 lines · Mete Durlu

On s390, CPUs can be in a state where it is not possible to hotplug them online before certain prequisite steps. For example the CPUs which get introduced during runtime of a system can posses a "deconfigured" state which prevents them from being hotplugged online before they get configured. Another case is when users set the configured state of CPUs themselves via "chcpu" or sysfs attributes.

On s390 available CPUs are being registered as new devices via smp_add_core() either during boot or after a CPU rescan (for newly added CPUs during runtime). Registered CPUs are marked as enabled without considering the configure states. Add necessary checks to smp_add_core() and userspace configure attribute handler. Reflect the configured CPUs to cpu_enabled_mask to correctly represent which CPUs can be hotplugged online.

Quoted 4 lines
---
 arch/s390/kernel/smp.c | 5 +++++
 1 file changed, 5 insertions(+)
maintainer Applied
#3 lore raw
In reply to Mete Durlu
Quoted 34 lines · Mete Durlu

On s390, CPUs can be in a state where it is not possible to hotplug them online before certain prequisite steps. For example the CPUs which get introduced during runtime of a system can posses a "deconfigured" state which prevents them from being hotplugged online before they get configured. Another case is when users set the configured state of CPUs themselves via "chcpu" or sysfs attributes.

On s390 available CPUs are being registered as new devices via smp_add_core() either during boot or after a CPU rescan (for newly added CPUs during runtime). Registered CPUs are marked as enabled without considering the configure states. Add necessary checks to smp_add_core() and userspace configure attribute handler. Reflect the configured CPUs to cpu_enabled_mask to correctly represent which CPUs can be hotplugged online.

---
4e1a7df45480 ("cpumask: Add enabled cpumask for present CPUs that can be brought online") introduces a new cpumask to signify which CPUs can be hotplugged online at a given time.

Originally the concept is introduced to reflect CPUs which are being kept offline by firmware decisions. For s390 the configure state of the CPUs matches this concept. CPUs can assume configured or deconfigured state. When a CPU is in deconfigured state, it cannot be brought online util it is back in configured state.

On s390 available CPUs are being registered as new devices via smp_add_core() either during boot or after a CPU rescan (for newly added CPUs during runtime). Registered CPUs are marked as enabled without considering the configure states. Add necessary checks to smp_add_core() and userspace configure attribute handler. Reflect the configured CPUs to cpu_enabled_mask to correctly represent which CPUs can be hotplugged online.

Quoted 3 lines
---
 arch/s390/kernel/smp.c | 5 +++++
 1 file changed, 5 insertions(+)

Applied, thank you!