public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix i486 boot failure due to stale %ds
@ 2007-11-04 16:44 Mikael Pettersson
  2007-11-04 18:29 ` H. Peter Anvin
  0 siblings, 1 reply; 15+ messages in thread
From: Mikael Pettersson @ 2007-11-04 16:44 UTC (permalink / raw)
  To: linux-kernel; +Cc: hpa, mingo, tglx

On Mon, 29 Oct 2007 01:05:58 +0100 (MET), Mikael Pettersson wrote:
>My old 486 fails to boot with the 2.6.24-rc1 kernel.
>Grub loads it, 4 lines of text appear but not the kernel's
>"Linux version <blah> greet", and the machine reboots.
>Double-checked with a serial console: nothing appears
>before it reboots.
>
>All 2.6 kernels up to 2.6.23 worked fine on this machine.

Problem identified and solved.

The last good kernel was 2.6.23-git17. The change in 2.6.23-git18
that broke my 486 was a24e785111a32ccb7cebafd24b1b1cb474ea8e5d,
which included the following:

>--- a/arch/x86/boot/compressed/head_32.S
>+++ b/arch/x86/boot/compressed/head_32.S
>@@ -27,13 +27,22 @@
> #include <asm/segment.h>
> #include <asm/page.h>
> #include <asm/boot.h>
>+#include <asm/asm-offsets.h>
> 
> .section ".text.head","ax",@progbits
>        .globl startup_32
> 
> startup_32:
>-       cld
>-       cli
>+       /* check to see if KEEP_SEGMENTS flag is meaningful */
>+       cmpw $0x207, BP_version(%esi)
>+       jb 1f
>+
>+       /* test KEEP_SEGMENTS flag to see if the bootloader is asking
>+        * us to not reload segments */
>+       testb $(1<<6), BP_loadflags(%esi)
>+       jnz 2f
>+
>+1:     cli
>        movl $(__BOOT_DS),%eax
>        movl %eax,%ds
>        movl %eax,%es

That is, it added loads from %ds:offset(%esi) before the code
that sanitises %ds et al. Commenting out these loads and tests
made the kernel boot again.

Adding debugging code to head_32.S and decompress_kernel(),
I found that startup_32 actually is invoked with a good %ds
(== 0x18 == __BOOT_DS) and a flat 4GB data segment in the
corresponding GDT entry.

Since data accesses work after %ds is (re)loaded with __BOOT_DS,
it's clear that on this machine, the hidden registers behind %ds
are stale on entry to startup_32. After adding a patch to reload
%ds with itself (not __BOOT_DS) at startup_32 the kernel doesn't
crash and reboot any more on this machine.

The machine in question is a ca 1993 vintage Siemens 486 with
a Quadtel S3 / Phoenix BIOS from 1994, booting via grub-0.95-13
from Fedora Core 4.

Signed-off-by: Mikael Pettersson <mikpe@it.uu.se>
---
 arch/x86/boot/compressed/head_32.S |    5 +++++
 1 files changed, 5 insertions(+)

--- linux-2.6.24-rc1-git13/arch/x86/boot/compressed/head_32.S.~1~	2007-11-04 16:34:33.000000000 +0100
+++ linux-2.6.24-rc1-git13/arch/x86/boot/compressed/head_32.S	2007-11-04 16:44:15.000000000 +0100
@@ -33,6 +33,11 @@
 	.globl startup_32
 
 startup_32:
+	/* workaround for BIOSen or boot loaders that don't reload %ds
+	   after changing the GDT (insane but unfortunately true) */
+	movl %ds,%eax
+	movl %eax,%ds
+
 	cld
 	/* test KEEP_SEGMENTS flag to see if the bootloader is asking
 	 * us to not reload segments */

^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: [PATCH] fix i486 boot failure due to stale %ds
@ 2007-11-04 19:38 Mikael Pettersson
  2007-11-04 19:41 ` H. Peter Anvin
  0 siblings, 1 reply; 15+ messages in thread
From: Mikael Pettersson @ 2007-11-04 19:38 UTC (permalink / raw)
  To: hpa, mikpe; +Cc: linux-kernel, mingo, tglx

