From 11100b1dfb6e9444d54d38e822753f59ee42a7e6 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Sun, 6 May 2007 14:50:57 -0700 Subject: uml: delete unused code Get rid of a bunch of unused stuff - cpu_feature had no users linux_prog is little-used, so its declaration is moved to the user for easy deletion when the whole file goes away a long-unused debugging aid in helper.c is gone Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/kern_util.h | 1 - arch/um/include/user_util.h | 1 - 2 files changed, 2 deletions(-) (limited to 'arch/um/include') diff --git a/arch/um/include/kern_util.h b/arch/um/include/kern_util.h index 173af029d12..be850b9ec94 100644 --- a/arch/um/include/kern_util.h +++ b/arch/um/include/kern_util.h @@ -23,7 +23,6 @@ struct kern_handlers { extern const struct kern_handlers handlinfo_kern; extern int ncpus; -extern char *linux_prog; extern char *gdb_init; extern int kmalloc_ok; extern int jail; diff --git a/arch/um/include/user_util.h b/arch/um/include/user_util.h index 023575f6734..99492d5c82d 100644 --- a/arch/um/include/user_util.h +++ b/arch/um/include/user_util.h @@ -60,7 +60,6 @@ extern void kill_child_dead(int pid); extern int cont(int pid); extern void check_sigio(void); extern void arch_check_bugs(void); -extern int cpu_feature(char *what, char *buf, int len); extern int arch_handle_signal(int sig, union uml_pt_regs *regs); extern int arch_fixup(unsigned long address, void *sc_ptr); extern void arch_init_thread(void); -- cgit v1.2.3 From b4ffb6ad8d8477b561377ca150bbbfc0db02da54 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Sun, 6 May 2007 14:50:59 -0700 Subject: uml: host_info tidying Move the host_info string from util.c to um_arch.c, where it is actually initialized and used. Also document its lack of locking. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/os.h | 2 +- arch/um/include/user_util.h | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'arch/um/include') diff --git a/arch/um/include/os.h b/arch/um/include/os.h index 5c74da41045..22666b4a8be 100644 --- a/arch/um/include/os.h +++ b/arch/um/include/os.h @@ -273,7 +273,7 @@ extern void stack_protections(unsigned long address); extern void task_protections(unsigned long address); extern int raw(int fd); extern void setup_machinename(char *machine_out); -extern void setup_hostinfo(void); +extern void setup_hostinfo(char *buf, int len); extern int setjmp_wrapper(void (*proc)(void *, void *), ...); /* time.c */ diff --git a/arch/um/include/user_util.h b/arch/um/include/user_util.h index 99492d5c82d..73ffea1829f 100644 --- a/arch/um/include/user_util.h +++ b/arch/um/include/user_util.h @@ -36,8 +36,6 @@ extern unsigned long end_vm; extern unsigned long start_vm; extern unsigned long long highmem; -extern char host_info[]; - extern unsigned long _stext, _etext, _sdata, _edata, __bss_start, _end; extern unsigned long _unprotected_end; extern unsigned long brk_start; -- cgit v1.2.3 From f34d9d2dcb7f17b64124841345b23adc0843e7a5 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Sun, 6 May 2007 14:51:04 -0700 Subject: uml: network interface hotplug error handling This fixes a number of problems associated with network interface hotplug. The userspace initialization function can fail in some cases, but the failure was never passed back to eth_configure, which proceeded with the configuration. This results in a zombie device that is present, but can't work. This is fixed by allowing the initialization routines to return an error, which is checked, and the configuration aborted on failure. eth_configure failed to check for many failures. Even when it did check, it didn't undo whatever initializations has already happened, so a present, but partially initialized and non-working device could result. It now checks everything that can fail, and bails out, undoing whatever had been done. The return value of eth_configure was always ignored, so it is now just void. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Cc: Jeff Garzik Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/net_user.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch/um/include') diff --git a/arch/um/include/net_user.h b/arch/um/include/net_user.h index 19f207cd70f..cfe7c50634b 100644 --- a/arch/um/include/net_user.h +++ b/arch/um/include/net_user.h @@ -14,7 +14,7 @@ #define UML_NET_VERSION (4) struct net_user_info { - void (*init)(void *, void *); + int (*init)(void *, void *); int (*open)(void *); void (*close)(int, void *); void (*remove)(void *); -- cgit v1.2.3 From c5e631cf65f4d6875efcd571275436f2964a8b48 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 6 May 2007 14:51:05 -0700 Subject: ARRAY_SIZE: check for type We can use a gcc extension to ensure that ARRAY_SIZE() is handed an array, not a pointer. This is especially important when code is changed from a fixed array to a pointer. I assume the Intel compiler doesn't support __builtin_types_compatible_p. [jdike@addtoit.com: uml: update UML definition of ARRAY_SIZE] Signed-off-by: Rusty Russell Signed-off-by: Jeff Dike Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/user_util.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'arch/um/include') diff --git a/arch/um/include/user_util.h b/arch/um/include/user_util.h index 73ffea1829f..b52bc408483 100644 --- a/arch/um/include/user_util.h +++ b/arch/um/include/user_util.h @@ -8,8 +8,19 @@ #include "sysdep/ptrace.h" -/* Copied from kernel.h */ -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +/* Copied from kernel.h and compiler-gcc.h */ + +/* Force a compilation error if condition is true, but also produce a + result (of value 0 and type size_t), so the expression can be used + e.g. in a structure initializer (or where-ever else comma expressions + aren't permitted). */ +#define BUILD_BUG_ON_ZERO(e) (sizeof(char[1 - 2 * !!(e)]) - 1) + +/* &a[0] degrades to a pointer: a different type from an array */ +#define __must_be_array(a) \ + BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0]))) + +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) #define CATCH_EINTR(expr) while ((errno = 0, ((expr) < 0)) && (errno == EINTR)) -- cgit v1.2.3 From c65badbdf5dc117e45873e760f807063ad59a854 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Sun, 6 May 2007 14:51:06 -0700 Subject: uml: move SIGIO testing to sigio.c This patch narrows the sigio interface. The boot-time SIGIO testing used to be in start_up.c, which meant that pty_output_sigio and pty_close_sigio needed to be global. By moving that code here, those can become static and the declarations moved from user_util.h. os_check_bugs is also here because it only does the SIGIO checking. If it does more, it'll probably move back to start_up.c. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/user_util.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'arch/um/include') diff --git a/arch/um/include/user_util.h b/arch/um/include/user_util.h index b52bc408483..df4869aa940 100644 --- a/arch/um/include/user_util.h +++ b/arch/um/include/user_util.h @@ -51,9 +51,6 @@ extern unsigned long _stext, _etext, _sdata, _edata, __bss_start, _end; extern unsigned long _unprotected_end; extern unsigned long brk_start; -extern int pty_output_sigio; -extern int pty_close_sigio; - extern void *add_signal_handler(int sig, void (*handler)(int)); extern int linux_main(int argc, char **argv); extern void set_cmdline(char *cmd); -- cgit v1.2.3 From eb8307595baa729a12db0fec9a80910b13bd6fc8 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Sun, 6 May 2007 14:51:07 -0700 Subject: uml: create arch.h This patch moves the declarations of the architecture hooks from user_util.h to a new header, arch.c, and adds the necessary includes to files which need those declarations. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/arch.h | 15 +++++++++++++++ arch/um/include/user_util.h | 4 ---- 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 arch/um/include/arch.h (limited to 'arch/um/include') diff --git a/arch/um/include/arch.h b/arch/um/include/arch.h new file mode 100644 index 00000000000..8e11dd7c1ad --- /dev/null +++ b/arch/um/include/arch.h @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) + * Licensed under the GPL + */ + +#ifndef __ARCH_H__ +#define __ARCH_H__ + +#include "sysdep/ptrace.h" + +extern void arch_check_bugs(void); +extern int arch_fixup(unsigned long address, void *sc_ptr); +extern int arch_handle_signal(int sig, union uml_pt_regs *regs); + +#endif diff --git a/arch/um/include/user_util.h b/arch/um/include/user_util.h index df4869aa940..fabad2372af 100644 --- a/arch/um/include/user_util.h +++ b/arch/um/include/user_util.h @@ -65,10 +65,6 @@ extern int attach(int pid); extern void kill_child_dead(int pid); extern int cont(int pid); extern void check_sigio(void); -extern void arch_check_bugs(void); -extern int arch_handle_signal(int sig, union uml_pt_regs *regs); -extern int arch_fixup(unsigned long address, void *sc_ptr); -extern void arch_init_thread(void); extern int raw(int fd); #endif -- cgit v1.2.3 From 4ff83ce1114827f707b7f1f4f2e5f69de9df94ac Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Sun, 6 May 2007 14:51:08 -0700 Subject: uml: create as-layout.h This patch moves all the the symbols defined in um_arch.c, which are mostly boundaries between different parts of the UML kernel address space, to a new header, as-layout.h. There are also a few things here which aren't really related to address space layout, but which don't really have a better place to go. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/as-layout.h | 35 +++++++++++++++++++++++++++++++++++ arch/um/include/user_util.h | 23 ----------------------- 2 files changed, 35 insertions(+), 23 deletions(-) create mode 100644 arch/um/include/as-layout.h (limited to 'arch/um/include') diff --git a/arch/um/include/as-layout.h b/arch/um/include/as-layout.h new file mode 100644 index 00000000000..fccf187bf4e --- /dev/null +++ b/arch/um/include/as-layout.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) + * Licensed under the GPL + */ + +#ifndef __START_H__ +#define __START_H__ + +#include "sysdep/ptrace.h" + +struct cpu_task { + int pid; + void *task; +}; + +extern struct cpu_task cpu_tasks[]; + +extern unsigned long low_physmem; +extern unsigned long high_physmem; +extern unsigned long uml_physmem; +extern unsigned long uml_reserved; +extern unsigned long end_vm; +extern unsigned long start_vm; +extern unsigned long long highmem; + +extern unsigned long _stext, _etext, _sdata, _edata, __bss_start, _end; +extern unsigned long _unprotected_end; +extern unsigned long brk_start; + +extern int linux_main(int argc, char **argv); +extern void set_cmdline(char *cmd); + +extern void (*sig_info[])(int, union uml_pt_regs *); + +#endif diff --git a/arch/um/include/user_util.h b/arch/um/include/user_util.h index fabad2372af..f04776e2436 100644 --- a/arch/um/include/user_util.h +++ b/arch/um/include/user_util.h @@ -30,30 +30,7 @@ extern int grantpt(int __fd); extern int unlockpt(int __fd); extern char *ptsname(int __fd); -struct cpu_task { - int pid; - void *task; -}; - -extern struct cpu_task cpu_tasks[]; - -extern void (*sig_info[])(int, union uml_pt_regs *); - -extern unsigned long low_physmem; -extern unsigned long high_physmem; -extern unsigned long uml_physmem; -extern unsigned long uml_reserved; -extern unsigned long end_vm; -extern unsigned long start_vm; -extern unsigned long long highmem; - -extern unsigned long _stext, _etext, _sdata, _edata, __bss_start, _end; -extern unsigned long _unprotected_end; -extern unsigned long brk_start; - extern void *add_signal_handler(int sig, void (*handler)(int)); -extern int linux_main(int argc, char **argv); -extern void set_cmdline(char *cmd); extern void input_cb(void (*proc)(void *), void *arg, int arg_len); extern int get_pty(void); extern int switcheroo(int fd, int prot, void *from, void *to, int size); -- cgit v1.2.3 From 24fa6c0832f4513ac897082d7d803970a40cc1b0 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Sun, 6 May 2007 14:51:09 -0700 Subject: uml: move remaining useful contents of user_util.h Rescue the useful contents of the soon-to-be-gone user-util.h. pty.c now gets ptsname from stdlib.h like it should have always done. CATCH_EINTR is now in os.h, although perhaps all usage should be under os-Linux at some point. get_pty is also in os.h. This patch restores the old definition of ARRAY_SIZE in user.h. This file is included only in userspace files, so there will be no conflict with the kernel's new ARRAY_SIZE. The copy of the kernel's ARRAY_SIZE and associated infrastructure is now gone. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/os.h | 6 ++++++ arch/um/include/user.h | 19 ++++++++----------- arch/um/include/user_util.h | 18 ------------------ 3 files changed, 14 insertions(+), 29 deletions(-) (limited to 'arch/um/include') diff --git a/arch/um/include/os.h b/arch/um/include/os.h index 22666b4a8be..394adcded0b 100644 --- a/arch/um/include/os.h +++ b/arch/um/include/os.h @@ -16,6 +16,8 @@ #include "sysdep/tls.h" #include "sysdep/archsetjmp.h" +#define CATCH_EINTR(expr) while ((errno = 0, ((expr) < 0)) && (errno == EINTR)) + #define OS_TYPE_FILE 1 #define OS_TYPE_DIR 2 #define OS_TYPE_SYMLINK 3 @@ -341,6 +343,10 @@ extern void maybe_sigio_broken(int fd, int read); extern void sig_handler_common_skas(int sig, void *sc_ptr); extern void user_signal(int sig, union uml_pt_regs *regs, int pid); +/* sys-x86_64/prctl.c */ extern int os_arch_prctl(int pid, int code, unsigned long *addr); +/* tty.c */ +int get_pty(void); + #endif diff --git a/arch/um/include/user.h b/arch/um/include/user.h index acadce3f271..a6da6260825 100644 --- a/arch/um/include/user.h +++ b/arch/um/include/user.h @@ -6,6 +6,14 @@ #ifndef __USER_H__ #define __USER_H__ +/* + * The usual definition - copied here because the kernel provides its own, + * fancier, type-safe, definition. Using that one would require + * copying too much infrastructure for my taste, so userspace files + * get less checking than kernel files. + */ +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + extern void panic(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); extern int printk(const char *fmt, ...) @@ -18,14 +26,3 @@ extern unsigned long strlcpy(char *, const char *, unsigned long); extern unsigned long strlcat(char *, const char *, unsigned long); #endif - -/* - * Overrides for Emacs so that we follow Linus's tabbing style. - * Emacs will notice this stuff at the end of the file and automatically - * adjust the settings for this buffer only. This must remain at the end - * of the file. - * --------------------------------------------------------------------------- - * Local variables: - * c-file-style: "linux" - * End: - */ diff --git a/arch/um/include/user_util.h b/arch/um/include/user_util.h index f04776e2436..7fa5c68f062 100644 --- a/arch/um/include/user_util.h +++ b/arch/um/include/user_util.h @@ -8,31 +8,13 @@ #include "sysdep/ptrace.h" -/* Copied from kernel.h and compiler-gcc.h */ - -/* Force a compilation error if condition is true, but also produce a - result (of value 0 and type size_t), so the expression can be used - e.g. in a structure initializer (or where-ever else comma expressions - aren't permitted). */ -#define BUILD_BUG_ON_ZERO(e) (sizeof(char[1 - 2 * !!(e)]) - 1) - -/* &a[0] degrades to a pointer: a different type from an array */ -#define __must_be_array(a) \ - BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0]))) - -#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) - -#define CATCH_EINTR(expr) while ((errno = 0, ((expr) < 0)) && (errno == EINTR)) - extern int mode_tt; extern int grantpt(int __fd); extern int unlockpt(int __fd); -extern char *ptsname(int __fd); extern void *add_signal_handler(int sig, void (*handler)(int)); extern void input_cb(void (*proc)(void *), void *arg, int arg_len); -extern int get_pty(void); extern int switcheroo(int fd, int prot, void *from, void *to, int size); extern void do_exec(int old_pid, int new_pid); extern void tracer_panic(char *msg, ...) -- cgit v1.2.3 From 9218b1714949095bff9d9739d80f431d58e561d6 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Sun, 6 May 2007 14:51:10 -0700 Subject: uml: remove user_util.h user_util.h isn't needed any more, so delete it and remove all includes of it. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/user_util.h | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 arch/um/include/user_util.h (limited to 'arch/um/include') diff --git a/arch/um/include/user_util.h b/arch/um/include/user_util.h deleted file mode 100644 index 7fa5c68f062..00000000000 --- a/arch/um/include/user_util.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) - * Licensed under the GPL - */ - -#ifndef __USER_UTIL_H__ -#define __USER_UTIL_H__ - -#include "sysdep/ptrace.h" - -extern int mode_tt; - -extern int grantpt(int __fd); -extern int unlockpt(int __fd); - -extern void *add_signal_handler(int sig, void (*handler)(int)); -extern void input_cb(void (*proc)(void *), void *arg, int arg_len); -extern int switcheroo(int fd, int prot, void *from, void *to, int size); -extern void do_exec(int old_pid, int new_pid); -extern void tracer_panic(char *msg, ...) - __attribute__ ((format (printf, 1, 2))); -extern int detach(int pid, int sig); -extern int attach(int pid); -extern void kill_child_dead(int pid); -extern int cont(int pid); -extern void check_sigio(void); -extern int raw(int fd); - -#endif -- cgit v1.2.3 From c74c69b442364125fd13259ecaa4cd2ee43b9172 Mon Sep 17 00:00:00 2001 From: Paolo 'Blaisorblade' Giarrusso Date: Sun, 6 May 2007 14:51:15 -0700 Subject: uml: Replace one-element array with zero-element array To look at users I did: $ find arch/um/ include/asm-um -name '*.[ch]'|xargs grep -r 'net_kern\.h' +-l|xargs grep '\' Most users just cast user to the appropriate pointer, the remaining ones are fixed here. In net_kern.c, I'm almost sure that save trick is not needed anymore, but I've not verified it. Signed-off-by: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Jeff Dike Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/net_kern.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch/um/include') diff --git a/arch/um/include/net_kern.h b/arch/um/include/net_kern.h index 125ab42df18..9237056b910 100644 --- a/arch/um/include/net_kern.h +++ b/arch/um/include/net_kern.h @@ -40,7 +40,7 @@ struct uml_net_private { void (*add_address)(unsigned char *, unsigned char *, void *); void (*delete_address)(unsigned char *, unsigned char *, void *); int (*set_mtu)(int mtu, void *); - int user[1]; + char user[0]; }; struct net_kern_info { -- cgit v1.2.3 From 6e21aec3fcf6c8862b755d45c0af45acdefff976 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Sun, 6 May 2007 14:51:21 -0700 Subject: uml: tidy process.c Clean up arch/um/kernel/process.c: - lots of return(x); -> return x; conversions - a number of the small functions are either unused, in which case they are gone, along any declarations in a header, or could be made static. - current_pid is ifdefed on CONFIG_MODE_TT and its declaration is ifdefed on both CONFIG_MODE_TT and UML_CONFIG_MODE_TT because we don't know whether it's being used in a userspace or kernel file. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/kern_util.h | 7 +++---- arch/um/include/tt/uaccess-tt.h | 2 -- arch/um/include/um_malloc.h | 1 - 3 files changed, 3 insertions(+), 7 deletions(-) (limited to 'arch/um/include') diff --git a/arch/um/include/kern_util.h b/arch/um/include/kern_util.h index be850b9ec94..09810bc48e5 100644 --- a/arch/um/include/kern_util.h +++ b/arch/um/include/kern_util.h @@ -8,6 +8,7 @@ #include "sysdep/ptrace.h" #include "sysdep/faultinfo.h" +#include "uml-config.h" typedef void (*kern_hndl)(int, union uml_pt_regs *); @@ -33,7 +34,9 @@ extern int nsyscalls; UML_ROUND_DOWN(((unsigned long) addr) + PAGE_SIZE - 1) extern int kernel_fork(unsigned long flags, int (*fn)(void *), void * arg); +#ifdef UML_CONFIG_MODE_TT extern unsigned long stack_sp(unsigned long page); +#endif extern int kernel_thread_proc(void *data); extern void syscall_segv(int sig); extern int current_pid(void); @@ -57,7 +60,6 @@ extern void add_input_request(int op, void (*proc)(int), void *arg); extern char *current_cmd(void); extern void timer_handler(int sig, union uml_pt_regs *regs); extern int set_signals(int enable); -extern void force_sigbus(void); extern int pid_to_processor_id(int pid); extern void deliver_signals(void *t); extern int next_trap_index(int max); @@ -69,7 +71,6 @@ extern void *syscall_sp(void *t); extern void syscall_trace(union uml_pt_regs *regs, int entryexit); extern int hz(void); extern unsigned int do_IRQ(int irq, union uml_pt_regs *regs); -extern int external_pid(void *t); extern void interrupt_end(void); extern void initial_thread_cb(void (*proc)(void *), void *arg); extern int debugger_signal(int status, int pid); @@ -80,7 +81,6 @@ extern int init_parent_proxy(int pid); extern int singlestepping(void *t); extern void check_stack_overflow(void *ptr); extern void relay_signal(int sig, union uml_pt_regs *regs); -extern void not_implemented(void); extern int user_context(unsigned long sp); extern void timer_irq(union uml_pt_regs *regs); extern void unprotect_stack(unsigned long stack); @@ -92,7 +92,6 @@ extern char *uml_strdup(char *string); extern void unprotect_kernel_mem(void); extern void protect_kernel_mem(void); extern void uml_cleanup(void); -extern void set_current(void *t); extern void lock_signalled_task(void *t); extern void IPI_handler(int cpu); extern int jail_setup(char *line, int *add); diff --git a/arch/um/include/tt/uaccess-tt.h b/arch/um/include/tt/uaccess-tt.h index b19645f32f2..13a64f61fcf 100644 --- a/arch/um/include/tt/uaccess-tt.h +++ b/arch/um/include/tt/uaccess-tt.h @@ -27,8 +27,6 @@ extern unsigned long uml_physmem; #define access_ok_tt(type, addr, size) \ (is_stack(addr, size)) -extern unsigned long get_fault_addr(void); - extern int __do_copy_from_user(void *to, const void *from, int n, void **fault_addr, void **fault_catcher); extern int __do_strncpy_from_user(char *dst, const char *src, size_t n, diff --git a/arch/um/include/um_malloc.h b/arch/um/include/um_malloc.h index 0363a9b53f8..e6d7c5aa3f4 100644 --- a/arch/um/include/um_malloc.h +++ b/arch/um/include/um_malloc.h @@ -11,7 +11,6 @@ extern void *um_kmalloc_atomic(int size); extern void kfree(const void *ptr); extern void *um_vmalloc(int size); -extern void *um_vmalloc_atomic(int size); extern void vfree(void *ptr); #endif /* __UM_MALLOC_H__ */ -- cgit v1.2.3 From 1ffb9164f51094b7105ce9f81600b222ddf5b82c Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Sun, 6 May 2007 14:51:22 -0700 Subject: uml: remove page_size() userspace code used to have to call the kernelspace function page_size() in order to determine the value of the kernel's PAGE_SIZE. Since this is now available directly from kern_constants.h as UM_KERN_PAGE_SIZE, page_size() can be deleted and calls changed to use the constant. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/kern_util.h | 1 - 1 file changed, 1 deletion(-) (limited to 'arch/um/include') diff --git a/arch/um/include/kern_util.h b/arch/um/include/kern_util.h index 09810bc48e5..ae434a9b400 100644 --- a/arch/um/include/kern_util.h +++ b/arch/um/include/kern_util.h @@ -52,7 +52,6 @@ extern void set_tracing(void *t, int tracing); extern int is_tracing(void *task); extern int segv_syscall(void); extern void kern_finish_exec(void *task, int new_pid, unsigned long stack); -extern int page_size(void); extern unsigned long page_mask(void); extern int need_finish_fork(void); extern void free_stack(unsigned long stack, int order); -- cgit v1.2.3 From 5d86456d3852cb95a38d2b23fe01cede54984ba5 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Sun, 6 May 2007 14:51:24 -0700 Subject: uml: tidy fault code Tidying in preparation for the segfault register dumping patch which follows. void * pointers are changed to union uml_pt_regs *. This makes the types match reality, except in arch_fixup, which is changed to operate on a union uml_pt_regs. This fixes a bug in the call from segv_handler, which passes a union uml_pt_regs, to segv, which expects to pass a struct sigcontext to arch_fixup. Whitespace and other style fixes. There's also a errno printk fix. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/arch.h | 2 +- arch/um/include/kern_util.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'arch/um/include') diff --git a/arch/um/include/arch.h b/arch/um/include/arch.h index 8e11dd7c1ad..10ad52daa8c 100644 --- a/arch/um/include/arch.h +++ b/arch/um/include/arch.h @@ -9,7 +9,7 @@ #include "sysdep/ptrace.h" extern void arch_check_bugs(void); -extern int arch_fixup(unsigned long address, void *sc_ptr); +extern int arch_fixup(unsigned long address, union uml_pt_regs *regs); extern int arch_handle_signal(int sig, union uml_pt_regs *regs); #endif diff --git a/arch/um/include/kern_util.h b/arch/um/include/kern_util.h index ae434a9b400..092a2841556 100644 --- a/arch/um/include/kern_util.h +++ b/arch/um/include/kern_util.h @@ -44,7 +44,7 @@ extern unsigned long alloc_stack(int order, int atomic); extern int do_signal(void); extern int is_stack_fault(unsigned long sp); extern unsigned long segv(struct faultinfo fi, unsigned long ip, - int is_user, void *sc); + int is_user, union uml_pt_regs *regs); extern int handle_page_fault(unsigned long address, unsigned long ip, int is_write, int is_user, int *code_out); extern void syscall_ready(void); -- cgit v1.2.3 From 377fad3acbb7e94ab9942a74e0d9ede8eeb2f039 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Sun, 6 May 2007 14:51:25 -0700 Subject: uml: kernel segfaults should dump proper registers If there's a segfault inside the kernel, we want a dump of the registers at the point of the segfault, not the registers at the point of calling panic or the last userspace registers. sig_handler_common_skas now uses a static register set in the case of a SIGSEGV to avoid messing up the process registers if the segfault turns out to be non-fatal. The architecture sigcontext-to-pt_regs copying code was repurposed to copy data out of the SEGV stack frame. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/common-offsets.h | 2 ++ arch/um/include/kern_util.h | 2 ++ 2 files changed, 4 insertions(+) (limited to 'arch/um/include') diff --git a/arch/um/include/common-offsets.h b/arch/um/include/common-offsets.h index 461175f8b1d..5593a802708 100644 --- a/arch/um/include/common-offsets.h +++ b/arch/um/include/common-offsets.h @@ -24,5 +24,7 @@ DEFINE(UM_ELF_CLASS, ELF_CLASS); DEFINE(UM_ELFCLASS32, ELFCLASS32); DEFINE(UM_ELFCLASS64, ELFCLASS64); +DEFINE(UM_NR_CPUS, NR_CPUS); + /* For crypto assembler code. */ DEFINE(crypto_tfm_ctx_offset, offsetof(struct crypto_tfm, __crt_ctx)); diff --git a/arch/um/include/kern_util.h b/arch/um/include/kern_util.h index 092a2841556..50a49691e0e 100644 --- a/arch/um/include/kern_util.h +++ b/arch/um/include/kern_util.h @@ -115,4 +115,6 @@ extern void time_init_kern(void); extern int __cant_sleep(void); extern void sigio_handler(int sig, union uml_pt_regs *regs); +extern void copy_sc(union uml_pt_regs *regs, void *from); + #endif -- cgit v1.2.3 From 3d564047a5f45cb628ec72514f68076e532988f3 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Sun, 6 May 2007 14:51:32 -0700 Subject: uml: start fixing os_read_file and os_write_file This patch starts the removal of a very old, very broken piece of code. This stems from the problem of passing a userspace buffer into read() or write() on the host. If that buffer had not yet been faulted in, read and write will return -EFAULT. To avoid this problem, the solution was to fault the buffer in before the system call by touching the pages that hold the buffer by doing a copy-user of a byte to each page. This is obviously bogus, but it does usually work, in tt mode, since the kernel and process are in the same address space and userspace addresses can be accessed directly in the kernel. In skas mode, where the kernel and process are in separate address spaces, it is completely bogus because the userspace address, which is invalid in the kernel, is passed into the system call instead of the corresponding physical address, which would be valid. Here, it appears that this code, on every host read() or write(), tries to fault in a random process page. This doesn't seem to cause any correctness problems, but there is a performance impact. This patch, and the ones following, result in a 10-15% performance gain on a kernel build. This code can't be immediately tossed out because when it is, you can't log in. Apparently, there is some code in the console driver which depends on this somehow. However, we can start removing it by switching the code which does I/O using kernel addresses to using plain read() and write(). This patch introduces os_read_file_k and os_write_file_k for use with kernel buffers and converts all call locations which use obvious kernel buffers to use them. These include I/O using buffers which are local variables which are on the stack or kmalloc-ed. Later patches will handle the less obvious cases, followed by a mass conversion back to the original interface. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/os.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'arch/um/include') diff --git a/arch/um/include/os.h b/arch/um/include/os.h index 394adcded0b..b463170a530 100644 --- a/arch/um/include/os.h +++ b/arch/um/include/os.h @@ -144,7 +144,9 @@ extern int os_mode_fd(int fd, int mode); extern int os_seek_file(int fd, __u64 offset); extern int os_open_file(char *file, struct openflags flags, int mode); extern int os_read_file(int fd, void *buf, int len); +extern int os_read_file_k(int fd, void *buf, int len); extern int os_write_file(int fd, const void *buf, int count); +extern int os_write_file_k(int fd, const void *buf, int len); extern int os_file_size(char *file, unsigned long long *size_out); extern int os_file_modtime(char *file, unsigned long *modtime); extern int os_pipe(int *fd, int stream, int close_on_exec); -- cgit v1.2.3 From 63843c265fd0e0c7894f713e0db5777560e756ae Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Sun, 6 May 2007 14:51:39 -0700 Subject: uml: dump core on panic Dump core after a panic. This will provide better debugging information than is currently available. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/os.h | 1 + 1 file changed, 1 insertion(+) (limited to 'arch/um/include') diff --git a/arch/um/include/os.h b/arch/um/include/os.h index b463170a530..901804db3c3 100644 --- a/arch/um/include/os.h +++ b/arch/um/include/os.h @@ -279,6 +279,7 @@ extern int raw(int fd); extern void setup_machinename(char *machine_out); extern void setup_hostinfo(char *buf, int len); extern int setjmp_wrapper(void (*proc)(void *, void *), ...); +extern void os_dump_core(void); /* time.c */ #define BILLION (1000 * 1000 * 1000) -- cgit v1.2.3 From a6ea4cceed18edebe1eb6001cb9e0f88cd741a6c Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Sun, 6 May 2007 14:51:43 -0700 Subject: uml: rename os_{read_write}_file_k back to os_{read_write}_file Rename os_{read_write}_file_k back to os_{read_write}_file, delete the originals and their bogus infrastructure, and fix all the callers. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/os.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'arch/um/include') diff --git a/arch/um/include/os.h b/arch/um/include/os.h index 901804db3c3..d6638090870 100644 --- a/arch/um/include/os.h +++ b/arch/um/include/os.h @@ -144,9 +144,7 @@ extern int os_mode_fd(int fd, int mode); extern int os_seek_file(int fd, __u64 offset); extern int os_open_file(char *file, struct openflags flags, int mode); extern int os_read_file(int fd, void *buf, int len); -extern int os_read_file_k(int fd, void *buf, int len); extern int os_write_file(int fd, const void *buf, int count); -extern int os_write_file_k(int fd, const void *buf, int len); extern int os_file_size(char *file, unsigned long long *size_out); extern int os_file_modtime(char *file, unsigned long *modtime); extern int os_pipe(int *fd, int stream, int close_on_exec); -- cgit v1.2.3 From 64f60841c096594b8073e408cd9b40d7d08dcfdd Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Sun, 6 May 2007 14:51:45 -0700 Subject: uml: speed page fault path Give the page fault code a specialized path. There is only one page to look at, so there's no point in going into the general page table walking code. There's only going to be one host operation, so there are no opportunities for merging. So, we go straight to the pte we want, figure out what needs doing, and do it. While I was in here, I fixed the wart where the address passed to unmap was a void *, but an unsigned long to map and protect. This gives me just under 10% on a kernel build. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/os.h | 2 +- arch/um/include/skas/mode_kern_skas.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'arch/um/include') diff --git a/arch/um/include/os.h b/arch/um/include/os.h index d6638090870..e11bdcd8afc 100644 --- a/arch/um/include/os.h +++ b/arch/um/include/os.h @@ -302,7 +302,7 @@ extern long syscall_stub_data(struct mm_id * mm_idp, extern int map(struct mm_id * mm_idp, unsigned long virt, unsigned long len, int r, int w, int x, int phys_fd, unsigned long long offset, int done, void **data); -extern int unmap(struct mm_id * mm_idp, void *addr, unsigned long len, +extern int unmap(struct mm_id * mm_idp, unsigned long addr, unsigned long len, int done, void **data); extern int protect(struct mm_id * mm_idp, unsigned long addr, unsigned long len, int r, int w, int x, int done, diff --git a/arch/um/include/skas/mode_kern_skas.h b/arch/um/include/skas/mode_kern_skas.h index 9cd9c6ec9a6..8ee6285dfac 100644 --- a/arch/um/include/skas/mode_kern_skas.h +++ b/arch/um/include/skas/mode_kern_skas.h @@ -33,6 +33,8 @@ extern unsigned long set_task_sizes_skas(unsigned long *task_size_out); extern int start_uml_skas(void); extern int external_pid_skas(struct task_struct *task); extern int thread_pid_skas(struct task_struct *task); +extern void flush_tlb_page_skas(struct vm_area_struct *vma, + unsigned long address); #define kmem_end_skas (host_task_size - 1024 * 1024) -- cgit v1.2.3 From 16dd07bc6404c8da0bdfeb7a5cde4e4a63991c00 Mon Sep 17 00:00:00 2001 From: Jeff Dike Date: Sun, 6 May 2007 14:51:48 -0700 Subject: uml: more page fault path trimming More trimming of the page fault path. Permissions are passed around in a single int rather than one bit per int. The permission values are copied from libc so that they can be passed to mmap and mprotect without any further conversion. The register sets used by do_syscall_stub and copy_context_skas0 are initialized once, at boot time, rather than once per call. wait_stub_done checks whether it is getting the signals it expects by comparing the wait status to a mask containing bits for the signals of interest rather than comparing individually to the signal numbers. It also has one check for a wait failure instead of two. The caller is expected to do the initial continue of the stub. This gets rid of an argument and some logic. The fname argument is gone, as that can be had from a stack trace. user_signal() is collapsed into userspace() as it is basically one or two lines of code afterwards. The physical memory remapping stuff is gone, as it is unused. flush_tlb_page is inlined. Signed-off-by: Jeff Dike Cc: Paolo 'Blaisorblade' Giarrusso Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/os.h | 6 ++---- arch/um/include/tlb.h | 8 ++------ 2 files changed, 4 insertions(+), 10 deletions(-) (limited to 'arch/um/include') diff --git a/arch/um/include/os.h b/arch/um/include/os.h index e11bdcd8afc..688d181b5f8 100644 --- a/arch/um/include/os.h +++ b/arch/um/include/os.h @@ -300,13 +300,12 @@ extern long syscall_stub_data(struct mm_id * mm_idp, unsigned long *data, int data_count, void **addr, void **stub_addr); extern int map(struct mm_id * mm_idp, unsigned long virt, - unsigned long len, int r, int w, int x, int phys_fd, + unsigned long len, int prot, int phys_fd, unsigned long long offset, int done, void **data); extern int unmap(struct mm_id * mm_idp, unsigned long addr, unsigned long len, int done, void **data); extern int protect(struct mm_id * mm_idp, unsigned long addr, - unsigned long len, int r, int w, int x, int done, - void **data); + unsigned long len, unsigned int prot, int done, void **data); /* skas/process.c */ extern int is_skas_winch(int pid, int fd, void *data); @@ -342,7 +341,6 @@ extern void maybe_sigio_broken(int fd, int read); /* skas/trap */ extern void sig_handler_common_skas(int sig, void *sc_ptr); -extern void user_signal(int sig, union uml_pt_regs *regs, int pid); /* sys-x86_64/prctl.c */ extern int os_arch_prctl(int pid, int code, unsigned long *addr); diff --git a/arch/um/include/tlb.h b/arch/um/include/tlb.h index 8efc1e0f1b8..bcd1a4afb84 100644 --- a/arch/um/include/tlb.h +++ b/arch/um/include/tlb.h @@ -14,9 +14,7 @@ struct host_vm_op { struct { unsigned long addr; unsigned long len; - unsigned int r:1; - unsigned int w:1; - unsigned int x:1; + unsigned int prot; int fd; __u64 offset; } mmap; @@ -27,9 +25,7 @@ struct host_vm_op { struct { unsigned long addr; unsigned long len; - unsigned int r:1; - unsigned int w:1; - unsigned int x:1; + unsigned int prot; } mprotect; } u; }; -- cgit v1.2.3 From c2f239d93e8af991392871c57465cb2ac556b482 Mon Sep 17 00:00:00 2001 From: Paolo 'Blaisorblade' Giarrusso Date: Sun, 6 May 2007 14:51:52 -0700 Subject: uml: fix prototypes Declare strlcpy and strlcat more correctly. Signed-off-by: Paolo 'Blaisorblade' Giarrusso Cc: Jeff Dike Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- arch/um/include/user.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'arch/um/include') diff --git a/arch/um/include/user.h b/arch/um/include/user.h index a6da6260825..d380e6d91a9 100644 --- a/arch/um/include/user.h +++ b/arch/um/include/user.h @@ -14,6 +14,11 @@ */ #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +/* + * This will provide the size_t definition in both kernel and userspace builds + */ +#include + extern void panic(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); extern int printk(const char *fmt, ...) @@ -21,8 +26,7 @@ extern int printk(const char *fmt, ...) extern void schedule(void); extern int in_aton(char *str); extern int open_gdb_chan(void); -/* These use size_t, however unsigned long is correct on both i386 and x86_64. */ -extern unsigned long strlcpy(char *, const char *, unsigned long); -extern unsigned long strlcat(char *, const char *, unsigned long); +extern size_t strlcpy(char *, const char *, size_t); +extern size_t strlcat(char *, const char *, size_t); #endif -- cgit v1.2.3