Linux s390 Architecture development
 help / color / mirror / Atom feed
* Re: [PATCH] s390/smp: Reflect (de)configured CPUs to cpu_enabled_mask
       [not found] <20260723-enabled_cpus-v1-1-3a2cbdc374b0@linux.ibm.com>
@ 2026-07-23 13:56 ` sashiko-bot
  2026-07-23 14:03 ` Heiko Carstens
  2026-07-29 13:01 ` Vasily Gorbik
  2 siblings, 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
       [not found] <20260723-enabled_cpus-v1-1-3a2cbdc374b0@linux.ibm.com>
  2026-07-23 13:56 ` [PATCH] s390/smp: Reflect (de)configured CPUs to cpu_enabled_mask sashiko-bot
@ 2026-07-23 14:03 ` Heiko Carstens
  2026-07-29 13:01 ` Vasily Gorbik
  2 siblings, 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

* Re: [PATCH] s390/smp: Reflect (de)configured CPUs to cpu_enabled_mask
       [not found] <20260723-enabled_cpus-v1-1-3a2cbdc374b0@linux.ibm.com>
  2026-07-23 13:56 ` [PATCH] s390/smp: Reflect (de)configured CPUs to cpu_enabled_mask sashiko-bot
  2026-07-23 14:03 ` Heiko Carstens
@ 2026-07-29 13:01 ` Vasily Gorbik
  2 siblings, 0 replies; 3+ messages in thread
From: Vasily Gorbik @ 2026-07-29 13:01 UTC (permalink / raw)
  To: Mete Durlu
  Cc: Heiko Carstens, 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>
> ---
> 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(+)

Applied, thank you!

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

end of thread, other threads:[~2026-07-29 13:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20260723-enabled_cpus-v1-1-3a2cbdc374b0@linux.ibm.com>
2026-07-23 13:56 ` [PATCH] s390/smp: Reflect (de)configured CPUs to cpu_enabled_mask sashiko-bot
2026-07-23 14:03 ` Heiko Carstens
2026-07-29 13:01 ` Vasily Gorbik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox