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

From: Borislav Petkov
Date: Tue Apr 16 2024 - 11:13:16 EST


On Wed, Apr 03, 2024 at 08:35:11AM -0700, Dave Hansen wrote:
>
> From: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
>
> IBS details are enumerated in an extended CPUID leaf. But
> the support has an open-coded CPUID region check. Use the
> new helper to trim down the code.
>
> Signed-off-by: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
> --
>
> Note: this cleanup could take another form:
>
> if (boot_cpu_data->extended_cpuid_level >= IBS_CPUID_FEATURES)
> caps = cpuid_eax(IBS_CPUID_FEATURES);
>
> that would be one fewer CPUID invocations, but one more
> line of code.
> ---
>
> b/arch/x86/events/amd/ibs.c | 9 ++-------
> 1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff -puN arch/x86/events/amd/ibs.c~ibs-region-helpers arch/x86/events/amd/ibs.c
> --- a/arch/x86/events/amd/ibs.c~ibs-region-helpers 2024-04-02 15:22:59.262912595 -0700
> +++ b/arch/x86/events/amd/ibs.c 2024-04-02 15:22:59.262912595 -0700
> @@ -1278,18 +1278,13 @@ static __init int perf_event_ibs_init(vo
>
> static __init u32 __get_ibs_caps(void)
> {
> - u32 caps;
> - unsigned int max_level;
> + u32 caps = 0;
>
> 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...

Thx.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette