[PATCH] Remove unnecessary #GP after flush_thread()

From: Arun Sharma
Date: Wed Jan 05 2005 - 18:28:33 EST



During execve(), we seem to have a window between flush_thread() and start_thread() where %gs = 0x33, but cpu_gdt_table[cpu][6] == 0. This causes an unnecessary #GP fault on __switch_to() if there is a context switch during the window. But most people are not noticing it because of the fixup in loadsegment().

Specifically, this BUG() was triggered during normal execution.

--- arch/i386/kernel/process.c- 2005-01-05 15:13:51.450321632 -0800
+++ arch/i386/kernel/process.c 2005-01-05 15:13:55.129762272 -0800
@@ -764,6 +764,12 @@
* Restore %fs and %gs if needed.
*/
if (unlikely(prev->fs | prev->gs | next->fs | next->gs)) {
+#if 1
+ if ((next->gs == 0x33)
+ && (cpu_gdt_table[cpu][6].a == 0)
+ && (cpu_gdt_table[cpu][6].b == 0))
+ BUG();
+#endif
loadsegment(fs, next->fs);
loadsegment(gs, next->gs);


This patch sets %gs = 0 _before_ the thread.tls_array is zeroed.

Signed-off-by: Arun Sharma <arun.sharma@xxxxxxxxx>

--- linux-2.6.10/arch/i386/kernel/process.c- 2005-01-05 15:15:25.469541136 -0800
+++ linux-2.6.10/arch/i386/kernel/process.c 2005-01-05 15:15:26.939317696 -0800
@@ -329,6 +329,7 @@
{
struct task_struct *tsk = current;

+ __asm__("movl %0,%%gs": :"r" (0));
memset(tsk->thread.debugreg, 0, sizeof(unsigned long)*8);
memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
/*