20 Commits

Author SHA1 Message Date
Oleg Nesterov 5614f9d933 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>
2015-10-27 17:03:37 +00:00
Andre Przywara 372f583d35 guest/init: update reboot() call
The reboot() call that guest/init used was an older version, the
manpage talks about libc4 and libc5.
Update it to the current version exported by glibc by using the right
include file and adjusting the parameter.
This also fixed GCC 5.1.0 compile, because linux/reboot.h misses the
actual prototype.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-06-16 18:31:42 +01:00
Andre Przywara 9ed717c350 guest/init: add missing #includes
GCC 5.1.0 complains about missing prototypes for waitpid() and
mkdir(), so add the appropriate #includes to get rid of the warning.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-06-16 18:31:42 +01:00
Marc Zyngier 1ad95468d8 kvm tools: fix zombie reaping in guest/init.c
init.c is not very kind with processes that get reparented when
their own parent die, leaving them hanging around. Looking at the
code, it only seem to care about its own flesh and blood. Bad init.

Teach it some basic zombie reaping skills.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:53 +01:00
Sasha Levin 5fab5964e2 kvm tools: add HOME env var to hostfs
Add a HOME env var when booting a hostfs guest. This will point out to a home
dir within the given guest name.

This will make several apps happier when being run under hostfs.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Asias He 69071bcef7 kvm tools: Mount devpts to /dev/pts
I'm seeing this in guest due to lacking of /dev/pts:

   sh-4.2# xterm
   xterm: Error 32, errno 28: No space left on device
   Reason: get_pty: not enough ptys

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Asias He b757c2a6c9 kvm tools: Export DISPLAY ENV as our default host ip address
It is useful to run a X program in guest and display it on host.

1) Make host's x server listen to localhost:6000
   host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
               UNIX-CONNECT:/tmp/.X11-unix/X0

2) Start the guest and run X program
   host_shell$ lkvm run -k /boot/bzImage
  guest_shell$ xlogo

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Asias He f20814b8cf kvm tools: Make 'lkvm setup' work outside kernel/tools/kvm dir
Generate

   ~/.lkvm/$guest/virt/etc/passwd
   ~/.lkvm/$guest/virt/init

on the fly.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Asias He 91d6a8e38a kvm tools: Merge guest init and init_stage2.c
Two stages init process is introduced in

   commit eaf720b285947a6f4e29174d0eba1899de31d8ab
   kvm tools: Split custom rootfs init into two stages

to address the outdated init binary issue.

Currenly, init binary is embedded in lkvm binary and generated on the
fly. So there is no need to split the init process.

This makes
   1) the size of lkvm binary smaller becasue only one
      statically linked init binary.
   2) the init process simpler and cleaner.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Pekka Enberg 10de19cf03 kvm tools: Remove bogus init printout
This patch removes the following printout from init:

  Starting '/bin/sh'...

which is completely bogus for "vm sandbox", for example.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:50 +01:00
Sasha Levin 5e048c182e kvm tool: Exit init only when /bin/sh itself stops
Right now we wait for any of the children to stop, which means we might
exit before /bin/sh stopped.

Instead, wait only for the /bin/sh (or the sandboxed) process.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:50 +01:00
Sasha Levin 98b39f1f23 kvm tools: Don't panic guest when exiting from custom rootfs
We currently panic guest when exiting from custom rootfs since at that point
we terminate init, and the guest kernel doesn't quite like that.

Instead, we do a graceful shutdown when init is done (either when 'lkvm
sandbox' command or '/bin/sh' is finished).

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:50 +01:00
Sasha Levin d50fe489e8 kvm tools: Allow easily sandboxing applications within a guest
This patch adds a '--sandbox' argument when used in conjuction with a custom
rootfs, it allows running a script or an executable in the guest environment
by using executables and other files from the host.

This is useful when testing code that might cause problems on the host, or
to automate kernel testing since it's now easy to link a kvm tools test
script with 'git bisect run'.

Suggested-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:49 +01:00
Sasha Levin 9cec19c8d7 kvm tools: Split custom rootfs init into two stages
Currently custom rootfs init is built along with the main KVM tools executable
and is copied into custom rootfs directories when they are created with
'kvm setup'. The problem there is that if the init code changes, they have
to be manually copied to custom rootfs directories.

Instead, this patch splits init process into two parts. One part that simply
handles mounts, and passes it to stage 2 of the init.

Stage 2 really sits along in the code tree, and does all the heavy lifting.

This allows us to make init changes in the code tree and have it automatically
be updated in custom rootfs guests without having to copy files over manua

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
[ penberg@kernel.org: fix 'make check' breakage in Makefile ]
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:49 +01:00
Sasha Levin ce6927e8fc kvm tools: Create /etc/passwd in shared rootfs
This patch creates a dummy /etc/passwd on guest creation.

This is done because some applications (read: git) get angry when they
can't find current user in /etc/passwd.

Reported-by: Darren Hart <dvhart@linux.intel.com>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Pekka Enberg 1819403689 kvm tools: NULL-terminate init env
This patch fixes 'kvm run' rootfs boot failures:

  Starting '/bin/sh'...
  Init failed: Bad address

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin c8de9b2a1f kvm tools: Set active console before running /bin/sh
This patch sets active console to the serial console before running the
shell. Doing so fixes two issues:

* Fix job control.

* Set all env vars.

The user visible issues are less warnings (no more of this:
  sh: cannot set terminal process group (-1): Inappropriate ioctl for device
  sh: no job control in this shell)

A working 'top', and a working ctrl-c.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin 575a9e3f31 kvm tools: Use kernel dhcp for network autoconfiguration
This patch removes the manual/usermode dhcp client configuration and instead
uses the DHCP client built within the kernel.

Since this client is tightly integrated with NFS (if NFS config is set), we
will add a specific NFS root addr in our DHCP offer to point it to a non
existent address so that we won't hang trying to poke it for our root.

Acked-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:47 +01:00
Sasha Levin 90ef0dc675 kvm tools: Add guestfs network autoconfiguration
Add a script to automatically configure networking in the guest.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:47 +01:00
Pekka Enberg 282113fd51 kvm tools: Introduce 'kvm setup' command
This patch implements 'kvm setup' command that can be used to setup a guest
filesystem that shares system libraries and binaries from host filesystem in
read-only mode.

You can setup a new shared rootfs guest with:

  ./kvm setup -n default

and launch it with:

  ./kvm run --9p /,hostfs -p "init=virt/init" -d ~/.kvm-tools/default/

We want to teach 'kvm run' to be able to launch guest filesystems by name in
the future. Furthermore, 'kvm run' should setup a 'default' filesystem and use
it by default unless the user specifies otherwise.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:47 +01:00