[PATCH 4/4] x86, 64-bit: Use user_mode() to determine new stack pointer in copy_thread()

From: Brian Gerst
Date: Fri Nov 13 2009 - 14:55:22 EST


Use user_mode() instead of a magic value for sp to determine when returning
to kernel mode. This simplifies kernel_thread().

Signed-off-by: Brian Gerst <brgerst@xxxxxxxxx>
---
arch/x86/kernel/process.c | 6 +-----
arch/x86/kernel/process_64.c | 5 +++--
2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index 71a22c9..4ebe3e4 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -255,7 +255,6 @@ extern void kernel_thread_helper(void);
int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
{
struct pt_regs regs;
- unsigned long newsp;

memset(&regs, 0, sizeof(regs));

@@ -267,9 +266,6 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
regs.es = __USER_DS;
regs.fs = __KERNEL_PERCPU;
regs.gs = __KERNEL_STACK_CANARY;
- newsp = 0;
-#else
- newsp = ~0UL;
#endif

regs.orig_ax = -1;
@@ -278,7 +274,7 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
regs.flags = X86_EFLAGS_IF | 2;

/* Ok, create the new process.. */
- return do_fork(flags | CLONE_VM | CLONE_UNTRACED, newsp, &regs, 0, NULL, NULL);
+ return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
}
EXPORT_SYMBOL(kernel_thread);

diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index 8151a82..a9be0d5 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -283,8 +283,9 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
*childregs = *regs;

childregs->ax = 0;
- childregs->sp = sp;
- if (sp == ~0UL)
+ if (user_mode(regs))
+ childregs->sp = sp;
+ else
childregs->sp = (unsigned long)childregs;

p->thread.sp = (unsigned long) childregs;
--
1.6.2.5

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