[patch] [sched] x86 idle thread should clear %fs, %gs

Ingo Molnar (mingo@elte.hu)
Sun, 27 Jan 2002 18:37:58 +0100 (CET)


the idle thread (on SMP, all idle threads) should clear the %fs and %gs
register, we forgot to clear these registers after the boot process. This
is especially important in kernels with the previous %fs/%gs patch
applied. (The patch below is against 2.5.3-pre3.)

i've checked and it apperas that the 0.01 Linux kernel source code has the
same problem, in boot/head.s the idle task loads the 0x10 selector, and
INIT_TASK's init TSS uses the 0x17 selector for %gs and never clears it.
:-)

while it's not an issue from the correctness point of view in the 0.01
kernel either, the TSS switching microcode probably exeutes slightly
faster if %gs is 0 for both tasks.

so it appears that this lowlevel x86 performance bug(?) is more than 11
years old! :-)

Ingo

--- linux/arch/i386/kernel/setup.c.orig Sun Jan 27 15:14:43 2002
+++ linux/arch/i386/kernel/setup.c Sun Jan 27 16:01:34 2002
@@ -2803,9 +2803,10 @@
load_TR(nr);
load_LDT(&init_mm);

- /*
- * Clear all 6 debug registers:
- */
+ /* Clear %fs and %gs. */
+ asm volatile ("xorl %eax, %eax; movl %eax, %fs; movl %eax, %gs");
+
+ /* Clear all 6 debug registers: */

#define CD(register) __asm__("movl %0,%%db" #register ::"r"(0) );

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/