Commit ab1eebe7 authored by Ingo Molnar's avatar Ingo Molnar

Merge branch 'x86/asm' into x86/urgent

Merge reason: it's stable so lets push it upstream.
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parents 186a2502 df59e7bf
...@@ -18,16 +18,24 @@ ...@@ -18,16 +18,24 @@
/* Common in X86_32 and X86_64 */ /* Common in X86_32 and X86_64 */
/* kernel/ioport.c */ /* kernel/ioport.c */
asmlinkage long sys_ioperm(unsigned long, unsigned long, int); asmlinkage long sys_ioperm(unsigned long, unsigned long, int);
long sys_iopl(unsigned int, struct pt_regs *);
/* kernel/process.c */ /* kernel/process.c */
int sys_fork(struct pt_regs *); int sys_fork(struct pt_regs *);
int sys_vfork(struct pt_regs *); int sys_vfork(struct pt_regs *);
long sys_execve(char __user *, char __user * __user *,
char __user * __user *, struct pt_regs *);
long sys_clone(unsigned long, unsigned long, void __user *,
void __user *, struct pt_regs *);
/* kernel/ldt.c */ /* kernel/ldt.c */
asmlinkage int sys_modify_ldt(int, void __user *, unsigned long); asmlinkage int sys_modify_ldt(int, void __user *, unsigned long);
/* kernel/signal.c */ /* kernel/signal.c */
long sys_rt_sigreturn(struct pt_regs *); long sys_rt_sigreturn(struct pt_regs *);
long sys_sigaltstack(const stack_t __user *, stack_t __user *,
struct pt_regs *);
/* kernel/tls.c */ /* kernel/tls.c */
asmlinkage int sys_set_thread_area(struct user_desc __user *); asmlinkage int sys_set_thread_area(struct user_desc __user *);
...@@ -35,18 +43,11 @@ asmlinkage int sys_get_thread_area(struct user_desc __user *); ...@@ -35,18 +43,11 @@ asmlinkage int sys_get_thread_area(struct user_desc __user *);
/* X86_32 only */ /* X86_32 only */
#ifdef CONFIG_X86_32 #ifdef CONFIG_X86_32
/* kernel/ioport.c */
long sys_iopl(struct pt_regs *);
/* kernel/process_32.c */
int sys_clone(struct pt_regs *);
int sys_execve(struct pt_regs *);
/* kernel/signal.c */ /* kernel/signal.c */
asmlinkage int sys_sigsuspend(int, int, old_sigset_t); asmlinkage int sys_sigsuspend(int, int, old_sigset_t);
asmlinkage int sys_sigaction(int, const struct old_sigaction __user *, asmlinkage int sys_sigaction(int, const struct old_sigaction __user *,
struct old_sigaction __user *); struct old_sigaction __user *);
int sys_sigaltstack(struct pt_regs *);
unsigned long sys_sigreturn(struct pt_regs *); unsigned long sys_sigreturn(struct pt_regs *);
/* kernel/sys_i386_32.c */ /* kernel/sys_i386_32.c */
...@@ -64,28 +65,15 @@ asmlinkage int sys_uname(struct old_utsname __user *); ...@@ -64,28 +65,15 @@ asmlinkage int sys_uname(struct old_utsname __user *);
asmlinkage int sys_olduname(struct oldold_utsname __user *); asmlinkage int sys_olduname(struct oldold_utsname __user *);
/* kernel/vm86_32.c */ /* kernel/vm86_32.c */
int sys_vm86old(struct pt_regs *); int sys_vm86old(struct vm86_struct __user *, struct pt_regs *);
int sys_vm86(struct pt_regs *); int sys_vm86(unsigned long, unsigned long, struct pt_regs *);
#else /* CONFIG_X86_32 */ #else /* CONFIG_X86_32 */
/* X86_64 only */ /* X86_64 only */
/* kernel/ioport.c */
asmlinkage long sys_iopl(unsigned int, struct pt_regs *);
/* kernel/process_64.c */ /* kernel/process_64.c */
asmlinkage long sys_clone(unsigned long, unsigned long,
void __user *, void __user *,
struct pt_regs *);
asmlinkage long sys_execve(char __user *, char __user * __user *,
char __user * __user *,
struct pt_regs *);
long sys_arch_prctl(int, unsigned long); long sys_arch_prctl(int, unsigned long);
/* kernel/signal.c */
asmlinkage long sys_sigaltstack(const stack_t __user *, stack_t __user *,
struct pt_regs *);
/* kernel/sys_x86_64.c */ /* kernel/sys_x86_64.c */
struct new_utsname; struct new_utsname;
......
...@@ -725,22 +725,61 @@ END(syscall_badsys) ...@@ -725,22 +725,61 @@ END(syscall_badsys)
/* /*
* System calls that need a pt_regs pointer. * System calls that need a pt_regs pointer.
*/ */
#define PTREGSCALL(name) \ #define PTREGSCALL0(name) \
ALIGN; \ ALIGN; \
ptregs_##name: \ ptregs_##name: \
leal 4(%esp),%eax; \ leal 4(%esp),%eax; \
jmp sys_##name; jmp sys_##name;
PTREGSCALL(iopl) #define PTREGSCALL1(name) \
PTREGSCALL(fork) ALIGN; \
PTREGSCALL(clone) ptregs_##name: \
PTREGSCALL(vfork) leal 4(%esp),%edx; \
PTREGSCALL(execve) movl (PT_EBX+4)(%esp),%eax; \
PTREGSCALL(sigaltstack) jmp sys_##name;
PTREGSCALL(sigreturn)
PTREGSCALL(rt_sigreturn) #define PTREGSCALL2(name) \
PTREGSCALL(vm86) ALIGN; \
PTREGSCALL(vm86old) ptregs_##name: \
leal 4(%esp),%ecx; \
movl (PT_ECX+4)(%esp),%edx; \
movl (PT_EBX+4)(%esp),%eax; \
jmp sys_##name;
#define PTREGSCALL3(name) \
ALIGN; \
ptregs_##name: \
leal 4(%esp),%eax; \
pushl %eax; \
movl PT_EDX(%eax),%ecx; \
movl PT_ECX(%eax),%edx; \
movl PT_EBX(%eax),%eax; \
call sys_##name; \
addl $4,%esp; \
ret
PTREGSCALL1(iopl)
PTREGSCALL0(fork)
PTREGSCALL0(vfork)
PTREGSCALL3(execve)
PTREGSCALL2(sigaltstack)
PTREGSCALL0(sigreturn)
PTREGSCALL0(rt_sigreturn)
PTREGSCALL2(vm86)
PTREGSCALL1(vm86old)
/* Clone is an oddball. The 4th arg is in %edi */
ALIGN;
ptregs_clone:
leal 4(%esp),%eax
pushl %eax
pushl PT_EDI(%eax)
movl PT_EDX(%eax),%ecx
movl PT_ECX(%eax),%edx
movl PT_EBX(%eax),%eax
call sys_clone
addl $8,%esp
ret
.macro FIXUP_ESPFIX_STACK .macro FIXUP_ESPFIX_STACK
/* /*
...@@ -1008,12 +1047,8 @@ END(spurious_interrupt_bug) ...@@ -1008,12 +1047,8 @@ END(spurious_interrupt_bug)
ENTRY(kernel_thread_helper) ENTRY(kernel_thread_helper)
pushl $0 # fake return address for unwinder pushl $0 # fake return address for unwinder
CFI_STARTPROC CFI_STARTPROC
movl %edx,%eax movl %edi,%eax
push %edx call *%esi
CFI_ADJUST_CFA_OFFSET 4
call *%ebx
push %eax
CFI_ADJUST_CFA_OFFSET 4
call do_exit call do_exit
ud2 # padding for call trace ud2 # padding for call trace
CFI_ENDPROC CFI_ENDPROC
......
...@@ -1166,63 +1166,20 @@ bad_gs: ...@@ -1166,63 +1166,20 @@ bad_gs:
jmp 2b jmp 2b
.previous .previous
/* ENTRY(kernel_thread_helper)
* Create a kernel thread.
*
* C extern interface:
* extern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
*
* asm input arguments:
* rdi: fn, rsi: arg, rdx: flags
*/
ENTRY(kernel_thread)
CFI_STARTPROC
FAKE_STACK_FRAME $child_rip
SAVE_ALL
# rdi: flags, rsi: usp, rdx: will be &pt_regs
movq %rdx,%rdi
orq kernel_thread_flags(%rip),%rdi
movq $-1, %rsi
movq %rsp, %rdx
xorl %r8d,%r8d
xorl %r9d,%r9d
# clone now
call do_fork
movq %rax,RAX(%rsp)
xorl %edi,%edi
/*
* It isn't worth to check for reschedule here,
* so internally to the x86_64 port you can rely on kernel_thread()
* not to reschedule the child before returning, this avoids the need
* of hacks for example to fork off the per-CPU idle tasks.
* [Hopefully no generic code relies on the reschedule -AK]
*/
RESTORE_ALL
UNFAKE_STACK_FRAME
ret
CFI_ENDPROC
END(kernel_thread)
ENTRY(child_rip)
pushq $0 # fake return address pushq $0 # fake return address
CFI_STARTPROC CFI_STARTPROC
/* /*
* Here we are in the child and the registers are set as they were * Here we are in the child and the registers are set as they were
* at kernel_thread() invocation in the parent. * at kernel_thread() invocation in the parent.
*/ */
movq %rdi, %rax call *%rsi
movq %rsi, %rdi
call *%rax
# exit # exit
mov %eax, %edi mov %eax, %edi
call do_exit call do_exit
ud2 # padding for call trace ud2 # padding for call trace
CFI_ENDPROC CFI_ENDPROC
END(child_rip) END(kernel_thread_helper)
/* /*
* execve(). This function needs to use IRET, not SYSRET, to set up all state properly. * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
......
...@@ -103,9 +103,10 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on) ...@@ -103,9 +103,10 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
* on system-call entry - see also fork() and the signal handling * on system-call entry - see also fork() and the signal handling
* code. * code.
*/ */
static int do_iopl(unsigned int level, struct pt_regs *regs) long sys_iopl(unsigned int level, struct pt_regs *regs)
{ {
unsigned int old = (regs->flags >> 12) & 3; unsigned int old = (regs->flags >> 12) & 3;
struct thread_struct *t = &current->thread;
if (level > 3) if (level > 3)
return -EINVAL; return -EINVAL;
...@@ -115,29 +116,8 @@ static int do_iopl(unsigned int level, struct pt_regs *regs) ...@@ -115,29 +116,8 @@ static int do_iopl(unsigned int level, struct pt_regs *regs)
return -EPERM; return -EPERM;
} }
regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12); regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
return 0;
}
#ifdef CONFIG_X86_32
long sys_iopl(struct pt_regs *regs)
{
unsigned int level = regs->bx;
struct thread_struct *t = &current->thread;
int rc;
rc = do_iopl(level, regs);
if (rc < 0)
goto out;
t->iopl = level << 12; t->iopl = level << 12;
set_iopl_mask(t->iopl); set_iopl_mask(t->iopl);
out:
return rc; return 0;
}
#else
asmlinkage long sys_iopl(unsigned int level, struct pt_regs *regs)
{
return do_iopl(level, regs);
} }
#endif
...@@ -255,6 +255,76 @@ int sys_vfork(struct pt_regs *regs) ...@@ -255,6 +255,76 @@ int sys_vfork(struct pt_regs *regs)
NULL, NULL); NULL, NULL);
} }
long
sys_clone(unsigned long clone_flags, unsigned long newsp,
void __user *parent_tid, void __user *child_tid, struct pt_regs *regs)
{
if (!newsp)
newsp = regs->sp;
return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
}
/*
* This gets run with %si containing the
* function to call, and %di containing
* the "args".
*/
extern void kernel_thread_helper(void);
/*
* Create a kernel thread
*/
int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
{
struct pt_regs regs;
memset(&regs, 0, sizeof(regs));
regs.si = (unsigned long) fn;
regs.di = (unsigned long) arg;
#ifdef CONFIG_X86_32
regs.ds = __USER_DS;
regs.es = __USER_DS;
regs.fs = __KERNEL_PERCPU;
regs.gs = __KERNEL_STACK_CANARY;
#endif
regs.orig_ax = -1;
regs.ip = (unsigned long) kernel_thread_helper;
regs.cs = __KERNEL_CS | get_kernel_rpl();
regs.flags = X86_EFLAGS_IF | 0x2;
/* Ok, create the new process.. */
return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
}
EXPORT_SYMBOL(kernel_thread);
/*
* sys_execve() executes a new program.
*/
long sys_execve(char __user *name, char __user * __user *argv,
char __user * __user *envp, struct pt_regs *regs)
{
long error;
char *filename;
filename = getname(name);
error = PTR_ERR(filename);
if (IS_ERR(filename))
return error;
error = do_execve(filename, argv, envp, regs);
#ifdef CONFIG_X86_32
if (error == 0) {
/* Make sure we don't return using sysenter.. */
set_thread_flag(TIF_IRET);
}
#endif
putname(filename);
return error;
}
/* /*
* Idle related variables and functions * Idle related variables and functions
......
...@@ -180,39 +180,6 @@ void show_regs(struct pt_regs *regs) ...@@ -180,39 +180,6 @@ void show_regs(struct pt_regs *regs)
show_trace(NULL, regs, &regs->sp, regs->bp); show_trace(NULL, regs, &regs->sp, regs->bp);
} }
/*
* This gets run with %bx containing the
* function to call, and %dx containing
* the "args".
*/
extern void kernel_thread_helper(void);
/*
* Create a kernel thread
*/
int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
{
struct pt_regs regs;
memset(&regs, 0, sizeof(regs));
regs.bx = (unsigned long) fn;
regs.dx = (unsigned long) arg;
regs.ds = __USER_DS;
regs.es = __USER_DS;
regs.fs = __KERNEL_PERCPU;
regs.gs = __KERNEL_STACK_CANARY;
regs.orig_ax = -1;
regs.ip = (unsigned long) kernel_thread_helper;
regs.cs = __KERNEL_CS | get_kernel_rpl();
regs.flags = X86_EFLAGS_IF | X86_EFLAGS_SF | X86_EFLAGS_PF | 0x2;
/* Ok, create the new process.. */
return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
}
EXPORT_SYMBOL(kernel_thread);
void release_thread(struct task_struct *dead_task) void release_thread(struct task_struct *dead_task)
{ {
BUG_ON(dead_task->mm); BUG_ON(dead_task->mm);
...@@ -424,46 +391,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p) ...@@ -424,46 +391,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
return prev_p; return prev_p;
} }
int sys_clone(struct pt_regs *regs)
{
unsigned long clone_flags;
unsigned long newsp;
int __user *parent_tidptr, *child_tidptr;
clone_flags = regs->bx;
newsp = regs->cx;
parent_tidptr = (int __user *)regs->dx;
child_tidptr = (int __user *)regs->di;
if (!newsp)
newsp = regs->sp;
return do_fork(clone_flags, newsp, regs, 0, parent_tidptr, child_tidptr);
}
/*
* sys_execve() executes a new program.
*/
int sys_execve(struct pt_regs *regs)
{
int error;
char *filename;
filename = getname((char __user *) regs->bx);
error = PTR_ERR(filename);
if (IS_ERR(filename))
goto out;
error = do_execve(filename,
(char __user * __user *) regs->cx,
(char __user * __user *) regs->dx,
regs);
if (error == 0) {
/* Make sure we don't return using sysenter.. */
set_thread_flag(TIF_IRET);
}
putname(filename);
out:
return error;
}
#define top_esp (THREAD_SIZE - sizeof(unsigned long)) #define top_esp (THREAD_SIZE - sizeof(unsigned long))
#define top_ebp (THREAD_SIZE - 2*sizeof(unsigned long)) #define top_ebp (THREAD_SIZE - 2*sizeof(unsigned long))
......
...@@ -57,8 +57,6 @@ asmlinkage extern void ret_from_fork(void); ...@@ -57,8 +57,6 @@ asmlinkage extern void ret_from_fork(void);
DEFINE_PER_CPU(unsigned long, old_rsp); DEFINE_PER_CPU(unsigned long, old_rsp);
static DEFINE_PER_CPU(unsigned char, is_idle); static DEFINE_PER_CPU(unsigned char, is_idle);
unsigned long kernel_thread_flags = CLONE_VM | CLONE_UNTRACED;
static ATOMIC_NOTIFIER_HEAD(idle_notifier); static ATOMIC_NOTIFIER_HEAD(idle_notifier);
void idle_notifier_register(struct notifier_block *n) void idle_notifier_register(struct notifier_block *n)
...@@ -273,8 +271,9 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, ...@@ -273,8 +271,9 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
*childregs = *regs; *childregs = *regs;
childregs->ax = 0; childregs->ax = 0;
if (user_mode(regs))
childregs->sp = sp; childregs->sp = sp;
if (sp == ~0UL) else
childregs->sp = (unsigned long)childregs; childregs->sp = (unsigned long)childregs;
p->thread.sp = (unsigned long) childregs; p->thread.sp = (unsigned long) childregs;
...@@ -508,25 +507,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p) ...@@ -508,25 +507,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
return prev_p; return prev_p;
} }
/*
* sys_execve() executes a new program.
*/
asmlinkage
long sys_execve(char __user *name, char __user * __user *argv,
char __user * __user *envp, struct pt_regs *regs)
{
long error;
char *filename;
filename = getname(name);
error = PTR_ERR(filename);
if (IS_ERR(filename))
return error;
error = do_execve(filename, argv, envp, regs);
putname(filename);
return error;
}
void set_personality_64bit(void) void set_personality_64bit(void)
{ {
/* inherit personality from parent */ /* inherit personality from parent */
...@@ -541,15 +521,6 @@ void set_personality_64bit(void) ...@@ -541,15 +521,6 @@ void set_personality_64bit(void)
current->personality &= ~READ_IMPLIES_EXEC; current->personality &= ~READ_IMPLIES_EXEC;
} }
asmlinkage long
sys_clone(unsigned long clone_flags, unsigned long newsp,
void __user *parent_tid, void __user *child_tid, struct pt_regs *regs)
{
if (!newsp)
newsp = regs->sp;
return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
}
unsigned long get_wchan(struct task_struct *p) unsigned long get_wchan(struct task_struct *p)
{ {
unsigned long stack; unsigned long stack;
......
...@@ -545,22 +545,12 @@ sys_sigaction(int sig, const struct old_sigaction __user *act, ...@@ -545,22 +545,12 @@ sys_sigaction(int sig, const struct old_sigaction __user *act,
} }
#endif /* CONFIG_X86_32 */ #endif /* CONFIG_X86_32 */
#ifdef CONFIG_X86_32 long
int sys_sigaltstack(struct pt_regs *regs)
{
const stack_t __user *uss = (const stack_t __user *)regs->bx;
stack_t __user *uoss = (stack_t __user *)regs->cx;
return do_sigaltstack(uss, uoss, regs->sp);
}
#else /* !CONFIG_X86_32 */
asmlinkage long
sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
struct pt_regs *regs) struct pt_regs *regs)
{ {
return do_sigaltstack(uss, uoss, regs->sp); return do_sigaltstack(uss, uoss, regs->sp);
} }
#endif /* CONFIG_X86_32 */
/* /*
* Do a signal return; undo the signal stack. * Do a signal return; undo the signal stack.
......
...@@ -197,9 +197,8 @@ static void mark_screen_rdonly(struct mm_struct *mm) ...@@ -197,9 +197,8 @@ static void mark_screen_rdonly(struct mm_struct *mm)
static int do_vm86_irq_handling(int subfunction, int irqnumber); static int do_vm86_irq_handling(int subfunction, int irqnumber);
static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk); static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk);
int sys_vm86old(struct pt_regs *regs) int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
{ {
struct vm86_struct __user *v86 = (struct vm86_struct __user *)regs->bx;
struct kernel_vm86_struct info; /* declare this _on top_, struct kernel_vm86_struct info; /* declare this _on top_,
* this avoids wasting of stack space. * this avoids wasting of stack space.
* This remains on the stack until we * This remains on the stack until we
...@@ -227,7 +226,7 @@ int sys_vm86old(struct pt_regs *regs) ...@@ -227,7 +226,7 @@ int sys_vm86old(struct pt_regs *regs)
} }
int sys_vm86(struct pt_regs *regs) int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
{ {
struct kernel_vm86_struct info; /* declare this _on top_, struct kernel_vm86_struct info; /* declare this _on top_,
* this avoids wasting of stack space. * this avoids wasting of stack space.
...@@ -239,12 +238,12 @@ int sys_vm86(struct pt_regs *regs) ...@@ -239,12 +238,12 @@ int sys_vm86(struct pt_regs *regs)
struct vm86plus_struct __user *v86; struct vm86plus_struct __user *v86;
tsk = current; tsk = current;
switch (regs->bx) { switch (cmd) {
case VM86_REQUEST_IRQ: case VM86_REQUEST_IRQ:
case VM86_FREE_IRQ: case VM86_FREE_IRQ:
case VM86_GET_IRQ_BITS: case VM86_GET_IRQ_BITS:
case VM86_GET_AND_RESET_IRQ: case VM86_GET_AND_RESET_IRQ:
ret = do_vm86_irq_handling(regs->bx, (int)regs->cx); ret = do_vm86_irq_handling(cmd, (int)arg);
goto out; goto out;
case VM86_PLUS_INSTALL_CHECK: case VM86_PLUS_INSTALL_CHECK:
/* /*
...@@ -261,7 +260,7 @@ int sys_vm86(struct pt_regs *regs) ...@@ -261,7 +260,7 @@ int sys_vm86(struct pt_regs *regs)
ret = -EPERM; ret = -EPERM;
if (tsk->thread.saved_sp0) if (tsk->thread.saved_sp0)
goto out; goto out;
v86 = (struct vm86plus_struct __user *)regs->cx; v86 = (struct vm86plus_struct __user *)arg;
tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs, tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
offsetof(struct kernel_vm86_struct, regs32) - offsetof(struct kernel_vm86_struct, regs32) -
sizeof(info.regs)); sizeof(info.regs));
......
...@@ -17,8 +17,6 @@ ...@@ -17,8 +17,6 @@
EXPORT_SYMBOL(mcount); EXPORT_SYMBOL(mcount);
#endif #endif
EXPORT_SYMBOL(kernel_thread);
EXPORT_SYMBOL(__get_user_1); EXPORT_SYMBOL(__get_user_1);
EXPORT_SYMBOL(__get_user_2); EXPORT_SYMBOL(__get_user_2);
EXPORT_SYMBOL(__get_user_4); EXPORT_SYMBOL(__get_user_4);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment