Skip to contentSkip to conversation

%fs/%gs cleanup in mmu_context.h

PATCH In review Chris Wright 2 participants 3 messages Aug 12, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 %fs/%gs cleanup in mmu_context.h

Small change to remove difference between Xen and mainline deactivate_mm. While there, cleanup prepare_arch_switch as well. This generates identical code.

---

linux-2.6-xen-sparse/include/asm-xen/asm-i386/mmu_context.h +5 -5
diff -r ba46bd7f5cdf linux-2.6-xen-sparse/include/asm-xen/asm-i386/mmu_context.h
@@ -34,10 +34,10 @@
 	 * are always kernel segments while inside the kernel. Must
 	 * happen before reload of cr3/ldt (i.e., not in __switch_to).
 	 */
-	__asm__ __volatile__ ( "mov %%fs,%0 ; mov %%gs,%1"
-		: "=m" (*(int *)&current->thread.fs),
-		  "=m" (*(int *)&current->thread.gs));
-	__asm__ __volatile__ ( "mov %0,%%fs ; mov %0,%%gs"
+	asm volatile ( "movl %%fs,%0 ; movl %%gs,%1"
+		: "=m" (current->thread.fs),
+		  "=m" (current->thread.gs));
+	asm volatile ( "movl %0,%%fs ; movl %0,%%gs"
 		: : "r" (0) );
 }
 
@@ -100,7 +100,7 @@
 }
 
 #define deactivate_mm(tsk, mm) \
-	asm("mov %0,%%fs ; mov %0,%%gs": :"r" (0))
+	asm("movl %0,%%fs ; movl %0,%%gs": :"r" (0))
 
 #define activate_mm(prev, next) \
 	switch_mm((prev),(next),NULL)
#1 lore raw
Quoted 9 lines · Chris Wright

diff -r ba46bd7f5cdf linux-2.6-xen-sparse/include/asm-xen/asm-i386/mmu_context.h

linux-2.6-xen-sparse/include/asm-xen/asm-i386/mmu_context.h +0 -1
@@ -34,10 +34,10 @@
 	 * are always kernel segments while inside the kernel. Must
 	 * happen before reload of cr3/ldt (i.e., not in __switch_to).
 	 */
-	__asm__ __volatile__ ( "mov %%fs,%0 ; mov %%gs,%1"

linux-2.6-xen-sparse/include/asm-xen/asm-i386/mmu_context.h line 43

Quoted 10 lines
linux-2.6-xen-sparse/include/asm-xen/asm-i386/mmu_context.h +4 -3
-		: "=m" (*(int *)&current->thread.fs),
-		  "=m" (*(int *)&current->thread.gs));
-	__asm__ __volatile__ ( "mov %0,%%fs ; mov %0,%%gs"
+	asm volatile ( "movl %%fs,%0 ; movl %%gs,%1"
+		: "=m" (current->thread.fs),
+		  "=m" (current->thread.gs));
+	asm volatile ( "movl %0,%%fs ; movl %0,%%gs"
 		: : "r" (0) );
 }
 

The first inline asm is wrong.
latest binutils no longer accept instructions for moving between a segment register and a 32bit memory location. you should keep the "mov" instead of "movl".

see:
http://sourceware.org/ml/binutils/2005-03/msg00873.html

linux-2.6-xen-sparse/include/asm-xen/asm-i386/mmu_context.h line 103

Quoted 6 lines
linux-2.6-xen-sparse/include/asm-xen/asm-i386/mmu_context.h +1 -1
@@ -100,7 +100,7 @@
 }
 
 #define deactivate_mm(tsk, mm) \
-	asm("mov %0,%%fs ; mov %0,%%gs": :"r" (0))
+	asm("movl %0,%%fs ; movl %0,%%gs": :"r" (0))

This one clearing the segment register is fine.

Signature · 1 line
Vincent Hanquez
#2 lore raw
Quoted 17 lines · * Vincent Hanquez ([email protected]) wrote:
Quoted 16 lines · Chris Wright

diff -r ba46bd7f5cdf linux-2.6-xen-sparse/include/asm-xen/asm-i386/mmu_context.h

linux-2.6-xen-sparse/include/asm-xen/asm-i386/mmu_context.h +4 -4
@@ -34,10 +34,10 @@
 	 * are always kernel segments while inside the kernel. Must
 	 * happen before reload of cr3/ldt (i.e., not in __switch_to).
 	 */
-	__asm__ __volatile__ ( "mov %%fs,%0 ; mov %%gs,%1"
-		: "=m" (*(int *)&current->thread.fs),
-		  "=m" (*(int *)&current->thread.gs));
-	__asm__ __volatile__ ( "mov %0,%%fs ; mov %0,%%gs"
+	asm volatile ( "movl %%fs,%0 ; movl %%gs,%1"
+		: "=m" (current->thread.fs),
+		  "=m" (current->thread.gs));
+	asm volatile ( "movl %0,%%fs ; movl %0,%%gs"
Quoted 8 lines

linux-2.6-xen-sparse/include/asm-xen/asm-i386/mmu_context.h line 43

Quoted 3 lines
linux-2.6-xen-sparse/include/asm-xen/asm-i386/mmu_context.h +0 -0
 		: : "r" (0) );
 }
 

The first inline asm is wrong.
latest binutils no longer accept instructions for moving between a segment register and a 32bit memory location. you should keep the "mov" instead of "movl".

Thanks Vincent (I had forgotten about that thread, ISTR Linus agruing vehemently against the change). Heh, the irony, objdump is showing the assembler generating movl in both cases. I have no preference, I'll resubmit.

thanks,
-chris