linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4 -v3]  x86, head_32: Some cleanups
@ 2013-02-11 14:22 Borislav Petkov
  2013-02-11 14:22 ` [PATCH 1/4] x86, head_32: Remove i386 pieces Borislav Petkov
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Borislav Petkov @ 2013-02-11 14:22 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: X86 ML, LKML, Borislav Petkov

From: Borislav Petkov <bp@suse.de>

Hi,

this is the new version with patch 5 from the old transformed into an
expanded, more verbose comment at the beginning of default_entry. No
changes otherwise.


Changelog:

v2:

Here's the next version with new_cpu_data left put and two minor fixlets
added at the end. The patchset was boot-tested on a bunch of baremetal
boxes and all QEMU cpu models - no issues.

Boot tests:

* baremetal:
- P4
- Atom n270
- 32-bit kernel on an AMD64 (F10h Phenom and Intel SNB)

* qemu, with cpu models:
 - qemu64
 - phenom
 - core2duo
 - kvm64
 - qemu32
 - kvm32
 - coreduo
 - 486{,SX}
 - pentium{,2,3}
 - athlon
 - n270,+movbe
 - Conroe
 - Penryn
 - Nehalem
 - Westmere
 - SandyBridge
 - Haswell
 - Opteron_G{1,2,3,4,5}

Why am I testing all those, you ask? Because I'm a sadistic mofo :-)

v1:

here are some initial low-hanging fruits wrt head_32.S cleanup. I've
made them as easily digestible as possible; after all, this is boot asm
and meddling with it tends to upset kernels.

Also, I've made the assumption that having boot_cpu_data.cpuid_level
contain the CPUID level for the boot cpu means that the APs have the
same CPUID level. This should be the case on X86.

They boot fine 486 and 486SX in qemu but I'd like to hear whether
the direction I'm going is ok before I continue testing them on real
hardware.

Borislav Petkov (4):
  x86, head_32: Remove i386 pieces
  x86: Detect CPUID support early at boot
  x86, head_32: Remove second CPUID detection from default_entry
  x86, head_32: Give the 6 label a real name

 arch/x86/kernel/head_32.S | 93 ++++++++++++++++++-----------------------------
 1 file changed, 36 insertions(+), 57 deletions(-)

-- 
1.8.1.3.535.ga923c31


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

* [PATCH 1/4] x86, head_32: Remove i386 pieces
  2013-02-11 14:22 [PATCH 0/4 -v3] x86, head_32: Some cleanups Borislav Petkov
@ 2013-02-11 14:22 ` Borislav Petkov
  2013-02-13  0:07   ` [tip:x86/asm] " tip-bot for Borislav Petkov
  2013-02-11 14:22 ` [PATCH 2/4] x86: Detect CPUID support early at boot Borislav Petkov
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Borislav Petkov @ 2013-02-11 14:22 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: X86 ML, LKML, Borislav Petkov

From: Borislav Petkov <bp@suse.de>

Remove code fragments detecting a 386 CPU since we don't support those
anymore. Also, do not do alignment checks because they're done only at
CPL3. Also, no need to preserve EFLAGS.

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

diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index 0b8c825fc264..f4d919e2cd2b 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -405,30 +405,21 @@ default_entry:
 	jz 1f				# Did we do this already?
 	call *%eax
 1:
-	
-/* check if it is 486 or 386. */
+
 /*
- * XXX - this does a lot of unnecessary setup.  Alignment checks don't
- * apply at our cpl of 0 and the stack ought to be aligned already, and
- * we don't need to preserve eflags.
+ * Check if it is 486
  */
 	movl $-1,X86_CPUID	# -1 for no CPUID initially
-	movb $3,X86		# at least 386
+	movb $4,X86		# at least 486
 	pushfl			# push EFLAGS
 	popl %eax		# get EFLAGS
 	movl %eax,%ecx		# save original EFLAGS
-	xorl $0x240000,%eax	# flip AC and ID bits in EFLAGS
+	xorl $0x200000,%eax	# flip ID bit in EFLAGS
 	pushl %eax		# copy to EFLAGS
 	popfl			# set EFLAGS
 	pushfl			# get new EFLAGS
 	popl %eax		# put it in eax
 	xorl %ecx,%eax		# change in flags
-	pushl %ecx		# restore original EFLAGS
-	popfl
-	testl $0x40000,%eax	# check if AC bit changed
-	je is386
-
-	movb $4,X86		# at least 486
 	testl $0x200000,%eax	# check if ID bit changed
 	je is486
 
