mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw@amazon.co.uk>
To: x86@kernel.org, bp@alien8.de, linux-kernel@vger.kernel.org
Subject: [PATCH] x86/cpuid: Fewer CPUID invocations in init_scattered_cpuid_features()
Date: Tue, 23 Jan 2018 14:53:33 +0000	[thread overview]
Message-ID: <1516719213-7199-1-git-send-email-dwmw@amazon.co.uk> (raw)

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

             reply	other threads:[~2018-01-23 14:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-23 14:53 David Woodhouse [this message]
2018-01-23 17:32 ` Borislav Petkov
2018-01-24  9:56   ` Borislav Petkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1516719213-7199-1-git-send-email-dwmw@amazon.co.uk \
    --to=dwmw@amazon.co.uk \
    --cc=bp@alien8.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®