diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-12 21:05:52 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-12 21:05:52 -0400 |
| commit | 4e21fc138bfd7fe625ff5dc81541399aaf9d429b (patch) | |
| tree | 43bedf14d2eee7711b8241dcfd6bd7b8737d9bd5 /init | |
| parent | 8418263e3547ed3816475e4c55a77004f0426ee6 (diff) | |
| parent | 5522be6a4624a5f505555569e4d9cee946630686 (diff) | |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/signal
Pull third pile of kernel_execve() patches from Al Viro:
"The last bits of infrastructure for kernel_thread() et.al., with
alpha/arm/x86 use of those. Plus sanitizing the asm glue and
do_notify_resume() on alpha, fixing the "disabled irq while running
task_work stuff" breakage there.
At that point the rest of kernel_thread/kernel_execve/sys_execve work
can be done independently for different architectures. The only
pending bits that do depend on having all architectures converted are
restrictred to fs/* and kernel/* - that'll obviously have to wait for
the next cycle.
I thought we'd have to wait for all of them done before we start
eliminating the longjump-style insanity in kernel_execve(), but it
turned out there's a very simple way to do that without flagday-style
changes."
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/signal:
alpha: switch to saner kernel_execve() semantics
arm: switch to saner kernel_execve() semantics
x86, um: convert to saner kernel_execve() semantics
infrastructure for saner ret_from_kernel_thread semantics
make sure that kernel_thread() callbacks call do_exit() themselves
make sure that we always have a return path from kernel_execve()
ppc: eeh_event should just use kthread_run()
don't bother with kernel_thread/kernel_execve for launching linuxrc
alpha: get rid of switch_stack argument of do_work_pending()
alpha: don't bother passing switch_stack separately from regs
alpha: take SIGPENDING/NOTIFY_RESUME loop into signal.c
alpha: simplify TIF_NEED_RESCHED handling
Diffstat (limited to 'init')
| -rw-r--r-- | init/do_mounts_initrd.c | 41 | ||||
| -rw-r--r-- | init/main.c | 33 |
2 files changed, 33 insertions, 41 deletions
diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c index 135959a276b..5e4ded51788 100644 --- a/init/do_mounts_initrd.c +++ b/init/do_mounts_initrd.c | |||
| @@ -16,13 +16,13 @@ | |||
| 16 | #include <linux/initrd.h> | 16 | #include <linux/initrd.h> |
| 17 | #include <linux/sched.h> | 17 | #include <linux/sched.h> |
| 18 | #include <linux/freezer.h> | 18 | #include <linux/freezer.h> |
| 19 | #include <linux/kmod.h> | ||
| 19 | 20 | ||
| 20 | #include "do_mounts.h" | 21 | #include "do_mounts.h" |
| 21 | 22 | ||
| 22 | unsigned long initrd_start, initrd_end; | 23 | unsigned long initrd_start, initrd_end; |
| 23 | int initrd_below_start_ok; | 24 | int initrd_below_start_ok; |
| 24 | unsigned int real_root_dev; /* do_proc_dointvec cannot handle kdev_t */ | 25 | unsigned int real_root_dev; /* do_proc_dointvec cannot handle kdev_t */ |
| 25 | static int __initdata old_fd, root_fd; | ||
| 26 | static int __initdata mount_initrd = 1; | 26 | static int __initdata mount_initrd = 1; |
| 27 | 27 | ||
| 28 | static int __init no_initrd(char *str) | 28 | static int __init no_initrd(char *str) |
| @@ -33,33 +33,29 @@ static int __init no_initrd(char *str) | |||
| 33 | 33 | ||
| 34 | __setup("noinitrd", no_initrd); | 34 | __setup("noinitrd", no_initrd); |
| 35 | 35 | ||
| 36 | static int __init do_linuxrc(void *_shell) | 36 | static int init_linuxrc(struct subprocess_info *info, struct cred *new) |
| 37 | { | 37 | { |
| 38 | static const char *argv[] = { "linuxrc", NULL, }; | 38 | sys_unshare(CLONE_FS | CLONE_FILES); |
| 39 | extern const char *envp_init[]; | 39 | /* move initrd over / and chdir/chroot in initrd root */ |
| 40 | const char *shell = _shell; | 40 | sys_chdir("/root"); |
| 41 | 41 | sys_mount(".", "/", NULL, MS_MOVE, NULL); | |
| 42 | sys_close(old_fd);sys_close(root_fd); | 42 | sys_chroot("."); |
| 43 | sys_setsid(); | 43 | sys_setsid(); |
| 44 | return kernel_execve(shell, argv, envp_init); | 44 | return 0; |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | static void __init handle_initrd(void) | 47 | static void __init handle_initrd(void) |
| 48 | { | 48 | { |
| 49 | static char *argv[] = { "linuxrc", NULL, }; | ||
| 50 | extern char *envp_init[]; | ||
| 49 | int error; | 51 | int error; |
| 50 | int pid; | ||
| 51 | 52 | ||
| 52 | real_root_dev = new_encode_dev(ROOT_DEV); | 53 | real_root_dev = new_encode_dev(ROOT_DEV); |
| 53 | create_dev("/dev/root.old", Root_RAM0); | 54 | create_dev("/dev/root.old", Root_RAM0); |
| 54 | /* mount initrd on rootfs' /root */ | 55 | /* mount initrd on rootfs' /root */ |
| 55 | mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY); | 56 | mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY); |
| 56 | sys_mkdir("/old", 0700); | 57 | sys_mkdir("/old", 0700); |
| 57 | root_fd = sys_open("/", 0, 0); | 58 | sys_chdir("/old"); |
| 58 | old_fd = sys_open("/old", 0, 0); | ||
| 59 | /* move initrd over / and chdir/chroot in initrd root */ | ||
| 60 | sys_chdir("/root"); | ||
| 61 | sys_mount(".", "/", NULL, MS_MOVE, NULL); | ||
| 62 | sys_chroot("."); | ||
| 63 | 59 | ||
| 64 | /* | 60 | /* |
| 65 | * In case that a resume from disk is carried out by linuxrc or one of | 61 | * In case that a resume from disk is carried out by linuxrc or one of |
| @@ -67,27 +63,22 @@ static void __init handle_initrd(void) | |||
| 67 | */ | 63 | */ |
| 68 | current->flags |= PF_FREEZER_SKIP; | 64 | current->flags |= PF_FREEZER_SKIP; |
| 69 | 65 | ||
| 70 | pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD); | 66 | call_usermodehelper_fns("/linuxrc", argv, envp_init, UMH_WAIT_PROC, |
| 71 | if (pid > 0) | 67 | init_linuxrc, NULL, NULL); |
| 72 | while (pid != sys_wait4(-1, NULL, 0, NULL)) | ||
| 73 | yield(); | ||
| 74 | 68 | ||
| 75 | current->flags &= ~PF_FREEZER_SKIP; | 69 | current->flags &= ~PF_FREEZER_SKIP; |
| 76 | 70 | ||
| 77 | /* move initrd to rootfs' /old */ | 71 | /* move initrd to rootfs' /old */ |
| 78 | sys_fchdir(old_fd); | 72 | sys_mount("..", ".", NULL, MS_MOVE, NULL); |
| 79 | sys_mount("/", ".", NULL, MS_MOVE, NULL); | ||
| 80 | /* switch root and cwd back to / of rootfs */ | 73 | /* switch root and cwd back to / of rootfs */ |
| 81 | sys_fchdir(root_fd); | 74 | sys_chroot(".."); |
| 82 | sys_chroot("."); | ||
| 83 | sys_close(old_fd); | ||
| 84 | sys_close(root_fd); | ||
| 85 | 75 | ||
| 86 | if (new_decode_dev(real_root_dev) == Root_RAM0) { | 76 | if (new_decode_dev(real_root_dev) == Root_RAM0) { |
| 87 | sys_chdir("/old"); | 77 | sys_chdir("/old"); |
| 88 | return; | 78 | return; |
| 89 | } | 79 | } |
| 90 | 80 | ||
| 81 | sys_chdir("/"); | ||
| 91 | ROOT_DEV = new_decode_dev(real_root_dev); | 82 | ROOT_DEV = new_decode_dev(real_root_dev); |
| 92 | mount_root(); | 83 | mount_root(); |
| 93 | 84 | ||
diff --git a/init/main.c b/init/main.c index 313360fe111..9cf77ab138a 100644 --- a/init/main.c +++ b/init/main.c | |||
| @@ -69,6 +69,7 @@ | |||
| 69 | #include <linux/slab.h> | 69 | #include <linux/slab.h> |
| 70 | #include <linux/perf_event.h> | 70 | #include <linux/perf_event.h> |
| 71 | #include <linux/file.h> | 71 | #include <linux/file.h> |
| 72 | #include <linux/ptrace.h> | ||
| 72 | 73 | ||
| 73 | #include <asm/io.h> | 74 | #include <asm/io.h> |
| 74 | #include <asm/bugs.h> | 75 | #include <asm/bugs.h> |
| @@ -791,17 +792,17 @@ static void __init do_pre_smp_initcalls(void) | |||
| 791 | do_one_initcall(*fn); | 792 | do_one_initcall(*fn); |
| 792 | } | 793 | } |
| 793 | 794 | ||
| 794 | static void run_init_process(const char *init_filename) | 795 | static int run_init_process(const char *init_filename) |
| 795 | { | 796 | { |
| 796 | argv_init[0] = init_filename; | 797 | argv_init[0] = init_filename; |
| 797 | kernel_execve(init_filename, argv_init, envp_init); | 798 | return kernel_execve(init_filename, argv_init, envp_init); |
| 798 | } | 799 | } |
| 799 | 800 | ||
| 800 | /* This is a non __init function. Force it to be noinline otherwise gcc | 801 | static void __init kernel_init_freeable(void); |
| 801 | * makes it inline to init() and it becomes part of init.text section | 802 | |
| 802 | */ | 803 | static int __ref kernel_init(void *unused) |
| 803 | static noinline int init_post(void) | ||
| 804 | { | 804 | { |
| 805 | kernel_init_freeable(); | ||
| 805 | /* need to finish all async __init code before freeing the memory */ | 806 | /* need to finish all async __init code before freeing the memory */ |
| 806 | async_synchronize_full(); | 807 | async_synchronize_full(); |
| 807 | free_initmem(); | 808 | free_initmem(); |
| @@ -813,7 +814,8 @@ static noinline int init_post(void) | |||
| 813 | flush_delayed_fput(); | 814 | flush_delayed_fput(); |
| 814 | 815 | ||
| 815 | if (ramdisk_execute_command) { | 816 | if (ramdisk_execute_command) { |
| 816 | run_init_process(ramdisk_execute_command); | 817 | if (!run_init_process(ramdisk_execute_command)) |
| 818 | return 0; | ||
| 817 | printk(KERN_WARNING "Failed to execute %s\n", | 819 | printk(KERN_WARNING "Failed to execute %s\n", |
| 818 | ramdisk_execute_command); | 820 | ramdisk_execute_command); |
| 819 | } | 821 | } |
| @@ -825,20 +827,22 @@ static noinline int init_post(void) | |||
| 825 | * trying to recover a really broken machine. | 827 | * trying to recover a really broken machine. |
| 826 | */ | 828 | */ |
| 827 | if (execute_command) { | 829 | if (execute_command) { |
| 828 | run_init_process(execute_command); | 830 | if (!run_init_process(execute_command)) |
| 831 | return 0; | ||
| 829 | printk(KERN_WARNING "Failed to execute %s. Attempting " | 832 | printk(KERN_WARNING "Failed to execute %s. Attempting " |
| 830 | "defaults...\n", execute_command); | 833 | "defaults...\n", execute_command); |
| 831 | } | 834 | } |
| 832 | run_init_process("/sbin/init"); | 835 | if (!run_init_process("/sbin/init") || |
| 833 | run_init_process("/etc/init"); | 836 | !run_init_process("/etc/init") || |
| 834 | run_init_process("/bin/init"); | 837 | !run_init_process("/bin/init") || |
| 835 | run_init_process("/bin/sh"); | 838 | !run_init_process("/bin/sh")) |
| 839 | return 0; | ||
| 836 | 840 | ||
| 837 | panic("No init found. Try passing init= option to kernel. " | 841 | panic("No init found. Try passing init= option to kernel. " |
| 838 | "See Linux Documentation/init.txt for guidance."); | 842 | "See Linux Documentation/init.txt for guidance."); |
| 839 | } | 843 | } |
| 840 | 844 | ||
| 841 | static int __init kernel_init(void * unused) | 845 | static void __init kernel_init_freeable(void) |
| 842 | { | 846 | { |
| 843 | /* | 847 | /* |
| 844 | * Wait until kthreadd is all set-up. | 848 | * Wait until kthreadd is all set-up. |
| @@ -893,7 +897,4 @@ static int __init kernel_init(void * unused) | |||
| 893 | * we're essentially up and running. Get rid of the | 897 | * we're essentially up and running. Get rid of the |
| 894 | * initmem segments and start the user-mode stuff.. | 898 | * initmem segments and start the user-mode stuff.. |
| 895 | */ | 899 | */ |
| 896 | |||
| 897 | init_post(); | ||
| 898 | return 0; | ||
| 899 | } | 900 | } |
