mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86/cpuid: Fewer CPUID invocations in init_scattered_cpuid_features()
@ 2018-01-23 14:53 David Woodhouse
  2018-01-23 17:32 ` Borislav Petkov
  0 siblings, 1 reply; 3+ messages in thread
From: David Woodhouse @ 2018-01-23 14:53 UTC (permalink / raw)
  To: x86, bp, linux-kernel

We were doing a fresh CPUID for every single bit in every single output
register. Do it once and then harvest *all* the bits we want.

We were also doing the max_level check with a new CPUID invocation for
every single bit. Stop that too.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
Spotted this in my travels; it offended me.

 arch/x86/kernel/cpu/scattered.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c
index df11f5d..26c15fb 100644
--- a/arch/x86/kernel/cpu/scattered.c
+++ b/arch/x86/kernel/cpu/scattered.c
@@ -23,8 +23,8 @@ static const struct cpuid_bit cpuid_bits[] = {
 	{ X86_FEATURE_EPB,		CPUID_ECX,  3, 0x00000006, 0 },
 	{ X86_FEATURE_CAT_L3,		CPUID_EBX,  1, 0x00000010, 0 },
 	{ X86_FEATURE_CAT_L2,		CPUID_EBX,  2, 0x00000010, 0 },
-	{ X86_FEATURE_CDP_L3,		CPUID_ECX,  2, 0x00000010, 1 },
 	{ X86_FEATURE_MBA,		CPUID_EBX,  3, 0x00000010, 0 },
+	{ X86_FEATURE_CDP_L3,		CPUID_ECX,  2, 0x00000010, 1 },
 	{ X86_FEATURE_HW_PSTATE,	CPUID_EDX,  7, 0x80000007, 0 },
 	{ X86_FEATURE_CPB,		CPUID_EDX,  9, 0x80000007, 0 },
 	{ X86_FEATURE_PROC_FEEDBACK,    CPUID_EDX, 11, 0x80000007, 0 },
@@ -38,20 +38,35 @@ void init_scattered_cpuid_features(struct cpuinfo_x86 *c)
 	u32 regs[4];
 	const struct cpuid_bit *cb;
 
+	/* Max level for basic CPUID leaves */
+	max_level = cpuid_eax(0);
+
 	for (cb = cpuid_bits; cb->feature; cb++) {
 
+		/* Are we on to extended CPUID leaves yet? */
+		if (cb->level >= 0x80000000 && max_level < 0x80000000) {
+			max_level = cpuid_eax(0x80000000);
+			if (max_level < 0x80000000 || max_level > 0x8000ffff) {
+				/* No extended leaves are supported */
+				break;
+			}
+		}
+
 		/* Verify that the level is valid */
-		max_level = cpuid_eax(cb->level & 0xffff0000);
-		if (max_level < cb->level ||
-		    max_level > (cb->level | 0xffff))
+		if (cb->level > max_level)
 			continue;
 
 		cpuid_count(cb->level, cb->sub_leaf, &regs[CPUID_EAX],
 			    &regs[CPUID_EBX], &regs[CPUID_ECX],
 			    &regs[CPUID_EDX]);
 
-		if (regs[cb->reg] & (1 << cb->bit))
-			set_cpu_cap(c, cb->feature);
+		do {
+			if (regs[cb->reg] & (1 << cb->bit))
+				set_cpu_cap(c, cb->feature);
+
+		} while (cb[1].level == cb[0].level &&
+			 cb[1].sub_leaf == cb[0].sub_leaf &&
+			 cb++);
 	}
 }
 
-- 
2.7.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-01-24  9:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-23 14:53 [PATCH] x86/cpuid: Fewer CPUID invocations in init_scattered_cpuid_features() David Woodhouse
2018-01-23 17:32 ` Borislav Petkov
2018-01-24  9:56   ` Borislav Petkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®