On Sun, 04 Nov 2007 10:29:34 -0800, H. Peter Anvin wrote:
>Could you send me your /proc/cpuinfo?

Sure. It's a 100Mhz Intel 486 DX4:

processor	: 0
vendor_id	: GenuineIntel
cpu family	: 4
model		: 8
model name	: 486 DX/4
stepping	: 0
cache size	: 0 KB
fdiv_bug	: no
hlt_bug		: no
f00f_bug	: no
coma_bug	: no
fpu		: yes
fpu_exception	: yes
cpuid level	: 1
wp		: yes
flags		: fpu vme
bogomips	: 49.66
clflush size	: 32

>Also, I would be very interested if you could try out this patch:
...
>Urk, -ENOTAWAKEYET.  Try *THIS* patch, please.

First patch didn't build. Second patch builds and boots Ok.

So this means the 486 DX4 has a buggy mov to %cr0?

/Mikael

^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: [PATCH] fix i486 boot failure due to stale %ds
@ 2007-11-04 21:58 Mikael Pettersson
  2007-11-04 22:20 ` H. Peter Anvin
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Mikael Pettersson @ 2007-11-04 21:58 UTC (permalink / raw)
  To: hpa, mikpe; +Cc: linux-kernel, mingo, tglx

On Sun, 04 Nov 2007 11:41:58 -0800, H. Peter Anvin wrote:
> Mikael Pettersson wrote:
> > 
> > First patch didn't build. Second patch builds and boots Ok.
> > 
> > So this means the 486 DX4 has a buggy mov to %cr0?
> > 
> 
> Apparently.

Maybe not. I had a look in Intel's SDM Vol3, and the
section "switching to protected mode" specifies that
a move to %cr0 that sets PE should immediately be
followed by a far jmp or call. They write that "random
failures can occur if other instructions exist between
[the move to %cr0] and [the far jmp/call]". The current
version of pmjump.S does exactly that: it executes
a bunch of moves to segment registers in that window.

(Section 9.9.1 in the Sept. 2005 revision I have in
front of me.)

Similarly, section "serializing instructions" writes
that a move to %cr0 that enables or disables paging
should be followed by a jump. They write that this isn't
required in P4 or P6 family processors, but is required
for compatibility with other ia32 processors. Reading
between the lines, they imply that older ia32 processors
don't treat %cr0 writes as completely serializing.

(Section 7.4 in the Sept. 2005 revision.)

/Mikael

^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: [PATCH] fix i486 boot failure due to stale %ds
@ 2007-11-05  1:18 Mikael Pettersson
  0 siblings, 0 replies; 15+ messages in thread
From: Mikael Pettersson @ 2007-11-05  1:18 UTC (permalink / raw)
  To: hpa, mikpe; +Cc: linux-kernel

On Sun, 04 Nov 2007 15:51:43 -0800, H. Peter Anvin wrote:
> Mikael, can you try this patch (rev 3) on your 486?

It works fine.

/Mikael

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

end of thread, other threads:[~2007-11-05  1:18 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-04 16:44 [PATCH] fix i486 boot failure due to stale %ds Mikael Pettersson
2007-11-04 18:29 ` H. Peter Anvin
2007-11-04 19:00   ` H. Peter Anvin
  -- strict thread matches above, loose matches on Subject: below --
2007-11-04 19:38 Mikael Pettersson
2007-11-04 19:41 ` H. Peter Anvin
2007-11-04 21:58 Mikael Pettersson
2007-11-04 22:20 ` H. Peter Anvin
2007-11-04 23:05 ` Andi Kleen
2007-11-04 23:07 ` Jeremy Fitzhardinge
2007-11-04 23:12   ` H. Peter Anvin
2007-11-04 23:50   ` H. Peter Anvin
2007-11-05  0:15     ` Linus Torvalds
2007-11-05  0:23       ` Linus Torvalds
2007-11-04 23:51   ` H. Peter Anvin
2007-11-05  1:18 Mikael Pettersson

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