Re: [RFC PATCH] x86/cpu: Change AMD uarch detection

From: Sean Christopherson

Date: Tue Oct 27 2026 - 11:29:57 EST


On Wed, Oct 21, 2026, Borislav Petkov wrote:
> Hi,
>
> I have been wondering how to improve that Zen uarch detection and handling and
> be able to do range checks of uarches, i.e., "this code needs to run on Zen
> microarchitectures 3 to 5". And I asked AI.
>
> It gave me a lot of blurb but the basic idea is good so I went and did it. See
> below.
>
> It boots in a VM, I'm not even trying to cause the cat to catch fire by
> booting on a real machine but that will happen soon too.
>
> The thing can easily be extended to pre-Zen but that is not really needed, I'd
> say.
>
> X86_FEATURE_ZEN to mark all Zens remains, that will be a future patch. Perhaps
> something as simple as:
>
> if (boot_cpu_data.x86_uarch)
>
> but I have to move Hygon off of that usage. We'll see. Small steps.

This is better than X86_FEATURE_ZENx, as I always found the lack of inclusivity,
e.g. ZEN4 not lighting up ZEN3, to be confusing/surprising.

But why invent another scheme? What stops AMD from implementing precise macros
as arch/x86/include/asm/intel-family.h does? Providing range-based checks would
"just" require more macros, no? E.g. couldn't we do

if (AMD_ZEN4_OR_LATER(boot_cpu_data.x86_vfm))
return amd_zen4_perfmon_event_map[hw_event];

if (AMD_ZEN2_OR_LATER(boot_cpu_data.x86_vfm))
return amd_zen2_perfmon_event_map[hw_event];

if (AMD_ZEN1_OR_LATER(boot_cpu_data.x86_vfm))
return amd_zen1_perfmon_event_map[hw_event];


and

if (AMD_ZEN3(boot_cpu_data.x86_vfm) ||
AMD_ZEN4(boot_cpu_data.x86_vfm)) {
...

}