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>
* Pekka Enberg <penberg@kernel.org> wrote:
> >In file included from virtio/net.c:3:0:
> >include/kvm/virtio.h: In function ‘virt_queue__available’:
> >include/kvm/virtio.h:42:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
> It's tools/kvm/include/kvm/virtio.h:
>
> static inline bool virt_queue__available(struct virt_queue *vq)
> {
> if (!vq->vring.avail)
> return 0;
>
> vring_avail_event(&vq->vring) = vq->last_avail_idx;
> return vq->vring.avail->idx != vq->last_avail_idx;
> }
>
> and include/linux/virtio_ring.h:
>
> #define vring_avail_event(vr) (*(__u16 *)&(vr)->used->ring[(vr)->num])
>
> I'm not sure what GCC thinks is wrong there...
i suspect the contrast might be from casting a 'struct
vring_used_elem's 'id' field to type '__u16 *' and dereferencing
it might break GCC alias optimizations, as it makes two uses of
the 'num' field - one the regular 32-bit usage, the other this
weird 16-bit usage.
I think the only sane way to solve this is to do what the kernel
does, to turn off strict aliasing. The patch below does this and
resolves the build bug. Note: i also switched optimization from
-Os to -O2 - the latter is generally the better option for
performance critical code. -Os sometimes produces really weird
code.
The other build problem is that it appears the default GCC
regparm model changed, which highlighted this prototype bug:
x86/bios/e820.c:32:15: error: conflicting types for ‘e820_query_map’
In file included from x86/bios/e820.c:1:0:
include/kvm/e820.h:10:6: note: previous declaration of ‘e820_query_map’ was here
and there are similar problems with other BIOS prototypes.
Resolved via the other bits in the patch below.
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
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>
This patch adds the possibility to run commands using the default parameter
in 'lkvm sandbox'. For example, a user would now be able to run:
'lkvm sandbox firefox'
And have a sandboxed firefox instance start in the guest.
For commands with parameters, we still need to use dashdash to pass the
parameters (similar to 'git bisect run'). For example:
'lkvm sandbox -- ls -al /bin
Suggested-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
write_in_full() would not return until count byes has been written or
error has occurred.
So
if (write_in_full(fd, buf, count) < 0)
goto err;
is enough.
And
if (write_in_full(fd, buf, count) != count)
goto err;
is not necessary.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
CC kvm-ipc.o
kvm-ipc.c: In function ???kvm_ipc__send_msg???:
kvm-ipc.c:53:34: error: comparison between signed and unsigned integer
expressions [-Werror=sign-compare]
cc1: all warnings being treated as errors
Reported-by: Jean-Philippe Menil <jean-philippe.menil@univ-nantes.fr>
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
If a guest's ram_size exceeds KVM_32BIT_GAP_START, the corresponding kvm tool's
virtual address size should be (ram_size + KVM_32BIT_GAP_SIZE), rather than ram_size.
Use macro define KVM_32BIT_MAX_MEM_SIZE instead of magic number "0x100000000ULL".
Signed-off-by: Hongyong Zang <zanghongyong@huawei.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch fixes the following valgrind reported memory leak:
==7684== 20 bytes in 8 blocks are definitely lost in loss record 3 of 46
==7684== at 0x4A0649D: malloc (vg_replace_malloc.c:236)
==7684== by 0x4116B5: virtio_p9_pdu_readf (9p-pdu.c:110)
==7684== by 0x40FD8C: virtio_p9_attach (9p.c:354)
==7684== by 0x410E80: virtio_p9_do_io (9p.c:1154)
==7684== by 0x40DB45: thread_pool__threadfunc (threadpool.c:56)
==7684== by 0x3DE7007B30: start_thread (in /lib64/libpthread-2.14.so)
==7684== by 0x3DE68DFD2C: clone (in /lib64/libc-2.14.so)
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch fixes the following valgrind reported memory leak in
virtio_9p_walk():
==6689== 1,058 bytes in 134 blocks are definitely lost in loss record 39 of 47
==6689== at 0x4A0649D: malloc (vg_replace_malloc.c:236)
==6689== by 0x4116A9: virtio_p9_pdu_readf (9p-pdu.c:110)
==6689== by 0x40FB9F: virtio_p9_walk (9p.c:305)
==6689== by 0x410E73: virtio_p9_do_io (9p.c:1151)
==6689== by 0x40DB45: thread_pool__threadfunc (threadpool.c:56)
==6689== by 0x3DE7007B30: start_thread (in /lib64/libpthread-2.14.so)
==6689== by 0x3DE68DFD2C: clone (in /lib64/libc-2.14.so)
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch silences the following harmless warning to reduce valgrind noise:
==5529== 864 bytes in 3 blocks are possibly lost in loss record 39 of 48
==5529== at 0x4A04B84: calloc (vg_replace_malloc.c:467)
==5529== by 0x3DE6410D44: _dl_allocate_tls (in /lib64/ld-2.14.so)
==5529== by 0x3DE70082F5: pthread_create@@GLIBC_2.2.5 (in /lib64/libpthread-2.14.so)
==5529== by 0x405755: kvm_cmd_run (builtin-run.c:1169)
==5529== by 0x40D47D: handle_command (kvm-cmd.c:84)
==5529== by 0x3DE682139C: (below main) (in /lib64/libc-2.14.so)
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Valgrind reports the following use after free error, when shutting down a
guest:
[penberg@tux kvm]$ valgrind ./vm run
[ snip ]
Mounting...
Starting '/bin/sh'...
sh-4.2# exit
[ snip ]
==4726== Thread 11:
==4726== Invalid read of size 8
==4726== at 0x407818: kvm__continue (kvm.c:518)
==4726== by 0x3DE683534F: ??? (in /lib64/libc-2.14.so)
==4726== by 0x3DE68D8AF6: ioctl (in /lib64/libc-2.14.so)
==4726== by 0x406C95: kvm_cpu__run (kvm-cpu.c:35)
==4726== by 0x406D95: kvm_cpu__start (kvm-cpu.c:109)
==4726== by 0x4046D5: kvm_cpu_thread (builtin-run.c:603)
==4726== by 0x3DE7007B30: start_thread (in /lib64/libpthread-2.14.so)
==4726== by 0x3DE68DFD2C: clone (in /lib64/libc-2.14.so)
==4726== Address 0x4c2e040 is 0 bytes inside a block of size 936 free'd
==4726== at 0x4A055FE: free (vg_replace_malloc.c:366)
==4726== by 0x4046E7: kvm_cpu_thread (builtin-run.c:606)
==4726== by 0x3DE7007B30: start_thread (in /lib64/libpthread-2.14.so)
==4726== by 0x3DE68DFD2C: clone (in /lib64/libc-2.14.so)
==4726==
==4726== Thread 1:
==4726== Invalid read of size 1
==4726== at 0x4057BC: kvm_cmd_run (builtin-run.c:1182)
==4726== by 0x40D46D: handle_command (kvm-cmd.c:84)
==4726== by 0x3DE682139C: (below main) (in /lib64/libc-2.14.so)
==4726== Address 0x4e36f58 is 920 bytes inside a block of size 936 free'd
==4726== at 0x4A055FE: free (vg_replace_malloc.c:366)
==4726== by 0x4046E7: kvm_cpu_thread (builtin-run.c:606)
==4726== by 0x3DE7007B30: start_thread (in /lib64/libpthread-2.14.so)
==4726== by 0x3DE68DFD2C: clone (in /lib64/libc-2.14.so)
This patch fixes the problem by moving the kvm_cpu__delete() call from
kvm_cpu_thread() to kvm_cmd_run() after we've made sure the VCPU thread is
stopped.
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Pick arch/$ARCH/boot/bzImage and vmlinux if we are in linux source tree root directory.
Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
It is user's or other program's reponsibility, not the current program.
Just try best to let the user know what happen.
Also make print_guest() keep the same behavior as do_debug()
do_pause() ...etc. when it failed.
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
comm is unused ==> fscanf() is unused ==> fd is unused
==> proc_name is unused.
so all this code can be removed.
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
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>
Remove this annoying message if user resumes or pauses a guest which
is already resumed or paused.
Warning: (builtin-run.c) handle_pause:520: failed condition: 1
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
lkvm {pause,resume} do not give any feedback to user who uses these
commands in the console where the command run.
This patch makes the command output in the command console instead of
guest console.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
'./lkvm list' does not give the correct vm status if the vm is paused
currently.
This patch fixes this by using KVM_IPC_VMSTATE IPC cmd to query the vm
status.
Suppose the guest is paused by ./lkvm pause:
Before:
asias@hj$ ./lkvm list
PID NAME STATE
------------------------------------
3036 guest-3036 running
default shut off
After:
asias@hj$ ./lkvm list
PID NAME STATE
------------------------------------
3036 guest-3036 paused
default shut off
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This can be used to get vm status information:
vm is running or paused.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This is useful when client submiting multiple IPC cmd in one socket
connection.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Adding FIFO functionality to the serial emulator to speed up the
console handling.
This also restricts sysrq functionality to the first serial port and
fixes the sysrq injection, which was broken because nothing ever reset
the BI status bit in the LSR.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
The commit 2b6c246215e8f936d2366ef8c4a6eec730b819b2
(kvm tools: Use compat message per device instead of per instance)
prevents multiple messages for the same type of device.
The variable compat_id is expected to be initialized to -1.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
If the guest is stopped, there is no need to run it.
This patch fixes this when running 'lkvm stop'.
KVM_RUN failed: Bad address
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Currently, 'lkvm stop' can not stop a pasued guest becasue
guest is blocked on the pause_lock.
This patch fixes it by un-pausing the guest before stops it.
The pthread_kill() call is not needed.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>