Re: [PATCH 2/4] perf/x86/ibs: Use CPUID region helper

From: Dave Hansen
Date: Tue Apr 16 2024 - 11:24:30 EST


On 4/16/24 08:12, Borislav Petkov wrote:
>> if (!boot_cpu_has(X86_FEATURE_IBS))
>> return 0;
>>
>> - /* check IBS cpuid feature flags */
>> - max_level = cpuid_eax(0x80000000);
>> - if (max_level < IBS_CPUID_FEATURES)
>> - return IBS_CAPS_DEFAULT;
>> + get_cpuid_region_leaf(IBS_CPUID_FEATURES, CPUID_EAX, &caps);
> I wanna say all this checking of max level is worthless because if you
> have X86_FEATURE_IBS, then it is a given that you also have that
> 0x8000001b CPUID leaf.
>
> Right, Bob?
>
> Unless there was some weird thing back then with the CPUID leafs...

When I was looking at it, I (maybe wrongly) assumed that 0x8000001b and
X86_FEATURE_IBS were independent for a reason. Because, oddly enough:

#define IBS_CAPS_DEFAULT (IBS_CAPS_AVAIL \
| IBS_CAPS_FETCHSAM \
| IBS_CAPS_OPSAM)

So, if the CPU enumerates X86_FEATURE_IBS but has a
max_level<IBS_CPUID_FEATURES then it assumes there's a working IBS
because the software-inserted IBS_CAPS_DEFAULT has IBS_CAPS_AVAIL set.

Actually, that even means that the new code should probably be:

u32 caps = IBS_CAPS_DEFAULT;

if (!boot_cpu_has(X86_FEATURE_IBS))
return 0;

get_cpuid_region_leaf(IBS_CPUID_FEATURES, CPUID_EAX, &caps);

to match the old.