@@ -456,10 +447,7 @@ default_entry:
 	movl %edx,X86_CAPABILITY
 
 is486:	movl $0x50022,%ecx	# set AM, WP, NE and MP
-	jmp 2f
-
-is386:	movl $2,%ecx		# set MP
-2:	movl %cr0,%eax
+	movl %cr0,%eax
 	andl $0x80000011,%eax	# Save PG,PE,ET
 	orl %ecx,%eax
 	movl %eax,%cr0
-- 
1.8.1.3.535.ga923c31


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

* [PATCH 2/4] x86: Detect CPUID support early at boot
  2013-02-11 14:22 [PATCH 0/4 -v3] x86, head_32: Some cleanups Borislav Petkov
  2013-02-11 14:22 ` [PATCH 1/4] x86, head_32: Remove i386 pieces Borislav Petkov
@ 2013-02-11 14:22 ` Borislav Petkov
  2013-02-13  0:09   ` [tip:x86/asm] " tip-bot for Borislav Petkov
  2013-02-11 14:22 ` [PATCH 3/4] x86, head_32: Remove second CPUID detection from default_entry Borislav Petkov
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Borislav Petkov @ 2013-02-11 14:22 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: X86 ML, LKML, Borislav Petkov

From: Borislav Petkov <bp@suse.de>

We detect CPUID function support on each 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 | 50 +++++++++++++++++++++++------------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index f4d919e2cd2b..73e084a6d2c5 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -318,30 +318,39 @@ default_entry:
 	movl %eax,%cr0
 
 /*
- *	New page tables may be in 4Mbyte page mode and may
- *	be using the global pages. 
+ * We want to start out with EFLAGS unambiguously cleared. Some BIOSes leave
+ * bits like NT set. This would confuse the debugger if this code is traced. So
+ * initialize them properly now before switching to protected mode. That means
+ * DF in particular (even though we have cleared it earlier after copying the
+ * command line) because GCC expects it.
+ */
+	pushl $0
+	popfl
+
+/*
+ * New page tables may be in 4Mbyte page mode and may be using the global pages.
  *
- *	NOTE! If we are on a 486 we may have no cr4 at all!
- *	Specifically, cr4 exists if and only if CPUID exists
- *	and has flags other than the FPU flag set.
+ * NOTE! If we are on a 486 we may have no cr4 at all! Specifically, cr4 exists
+ * if and only if CPUID exists and has flags other than the FPU flag set.
  */
+	movl $-1,pa(X86_CPUID)		# preset CPUID level
 	movl $X86_EFLAGS_ID,%ecx
 	pushl %ecx
-	popfl
-	pushfl
-	popl %eax
-	pushl $0
-	popfl
+	popfl				# set EFLAGS=ID
 	pushfl
-	popl %edx
-	xorl %edx,%eax
-	testl %ecx,%eax
-	jz 6f			# No ID flag = no CPUID = no CR4
+	popl %eax			# get EFLAGS
+	testl $X86_EFLAGS_ID,%eax	# did EFLAGS.ID remained set?
+	jz 6f				# hw disallowed setting of ID bit
+					# which means no CPUID and no CR4
+
+	xorl %eax,%eax
+	cpuid
+	movl %eax,pa(X86_CPUID)		# save largest std CPUID function
 
 	movl $1,%eax
 	cpuid
-	andl $~1,%edx		# Ignore CPUID.FPU
-	jz 6f			# No flags or only CPUID.FPU = no CR4
+	andl $~1,%edx			# Ignore CPUID.FPU
+	jz 6f				# No flags or only CPUID.FPU = no CR4
 
 	movl pa(mmu_cr4_features),%eax
 	movl %eax,%cr4
@@ -389,14 +398,6 @@ default_entry:
 	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
-
-/*
  * start system 32-bit setup. We need to re-do some of the things done
  * in 16-bit mode for the "real" operations.
  */
@@ -472,7 +473,6 @@ is486:	movl $0x50022,%ecx	# set AM, WP, NE and MP
 	xorl %eax,%eax			# Clear LDT
 	lldt %ax
 
-	cld			# gcc2 wants the direction flag cleared at all times
 	pushl $0		# fake return address for unwinder
 	jmp *(initial_code)
 
-- 
1.8.1.3.535.ga923c31


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

