diff options
author | Bodo Stroesser <bstroesser@fujitsu-siemens.com> | 2005-07-07 20:56:50 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-07-07 21:23:44 -0400 |
commit | 9786a8f3cbc61f990266e23ffdb338ee3118b03d (patch) | |
tree | c987811d30508728f954cc8aaa14de1f7fa5b44a /arch/um/kernel | |
parent | d67b569f5f620c0fb95d5212642746b7ba9d29e4 (diff) |
[PATCH] uml: Proper clone support for skas0
This patch implements the clone-stub mechanism, which allows skas0 to run
with proc_mm==0, even if the clib in UML uses modify_ldt.
Note: There is a bug in skas3.v7 host patch, that avoids UML-skas from
running properly on a SMP-box. In full skas3, I never really saw problems,
but in skas0 they showed up.
More commentary by jdike - What this patch does is makes sure that the host
parent of each new host process matches the UML parent of the corresponding
UML process. This ensures that any changed LDTs are inherited. This is
done by having clone actually called by the UML process from its stub,
rather than by the kernel. We have special syscall stubs that are loaded
onto the stub code page because that code must be completely
self-contained. These stubs are given C interfaces, and used like normal C
functions, but there are subtleties. Principally, we have to be careful
about stack variables in stub_clone_handler after the clone. The code is
written so that there aren't any - everything boils down to a fixed
address. If there were any locals, references to them after the clone
would be wrong because the stack just changed.
Signed-off-by: Bodo Stroesser <bstroesser@fujitsu-siemens.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/um/kernel')
-rw-r--r-- | arch/um/kernel/skas/Makefile | 7 | ||||
-rw-r--r-- | arch/um/kernel/skas/clone.c | 44 | ||||
-rw-r--r-- | arch/um/kernel/skas/include/skas.h | 1 | ||||
-rw-r--r-- | arch/um/kernel/skas/include/stub-data.h | 18 | ||||
-rw-r--r-- | arch/um/kernel/skas/mmu.c | 7 | ||||
-rw-r--r-- | arch/um/kernel/skas/process.c | 63 | ||||
-rw-r--r-- | arch/um/kernel/time.c | 7 |
7 files changed, 144 insertions, 3 deletions
diff --git a/arch/um/kernel/skas/Makefile b/arch/um/kernel/skas/Makefile index ff69c4b312c0..d296d55ade4b 100644 --- a/arch/um/kernel/skas/Makefile +++ b/arch/um/kernel/skas/Makefile | |||
@@ -3,11 +3,14 @@ | |||
3 | # Licensed under the GPL | 3 | # Licensed under the GPL |
4 | # | 4 | # |
5 | 5 | ||
6 | obj-y := exec_kern.o mem.o mem_user.o mmu.o process.o process_kern.o \ | 6 | obj-y := clone.o exec_kern.o mem.o mem_user.o mmu.o process.o process_kern.o \ |
7 | syscall_kern.o syscall_user.o tlb.o trap_user.o uaccess.o \ | 7 | syscall_kern.o syscall_user.o tlb.o trap_user.o uaccess.o \ |
8 | 8 | ||
9 | subdir- := util | 9 | subdir- := util |
10 | 10 | ||
11 | USER_OBJS := process.o | 11 | USER_OBJS := process.o clone.o |
12 | 12 | ||
13 | include arch/um/scripts/Makefile.rules | 13 | include arch/um/scripts/Makefile.rules |
14 | |||
15 | # clone.o is in the stub, so it can't be built with profiling | ||
16 | $(obj)/clone.o : c_flags = -Wp,-MD,$(depfile) $(call unprofile,$(USER_CFLAGS)) | ||
diff --git a/arch/um/kernel/skas/clone.c b/arch/um/kernel/skas/clone.c new file mode 100644 index 000000000000..4dc55f10cd18 --- /dev/null +++ b/arch/um/kernel/skas/clone.c | |||
@@ -0,0 +1,44 @@ | |||
1 | #include <sched.h> | ||
2 | #include <signal.h> | ||
3 | #include <sys/mman.h> | ||
4 | #include <sys/time.h> | ||
5 | #include <asm/unistd.h> | ||
6 | #include <asm/page.h> | ||
7 | #include "ptrace_user.h" | ||
8 | #include "skas.h" | ||
9 | #include "stub-data.h" | ||
10 | #include "uml-config.h" | ||
11 | #include "sysdep/stub.h" | ||
12 | |||
13 | /* This is in a separate file because it needs to be compiled with any | ||
14 | * extraneous gcc flags (-pg, -fprofile-arcs, -ftest-coverage) disabled | ||
15 | */ | ||
16 | void __attribute__ ((__section__ (".__syscall_stub"))) | ||
17 | stub_clone_handler(void) | ||
18 | { | ||
19 | long err; | ||
20 | struct stub_data *from = (struct stub_data *) UML_CONFIG_STUB_DATA; | ||
21 | |||
22 | err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | SIGCHLD, | ||
23 | UML_CONFIG_STUB_DATA + PAGE_SIZE / 2 - | ||
24 | sizeof(void *)); | ||
25 | if(err != 0) | ||
26 | goto out; | ||
27 | |||
28 | err = stub_syscall4(__NR_ptrace, PTRACE_TRACEME, 0, 0, 0); | ||
29 | if(err) | ||
30 | goto out; | ||
31 | |||
32 | err = stub_syscall3(__NR_setitimer, ITIMER_VIRTUAL, | ||
33 | (long) &from->timer, 0); | ||
34 | if(err) | ||
35 | goto out; | ||
36 | |||
37 | err = stub_syscall6(STUB_MMAP_NR, UML_CONFIG_STUB_DATA, PAGE_SIZE, | ||
38 | PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, | ||
39 | from->fd, from->offset); | ||
40 | out: | ||
41 | /* save current result. Parent: pid; child: retcode of mmap */ | ||
42 | from->err = err; | ||
43 | trap_myself(); | ||
44 | } | ||
diff --git a/arch/um/kernel/skas/include/skas.h b/arch/um/kernel/skas/include/skas.h index d91a60f3830a..d983ea842547 100644 --- a/arch/um/kernel/skas/include/skas.h +++ b/arch/um/kernel/skas/include/skas.h | |||
@@ -32,6 +32,7 @@ extern int protect(struct mm_id * mm_idp, unsigned long addr, | |||
32 | extern void user_signal(int sig, union uml_pt_regs *regs, int pid); | 32 | extern void user_signal(int sig, union uml_pt_regs *regs, int pid); |
33 | extern int new_mm(int from); | 33 | extern int new_mm(int from); |
34 | extern int start_userspace(unsigned long stub_stack); | 34 | extern int start_userspace(unsigned long stub_stack); |
35 | extern int copy_context_skas0(unsigned long stack, int pid); | ||
35 | extern void get_skas_faultinfo(int pid, struct faultinfo * fi); | 36 | extern void get_skas_faultinfo(int pid, struct faultinfo * fi); |
36 | extern long execute_syscall_skas(void *r); | 37 | extern long execute_syscall_skas(void *r); |
37 | extern unsigned long current_stub_stack(void); | 38 | extern unsigned long current_stub_stack(void); |
diff --git a/arch/um/kernel/skas/include/stub-data.h b/arch/um/kernel/skas/include/stub-data.h new file mode 100644 index 000000000000..f6ed92c3727d --- /dev/null +++ b/arch/um/kernel/skas/include/stub-data.h | |||
@@ -0,0 +1,18 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2005 Jeff Dike (jdike@karaya.com) | ||
3 | * Licensed under the GPL | ||
4 | */ | ||
5 | |||
6 | #ifndef __STUB_DATA_H | ||
7 | #define __STUB_DATA_H | ||
8 | |||
9 | #include <sys/time.h> | ||
10 | |||
11 | struct stub_data { | ||
12 | long offset; | ||
13 | int fd; | ||
14 | struct itimerval timer; | ||
15 | long err; | ||
16 | }; | ||
17 | |||
18 | #endif | ||
diff --git a/arch/um/kernel/skas/mmu.c b/arch/um/kernel/skas/mmu.c index 511a855c9ec0..d232daa42c31 100644 --- a/arch/um/kernel/skas/mmu.c +++ b/arch/um/kernel/skas/mmu.c | |||
@@ -75,6 +75,7 @@ static int init_stub_pte(struct mm_struct *mm, unsigned long proc, | |||
75 | int init_new_context_skas(struct task_struct *task, struct mm_struct *mm) | 75 | int init_new_context_skas(struct task_struct *task, struct mm_struct *mm) |
76 | { | 76 | { |
77 | struct mm_struct *cur_mm = current->mm; | 77 | struct mm_struct *cur_mm = current->mm; |
78 | struct mm_id *cur_mm_id = &cur_mm->context.skas.id; | ||
78 | struct mm_id *mm_id = &mm->context.skas.id; | 79 | struct mm_id *mm_id = &mm->context.skas.id; |
79 | unsigned long stack; | 80 | unsigned long stack; |
80 | int from, ret; | 81 | int from, ret; |
@@ -115,7 +116,11 @@ int init_new_context_skas(struct task_struct *task, struct mm_struct *mm) | |||
115 | goto out_free; | 116 | goto out_free; |
116 | 117 | ||
117 | mm->nr_ptes--; | 118 | mm->nr_ptes--; |
118 | mm_id->u.pid = start_userspace(stack); | 119 | |
120 | if((cur_mm != NULL) && (cur_mm != &init_mm)) | ||
121 | mm_id->u.pid = copy_context_skas0(stack, | ||
122 | cur_mm_id->u.pid); | ||
123 | else mm_id->u.pid = start_userspace(stack); | ||
119 | } | 124 | } |
120 | 125 | ||
121 | return 0; | 126 | return 0; |
diff --git a/arch/um/kernel/skas/process.c b/arch/um/kernel/skas/process.c index 1647abb0d1aa..ba671dab8878 100644 --- a/arch/um/kernel/skas/process.c +++ b/arch/um/kernel/skas/process.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <sys/wait.h> | 13 | #include <sys/wait.h> |
14 | #include <sys/mman.h> | 14 | #include <sys/mman.h> |
15 | #include <sys/user.h> | 15 | #include <sys/user.h> |
16 | #include <sys/time.h> | ||
16 | #include <asm/unistd.h> | 17 | #include <asm/unistd.h> |
17 | #include <asm/types.h> | 18 | #include <asm/types.h> |
18 | #include "user.h" | 19 | #include "user.h" |
@@ -22,6 +23,7 @@ | |||
22 | #include "user_util.h" | 23 | #include "user_util.h" |
23 | #include "kern_util.h" | 24 | #include "kern_util.h" |
24 | #include "skas.h" | 25 | #include "skas.h" |
26 | #include "stub-data.h" | ||
25 | #include "mm_id.h" | 27 | #include "mm_id.h" |
26 | #include "sysdep/sigcontext.h" | 28 | #include "sysdep/sigcontext.h" |
27 | #include "sysdep/stub.h" | 29 | #include "sysdep/stub.h" |
@@ -296,6 +298,67 @@ void userspace(union uml_pt_regs *regs) | |||
296 | #define INIT_JMP_HALT 3 | 298 | #define INIT_JMP_HALT 3 |
297 | #define INIT_JMP_REBOOT 4 | 299 | #define INIT_JMP_REBOOT 4 |
298 | 300 | ||
301 | |||
302 | int copy_context_skas0(unsigned long new_stack, int pid) | ||
303 | { | ||
304 | int err; | ||
305 | unsigned long regs[MAX_REG_NR]; | ||
306 | unsigned long current_stack = current_stub_stack(); | ||
307 | struct stub_data *data = (struct stub_data *) current_stack; | ||
308 | struct stub_data *child_data = (struct stub_data *) new_stack; | ||
309 | __u64 new_offset; | ||
310 | int new_fd = phys_mapping(to_phys((void *)new_stack), &new_offset); | ||
311 | |||
312 | /* prepare offset and fd of child's stack as argument for parent's | ||
313 | * and child's mmap2 calls | ||
314 | */ | ||
315 | *data = ((struct stub_data) { .offset = MMAP_OFFSET(new_offset), | ||
316 | .fd = new_fd, | ||
317 | .timer = ((struct itimerval) | ||
318 | { { 0, 1000000 / hz() }, | ||
319 | { 0, 1000000 / hz() }})}); | ||
320 | get_safe_registers(regs); | ||
321 | |||
322 | /* Set parent's instruction pointer to start of clone-stub */ | ||
323 | regs[REGS_IP_INDEX] = UML_CONFIG_STUB_CODE + | ||
324 | (unsigned long) stub_clone_handler - | ||
325 | (unsigned long) &__syscall_stub_start; | ||
326 | regs[REGS_SP_INDEX] = UML_CONFIG_STUB_DATA + PAGE_SIZE - | ||
327 | sizeof(void *); | ||
328 | err = ptrace_setregs(pid, regs); | ||
329 | if(err < 0) | ||
330 | panic("copy_context_skas0 : PTRACE_SETREGS failed, " | ||
331 | "pid = %d, errno = %d\n", pid, errno); | ||
332 | |||
333 | /* set a well known return code for detection of child write failure */ | ||
334 | child_data->err = 12345678; | ||
335 | |||
336 | /* Wait, until parent has finished its work: read child's pid from | ||
337 | * parent's stack, and check, if bad result. | ||
338 | */ | ||
339 | wait_stub_done(pid, 0, "copy_context_skas0"); | ||
340 | |||
341 | pid = data->err; | ||
342 | if(pid < 0) | ||
343 | panic("copy_context_skas0 - stub-parent reports error %d\n", | ||
344 | pid); | ||
345 | |||
346 | /* Wait, until child has finished too: read child's result from | ||
347 | * child's stack and check it. | ||
348 | */ | ||
349 | wait_stub_done(pid, -1, "copy_context_skas0"); | ||
350 | if (child_data->err != UML_CONFIG_STUB_DATA) | ||
351 | panic("copy_context_skas0 - stub-child reports error %d\n", | ||
352 | child_data->err); | ||
353 | |||
354 | if (ptrace(PTRACE_OLDSETOPTIONS, pid, NULL, | ||
355 | (void *)PTRACE_O_TRACESYSGOOD) < 0) | ||
356 | panic("copy_context_skas0 : PTRACE_SETOPTIONS failed, " | ||
357 | "errno = %d\n", errno); | ||
358 | |||
359 | return pid; | ||
360 | } | ||
361 | |||
299 | void new_thread(void *stack, void **switch_buf_ptr, void **fork_buf_ptr, | 362 | void new_thread(void *stack, void **switch_buf_ptr, void **fork_buf_ptr, |
300 | void (*handler)(int)) | 363 | void (*handler)(int)) |
301 | { | 364 | { |
diff --git a/arch/um/kernel/time.c b/arch/um/kernel/time.c index f829b309b63c..c40b611e3d93 100644 --- a/arch/um/kernel/time.c +++ b/arch/um/kernel/time.c | |||
@@ -48,6 +48,13 @@ void enable_timer(void) | |||
48 | set_interval(ITIMER_VIRTUAL); | 48 | set_interval(ITIMER_VIRTUAL); |
49 | } | 49 | } |
50 | 50 | ||
51 | void prepare_timer(void * ptr) | ||
52 | { | ||
53 | int usec = 1000000/hz(); | ||
54 | *(struct itimerval *)ptr = ((struct itimerval) { { 0, usec }, | ||
55 | { 0, usec }}); | ||
56 | } | ||
57 | |||
51 | void disable_timer(void) | 58 | void disable_timer(void) |
52 | { | 59 | { |
53 | struct itimerval disable = ((struct itimerval) { { 0, 0 }, { 0, 0 }}); | 60 | struct itimerval disable = ((struct itimerval) { { 0, 0 }, { 0, 0 }}); |