Skip to contentSkip to conversation

Setup code crashes my old 486 box

PATCH Joerg Roedel 4 participants 8 messages Aug 12, 2008 – Aug 13, 2008 x86

lore
Share & tools
lore
#0 lore raw

Hello,

yesterday I tried to reactivate my old 486 box and wanted to install a current Linux with latest kernel on it. But it turned out that the latest kernel does not boot because the machine crashes early in the setup code.
After some debugging it turned out that the problem is the query_ist() function. If this interrupt with that function is called the machine simply locks up. It looks like a BIOS bug. Looking for a workaround for this problem I wrote the attached patch. It checks for the CPUID instruction and if it is not implemented it does not call the speedstep BIOS function. As far as I know speedstep should be available since some Pentium earliest.
Is this an acceptable workaround or is there a better one for this?

Regards,

Joerg

Here is the patch which makes the kernel boot on my old box again:

From: Joerg Roedel <[email protected]>

This patch adds a check to the query_ist function to check for the cpuid instruction before calling the speedstep init code. This works around a buggy 486 BIOS which crashes the machine on the speedstep BIOS initcall.

---
 arch/x86/boot/main.c |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 47 insertions(+), 0 deletions(-)
arch/x86/boot/main.c +47 -0
index 2296164..3bf5fa0 100644
@@ -68,11 +68,58 @@ static void keyboard_set_repeat(void)
 		     : : "ecx", "edx", "esi", "edi");
 }
 
