Remove some redundant members between struct kvm_config and struct kvm
since options are now contained within struct kvm.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Contain the options within struct kvm itself. This way options are specific
to a given struct kvm and not just global.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Move all the non-arch specific members into a generic struct, and the arch specific
members into a arch specific kvm_arch. This prevents code duplication across different
archs.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Since we now store options in a struct, we should generate the command line options
dynamically. This is a pre-requisite to the following patch moving the options
into struct kvm.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Move all the configurable options from global static variables to a self-contained
structure.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
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>
Instead of a get/set for config values, just request the address of the
config region, and handle that by simply reading directly from that region.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
We're not supposed to kill all fids when a new attach request
arrives. This used to cause issues when the guest would send
multiple attach requests.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Build with -flto set, which should enable link-time-optimizations.
I'm not sure if it provides a significant performance increase, but
it's probably just worth it for catching issues which it may cause.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Fix up warnings related to not checking return value of read/write by actually
handling errors there.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
We still create GSIs and keep them for two reasons:
- They're required by virtio-* devices.
- There's not much overhead since we just create them when starting the
guest, they don't use anything when the guest is running.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
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>
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>
Respect guest tcp window size and stop sending tcp segments to guest
if guest's receive window is closed.
This fixes the TCP hang I'm seeing where guest and host are transferring
big chuck of data.
This problem was not triggered when guest and external host
communicates, probably because guest to external host communication
walks through real network and is much slower than guest and host
communication. Thus, guest's receive window has little chance to be
closed.
v2: use pthread_cond_wait to wait
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This pach makes tcp between 'guest ip' and 'host virtual ip' work in UIP mode.
(The defulat guest ip is 192.168.33.15, host virtual ip is 192.168.33.1)
guest$ wget http://192.168.33.1/file
guest$ ssh 192.168.33.1
Without this patch, user has to figure out the ip address of host's
interface (e.g. eth0) and use that ip address to access host.
With this patch, user can simply use the virtual host ip.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
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>
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>
We generate guest init and init_stage2 on the fly and put them in
~/.lkvm/$guest/virt/init
~/.lkvm/$guest/virt/init_stage2
.
This makes 'lkvm run' no longer depending on guest/{int, init_stage2}.
Further, we can merge init and init_stage2 since there is no need to
split the init function into two stages any more.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch brings virito-scsi support to kvm tool.
With the introduce of tcm_vhost (vhost-scsi)
tcm_vhost: Initial merge for vhost level target fabric driver
we can implement virito-scsi by simply having vhost-scsi to handle the
SCSI command.
Howto use:
1) Setup the tcm_vhost target through /sys/kernel/config
[Stefan Hajnoczi, Thanks for the script to setup tcm_vhost]
** Setup wwpn and tpgt
$ wwpn="naa.0"
$ tpgt=/sys/kernel/config/target/vhost/$wwpn/tpgt_0
$ nexus=$tpgt/nexus
$ mkdir -p $tpgt
$ echo -n $wwpn > $nexus
** Setup lun using /dev/ram
$ n=0
$ lun=$tpgt/lun/lun_${n}
$ data=/sys/kernel/config/target/core/iblock_0/data_${n}
$ ram=/dev/ram${n}
$ mkdir -p $lun
$ mkdir -p $data
$ echo -n udev_path=${ram} > $data/control
$ echo -n 1 > $data/enable
$ ln -s $data $lun
2) Run kvm tool with the new disk option '-d scsi:$wwpn:$tpgt', e.g
$ lkvm run -k /boot/bzImage -d ~/img/sid.img -d scsi:naa.0:0
Signed-off-by: Asias He <asias.hejun@gmail.com>
Cc: Nicholas A. Bellinger <nab@linux-iscsi.org>
Cc: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Add a new 'install' target to Makefile that installs 'lkvm' binary to
$HOME/bin by default. The installed binary still needs to be launched
from linux/tools/kvm directory because of our silly external dependency
to stage 2 guest init file:
[penberg@tux ~]$ lkvm run
Fatal: Failed linking stage 2 of init.
The most convinent way to fix that is to embed the stage 2 image in
'lkvm' executable like we do with our mini-BIOS.
Signed-off-by: Pekka Enberg <penberg@kernel.org>
The segfault is triggered by just running "lkvm run". On my system, it
does not find any kernel, so kvm_cmd_run_init() returns EINVAL which
fails the (r < 0) check in kvm_cmd_run(). Since kvm_cmd_run_init() does
not get to initialize the cpus, kvm_cpus gets mistakenly dereferenced in
kvm_cmd_run_work().
The errors from kvm_cmd_run_init() are not handled properly as they are
returned as positive values.
Acked-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Paul Neumann <paul104x@yahoo.de>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Currently the parsing of network command line parameters doesn't check
for unknown parameters.
For example "-n mod=none" will cause kvmtool to setup TAP networking.
Save users from their typos by checking for unknown parameters and bailing.
Acked-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This error message is missing a space, and has a redundant ":" at the end,
currently it produces:
You have requested a TAP device, but creation of one hasfailed because:: No such file or directory
Add a space to "hasfailed" and remove the extra ":".
Don't split the line to improve grepability.
Acked-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
In uip_dhcp_get_dns() we try to open /etc/resolv.conf. If we fail to
open it we then SEGV trying to fclose() it.
Fix the code to just return directly if we can't open it.
Acked-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This is something we can calculate on the fly, and doesn't justify the overhead
of tracking it all over fid transitions.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Use the new KVM_KVMCLOCK_CTRL ioctl to prevent guests from wrongfully
detecting lockups when in fact they were paused.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
With Direct I/O, file reads and writes go directly from the applications
to the storage device, bypassing the operating system read and write
caches. This is useful for applications that manage their own caches.
Open a disk image with O_DIRECT:
$ lkvm run -d ~/img/test.img,direct
The original readonly flag is still supported.
Open a disk image with O_DIRECT and readonly:
$ lkvm run -d ~/img/test.img,direct,ro
Signed-off-by: Asias He <asias.hejun@gmail.com>
Acked-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>