* [PATCH 3/4] x86, head_32: Remove second CPUID detection from default_entry
  2013-02-11 14:22 [PATCH 0/4 -v3] x86, head_32: Some cleanups Borislav Petkov
  2013-02-11 14:22 ` [PATCH 1/4] x86, head_32: Remove i386 pieces Borislav Petkov
  2013-02-11 14:22 ` [PATCH 2/4] x86: Detect CPUID support early at boot Borislav Petkov
@ 2013-02-11 14:22 ` Borislav Petkov
  2013-02-11 15:49   ` H. Peter Anvin
  2013-02-13  0:10   ` [tip:x86/asm] " tip-bot for Borislav Petkov
  2013-02-11 14:22 ` [PATCH 4/4] x86, head_32: Give the 6 label a real name Borislav Petkov
  2013-02-11 16:56 ` [PATCH 0/4 -v3] x86, head_32: Some cleanups H. Peter Anvin
  4 siblings, 2 replies; 13+ messages in thread
From: Borislav Petkov @ 2013-02-11 14:22 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: X86 ML, LKML, Borislav Petkov

From: Borislav Petkov <bp@suse.de>

We do that once earlier now and cache it into new_cpu_data.cpuid_level
so no need for the EFLAGS.ID toggling dance anymore.

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

diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index 73e084a6d2c5..e893ac09ca03 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -410,18 +410,7 @@ default_entry:
 /*
  * Check if it is 486
  */
-	movl $-1,X86_CPUID	# -1 for no CPUID initially
-	movb $4,X86		# at least 486
-	pushfl			# push EFLAGS
-	popl %eax		# get EFLAGS
-	movl %eax,%ecx		# save original EFLAGS
-	xorl $0x200000,%eax	# flip ID bit in EFLAGS
-	pushl %eax		# copy to EFLAGS
-	popfl			# set EFLAGS
-	pushfl			# get new EFLAGS
-	popl %eax		# put it in eax
-	xorl %ecx,%eax		# change in flags
-	testl $0x200000,%eax	# check if ID bit changed
+	cmpl $-1,X86_CPUID
 	je is486
 
 	/* get vendor info */
@@ -447,7 +436,9 @@ default_entry:
 	movb %cl,X86_MASK
 	movl %edx,X86_CAPABILITY
 
-is486:	movl $0x50022,%ecx	# set AM, WP, NE and MP
+is486:
+	movb $4,X86
+	movl $0x50022,%ecx	# set AM, WP, NE and MP
 	movl %cr0,%eax
 	andl $0x80000011,%eax	# Save PG,PE,ET
 	orl %ecx,%eax
-- 
1.8.1.3.535.ga923c31


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

* [PATCH 4/4] x86, head_32: Give the 6 label a real name
  2013-02-11 14:22 [PATCH 0/4 -v3] x86, head_32: Some cleanups Borislav Petkov
                   ` (2 preceding siblings ...)
  2013-02-11 14:22 ` [PATCH 3/4] x86, head_32: Remove second CPUID detection from default_entry Borislav Petkov
@ 2013-02-11 14:22 ` Borislav Petkov
  2013-02-13  0:11   ` [tip:x86/asm] " tip-bot for Borislav Petkov
  2013-02-11 16:56 ` [PATCH 0/4 -v3] x86, head_32: Some cleanups H. Peter Anvin
  4 siblings, 1 reply; 13+ messages in thread
From: Borislav Petkov @ 2013-02-11 14:22 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: X86 ML, LKML, Borislav Petkov

From: Borislav Petkov <bp@suse.de>

Jumping here we are about to enable paging so rename the label
accordingly.

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

diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index e893ac09ca03..73afd11799ca 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -340,7 +340,7 @@ default_entry:
 	pushfl
 	popl %eax			# get EFLAGS
 	testl $X86_EFLAGS_ID,%eax	# did EFLAGS.ID remained set?
-	jz 6f				# hw disallowed setting of ID bit
+	jz enable_paging		# hw disallowed setting of ID bit
 					# which means no CPUID and no CR4
 
 	xorl %eax,%eax
@@ -350,13 +350,13 @@ default_entry:
 	movl $1,%eax
 	cpuid
 	andl $~1,%edx			# Ignore CPUID.FPU
