aboutsummaryrefslogtreecommitdiffstats
path: root/arch/hexagon
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-12-12 15:22:13 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-12-12 15:22:13 -0500
commit9977d9b379cb77e0f67bd6f4563618106e58e11d (patch)
tree0191accfddf578edb52c69c933d64521e3dce297 /arch/hexagon
parentcf4af01221579a4e895f43dbfc47598fbfc5a731 (diff)
parent541880d9a2c7871f6370071d55aa6662d329c51e (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/Kconfig2
-rw-r--r--arch/hexagon/include/asm/processor.h1
-rw-r--r--arch/hexagon/include/asm/syscall.h8
-rw-r--r--arch/hexagon/include/uapi/asm/ptrace.h4
-rw-r--r--arch/hexagon/include/uapi/asm/unistd.h2
-rw-r--r--arch/hexagon/kernel/Makefile3
-rw-r--r--arch/hexagon/kernel/process.c100
-rw-r--r--arch/hexagon/kernel/signal.c4
-rw-r--r--arch/hexagon/kernel/syscall.c89
-rw-r--r--arch/hexagon/kernel/vm_entry.S4
10 files changed, 46 insertions, 171 deletions
diff --git a/arch/hexagon/Kconfig b/arch/hexagon/Kconfig
index 0744f7d7b1fd..e418803b6c8e 100644
--- a/arch/hexagon/Kconfig
+++ b/arch/hexagon/Kconfig
@@ -31,6 +31,8 @@ config HEXAGON
31 select GENERIC_CLOCKEVENTS 31 select GENERIC_CLOCKEVENTS
32 select GENERIC_CLOCKEVENTS_BROADCAST 32 select GENERIC_CLOCKEVENTS_BROADCAST
33 select MODULES_USE_ELF_RELA 33 select MODULES_USE_ELF_RELA
34 select GENERIC_KERNEL_THREAD
35 select GENERIC_KERNEL_EXECVE
34 ---help--- 36 ---help---
35 Qualcomm Hexagon is a processor architecture designed for high 37 Qualcomm Hexagon is a processor architecture designed for high
36 performance and low power across a wide variety of applications. 38 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 a03323ab9d44..6dd5d3706869 100644
--- a/arch/hexagon/include/asm/processor.h
+++ b/arch/hexagon/include/asm/processor.h
@@ -34,7 +34,6 @@
34struct task_struct; 34struct task_struct;
35 35
36/* this is defined in arch/process.c */ 36/* this is defined in arch/process.c */
37extern pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
38extern unsigned long thread_saved_pc(struct task_struct *tsk); 37extern unsigned long thread_saved_pc(struct task_struct *tsk);
39 38
40extern void start_thread(struct pt_regs *, unsigned long, unsigned long); 39extern 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 fb0e9d48faa6..4af9c7b6f13a 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,
25 unsigned long, unsigned long, 25 unsigned long, unsigned long,
26 unsigned long, unsigned long); 26 unsigned long, unsigned long);
27 27
28asmlinkage int sys_execve(char __user *ufilename, char __user * __user *argv,
29 char __user * __user *envp);
30asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
31 unsigned long parent_tidp, unsigned long child_tidp);
32
33#define sys_execve sys_execve
34#define sys_clone sys_clone
35
36#include <asm-generic/syscalls.h> 28#include <asm-generic/syscalls.h>
37 29
38extern void *sys_call_table[]; 30extern void *sys_call_table[];
diff --git a/arch/hexagon/include/uapi/asm/ptrace.h b/arch/hexagon/include/uapi/asm/ptrace.h
index 8ef784047a74..1ffce0c6ee07 100644
--- a/arch/hexagon/include/uapi/asm/ptrace.h
+++ b/arch/hexagon/include/uapi/asm/ptrace.h
@@ -32,4 +32,8 @@
32extern int regs_query_register_offset(const char *name); 32extern int regs_query_register_offset(const char *name);
33extern const char *regs_query_register_name(unsigned int offset); 33extern const char *regs_query_register_name(unsigned int offset);
34 34
35#define current_pt_regs() \
36 ((struct pt_regs *) \
37 ((unsigned long)current_thread_info() + THREAD_SIZE) - 1)
38
35#endif 39#endif
diff --git a/arch/hexagon/include/uapi/asm/unistd.h b/arch/hexagon/include/uapi/asm/unistd.h
index 81312d6a52e6..2af81533bd0f 100644
--- a/arch/hexagon/include/uapi/asm/unistd.h
+++ b/arch/hexagon/include/uapi/asm/unistd.h
@@ -27,5 +27,7 @@
27 */ 27 */
28 28
29#define sys_mmap2 sys_mmap_pgoff 29#define sys_mmap2 sys_mmap_pgoff
30#define __ARCH_WANT_SYS_EXECVE
31#define __ARCH_WANT_SYS_CLONE
30 32
31#include <asm-generic/unistd.h> 33#include <asm-generic/unistd.h>
diff --git a/arch/hexagon/kernel/Makefile b/arch/hexagon/kernel/Makefile
index 536aec093e62..6c19501b487c 100644
--- a/arch/hexagon/kernel/Makefile
+++ b/arch/hexagon/kernel/Makefile
@@ -3,8 +3,7 @@ extra-y := head.o vmlinux.lds
3obj-$(CONFIG_SMP) += smp.o topology.o 3obj-$(CONFIG_SMP) += smp.o topology.o
4 4
5obj-y += setup.o irq_cpu.o traps.o syscalltab.o signal.o time.o 5obj-y += setup.o irq_cpu.o traps.o syscalltab.o signal.o time.o
6obj-y += process.o syscall.o trampoline.o reset.o ptrace.o 6obj-y += process.o trampoline.o reset.o ptrace.o vdso.o
7obj-y += vdso.o
8 7
9obj-$(CONFIG_KGDB) += kgdb.o 8obj-$(CONFIG_KGDB) += kgdb.o
10obj-$(CONFIG_MODULES) += module.o hexagon_ksyms.o 9obj-$(CONFIG_MODULES) += module.o hexagon_ksyms.o
diff --git a/arch/hexagon/kernel/process.c b/arch/hexagon/kernel/process.c
index 9f6d7411b574..06ae9ffcabd5 100644
--- a/arch/hexagon/kernel/process.c
+++ b/arch/hexagon/kernel/process.c
@@ -26,33 +26,6 @@
26#include <linux/slab.h> 26#include <linux/slab.h>
27 27
28/* 28/*
29 * Kernel thread creation. The desired kernel function is "wrapped"
30 * in the kernel_thread_helper function, which does cleanup
31 * afterwards.
32 */
33static void __noreturn kernel_thread_helper(void *arg, int (*fn)(void *))
34{
35 do_exit(fn(arg));
36}
37
38int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
39{
40 struct pt_regs regs;
41
42 memset(&regs, 0, sizeof(regs));
43 /*
44 * Yes, we're exploting illicit knowledge of the ABI here.
45 */
46 regs.r00 = (unsigned long) arg;
47 regs.r01 = (unsigned long) fn;
48 pt_set_elr(&regs, (unsigned long)kernel_thread_helper);
49 pt_set_kmode(&regs);
50
51 return do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
52}
53EXPORT_SYMBOL(kernel_thread);
54
55/*
56 * Program thread launch. Often defined as a macro in processor.h, 29 * Program thread launch. Often defined as a macro in processor.h,
57 * but we're shooting for a small footprint and it's not an inner-loop 30 * but we're shooting for a small footprint and it's not an inner-loop
58 * performance-critical operation. 31 * performance-critical operation.
@@ -114,8 +87,7 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
114 * Copy architecture-specific thread state 87 * Copy architecture-specific thread state
115 */ 88 */
116int copy_thread(unsigned long clone_flags, unsigned long usp, 89int copy_thread(unsigned long clone_flags, unsigned long usp,
117 unsigned long unused, struct task_struct *p, 90 unsigned long arg, struct task_struct *p)
118 struct pt_regs *regs)
119{ 91{
120 struct thread_info *ti = task_thread_info(p); 92 struct thread_info *ti = task_thread_info(p);
121 struct hexagon_switch_stack *ss; 93 struct hexagon_switch_stack *ss;
@@ -125,61 +97,51 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
125 childregs = (struct pt_regs *) (((unsigned long) ti + THREAD_SIZE) - 97 childregs = (struct pt_regs *) (((unsigned long) ti + THREAD_SIZE) -
126 sizeof(*childregs)); 98 sizeof(*childregs));
127 99
128 memcpy(childregs, regs, sizeof(*childregs));
129 ti->regs = childregs; 100 ti->regs = childregs;
130 101
131 /* 102 /*
132 * Establish kernel stack pointer and initial PC for new thread 103 * Establish kernel stack pointer and initial PC for new thread
104 * Note that unlike the usual situation, we do not copy the
105 * parent's callee-saved here; those are in pt_regs and whatever
106 * we leave here will be overridden on return to userland.
133 */ 107 */
134 ss = (struct hexagon_switch_stack *) ((unsigned long) childregs - 108 ss = (struct hexagon_switch_stack *) ((unsigned long) childregs -
135 sizeof(*ss)); 109 sizeof(*ss));
136 ss->lr = (unsigned long)ret_from_fork; 110 ss->lr = (unsigned long)ret_from_fork;
137 p->thread.switch_sp = ss; 111 p->thread.switch_sp = ss;
112 if (unlikely(p->flags & PF_KTHREAD)) {
113 memset(childregs, 0, sizeof(struct pt_regs));
114 /* r24 <- fn, r25 <- arg */
115 ss->r2524 = usp | ((u64)arg << 32);
116 pt_set_kmode(childregs);
117 return 0;
118 }
119 memcpy(childregs, current_pt_regs(), sizeof(*childregs));
120 ss->r2524 = 0;
138 121
139 /* If User mode thread, set pt_reg stack pointer as per parameter */ 122 if (usp)
140 if (user_mode(childregs)) {
141 pt_set_rte_sp(childregs, usp); 123 pt_set_rte_sp(childregs, usp);
142 124
143 /* Child sees zero return value */ 125 /* Child sees zero return value */
144 childregs->r00 = 0; 126 childregs->r00 = 0;
145 127
146 /* 128 /*
147 * The clone syscall has the C signature: 129 * The clone syscall has the C signature:
148 * int [r0] clone(int flags [r0], 130 * int [r0] clone(int flags [r0],
149 * void *child_frame [r1], 131 * void *child_frame [r1],
150 * void *parent_tid [r2], 132 * void *parent_tid [r2],
151 * void *child_tid [r3], 133 * void *child_tid [r3],
152 * void *thread_control_block [r4]); 134 * void *thread_control_block [r4]);
153 * ugp is used to provide TLS support. 135 * ugp is used to provide TLS support.
154 */ 136 */
155 if (clone_flags & CLONE_SETTLS) 137 if (clone_flags & CLONE_SETTLS)
156 childregs->ugp = childregs->r04; 138 childregs->ugp = childregs->r04;
157
158 /*
159 * Parent sees new pid -- not necessary, not even possible at
160 * this point in the fork process
161 * Might also want to set things like ti->addr_limit
162 */
163 } else {
164 /*
165 * If kernel thread, resume stack is kernel stack base.
166 * Note that this is pointer arithmetic on pt_regs *
167 */
168 pt_set_rte_sp(childregs, (unsigned long)(childregs + 1));
169 /*
170 * We need the current thread_info fast path pointer
171 * set up in pt_regs. The register to be used is
172 * parametric for assembler code, but the mechanism
173 * doesn't drop neatly into C. Needs to be fixed.
174 */
175 childregs->THREADINFO_REG = (unsigned long) ti;
176 }
177 139
178 /* 140 /*
179 * thread_info pointer is pulled out of task_struct "stack" 141 * Parent sees new pid -- not necessary, not even possible at
180 * field on switch_to. 142 * this point in the fork process
143 * Might also want to set things like ti->addr_limit
181 */ 144 */
182 p->stack = (void *)ti;
183 145
184 return 0; 146 return 0;
185} 147}
diff --git a/arch/hexagon/kernel/signal.c b/arch/hexagon/kernel/signal.c
index 5047b8b879c0..fe0d1373165d 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)
249 */ 249 */
250asmlinkage int sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss) 250asmlinkage int sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss)
251{ 251{
252 struct pt_regs *regs = current_thread_info()->regs; 252 struct pt_regs *regs = current_pt_regs();
253 253
254 return do_sigaltstack(uss, uoss, regs->r29); 254 return do_sigaltstack(uss, uoss, regs->r29);
255} 255}
256 256
257asmlinkage int sys_rt_sigreturn(void) 257asmlinkage int sys_rt_sigreturn(void)
258{ 258{
259 struct pt_regs *regs = current_thread_info()->regs; 259 struct pt_regs *regs = current_pt_regs();
260 struct rt_sigframe __user *frame; 260 struct rt_sigframe __user *frame;
261 sigset_t blocked; 261 sigset_t blocked;
262 262
diff --git a/arch/hexagon/kernel/syscall.c b/arch/hexagon/kernel/syscall.c
deleted file mode 100644
index 319fa6494f58..000000000000
--- a/arch/hexagon/kernel/syscall.c
+++ /dev/null
@@ -1,89 +0,0 @@
1/*
2 * Hexagon system calls
3 *
4 * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 and
8 * only version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA.
19 */
20
21#include <linux/file.h>
22#include <linux/fs.h>
23#include <linux/linkage.h>
24#include <linux/mm.h>
25#include <linux/module.h>
26#include <linux/sched.h>
27#include <linux/slab.h>
28#include <linux/syscalls.h>
29#include <linux/unistd.h>
30#include <asm/mman.h>
31#include <asm/registers.h>
32
33/*
34 * System calls with architecture-specific wrappers.
35 * See signal.c for signal-related system call wrappers.
36 */
37
38asmlinkage int sys_execve(char __user *ufilename,
39 const char __user *const __user *argv,
40 const char __user *const __user *envp)
41{
42 struct pt_regs *pregs = current_thread_info()->regs;
43 struct filename *filename;
44 int retval;
45
46 filename = getname(ufilename);
47 retval = PTR_ERR(filename);
48 if (IS_ERR(filename))
49 return retval;
50
51 retval = do_execve(filename->name, argv, envp, pregs);
52 putname(filename);
53
54 return retval;
55}
56
57asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
58 unsigned long parent_tidp, unsigned long child_tidp)
59{
60 struct pt_regs *pregs = current_thread_info()->regs;
61
62 if (!newsp)
63 newsp = pregs->SP;
64 return do_fork(clone_flags, newsp, pregs, 0, (int __user *)parent_tidp,
65 (int __user *)child_tidp);
66}
67
68/*
69 * Do a system call from the kernel, so as to have a proper pt_regs
70 * and recycle the sys_execvpe infrustructure.
71 */
72int kernel_execve(const char *filename,
73 const char *const argv[], const char *const envp[])
74{
75 register unsigned long __a0 asm("r0") = (unsigned long) filename;
76 register unsigned long __a1 asm("r1") = (unsigned long) argv;
77 register unsigned long __a2 asm("r2") = (unsigned long) envp;
78 int retval;
79
80 __asm__ volatile(
81 " R6 = #%4;\n"
82 " trap0(#1);\n"
83 " %0 = R0;\n"
84 : "=r" (retval)
85 : "r" (__a0), "r" (__a1), "r" (__a2), "i" (__NR_execve)
86 );
87
88 return retval;
89}
diff --git a/arch/hexagon/kernel/vm_entry.S b/arch/hexagon/kernel/vm_entry.S
index cd71673ac259..425e50c694f7 100644
--- a/arch/hexagon/kernel/vm_entry.S
+++ b/arch/hexagon/kernel/vm_entry.S
@@ -266,4 +266,8 @@ _K_enter_machcheck:
266 .globl ret_from_fork 266 .globl ret_from_fork
267ret_from_fork: 267ret_from_fork:
268 call schedule_tail 268 call schedule_tail
269 P0 = cmp.eq(R24, #0);
270 if P0 jump return_from_syscall
271 R0 = R25;
272 callr R24
269 jump return_from_syscall 273 jump return_from_syscall