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 1/2] x86/cacheinfo: Fix cache ID collisions on hybrid processors
Date: Wed, 02 Dec 2026 20:58:04 -0800 [thread overview]
Message-ID: <20261202-rneri-x86-cacheinfoid-bug-v2-1-a00d768927f2@linux.intel.com> (raw)
In-Reply-To: <20261202-rneri-x86-cacheinfoid-bug-v2-0-a00d768927f2@linux.intel.com>
calc_cache_topo_id() and get_cache_id() both compute a cache ID from an
APIC ID. Intel processors use calc_cache_topo_id() for the cache IDs in
struct cpuinfo_x86. On all vendors, get_cache_id() computes the IDs in
/sys/devices/system/cpu/cpuX/cache/index*/id. On hybrid processors,
those IDs can collide.
Both functions use N, the smallest integer such that 2^N is greater than or
equal to the maximum number of addressable IDs for logical processors
sharing a cache. That number is CPUID(0x4).EAX[25:14] + 1, with ECX as
the cache index. calc_cache_topo_id() masks off the N least-significant
bits of the APIC ID. get_cache_id() right-shifts the APIC ID by N instead.
Masking yields unique IDs even when N differs across CPUs. Shifting does
not. On hybrid processors, cores of different types can report different
values of N.
Consider the APIC IDs and CPUID(0x4) data for the L1 cache of selected
CPUs from a Meteor Lake-based Lenovo ThinkPad T16 Gen 3:
CPU APICID N calc_cache_topo_id() get_cache_id()
2 0x18 1 0x18 0xc
3 0x19 1 0x18 0xc
10 0xc 0 0xc 0xc
CPUs 2 and 3 are the two logical CPUs of one core and share the L1
cache. CPU 10 does not, yet get_cache_id() assigns it the same ID.
The collision occurs without SMT too. On an Arrow Lake-S Core Ultra 7
265, which has no SMT, N is 1 for the L1 cache of the P-cores and 0 for
that of the E-cores.
The colliding IDs also corrupt shared_cpu_list after CPU hotplug. At boot,
__cache_cpumap_setup() builds the sharing masks correctly by comparing
APIC IDs. When a CPU comes back online, cache_shared_cpu_map_setup()
rebuilds them by comparing cache IDs instead. On a ThinkPad X1 Carbon
Gen 12, whose CPUs 2, 3 and 10 have the APIC IDs in the table above:
# cat /sys/devices/system/cpu/cpu{2,10}/cache/index0/shared_cpu_list
2-3
10
# echo 0 > /sys/devices/system/cpu/cpu10/online
# echo 1 > /sys/devices/system/cpu/cpu10/online
# cat /sys/devices/system/cpu/cpu{2,10}/cache/index0/shared_cpu_list
2-3,10
2-3,10
On hybrid processors, use calc_cache_topo_id() for the IDs exposed in
sysfs. If such a processor has resctrl L2 or L3 resources, their domain
IDs, which are derived from the cache IDs, change as well. Users that
read the IDs at run time from sysfs or resctrl are not affected.
On all other processors, keep get_cache_id(): their IDs do not collide.
Changing them would break userspace that stored them. A libvirt domain
whose <cachetune> element names a cache ID that no longer exists fails
to start.
Fixes: d57e3ab7e34c ("x86/intel_cacheinfo: Enable cache id in cache info")
Reported-by: Len Brown <len.brown@intel.com>
Reported-by: Javid Rzayev <rz.cavid@gmail.com>
Closes: https://lore.kernel.org/r/20261109165537.6656-1-rz.cavid@gmail.com
Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
Tested-by: Len Brown <len.brown@intel.com>
Tested-by: Javid Rzayev <rz.cavid@gmail.com>
---
Stable maintainers: besides fixing the collisions, this patch changes the
cache IDs that userspace sees on hybrid processors only. It applies
cleanly from v6.16, where calc_cache_topo_id() was introduced. Older
trees need a backport.
Changes in v2:
- Change the IDs only on hybrid processors. v1 changed them on all
processors, including the LLC ID of AMD processors, which
srat_detect_node() and the AMD uncore PMU driver need to stay small.
On an EPYC 9354, the IDs from v1 also make a libvirt domain with a
stored <cachetune> cache ID fail to start.
- Describe the userspace impact (resctrl domain IDs, libvirt <cachetune>).
- Describe the shared_cpu_list corruption after CPU hotplug (Javid).
- Add a Fixes: tag and a note for the stable maintainers.
- Move the __cache_cpumap_setup() hunk into its own patch.
---
arch/x86/kernel/cpu/cacheinfo.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinfo.c
index 13ed16527905..4d0f47e5f6c0 100644
--- a/arch/x86/kernel/cpu/cacheinfo.c
+++ b/arch/x86/kernel/cpu/cacheinfo.c
@@ -622,7 +622,18 @@ int populate_cache_leaves(unsigned int cpu)
if (ret)
return ret;
- id4.id = get_cache_id(apicid, &id4);
+ /*
+ * On hybrid processors, cores of different types can report
+ * different numbers of addressable IDs for the logical
+ * processors sharing a cache. The shifted IDs of
+ * get_cache_id() can then collide. Other processors use the
+ * shifted IDs, which are unique there and which userspace may
+ * have stored.
+ */
+ if (cpu_feature_enabled(X86_FEATURE_HYBRID_CPU))
+ id4.id = calc_cache_topo_id(&cpu_data(cpu), &id4);
+ else
+ id4.id = get_cache_id(apicid, &id4);
if (cpu_vendor == X86_VENDOR_AMD || cpu_vendor == X86_VENDOR_HYGON)
nb = amd_init_l3_cache(idx);
--
2.43.0
next 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 " Ricardo Neri
2026-12-03 4:58 ` Ricardo Neri [this message]
2026-12-03 4:58 ` [PATCH v2 2/2] x86/cacheinfo: Use calc_cache_topo_id() in __cache_cpumap_setup() Ricardo Neri
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-1-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®