-	jz 6f				# No flags or only CPUID.FPU = no CR4
+	jz enable_paging		# No flags or only CPUID.FPU = no CR4
 
 	movl pa(mmu_cr4_features),%eax
 	movl %eax,%cr4
 
 	testb $X86_CR4_PAE, %al		# check if PAE is enabled
-	jz 6f
+	jz enable_paging
 
 	/* Check if extended functions are implemented */
 	movl $0x80000000, %eax
@@ -364,7 +364,7 @@ default_entry:
 	/* Value must be in the range 0x80000001 to 0x8000ffff */
 	subl $0x80000001, %eax
 	cmpl $(0x8000ffff-0x80000001), %eax
-	ja 6f
+	ja enable_paging
 
 	/* Clear bogus XD_DISABLE bits */
 	call verify_cpu
@@ -373,7 +373,7 @@ default_entry:
 	cpuid
 	/* Execute Disable bit supported? */
 	btl $(X86_FEATURE_NX & 31), %edx
-	jnc 6f
+	jnc enable_paging
 
 	/* Setup EFER (Extended Feature Enable Register) */
 	movl $MSR_EFER, %ecx
@@ -383,7 +383,7 @@ default_entry:
 	/* Make changes effective */
 	wrmsr
 
-6:
+enable_paging:
 
 /*
  * Enable paging
-- 
1.8.1.3.535.ga923c31


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

* Re: [PATCH 3/4] x86, head_32: Remove second CPUID detection from default_entry
  2013-02-11 14:22 ` [PATCH 3/4] x86, head_32: Remove second CPUID detection from default_entry Borislav Petkov
@ 2013-02-11 15:49   ` H. Peter Anvin
  2013-02-11 17:15     ` Borislav Petkov
  2013-02-13  0:10   ` [tip:x86/asm] " tip-bot for Borislav Petkov
  1 sibling, 1 reply; 13+ messages in thread
From: H. Peter Anvin @ 2013-02-11 15:49 UTC (permalink / raw)
  To: Borislav Petkov; +Cc: X86 ML, LKML, Borislav Petkov

What about CPUs with inconsistent cpuid levels?  Yes, they can and do happen, as we discussed on IRC.

Borislav Petkov <bp@alien8.de> wrote:

>From: Borislav Petkov <bp@suse.de>
>
>We do that once earlier now and cache it into new_cpu_data.cpuid_level
>so no need for the EFLAGS.ID toggling dance anymore.
>
>Signed-off-by: Borislav Petkov <bp@suse.de>
>---
> arch/x86/kernel/head_32.S | 17 ++++-------------
> 1 file changed, 4 insertions(+), 13 deletions(-)
>
>diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
>index 73e084a6d2c5..e893ac09ca03 100644
>--- a/arch/x86/kernel/head_32.S
>+++ b/arch/x86/kernel/head_32.S
>@@ -410,18 +410,7 @@ default_entry:
> /*
>  * Check if it is 486
>  */
>-	movl $-1,X86_CPUID	# -1 for no CPUID initially
>-	movb $4,X86		# at least 486
>-	pushfl			# push EFLAGS
>-	popl %eax		# get EFLAGS
>-	movl %eax,%ecx		# save original EFLAGS
>-	xorl $0x200000,%eax	# flip ID bit in EFLAGS
>-	pushl %eax		# copy to EFLAGS
>-	popfl			# set EFLAGS
>-	pushfl			# get new EFLAGS
>-	popl %eax		# put it in eax
>-	xorl %ecx,%eax		# change in flags
>-	testl $0x200000,%eax	# check if ID bit changed
>+	cmpl $-1,X86_CPUID
> 	je is486
> 
> 	/* get vendor info */
>@@ -447,7 +436,9 @@ default_entry:
> 	movb %cl,X86_MASK
> 	movl %edx,X86_CAPABILITY
> 
>-is486:	movl $0x50022,%ecx	# set AM, WP, NE and MP
>+is486:
>+	movb $4,X86
>+	movl $0x50022,%ecx	# set AM, WP, NE and MP
> 	movl %cr0,%eax
> 	andl $0x80000011,%eax	# Save PG,PE,ET
> 	orl %ecx,%eax

-- 
Sent from my mobile phone. Please excuse brevity and lack of formatting.

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

* Re: [PATCH 0/4 -v3]  x86, head_32: Some cleanups
  2013-02-11 14:22 [PATCH 0/4 -v3] x86, head_32: Some cleanups Borislav Petkov
                   ` (3 preceding siblings ...)
  2013-02-11 14:22 ` [PATCH 4/4] x86, head_32: Give the 6 label a real name Borislav Petkov
