lkml.org 
[lkml]   [2013]   [Feb]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/4] x86: Detect CPUID support early at boot
Date
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


\
 
 \ /
  Last update: 2013-02-03 18:01    [W:0.637 / U:0.004 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site