From: "Ahmed S. Darwish" <darwi@linutronix.de>
To: Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Andrew Cooper <andrew.cooper3@citrix.com>,
"H. Peter Anvin" <hpa@zytor.com>,
John Ogness <john.ogness@linutronix.de>,
x86@kernel.org, x86-cpuid@lists.linux.dev,
LKML <linux-kernel@vger.kernel.org>,
"Ahmed S. Darwish" <darwi@linutronix.de>
Subject: [PATCH v2 0/2] x86/cacheinfo: Fixes for CPUID(0x80000005) and CPUID(0x80000006)
Date: Wed, 9 Apr 2025 14:22:29 +0200 [thread overview]
Message-ID: <20250409122233.1058601-1-darwi@linutronix.de> (raw)
Hi,
Changelog v2:
-------------
Rebase over tip:master, as of now:
5c5e95d43de9 ("Merge branch into tip/master: 'x86/nmi'")
per Ingo's request.
Changelog v1:
-------------
https://lore.kernel.org/lkml/20250409105429.1048199-1-darwi@linutronix.de
While working on the x86-cpuid-db CPUID model on top of the CPUID(2) and
CPUID(4) cleanups at tip/x86/cpu,[*] I've discovered some L1/2/3 cache
associativity parsing issues for the AMD CPUID(4) emulation logic .
Here are the fixes on top of -rc1.
* Summary:
The AMD CPUID(4) emulation logic, uses CPUID(0x80000005) and
CPUID(0x80000006) for extracting the L1/L2/L3 cache info. It then uses
an assocs[] associativity mapping array to map the extracted
associativity values to their CPUID(4) equivalents.
Using the same associativity mapping array for both leaves is invalid.
Per the AMD manuals, the associativity field semantics between
CPUID(0x80000005) and CPUID(0x80000006) is different. The first patch
fixes that for the former leaf. For the latter leaf, the second patch
completes the associativity mapping array and handles the special case of
an L2/L3 associativity of 9, which is just a marker — not a real cache
associativity value.
* Example testing for L1d cacheinfo:
On a Qemu-emulated AMD machine without CPUID(0x8000001d) topology
extensions, and with below cpuid(1) view:
L1 data cache information (0x80000005/ecx):
line size (bytes) = 0x40 (64)
lines per tag = 0x1 (1)
associativity = 0x8 (8)
size (KB) = 0x20 (32)
L1 instruction cache information (0x80000005/edx):
line size (bytes) = 0x40 (64)
lines per tag = 0x1 (1)
associativity = 0x4 (4)
size (KB) = 0x40 (64)
L2 unified cache information (0x80000006/ecx):
line size (bytes) = 0x40 (64)
lines per tag = 0x1 (1)
associativity = 8-way (6)
size (KB) = 0x200 (512)
L3 cache information (0x80000006/edx):
line size (bytes) = 0x40 (64)
lines per tag = 0x1 (1)
associativity = 16-way (8)
size (in 512KB units) = 0x10 (16)
Before applying this PQ, we get:
/sys/devices/system/cpu/cpu[0-8]/cache/index0/ways_of_associativity: 16
/sys/devices/system/cpu/cpu[0-8]/cache/index0/number_of_sets: 32
and after:
/sys/devices/system/cpu/cpu[0-8]/cache/index0/ways_of_associativity: 8
/sys/devices/system/cpu/cpu[0-8]/cache/index0/number_of_sets: 64
Thanks,
[*] https://lore.kernel.org/lkml/20250304085152.51092-1-darwi@linutronix.de
https://lore.kernel.org/lkml/20250324133324.23458-1-darwi@linutronix.de
8<--
Ahmed S. Darwish (2):
x86/cacheinfo: Properly parse CPUID(0x80000005) L1d/L1i associativity
x86/cacheinfo: Properly parse CPUID(0x80000006) L2/L3 associativity
arch/x86/kernel/cpu/cacheinfo.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
base-commit: 5c5e95d43de95309622fbf85bf55765ca2cae551
--
2.49.0
next reply other threads:[~2025-04-09 12:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-09 12:22 Ahmed S. Darwish [this message]
2025-04-09 12:22 ` [PATCH v2 1/2] x86/cacheinfo: Properly parse CPUID(0x80000005) L1d/L1i associativity Ahmed S. Darwish
2025-04-09 18:52 ` Ingo Molnar
2025-04-10 5:53 ` Ahmed S. Darwish
2025-04-09 19:40 ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-04-09 12:22 ` [PATCH v2 2/2] x86/cacheinfo: Properly parse CPUID(0x80000006) L2/L3 associativity Ahmed S. Darwish
2025-04-09 19:40 ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
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=20250409122233.1058601-1-darwi@linutronix.de \
--to=darwi@linutronix.de \
--cc=andrew.cooper3@citrix.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86-cpuid@lists.linux.dev \
--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®