@ 2013-02-11 16:56 ` H. Peter Anvin
  4 siblings, 0 replies; 13+ messages in thread
From: H. Peter Anvin @ 2013-02-11 16:56 UTC (permalink / raw)
  To: Borislav Petkov; +Cc: X86 ML, LKML, Borislav Petkov

On 02/11/2013 06:22 AM, Borislav Petkov wrote:
> From: Borislav Petkov <bp@suse.de>
>
> Hi,
>
> this is the new version with patch 5 from the old transformed into an
> expanded, more verbose comment at the beginning of default_entry. No
> changes otherwise.
>

By the way, I like the series.  I do think we should try to keep the 
current "best effort" support for hetero systems (they do happen, I see 
them every now and then in the field), but other than that this is a 
nice cleanup.

	-hpa

-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.


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

* Re: [PATCH 3/4] x86, head_32: Remove second CPUID detection from default_entry
  2013-02-11 15:49   ` H. Peter Anvin
@ 2013-02-11 17:15     ` Borislav Petkov
  2013-02-11 17:21       ` H. Peter Anvin
  0 siblings, 1 reply; 13+ messages in thread
From: Borislav Petkov @ 2013-02-11 17:15 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: X86 ML, LKML, Borislav Petkov

On Mon, Feb 11, 2013 at 07:49:14AM -0800, H. Peter Anvin wrote:
> What about CPUs with inconsistent cpuid levels? Yes, they can and do
> happen, as we discussed on IRC.

Yes, this should still work. We're doing the EFLAGS.ID dance right at
the beginning of default_entry on each cpu and cache cpuld level in
new_cpu_data for the time we're in this code.

What this particular patch removes is the yet-another EFLAGS.ID dance
which we IMHO unnecessarily did after enabling paging.

So basically nothing changes wrt handling inconsistent cpuid levels and
MSR mis-programming - we still should be taking care of those cases.

Thanks.

-- 
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--

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

* Re: [PATCH 3/4] x86, head_32: Remove second CPUID detection from default_entry
  2013-02-11 17:15     ` Borislav Petkov
@ 2013-02-11 17:21       ` H. Peter Anvin
  0 siblings, 0 replies; 13+ messages in thread
From: H. Peter Anvin @ 2013-02-11 17:21 UTC (permalink / raw)
  To: Borislav Petkov, X86 ML, LKML, Borislav Petkov

On 02/11/2013 09:15 AM, Borislav Petkov wrote:
> On Mon, Feb 11, 2013 at 07:49:14AM -0800, H. Peter Anvin wrote:
>> What about CPUs with inconsistent cpuid levels? Yes, they can and do
>> happen, as we discussed on IRC.
>
> Yes, this should still work. We're doing the EFLAGS.ID dance right at
> the beginning of default_entry on each cpu and cache cpuld level in
> new_cpu_data for the time we're in this code.
>
> What this particular patch removes is the yet-another EFLAGS.ID dance
> which we IMHO unnecessarily did after enabling paging.
>
> So basically nothing changes wrt handling inconsistent cpuid levels and
> MSR mis-programming - we still should be taking care of those cases.
>

Cool.  I misread your 0/4 cover and hadn't quite dug into the details yet.

	-hpa


-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.


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

* [tip:x86/asm] x86, head_32: Remove i386 pieces
  2013-02-11 14:22 ` [PATCH 1/4] x86, head_32: Remove i386 pieces Borislav Petkov
@ 2013-02-13  0:07   ` tip-bot for Borislav Petkov
  0 siblings, 0 replies; 13+ messages in thread
From: tip-bot for Borislav Petkov @ 2013-02-13  0:07 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, tglx, hpa, bp

Commit-ID:  166df91daf38f619d4ca90b58ff90983de6e40d2
Gitweb:     http://git.kernel.org/tip/166df91daf38f619d4ca90b58ff90983de6e40d2
Author:     Borislav Petkov <bp@suse.de>
AuthorDate: Mon, 11 Feb 2013 15:22:15 +0100
Committer:  H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Tue, 12 Feb 2013 15:48:40 -0800

x86, head_32: Remove i386 pieces

Remove code fragments detecting a 386 CPU since we don't support those
anymore. Also, do not do alignment checks because they're done only at
CPL3. Also, no need to preserve EFLAGS.

