This patch reworks on virtio transport abstraction.
* Move virtio transport operations to virtio operations and drop
virtio/trans.c This makes the abstraction much cleaner.
* Rename struct virtio_trans to struct virtio_device
struct virtio_trans {
void *virtio;
enum virtio_trans_type type;
struct virtio_trans_ops *trans_ops;
struct virtio_ops *virtio_ops;
};
struct virtio_device {
void *virtio;
struct virtio_ops *ops;
};
The virtio_trans struct is bit confusing since it also includes virtio
operations.
* Introduce virtio_init()
To init device, e.g.
Before:
virtio_trans_init()
ndev->vtrans.trans_ops->init()
ndev->vtrans.virtio_ops = &net_dev_virtio_ops
After:
virtio_init()
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Add is_pio flag to set KVM_IOEVENTFD_FLAG_PIO. This is useful for
attaching an ioeventfd to MMIO address as well as PIO address.
virtio-mmio needs an ioeventfd to MMIO address.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
The realpath() function can fail, so check for errors to fix up compilation
with "-Werror".
Reported-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Otherwise overlaps might happen (and actually having anything but .text
here at moment make no sense) and it triggers the following error on
Golden ld
# ld: error: load segment overlap [0x0 -> 0x38c] and [0x0 -> 0x0]
Reported-and-tested-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch changes 'vm sandbox' to automatically prefix a program path with
"/host" in the guest side making this, for example, work as expected:
$ ./vm sandbox -- ~/trinity/trinity --mode=random --dangerous
Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
In case if no firmware used we should put mptables
at repdefined address thus kernel scanner will recognized
it.
For this make a distinction between firmware address
and own bios address.
Reported-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
SeaBIOS outputs debugging messages to special debug port ("0x0402"). This patch
unconditionally hooks the PIO port to LKVM so that when user specifies a
SeaBIOS image, you'll see this for "vm run":
[penberg@tux kvm]$ ./vm run --firmware /usr/share/seabios/bios.bin
# lkvm run -k ../../arch/x86/boot/bzImage -m 448 -c 4 --name guest-25983
Start bios (version 0.6.0)
Unable to unlock ram - bridge not found
Ram Size=0x00100000 (0x0000000000000000 high)
<hangs here>
Once we have SeaBIOS fully operational, we probably should hide the feature
under "--debug-seabios" command line option.
Acked-by Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Yang Bai <hamo.by@gmail.com>
Cc: Matt Evans <matt@ozlabs.org>
Cc: Ron Minnich <rminnich@gmail.com>
Cc: Anthony Liguori <aliguori@us.ibm.com>
Cc: John Floren <john@jfloren.net>
Cc: Sasha Levin <levinsasha928@gmail.com>
Cc: Asias He <asias.hejun@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch adds a "--firmware" command line option to "vm run". You can use
this to try to boot with SeaBIOS, for example:
./vm run --firmware=/usr/share/seabios/bios.bin \
--disk $HOME/images/debian_lenny_amd64_standard.qcow2
This doesn't boot yet for obvious reasons but at least people can now start to
play with external BIOS images easily.
Acked-by Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Yang Bai <hamo.by@gmail.com>
Cc: Matt Evans <matt@ozlabs.org>
Cc: Ron Minnich <rminnich@gmail.com>
Cc: Anthony Liguori <aliguori@us.ibm.com>
Cc: John Floren <john@jfloren.net>
Cc: Sasha Levin <levinsasha928@gmail.com>
Cc: Asias He <asias.hejun@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
By checking the return value from kvm_ipc__register_handler,
we can ensure that it succeeds.
Signed-off-by: Yang Bai <hamo.by@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
If kvm_ipc__start failed, it returns a negative and by checking
this return value, we can ensure that it succeeds.
Signed-off-by: Yang Bai <hamo.by@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
When error occurs, just set the ret to the reason,
then jump to the error handle labels.
This makes the code more readable.
Signed-off-by: Yang Bai <hamo.by@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
If kvm__check_extensions found that some of the required
KVM extention is not supported by OS, we should stop the
init and free all allocated resources.
Signed-off-by: Yang Bai <hamo.by@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Since 44287dd (Repair running on non ioeventfd-capable platforms)
it's possible that ioeventfd__init() fails, but the VM still runs.
This means we end up calling ioeventfd__exit(), which writes()
and then reads() epoll_stop_fd. Because we failed the init,
epoll_stop_fd is 0, so we end up writing/reading stdin, which
exhibits as kvm-tool blocking until something is entered on the
console.
Once we break out of the read we close epoll_fd and epoll_stop_fd,
both 0, and so term_exit() fails to cleanup the terminal properly.
The fix is simply to check ioeventfd_avail in ioevetfd__exit() and
do nothing if it is false.
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
By "enable", I mean "fix"; the re-jigged commit 7ef85e8b builds libfdt
using OBJS rather than OTHEROBJS hence ignores the relaxed CFLAGS.
This commit builds it via OTHEROBJS.
Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
In case if there error happened in kvm__init and we have
no files opened -- we should not try to close them.
Also once kvm failed to init the caller should not try
to dereference a pointer obtained, otherwise we might get
SIGSEV
| [cyrill@moon kvm]$ ./lkvm run ...
| Error: '/dev/kvm' not found. Please make sure your kernel has CONFIG_KVM
| enabled and that the KVM modules are loaded.
| Segmentation fault (core dumped)
| [cyrill@moon kvm]$
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
If default guest name is used (which is the default
case) the kvm might end up carrying the pointer to
a name which is allocated on stack.
kvm_cmd_run_init
(on stack) default_name
kvm__init(..., default_name)
kvm->name = default_name
So make it to carry a copy of name.
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This is the final piece of the puzzle for PPC SPAPR PCI; this
function splits MMIO accesses into the two PHB windows & directs
things to MMIO/IO emulation as appropriate.
Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This provides the PCI bridge, definitions for the address layout of the windows
and wires in IRQs. Once PCI devices are all registered, they are enumerated and
DT nodes generated for each.
Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch adds XICS emulation code (heavily borrowed from QEMU), and wires
this into kvm_cpu__irq() to fire a CPU IRQ via KVM. A device tree entry is
also added. IPIs work, xics_alloc_irqnum() is added to allocate an external
IRQ (which will later be used by the PHB PCI code) and finally, kvm__irq_line()
can be called to raise an IRQ on XICS.
Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This adds the console code, plus VIO HV terminal nodes are added to
the device tree so the guest kernel will pick it up.
Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch adds the basic structure for HV calls, their registration and some of
the simpler calls. A similar layout for RTAS calls is also added, again with
some of the simpler RTAS calls used by the guest. The SPAPR RTAS stub is
generated inline. Also, nodes for RTAS are added to the device tree.
Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
The generated DT is the bare minimum structure required for SPAPR (on which
subsequent patches for VIO, XICS, PCI etc. will build); root node, cpus, memory.
The DT contains CPU-specific configuration; a very simple 'cpu info' mechanism
is added to recognise/differentiate DT entries for POWER7 and PPC970 host CPUs.
Future support of more CPUs is possible.
libfdt is included from scripts/dtc/libfdt.
Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Allocate a page table and point SDR1 to it in order to support the -PR
PPC64 KVM mode. (The alternative, -HV mode, is available only on a small
set of machines.)
This patch also removes the previous dependency on mapping guest RAM with
huge pages; PR KVM doesn't require them so the user isn't forced to use them.
A new option, '--hugetlbfs default', uses a default path for 16M pages for
HV mode, if required.
Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Sasha noticed during code review that commit e106906 ("kvm tool: Change
kvm->ram_size to real mapped size.") changed kvm->ram_size accounting to
include 32-bit memory hole but forgot to update munmap in
kvm__arch_delete_ram().
Reported-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
There's absolutely no point in printing out an error message for symbol lookup
init failure because we run just fine without them.
Suggested-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Valgrind spotted another issue:
==2343== Invalid read of size 8
==2343== at 0x408EAD: kvm__pause (kvm.c:529)
==2343== by 0x407E07: ioport__unregister (ioport.c:100)
==2343== by 0x409537: pci__exit (pci.c:210)
==2343== by 0x406303: kvm_cmd_run (builtin-run.c:1314)
==2343== by 0x410670: handle_command (kvm-cmd.c:84)
==2343== by 0x3DE682139C: (below main) (in /lib64/libc-2.14.so)
==2343== Address 0x4c30ca0 is 0 bytes inside a block of size 520 free'd
==2343== at 0x4A055FE: free (vg_replace_malloc.c:366)
==2343== by 0x406293: kvm_cmd_run (builtin-run.c:1292)
==2343== by 0x410670: handle_command (kvm-cmd.c:84)
==2343== by 0x3DE682139C: (below main) (in /lib64/libc-2.14.so)
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Valgrind spotted this issue with KVM tool shutdown:
==1823== Invalid read of size 8
==1823== at 0x410DD0: rb_next (rbtree.c:390)
==1823== by 0x417376: irq__exit (irq.c:182)
==1823== by 0x406230: kvm_cmd_run (builtin-run.c:1275)
==1823== by 0x410670: handle_command (kvm-cmd.c:84)
==1823== by 0x3DE682139C: (below main) (in /lib64/libc-2.14.so)
==1823== Address 0x4f7cca0 is 0 bytes inside a block of size 48 free'd
==1823== at 0x4A055FE: free (vg_replace_malloc.c:366)
==1823== by 0x41736E: irq__exit (irq.c:192)
==1823== by 0x406230: kvm_cmd_run (builtin-run.c:1275)
==1823== by 0x410670: handle_command (kvm-cmd.c:84)
==1823== by 0x3DE682139C: (below main) (in /lib64/libc-2.14.so)
Fix it up.
Signed-off-by: Pekka Enberg <penberg@kernel.org>
On error mmap returns MAP_FAILED so we need a proper test here.
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit adds a target for 'lkvm-static' which is linked -static.
(This can be useful to construct kvmtool binaries for minimalist
auto-test host filesystems.)
Since extra features (SDL, AIO, VNC etc.) are auto-detected in the makefile
AND some features may only work when linked one way (but not both), the
feature detection now checks for both dynamic & static success. Intermediate
objects build with correct flags (e.g. CONFIG_HAS_AIO) for the end target.
Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
- drop double underscopes in names
- a variable which return integer error
code should be either 'ret' either 'err'
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Commit d3923126a24212f1e746a84a575dadbd9f259418 added a bunch of
nice error checking around ioevent__init() but the init may gracefully
fail if ioevents simply aren't supported (PPC64 KVM).
This commit adds a new return code for the init -- positive, but
identifiable as 'not success 0'.
Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Commit b50cac5 ("PCI/sysfs: add per pci device msi[x] irq listing (v5)") added
"struct kobject" dependency to <linux/msi.h> which breaks KVM tool build. As
the header file is no longer about MSI hardware, make a new header file for
"struct msi_ms".
Reported-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@kernel.org>