Commit Graph

1183 Commits

Author SHA1 Message Date
Sasha Levin 226e727b20 kvm tools: support injecting arbitrary sysrqs
Add support to 'lkvm debug' to inject arbitrary sysrqs using a new
'-s <sysrq>' argument.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Sasha Levin e23415808a kvm tools: dynamically allocate p9 fids
This removes the limit for p9 fids and the huge fid array that came along with
it. Instead, it dynamically allocates fids and stores them in a rb-tree.

This is useful when the guest needs a lot of fids, such as when stress
testing guests.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Michael Ellerman cb90966cff kvm tools, powerpc: Use MMU info for ibm,slb-size
Acked-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Michael Ellerman 38baf7775d kvm tools, powerpc: Use MMU info for ibm,processor-segment-sizes
Acked-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Michael Ellerman de494ec5a1 kvm tools, powerpc: Use MMU info from the kernel for ibm,segment-page-sizes
Recent kernels (>= v3.5-rc1) have an ioctl which allows us to retrieve the
list of page sizes supported for the guest.

So rework the cpu info code to use that ioctl when available, falling
back to the same values we used previously if the ioctl is not present.

We may also need to filter the list of page sizes against the page size
of the memory backing guest RAM - this accounts for the unfortunate amount
of code in setup_mmu_info().

Finally we need to turn the structure as returned by the kernel into the
format expected in the device tree.

Acked-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Michael Ellerman 4a75c6033b kvm tools, powerpc: Restructure find_cpu_info()
We are about to add more logic to find_cpu_info(). To support this we
need to pass kvm through to it, and also restructure the return flow
so we can operate on info before it is returned.

Acked-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Michael Ellerman ac92dd434f kvm tools, powerpc: Reformatting in find_cpu_info()
Matt's enter key was broken when he wrote this ;)

Acked-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Michael Ellerman 2b5ca5cd3d kvm tools, powerpc: Use ARRAY_SIZE() in find_cpu_info()
Acked-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Michael Ellerman 95477af3a9 kvm tools, powerpc: Use designated initializers for struct cpu_info
Using designated initializers for structs is preferable because it
is self documenting, and more robust against changes to the structure
layout.

Acked-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Michael Ellerman 3ebd8e0bf3 kvm tools: Remember page size as kvm->ram_pagesize
On some powerpc platforms we need to make sure we only advertise page
sizes to the guest which are <= the size of the pages backing guest RAM.

So have mmap_hugetblfs() save the hugetblfs page size for us, and also
teach mmap_anon_or_hugetblfs() to set the page size for anonymous mmap.

Acked-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Michael Ellerman 8cd50b938e kvm tools, powerpc: Use mmap_anon_or_hugetblfs() in kvm__arch_init()
It implements essentially the same logic. The one difference is it sets
MAP_NORESERVE when using anonymous mmap, but I think that is OK.

Reword the comment about hugetblfs, we are no longer required to use
hugepages to back the guest.

Acked-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Michael Ellerman f8edca99fb kvm tools: Move mmap_anon_or_hugetblfs() into util
So we can use it on powerpc.

Acked-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Asias He 97f16d6688 kvm tools: Introduce struct disk_image_params
Introduce struct disk_image_params to contain all the disk image parameters.
This is useful for adding more disk image parameters, e.g. disk image
cache mode.

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 627d68743d kvm tools: Do not poll ioeventfd if vhost is enabled
If vhost is enabled for a virtio device, vhost will poll the ioeventfd
in kernel side and there is no need to poll it in userspace. Otherwise,
both vhost kernel and userspace will race to poll.

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 8b79545748 kvm tools: Fix VHOST_SET_MEM_TABLE failure
VHOST_SET_MEM_TABLE failed: Operation not supported

In vhost_set_memory(), We have

        if (mem.padding)
                return -EOPNOTSUPP;

So, we need to zero struct vhost_memory.

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
Michael Ellerman 54cb8a31fc kvm tool: Fix powerpc/kvm-cpu.c for new KVM_SET_ONE_REG API
I think this code was based on an earlier version of the KVM_SET_ONE_REG
API, which at the time was in agraf's tree but not mainline?

Either way it doesn't compile as is, so fix it up.

Acked-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Michael Ellerman 2f82e465e5 kvm tools: Cleanup ARCH & uname_M in Makefile
The sed expression for ARCH seems to have been cribbed from the top-level
kernel Makefile, and includes lots of architectures kvmtool doesn't
support - strip it down.

Also call uname -m directly there and get rid of uname_M.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Michael Ellerman e15b23071e kvm tools: Support cross compilation
Allow CROSS_COMPILE to be used to prefix CC as is done in the kernel
Makefile. If CROSS_COMPILE is unset it has no effect, and still allows
CC to be overridden.