Signed-off-by: Borislav Petkov <bp@suse.de>
Link: http://lkml.kernel.org/r/1360592538-10643-2-git-send-email-bp@alien8.de
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
---
 arch/x86/kernel/head_32.S | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)

diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index c8932c7..a9c5cc8 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -394,30 +394,21 @@ default_entry:
 	jz 1f				# Did we do this already?
 	call *%eax
 1:
-	
-/* check if it is 486 or 386. */
+
 /*
- * XXX - this does a lot of unnecessary setup.  Alignment checks don't
- * apply at our cpl of 0 and the stack ought to be aligned already, and
- * we don't need to preserve eflags.
+ * Check if it is 486
  */
 	movl $-1,X86_CPUID	# -1 for no CPUID initially
-	movb $3,X86		# at least 386
+	movb $4,X86		# at least 486
 	pushfl			# push EFLAGS
 	popl %eax		# get EFLAGS
 	movl %eax,%ecx		# save original EFLAGS
-	xorl $0x240000,%eax	# flip AC and ID bits in EFLAGS
+	xorl $0x200000,%eax	# flip ID bit in EFLAGS
 	pushl %eax		# copy to EFLAGS
 	popfl			# set EFLAGS
 	pushfl			# get new EFLAGS
 	popl %eax		# put it in eax
 	xorl %ecx,%eax		# change in flags
-	pushl %ecx		# restore original EFLAGS
-	popfl
-	testl $0x40000,%eax	# check if AC bit changed
-	je is386
-
-	movb $4,X86		# at least 486
 	testl $0x200000,%eax	# check if ID bit changed
 	je is486
 
@@ -445,10 +436,7 @@ default_entry:
 	movl %edx,X86_CAPABILITY
 
 is486:	movl $0x50022,%ecx	# set AM, WP, NE and MP
-	jmp 2f
-
-is386:	movl $2,%ecx		# set MP
-2:	movl %cr0,%eax
+	movl %cr0,%eax
 	andl $0x80000011,%eax	# Save PG,PE,ET
 	orl %ecx,%eax
 	movl %eax,%cr0

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

* [tip:x86/asm] x86: Detect CPUID support early at boot
  2013-02-11 14:22 ` [PATCH 2/4] x86: Detect CPUID support early at boot Borislav Petkov
@ 2013-02-13  0:09   ` tip-bot for Borislav Petkov
  0 siblings, 0 replies; 13+ messages in thread
From: tip-bot for Borislav Petkov @ 2013-02-13  0:09 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, tglx, hpa, bp

Commit-ID:  9efb58de919efa8312861d454be014094f6f0ffc
Gitweb:     http://git.kernel.org/tip/9efb58de919efa8312861d454be014094f6f0ffc
Author:     Borislav Petkov <bp@suse.de>
AuthorDate: Mon, 11 Feb 2013 15:22:16 +0100
Committer:  H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Tue, 12 Feb 2013 15:48:41 -0800

x86: Detect CPUID support early at boot

We detect CPUID function support on each 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>
Link: http://lkml.kernel.org/r/1360592538-10643-3-git-send-email-bp@alien8.de
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
---
 arch/x86/kernel/head_32.S | 50 +++++++++++++++++++++++------------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index a9c5cc8..e3725a0 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -307,30 +307,39 @@ default_entry:
 	movl %eax,%cr0
 
 /*
- *	New page tables may be in 4Mbyte page mode and may
- *	be using the global pages. 
+ * We want to start out with EFLAGS unambiguously cleared. Some BIOSes leave
+ * bits like NT set. This would confuse the debugger if this code is traced. So
+ * initialize them properly now before switching to protected mode. That means
+ * DF in particular (even though we have cleared it earlier after copying the
+ * command line) because GCC expects it.
+ */
+	pushl $0
+	popfl
+
+/*
+ * New page tables may be in 4Mbyte page mode and may be using the global pages.
  *
- *	NOTE! If we are on a 486 we may have no cr4 at all!
- *	Specifically, cr4 exists if and only if CPUID exists
- *	and has flags other than the FPU flag set.
+ * NOTE! If we are on a 486 we may have no cr4 at all! Specifically, cr4 exists
+ * if and only if CPUID exists and has flags other than the FPU flag set.
  */
+	movl $-1,pa(X86_CPUID)		# preset CPUID level
 	movl $X86_EFLAGS_ID,%ecx
 	pushl %ecx
