diff options
Diffstat (limited to 'arch/um')
-rw-r--r-- | arch/um/Kconfig.i386 | 7 | ||||
-rw-r--r-- | arch/um/Makefile | 2 | ||||
-rw-r--r-- | arch/um/Makefile-i386 | 5 | ||||
-rw-r--r-- | arch/um/drivers/chan_user.c | 11 | ||||
-rw-r--r-- | arch/um/drivers/harddog_user.c | 4 | ||||
-rw-r--r-- | arch/um/drivers/net_kern.c | 2 | ||||
-rw-r--r-- | arch/um/drivers/net_user.c | 2 | ||||
-rw-r--r-- | arch/um/drivers/slip_user.c | 12 | ||||
-rw-r--r-- | arch/um/drivers/slirp_user.c | 15 | ||||
-rw-r--r-- | arch/um/drivers/ubd_kern.c | 1 | ||||
-rw-r--r-- | arch/um/drivers/ubd_user.c | 3 | ||||
-rw-r--r-- | arch/um/include/os.h | 2 | ||||
-rw-r--r-- | arch/um/os-Linux/aio.c | 4 | ||||
-rw-r--r-- | arch/um/os-Linux/drivers/ethertap_user.c | 10 | ||||
-rw-r--r-- | arch/um/os-Linux/drivers/tuntap_user.c | 2 | ||||
-rw-r--r-- | arch/um/os-Linux/helper.c | 38 | ||||
-rw-r--r-- | arch/um/os-Linux/process.c | 4 | ||||
-rw-r--r-- | arch/um/os-Linux/skas/process.c | 12 | ||||
-rw-r--r-- | arch/um/os-Linux/time.c | 55 | ||||
-rw-r--r-- | arch/um/os-Linux/util.c | 2 |
20 files changed, 124 insertions, 69 deletions
diff --git a/arch/um/Kconfig.i386 b/arch/um/Kconfig.i386 index e0ac74e5d4c..717f5d3440e 100644 --- a/arch/um/Kconfig.i386 +++ b/arch/um/Kconfig.i386 @@ -8,6 +8,13 @@ config UML_X86 bool default y +config X86_32 + bool + default y + +config RWSEM_XCHGADD_ALGORITHM + def_bool y + config 64BIT bool default n diff --git a/arch/um/Makefile b/arch/um/Makefile index 31999bc1c8a..ba6813a4aa3 100644 --- a/arch/um/Makefile +++ b/arch/um/Makefile @@ -168,7 +168,7 @@ ifneq ($(KBUILD_SRC),) $(Q)mkdir -p $(objtree)/include/asm-um $(Q)ln -fsn $(srctree)/include/asm-$(HEADER_ARCH) include/asm-um/arch else - $(Q)cd $(TOPDIR)/include/asm-um && ln -fsn ../asm-$(SUBARCH) arch + $(Q)cd $(TOPDIR)/include/asm-um && ln -fsn ../asm-$(HEADER_ARCH) arch endif $(objtree)/$(ARCH_DIR)/include: diff --git a/arch/um/Makefile-i386 b/arch/um/Makefile-i386 index 67290117d90..561e373bd85 100644 --- a/arch/um/Makefile-i386 +++ b/arch/um/Makefile-i386 @@ -22,11 +22,6 @@ export LDFLAGS HOSTCFLAGS HOSTLDFLAGS UML_OBJCOPYFLAGS endif endif -KBUILD_CFLAGS += -DCONFIG_X86_32 -KBUILD_AFLAGS += -DCONFIG_X86_32 -CONFIG_X86_32 := y -export CONFIG_X86_32 - # First of all, tune CFLAGS for the specific CPU. This actually sets cflags-y. include $(srctree)/arch/x86/Makefile_32.cpu diff --git a/arch/um/drivers/chan_user.c b/arch/um/drivers/chan_user.c index b88e93b3a39..025764089ac 100644 --- a/arch/um/drivers/chan_user.c +++ b/arch/um/drivers/chan_user.c @@ -74,10 +74,16 @@ void generic_free(void *data) int generic_console_write(int fd, const char *buf, int n) { + sigset_t old, no_sigio; struct termios save, new; int err; if (isatty(fd)) { + sigemptyset(&no_sigio); + sigaddset(&no_sigio, SIGIO); + if (sigprocmask(SIG_BLOCK, &no_sigio, &old)) + goto error; + CATCH_EINTR(err = tcgetattr(fd, &save)); if (err) goto error; @@ -97,8 +103,11 @@ int generic_console_write(int fd, const char *buf, int n) * Restore raw mode, in any case; we *must* ignore any error apart * EINTR, except for debug. */ - if (isatty(fd)) + if (isatty(fd)) { CATCH_EINTR(tcsetattr(fd, TCSAFLUSH, &save)); + sigprocmask(SIG_SETMASK, &old, NULL); + } + return err; error: return -errno; diff --git a/arch/um/drivers/harddog_user.c b/arch/um/drivers/harddog_user.c index b56f8e0196a..448ba59207a 100644 --- a/arch/um/drivers/harddog_user.c +++ b/arch/um/drivers/harddog_user.c @@ -79,14 +79,14 @@ int start_watchdog(int *in_fd_ret, int *out_fd_ret, char *sock) n = read(in_fds[0], &c, sizeof(c)); if (n == 0) { printk("harddog_open - EOF on watchdog pipe\n"); - helper_wait(pid); + helper_wait(pid, 1, NULL); err = -EIO; goto out_close_out; } else if (n < 0) { printk("harddog_open - read of watchdog pipe failed, " "err = %d\n", errno); - helper_wait(pid); + helper_wait(pid, 1, NULL); err = n; goto out_close_out; } diff --git a/arch/um/drivers/net_kern.c b/arch/um/drivers/net_kern.c index 73681f14f9f..3c6c44ca1ff 100644 --- a/arch/um/drivers/net_kern.c +++ b/arch/um/drivers/net_kern.c @@ -98,10 +98,10 @@ static int uml_net_rx(struct net_device *dev) if (pkt_len > 0) { skb_trim(skb, pkt_len); skb->protocol = (*lp->protocol)(skb); - netif_rx(skb); lp->stats.rx_bytes += skb->len; lp->stats.rx_packets++; + netif_rx(skb); return pkt_len; } diff --git a/arch/um/drivers/net_user.c b/arch/um/drivers/net_user.c index 90d7f2e8ead..29185cad9ff 100644 --- a/arch/um/drivers/net_user.c +++ b/arch/um/drivers/net_user.c @@ -201,7 +201,7 @@ static int change_tramp(char **argv, char *output, int output_len) close(fds[1]); if (pid > 0) - CATCH_EINTR(err = waitpid(pid, NULL, 0)); + helper_wait(pid, 0, "change_tramp"); return pid; } diff --git a/arch/um/drivers/slip_user.c b/arch/um/drivers/slip_user.c index 5f06204d687..b8711e50da8 100644 --- a/arch/um/drivers/slip_user.c +++ b/arch/um/drivers/slip_user.c @@ -77,7 +77,7 @@ static int slip_tramp(char **argv, int fd) { struct slip_pre_exec_data pe_data; char *output; - int status, pid, fds[2], err, output_len; + int pid, fds[2], err, output_len; err = os_pipe(fds, 1, 0); if (err < 0) { @@ -109,15 +109,7 @@ static int slip_tramp(char **argv, int fd) read_output(fds[0], output, output_len); printk("%s", output); - CATCH_EINTR(err = waitpid(pid, &status, 0)); - if (err < 0) - err = errno; - else if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) { - printk(UM_KERN_ERR "'%s' didn't exit with status 0\n", argv[0]); - err = -EINVAL; - } - else err = 0; - + err = helper_wait(pid, 0, argv[0]); close(fds[0]); out_free: diff --git a/arch/um/drivers/slirp_user.c b/arch/um/drivers/slirp_user.c index 1865089ff41..89c1be225fd 100644 --- a/arch/um/drivers/slirp_user.c +++ b/arch/um/drivers/slirp_user.c @@ -79,7 +79,7 @@ out: static void slirp_close(int fd, void *data) { struct slirp_data *pri = data; - int status,err; + int err; close(fd); close(pri->slave); @@ -98,18 +98,9 @@ static void slirp_close(int fd, void *data) "(%d)\n", pri->pid, errno); } #endif - - CATCH_EINTR(err = waitpid(pri->pid, &status, WNOHANG)); - if (err < 0) { - printk(UM_KERN_ERR "slirp_close: waitpid returned %d\n", errno); - return; - } - - if (err == 0) { - printk(UM_KERN_ERR "slirp_close: process %d has not exited\n", - pri->pid); + err = helper_wait(pri->pid, 1, "slirp_close"); + if (err < 0) return; - } pri->pid = -1; } diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index 7e6cdde62ea..b1a77b11f08 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c @@ -1128,6 +1128,7 @@ static void do_ubd_request(struct request_queue *q) "errno = %d\n", -n); else if(list_empty(&dev->restart)) list_add(&dev->restart, &restart); + kfree(io_req); return; } diff --git a/arch/um/drivers/ubd_user.c b/arch/um/drivers/ubd_user.c index 41d254bd38d..48fc7452bc1 100644 --- a/arch/um/drivers/ubd_user.c +++ b/arch/um/drivers/ubd_user.c @@ -49,8 +49,7 @@ int start_io_thread(unsigned long sp, int *fd_out) goto out_close; } - pid = clone(io_thread, (void *) sp, CLONE_FILES | CLONE_VM | SIGCHLD, - NULL); + pid = clone(io_thread, (void *) sp, CLONE_FILES | CLONE_VM, NULL); if(pid < 0){ err = -errno; printk("start_io_thread - clone failed : errno = %d\n", errno); diff --git a/arch/um/include/os.h b/arch/um/include/os.h index fbf0a87c6ea..6f0d1c741bc 100644 --- a/arch/um/include/os.h +++ b/arch/um/include/os.h @@ -214,7 +214,7 @@ extern int execvp_noalloc(char *buf, const char *file, char *const argv[]); extern int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv); extern int run_helper_thread(int (*proc)(void *), void *arg, unsigned int flags, unsigned long *stack_out); -extern int helper_wait(int pid); +extern int helper_wait(int pid, int nohang, char *pname); /* tls.c */ diff --git a/arch/um/os-Linux/aio.c b/arch/um/os-Linux/aio.c index 4158118c4a5..93dc0c80eba 100644 --- a/arch/um/os-Linux/aio.c +++ b/arch/um/os-Linux/aio.c @@ -218,7 +218,7 @@ static int init_aio_24(void) goto out_close_pipe; err = run_helper_thread(not_aio_thread, NULL, - CLONE_FILES | CLONE_VM | SIGCHLD, &aio_stack); + CLONE_FILES | CLONE_VM, &aio_stack); if (err < 0) goto out_close_pipe; @@ -254,7 +254,7 @@ static int init_aio_26(void) } err = run_helper_thread(aio_thread, NULL, - CLONE_FILES | CLONE_VM | SIGCHLD, &aio_stack); + CLONE_FILES | CLONE_VM, &aio_stack); if (err < 0) return err; diff --git a/arch/um/os-Linux/drivers/ethertap_user.c b/arch/um/os-Linux/drivers/ethertap_user.c index 4ff55360344..07ca0cb472a 100644 --- a/arch/um/os-Linux/drivers/ethertap_user.c +++ b/arch/um/os-Linux/drivers/ethertap_user.c @@ -94,7 +94,7 @@ static int etap_tramp(char *dev, char *gate, int control_me, int control_remote, int data_me, int data_remote) { struct etap_pre_exec_data pe_data; - int pid, status, err, n; + int pid, err, n; char version_buf[sizeof("nnnnn\0")]; char data_fd_buf[sizeof("nnnnnn\0")]; char gate_buf[sizeof("nnn.nnn.nnn.nnn\0")]; @@ -131,13 +131,7 @@ static int etap_tramp(char *dev, char *gate, int control_me, } if (c != 1) { printk(UM_KERN_ERR "etap_tramp : uml_net failed\n"); - err = -EINVAL; - CATCH_EINTR(n = waitpid(pid, &status, 0)); - if (n < 0) - err = -errno; - else if (!WIFEXITED(status) || (WEXITSTATUS(status) != 1)) - printk(UM_KERN_ERR "uml_net didn't exit with " - "status 1\n"); + err = helper_wait(pid, 0, "uml_net"); } return err; } diff --git a/arch/um/os-Linux/drivers/tuntap_user.c b/arch/um/os-Linux/drivers/tuntap_user.c index 6c55d3c8ead..1037a3b6386 100644 --- a/arch/um/os-Linux/drivers/tuntap_user.c +++ b/arch/um/os-Linux/drivers/tuntap_user.c @@ -107,7 +107,7 @@ static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote, "errno = %d\n", errno); return err; } - CATCH_EINTR(waitpid(pid, NULL, 0)); + helper_wait(pid, 0, "tuntap_open_tramp"); cmsg = CMSG_FIRSTHDR(&msg); if (cmsg == NULL) { diff --git a/arch/um/os-Linux/helper.c b/arch/um/os-Linux/helper.c index 7a72dbb61b0..fba3f0fefee 100644 --- a/arch/um/os-Linux/helper.c +++ b/arch/um/os-Linux/helper.c @@ -76,7 +76,7 @@ int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv) data.fd = fds[1]; data.buf = __cant_sleep() ? kmalloc(PATH_MAX, UM_GFP_ATOMIC) : kmalloc(PATH_MAX, UM_GFP_KERNEL); - pid = clone(helper_child, (void *) sp, CLONE_VM | SIGCHLD, &data); + pid = clone(helper_child, (void *) sp, CLONE_VM, &data); if (pid < 0) { ret = -errno; printk("run_helper : clone failed, errno = %d\n", errno); @@ -101,7 +101,7 @@ int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv) ret = n; kill(pid, SIGKILL); } - CATCH_EINTR(waitpid(pid, NULL, 0)); + CATCH_EINTR(waitpid(pid, NULL, __WCLONE)); } out_free2: @@ -126,7 +126,7 @@ int run_helper_thread(int (*proc)(void *), void *arg, unsigned int flags, return -ENOMEM; sp = stack + UM_KERN_PAGE_SIZE - sizeof(void *); - pid = clone(proc, (void *) sp, flags | SIGCHLD, arg); + pid = clone(proc, (void *) sp, flags, arg); if (pid < 0) { err = -errno; printk("run_helper_thread : clone failed, errno = %d\n", @@ -134,7 +134,7 @@ int run_helper_thread(int (*proc)(void *), void *arg, unsigned int flags, return err; } if (stack_out == NULL) { - CATCH_EINTR(pid = waitpid(pid, &status, 0)); + CATCH_EINTR(pid = waitpid(pid, &status, __WCLONE)); if (pid < 0) { err = -errno; printk("run_helper_thread - wait failed, errno = %d\n", @@ -150,14 +150,30 @@ int run_helper_thread(int (*proc)(void *), void *arg, unsigned int flags, return pid; } -int helper_wait(int pid) +int helper_wait(int pid, int nohang, char *pname) { - int ret; + int ret, status; + int wflags = __WCLONE; - CATCH_EINTR(ret = waitpid(pid, NULL, WNOHANG)); + if (nohang) + wflags |= WNOHANG; + + if (!pname) + pname = "helper_wait"; + + CATCH_EINTR(ret = waitpid(pid, &status, wflags)); if (ret < 0) { - ret = -errno; - printk("helper_wait : waitpid failed, errno = %d\n", errno); - } - return ret; + printk(UM_KERN_ERR "%s : waitpid process %d failed, " + "errno = %d\n", pname, pid, errno); + return -errno; + } else if (nohang && ret == 0) { + printk(UM_KERN_ERR "%s : process %d has not exited\n", + pname, pid); + return -ECHILD; + } else if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { + printk(UM_KERN_ERR "%s : process %d didn't exit with " + "status 0\n", pname, pid); + return -ECHILD; + } else + return 0; } diff --git a/arch/um/os-Linux/process.c b/arch/um/os-Linux/process.c index 37781db4cec..bda5c3150d6 100644 --- a/arch/um/os-Linux/process.c +++ b/arch/um/os-Linux/process.c @@ -101,7 +101,7 @@ void os_kill_process(int pid, int reap_child) { kill(pid, SIGKILL); if (reap_child) - CATCH_EINTR(waitpid(pid, NULL, 0)); + CATCH_EINTR(waitpid(pid, NULL, __WALL)); } /* This is here uniquely to have access to the userspace errno, i.e. the one @@ -130,7 +130,7 @@ void os_kill_ptraced_process(int pid, int reap_child) ptrace(PTRACE_KILL, pid); ptrace(PTRACE_CONT, pid); if (reap_child) - CATCH_EINTR(waitpid(pid, NULL, 0)); + CATCH_EINTR(waitpid(pid, NULL, __WALL)); } /* Don't use the glibc version, which caches the result in TLS. It misses some diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c index d77c81d7068..e8b7a97e83d 100644 --- a/arch/um/os-Linux/skas/process.c +++ b/arch/um/os-Linux/skas/process.c @@ -64,7 +64,7 @@ void wait_stub_done(int pid) int n, status, err; while (1) { - CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); + CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED | __WALL)); if ((n < 0) || !WIFSTOPPED(status)) goto bad_wait; @@ -153,7 +153,7 @@ static void handle_trap(int pid, struct uml_pt_regs *regs, panic("handle_trap - continuing to end of syscall " "failed, errno = %d\n", errno); - CATCH_EINTR(err = waitpid(pid, &status, WUNTRACED)); + CATCH_EINTR(err = waitpid(pid, &status, WUNTRACED | __WALL)); if ((err < 0) || !WIFSTOPPED(status) || (WSTOPSIG(status) != SIGTRAP + 0x80)) { err = ptrace_dump_regs(pid); @@ -255,16 +255,18 @@ int start_userspace(unsigned long stub_stack) panic("start_userspace : mmap failed, errno = %d", errno); sp = (unsigned long) stack + UM_KERN_PAGE_SIZE - sizeof(void *); - flags = CLONE_FILES | SIGCHLD; + flags = CLONE_FILES; if (proc_mm) flags |= CLONE_VM; + else + flags |= SIGCHLD; pid = clone(userspace_tramp, (void *) sp, flags, (void *) stub_stack); if (pid < 0) panic("start_userspace : clone failed, errno = %d", errno); do { - CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED)); + CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED | __WALL)); if (n < 0) panic("start_userspace : wait failed, errno = %d", errno); @@ -314,7 +316,7 @@ void userspace(struct uml_pt_regs *regs) "pid=%d, ptrace operation = %d, errno = %d\n", pid, op, errno); - CATCH_EINTR(err = waitpid(pid, &status, WUNTRACED)); + CATCH_EINTR(err = waitpid(pid, &status, WUNTRACED | __WALL)); if (err < 0) panic("userspace - waitpid failed, errno = %d\n", errno); diff --git a/arch/um/os-Linux/time.c b/arch/um/os-Linux/time.c index e34e1effe0f..e4928059946 100644 --- a/arch/um/os-Linux/time.c +++ b/arch/um/os-Linux/time.c @@ -59,7 +59,7 @@ long long disable_timer(void) { struct itimerval time = ((struct itimerval) { { 0, 0 }, { 0, 0 } }); - if(setitimer(ITIMER_VIRTUAL, &time, &time) < 0) + if (setitimer(ITIMER_VIRTUAL, &time, &time) < 0) printk(UM_KERN_ERR "disable_timer - setitimer failed, " "errno = %d\n", errno); @@ -74,13 +74,62 @@ long long os_nsecs(void) return timeval_to_ns(&tv); } +#ifdef UML_CONFIG_NO_HZ +static int after_sleep_interval(struct timespec *ts) +{ + return 0; +} +#else +static inline long long timespec_to_us(const struct timespec *ts) +{ + return ((long long) ts->tv_sec * UM_USEC_PER_SEC) + + ts->tv_nsec / UM_NSEC_PER_USEC; +} + +static int after_sleep_interval(struct timespec *ts) +{ + int usec = UM_USEC_PER_SEC / UM_HZ; + long long start_usecs = timespec_to_us(ts); + struct timeval tv; + struct itimerval interval; + + /* + * It seems that rounding can increase the value returned from + * setitimer to larger than the one passed in. Over time, + * this will cause the remaining time to be greater than the + * tick interval. If this happens, then just reduce the first + * tick to the interval value. + */ + if (start_usecs > usec) + start_usecs = usec; + tv = ((struct timeval) { .tv_sec = start_usecs / UM_USEC_PER_SEC, + .tv_usec = start_usecs % UM_USEC_PER_SEC }); + interval = ((struct itimerval) { { 0, usec }, tv }); + + if (setitimer(ITIMER_VIRTUAL, &interval, NULL) == -1) + return -errno; + + return 0; +} +#endif + extern void alarm_handler(int sig, struct sigcontext *sc); void idle_sleep(unsigned long long nsecs) { - struct timespec ts = { .tv_sec = nsecs / UM_NSEC_PER_SEC, - .tv_nsec = nsecs % UM_NSEC_PER_SEC }; + struct timespec ts; + + /* + * nsecs can come in as zero, in which case, this starts a + * busy loop. To prevent this, reset nsecs to the tick + * interval if it is zero. + */ + if (nsecs == 0) + nsecs = UM_NSEC_PER_SEC / UM_HZ; + ts = ((struct timespec) { .tv_sec = nsecs / UM_NSEC_PER_SEC, + .tv_nsec = nsecs % UM_NSEC_PER_SEC }); if (nanosleep(&ts, &ts) == 0) alarm_handler(SIGVTALRM, NULL); + after_sleep_interval(&ts); } diff --git a/arch/um/os-Linux/util.c b/arch/um/os-Linux/util.c index ef095436a78..3e058ce9ffb 100644 --- a/arch/um/os-Linux/util.c +++ b/arch/um/os-Linux/util.c @@ -141,7 +141,7 @@ void os_dump_core(void) * nothing reasonable to do if that fails. */ - while ((pid = waitpid(-1, NULL, WNOHANG)) > 0) + while ((pid = waitpid(-1, NULL, WNOHANG | __WALL)) > 0) os_kill_ptraced_process(pid, 0); abort(); |