diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-12-12 12:22:13 -0800 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-12-12 12:22:13 -0800 |
commit | 9977d9b379cb77e0f67bd6f4563618106e58e11d (patch) | |
tree | 0191accfddf578edb52c69c933d64521e3dce297 /arch/hexagon | |
parent | cf4af01221579a4e895f43dbfc47598fbfc5a731 (diff) | |
parent | 541880d9a2c7871f6370071d55aa6662d329c51e (diff) |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/signal
Pull big execve/kernel_thread/fork unification series from Al Viro:
"All architectures are converted to new model. Quite a bit of that
stuff is actually shared with architecture trees; in such cases it's
literally shared branch pulled by both, not a cherry-pick.
A lot of ugliness and black magic is gone (-3KLoC total in this one):
- kernel_thread()/kernel_execve()/sys_execve() redesign.
We don't do syscalls from kernel anymore for either kernel_thread()
or kernel_execve():
kernel_thread() is essentially clone(2) with callback run before we
return to userland, the callbacks either never return or do
successful do_execve() before returning.
kernel_execve() is a wrapper for do_execve() - it doesn't need to
do transition to user mode anymore.
As a result kernel_thread() and kernel_execve() are
arch-independent now - they live in kernel/fork.c and fs/exec.c
resp. sys_execve() is also in fs/exec.c and it's completely
architecture-independent.
- daemonize() is gone, along with its parts in fs/*.c
- struct pt_regs * is no longer passed to do_fork/copy_process/
copy_thread/do_execve/search_binary_handler/->load_binary/do_coredump.
- sys_fork()/sys_vfork()/sys_clone() unified; some architectures
still need wrappers (ones with callee-saved registers not saved in
pt_regs on syscall entry), but the main part of those suckers is in
kernel/fork.c now."
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/signal: (113 commits)
do_coredump(): get rid of pt_regs argument
print_fatal_signal(): get rid of pt_regs argument
ptrace_signal(): get rid of unused arguments
get rid of ptrace_signal_deliver() arguments
new helper: signal_pt_regs()
unify default ptrace_signal_deliver
flagday: kill pt_regs argument of do_fork()
death to idle_regs()
don't pass regs to copy_process()
flagday: don't pass regs to copy_thread()
bfin: switch to generic vfork, get rid of pointless wrappers
xtensa: switch to generic clone()
openrisc: switch to use of generic fork and clone
unicore32: switch to generic clone(2)
score: switch to generic fork/vfork/clone
c6x: sanitize copy_thread(), get rid of clone(2) wrapper, switch to generic clone()
take sys_fork/sys_vfork/sys_clone prototypes to linux/syscalls.h
mn10300: switch to generic fork/vfork/clone
h8300: switch to generic fork/vfork/clone
tile: switch to generic clone()
...
Conflicts:
arch/microblaze/include/asm/Kbuild
Diffstat (limited to 'arch/hexagon')
-rw-r--r-- | arch/hexagon/Kconfig | 2 | ||||
-rw-r--r-- | arch/hexagon/include/asm/processor.h | 1 | ||||
-rw-r--r-- | arch/hexagon/include/asm/syscall.h | 8 | ||||
-rw-r--r-- | arch/hexagon/include/uapi/asm/ptrace.h | 4 | ||||
-rw-r--r-- | arch/hexagon/include/uapi/asm/unistd.h | 2 | ||||
-rw-r--r-- | arch/hexagon/kernel/Makefile | 3 | ||||
-rw-r--r-- | arch/hexagon/kernel/process.c | 100 | ||||
-rw-r--r-- | arch/hexagon/kernel/signal.c | 4 | ||||
-rw-r--r-- | arch/hexagon/kernel/syscall.c | 89 | ||||
-rw-r--r-- | arch/hexagon/kernel/vm_entry.S | 4 |
10 files changed, 46 insertions, 171 deletions
diff --git a/arch/hexagon/Kconfig b/arch/hexagon/Kconfig index 0744f7d7b1f..e418803b6c8 100644 --- a/arch/hexagon/Kconfig +++ b/arch/hexagon/Kconfig @@ -31,6 +31,8 @@ config HEXAGON select GENERIC_CLOCKEVENTS select GENERIC_CLOCKEVENTS_BROADCAST select MODULES_USE_ELF_RELA + select GENERIC_KERNEL_THREAD + select GENERIC_KERNEL_EXECVE ---help--- Qualcomm Hexagon is a processor architecture designed for high performance and low power across a wide variety of applications. diff --git a/arch/hexagon/include/asm/processor.h b/arch/hexagon/include/asm/processor.h index a03323ab9d4..6dd5d370686 100644 --- a/arch/hexagon/include/asm/processor.h +++ b/arch/hexagon/include/asm/processor.h @@ -34,7 +34,6 @@ struct task_struct; /* this is defined in arch/process.c */ -extern pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags); extern unsigned long thread_saved_pc(struct task_struct *tsk); extern void start_thread(struct pt_regs *, unsigned long, unsigned long); diff --git a/arch/hexagon/include/asm/syscall.h b/arch/hexagon/include/asm/syscall.h index fb0e9d48faa..4af9c7b6f13 100644 --- a/arch/hexagon/include/asm/syscall.h +++ b/arch/hexagon/include/asm/syscall.h @@ -25,14 +25,6 @@ typedef long (*syscall_fn)(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); -asmlinkage int sys_execve(char __user *ufilename, char __user * __user *argv, - char __user * __user *envp); -asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp, - unsigned long parent_tidp, unsigned long child_tidp); - -#define sys_execve sys_execve -#define sys_clone sys_clone - #include <asm-generic/syscalls.h> extern void *sys_call_table[]; diff --git a/arch/hexagon/include/uapi/asm/ptrace.h b/arch/hexagon/include/uapi/asm/ptrace.h index 8ef784047a7..1ffce0c6ee0 100644 --- a/arch/hexagon/include/uapi/asm/ptrace.h +++ b/arch/hexagon/include/uapi/asm/ptrace.h @@ -32,4 +32,8 @@ extern int regs_query_register_offset(const char *name); extern const char *regs_query_register_name(unsigned int offset); +#define current_pt_regs() \ + ((struct pt_regs *) \ + ((unsigned long)current_thread_info() + THREAD_SIZE) - 1) + #endif diff --git a/arch/hexagon/include/uapi/asm/unistd.h b/arch/hexagon/include/uapi/asm/unistd.h index 81312d6a52e..2af81533bd0 100644 --- a/arch/hexagon/include/uapi/asm/unistd.h +++ b/arch/hexagon/include/uapi/asm/unistd.h @@ -27,5 +27,7 @@ */ #define sys_mmap2 sys_mmap_pgoff +#define __ARCH_WANT_SYS_EXECVE +#define __ARCH_WANT_SYS_CLONE #include <asm-generic/unistd.h> diff --git a/arch/hexagon/kernel/Makefile b/arch/hexagon/kernel/Makefile index 536aec093e6..6c19501b487 100644 --- a/arch/hexagon/kernel/Makefile +++ b/arch/hexagon/kernel/Makefile @@ -3,8 +3,7 @@ extra-y := head.o vmlinux.lds obj-$(CONFIG_SMP) += smp.o topology.o obj-y += setup.o irq_cpu.o traps.o syscalltab.o signal.o time.o -obj-y += process.o syscall.o trampoline.o reset.o ptrace.o -obj-y += vdso.o +obj-y += process.o trampoline.o reset.o ptrace.o vdso.o obj-$(CONFIG_KGDB) += kgdb.o obj-$(CONFIG_MODULES) += module.o hexagon_ksyms.o diff --git a/arch/hexagon/kernel/process.c b/arch/hexagon/kernel/process.c index 9f6d7411b57..06ae9ffcabd 100644 --- a/arch/hexagon/kernel/process.c +++ b/arch/hexagon/kernel/process.c @@ -26,33 +26,6 @@ #include <linux/slab.h> /* - * Kernel thread creation. The desired kernel function is "wrapped" - * in the kernel_thread_helper function, which does cleanup - * afterwards. - */ -static void __noreturn kernel_thread_helper(void *arg, int (*fn)(void *)) -{ - do_exit(fn(arg)); -} - -int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags) -{ - struct pt_regs regs; - - memset(®s, 0, sizeof(regs)); - /* - * Yes, we're exploting illicit knowledge of the ABI here. - */ - regs.r00 = (unsigned long) arg; - regs.r01 = (unsigned long) fn; - pt_set_elr(®s, (unsigned long)kernel_thread_helper); - pt_set_kmode(®s); - - return do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, ®s, 0, NULL, NULL); -} -EXPORT_SYMBOL(kernel_thread); - -/* * Program thread launch. Often defined as a macro in processor.h, * but we're shooting for a small footprint and it's not an inner-loop * performance-critical operation. @@ -114,8 +87,7 @@ unsigned long thread_saved_pc(struct task_struct *tsk) * Copy architecture-specific thread state */ int copy_thread(unsigned long clone_flags, unsigned long usp, - unsigned long unused, struct task_struct *p, - struct pt_regs *regs) + unsigned long arg, struct task_struct *p) { struct thread_info *ti = task_thread_info(p); struct hexagon_switch_stack *ss; @@ -125,61 +97,51 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, childregs = (struct pt_regs *) (((unsigned long) ti + THREAD_SIZE) - sizeof(*childregs)); - memcpy(childregs, regs, sizeof(*childregs)); ti->regs = childregs; /* * Establish kernel stack pointer and initial PC for new thread + * Note that unlike the usual situation, we do not copy the + * parent's callee-saved here; those are in pt_regs and whatever + * we leave here will be overridden on return to userland. */ ss = (struct hexagon_switch_stack *) ((unsigned long) childregs - sizeof(*ss)); ss->lr = (unsigned long)ret_from_fork; p->thread.switch_sp = ss; + if (unlikely(p->flags & PF_KTHREAD)) { + memset(childregs, 0, sizeof(struct pt_regs)); + /* r24 <- fn, r25 <- arg */ + ss->r2524 = usp | ((u64)arg << 32); + pt_set_kmode(childregs); + return 0; + } + memcpy(childregs, current_pt_regs(), sizeof(*childregs)); + ss->r2524 = 0; - /* If User mode thread, set pt_reg stack pointer as per parameter */ - if (user_mode(childregs)) { + if (usp) pt_set_rte_sp(childregs, usp); - /* Child sees zero return value */ - childregs->r00 = 0; - - /* - * The clone syscall has the C signature: - * int [r0] clone(int flags [r0], - * void *child_frame [r1], - * void *parent_tid [r2], - * void *child_tid [r3], - * void *thread_control_block [r4]); - * ugp is used to provide TLS support. - */ - if (clone_flags & CLONE_SETTLS) - childregs->ugp = childregs->r04; - - /* - * Parent sees new pid -- not necessary, not even possible at - * this point in the fork process - * Might also want to set things like ti->addr_limit - */ - } else { - /* - * If kernel thread, resume stack is kernel stack base. - * Note that this is pointer arithmetic on pt_regs * - */ - pt_set_rte_sp(childregs, (unsigned long)(childregs + 1)); - /* - * We need the current thread_info fast path pointer - * set up in pt_regs. The register to be used is - * parametric for assembler code, but the mechanism - * doesn't drop neatly into C. Needs to be fixed. - */ - childregs->THREADINFO_REG = (unsigned long) ti; - } + /* Child sees zero return value */ + childregs->r00 = 0; + + /* + * The clone syscall has the C signature: + * int [r0] clone(int flags [r0], + * void *child_frame [r1], + * void *parent_tid [r2], + * void *child_tid [r3], + * void *thread_control_block [r4]); + * ugp is used to provide TLS support. + */ + if (clone_flags & CLONE_SETTLS) + childregs->ugp = childregs->r04; /* - * thread_info pointer is pulled out of task_struct "stack" - * field on switch_to. + * Parent sees new pid -- not necessary, not even possible at + * this point in the fork process + * Might also want to set things like ti->addr_limit */ - p->stack = (void *)ti; return 0; } diff --git a/arch/hexagon/kernel/signal.c b/arch/hexagon/kernel/signal.c index 5047b8b879c..fe0d1373165 100644 --- a/arch/hexagon/kernel/signal.c +++ b/arch/hexagon/kernel/signal.c @@ -249,14 +249,14 @@ void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags) */ asmlinkage int sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss) { - struct pt_regs *regs = current_thread_info()->regs; + struct pt_regs *regs = current_pt_regs(); return do_sigaltstack(uss, uoss, regs->r29); } asmlinkage int sys_rt_sigreturn(void) { - struct pt_regs *regs = current_thread_info()->regs; + struct pt_regs *regs = current_pt_regs(); struct rt_sigframe __user *frame; sigset_t blocked; diff --git a/arch/hexagon/kernel/syscall.c b/arch/hexagon/kernel/syscall.c deleted file mode 100644 index 319fa6494f5..00000000000 --- a/arch/hexagon/kernel/syscall.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Hexagon system calls - * - * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 and - * only version 2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#include <linux/file.h> -#include <linux/fs.h> -#include <linux/linkage.h> -#include <linux/mm.h> -#include <linux/module.h> -#include <linux/sched.h> -#include <linux/slab.h> -#include <linux/syscalls.h> -#include <linux/unistd.h> -#include <asm/mman.h> -#include <asm/registers.h> - -/* - * System calls with architecture-specific wrappers. - * See signal.c for signal-related system call wrappers. - */ - -asmlinkage int sys_execve(char __user *ufilename, - const char __user *const __user *argv, - const char __user *const __user *envp) -{ - struct pt_regs *pregs = current_thread_info()->regs; - struct filename *filename; - int retval; - - filename = getname(ufilename); - retval = PTR_ERR(filename); - if (IS_ERR(filename)) - return retval; - - retval = do_execve(filename->name, argv, envp, pregs); - putname(filename); - - return retval; -} - -asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp, - unsigned long parent_tidp, unsigned long child_tidp) -{ - struct pt_regs *pregs = current_thread_info()->regs; - - if (!newsp) - newsp = pregs->SP; - return do_fork(clone_flags, newsp, pregs, 0, (int __user *)parent_tidp, - (int __user *)child_tidp); -} - -/* - * Do a system call from the kernel, so as to have a proper pt_regs - * and recycle the sys_execvpe infrustructure. - */ -int kernel_execve(const char *filename, - const char *const argv[], const char *const envp[]) -{ - register unsigned long __a0 asm("r0") = (unsigned long) filename; - register unsigned long __a1 asm("r1") = (unsigned long) argv; - register unsigned long __a2 asm("r2") = (unsigned long) envp; - int retval; - - __asm__ volatile( - " R6 = #%4;\n" - " trap0(#1);\n" - " %0 = R0;\n" - : "=r" (retval) - : "r" (__a0), "r" (__a1), "r" (__a2), "i" (__NR_execve) - ); - - return retval; -} diff --git a/arch/hexagon/kernel/vm_entry.S b/arch/hexagon/kernel/vm_entry.S index cd71673ac25..425e50c694f 100644 --- a/arch/hexagon/kernel/vm_entry.S +++ b/arch/hexagon/kernel/vm_entry.S @@ -266,4 +266,8 @@ _K_enter_machcheck: .globl ret_from_fork ret_from_fork: call schedule_tail + P0 = cmp.eq(R24, #0); + if P0 jump return_from_syscall + R0 = R25; + callr R24 jump return_from_syscall |