From: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
To: x86@kernel.org
Cc: Reinette Chatre <reinette.chatre@intel.com>,
Tony Luck <tony.luck@intel.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
"Ahmed S. Darwish" <darwi@linutronix.de>,
Len Brown <len.brown@intel.com>,
Javid Rzayev <rz.cavid@gmail.com>,
Ricardo Neri <ricardo.neri@intel.com>,
linux-kernel@vger.kernel.org,
Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
Subject: [PATCH v2 2/2] x86/cacheinfo: Use calc_cache_topo_id() in __cache_cpumap_setup()
Date: Wed, 02 Dec 2026 20:58:05 -0800 [thread overview]
Message-ID: <20261202-rneri-x86-cacheinfoid-bug-v2-2-a00d768927f2@linux.intel.com> (raw)
In-Reply-To: <20261202-rneri-x86-cacheinfoid-bug-v2-0-a00d768927f2@linux.intel.com>
__cache_cpumap_setup() open-codes a cache ID comparison: it right-shifts
the APIC IDs of two CPUs by N and compares the results. N is the
smallest integer such that 2^N is greater than or equal to the maximum
number of addressable IDs for logical processors sharing the cache of
the CPU being set up. calc_cache_topo_id() already computes the cache
IDs exposed in sysfs on hybrid processors.
Use calc_cache_topo_id() for that comparison as well, so that the file
no longer open-codes a cache ID computation next to its two helpers.
No functional change intended: both sides use the N of the CPU being set
up. With the same N, masking and shifting select the same CPUs. A different
N on other CPUs does not matter. The CPUs sharing a cache with the CPU
being set up are those whose APIC IDs match its APIC ID in all but the N
least-significant bits.
Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
---
Changes in v2:
- Introduce this patch.
---
arch/x86/kernel/cpu/cacheinfo.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinfo.c
index 4d0f47e5f6c0..5e830ee44d13 100644
--- a/arch/x86/kernel/cpu/cacheinfo.c
+++ b/arch/x86/kernel/cpu/cacheinfo.c
@@ -551,7 +551,8 @@ static void __cache_cpumap_setup(unsigned int cpu, int index,
struct cpuinfo_x86 *c = &cpu_data(cpu);
struct cacheinfo *ci, *sibling_ci;
unsigned long num_threads_sharing;
- int index_msb, i;
+ unsigned int cache_id;
+ int i;
if (c->x86_vendor == X86_VENDOR_AMD || c->x86_vendor == X86_VENDOR_HYGON) {
if (__cache_amd_cpumap_setup(cpu, index, id4))
@@ -565,10 +566,15 @@ static void __cache_cpumap_setup(unsigned int cpu, int index,
if (num_threads_sharing == 1)
return;
- index_msb = get_count_order(num_threads_sharing);
+ cache_id = calc_cache_topo_id(c, id4);
- for_each_online_cpu(i)
- if (cpu_data(i).topo.apicid >> index_msb == c->topo.apicid >> index_msb) {
+ for_each_online_cpu(i) {
+ /*
+ * Use @cpu's CPUID(0x4) data for CPU i too: CPU i shares this
+ * cache iff its APIC ID matches @cpu's in all bits above those
+ * reserved for the CPUs sharing the cache.
+ */
+ if (cache_id == calc_cache_topo_id(&cpu_data(i), id4)) {
struct cpu_cacheinfo *sib_cpu_ci = get_cpu_cacheinfo(i);
/* Skip if itself or no cacheinfo */
@@ -579,6 +585,7 @@ static void __cache_cpumap_setup(unsigned int cpu, int index,
cpumask_set_cpu(i, &ci->shared_cpu_map);
cpumask_set_cpu(cpu, &sibling_ci->shared_cpu_map);
}
+ }
}
static void ci_info_init(struct cacheinfo *ci, const struct _cpuid4_info *id4,
--
2.43.0
prev parent reply other threads:[~2026-12-03 4:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 4:58 [PATCH v2 0/2] x86/cacheinfo: Make cache IDs unique on hybrid processors Ricardo Neri
2026-12-03 4:58 ` [PATCH v2 1/2] x86/cacheinfo: Fix cache ID collisions " Ricardo Neri
2026-12-03 4:58 ` Ricardo Neri [this message]
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=20261202-rneri-x86-cacheinfoid-bug-v2-2-a00d768927f2@linux.intel.com \
--to=ricardo.neri-calderon@linux.intel.com \
--cc=darwi@linutronix.de \
--cc=kprateek.nayak@amd.com \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=reinette.chatre@intel.com \
--cc=ricardo.neri@intel.com \
--cc=rz.cavid@gmail.com \
--cc=tony.luck@intel.com \
--cc=x86@kernel.org \
/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
all inboxes | Powered by JetHome®