[PATCH v6 31/90] x86/cpuid: Warn once on invalid CPUID(0x2) iteration count

Ahmed S. Darwish posted 90 patches 6 days, 16 hours ago
[PATCH v6 31/90] x86/cpuid: Warn once on invalid CPUID(0x2) iteration count
Posted by Ahmed S. Darwish 6 days, 16 hours ago
CPUID(0x2) output includes a "query count" byte.  That byte was supposed to
specify the number of repeated CPUID(0x2) subleaf 0 queries needed to
extract all of the CPU's cache and TLB descriptors.

Per current Intel manuals, all CPUs supporting this leaf "will always"
return an iteration count of 1.

Since the CPUID parser ignores any CPUID(0x2) output with an invalid
iteration count, lightly warn about this once in the kernel log.

Do not emit a warning if some of the CPUID(0x2) output registers, or even
all of them, are invalid.  This is an architecturally-defined response.

Suggested-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Ahmed S. Darwish <darwi@linutronix.de>
References: b5969494c8d8 ("x86/cpu: Remove CPUID leaf 0x2 parsing loop")
Link: https://lore.kernel.org/lkml/aBnmy_Bmf-H0wxqz@gmail.com
---
 arch/x86/kernel/cpu/cpuid_parser.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/cpuid_parser.c b/arch/x86/kernel/cpu/cpuid_parser.c
index be340b202182..bddd9937bb2b 100644
--- a/arch/x86/kernel/cpu/cpuid_parser.c
+++ b/arch/x86/kernel/cpu/cpuid_parser.c
@@ -3,6 +3,8 @@
  * CPUID parser; for populating the system's CPUID tables.
  */
 
+#define pr_fmt(fmt) "x86/cpuid: " fmt
+
 #include <linux/kernel.h>
 
 #include <asm/cpuid/api.h>
@@ -54,8 +56,11 @@ cpuid_read_0x2(const struct cpuid_parse_entry *e, const struct cpuid_read_output
 	 * keep the leaf marked as invalid at the CPUID table.
 	 */
 	cpuid_read_subleaf(e->leaf, e->subleaf, l);
-	if (l->iteration_count != 0x01)
+	if (l->iteration_count != 0x01) {
+		pr_warn_once("Ignoring CPUID(0x2) due to invalid iteration count = %d",
+			     l->iteration_count);
 		return;
+	}
 
 	/*
 	 * The most significant bit (MSB) of each CPUID(0x2) register must be clear.
-- 
2.53.0