-	popfl
-	pushfl
-	popl %eax
-	pushl $0
-	popfl
+	popfl				# set EFLAGS=ID
 	pushfl
-	popl %edx
-	xorl %edx,%eax
-	testl %ecx,%eax
-	jz 6f			# No ID flag = no CPUID = no CR4
+	popl %eax			# get EFLAGS
+	testl $X86_EFLAGS_ID,%eax	# did EFLAGS.ID remained set?
+	jz 6f				# hw disallowed setting of ID bit
+					# which means no CPUID and no CR4
+
+	xorl %eax,%eax
+	cpuid
+	movl %eax,pa(X86_CPUID)		# save largest std CPUID function
 
 	movl $1,%eax
 	cpuid
-	andl $~1,%edx		# Ignore CPUID.FPU
-	jz 6f			# No flags or only CPUID.FPU = no CR4
+	andl $~1,%edx			# Ignore CPUID.FPU
+	jz 6f				# No flags or only CPUID.FPU = no CR4
 
 	movl pa(mmu_cr4_features),%eax
 	movl %eax,%cr4
@@ -378,14 +387,6 @@ default_entry:
 	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
-
-/*
  * start system 32-bit setup. We need to re-do some of the things done
  * in 16-bit mode for the "real" operations.
  */
@@ -461,7 +462,6 @@ is486:	movl $0x50022,%ecx	# set AM, WP, NE and MP
 	xorl %eax,%eax			# Clear LDT
 	lldt %ax
 
-	cld			# gcc2 wants the direction flag cleared at all times
 	pushl $0		# fake return address for unwinder
 	jmp *(initial_code)
 

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

* [tip:x86/asm] x86, head_32: Remove second CPUID detection from default_entry
  2013-02-11 14:22 ` [PATCH 3/4] x86, head_32: Remove second CPUID detection from default_entry Borislav Petkov
  2013-02-11 15:49   ` H. Peter Anvin
@ 2013-02-13  0:10   ` tip-bot for Borislav Petkov
  1 sibling, 0 replies; 13+ messages in thread
From: tip-bot for Borislav Petkov @ 2013-02-13  0:10 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, tglx, hpa, bp

Commit-ID:  c3a22a26d07d928e2b74b58e2f9d2436958620f0
Gitweb:     http://git.kernel.org/tip/c3a22a26d07d928e2b74b58e2f9d2436958620f0
Author:     Borislav Petkov <bp@suse.de>
AuthorDate: Mon, 11 Feb 2013 15:22:17 +0100
Committer:  H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Tue, 12 Feb 2013 15:48:42 -0800

x86, head_32: Remove second CPUID detection from default_entry

We do that once earlier now and cache it into new_cpu_data.cpuid_level
so no need for the EFLAGS.ID toggling dance anymore.

Signed-off-by: Borislav Petkov <bp@suse.de>
Link: http://lkml.kernel.org/r/1360592538-10643-4-git-send-email-bp@alien8.de
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
---
 arch/x86/kernel/head_32.S | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index e3725a0..2e8532e 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -399,18 +399,7 @@ default_entry:
 /*
  * Check if it is 486
  */
-	movl $-1,X86_CPUID	# -1 for no CPUID initially
-	movb $4,X86		# at least 486
-	pushfl			# push EFLAGS
-	popl %eax		# get EFLAGS
-	movl %eax,%ecx		# save original EFLAGS
-	xorl $0x200000,%eax	# flip ID bit in EFLAGS
-	pushl %eax		# copy to EFLAGS
-	popfl			# set EFLAGS
-	pushfl			# get new EFLAGS
-	popl %eax		# put it in eax
-	xorl %ecx,%eax		# change in flags
-	testl $0x200000,%eax	# check if ID bit changed
+	cmpl $-1,X86_CPUID
 	je is486
 
 	/* get vendor info */
@@ -436,7 +425,9 @@ default_entry:
 	movb %cl,X86_MASK
 	movl %edx,X86_CAPABILITY
 
-is486:	movl $0x50022,%ecx	# set AM, WP, NE and MP
+is486:
+	movb $4,X86
+	movl $0x50022,%ecx	# set AM, WP, NE and MP
 	movl %cr0,%eax
 	andl $0x80000011,%eax	# Save PG,PE,ET
 	orl %ecx,%eax

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

* [tip:x86/asm] x86, head_32: Give the 6 label a real name
  2013-02-11 14:22 ` [PATCH 4/4] x86, head_32: Give the 6 label a real name Borislav Petkov
