1565 Commits

Author SHA1 Message Date
James Hunt b5891a4337 Tabs should not be used outside rules.
Signed-off-by: James Hunt <james.o.hunt@intel.com>
2015-11-06 13:42:27 +00:00
James Hunt 1585ee7682 Merge branch 'upstream' 2015-11-05 09:48:31 +00:00
James Hunt 37eab77bea Merge branch 'upstream'
Signed-off-by: James Hunt <james.o.hunt@intel.com>
2015-11-04 13:24:07 +00:00
Will Deacon 3ce000c5f3 Revert "Makefile: allow overriding CFLAGS on the command line"
Riku Voipio reports a regression introduced by d0e2772b93 ("Makefile:
allow overriding CFLAGS on the command line"):

| This breaks builds of debian packages as dpkg-buildpackage sets LDFLAGS
| to something unsuitable for guest init.

Revert the problematic patch for the moment, while we rethink how we'd
like to support user-provided toolchain flags.

This reverts commit d0e2772b93.

Conflicts:
	Makefile

Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-11-04 10:45:28 +00:00
Andre Przywara 03c49af7fd Makefile: consider LDFLAGS on feature tests and when linking executables
While we have an LDFLAGS variable in kvmtool's Makefile, it's not
really used when both doing the feature tests and when finally linking
the lkvm executable.
Add that variable to all the linking steps to allow the user to
specify custom library directories or linker options on the command
line.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-11-02 12:15:45 +00:00
Andre Przywara d0e2772b93 Makefile: allow overriding CFLAGS on the command line
When a Makefile variable is set on the make command line, all
Makefile-internal assignments to that very variable are _ignored_.
Since we add quite some essential values to CFLAGS internally,
specifying some CFLAGS on the command line will usually break the
build (and not fix any include file problems you hoped to overcome
with that).
Somewhat against intuition GNU make provides the "override" directive
to change this behavior; with that assignments in the Makefile get
_appended_ to the value given on the command line. [1]

Change any internal assignments to use that directive, so that a user
can use:
$ make CFLAGS=/path/to/my/include/dir
to teach kvmtool about non-standard header file locations (helpful
for cross-compilation) or to tweak other compiler options.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>

[1] https://www.gnu.org/software/make/manual/html_node/Override-Directive.html
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-11-02 12:15:45 +00:00
William Dauchy d583df25ed kvmtool/run: set a default cmdline if not set
when starting with custom kernel and disk options, kernel_cmdline is
NULL; it results in a segfault while trying to look for a string
using `strstr`:

__strstr_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strstr-sse2-unaligned.S:40
0x00000000004056bf in kvm_cmd_run_init (argc=<optimized out>, argv=<optimized out>) at builtin-run.c:608
0x000000000040639d in kvm_cmd_run (argc=<optimized out>, argv=<optimized out>, prefix=<optimized out>) at builtin-run.c:659
0x0000000000412b8f in handle_command (command=0x62bbc0 <kvm_commands>, argc=5, argv=0x7fffffffe840) at kvm-cmd.c:84
0x00007ffff7211b45 in __libc_start_main (main=0x403540 <main>, argc=6, argv=0x7fffffffe838, init=<optimized out>, fini=<optimized out>,
  rtld_fini=<optimized out>, stack_end=0x7fffffffe828) at libc-start.c:287
0x0000000000403962 in _start ()

this patch suggests to set a minimal cmdline when kernel_cmdline is NULL

Fixes: 8a7163f3db ("kvmtool/run: append cfg.kernel_cmdline at the end of real_cmdline")
Signed-off-by: William Dauchy <william@gandi.net>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-11-02 12:06:00 +00:00
Sasha Levin 6d7eeb7a13 kvmtool: set 9p caching mode to support writable mmaps
9p doesn't support writable mmaps by default (when cache=none), set it to
loose caching to allow for writable mmaps.

Reported-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-10-28 10:45:52 +00:00
Oleg Nesterov 30867c5501 kvmtool/run: do not overwrite /virt/init
To me kvm_setup_guest_init() behaviour looks "obviously wrong" and
unfriendly because it always overwrites /virt/init.

kvm_setup_guest_init() is also called when we are going to use this
tree as a rootfs, and without another patch ("kvmtool/run: append
cfg.kernel_cmdline at the end of real_cmdline") the user can't use
"lkvm run -p init=my_init_path". This simply means that you can not
use a customized init unless you patch kvmtool.

Change extract_file() to do nothing if the file already exists. This
should not affect do_setup() which calls kvm_setup_guest_init() only
if make_dir(guestfs_name) creates the new/empty dir.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-10-27 17:06:49 +00:00
Oleg Nesterov 1c2a21f054 kvmtool/run: don't abuse "root=" parameter, don't pass "rw" to v9fs_mount()
1. kvm_cmd_run_init() appends "root=/dev/root" to real_cmdline if
   cfg.using_rootfs == T. This doesn't hurt but makes no sense and
   looks confusing.

   We do not need to initialiaze the kernel's saved_root_name[] and
   "/dev/root" means nothing to name_to_dev_t().

   We only need to pass this mount-tag to 9p but the kernel always
   uses dev_name="/dev/root" in mount_root() path, so we can safely
   remove this option from the command line.

2. "rw" in rootflags looks confusing too, it is silently ignored by
   v9fs_parse_options() and has no effect.

   We need to clear MS_RDONLY from root_mountflags, this is what the
   "standalone" kernel parameter correctly does.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-10-27 17:06:49 +00:00
Oleg Nesterov f8a7e35cbb kvmtool: add lkvm-static to gitignore
add lkvm-static to gitignore

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-10-27 17:06:48 +00:00
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
Oleg Nesterov 0f04bdf429 kvmtool/build: introduce GUEST_PRE_INIT target
This comes as a separate patch because I do not really understand
/usr/bin/make, probably it should be updated.

Change the main Makefile so that if an arch defines ARCH_PRE_INIT
then we

    - build $GUEST_INIT without "-static"

    - add -DCONFIG_GUEST_PRE_INIT to $CFLAGS

    - build $ARCH_PRE_INIT as guest/guest_pre_init.o and embed it
      into lkvm the same as we do with guest/guest_init.o

This also means that ARCH_PRE_INIT case doesn't depend on glibc-static,
we can relax the SOURCE_STATIC check later.

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:33 +00:00
Oleg Nesterov 26e94dc425 kvmtool/setup: Introduce extract_file() helper
Turn kvm_setup_guest_init(guestfs_name) into a more generic helper,
extract_file(guestfs_name, filename, data, size) and reimplement
kvm_setup_guest_init() as a trivial wrapper.

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:18 +00:00
Sasha Levin a44c32936d kvmtool: correct order of the vcpu destructor
The vcpu module is a core component which should be removed last, but the
destructor was mistakenly marked as something that should be done first.

This would cause the vcpu data to be freed up before anything else had the
chance to exit, and assuming that that data was still valid - causing use
after frees.

Reported-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-10-27 16:08:53 +00:00
Oleg Nesterov 4d7f252f21 kvmtool/term: unexport term_set_tty, term_init, term_exit
According to git grep they can be static.

term_got_escape can be static too, and we can even move it into
term_getc().

"int term_escape_char" doesn't make sense at least until we allow
to redefine it, turn it into preprocessor constant.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-10-27 16:01:59 +00:00
Oleg Nesterov 8a7163f3db kvmtool/run: append cfg.kernel_cmdline at the end of real_cmdline
This allows the user to always override the paramaters set by lkvm.
Say, currently 'lkvm run -p ro' doesn't work.

To keep the current logic we need to change strstr("root=") to check
cfg.kernel_cmdline, not real_cmdline. And perhaps we can even add a
simple helper add_param(name, val) to make this all more consistent;
it should only append "name=val" to real_cmdline if cfg.kernel_cmdline
doesn't include this paramater.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-10-27 16:01:57 +00:00
James Hunt 3b5e690a70 Merge pull request #3 from xnox/clr
Fan Du patches
2015-10-23 16:26:51 +01:00
Fan Du b1ef6ede7b kvmtool: {x86} Add initrd support when loading elf kernel
Signed-off-by: Fan Du <fan.du@intel.com>
Signed-off-by: Dimitri John Ledkov <dimitri.j.ledkov@intel.com>
2015-10-23 14:32:51 +01:00
Xiaochen Shen 259e76b395 kvmtool: Makefile: remove static dependency files when make clean
After make lkvm-static & make clean, the dependency files for static
objects (.xxx.static.o.d) are not removed.

Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
Signed-off-by: Dimitri John Ledkov <dimitri.j.ledkov@intel.com>
2015-10-23 14:30:01 +01:00
Xiaochen Shen e6916f14ba kvmtool: Makefile: fix lkvm-static compiling errors
This is regression issue introduced by patch:
0001-tools-kvm-fix-assumption-of-no-IP-options.patch

This line of code breaks SOURCE_AIO try-build logic
CFLAGS  += $(WARNINGS) -DCONFIG_HAS_AIO

The compiling error:
 # make lkvm-static
disk/core.static.o: In function `disk_image__thread':
kvmtool/disk/core.c:69: undefined reference to `io_getevents'
disk/core.static.o: In function `disk_image__new':
kvmtool/disk/core.c:112: undefined reference to `io_setup'
util/read-write.static.o: In function `aio_pwritev':
kvmtool/util/read-write.c:332: undefined reference to `io_submit'
util/read-write.static.o: In function `aio_preadv':
kvmtool/util/read-write.c:349: undefined reference to `io_submit'
collect2: error: ld returned 1 exit status
make: *** [lkvm-static] Error 1

Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
Signed-off-by: Dimitri John Ledkov <dimitri.j.ledkov@intel.com>
2015-10-23 14:28:07 +01:00
Dimitri John Ledkov 1148f58db6 Merge pull request #1 from clearlinux/clear-patches-sync-with-master
Clear patches sync with master
2015-10-20 13:30:24 +01:00
James Hunt c5b70fc6e1 Makefile: Allow Ubuntu to find asm/e820.h.
Signed-off-by: James Hunt <james.o.hunt@intel.com>
2015-10-16 12:37:30 +01:00
James Hunt 5299047e5b Merge branch 'master' into clear-patches
Signed-off-by: James Hunt <james.o.hunt@intel.com>

Conflicts:
	Makefile
	builtin-run.c
	builtin-setup.c
	virtio/net.c
2015-10-16 12:33:39 +01:00
Sven Dowideit 3695adeb22 Add a link to the lwn.net article
Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-10-09 10:00:59 +01:00
Dimitri John Ledkov cdce942c1a Make static libc and guest-init functionality optional.
If one typically only boots full disk-images, one wouldn't necessaraly
want to statically link glibc, for the guest-init feature of the
kvmtool. As statically linked glibc triggers haevy security
maintainance.

Signed-off-by: Dimitri John Ledkov <dimitri.j.ledkov@intel.com>
[will: moved all the guest_init handling into builtin_setup.c]
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-09-15 18:18:58 +01:00
Riku Voipio 0837fbe242 Makefile: relax arm test
Currently Makefile accepts only armv7l.* When building kvmtool under 32bit
personality on Aarch64 machines, uname -m reports "armv8l", so build fails.
We expect doing 32bit arm builds in Aarch64 to become standard the same way
people do i386 builds on x86_64 machines.

Make the sed test a little more greedy so armv8l becomes acceptable.

Acked-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-09-10 11:13:58 +01:00
Dimitri John Ledkov e0b5a5d99c Fix compilation with old kernel headers.
Signed-off-by: Dimitri John Ledkov <dimitri.j.ledkov@intel.com>
2015-09-04 16:09:56 +01:00
Dimitri John Ledkov 1578f2d0ea Make static libc and guest-init functionality optional.
If one typically only boots full disk-images, one wouldn't necessaraly
want to statically link glibc, for the guest-init feature of the
kvmtool. As statically linked glibc triggers haevy security
maintainance.

Signed-off-by: Dimitri John Ledkov <dimitri.j.ledkov@intel.com>
2015-09-04 16:09:51 +01:00
Dimitri John Ledkov b56b0d9ebe Silence exit message. 2015-09-04 16:09:46 +01:00
Fan Du 40c60808fe kvmtool: Restrict virtio queue number to 1 when vhost on
vhost kernel driver does not support mutiple queue yet,
Tweak queue number will fail with "--net mode=tap,vhost=1,mq=2"
as below when lkvm trying to set ring kick fd for queue 2:

VHOST_SET_VRING_KICK failed: No buffer space available

Error on this scenario, and overide with the default one queue
configuration.

Signed-off-by: Fan Du <fan.du@intel.com>
2015-09-04 16:09:46 +01:00
Fan Du a6740cbebb kvmtool: Introduce downscript option for virtio-net
To detach tap device automatically from bridge when exiting,
just like what the reverse of "script" does.

Signed-off-by: Fan Du <fan.du@intel.com>
2015-09-04 16:09:46 +01:00
Dimitri John Ledkov ad5ecfa6f5 kvmtool: stat the filesize when loading shmem device. 2015-09-04 16:09:46 +01:00
Dimitri John Ledkov fdd5905807 Move more messages to debug. 2015-09-04 16:09:35 +01:00
Dimitri John Ledkov 7f58a12292 Skip creating custom rootfs. 2015-09-04 16:09:30 +01:00
Mark Rutland 0161ed7758 Handle KVM_EXIT_SYSTEM_EVENT on any VCPU
When VCPU #0 exits (e.g. due to KVM_EXIT_SYSTEM_EVENT), it sends
SIGKVMEXIT to all other VCPUs, waits for them to exit, then tears down
any remaining context. The signalling of SIGKVMEXIT is critical to
forcing VCPUs to shut down in response to a system event (e.g. PSCI
SYSTEM_OFF).

VCPUs other that VCPU #0 simply exit in kvm_cpu_thread without forcing
other CPUs to shut down. Thus if a system event is taken on a VCPU other
than VCPU #0, the remaining CPUs are left online. This results in KVM
tool not exiting as expected when a system event is taken on a VCPU
other than VCPU #0 (as may happen if the guest panics).

Fix this by tearing down all CPUs upon a system event, regardless of the
CPU on which the event occurred. While this means the VCPU thread will
signal itself, and VCPU #0 will signal all other VCPU threads a second
time, these are harmless.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Marc Zyngier <marc.zyngier@arm.com>
Cc: Suzuki Poulose <suzuki.poulose@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-09-04 11:42:12 +01:00
Josh Triplett efcf862611 README: Add section for where to send patches.
Signed-off-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-08-07 15:31:37 +01:00
Josh Triplett 2ec1740506 kvm__emulate_io: Don't fall through from IO in to IO out if no handler
If an IO port device has no io_in handler, kvm__emulate_io would fall
through and call the io_out handler instead.  Fix to only call the
handler for the appropriate direction.

If no handler exists, kvm__emulate_io will automatically treat it as an
IO error (due to the default "ret = false").

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-08-07 15:31:37 +01:00
Josh Triplett e7b95bd430 kvm__emulate_io: Don't call br_read_unlock() twice on IO error
The IO error path in kvm__emulate_io would call br_read_unlock(), then
goto error, which would call br_read_unlock() again.  Refactor the
control flow to have only one exit path and one call to
br_read_unlock().

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-08-07 15:31:37 +01:00
Fan Du eef27ae368 kvmtool: Introduce downscript option for virtio-net
To detach tap device automatically from bridge when exiting,
just like what the reverse of "script" does.

Signed-off-by: Fan Du <fan.du@intel.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-08-06 18:37:37 +01:00
Andre Przywara 4095fac878 avoid redefining PAGE_SIZE
PAGE_SIZE may have been defined by the C libary (musl-libc does that).
So avoid redefining it here unconditionally, instead only use our
definition if none has been provided by the libc.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-07-22 16:57:34 +01:00
Andre Przywara f9183c63e3 Makefile: avoid non-literal printf format string warnings
The clang compiler by default dislikes non-literal format strings
in *printf functions, so it complains about kvm__set_dir() in kvm.c
and about the error reporting functions.
Since a fix is not easy and the code itself is fine (just seems that
the compiler is not smart enough to see that), let's just disable
the warning. Since GCC knows about this option as well (it just
doesn't have it enabled with -Wall), we can unconditionally add this
to the warning options.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-07-22 16:57:34 +01:00
Andre Przywara 1c40b18c9b remove KVM_CAP_MAX_VCPUS hack
As we now have the header file in our repository, we can safely follow
the recommendation in kvm.c and remove the hack adding the
KVM_CAP_MAX_VCPUS macro.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-07-20 18:25:48 +01:00
Andre Przywara 8f22adc423 check for and use C library provided strlcpy and strlcat
The musl-libc library provides implementations of strlcpy and strlcat,
so introduce a feature check for it and only use the kvmtool
implementation if there is no library support for it.
This avoids clashes with the public definition.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-07-20 18:25:48 +01:00
Andre Przywara 52c22e6e64 use <poll.h> instead of <sys/poll.h>
The manpage of poll(2) states that the prototype of poll is defined
in <poll.h>. Use that header file instead of <sys/poll.h> to allow
compilation against musl-libc.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-07-20 18:25:48 +01:00
Andre Przywara d77bd4f466 Fix call to connect()
According to the manpage and the prototype the second argument to
connect(2) is a "const struct sockaddr*", so cast our protocol
specific type back to the super type.
This fixes compilation on musl-libc.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-07-20 18:25:48 +01:00
Andre Przywara 369c27e683 ui: remove pointless double const in keymap declarations
clang does not like two const specifiers in one declaration, so
remove one to let clang compile kvmtool.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-07-20 18:25:48 +01:00
Andre Przywara 5389d44f5f Makefile: remove unneeded -s switch on compiling BIOS files
Stripping has no effect on object files, so having "-s -c" on the
command line makes no sense.
In fact clang complains about it and aborts with an error, so lets
just remove the unneeded "-s" switch here.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-07-20 18:25:48 +01:00
Andre Przywara a2583dbf82 kvm-ipc: use proper type for file descriptor
A socket (as any other file descriptor) is of type "int" to catch the
negative error cases. Fix the declaration to allow errors to be
detected.
Found and needed by clang.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-07-20 18:25:48 +01:00
Andre Przywara 823c7fd8e9 qcow: fix signedness bugs
Some functions in qcow.c return u64, but are checked against < 0
because they want to check for the -1 error return value.
Do an explicit comparison against the casted -1 to express this
properly.
This was silently compiled out by gcc, but clang complained about it.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-07-20 18:25:48 +01:00