+static unsigned read_flags(void)
+{
+	unsigned eax;
+
+	asm volatile("pushf\n\t"
+		     "popl %%eax\n\t"
+		     : "=a" (eax));
+
+	return eax;
+}
+
+static inline void write_flags(unsigned f)
+{
+	asm volatile("pushl %0\n\t"
+		     "popf\n\t"
+		     : : "r" (f));
+}
+
+static int has_cpuid(void)
+{
+	unsigned f = read_flags();
+	unsigned id_mask = (1 << 21);
+
+	write_flags(f | id_mask);
+	f = read_flags() & id_mask;
+	if (!f)
+		return 0;
+	f = read_flags() & ~id_mask;
+	write_flags(f);
+	f = read_flags() & id_mask;
+	if (f)
+		return 0;
+
+	return 1;
+}
+
+static int no_ist_check(void)
+{
+	if (!has_cpuid())
+		return 1;
+
+	return 0;
+}
+
 /*
  * Get Intel SpeedStep (IST) information.
  */
 static void query_ist(void)
 {
+	if (no_ist_check())
+		return;
+
 	asm("int $0x15"
 	    : "=a" (boot_params.ist_info.signature),
 	      "=b" (boot_params.ist_info.command),
Signature · 1 line
1.5.4.3
#1 lore raw
Quoted 15 lines · Joerg Roedel

Hello,

yesterday I tried to reactivate my old 486 box and wanted to install a current Linux with latest kernel on it. But it turned out that the latest kernel does not boot because the machine crashes early in the setup code.
After some debugging it turned out that the problem is the query_ist() function. If this interrupt with that function is called the machine simply locks up. It looks like a BIOS bug. Looking for a workaround for this problem I wrote the attached patch. It checks for the CPUID instruction and if it is not implemented it does not call the speedstep BIOS function. As far as I know speedstep should be available since some Pentium earliest.
Is this an acceptable workaround or is there a better one for this?

Quoted 3 lines

Regards,

Joerg

Right in concept, but I dislike the implementation (duplication of the CPU detect code we already have). Could you try this patch and see if it works for you?

-hpa

arch/x86/boot/boot.h +6 -0
index a34b998..9ce8d29 100644
@@ -242,6 +242,12 @@ int cmdline_find_option(const char *option, char *buffer, int bufsize);
 int cmdline_find_option_bool(const char *option);
 
 /* cpu.c, cpucheck.c */
+struct cpu_features {
+	int level;		/* Family, or 64 for x86-64 */
+	int model;
+	u32 flags[NCAPINTS];
+};
+extern struct cpu_features cpu;
 int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr);
 int validate_cpu(void);
 
arch/x86/boot/cpucheck.c +1 -7
index 7804389..c1ce030 100644
@@ -30,13 +30,7 @@
 #include <asm/required-features.h>
 #include <asm/msr-index.h>
 
-struct cpu_features {
-	int level;		/* Family, or 64 for x86-64 */
-	int model;
-	u32 flags[NCAPINTS];
-};
-
-static struct cpu_features cpu;
+struct cpu_features cpu;
 static u32 cpu_vendor[3];
 static u32 err_flags[NCAPINTS];
 
arch/x86/boot/main.c +4 -0
index 2296164..9b04773 100644
@@ -73,6 +73,10 @@ static void keyboard_set_repeat(void)
  */
 static void query_ist(void)
 {
+	/* Some 486 BIOSes apparently crash on this call */
+	if (cpu.level < 5)
+		return;
+
 	asm("int $0x15"
 	    : "=a" (boot_params.ist_info.signature),
 	      "=b" (boot_params.ist_info.command),
#2 lore raw
Quoted 3 lines

Right in concept, but I dislike the implementation (duplication of the CPU detect code we already have). Could you try this patch and see if it works for you?

I was under the impression that spudstop came in with the Pentium II so presumably < 6 would be even safer ?

Alan

#3 lore raw
Quoted 4 lines · Alan Cox
Quoted 1 line

Right in concept, but I dislike the implementation (duplication of the CPU detect code we already have). Could you try this patch and see if it works for you?

I was under the impression that spudstop came in with the Pentium II so presumably < 6 would be even safer ?

I think you're right about that.

-hpa

#4 lore raw
In reply to H. Peter Anvin
Quoted 3 lines · H. Peter Anvin

Right in concept, but I dislike the implementation (duplication of the CPU detect code we already have). Could you try this patch and see if it works for you?

Cool, with a small modification to fix a build error with it the resulting kernel boots my machine. Thanks.
Would be cool to have this patch one merged soon :-) Attached is your patch with my little build fix. It redefines a values already defines in cpufeatures.h but I can't include that file in the boot code so I simply redeclared it. Maybe there is a cleaner solution for this.

Joerg

arch/x86/boot/boot.h +8 -0
index a34b998..9d4b4b4 100644
@@ -25,6 +25,8 @@
 #include <asm/boot.h>
 #include <asm/setup.h>
 
+#define NCAPINTS   8
+
 /* Useful macros */
 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
 
@@ -242,6 +244,12 @@ int cmdline_find_option(const char *option, char *buffer, int bufsize);
 int cmdline_find_option_bool(const char *option);
 
 /* cpu.c, cpucheck.c */
+struct cpu_features {
+	int level;		/* Family, or 64 for x86-64 */
+	int model;
+	u32 flags[NCAPINTS];
+};
+extern struct cpu_features cpu;
 int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr);
 int validate_cpu(void);
 
arch/x86/boot/cpucheck.c +1 -7
index 7804389..c1ce030 100644
@@ -30,13 +30,7 @@
 #include <asm/required-features.h>
 #include <asm/msr-index.h>
 
-struct cpu_features {
-	int level;		/* Family, or 64 for x86-64 */
-	int model;
-	u32 flags[NCAPINTS];
-};
-
-static struct cpu_features cpu;
+struct cpu_features cpu;
 static u32 cpu_vendor[3];
 static u32 err_flags[NCAPINTS];
 
arch/x86/boot/main.c +4 -0
index 2296164..01aa64b 100644
@@ -73,6 +73,10 @@ static void keyboard_set_repeat(void)
  */
 static void query_ist(void)
 {
+	/* Some 486 BIOSes apparently crash on this call */
+	if (cpu.level < 6)
+		return;
+
 	asm("int $0x15"
 	    : "=a" (boot_params.ist_info.signature),
 	      "=b" (boot_params.ist_info.command),
#5 lore raw
Quoted 5 lines · Joerg Roedel
Quoted 3 lines · H. Peter Anvin

Right in concept, but I dislike the implementation (duplication of the CPU detect code we already have). Could you try this patch and see if it works for you?

Quoted 7 lines

Cool, with a small modification to fix a build error with it the resulting kernel boots my machine. Thanks.
Would be cool to have this patch one merged soon :-) Attached is your patch with my little build fix. It redefines a values already defines in cpufeatures.h but I can't include that file in the boot code so I simply redeclared it. Maybe there is a cleaner solution for this.

thanks, i've commited the fix below to tip/x86/urgent - it should show up in v2.6.27-rc4 and it might even be backportable to -stable. I've added your Signed-off-by - is that ok with you?

Ingo

------------->

Quoted 1 line

From 7b27718bdb1b70166383dec91391df5534d449ee Mon Sep 17 00:00:00 2001

From: Joerg Roedel <[email protected]>
Date: Wed, 13 Aug 2008 10:07:05 +0200
Subject: [PATCH] x86: fix setup code crashes on my old 486 box

yesterday I tried to reactivate my old 486 box and wanted to install a current Linux with latest kernel on it. But it turned out that the latest kernel does not boot because the machine crashes early in the setup code.

After some debugging it turned out that the problem is the query_ist() function. If this interrupt with that function is called the machine simply locks up. It looks like a BIOS bug. Looking for a workaround for this problem I wrote the attached patch. It checks for the CPUID instruction and if it is not implemented it does not call the speedstep BIOS function. As far as I know speedstep should be available since some Pentium earliest.

Alan Cox observed that it's available since the Pentium II, so cpuid levels 4 and 5 can be excluded altogether.

H. Peter Anvin cleaned up the code some more:

Quoted 3 lines

Right in concept, but I dislike the implementation (duplication of the CPU detect code we already have). Could you try this patch and see if it works for you?

which, with a small modification to fix a build error with it the resulting kernel boots on my machine.

---
 arch/x86/boot/boot.h     |    8 ++++++++
 arch/x86/boot/cpucheck.c |    8 +-------
 arch/x86/boot/main.c     |    4 ++++
 3 files changed, 13 insertions(+), 7 deletions(-)
arch/x86/boot/boot.h +8 -0
index a34b998..9d4b4b4 100644
@@ -25,6 +25,8 @@
 #include <asm/boot.h>
 #include <asm/setup.h>
 
+#define NCAPINTS   8
+
 /* Useful macros */
 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
 
@@ -242,6 +244,12 @@ int cmdline_find_option(const char *option, char *buffer, int bufsize);
 int cmdline_find_option_bool(const char *option);
 
 /* cpu.c, cpucheck.c */
+struct cpu_features {
+	int level;		/* Family, or 64 for x86-64 */
+	int model;
+	u32 flags[NCAPINTS];
+};
+extern struct cpu_features cpu;
 int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr);
 int validate_cpu(void);
 
arch/x86/boot/cpucheck.c +1 -7
index 7804389..c1ce030 100644
@@ -30,13 +30,7 @@
 #include <asm/required-features.h>
 #include <asm/msr-index.h>
 
-struct cpu_features {
-	int level;		/* Family, or 64 for x86-64 */
-	int model;
-	u32 flags[NCAPINTS];
-};
-
-static struct cpu_features cpu;
+struct cpu_features cpu;
 static u32 cpu_vendor[3];
 static u32 err_flags[NCAPINTS];
 
arch/x86/boot/main.c +4 -0
index 2296164..01aa64b 100644
@@ -73,6 +73,10 @@ static void keyboard_set_repeat(void)
  */
 static void query_ist(void)
 {
+	/* Some 486 BIOSes apparently crash on this call */
+	if (cpu.level < 6)
+		return;
+
 	asm("int $0x15"
 	    : "=a" (boot_params.ist_info.signature),
 	      "=b" (boot_params.ist_info.command),
#6 lore raw
Quoted 16 lines · Ingo Molnar
Quoted 5 lines · Joerg Roedel
Quoted 3 lines · H. Peter Anvin

Right in concept, but I dislike the implementation (duplication of the CPU detect code we already have). Could you try this patch and see if it works for you?

Quoted 7 lines

Cool, with a small modification to fix a build error with it the resulting kernel boots my machine. Thanks.
Would be cool to have this patch one merged soon :-) Attached is your patch with my little build fix. It redefines a values already defines in cpufeatures.h but I can't include that file in the boot code so I simply redeclared it. Maybe there is a cleaner solution for this.

Quoted 3 lines

thanks, i've commited the fix below to tip/x86/urgent - it should show up in v2.6.27-rc4 and it might even be backportable to -stable. I've added your Signed-off-by - is that ok with you?

Ok, cool. Thats fine for me. Thanks.

Joerg

#7 lore raw
In reply to Joerg Roedel
Quoted 11 lines · Joerg Roedel
Quoted 1 line · H. Peter Anvin

Right in concept, but I dislike the implementation (duplication of the CPU detect code we already have). Could you try this patch and see if it works for you?

Cool, with a small modification to fix a build error with it the resulting kernel boots my machine. Thanks.
Would be cool to have this patch one merged soon :-) Attached is your patch with my little build fix. It redefines a values already defines in cpufeatures.h but I can't include that file in the boot code so I simply redeclared it. Maybe there is a cleaner solution for this.

There is... let me cook it up and add Alan's correction.

-hpa