]> git.ipfire.org Git - thirdparty/linux.git/commit
tools/x86/kcpuid: Filter valid CPUID ranges
authorAhmed S. Darwish <darwi@linutronix.de>
Mon, 24 Mar 2025 14:20:35 +0000 (15:20 +0100)
committerIngo Molnar <mingo@kernel.org>
Tue, 25 Mar 2025 08:53:46 +0000 (09:53 +0100)
commit72383c8274edf0a1736973462603dcfd0a088bb9
treea1a70a92d3bc7d16fe35b096c9f99e0bc4755df3
parent74d29127f83042500c20c903dd67151dbdd86ec8
tools/x86/kcpuid: Filter valid CPUID ranges

Next commits will introduce vendor-specific CPUID ranges like Transmeta's
0x8086000 range and Centaur's 0xc0000000.

Initially explicit vendor detection was implemented, but it turned out to
be not strictly necessary.  As Dave Hansen noted, even established tools
like cpuid(1) just tries all ranges indices, and see if the CPU responds
back with something sensible.

Do something similar at setup_cpuid_range().  Query the range's index,
and check the maximum range function value returned.  If it's within an
expected interval of [range_index, range_index + MAX_RANGE_INDEX_OFFSET],
accept the range as valid and further query its leaves.

Set MAX_RANGE_INDEX_OFFSET to a heuristic of 0xff.  That should be
sensible enough since all the ranges covered by x86-cpuid-db XML database
are:

0x00000000 0x00000023
0x40000000 0x40000000
0x80000000 0x80000026
0x80860000 0x80860007
0xc0000000 0xc0000001

At setup_cpuid_range(), if the range's returned maximum function was not
sane, mark it as invalid by setting its number of leaves, range->nr, to
zero.

Introduce the for_each_valid_cpuid_range() iterator instead of sprinkling
"range->nr != 0" checks throughout the code.

Suggested-by: Dave Hansen <dave.hansen@intel.com>
Signed-off-by: Ahmed S. Darwish <darwi@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Link: https://lore.kernel.org/r/20250324142042.29010-15-darwi@linutronix.de
tools/arch/x86/kcpuid/kcpuid.c