diff options
author | Oleg Nesterov <oleg@redhat.com> | 2015-10-19 12:59:48 +0200 |
---|---|---|
committer | Will Deacon <will.deacon@arm.com> | 2015-10-27 17:03:37 +0000 |
commit | 5614f9d933c9fac94886fe359f807a60acda3fa4 (patch) | |
tree | 8fc4530f45572247a192e860fe582a5a1a0c8ee4 | |
parent | 0f04bdf429a732f37180aa7411ec87c4197e8990 (diff) | |
download | kvmtool-5614f9d933c9fac94886fe359f807a60acda3fa4.tar.gz |
kvmtool/x86: implement guest_pre_init
Add the tiny x86/init.S which just mounts /host and execs
/virt/init.
NOTE: of course, the usage of CONFIG_GUEST_PRE_INIT is ugly, we
need to cleanup this code. But I'd prefer to do this on top of
this minimal/simple change. And I think this needs cleanups in
any case, for example I think lkvm shouldn't abuse the "init="
kernel parameter at all.
Acked-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | builtin-run.c | 4 | ||||
-rw-r--r-- | builtin-setup.c | 14 | ||||
-rw-r--r-- | guest/init.c | 2 | ||||
-rw-r--r-- | x86/init.S | 38 |
5 files changed, 58 insertions, 1 deletions
@@ -110,6 +110,7 @@ endif ifeq ($(ARCH),x86_64) ARCH := x86 DEFINES += -DCONFIG_X86_64 + ARCH_PRE_INIT = x86/init.S endif ### Arch-specific stuff diff --git a/builtin-run.c b/builtin-run.c index aa5eaad2..ab1fc2ad 100644 --- a/builtin-run.c +++ b/builtin-run.c @@ -594,7 +594,11 @@ static struct kvm *kvm_cmd_run_init(int argc, const char **argv) if (kvm->cfg.custom_rootfs) { kvm_run_set_sandbox(kvm); +#ifdef CONFIG_GUEST_PRE_INIT + strcat(real_cmdline, " init=/virt/pre_init"); +#else strcat(real_cmdline, " init=/virt/init"); +#endif if (!kvm->cfg.no_dhcp) strcat(real_cmdline, " ip=dhcp"); diff --git a/builtin-setup.c b/builtin-setup.c index bb7c71c5..1e5b1e47 100644 --- a/builtin-setup.c +++ b/builtin-setup.c @@ -144,12 +144,24 @@ static int extract_file(const char *guestfs_name, const char *filename, extern char _binary_guest_init_start; extern char _binary_guest_init_size; +extern char _binary_guest_pre_init_start; +extern char _binary_guest_pre_init_size; int kvm_setup_guest_init(const char *guestfs_name) { - return extract_file(guestfs_name, "virt/init", + int err; + +#ifdef CONFIG_GUEST_PRE_INIT + err = extract_file(guestfs_name, "virt/pre_init", + &_binary_guest_pre_init_start, + &_binary_guest_pre_init_size); + if (err) + return err; +#endif + err = extract_file(guestfs_name, "virt/init", &_binary_guest_init_start, &_binary_guest_init_size); + return err; } #else int kvm_setup_guest_init(const char *guestfs_name) diff --git a/guest/init.c b/guest/init.c index 7277a07d..46e3fa4c 100644 --- a/guest/init.c +++ b/guest/init.c @@ -30,7 +30,9 @@ static int run_process_sandbox(char *filename) static void do_mounts(void) { +#ifndef CONFIG_GUEST_PRE_INIT mount("hostfs", "/host", "9p", MS_RDONLY, "trans=virtio,version=9p2000.L"); +#endif mount("", "/sys", "sysfs", 0, NULL); mount("proc", "/proc", "proc", 0, NULL); mount("devtmpfs", "/dev", "devtmpfs", 0, NULL); diff --git a/x86/init.S b/x86/init.S new file mode 100644 index 00000000..488a93fe --- /dev/null +++ b/x86/init.S @@ -0,0 +1,38 @@ +.data + +.m_dev: +.string "hostfs" +.m_dir: +.string "/host" +.m_typ: +.string "9p" +.m_opt: +.string "trans=virtio,version=9p2000.L" + +.e_nam: +.string "/virt/init" + +.text +.globl _start +_start: + + mov $165, %rax # __NR_mount + mov $.m_dev, %rdi + mov $.m_dir, %rsi + mov $.m_typ, %rdx + mov $1, %r10 # MS_RDONLY + mov $.m_opt, %r8 + syscall + + mov $59, %rax # __NR_execve + mov $.e_nam, %rdi + lea 8(%rsp), %rsi # argv[] + mov %rdi, (%rsi) # change argv[0] + pop %rcx # argc + inc %rcx + lea (%rsi,%rcx,8), %rdx # envp[] + syscall + + mov $60, %rax # __NR_exit + mov $1, %rdi + syscall # panic |