@ 2013-02-13  0:11   ` tip-bot for Borislav Petkov
  0 siblings, 0 replies; 13+ messages in thread
From: tip-bot for Borislav Petkov @ 2013-02-13  0:11 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, tglx, hpa, bp

Commit-ID:  5e2a044daf0c6f897eb69de931e3b29020e874a9
Gitweb:     http://git.kernel.org/tip/5e2a044daf0c6f897eb69de931e3b29020e874a9
Author:     Borislav Petkov <bp@suse.de>
AuthorDate: Mon, 11 Feb 2013 15:22:18 +0100
Committer:  H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Tue, 12 Feb 2013 15:48:42 -0800

x86, head_32: Give the 6 label a real name

Jumping here we are about to enable paging so rename the label
accordingly.

Signed-off-by: Borislav Petkov <bp@suse.de>
Link: http://lkml.kernel.org/r/1360592538-10643-5-git-send-email-bp@alien8.de
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
---
 arch/x86/kernel/head_32.S | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index 2e8532e..3c3f58a 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -329,7 +329,7 @@ default_entry:
 	pushfl
 	popl %eax			# get EFLAGS
 	testl $X86_EFLAGS_ID,%eax	# did EFLAGS.ID remained set?
-	jz 6f				# hw disallowed setting of ID bit
+	jz enable_paging		# hw disallowed setting of ID bit
 					# which means no CPUID and no CR4
 
 	xorl %eax,%eax
@@ -339,13 +339,13 @@ default_entry:
 	movl $1,%eax
 	cpuid
 	andl $~1,%edx			# Ignore CPUID.FPU
-	jz 6f				# No flags or only CPUID.FPU = no CR4
+	jz enable_paging		# No flags or only CPUID.FPU = no CR4
 
 	movl pa(mmu_cr4_features),%eax
 	movl %eax,%cr4
 
 	testb $X86_CR4_PAE, %al		# check if PAE is enabled
-	jz 6f
+	jz enable_paging
 
 	/* Check if extended functions are implemented */
 	movl $0x80000000, %eax
@@ -353,7 +353,7 @@ default_entry:
 	/* Value must be in the range 0x80000001 to 0x8000ffff */
 	subl $0x80000001, %eax
 	cmpl $(0x8000ffff-0x80000001), %eax
-	ja 6f
+	ja enable_paging
 
 	/* Clear bogus XD_DISABLE bits */
 	call verify_cpu
@@ -362,7 +362,7 @@ default_entry:
 	cpuid
 	/* Execute Disable bit supported? */
 	btl $(X86_FEATURE_NX & 31), %edx
-	jnc 6f
+	jnc enable_paging
 
 	/* Setup EFER (Extended Feature Enable Register) */
 	movl $MSR_EFER, %ecx
@@ -372,7 +372,7 @@ default_entry:
 	/* Make changes effective */
 	wrmsr
 
-6:
+enable_paging:
 
 /*
  * Enable paging

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

end of thread, other threads:[~2013-02-13  0:13 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-11 14:22 [PATCH 0/4 -v3] x86, head_32: Some cleanups Borislav Petkov
2013-02-11 14:22 ` [PATCH 1/4] x86, head_32: Remove i386 pieces Borislav Petkov
2013-02-13  0:07   ` [tip:x86/asm] " tip-bot for Borislav Petkov
2013-02-11 14:22 ` [PATCH 2/4] x86: Detect CPUID support early at boot Borislav Petkov
2013-02-13  0:09   ` [tip:x86/asm] " tip-bot for Borislav Petkov
2013-02-11 14:22 ` [PATCH 3/4] x86, head_32: Remove second CPUID detection from default_entry Borislav Petkov
2013-02-11 15:49   ` H. Peter Anvin
2013-02-11 17:15     ` Borislav Petkov
2013-02-11 17:21       ` H. Peter Anvin
2013-02-13  0:10   ` [tip:x86/asm] " tip-bot for Borislav Petkov
2013-02-11 14:22 ` [PATCH 4/4] x86, head_32: Give the 6 label a real name Borislav Petkov
2013-02-13  0:11   ` [tip:x86/asm] " tip-bot for Borislav Petkov
2013-02-11 16:56 ` [PATCH 0/4 -v3] x86, head_32: Some cleanups H. Peter Anvin

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).