All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] s390/smp: Reflect (de)configured CPUs to cpu_enabled_mask
@ 2026-07-23 13:36 Mete Durlu
  2026-07-23 13:56 ` sashiko-bot
  2026-07-23 14:03 ` Heiko Carstens
  0 siblings, 2 replies; 3+ messages in thread
From: Mete Durlu @ 2026-07-23 13:36 UTC (permalink / raw)
  To: Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
	Christian Borntraeger, Sven Schnelle, Ilya Leoshkevich
  Cc: linux-s390, 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.

Signed-off-by: Mete Durlu <meted@linux.ibm.com>
---
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(+)

diff --git a/arch/s390/kernel/smp.c b/arch/s390/kernel/smp.c
index 0ba7f89b8161..e0c9480c7bd2 100644
--- a/arch/s390/kernel/smp.c
+++ b/arch/s390/kernel/smp.c
@@ -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,
-- 
Mete Durlu <meted@linux.ibm.com>


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

* Re: [PATCH] s390/smp: Reflect (de)configured CPUs to cpu_enabled_mask
  2026-07-23 13:36 [PATCH] s390/smp: Reflect (de)configured CPUs to cpu_enabled_mask Mete Durlu
@ 2026-07-23 13:56 ` sashiko-bot
  2026-07-23 14:03 ` Heiko Carstens
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-07-23 13:56 UTC (permalink / raw)
  To: Mete Durlu; +Cc: Alexander Gordeev, Heiko Carstens, Vasily Gorbik, linux-s390

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 <meted@linux.ibm.com>

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.

> diff --git a/arch/s390/kernel/smp.c b/arch/s390/kernel/smp.c
> index 0ba7f89b81611..e0c9480c7bd24 100644
> --- a/arch/s390/kernel/smp.c
> +++ b/arch/s390/kernel/smp.c
> @@ -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?

>  		}
>  		topology_expect_change();
>  		break;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260723-enabled_cpus-v1-1-3a2cbdc374b0@linux.ibm.com?part=1

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

* Re: [PATCH] s390/smp: Reflect (de)configured CPUs to cpu_enabled_mask
  2026-07-23 13:36 [PATCH] s390/smp: Reflect (de)configured CPUs to cpu_enabled_mask Mete Durlu
  2026-07-23 13:56 ` sashiko-bot
@ 2026-07-23 14:03 ` Heiko Carstens
  1 sibling, 0 replies; 3+ messages in thread
From: Heiko Carstens @ 2026-07-23 14:03 UTC (permalink / raw)
  To: Mete Durlu
  Cc: Vasily Gorbik, Alexander Gordeev, Christian Borntraeger,
	Sven Schnelle, Ilya Leoshkevich, linux-s390

On Thu, Jul 23, 2026 at 03:36:43PM +0200, Mete Durlu wrote:
> 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.
> 
> Signed-off-by: Mete Durlu <meted@linux.ibm.com>
> ---
>  arch/s390/kernel/smp.c | 5 +++++
>  1 file changed, 5 insertions(+)

Acked-by: Heiko Carstens <hca@linux.ibm.com>

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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-23 13:36 [PATCH] s390/smp: Reflect (de)configured CPUs to cpu_enabled_mask Mete Durlu
2026-07-23 13:56 ` sashiko-bot
2026-07-23 14:03 ` Heiko Carstens

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.