Re: [PATCH v11 04/12] x86/mm: get INVLPGB count max from CPUID

From: Borislav Petkov
Date: Wed Feb 19 2025 - 06:57:05 EST


On Thu, Feb 13, 2025 at 11:13:55AM -0500, Rik van Riel wrote:
> The CPU advertises the maximum number of pages that can be shot down
> with one INVLPGB instruction in the CPUID data.
>
> Save that information for later use.
>
> Signed-off-by: Rik van Riel <riel@xxxxxxxxxxx>
> Tested-by: Manali Shukla <Manali.Shukla@xxxxxxx>
> Tested-by: Brendan Jackman <jackmanb@xxxxxxxxxx>
> Tested-by: Michael Kelley <mhklinux@xxxxxxxxxxx>
> ---
> arch/x86/Kconfig.cpu | 5 +++++
> arch/x86/include/asm/cpufeatures.h | 1 +
> arch/x86/include/asm/tlbflush.h | 7 +++++++
> arch/x86/kernel/cpu/amd.c | 8 ++++++++
> 4 files changed, 21 insertions(+)
>
> diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
> index 2a7279d80460..abe013a1b076 100644
> --- a/arch/x86/Kconfig.cpu
> +++ b/arch/x86/Kconfig.cpu
> @@ -395,6 +395,10 @@ config X86_VMX_FEATURE_NAMES
> def_bool y
> depends on IA32_FEAT_CTL
>
> +config X86_BROADCAST_TLB_FLUSH
> + def_bool y
> + depends on CPU_SUP_AMD && 64BIT
> +
> menuconfig PROCESSOR_SELECT
> bool "Supported processor vendors" if EXPERT
> help
> @@ -431,6 +435,7 @@ config CPU_SUP_CYRIX_32
> config CPU_SUP_AMD
> default y
> bool "Support AMD processors" if PROCESSOR_SELECT
> + select X86_BROADCAST_TLB_FLUSH

CPU_SUP_AMD selects X86_BROADCAST_TLB_FLUSH which depends on CPU_SUP_AMD which
selects X86_BROADCAST_TLB_FLUSH which depends on CPU_SUP_AMD...

Why do you really need yet another Kconfig symbol? Just whack
X86_BROADCAST_TLB_FLUSH - it'll be enabled by default on everything anyway.

> @@ -1139,6 +1141,12 @@ static void cpu_detect_tlb_amd(struct cpuinfo_x86 *c)
> tlb_lli_2m[ENTRIES] = eax & mask;
>
> tlb_lli_4m[ENTRIES] = tlb_lli_2m[ENTRIES] >> 1;
> +
> + /* Max number of pages INVLPGB can invalidate in one shot */
> + if (boot_cpu_has(X86_FEATURE_INVLPGB)) {
> + cpuid(0x80000008, &eax, &ebx, &ecx, &edx);
> + invlpgb_count_max = (edx & 0xffff) + 1;
> + }

get_cpu_cap() already reads that leaf. You don't need to do it here again.

--
Regards/Gruss,
Boris.

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