linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: X86 ML <x86@kernel.org>, LKML <linux-kernel@vger.kernel.org>,
	Borislav Petkov <bp@suse.de>
Subject: [PATCH 2/4] x86: Detect CPUID support early at boot
Date: Sun,  3 Feb 2013 17:14:37 +0100	[thread overview]
Message-ID: <1359908079-10469-3-git-send-email-bp@alien8.de> (raw)
In-Reply-To: <1359908079-10469-1-git-send-email-bp@alien8.de>

From: Borislav Petkov <bp@suse.de>

We detect CPUID function support on the boot CPU and save it for later
use, obviating the need to play the toggle EFLAGS.ID game every time. C
code is looking at ->cpuid_level anyway.

Signed-off-by: Borislav Petkov <bp@suse.de>
---
 arch/x86/kernel/head_32.S | 36 +++++++++++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index a9c5cc851285..ce6b557017f4 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -29,16 +29,16 @@
 /*
  * References to members of the new_cpu_data structure.
  */
-
 #define X86		new_cpu_data+CPUINFO_x86
 #define X86_VENDOR	new_cpu_data+CPUINFO_x86_vendor
 #define X86_MODEL	new_cpu_data+CPUINFO_x86_model
 #define X86_MASK	new_cpu_data+CPUINFO_x86_mask
 #define X86_HARD_MATH	new_cpu_data+CPUINFO_hard_math
-#define X86_CPUID	new_cpu_data+CPUINFO_cpuid_level
 #define X86_CAPABILITY	new_cpu_data+CPUINFO_x86_capability
 #define X86_VENDOR_ID	new_cpu_data+CPUINFO_x86_vendor_id
 
+#define X86_CPUID	boot_cpu_data+CPUINFO_cpuid_level
+
 /*
  * This is how much memory in addition to the memory covered up to
  * and including _end we need mapped initially.
@@ -263,6 +263,33 @@ subarch_entries:
 num_subarch_entries = (. - subarch_entries) / 4
 .previous
 #else
+
+/*
+ * Initialize EFLAGS. Some BIOS's leave bits like NT set. This would confuse the
+ * debugger if this code is traced.
+ */
+	pushl $0
+	popfl
+
+/*
+ * Check whether this CPU supports CPUID, and, if so, save the highest standard
+ * CPUID function number for later.
+ */
+	movl $X86_EFLAGS_ID,%ecx	/* EFLAGS.ID */
+	pushl %ecx
+	popfl				/* set EFLAGS=ID */
+	pushfl				/* get EFLAGS */
+	popl %eax
+	xorl %ecx,%eax
+	jnz 1f				/* hw disallowed setting of ID bit */
+
+	xorl %eax,%eax
+	cpuid
+	movl %eax,pa(X86_CPUID)		/* save largest std CPUID function */
+	jmp default_entry
+
+1:
+	movl $-1,pa(X86_CPUID)
 	jmp default_entry
 #endif /* CONFIG_PARAVIRT */
 
@@ -377,11 +404,6 @@ default_entry:
 	/* Shift the stack pointer to a virtual address */
 	addl $__PAGE_OFFSET, %esp
 
-/*
- * Initialize eflags.  Some BIOS's leave bits like NT set.  This would
- * confuse the debugger if this code is traced.
- * XXX - best to initialize before switching to protected mode.
- */
 	pushl $0
 	popfl
 
-- 
1.8.1.2.422.g08c0e7f


  parent reply	other threads:[~2013-02-03 16:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-03 16:14 [PATCH 0/4] x86, head_32: Some cleanups Borislav Petkov
2013-02-03 16:14 ` [PATCH 1/4] x86, head_32: Remove i386 pieces Borislav Petkov
2013-02-03 16:14 ` Borislav Petkov [this message]
2013-02-03 16:14 ` [PATCH 3/4] x86, head_32: Remove CPUID detection from default_entry Borislav Petkov
2013-02-03 16:14 ` [PATCH 4/4] x86, 32-bit: Drop new_cpu_data Borislav Petkov
2013-02-03 23:44   ` H. Peter Anvin
2013-02-04  5:27     ` Borislav Petkov
2013-02-04  5:44       ` H. Peter Anvin
2013-02-04  9:02         ` Borislav Petkov
2013-02-04 16:55           ` H. Peter Anvin
2013-02-04 17:01             ` Borislav Petkov
2013-02-11 14:22 [PATCH 0/4 -v3] x86, head_32: Some cleanups Borislav Petkov
2013-02-11 14:22 ` [PATCH 2/4] x86: Detect CPUID support early at boot 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=1359908079-10469-3-git-send-email-bp@alien8.de \
    --to=bp@alien8.de \
    --cc=bp@suse.de \
    --cc=hpa@zytor.com \
    --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;
as well as URLs for NNTP newsgroup(s).