We need to fix a few places to use ARCH instead of uname_M directly, so
that the overridden setting of ARCH takes effect.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Michael Ellerman 6aab5e47cd kvm tools: Use asm/barrier.h on powerpc
Commit 141124c deleted system.h, we really want barrier.h

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Michael Ellerman 2df530136d kvm tools: Define KVM_VIRTIO_MMIO_AREA for powerpc
Commit 82ea06e "Introduce KVM_VIRTIO_MMIO_AREA" did just that, but only
for x86. Causing the following commit 5c301a3 "Add virtio-mmio support"
to break the build for powerpc.

We follow what x86 did and place it 16MB past the PCI area, I have no
idea if that is actually a good idea, or whether it works at all.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Sasha Levin 0d5b41d930 kvm tools: set the HYPERVISOR flag in cpuid
We need to set the HYPERVISOR flag to let the kernel know we're running
under a hypervisor.

This makes the kernel enable all sorts of para-virtualization options
such as kvm-clock.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
[gorcunov@: Add comments on bits]
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Sasha Levin 5cc808aad7 kvm tools: support 9p flush command
While we process 9p requests serially, so there's no point for implementing
flush, we still need to answer it to prevent guest kernel from hanging waiting
for it.

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 5ac1178bb8 kvm tools: Process virito blk requests in separate thread
All blk requests are processed in notify_vq() which is in the context of
ioeventfd thread: ioeventfd__thread(). The processing in notify_vq() may
take a long time to complete and all devices share the single ioeventfd
thead, so this might block other device's notify_vq() being called and
starve other devices.

This patch makes virtio blk's notify_vq() just notify the blk thread
instead of doing the real hard read/write work. Tests show that the
overhead of the notification operations is small.

The reasons for using dedicated thead instead of using thead pool
follow:

1) In thread pool model, each job handling operation:
thread_pool__do_job() takes about 6 or 7 mutex_{lock,unlock} ops. Most
of the mutex are global (job_mutex) which are contented by the threads
in the pool. It's fine for the non performance critical virtio devices,
such as console, rng, etc. But it's not optimal for net and blk devices.

2) Using dedicated threads to handle blk requests opens the door for
user to set different IO priority for the blk threads.

3) It also reduces the contentions between net and blk devices if they
do not share the thead pool.

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 fea74936f1 kvm tools: Increase AIO_MAX to 256
The queue size for virtio_blk is 256 and AIO_MAX is 32, we might be
short of available aio events if guest issues > 32 requests
simultaneously. Following error is observed when guest running stressed
I/O workload.

  Info: disk_image__read error: total=-11

To fix this, let's increase the aio events limit.

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
Cyrill Gorcunov 2c82d39a08 kvm tools: Add test for -static libc present
Make sure the static binaries can be built.

Reported-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
[ penberg@kernel.org: improve error message ]
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Cyrill Gorcunov 24ed52db06 kvm tools: Use safe string handling functions
Use str[n|l] functions to make sure destination is
not overflowed.

Seems socket path generation should be moved into
a separate helper, but it's for another patch.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:52 +01:00
Asias He 27cead0dd2 kvm tools: Improve compat message format
---------
Before:
---------
*** Compatibility Warning ***

        virtio-blk device was not detected

While you have requested a virtio-blk device, the guest kernel did not initialize it.
Please make sure that the guest kernel was compiled with CONFIG_VIRTIO_BLK=y enabled in its .config

*** Compatibility Warning ***

        virtio-net device was not detected

While you have requested a virtio-net device, the guest kernel did not initialize it.
Please make sure that the guest kernel was compiled with CONFIG_VIRTIO_NET=y enabled in its .config

  # KVM session ended normally.

