From: Oleg Nesterov <oleg@redhat.com>
To: Andre Przywara <andre.przywara@arm.com>,
Dimitri Ledkov <dimitri.j.ledkov@intel.com>,
Ingo Molnar <mingo@kernel.org>, Pekka Enberg <penberg@kernel.org>,
Will Deacon <will.deacon@arm.com>
Cc: kvm@vger.kernel.org
Subject: [PATCH 3/3] kvmtool/x86: implement guest_pre_init
Date: Mon, 19 Oct 2015 12:59:48 +0200 [thread overview]
Message-ID: <20151019105948.GA12435@redhat.com> (raw)
In-Reply-To: <20151019105930.GA12411@redhat.com>
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.
TODO: x86/init.S doesn't handle i386, should be simple to add.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
Makefile | 1 +
builtin-run.c | 4 ++++
builtin-setup.c | 14 +++++++++++++-
guest/init.c | 2 ++
x86/init.S | 38 ++++++++++++++++++++++++++++++++++++++
5 files changed, 58 insertions(+), 1 deletion(-)
create mode 100644 x86/init.S
diff --git a/Makefile b/Makefile
index 0f8e003..f8f7cc4 100644
--- a/Makefile
+++ b/Makefile
@@ -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 e0c8732..3da00da 100644
--- a/builtin-run.c
+++ b/builtin-run.c
@@ -600,7 +600,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 bb7c71c..1e5b1e4 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 7277a07..46e3fa4 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 0000000..488a93f
--- /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
--
2.4.3
next prev parent reply other threads:[~2015-10-19 11:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-19 10:59 [PATCH 0/3] kvmtool: tiny init fox x86_64 Oleg Nesterov
2015-10-19 10:59 ` [PATCH 1/3] kvmtool/setup: Introduce extract_file() helper Oleg Nesterov
2015-10-19 10:59 ` [PATCH 2/3] kvmtool/build: introduce GUEST_PRE_INIT target Oleg Nesterov
2015-10-19 10:59 ` Oleg Nesterov [this message]
2015-10-22 7:59 ` [PATCH 0/3] kvmtool: tiny init fox x86_64 Pekka Enberg
2015-10-22 15:58 ` Oleg Nesterov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151019105948.GA12435@redhat.com \
--to=oleg@redhat.com \
--cc=andre.przywara@arm.com \
--cc=dimitri.j.ledkov@intel.com \
--cc=kvm@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=penberg@kernel.org \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).