From 995218555433b260b58059802e1c01f35b4cd860 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Thu, 18 Oct 2012 22:45:24 -0400 Subject: hexagon: kernel_thread()/kernel_execve() conversion introduce sane current_pt_regs(), use it in syscalls where needed. Signed-off-by: Al Viro --- arch/hexagon/Kconfig | 2 + arch/hexagon/include/asm/processor.h | 1 - arch/hexagon/include/asm/ptrace.h | 4 ++ arch/hexagon/kernel/process.c | 102 +++++++++++------------------------ arch/hexagon/kernel/signal.c | 4 +- arch/hexagon/kernel/syscall.c | 27 +--------- arch/hexagon/kernel/vm_entry.S | 4 ++ 7 files changed, 46 insertions(+), 98 deletions(-) (limited to 'arch/hexagon') diff --git a/arch/hexagon/Kconfig b/arch/hexagon/Kconfig index 0744f7d..e418803 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 e8ea459..8483b49 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/ptrace.h b/arch/hexagon/include/asm/ptrace.h index 3d2f607..7e1e374 100644 --- a/arch/hexagon/include/asm/ptrace.h +++ b/arch/hexagon/include/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/kernel/process.c b/arch/hexagon/kernel/process.c index af51de6..8a016f7 100644 --- a/arch/hexagon/kernel/process.c +++ b/arch/hexagon/kernel/process.c @@ -26,33 +26,6 @@ #include /* - * 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,7 +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, + unsigned long arg, struct task_struct *p, struct pt_regs *regs) { struct thread_info *ti = task_thread_info(p); @@ -125,61 +98,50 @@ 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 User mode thread, set pt_reg stack pointer as per parameter */ - if (user_mode(childregs)) { - 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; + 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, regs, sizeof(*childregs)); + ss->r2524 = 0; + + 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; /* - * 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 1ea16be..28b9e26 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 index 25a9bfe..120f1a5 100644 --- a/arch/hexagon/kernel/syscall.c +++ b/arch/hexagon/kernel/syscall.c @@ -39,7 +39,7 @@ 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 pt_regs *pregs = current_pt_regs(); struct filename *filename; int retval; @@ -57,33 +57,10 @@ asmlinkage int sys_execve(char __user *ufilename, 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; + struct pt_regs *pregs = current_pt_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 5b99066..1a7fcf5 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 -- cgit v1.1 From 27aedbd52fb78bbead55c81a8dd906afd405c3fc Mon Sep 17 00:00:00 2001 From: Al Viro Date: Thu, 18 Oct 2012 22:48:18 -0400 Subject: hexagon: switch to generic sys_execve() Signed-off-by: Al Viro --- arch/hexagon/include/asm/unistd.h | 1 + arch/hexagon/kernel/syscall.c | 19 ------------------- 2 files changed, 1 insertion(+), 19 deletions(-) (limited to 'arch/hexagon') diff --git a/arch/hexagon/include/asm/unistd.h b/arch/hexagon/include/asm/unistd.h index c0d5565..acbd5ad 100644 --- a/arch/hexagon/include/asm/unistd.h +++ b/arch/hexagon/include/asm/unistd.h @@ -27,5 +27,6 @@ */ #define sys_mmap2 sys_mmap_pgoff +#define __ARCH_WANT_SYS_EXECVE #include diff --git a/arch/hexagon/kernel/syscall.c b/arch/hexagon/kernel/syscall.c index 120f1a5..e28f4e5 100644 --- a/arch/hexagon/kernel/syscall.c +++ b/arch/hexagon/kernel/syscall.c @@ -35,25 +35,6 @@ * 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_pt_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) { -- cgit v1.1 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/hexagon/include/asm/syscall.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'arch/hexagon') diff --git a/arch/hexagon/include/asm/syscall.h b/arch/hexagon/include/asm/syscall.h index fb0e9d4..ec2ce67 100644 --- a/arch/hexagon/include/asm/syscall.h +++ b/arch/hexagon/include/asm/syscall.h @@ -25,12 +25,9 @@ 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 -- cgit v1.1 From f01aceac61ad5cc9ea463f6bb185c1f72702357f Mon Sep 17 00:00:00 2001 From: Al Viro Date: Fri, 26 Oct 2012 19:25:46 -0400 Subject: hexagon: switch to generic clone() Signed-off-by: Al Viro --- arch/hexagon/include/uapi/asm/unistd.h | 1 + arch/hexagon/kernel/Makefile | 3 +-- arch/hexagon/kernel/process.c | 7 ++--- arch/hexagon/kernel/syscall.c | 47 ---------------------------------- 4 files changed, 6 insertions(+), 52 deletions(-) delete mode 100644 arch/hexagon/kernel/syscall.c (limited to 'arch/hexagon') diff --git a/arch/hexagon/include/uapi/asm/unistd.h b/arch/hexagon/include/uapi/asm/unistd.h index 26b2e0f..2af8153 100644 --- a/arch/hexagon/include/uapi/asm/unistd.h +++ b/arch/hexagon/include/uapi/asm/unistd.h @@ -28,5 +28,6 @@ #define sys_mmap2 sys_mmap_pgoff #define __ARCH_WANT_SYS_EXECVE +#define __ARCH_WANT_SYS_CLONE #include diff --git a/arch/hexagon/kernel/Makefile b/arch/hexagon/kernel/Makefile index 536aec0..6c19501 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 cfbc52b..36dce17 100644 --- a/arch/hexagon/kernel/process.c +++ b/arch/hexagon/kernel/process.c @@ -88,7 +88,7 @@ unsigned long thread_saved_pc(struct task_struct *tsk) */ int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg, struct task_struct *p, - struct pt_regs *regs) + struct pt_regs *unused) { struct thread_info *ti = task_thread_info(p); struct hexagon_switch_stack *ss; @@ -117,10 +117,11 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, pt_set_kmode(childregs); return 0; } - memcpy(childregs, regs, sizeof(*childregs)); + memcpy(childregs, current_pt_regs(), sizeof(*childregs)); ss->r2524 = 0; - pt_set_rte_sp(childregs, usp); + if (usp) + pt_set_rte_sp(childregs, usp); /* Child sees zero return value */ childregs->r00 = 0; diff --git a/arch/hexagon/kernel/syscall.c b/arch/hexagon/kernel/syscall.c deleted file mode 100644 index d2cc327..0000000 --- a/arch/hexagon/kernel/syscall.c +++ /dev/null @@ -1,47 +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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * System calls with architecture-specific wrappers. - * See signal.c for signal-related system call wrappers. - */ - -asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp, - unsigned long parent_tidp, unsigned long child_tidp) -{ - struct pt_regs *pregs = current_pt_regs(); - - if (!newsp) - newsp = pregs->SP; - return do_fork(clone_flags, newsp, pregs, 0, (int __user *)parent_tidp, - (int __user *)child_tidp); -} -- cgit v1.1 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/hexagon/include/asm/syscall.h | 5 ----- 1 file changed, 5 deletions(-) (limited to 'arch/hexagon') diff --git a/arch/hexagon/include/asm/syscall.h b/arch/hexagon/include/asm/syscall.h index ec2ce67..4af9c7b 100644 --- a/arch/hexagon/include/asm/syscall.h +++ b/arch/hexagon/include/asm/syscall.h @@ -25,11 +25,6 @@ typedef long (*syscall_fn)(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); -asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp, - unsigned long parent_tidp, unsigned long child_tidp); - -#define sys_clone sys_clone - #include extern void *sys_call_table[]; -- cgit v1.1 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/hexagon/kernel/process.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'arch/hexagon') diff --git a/arch/hexagon/kernel/process.c b/arch/hexagon/kernel/process.c index 36dce17..06ae9ff 100644 --- a/arch/hexagon/kernel/process.c +++ b/arch/hexagon/kernel/process.c @@ -87,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 arg, struct task_struct *p, - struct pt_regs *unused) + unsigned long arg, struct task_struct *p) { struct thread_info *ti = task_thread_info(p); struct hexagon_switch_stack *ss; -- cgit v1.1