Linux s390 Architecture development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "K Prateek Nayak" <kprateek.nayak@amd.com>
Cc: "Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	linux-s390@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>
Subject: Re: [RFC PATCH v3 08/13] sparc64: Initialize sbm topology on multi-LLC system
Date: Fri, 02 Oct 2026 09:13:24 +0000	[thread overview]
Message-ID: <20261002091324.869411F00893@smtp.kernel.org> (raw)
In-Reply-To: <20261001192849.74788-9-kprateek.nayak@amd.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] sparc64: sbm topology initialization runs before CPU data is populated
- [High] sparc64: ghost SBM instances created by iterating uninitialized possible CPUs
--

commit e3accb8257522fa2bde71974a4d31cb5abc096f8
Author: K Prateek Nayak <kprateek.nayak@amd.com>

sparc64: Initialize sbm topology on multi-LLC system

This commit initializes the sparsebitmap (sbm) topology for SPARC64 after
the CPU topology is parsed. It introduces init_sbm_topology() which counts
LLC/NUMA instances and their maximum thread counts, calling it from
setup_arch().

> diff --git a/arch/sparc/kernel/setup_64.c b/arch/sparc/kernel/setup_64.c
> index 63615f5c99b47..7ab52d17e46f4 100644
> --- a/arch/sparc/kernel/setup_64.c
> +++ b/arch/sparc/kernel/setup_64.c

[ ... ]

> @@ -619,6 +621,48 @@ static void __init alloc_irqstack_bootmem(void)
>  	}
>  }
>  
> +static struct cpumask cpu_sbm_setup_map __initdata;
> +static int __node_thread_count[NR_CPUS] __initdata;
> +
> +int arch_sbm_cpu_instance_id(int cpu)
> +{
> +	/* Combine the node and cache identifier. */
> +	return ((u32)cpu_to_node(cpu) << 16) |
> +	       cpu_data(cpu).max_cache_id;
> +}
> +
> +static void __init init_sbm_topology(void)
> +{
> +	int num_sbm_instances, max_threads_per_instance = 1;
> +	int i;
> +
> +	for_each_possible_cpu(i) {

[Severity: High]
Will this loop over uninitialized offline or absent CPUs?

If the possible mask exceeds the present mask, absent CPUs will evaluate
their uninitialized max_cache_id to 0.

They would then incorrectly match each other and be grouped into a single
phantom instance, which could heavily inflate the max_threads_per_instance
calculation below and misallocate the global sparsebitmap arrays.

Should this use for_each_present_cpu() instead?

> +		bool found = false;
> +		int j;
> +
> +		for_each_cpu(j, &cpu_sbm_setup_map) {
> +			if (cpu_to_node(i) == cpu_to_node(j) &&
> +			    cpu_data(i).max_cache_id == cpu_data(j).max_cache_id) {

[Severity: High]
Are the max_cache_id and node values actually initialized when this runs?

This function is called from setup_arch(), but max_cache_id is populated
later during SMP initialization:

arch/sparc/kernel/smp_64.c:setup_per_cpu_areas() {
    ...
    of_fill_in_cpu_data();
    if (tlb_type == hypervisor)
        mdesc_fill_in_cpu_data(cpu_all_mask);
    ...
}

Because setup_per_cpu_areas() runs after setup_arch(),
cpu_data(i).max_cache_id and cpu_to_node(i) will evaluate to zero for all
CPUs here. This would group all CPUs into a single instance instead of
distributing them based on max_cache_id.

If alloc_sbm_index() later finds the true max_cache_id, could it fail to
allocate leaves and return -ENOENT? This might leave __sbm_cpu_to_idx[cpu]
as -1, potentially causing out-of-bounds array accesses in the scheduler
fast paths.

> +				found = true;
> +				break;
> +			}
> +		}

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261001192849.74788-1-kprateek.nayak@amd.com?part=8

  reply	other threads:[~2026-10-02  9:13 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01 19:28 [RFC PATCH v3 00/13] lib, sched: Introduce sparsebitmap (sbm) K Prateek Nayak
2026-10-01 19:28 ` [RFC PATCH v3 01/13] lib/sbm: Introduce helpers for architectures to configure LLC properties K Prateek Nayak
2026-10-02  9:13   ` sashiko-bot
2026-10-07  5:43   ` Shrikanth Hegde
2026-10-01 19:28 ` [RFC PATCH v3 02/13] drivers/base/arch_topology: Add support for initializing sbm topology K Prateek Nayak
2026-10-02  9:13   ` sashiko-bot
2026-10-01 19:28 ` [RFC PATCH v3 03/13] LoongArch: Initialize CPU _PXM relation for disabled CPUs from SRAT K Prateek Nayak
2026-10-02  9:13   ` sashiko-bot
2026-10-01 19:28 ` [RFC PATCH v3 04/13] LoongArch: Configure sbm topology during SMP preparation K Prateek Nayak
2026-10-02  9:13   ` sashiko-bot
2026-10-07  3:51   ` [RFC PATCH v3.1 " K Prateek Nayak
2026-10-01 19:28 ` [RFC PATCH v3 05/13] MIPS: Initialize sbm topology on multi-node systems K Prateek Nayak
2026-10-02  9:13   ` sashiko-bot
2026-10-01 19:28 ` [RFC PATCH v3 06/13] powerpc/setup: Initialize sbm topology based on coregroup / NUMA topology K Prateek Nayak
2026-10-02  9:13   ` sashiko-bot
2026-10-07 14:43   ` Shrikanth Hegde
2026-10-01 19:28 ` [RFC PATCH v3 07/13] s390/topology: Initialize sbm topology during topology_init_early() K Prateek Nayak
2026-10-02  9:13   ` sashiko-bot
2026-10-07 10:19   ` Mete Durlu
2026-10-01 19:28 ` [RFC PATCH v3 08/13] sparc64: Initialize sbm topology on multi-LLC system K Prateek Nayak
2026-10-02  9:13   ` sashiko-bot [this message]
2026-10-01 19:28 ` [RFC PATCH v3 09/13] x86/cpu/topology: Initialize sbm topology after topology parsing K Prateek Nayak
2026-10-02  9:13   ` sashiko-bot
2026-10-03  8:27   ` Chen Yu
2026-10-04  6:17     ` K Prateek Nayak
2026-10-07  3:52   ` [RFC PATCH v3.1 " K Prateek Nayak
2026-10-01 19:28 ` [RFC PATCH v3 10/13] lib/sbm: Dynamically allocate sbm index when CPU is activated K Prateek Nayak
2026-10-02  9:13   ` sashiko-bot
2026-10-01 19:28 ` [RFC PATCH v3 11/13] lib/sbm: Add helpers to allocate, set, clear, and traverse the bits on sbm K Prateek Nayak
2026-10-02  9:13   ` sashiko-bot
2026-10-01 19:28 ` [RFC PATCH v3 12/13] sched/fair: Allocate nohz.idle_cpus_mask during sched_init_smp() K Prateek Nayak
2026-10-02  9:13   ` sashiko-bot
2026-10-01 19:28 ` [RFC PATCH v3 13/13] sched/fair: Switch nohz.idle_cpus to use sbm K Prateek Nayak
2026-10-02  9:13   ` sashiko-bot
2026-10-03  9:10 ` [RFC PATCH v3 00/13] lib, sched: Introduce sparsebitmap (sbm) Chen Yu
2026-10-04  6:13   ` K Prateek Nayak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261002091324.869411F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-s390@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox