mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 0/2] x86/cacheinfo: Make cache IDs unique on hybrid processors
Date: Wed, 02 Dec 2026 20:58:03 -0800	[thread overview]
Message-ID: <20261202-rneri-x86-cacheinfoid-bug-v2-0-a00d768927f2@linux.intel.com> (raw)

get_cache_id() computes the cache IDs in
/sys/devices/system/cpu/cpuX/cache/index*/id by right-shifting the APIC
ID by an amount that depends on the CPU. On hybrid processors, cores of
different types use different shifts, and caches that are not shared
end up with the same ID. Since v6.4, the generic cacheinfo code rebuilds
shared_cpu_map from these IDs when a CPU comes back online, including
after suspend to RAM and hibernation. shared_cpu_list then also reports
a P-core and an E-core as sharing their L1 cache.

Patch 1 is the fix and can be applied on its own. On hybrid processors,
it computes the exposed IDs with calc_cache_topo_id(), which masks the
APIC ID instead. All other processors keep their IDs: they do not
collide there. Changing them would break userspace that stored them,
such as libvirt's <cachetune>.

Patch 2 uses calc_cache_topo_id() for the boot-time sharing masks as
well. It does not change which CPUs are matched.

Testing:

- Lenovo ThinkPad X1 Carbon Gen 12 (Meteor Lake): without the series,
  offlining and onlining an E-core, or a hibernate/resume cycle, makes
  shared_cpu_list report the E-core as sharing its L1 cache with a
  P-core. With the series, the lists stay correct.
- AMD Ryzen AI 9 HX 370 (Zen 5 + Zen 5c), 2-socket EPYC 9555 (Zen 5) and
  2-socket EPYC 9354 (Zen 4): none of them sets X86_FEATURE_HYBRID_CPU.
  The Ryzen mixes core types, but its IDs do not collide. The series
  changes nothing userspace sees: every cache ID, resctrl domain ID and
  shared_cpu_list stays the same. This also holds across 20
  offline/online cycles of each of three CPUs per machine (the first CPU
  of an L3, another CPU in it and the first CPU's SMT sibling), and
  across a hibernate/resume cycle on the Ryzen.
- On the EPYC 9354, a libvirt domain with a stored <cachetune> cache ID
  keeps starting with the series.
- Javid tested v1 on an Arrow Lake-S Core Ultra 7 265: unique L1 IDs,
  and shared_cpu_list stays correct across CPU hotplug. Len tested v1 on
  a Meteor Lake-based Lenovo ThinkPad T16 Gen 3. The hybrid code path is
  the same in v2.
- Patch 1 alone was build-tested only.

Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
---
Changes in v2:
- Change the IDs only on hybrid processors, so that stored IDs keep
  working on all others (patch 1).
- Move the no-op __cache_cpumap_setup() change into patch 2.
- Changelog: CPU hotplug effect, Fixes: tag, resctrl IDs.
- Link to v1: https://lore.kernel.org/r/20260319-rneri-x86-cacheinfoid-bug-v1-1-5875849dd0e5@linux.intel.com

---
Ricardo Neri (2):
      x86/cacheinfo: Fix cache ID collisions on hybrid processors
      x86/cacheinfo: Use calc_cache_topo_id() in __cache_cpumap_setup()

 arch/x86/kernel/cpu/cacheinfo.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)
---
base-commit: 782a14f283513f52785f7f9c207b0af2ba4aecb6
change-id: 20260220-rneri-x86-cacheinfoid-bug-71e3f7e28e94

Best regards,
-- 
Ricardo Neri <ricardo.neri-calderon@linux.intel.com>


             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 Ricardo Neri [this message]
2026-12-03  4:58 ` [PATCH v2 1/2] x86/cacheinfo: Fix cache ID collisions " Ricardo Neri
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-0-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®