From 733deca197143857f938b41d671cd7ce9c53c4bc Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 20 Oct 2012 13:13:11 -0400 Subject: Drop struct pt_regs * argument in compat_sys_execve() Signed-off-by: Al Viro --- arch/tile/include/asm/compat.h | 6 ------ arch/tile/include/asm/processor.h | 3 +++ arch/tile/kernel/compat.c | 1 - arch/tile/kernel/intvec_64.S | 1 - arch/tile/kernel/process.c | 6 +++--- 5 files changed, 6 insertions(+), 11 deletions(-) (limited to 'arch/tile') diff --git a/arch/tile/include/asm/compat.h b/arch/tile/include/asm/compat.h index 3063e6fc8da..3bcf1b94b56 100644 --- a/arch/tile/include/asm/compat.h +++ b/arch/tile/include/asm/compat.h @@ -275,9 +275,6 @@ extern int compat_setup_rt_frame(int sig, struct k_sigaction *ka, struct compat_sigaction; struct compat_siginfo; struct compat_sigaltstack; -long compat_sys_execve(const char __user *path, - compat_uptr_t __user *argv, - compat_uptr_t __user *envp, struct pt_regs *); long compat_sys_rt_sigaction(int sig, struct compat_sigaction __user *act, struct compat_sigaction __user *oact, size_t sigsetsize); @@ -304,9 +301,6 @@ long compat_sys_sched_rr_get_interval(compat_pid_t pid, struct compat_timespec __user *interval); /* These are the intvec_64.S trampolines. */ -long _compat_sys_execve(const char __user *path, - const compat_uptr_t __user *argv, - const compat_uptr_t __user *envp); long _compat_sys_sigaltstack(const struct compat_sigaltstack __user *uss_ptr, struct compat_sigaltstack __user *uoss_ptr); long _compat_sys_rt_sigreturn(void); diff --git a/arch/tile/include/asm/processor.h b/arch/tile/include/asm/processor.h index 8c4dd9ff91e..9a83e531e84 100644 --- a/arch/tile/include/asm/processor.h +++ b/arch/tile/include/asm/processor.h @@ -239,6 +239,9 @@ unsigned long get_wchan(struct task_struct *p); #define KSTK_TOP(task) (task_ksp0(task) - STACK_TOP_DELTA) #define task_pt_regs(task) \ ((struct pt_regs *)(task_ksp0(task) - KSTK_PTREGS_GAP) - 1) +#define current_pt_regs() \ + ((struct pt_regs *)((stack_pointer | (THREAD_SIZE - 1)) - \ + (KSTK_PTREGS_GAP - 1)) - 1) #define task_sp(task) (task_pt_regs(task)->sp) #define task_pc(task) (task_pt_regs(task)->pc) /* Aliases for pc and sp (used in fs/proc/array.c) */ diff --git a/arch/tile/kernel/compat.c b/arch/tile/kernel/compat.c index d67459b9ac2..a8e5a847037 100644 --- a/arch/tile/kernel/compat.c +++ b/arch/tile/kernel/compat.c @@ -103,7 +103,6 @@ long compat_sys_sched_rr_get_interval(compat_pid_t pid, #define compat_sys_readahead sys32_readahead /* Call the trampolines to manage pt_regs where necessary. */ -#define compat_sys_execve _compat_sys_execve #define compat_sys_sigaltstack _compat_sys_sigaltstack #define compat_sys_rt_sigreturn _compat_sys_rt_sigreturn #define sys_clone _sys_clone diff --git a/arch/tile/kernel/intvec_64.S b/arch/tile/kernel/intvec_64.S index 7c06d597ffd..73f6c0a648c 100644 --- a/arch/tile/kernel/intvec_64.S +++ b/arch/tile/kernel/intvec_64.S @@ -1194,7 +1194,6 @@ PTREGS_SYSCALL(sys_execve, r3) PTREGS_SYSCALL(sys_sigaltstack, r2) PTREGS_SYSCALL_SIGRETURN(sys_rt_sigreturn, r0) #ifdef CONFIG_COMPAT -PTREGS_SYSCALL(compat_sys_execve, r3) PTREGS_SYSCALL(compat_sys_sigaltstack, r2) PTREGS_SYSCALL_SIGRETURN(compat_sys_rt_sigreturn, r0) #endif diff --git a/arch/tile/kernel/process.c b/arch/tile/kernel/process.c index 307d010696c..9dc139127f8 100644 --- a/arch/tile/kernel/process.c +++ b/arch/tile/kernel/process.c @@ -614,8 +614,7 @@ out: #ifdef CONFIG_COMPAT long compat_sys_execve(const char __user *path, compat_uptr_t __user *argv, - compat_uptr_t __user *envp, - struct pt_regs *regs) + compat_uptr_t __user *envp) { long error; struct filename *filename; @@ -624,7 +623,8 @@ long compat_sys_execve(const char __user *path, error = PTR_ERR(filename); if (IS_ERR(filename)) goto out; - error = compat_do_execve(filename->name, argv, envp, regs); + error = compat_do_execve(filename->name, argv, envp, + current_pt_regs()); putname(filename); if (error == 0) single_step_execve(); -- cgit v1.2.3 From 0f8b983812f5ff588d7e3459b203714e4e58a9b2 Mon Sep 17 00:00:00 2001 From: Chris Metcalf Date: Fri, 19 Oct 2012 16:25:12 -0400 Subject: tile: support GENERIC_KERNEL_THREAD and GENERIC_KERNEL_EXECVE Also provide an optimized current_pt_regs() while we're at it. Signed-off-by: Chris Metcalf Signed-off-by: Al Viro --- arch/tile/Kconfig | 2 + arch/tile/include/asm/switch_to.h | 5 +- arch/tile/kernel/entry.S | 11 ---- arch/tile/kernel/intvec_32.S | 15 ++++++ arch/tile/kernel/intvec_64.S | 15 ++++++ arch/tile/kernel/process.c | 103 +++++++++++++++----------------------- 6 files changed, 75 insertions(+), 76 deletions(-) (limited to 'arch/tile') diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig index 875d008828b..ea7f61e8bc9 100644 --- a/arch/tile/Kconfig +++ b/arch/tile/Kconfig @@ -21,6 +21,8 @@ config TILE select ARCH_HAVE_NMI_SAFE_CMPXCHG select GENERIC_CLOCKEVENTS select MODULES_USE_ELF_RELA + select GENERIC_KERNEL_THREAD + select GENERIC_KERNEL_EXECVE # FIXME: investigate whether we need/want these options. # select HAVE_IOREMAP_PROT diff --git a/arch/tile/include/asm/switch_to.h b/arch/tile/include/asm/switch_to.h index 1d48c5fee8b..b8f888cbe6b 100644 --- a/arch/tile/include/asm/switch_to.h +++ b/arch/tile/include/asm/switch_to.h @@ -68,7 +68,10 @@ extern unsigned long get_switch_to_pc(void); /* Support function for forking a new task. */ void ret_from_fork(void); -/* Called from ret_from_fork() when a new process starts up. */ +/* Support function for forking a new kernel thread. */ +void ret_from_kernel_thread(void *fn, void *arg); + +/* Called from ret_from_xxx() when a new process starts up. */ struct task_struct *sim_notify_fork(struct task_struct *prev); #endif /* !__ASSEMBLY__ */ diff --git a/arch/tile/kernel/entry.S b/arch/tile/kernel/entry.S index c31637baff2..f116cb0bce2 100644 --- a/arch/tile/kernel/entry.S +++ b/arch/tile/kernel/entry.S @@ -27,17 +27,6 @@ STD_ENTRY(current_text_addr) { move r0, lr; jrp lr } STD_ENDPROC(current_text_addr) -/* - * Implement execve(). The i386 code has a note that forking from kernel - * space results in no copy on write until the execve, so we should be - * careful not to write to the stack here. - */ -STD_ENTRY(kernel_execve) - moveli TREG_SYSCALL_NR_NAME, __NR_execve - swint1 - jrp lr - STD_ENDPROC(kernel_execve) - /* * We don't run this function directly, but instead copy it to a page * we map into every user process. See vdso_setup(). diff --git a/arch/tile/kernel/intvec_32.S b/arch/tile/kernel/intvec_32.S index 6943515100f..58aad519b7d 100644 --- a/arch/tile/kernel/intvec_32.S +++ b/arch/tile/kernel/intvec_32.S @@ -1291,6 +1291,21 @@ STD_ENTRY(ret_from_fork) } STD_ENDPROC(ret_from_fork) +STD_ENTRY(ret_from_kernel_thread) + jal sim_notify_fork + jal schedule_tail + FEEDBACK_REENTER(ret_from_fork) + { + move r0, r31 + jalr r30 + } + FEEDBACK_REENTER(ret_from_kernel_thread) + { + movei r30, 0 /* not an NMI */ + j .Lresume_userspace /* jump into middle of interrupt_return */ + } + STD_ENDPROC(ret_from_kernel_thread) + /* * Code for ill interrupt. */ diff --git a/arch/tile/kernel/intvec_64.S b/arch/tile/kernel/intvec_64.S index 73f6c0a648c..f66bd5f67d4 100644 --- a/arch/tile/kernel/intvec_64.S +++ b/arch/tile/kernel/intvec_64.S @@ -1150,6 +1150,21 @@ STD_ENTRY(ret_from_fork) } STD_ENDPROC(ret_from_fork) +STD_ENTRY(ret_from_kernel_thread) + jal sim_notify_fork + jal schedule_tail + FEEDBACK_REENTER(ret_from_fork) + { + move r0, r31 + jalr r30 + } + FEEDBACK_REENTER(ret_from_kernel_thread) + { + movei r30, 0 /* not an NMI */ + j .Lresume_userspace /* jump into middle of interrupt_return */ + } + STD_ENDPROC(ret_from_kernel_thread) + /* Various stub interrupt handlers and syscall handlers */ STD_ENTRY_LOCAL(_kernel_double_fault) diff --git a/arch/tile/kernel/process.c b/arch/tile/kernel/process.c index 9dc139127f8..da6e4d78da6 100644 --- a/arch/tile/kernel/process.c +++ b/arch/tile/kernel/process.c @@ -157,24 +157,44 @@ void arch_release_thread_info(struct thread_info *info) static void save_arch_state(struct thread_struct *t); int copy_thread(unsigned long clone_flags, unsigned long sp, - unsigned long stack_size, + unsigned long arg, struct task_struct *p, struct pt_regs *regs) { - struct pt_regs *childregs; + struct pt_regs *childregs = task_pt_regs(p); unsigned long ksp; + unsigned long *callee_regs; /* - * When creating a new kernel thread we pass sp as zero. - * Assign it to a reasonable value now that we have the stack. + * Set up the stack and stack pointer appropriately for the + * new child to find itself woken up in __switch_to(). + * The callee-saved registers must be on the stack to be read; + * the new task will then jump to assembly support to handle + * calling schedule_tail(), etc., and (for userspace tasks) + * returning to the context set up in the pt_regs. */ - if (sp == 0 && regs->ex1 == PL_ICS_EX1(KERNEL_PL, 0)) - sp = KSTK_TOP(p); + ksp = (unsigned long) childregs; + ksp -= C_ABI_SAVE_AREA_SIZE; /* interrupt-entry save area */ + ((long *)ksp)[0] = ((long *)ksp)[1] = 0; + ksp -= CALLEE_SAVED_REGS_COUNT * sizeof(unsigned long); + callee_regs = (unsigned long *)ksp; + ksp -= C_ABI_SAVE_AREA_SIZE; /* __switch_to() save area */ + ((long *)ksp)[0] = ((long *)ksp)[1] = 0; + p->thread.ksp = ksp; - /* - * Do not clone step state from the parent; each thread - * must make its own lazily. - */ - task_thread_info(p)->step_state = NULL; + /* Record the pid of the task that created this one. */ + p->thread.creator_pid = current->pid; + + if (unlikely(!regs)) { + /* kernel thread */ + memset(childregs, 0, sizeof(struct pt_regs)); + memset(&callee_regs[2], 0, + (CALLEE_SAVED_REGS_COUNT - 2) * sizeof(unsigned long)); + callee_regs[0] = sp; /* r30 = function */ + callee_regs[1] = arg; /* r31 = arg */ + childregs->ex1 = PL_ICS_EX1(KERNEL_PL, 0); + p->thread.pc = (unsigned long) ret_from_kernel_thread; + return 0; + } /* * Start new thread in ret_from_fork so it schedules properly @@ -182,20 +202,24 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, */ p->thread.pc = (unsigned long) ret_from_fork; + /* + * Do not clone step state from the parent; each thread + * must make its own lazily. + */ + task_thread_info(p)->step_state = NULL; + /* Save user stack top pointer so we can ID the stack vm area later. */ p->thread.usp0 = sp; - /* Record the pid of the process that created this one. */ - p->thread.creator_pid = current->pid; - /* * Copy the registers onto the kernel stack so the * return-from-interrupt code will reload it into registers. */ - childregs = task_pt_regs(p); *childregs = *regs; childregs->regs[0] = 0; /* return value is zero */ childregs->sp = sp; /* override with new user stack pointer */ + memcpy(callee_regs, ®s->regs[CALLEE_SAVED_FIRST_REG], + CALLEE_SAVED_REGS_COUNT * sizeof(unsigned long)); /* * If CLONE_SETTLS is set, set "tp" in the new task to "r4", @@ -204,24 +228,6 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, if (clone_flags & CLONE_SETTLS) childregs->tp = regs->regs[4]; - /* - * Copy the callee-saved registers from the passed pt_regs struct - * into the context-switch callee-saved registers area. - * This way when we start the interrupt-return sequence, the - * callee-save registers will be correctly in registers, which - * is how we assume the compiler leaves them as we start doing - * the normal return-from-interrupt path after calling C code. - * Zero out the C ABI save area to mark the top of the stack. - */ - ksp = (unsigned long) childregs; - ksp -= C_ABI_SAVE_AREA_SIZE; /* interrupt-entry save area */ - ((long *)ksp)[0] = ((long *)ksp)[1] = 0; - ksp -= CALLEE_SAVED_REGS_COUNT * sizeof(unsigned long); - memcpy((void *)ksp, ®s->regs[CALLEE_SAVED_FIRST_REG], - CALLEE_SAVED_REGS_COUNT * sizeof(unsigned long)); - ksp -= C_ABI_SAVE_AREA_SIZE; /* __switch_to() save area */ - ((long *)ksp)[0] = ((long *)ksp)[1] = 0; - p->thread.ksp = ksp; #if CHIP_HAS_TILE_DMA() /* @@ -650,37 +656,6 @@ unsigned long get_wchan(struct task_struct *p) return 0; } -/* - * We pass in lr as zero (cleared in kernel_thread) and the caller - * part of the backtrace ABI on the stack also zeroed (in copy_thread) - * so that backtraces will stop with this function. - * Note that we don't use r0, since copy_thread() clears it. - */ -static void start_kernel_thread(int dummy, int (*fn)(int), int arg) -{ - do_exit(fn(arg)); -} - -/* - * Create a kernel thread - */ -int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags) -{ - struct pt_regs regs; - - memset(®s, 0, sizeof(regs)); - regs.ex1 = PL_ICS_EX1(KERNEL_PL, 0); /* run at kernel PL, no ICS */ - regs.pc = (long) start_kernel_thread; - regs.flags = PT_FLAGS_CALLER_SAVES; /* need to restore r1 and r2 */ - regs.regs[1] = (long) fn; /* function pointer */ - regs.regs[2] = (long) arg; /* parameter register */ - - /* Ok, create the new process.. */ - return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, ®s, - 0, NULL, NULL); -} -EXPORT_SYMBOL(kernel_thread); - /* Flush thread state. */ void flush_thread(void) { -- cgit v1.2.3 From 530550651fdfd548d25b6bd5ff4607803540508b Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 20 Oct 2012 13:14:08 -0400 Subject: tile: switch to generic sys_execve() Acked-by: Chris Metcalf Signed-off-by: Al Viro --- arch/tile/include/asm/elf.h | 1 + arch/tile/include/asm/processor.h | 1 + arch/tile/include/asm/syscalls.h | 3 ++- arch/tile/include/asm/unistd.h | 1 + arch/tile/kernel/intvec_32.S | 1 - arch/tile/kernel/intvec_64.S | 1 - arch/tile/kernel/process.c | 45 --------------------------------------- arch/tile/kernel/sys.c | 1 - 8 files changed, 5 insertions(+), 49 deletions(-) (limited to 'arch/tile') diff --git a/arch/tile/include/asm/elf.h b/arch/tile/include/asm/elf.h index f8ccf08f693..b73e1039c91 100644 --- a/arch/tile/include/asm/elf.h +++ b/arch/tile/include/asm/elf.h @@ -148,6 +148,7 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm, #define compat_start_thread(regs, ip, usp) do { \ regs->pc = ptr_to_compat_reg((void *)(ip)); \ regs->sp = ptr_to_compat_reg((void *)(usp)); \ + single_step_execve(); \ } while (0) /* diff --git a/arch/tile/include/asm/processor.h b/arch/tile/include/asm/processor.h index 9a83e531e84..879073e7658 100644 --- a/arch/tile/include/asm/processor.h +++ b/arch/tile/include/asm/processor.h @@ -211,6 +211,7 @@ static inline void start_thread(struct pt_regs *regs, { regs->pc = pc; regs->sp = usp; + single_step_execve(); } /* Free all resources held by a thread. */ diff --git a/arch/tile/include/asm/syscalls.h b/arch/tile/include/asm/syscalls.h index 06f0464cfed..0d52992f8e0 100644 --- a/arch/tile/include/asm/syscalls.h +++ b/arch/tile/include/asm/syscalls.h @@ -68,9 +68,10 @@ long _sys_sigaltstack(const stack_t __user *, stack_t __user *); long _sys_rt_sigreturn(void); long _sys_clone(unsigned long clone_flags, unsigned long newsp, void __user *parent_tid, void __user *child_tid); -long _sys_execve(const char __user *filename, +long sys_execve(const char __user *filename, const char __user *const __user *argv, const char __user *const __user *envp); +#define sys_execve sys_execve #include diff --git a/arch/tile/include/asm/unistd.h b/arch/tile/include/asm/unistd.h index 6e032a0a268..dab827dc8ac 100644 --- a/arch/tile/include/asm/unistd.h +++ b/arch/tile/include/asm/unistd.h @@ -16,4 +16,5 @@ #define __ARCH_WANT_SYS_LLSEEK #endif #define __ARCH_WANT_SYS_NEWFSTATAT +#define __ARCH_WANT_SYS_EXECVE #include diff --git a/arch/tile/kernel/intvec_32.S b/arch/tile/kernel/intvec_32.S index 58aad519b7d..174b837ef92 100644 --- a/arch/tile/kernel/intvec_32.S +++ b/arch/tile/kernel/intvec_32.S @@ -1476,7 +1476,6 @@ STD_ENTRY_LOCAL(bad_intr) }; \ STD_ENDPROC(_##x) -PTREGS_SYSCALL(sys_execve, r3) PTREGS_SYSCALL(sys_sigaltstack, r2) PTREGS_SYSCALL_SIGRETURN(sys_rt_sigreturn, r0) PTREGS_SYSCALL(sys_cmpxchg_badaddr, r1) diff --git a/arch/tile/kernel/intvec_64.S b/arch/tile/kernel/intvec_64.S index f66bd5f67d4..283efedf67d 100644 --- a/arch/tile/kernel/intvec_64.S +++ b/arch/tile/kernel/intvec_64.S @@ -1205,7 +1205,6 @@ STD_ENTRY_LOCAL(bad_intr) }; \ STD_ENDPROC(_##x) -PTREGS_SYSCALL(sys_execve, r3) PTREGS_SYSCALL(sys_sigaltstack, r2) PTREGS_SYSCALL_SIGRETURN(sys_rt_sigreturn, r0) #ifdef CONFIG_COMPAT diff --git a/arch/tile/kernel/process.c b/arch/tile/kernel/process.c index da6e4d78da6..58f8fd1f0bc 100644 --- a/arch/tile/kernel/process.c +++ b/arch/tile/kernel/process.c @@ -594,51 +594,6 @@ SYSCALL_DEFINE5(clone, unsigned long, clone_flags, unsigned long, newsp, parent_tidptr, child_tidptr); } -/* - * sys_execve() executes a new program. - */ -SYSCALL_DEFINE4(execve, const char __user *, path, - const char __user *const __user *, argv, - const char __user *const __user *, envp, - struct pt_regs *, regs) -{ - long error; - struct filename *filename; - - filename = getname(path); - error = PTR_ERR(filename); - if (IS_ERR(filename)) - goto out; - error = do_execve(filename->name, argv, envp, regs); - putname(filename); - if (error == 0) - single_step_execve(); -out: - return error; -} - -#ifdef CONFIG_COMPAT -long compat_sys_execve(const char __user *path, - compat_uptr_t __user *argv, - compat_uptr_t __user *envp) -{ - long error; - struct filename *filename; - - filename = getname(path); - error = PTR_ERR(filename); - if (IS_ERR(filename)) - goto out; - error = compat_do_execve(filename->name, argv, envp, - current_pt_regs()); - putname(filename); - if (error == 0) - single_step_execve(); -out: - return error; -} -#endif - unsigned long get_wchan(struct task_struct *p) { struct KBacktraceIterator kbt; diff --git a/arch/tile/kernel/sys.c b/arch/tile/kernel/sys.c index b08095b402d..359e76f6883 100644 --- a/arch/tile/kernel/sys.c +++ b/arch/tile/kernel/sys.c @@ -107,7 +107,6 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len, #endif /* Call the trampolines to manage pt_regs where necessary. */ -#define sys_execve _sys_execve #define sys_sigaltstack _sys_sigaltstack #define sys_rt_sigreturn _sys_rt_sigreturn #define sys_clone _sys_clone -- cgit v1.2.3 From 6b14e4198c729b748a7f6d22059e6a101d2b241a Mon Sep 17 00:00:00 2001 From: Chris Metcalf Date: Tue, 23 Oct 2012 13:30:54 -0400 Subject: arch/tile: eliminate pt_regs trampolines for syscalls Using the new current_pt_regs() model, we can remove some trampolines from assembly code and call directly to the C syscall implementations. rt_sigreturn() and clone() still need some assembly wrapping, but no longer are passed a pt_regs pointer. sigaltstack() and the tilepro-specific cmpxchg_badaddr() syscalls are now just straight C. Signed-off-by: Chris Metcalf --- arch/tile/include/asm/compat.h | 9 +++------ arch/tile/include/asm/syscalls.h | 19 +++++++++++++------ arch/tile/kernel/compat.c | 4 ++-- arch/tile/kernel/compat_signal.c | 10 +++++----- arch/tile/kernel/intvec_32.S | 13 +------------ arch/tile/kernel/intvec_64.S | 13 +------------ arch/tile/kernel/process.c | 6 +++--- arch/tile/kernel/signal.c | 9 +++++---- arch/tile/kernel/sys.c | 8 +++----- arch/tile/mm/fault.c | 5 +++-- 10 files changed, 39 insertions(+), 57 deletions(-) (limited to 'arch/tile') diff --git a/arch/tile/include/asm/compat.h b/arch/tile/include/asm/compat.h index 3bcf1b94b56..ca61fb4296b 100644 --- a/arch/tile/include/asm/compat.h +++ b/arch/tile/include/asm/compat.h @@ -280,10 +280,9 @@ long compat_sys_rt_sigaction(int sig, struct compat_sigaction __user *act, size_t sigsetsize); long compat_sys_rt_sigqueueinfo(int pid, int sig, struct compat_siginfo __user *uinfo); -long compat_sys_rt_sigreturn(struct pt_regs *); +long compat_sys_rt_sigreturn(void); long compat_sys_sigaltstack(const struct compat_sigaltstack __user *uss_ptr, - struct compat_sigaltstack __user *uoss_ptr, - struct pt_regs *); + struct compat_sigaltstack __user *uoss_ptr); long compat_sys_truncate64(char __user *filename, u32 dummy, u32 low, u32 high); long compat_sys_ftruncate64(unsigned int fd, u32 dummy, u32 low, u32 high); long compat_sys_pread64(unsigned int fd, char __user *ubuf, size_t count, @@ -300,9 +299,7 @@ long compat_sys_fallocate(int fd, int mode, long compat_sys_sched_rr_get_interval(compat_pid_t pid, struct compat_timespec __user *interval); -/* These are the intvec_64.S trampolines. */ -long _compat_sys_sigaltstack(const struct compat_sigaltstack __user *uss_ptr, - struct compat_sigaltstack __user *uoss_ptr); +/* Assembly trampoline to avoid clobbering r0. */ long _compat_sys_rt_sigreturn(void); #endif /* _ASM_TILE_COMPAT_H */ diff --git a/arch/tile/include/asm/syscalls.h b/arch/tile/include/asm/syscalls.h index 0d52992f8e0..369696d63e7 100644 --- a/arch/tile/include/asm/syscalls.h +++ b/arch/tile/include/asm/syscalls.h @@ -51,8 +51,7 @@ long sys_cacheflush(unsigned long addr, unsigned long len, #ifndef __tilegx__ /* mm/fault.c */ -long sys_cmpxchg_badaddr(unsigned long address, struct pt_regs *); -long _sys_cmpxchg_badaddr(unsigned long address); +long sys_cmpxchg_badaddr(unsigned long address); #endif #ifdef CONFIG_COMPAT @@ -63,15 +62,23 @@ long sys_truncate64(const char __user *path, loff_t length); long sys_ftruncate64(unsigned int fd, loff_t length); #endif -/* These are the intvec*.S trampolines. */ -long _sys_sigaltstack(const stack_t __user *, stack_t __user *); -long _sys_rt_sigreturn(void); -long _sys_clone(unsigned long clone_flags, unsigned long newsp, +/* Provide versions of standard syscalls that use current_pt_regs(). */ +long sys_clone(unsigned long clone_flags, unsigned long newsp, void __user *parent_tid, void __user *child_tid); long sys_execve(const char __user *filename, const char __user *const __user *argv, const char __user *const __user *envp); +long sys_rt_sigreturn(void); +long sys_sigaltstack(const stack_t __user *, stack_t __user *); +#define sys_clone sys_clone #define sys_execve sys_execve +#define sys_rt_sigreturn sys_rt_sigreturn +#define sys_sigaltstack sys_sigaltstack + +/* These are the intvec*.S trampolines. */ +long _sys_rt_sigreturn(void); +long _sys_clone(unsigned long clone_flags, unsigned long newsp, + void __user *parent_tid, void __user *child_tid); #include diff --git a/arch/tile/kernel/compat.c b/arch/tile/kernel/compat.c index a8e5a847037..a2e805569d5 100644 --- a/arch/tile/kernel/compat.c +++ b/arch/tile/kernel/compat.c @@ -102,9 +102,9 @@ long compat_sys_sched_rr_get_interval(compat_pid_t pid, #define compat_sys_fadvise64_64 sys32_fadvise64_64 #define compat_sys_readahead sys32_readahead -/* Call the trampolines to manage pt_regs where necessary. */ -#define compat_sys_sigaltstack _compat_sys_sigaltstack +/* Call the assembly trampolines where necessary. */ #define compat_sys_rt_sigreturn _compat_sys_rt_sigreturn +#undef sys_clone #define sys_clone _sys_clone /* diff --git a/arch/tile/kernel/compat_signal.c b/arch/tile/kernel/compat_signal.c index 08b4fe1717b..210a9bbae96 100644 --- a/arch/tile/kernel/compat_signal.c +++ b/arch/tile/kernel/compat_signal.c @@ -197,8 +197,7 @@ int copy_siginfo_from_user32(siginfo_t *to, struct compat_siginfo __user *from) } long compat_sys_sigaltstack(const struct compat_sigaltstack __user *uss_ptr, - struct compat_sigaltstack __user *uoss_ptr, - struct pt_regs *regs) + struct compat_sigaltstack __user *uoss_ptr) { stack_t uss, uoss; int ret; @@ -219,7 +218,7 @@ long compat_sys_sigaltstack(const struct compat_sigaltstack __user *uss_ptr, set_fs(KERNEL_DS); ret = do_sigaltstack(uss_ptr ? (stack_t __user __force *)&uss : NULL, (stack_t __user __force *)&uoss, - (unsigned long)compat_ptr(regs->sp)); + (unsigned long)compat_ptr(current_pt_regs()->sp)); set_fs(seg); if (ret >= 0 && uoss_ptr) { if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(*uoss_ptr)) || @@ -232,8 +231,9 @@ long compat_sys_sigaltstack(const struct compat_sigaltstack __user *uss_ptr, } /* The assembly shim for this function arranges to ignore the return value. */ -long compat_sys_rt_sigreturn(struct pt_regs *regs) +long compat_sys_rt_sigreturn(void) { + struct pt_regs *regs = current_pt_regs(); struct compat_rt_sigframe __user *frame = (struct compat_rt_sigframe __user *) compat_ptr(regs->sp); sigset_t set; @@ -248,7 +248,7 @@ long compat_sys_rt_sigreturn(struct pt_regs *regs) if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) goto badframe; - if (compat_sys_sigaltstack(&frame->uc.uc_stack, NULL, regs) != 0) + if (compat_sys_sigaltstack(&frame->uc.uc_stack, NULL) != 0) goto badframe; return 0; diff --git a/arch/tile/kernel/intvec_32.S b/arch/tile/kernel/intvec_32.S index 174b837ef92..f212bf7cea8 100644 --- a/arch/tile/kernel/intvec_32.S +++ b/arch/tile/kernel/intvec_32.S @@ -1452,15 +1452,6 @@ STD_ENTRY_LOCAL(bad_intr) panic "Unhandled interrupt %#x: PC %#lx" STD_ENDPROC(bad_intr) -/* Put address of pt_regs in reg and jump. */ -#define PTREGS_SYSCALL(x, reg) \ - STD_ENTRY(_##x); \ - { \ - PTREGS_PTR(reg, PTREGS_OFFSET_BASE); \ - j x \ - }; \ - STD_ENDPROC(_##x) - /* * Special-case sigreturn to not write r0 to the stack on return. * This is technically more efficient, but it also avoids difficulties @@ -1476,11 +1467,9 @@ STD_ENTRY_LOCAL(bad_intr) }; \ STD_ENDPROC(_##x) -PTREGS_SYSCALL(sys_sigaltstack, r2) PTREGS_SYSCALL_SIGRETURN(sys_rt_sigreturn, r0) -PTREGS_SYSCALL(sys_cmpxchg_badaddr, r1) -/* Save additional callee-saves to pt_regs, put address in r4 and jump. */ +/* Save additional callee-saves to pt_regs and jump to standard function. */ STD_ENTRY(_sys_clone) push_extra_callee_saves r4 j sys_clone diff --git a/arch/tile/kernel/intvec_64.S b/arch/tile/kernel/intvec_64.S index 283efedf67d..54bc9a6678e 100644 --- a/arch/tile/kernel/intvec_64.S +++ b/arch/tile/kernel/intvec_64.S @@ -1181,15 +1181,6 @@ STD_ENTRY_LOCAL(bad_intr) panic "Unhandled interrupt %#x: PC %#lx" STD_ENDPROC(bad_intr) -/* Put address of pt_regs in reg and jump. */ -#define PTREGS_SYSCALL(x, reg) \ - STD_ENTRY(_##x); \ - { \ - PTREGS_PTR(reg, PTREGS_OFFSET_BASE); \ - j x \ - }; \ - STD_ENDPROC(_##x) - /* * Special-case sigreturn to not write r0 to the stack on return. * This is technically more efficient, but it also avoids difficulties @@ -1205,14 +1196,12 @@ STD_ENTRY_LOCAL(bad_intr) }; \ STD_ENDPROC(_##x) -PTREGS_SYSCALL(sys_sigaltstack, r2) PTREGS_SYSCALL_SIGRETURN(sys_rt_sigreturn, r0) #ifdef CONFIG_COMPAT -PTREGS_SYSCALL(compat_sys_sigaltstack, r2) PTREGS_SYSCALL_SIGRETURN(compat_sys_rt_sigreturn, r0) #endif -/* Save additional callee-saves to pt_regs, put address in r4 and jump. */ +/* Save additional callee-saves to pt_regs and jump to standard function. */ STD_ENTRY(_sys_clone) push_extra_callee_saves r4 j sys_clone diff --git a/arch/tile/kernel/process.c b/arch/tile/kernel/process.c index 58f8fd1f0bc..6e7fb4e41f1 100644 --- a/arch/tile/kernel/process.c +++ b/arch/tile/kernel/process.c @@ -584,10 +584,10 @@ int do_work_pending(struct pt_regs *regs, u32 thread_info_flags) } /* Note there is an implicit fifth argument if (clone_flags & CLONE_SETTLS). */ -SYSCALL_DEFINE5(clone, unsigned long, clone_flags, unsigned long, newsp, - void __user *, parent_tidptr, void __user *, child_tidptr, - struct pt_regs *, regs) +SYSCALL_DEFINE4(clone, unsigned long, clone_flags, unsigned long, newsp, + void __user *, parent_tidptr, void __user *, child_tidptr) { + struct pt_regs *regs = current_pt_regs(); if (!newsp) newsp = regs->sp; return do_fork(clone_flags, newsp, regs, 0, diff --git a/arch/tile/kernel/signal.c b/arch/tile/kernel/signal.c index 67efb656d10..657a7ace4ab 100644 --- a/arch/tile/kernel/signal.c +++ b/arch/tile/kernel/signal.c @@ -37,10 +37,10 @@ #define DEBUG_SIG 0 -SYSCALL_DEFINE3(sigaltstack, const stack_t __user *, uss, - stack_t __user *, uoss, struct pt_regs *, regs) +SYSCALL_DEFINE2(sigaltstack, const stack_t __user *, uss, + stack_t __user *, uoss) { - return do_sigaltstack(uss, uoss, regs->sp); + return do_sigaltstack(uss, uoss, current_pt_regs()->sp); } @@ -83,8 +83,9 @@ void signal_fault(const char *type, struct pt_regs *regs, } /* The assembly shim for this function arranges to ignore the return value. */ -SYSCALL_DEFINE1(rt_sigreturn, struct pt_regs *, regs) +SYSCALL_DEFINE0(rt_sigreturn) { + struct pt_regs *regs = current_pt_regs(); struct rt_sigframe __user *frame = (struct rt_sigframe __user *)(regs->sp); sigset_t set; diff --git a/arch/tile/kernel/sys.c b/arch/tile/kernel/sys.c index 359e76f6883..02ff5c0ef77 100644 --- a/arch/tile/kernel/sys.c +++ b/arch/tile/kernel/sys.c @@ -106,13 +106,11 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len, #define sys_readahead sys32_readahead #endif -/* Call the trampolines to manage pt_regs where necessary. */ -#define sys_sigaltstack _sys_sigaltstack +/* Call the assembly trampolines where necessary. */ +#undef sys_rt_sigreturn #define sys_rt_sigreturn _sys_rt_sigreturn +#undef sys_clone #define sys_clone _sys_clone -#ifndef __tilegx__ -#define sys_cmpxchg_badaddr _sys_cmpxchg_badaddr -#endif /* * Note that we can't include here since the header diff --git a/arch/tile/mm/fault.c b/arch/tile/mm/fault.c index fe811fa5f1b..3d2b81c163a 100644 --- a/arch/tile/mm/fault.c +++ b/arch/tile/mm/fault.c @@ -70,9 +70,10 @@ static noinline void force_sig_info_fault(const char *type, int si_signo, * Synthesize the fault a PL0 process would get by doing a word-load of * an unaligned address or a high kernel address. */ -SYSCALL_DEFINE2(cmpxchg_badaddr, unsigned long, address, - struct pt_regs *, regs) +SYSCALL_DEFINE1(cmpxchg_badaddr, unsigned long, address) { + struct pt_regs *regs = current_pt_regs(); + if (address >= PAGE_OFFSET) force_sig_info_fault("atomic segfault", SIGSEGV, SEGV_MAPERR, address, INT_DTLB_MISS, current, regs); -- cgit v1.2.3 From 008f17948725c112a3422f72ed57fdc980e146a8 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Tue, 23 Oct 2012 23:32:21 -0400 Subject: tile: sanitize copy_thread() Acked-by: Chris Metcalf Signed-off-by: Al Viro --- arch/tile/kernel/process.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'arch/tile') diff --git a/arch/tile/kernel/process.c b/arch/tile/kernel/process.c index 6e7fb4e41f1..1c20029d2f5 100644 --- a/arch/tile/kernel/process.c +++ b/arch/tile/kernel/process.c @@ -158,7 +158,7 @@ static void save_arch_state(struct thread_struct *t); int copy_thread(unsigned long clone_flags, unsigned long sp, unsigned long arg, - struct task_struct *p, struct pt_regs *regs) + struct task_struct *p, struct pt_regs *unused) { struct pt_regs *childregs = task_pt_regs(p); unsigned long ksp; @@ -184,7 +184,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, /* Record the pid of the task that created this one. */ p->thread.creator_pid = current->pid; - if (unlikely(!regs)) { + if (unlikely(p->flags & PF_KTHREAD)) { /* kernel thread */ memset(childregs, 0, sizeof(struct pt_regs)); memset(&callee_regs[2], 0, @@ -208,25 +208,26 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, */ task_thread_info(p)->step_state = NULL; - /* Save user stack top pointer so we can ID the stack vm area later. */ - p->thread.usp0 = sp; - /* * Copy the registers onto the kernel stack so the * return-from-interrupt code will reload it into registers. */ - *childregs = *regs; + *childregs = *current_pt_regs(); childregs->regs[0] = 0; /* return value is zero */ - childregs->sp = sp; /* override with new user stack pointer */ - memcpy(callee_regs, ®s->regs[CALLEE_SAVED_FIRST_REG], + if (sp) + childregs->sp = sp; /* override with new user stack pointer */ + memcpy(callee_regs, &childregs->regs[CALLEE_SAVED_FIRST_REG], CALLEE_SAVED_REGS_COUNT * sizeof(unsigned long)); + /* Save user stack top pointer so we can ID the stack vm area later. */ + p->thread.usp0 = childregs->sp; + /* * If CLONE_SETTLS is set, set "tp" in the new task to "r4", * which is passed in as arg #5 to sys_clone(). */ if (clone_flags & CLONE_SETTLS) - childregs->tp = regs->regs[4]; + childregs->tp = childregs->regs[4]; #if CHIP_HAS_TILE_DMA() @@ -587,10 +588,7 @@ int do_work_pending(struct pt_regs *regs, u32 thread_info_flags) SYSCALL_DEFINE4(clone, unsigned long, clone_flags, unsigned long, newsp, void __user *, parent_tidptr, void __user *, child_tidptr) { - struct pt_regs *regs = current_pt_regs(); - if (!newsp) - newsp = regs->sp; - return do_fork(clone_flags, newsp, regs, 0, + return do_fork(clone_flags, newsp, current_pt_regs(), 0, parent_tidptr, child_tidptr); } -- cgit v1.2.3 From e3cb7e9f0d826b052b519f1ea18a1bd1718a6016 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Wed, 28 Nov 2012 21:43:21 -0500 Subject: tile: compat rt_sigreturn gets too enthusiastic about sigaltstack errors Signed-off-by: Al Viro --- arch/tile/kernel/compat_signal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch/tile') diff --git a/arch/tile/kernel/compat_signal.c b/arch/tile/kernel/compat_signal.c index 210a9bbae96..2e4cc69224a 100644 --- a/arch/tile/kernel/compat_signal.c +++ b/arch/tile/kernel/compat_signal.c @@ -248,7 +248,7 @@ long compat_sys_rt_sigreturn(void) if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) goto badframe; - if (compat_sys_sigaltstack(&frame->uc.uc_stack, NULL) != 0) + if (compat_sys_sigaltstack(&frame->uc.uc_stack, NULL) == -EFAULT) goto badframe; return 0; -- cgit v1.2.3 From 6b94631f9e8c45a46056cbc6a7a50ecebea4f8da Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 20 Oct 2012 13:32:30 -0400 Subject: consolidate sys_execve() prototype Signed-off-by: Al Viro --- arch/tile/include/asm/syscalls.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'arch/tile') diff --git a/arch/tile/include/asm/syscalls.h b/arch/tile/include/asm/syscalls.h index 369696d63e7..394c76f2dc7 100644 --- a/arch/tile/include/asm/syscalls.h +++ b/arch/tile/include/asm/syscalls.h @@ -65,13 +65,9 @@ long sys_ftruncate64(unsigned int fd, loff_t length); /* Provide versions of standard syscalls that use current_pt_regs(). */ long sys_clone(unsigned long clone_flags, unsigned long newsp, void __user *parent_tid, void __user *child_tid); -long sys_execve(const char __user *filename, - const char __user *const __user *argv, - const char __user *const __user *envp); long sys_rt_sigreturn(void); long sys_sigaltstack(const stack_t __user *, stack_t __user *); #define sys_clone sys_clone -#define sys_execve sys_execve #define sys_rt_sigreturn sys_rt_sigreturn #define sys_sigaltstack sys_sigaltstack -- cgit v1.2.3 From 910cdc553a324d3df56b73c84cdef20836817d52 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 20 Oct 2012 21:42:37 -0400 Subject: kill stray kernel_thread() garbage Signed-off-by: Al Viro --- arch/tile/include/asm/processor.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'arch/tile') diff --git a/arch/tile/include/asm/processor.h b/arch/tile/include/asm/processor.h index 879073e7658..2b70dfb1442 100644 --- a/arch/tile/include/asm/processor.h +++ b/arch/tile/include/asm/processor.h @@ -220,8 +220,6 @@ static inline void release_thread(struct task_struct *dead_task) /* Nothing for now */ } -extern int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags); - extern int do_work_pending(struct pt_regs *regs, u32 flags); -- cgit v1.2.3 From e9eac30418dbbe51217a7c91906d349f9f4658e1 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Fri, 26 Oct 2012 23:36:42 -0400 Subject: tile: switch to generic clone() Signed-off-by: Al Viro --- arch/tile/include/asm/unistd.h | 1 + arch/tile/kernel/process.c | 8 -------- 2 files changed, 1 insertion(+), 8 deletions(-) (limited to 'arch/tile') diff --git a/arch/tile/include/asm/unistd.h b/arch/tile/include/asm/unistd.h index dab827dc8ac..b51c6ee3cd6 100644 --- a/arch/tile/include/asm/unistd.h +++ b/arch/tile/include/asm/unistd.h @@ -17,4 +17,5 @@ #endif #define __ARCH_WANT_SYS_NEWFSTATAT #define __ARCH_WANT_SYS_EXECVE +#define __ARCH_WANT_SYS_CLONE #include diff --git a/arch/tile/kernel/process.c b/arch/tile/kernel/process.c index 1c20029d2f5..267936b51b5 100644 --- a/arch/tile/kernel/process.c +++ b/arch/tile/kernel/process.c @@ -584,14 +584,6 @@ int do_work_pending(struct pt_regs *regs, u32 thread_info_flags) panic("work_pending: bad flags %#x\n", thread_info_flags); } -/* Note there is an implicit fifth argument if (clone_flags & CLONE_SETTLS). */ -SYSCALL_DEFINE4(clone, unsigned long, clone_flags, unsigned long, newsp, - void __user *, parent_tidptr, void __user *, child_tidptr) -{ - return do_fork(clone_flags, newsp, current_pt_regs(), 0, - parent_tidptr, child_tidptr); -} - unsigned long get_wchan(struct task_struct *p) { struct KBacktraceIterator kbt; -- cgit v1.2.3 From 24465a40ba452bd81fdc9eecb2d75bb903aafdf6 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Wed, 28 Nov 2012 23:04:26 -0500 Subject: take sys_fork/sys_vfork/sys_clone prototypes to linux/syscalls.h now it can be done... Signed-off-by: Al Viro --- arch/tile/include/asm/syscalls.h | 3 --- arch/tile/kernel/compat.c | 1 - arch/tile/kernel/sys.c | 1 - 3 files changed, 5 deletions(-) (limited to 'arch/tile') diff --git a/arch/tile/include/asm/syscalls.h b/arch/tile/include/asm/syscalls.h index 394c76f2dc7..4c8462a62cb 100644 --- a/arch/tile/include/asm/syscalls.h +++ b/arch/tile/include/asm/syscalls.h @@ -63,11 +63,8 @@ long sys_ftruncate64(unsigned int fd, loff_t length); #endif /* Provide versions of standard syscalls that use current_pt_regs(). */ -long sys_clone(unsigned long clone_flags, unsigned long newsp, - void __user *parent_tid, void __user *child_tid); long sys_rt_sigreturn(void); long sys_sigaltstack(const stack_t __user *, stack_t __user *); -#define sys_clone sys_clone #define sys_rt_sigreturn sys_rt_sigreturn #define sys_sigaltstack sys_sigaltstack diff --git a/arch/tile/kernel/compat.c b/arch/tile/kernel/compat.c index a2e805569d5..9cd7cb6041c 100644 --- a/arch/tile/kernel/compat.c +++ b/arch/tile/kernel/compat.c @@ -104,7 +104,6 @@ long compat_sys_sched_rr_get_interval(compat_pid_t pid, /* Call the assembly trampolines where necessary. */ #define compat_sys_rt_sigreturn _compat_sys_rt_sigreturn -#undef sys_clone #define sys_clone _sys_clone /* diff --git a/arch/tile/kernel/sys.c b/arch/tile/kernel/sys.c index 02ff5c0ef77..b881a7be24b 100644 --- a/arch/tile/kernel/sys.c +++ b/arch/tile/kernel/sys.c @@ -109,7 +109,6 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len, /* Call the assembly trampolines where necessary. */ #undef sys_rt_sigreturn #define sys_rt_sigreturn _sys_rt_sigreturn -#undef sys_clone #define sys_clone _sys_clone /* -- cgit v1.2.3 From afa86fc426ff7e7f5477f15da9c405d08d5cf790 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Mon, 22 Oct 2012 22:51:14 -0400 Subject: flagday: don't pass regs to copy_thread() Signed-off-by: Al Viro --- arch/tile/kernel/process.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'arch/tile') diff --git a/arch/tile/kernel/process.c b/arch/tile/kernel/process.c index 267936b51b5..0e5661e7d00 100644 --- a/arch/tile/kernel/process.c +++ b/arch/tile/kernel/process.c @@ -157,10 +157,9 @@ void arch_release_thread_info(struct thread_info *info) static void save_arch_state(struct thread_struct *t); int copy_thread(unsigned long clone_flags, unsigned long sp, - unsigned long arg, - struct task_struct *p, struct pt_regs *unused) + unsigned long arg, struct task_struct *p) { - struct pt_regs *childregs = task_pt_regs(p); + struct pt_regs *childregs = task_pt_regs(p), *regs = current_pt_regs(); unsigned long ksp; unsigned long *callee_regs; -- cgit v1.2.3