Skip to contentSkip to conversation

x86-64: make compat_start_thread() match start_thread()

RFC In review H. Peter Anvin 2 participants 2 messages Oct 9, 2009

Subsystems (2)
lore
Share & tools
lore

H. Peter Anvin

author reviewer
#0 lore raw

RFC 1/1 x86-64: make compat_start_thread() match start_thread()

[This is an RFC post; I intend to commit this tomorrow but I would appreciate anyone looking over it.]

Quoted 1 line

From c843d5b6bd5923b91359e4806f5fca905774b41f Mon Sep 17 00:00:00 2001

From: H. Peter Anvin <[email protected]>
Date: Thu, 8 Oct 2009 18:02:54 -0700
Subject: [PATCH] x86-64: make compat_start_thread() match start_thread()

For no real good reason, compat_start_thread() was embedded inline in <asm/elf.h> whereas the native start_thread() lives in process_*.c. Move compat_start_thread() to process_64.c, remove gratuitious differences, and fix a few items which mostly look like bit rot.

In particular, compat_start_thread() didn't do free_thread_xstate(), which means it was hanging on to the xstate store area even when it was not needed. It was also not setting old_rsp, but it looks like that generally shouldn't matter for a 32-bit process.

---
 arch/x86/include/asm/elf.h   |   19 +------------------
 arch/x86/kernel/process_64.c |   23 ++++++++++++++++++++++-
 2 files changed, 23 insertions(+), 19 deletions(-)
arch/x86/include/asm/elf.h +1 -18
index 456a304..5a5d541 100644
@@ -157,19 +157,6 @@ do {						\
 
 #define compat_elf_check_arch(x)	elf_check_arch_ia32(x)
 
-static inline void start_ia32_thread(struct pt_regs *regs, u32 ip, u32 sp)
-{
-	loadsegment(fs, 0);
-	loadsegment(ds, __USER32_DS);
-	loadsegment(es, __USER32_DS);
-	load_gs_index(0);
-	regs->ip = ip;
-	regs->sp = sp;
-	regs->flags = X86_EFLAGS_IF;
-	regs->cs = __USER32_CS;
-	regs->ss = __USER32_DS;
-}
-
 static inline void elf_common_init(struct thread_struct *t,
 				   struct pt_regs *regs, const u16 ds)
 {
@@ -191,11 +178,7 @@ do {							\
 #define	COMPAT_ELF_PLAT_INIT(regs, load_addr)		\
 	elf_common_init(&current->thread, regs, __USER_DS)
 
-#define	compat_start_thread(regs, ip, sp)		\
-do {							\
-	start_ia32_thread(regs, ip, sp);		\
-	set_fs(USER_DS);				\
-} while (0)
+void compat_start_thread(struct pt_regs *regs, u32 new_ip, u32 new_sp);
 
 #define COMPAT_SET_PERSONALITY(ex)			\
 do {							\
arch/x86/kernel/process_64.c +22 -1
index ad535b6..ec223a8 100644
@@ -356,7 +356,7 @@ start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp)
 	percpu_write(old_rsp, new_sp);
 	regs->cs		= __USER_CS;
 	regs->ss		= __USER_DS;
-	regs->flags		= 0x200;
+	regs->flags		= X86_EFLAGS_IF;
 	set_fs(USER_DS);
 	/*
 	 * Free the old FP and other extended state
@@ -365,6 +365,27 @@ start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp)
 }
 EXPORT_SYMBOL_GPL(start_thread);
 
+#ifdef CONFIG_IA32_EMULATION
+void compat_start_thread(struct pt_regs *regs, u32 new_ip, u32 new_sp)
+{
+	loadsegment(fs, 0);
+	loadsegment(ds, __USER32_DS);
+	loadsegment(es, __USER32_DS);
+	load_gs_index(0);
+	regs->ip		= new_ip;
+	regs->sp		= new_sp;
+	percpu_write(old_rsp, new_sp);
+	regs->cs		= __USER32_CS;
+	regs->ss		= __USER32_DS;
+	regs->flags		= X86_EFLAGS_IF;
+	set_fs(USER_DS);
+	/*
+	 * Free the old FP and other extended state
+	 */
+	free_thread_xstate(current);
+}
+#endif
+
 /*
  *	switch_to(x,y) should switch tasks from x to y.
  *
Signature · 1 line
1.6.2.5
#1 lore raw
Quoted 32 lines · H. Peter Anvin
arch/x86/kernel/process_64.c +1 -1
index ad535b6..ec223a8 100644
@@ -356,7 +356,7 @@ start_thread(struct pt_regs *regs, unsigned long
 new_ip, unsigned long new_sp)
        percpu_write(old_rsp, new_sp);
        regs->cs                = __USER_CS;
        regs->ss                = __USER_DS;
-       regs->flags             = 0x200;
+       regs->flags             = X86_EFLAGS_IF;
        set_fs(USER_DS);
        /*

* Free the old FP and other extended state

arch/x86/kernel/process_64.c +11 -0
@@ -365,6 +365,27 @@ start_thread(struct pt_regs *regs, unsigned long
 new_ip, unsigned long new_sp)
 }
 EXPORT_SYMBOL_GPL(start_thread);
 
+#ifdef CONFIG_IA32_EMULATION
+void compat_start_thread(struct pt_regs *regs, u32 new_ip, u32
 new_sp)
+{
+       loadsegment(fs, 0);
+       loadsegment(ds, __USER32_DS);
+       loadsegment(es, __USER32_DS);
+       load_gs_index(0);
+       regs->ip                = new_ip;
+       regs->sp                = new_sp;
+       percpu_write(old_rsp, new_sp);
+       regs->cs                = __USER32_CS;

arch/x86/kernel/process_64.c start_thread(struct pt_regs *regs, unsigned long · line 390

Quoted 10 lines
arch/x86/kernel/process_64.c +10 -0
+       regs->ss                = __USER32_DS;
+       regs->flags             = X86_EFLAGS_IF;
+       set_fs(USER_DS);
+       /*
+        * Free the old FP and other extended state
+        */
+       free_thread_xstate(current);
+}
+#endif
+

Peter, While you are it, we should just merge most of the meat into one common function handling both modes. That will be more cleaner.

thanks,
suresh