---------
After:
---------
  # KVM compatibility warning.
        virtio-blk device was not detected.
        While you have requested a virtio-blk device, the guest kernel did not initialize it.
        Please make sure that the guest kernel was compiled with CONFIG_VIRTIO_BLK=y enabled in .config.

  # KVM compatibility warning.
        virtio-net device was not detected.
        While you have requested a virtio-net device, the guest kernel did not initialize it.
        Please make sure that the guest kernel was compiled with CONFIG_VIRTIO_NET=y enabled in .config.

  # KVM session ended normally.

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 d278197dc9 kvm tools: Fix compat message
compat_id is initialized to -1 for each type of device. We should add
compat message if the compat_id == -1 which means we haven't added
compat message for this type of device.

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 52f34d2c8b kvm tools: Introduce virtio_compat_add_message() helper
This patch introduces a helper virtio_compat_add_message() to simplify
adding compat message for virtio device.

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 b7c2f3bc49 kvm tools: Code cleanup for disk/raw.c
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 449ca0aefe kvm tools: Code cleanup for disk/qcow.c
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 54c84566ec kvm tools: Code cleanup for disk/core.c
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 ff00c1e447 kvm tools: Code cleanup for virtio/net.c
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 0af1e5a77c kvm tools: Code cleanup for virtio/console.c
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 34239c780a kvm tools: Code cleanup for virtio/blk.c
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Asias He e4a3dd87e7 kvm tools: Code cleanup for virtio/balloon.c
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Asias He a8a4464983 kvm tools: Code cleanup for virtio/9p.c
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Asias He dcd3cd8e4e kvm tools: Simplify disk read write function name
We read and write in sectors by default. It makes little sense to add
the extra _sector string for read and write ops/function name.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Asias He 0ecc970fb2 kvm tools: Restart io_submit if it returns EAGAIN
Keep trying if io_submit returns EAGAIN. No need to fail the request.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Asias He 354b198b3f kvm tools: Rename ~/.kvm-tools/ to ~/.lkvm/
The new directory name is simpler and easier to type and remember.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Asias He f4450d4e08 kvm tools: Remove unused req_mutex variable.
The req_mutex was used to protect the request list. In commit b7b038d, I
removed the use of the virtio_blk_req_{pop, push} which needs the
req_mutex, but I forgot to remove the req_mutex. So remove it now.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Sasha Levin c40c205b0f kvm tools: increase amount of virtio-9p FIDs
Increase the amount of FIDs since we easily reach current amount with
simple stress tests.

This should be changed to use a rbtree or something faster in the
future.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Sasha Levin 31a6fb8d33 kvm tools: use accessor function for virtio-9p FIDs
Since the 9p functions don't know the size of the fid array, they might
request an FID outside of the allowed range. Use an accessor to prevent
that and to hide the internal implementation from them.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Sasha Levin 066c58090b kvm tools: use bitwise 'and' in kvm-ipc
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Sasha Levin 7f37fa7e92 kvm tools: fix sigsegv in irq__exit
We free the structure, but never remove them from the tree or list, then
we freed them the next time we ran through that structure.

This patch also simplifies irq__exit a bit.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Jean-Philippe Menil d4f57aa4b0 kvm tools: Fix printf() format string in kvm__load_firmware()
Fixes the following build breakage with '-Werror':

  cc1: warnings being treated as errors
  x86/boot.c: In function ‘kvm__load_firmware’:
  x86/boot.c:29: error: format ‘%lu’ expects type ‘long unsigned int’, but
  argument 3 has type ‘__off64_t’
  make: *** [x86/boot.o] Erreur 1

Signed-off-by: Jean-Philippe Menil <jean-philippe.menil@univ-nantes.fr>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Cyrill Gorcunov dbb1237965 kvm tools: Add own barrier() definition
Otherwise I'm getting the following compile problem on my Fedora
machine. The helper is rather taken from linux kernel.

 | [cyrill@moon kvm]$ make tags
 | x86/include/kvm/barrier.h:11:25: fatal error: asm/barrier.h: No such file or directory compilation terminated.

Acked-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Cyrill Gorcunov d562e08683 kvm tools: Add --debug-mmio option
This switches the default behaviour of lkvm if access
on unregistered MMIO address happens -- we don't spam
a user with warning messages anymore. If one needs details
on unhandled MMIOs the --debug-mmio option should be passed.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Pekka Enberg 085d5c7a9d kvm tools: Fix build breakage due to <linux/stddef.h> changes
Commit 2084c24 ("do not export kernel's NULL #define to userspace") broken KVM
tool build:

  FYI:

   CC       framebuffer.o
  In file included from include/kvm/framebuffer.h:5:0,
                from framebuffer.c:1:
  ../../include/linux/list.h: In function ‘INIT_HLIST_NODE’:
  ../../include/linux/list.h:572:12: error: ‘NULL’ undeclared (first use in this function)
  ../../include/linux/list.h:572:12: note: each undeclared identifier is reported only once for each function it appears in
  ../../include/linux/list.h: In function ‘hlist_move_list’:
  ../../include/linux/list.h:657:15: error: ‘NULL’ undeclared (first use in this function)
  make: *** [framebuffer.o] Error 1

  due to this upstream commit:

   2084c24a8141 do not export kernel's NULL #define to userspace

Fix that.

Reported-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00
Asias He e5f41ac455 kvm tools: Update README for CONFIG_FB_VESA
CONFIG_FB_VESA is needed for --sdl or --vnc. Update README for it.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:51 +01:00