Re: [PATCH v2 03/29] x86/cpu: Remove leaf 0x2 parsing loop and add helpers

From: Ingo Molnar
Date: Mon Mar 17 2025 - 17:36:51 EST



* Ahmed S. Darwish <darwi@xxxxxxxxxxxxx> wrote:

> Leaf 0x2 output includes a "query count" byte where it was supposed to
> specify the number of repeated CPUID leaf 0x2 subleaf 0 queries needed
> to extract all of the hardware's cache and TLB descriptors.
>
> Per current Intel manuals, all CPUs supporting this leaf "will always"
> return an iteration count of 1.
>
> Remove the leaf 0x2 query count loop and just query the hardware once.
> Parse the output with C99 bitfields instead of ugly bitwise operations.
>
> Provide leaf 0x2 parsing helpers with all the above. Use such helpers
> at x86/cpu intel.c. Further commits will use them for x86/cacheinfo.
>
> Suggested-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> Signed-off-by: Ahmed S. Darwish <darwi@xxxxxxxxxxxxx>
> ---
> arch/x86/include/asm/cpuid.h | 1 +
> arch/x86/include/asm/cpuid/leaf_0x2_api.h | 65 +++++++++++++++++++++++
> arch/x86/include/asm/cpuid/types.h | 16 ++++++
> arch/x86/kernel/cpu/intel.c | 24 +++------
> 4 files changed, 88 insertions(+), 18 deletions(-)
> create mode 100644 arch/x86/include/asm/cpuid/leaf_0x2_api.h

Could you please turn this into at least two patches:

- One does the functional change - this patch should be as small as
possible. This patch turns a piece of 'Intel documents' property
into 'actual code' that differs from the previous code, which may
or may not regress in practice.

- The other does the factoring out and the introduction of
<asm/cpuid/leaf_0x2_api.h>.

Thanks,

Ingo