]> git.karo-electronics.de Git - karo-tx-linux.git/log
karo-tx-linux.git
12 years agokvm tools: Remove tags/TAGS on "make clean"
Cyrill Gorcunov [Sun, 15 Jan 2012 13:15:45 +0000 (17:15 +0400)]
kvm tools: Remove tags/TAGS on "make clean"

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Remove bogus init printout
Pekka Enberg [Sun, 15 Jan 2012 13:02:40 +0000 (15:02 +0200)]
kvm tools: Remove bogus init printout

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>
12 years agokvm tools: Improve 'lkvm sandbox' syntax
Sasha Levin [Fri, 13 Jan 2012 09:42:05 +0000 (11:42 +0200)]
kvm tools: Improve 'lkvm sandbox' syntax

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>
12 years agokvm tools: Simply write_in_full() check semantics
Asias He [Mon, 9 Jan 2012 09:19:26 +0000 (17:19 +0800)]
kvm tools: Simply write_in_full() check semantics

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>
12 years agokvm tools: Fix kvm-ipc.c build breakage
Asias He [Mon, 9 Jan 2012 09:18:01 +0000 (17:18 +0800)]
kvm tools: Fix kvm-ipc.c build breakage

      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>
12 years agokvm tool: Change kvm->ram_size to real mapped size.
Hongyong Zang [Fri, 6 Jan 2012 02:06:26 +0000 (10:06 +0800)]
kvm tool: Change kvm->ram_size to real mapped size.

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>
12 years agokvm tools, 9p: Fix memory leak in virtio_9p_attach()
Pekka Enberg [Tue, 3 Jan 2012 17:49:49 +0000 (19:49 +0200)]
kvm tools, 9p: Fix memory leak in virtio_9p_attach()

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>
12 years agokvm tools, 9p: Fix memory leak in virtio_p9_walk()
Pekka Enberg [Tue, 3 Jan 2012 17:39:14 +0000 (19:39 +0200)]
kvm tools, 9p: Fix memory leak in virtio_p9_walk()

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>
12 years agokvm tools: Free vcpu array on shutdown
Pekka Enberg [Tue, 3 Jan 2012 17:25:28 +0000 (19:25 +0200)]
kvm tools: Free vcpu array on shutdown

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>
12 years agokvm tools: Fix use after free during shutdown
Pekka Enberg [Tue, 3 Jan 2012 17:20:23 +0000 (19:20 +0200)]
kvm tools: Fix use after free during shutdown

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>
12 years agokvm tools: pick kernel from linux source tree root
Konstantin Khlebnikov [Wed, 21 Dec 2011 11:18:00 +0000 (14:18 +0300)]
kvm tools: pick kernel from linux source tree root

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>
12 years agokvm tools: Add kvm__arch_delete_ram()
Lai Jiangshan [Tue, 27 Dec 2011 07:36:41 +0000 (15:36 +0800)]
kvm tools: Add kvm__arch_delete_ram()

unmap all the memory maped memory for guest ram.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Don't remove any file which is not created by itself
Lai Jiangshan [Tue, 27 Dec 2011 07:36:38 +0000 (15:36 +0800)]
kvm tools: Don't remove any file which is not created by itself

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>
12 years agokvm tools: Check the state before pause/resume
Lai Jiangshan [Tue, 27 Dec 2011 07:36:37 +0000 (15:36 +0800)]
kvm tools: Check the state before pause/resume

Let the user know what happened

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Remove unused code for print_guest()
Lai Jiangshan [Tue, 27 Dec 2011 07:36:36 +0000 (15:36 +0800)]
kvm tools: Remove unused code for print_guest()

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>
12 years agokvm tools: use custom rootfs_name for guest name
Lai Jiangshan [Tue, 27 Dec 2011 07:36:35 +0000 (15:36 +0800)]
kvm tools: use custom rootfs_name for guest name

It is better than a anonymous "guest-xxx".

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: fix a typo in x86/bios.c
Xiaochen Wang [Mon, 2 Jan 2012 13:21:17 +0000 (21:21 +0800)]
kvm tools: fix a typo in x86/bios.c

Fix a typo: 'hadler' -> 'handler'

Signed-off-by: Xiaochen Wang <wangxiaochen0@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tool: Exit init only when /bin/sh itself stops
Sasha Levin [Mon, 26 Dec 2011 10:18:23 +0000 (12:18 +0200)]
kvm tool: Exit init only when /bin/sh itself stops

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>
12 years agokvm tools: Use kvm_ipc__send to send IPC msg
Asias He [Thu, 22 Dec 2011 02:10:47 +0000 (10:10 +0800)]
kvm tools: Use kvm_ipc__send to send IPC msg

No need to send IPC msg using bare write() any more.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Remove resume pause noise.
Asias He [Thu, 22 Dec 2011 02:10:46 +0000 (10:10 +0800)]
kvm tools: Remove resume pause noise.

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>
12 years agokvm tools: Improve 'lkvm {pause,resume}'s output
Asias He [Thu, 22 Dec 2011 02:10:45 +0000 (10:10 +0800)]
kvm tools: Improve 'lkvm {pause,resume}'s output

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>
12 years agokvm tools: Respect paused status in ./lkvm list
Asias He [Thu, 22 Dec 2011 02:10:44 +0000 (10:10 +0800)]
kvm tools: Respect paused status in ./lkvm list

'./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>
12 years agokvm tools: Introduce KVM_IPC_VMSTATE IPC cmd
Asias He [Thu, 22 Dec 2011 02:10:43 +0000 (10:10 +0800)]
kvm tools: Introduce KVM_IPC_VMSTATE IPC cmd

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>
12 years agokvm tools: Handle multiple IPC cmd at a time
Asias He [Thu, 22 Dec 2011 02:10:42 +0000 (10:10 +0800)]
kvm tools: Handle multiple IPC cmd at a time

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>
12 years agokvm tools: cleanup useless arguments in kvm__arch_init
Wanlong Gao [Wed, 21 Dec 2011 23:40:37 +0000 (07:40 +0800)]
kvm tools: cleanup useless arguments in kvm__arch_init

Remove useless arguments kvm_dev and name.

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tool: Implement a serial FIFO emulation
Thomas Gleixner [Wed, 21 Dec 2011 15:38:10 +0000 (16:38 +0100)]
kvm tool: Implement a serial FIFO emulation

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>
12 years agokvm tools: Fix compat message per device for virtio/blk
Asias He [Wed, 21 Dec 2011 15:11:10 +0000 (23:11 +0800)]
kvm tools: Fix compat message per device for virtio/blk

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>
12 years agokvm tools: Do not run guest if it is stopped.
Asias He [Wed, 21 Dec 2011 13:47:11 +0000 (21:47 +0800)]
kvm tools: Do not run guest if it is stopped.

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>
12 years agokvm tools: Fix 'lkvm stop' when guest is pasued.
Asias He [Wed, 21 Dec 2011 13:47:10 +0000 (21:47 +0800)]
kvm tools: Fix 'lkvm stop' when guest is pasued.

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>
12 years agokvm tools: Remove lkvm alias vm in 'make clean'
Asias He [Wed, 21 Dec 2011 08:07:21 +0000 (16:07 +0800)]
kvm tools: Remove lkvm alias vm in 'make clean'

lkvm alias vm is not removed in 'make clean'.
This patch fixes this.

Reviewed-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tool: Introduce own BUG_ON handler
Cyrill Gorcunov [Tue, 20 Dec 2011 16:58:35 +0000 (20:58 +0400)]
kvm tool: Introduce own BUG_ON handler

Raise SIGABRT in case if run-time crtitical
problem found.

Proposed-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Don't panic guest when exiting from custom rootfs
Sasha Levin [Tue, 20 Dec 2011 10:23:20 +0000 (12:23 +0200)]
kvm tools: Don't panic guest when exiting from custom rootfs

We currently panic guest when exiting from custom rootfs since at that point
we terminate init, and the guest kernel doesn't quite like that.

Instead, we do a graceful shutdown when init is done (either when 'lkvm
sandbox' command or '/bin/sh' is finished).

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: carefully send and handle balloon stat ipc
Lai Jiangshan [Tue, 20 Dec 2011 09:08:57 +0000 (17:08 +0800)]
kvm tools: carefully send and handle balloon stat ipc

Remove struct stat_cmd and use kvm_ipc__send().

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: carefully send and handle pause/resume ipc
Lai Jiangshan [Tue, 20 Dec 2011 09:08:56 +0000 (17:08 +0800)]
kvm tools: carefully send and handle pause/resume ipc

Remove struct pause_cmd/resume_cmd and use kvm_ipc__send().

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: carefully send and handle debug ipc
Lai Jiangshan [Tue, 20 Dec 2011 09:08:55 +0000 (17:08 +0800)]
kvm tools: carefully send and handle debug ipc

Remove struct debug_cmd and use kvm_ipc__send_msg().

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: carefully send and handle balloon ipc
Lai Jiangshan [Tue, 20 Dec 2011 09:08:54 +0000 (17:08 +0800)]
kvm tools: carefully send and handle balloon ipc

Remove struct balloon_cmd and use kvm_ipc__send_msg().

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: carefully send and handle stop ipc
Lai Jiangshan [Tue, 20 Dec 2011 09:08:53 +0000 (17:08 +0800)]
kvm tools: carefully send and handle stop ipc

Remove struct stop_cmd and use kvm_ipc__send().

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: add WARN_ON()
Lai Jiangshan [Tue, 20 Dec 2011 09:08:52 +0000 (17:08 +0800)]
kvm tools: add WARN_ON()

like the WARN_ON() of kernel code.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: add kvm_ipc__send() and kvm_ipc__send_msg()
Lai Jiangshan [Tue, 20 Dec 2011 09:08:51 +0000 (17:08 +0800)]
kvm tools: add kvm_ipc__send() and kvm_ipc__send_msg()

Current code write the sock manually. There is nothing constrains the format of
the written data is expect. Use kvm_ipc__send() and kvm_ipc__send_msg() for
such constraint.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: add kvm_ipc__receive()
Lai Jiangshan [Tue, 20 Dec 2011 09:08:50 +0000 (17:08 +0800)]
kvm tools: add kvm_ipc__receive()

Rename struct kvm_ipc_msg to struct kvm_ipc_head.
Change current kvm_ipc__new_data() to kvm_ipc__receive().
Don't allocate memory for the msg head.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: cleanup kvm_ipc__handle()
Lai Jiangshan [Tue, 20 Dec 2011 09:08:49 +0000 (17:08 +0800)]
kvm tools: cleanup kvm_ipc__handle()

Make it be a static function.
Expland to kvm_ipc_msg to its arguments.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: cleanup kvm_cmd_stop()
Lai Jiangshan [Tue, 20 Dec 2011 09:08:48 +0000 (17:08 +0800)]
kvm tools: cleanup kvm_cmd_stop()

Use stack variable.
Remove unneeded branch.
Close opened file.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: cleanup kvm_cmd_stat()
Lai Jiangshan [Tue, 20 Dec 2011 09:08:47 +0000 (17:08 +0800)]
kvm tools: cleanup kvm_cmd_stat()

Use stack variable.
Remove unneeded branch.
Close opened file.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: cleanup kvm_cmd_resume()
Lai Jiangshan [Tue, 20 Dec 2011 09:08:46 +0000 (17:08 +0800)]
kvm tools: cleanup kvm_cmd_resume()

Use stack variable.
Remove unneeded branch.
Close opened file.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: cleanup kvm_cmd_pause()
Lai Jiangshan [Tue, 20 Dec 2011 09:08:45 +0000 (17:08 +0800)]
kvm tools: cleanup kvm_cmd_pause()

Use stack variable.
Remove unneeded branch.
Close opened file.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: cleanup kvm_cmd_debug()
Lai Jiangshan [Tue, 20 Dec 2011 09:08:44 +0000 (17:08 +0800)]
kvm tools: cleanup kvm_cmd_debug()

Use stack variable.
Remove unneeded branch.
Close opened file.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: cleanup kvm_cmd_balloon()
Lai Jiangshan [Tue, 20 Dec 2011 09:08:43 +0000 (17:08 +0800)]
kvm tools: cleanup kvm_cmd_balloon()

Use stack variable.
Remove unneeded branch.
Close opened file.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: mark usages functions as NORETURN
Lai Jiangshan [Tue, 20 Dec 2011 09:08:42 +0000 (17:08 +0800)]
kvm tools: mark usages functions as NORETURN

It will help for simplifying codes like this:

{
if (cond == NULL)
NORETURN_func();

/* use cond safely, it is not NULL and don't need to check it again */
}

It also helps for readability.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Avoid overflow
Lai Jiangshan [Tue, 20 Dec 2011 09:08:41 +0000 (17:08 +0800)]
kvm tools: Avoid overflow

"entry.d_name[strlen(entry.d_name)-5] = 0" may overflow
when strlen(entry.d_name) < 5.

also avoid magic number(5).

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Make kvm__arch_setup_firmware to return error code
Cyrill Gorcunov [Sun, 18 Dec 2011 20:24:56 +0000 (00:24 +0400)]
kvm tools: Make kvm__arch_setup_firmware to return error code

If some of subsequent calls fails we better to return error
code instead of dying with a message. This is a first step
in getting rid of number of die() calls we have in code.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: change the binary name from kvm to lkvm in print message
Wanlong Gao [Sat, 17 Dec 2011 14:43:08 +0000 (22:43 +0800)]
kvm tools: change the binary name from kvm to lkvm in print message

Introduce a new macro KVM_BINARY_NAME for the binary name of kvm tools,
also for future using in printing command messages like these.

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: change the binary name from kvm to lkvm for commands' usage
Wanlong Gao [Sat, 17 Dec 2011 14:43:07 +0000 (22:43 +0800)]
kvm tools: change the binary name from kvm to lkvm for commands' usage

Commands' usage : Change the binary name from *kvm* to *lkvm*,
since commit ad3efb18 has done it.

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: change the binary name from kvm to lkvm in README
Wanlong Gao [Sat, 17 Dec 2011 14:43:06 +0000 (22:43 +0800)]
kvm tools: change the binary name from kvm to lkvm in README

README: change the binary name from kvm to lkvm since
commit ad3efb18 has already done it.

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: change the binary name kvm to lkvm in Documentation
Wanlong Gao [Sat, 17 Dec 2011 14:43:05 +0000 (22:43 +0800)]
kvm tools: change the binary name kvm to lkvm in Documentation

Documentation: Change the binary name from *kvm* to *lkvm*,
since commit ad3efb18 already called the binary *lkvm* and
with a alias name *vm*.

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools, sd: Fix array size for keymap
Cyrill Gorcunov [Sun, 18 Dec 2011 18:57:21 +0000 (22:57 +0400)]
kvm tools, sd: Fix array size for keymap

Index is u8 value so array size should be 256.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Rename pr_error to pr_err to follow kernel convention
Cyrill Gorcunov [Sun, 18 Dec 2011 18:39:04 +0000 (22:39 +0400)]
kvm tools: Rename pr_error to pr_err to follow kernel convention

The kernel already has pr_err helper lets do the same.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Define __compiletime_error helper
Cyrill Gorcunov [Sun, 18 Dec 2011 15:16:09 +0000 (19:16 +0400)]
kvm tools: Define __compiletime_error helper

To eliminate compile errors like

 |  CC       builtin-run.o
 | In file included from ../../arch/x86/include/asm/system.h:7:0,
 |                 from include/kvm/barrier.h:13,
 |                 from builtin-run.c:16:
 | ../../arch/x86/include/asm/cmpxchg.h:11:13: error: no previous prototype for ‘__xchg_wrong_size’ [-Werror=missing-prototypes]
 | ../../arch/x86/include/asm/cmpxchg.h: In function ‘__xchg_wrong_size’:
 | ../../arch/x86/include/asm/cmpxchg.h:12:2: error: expected declaration specifiers before ‘__compiletime_error’

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Add BUG_ON() helper to make a run-time critical tests
Cyrill Gorcunov [Mon, 19 Dec 2011 08:25:45 +0000 (12:25 +0400)]
kvm tools: Add BUG_ON() helper to make a run-time critical tests

Also drop useless assert.h inclusions.

Acked-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: prevent the redefined error
Wanlong Gao [Sat, 17 Dec 2011 12:17:19 +0000 (20:17 +0800)]
kvm tools: prevent the redefined error

In file included from ../../include/linux/stddef.h:4:0,
                 from ../../include/linux/list.h:5,
                 from include/kvm/framebuffer.h:5,
                 from builtin-run.c:8:
include/linux/compiler.h:8:0: error: "__attribute_const__" redefined [-Werror]
/usr/include/sys/cdefs.h:226:0: note: this is the location of the previous definition
cc1: all warnings being treated as errors

make: *** [builtin-run.o] Error 1

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Fix 'make kvmconfig'
Sasha Levin [Fri, 16 Dec 2011 08:58:41 +0000 (10:58 +0200)]
kvm tools: Fix 'make kvmconfig'

Set features which depend on the config we select to make 'make kvmconfig'
non-interactive.

Acked-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm-tools: remove unneed SIGKVMXX
Lai Jiangshan [Fri, 16 Dec 2011 09:12:09 +0000 (17:12 +0800)]
kvm-tools: remove unneed SIGKVMXX

It will not be used in future either.

Acked-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm-tools: fix wrong "./lkvm list -i"
Lai Jiangshan [Fri, 16 Dec 2011 09:12:08 +0000 (17:12 +0800)]
kvm-tools: fix wrong "./lkvm list -i"

because the program name is changed, "./lkvm list -i" can't work now.
This fix just remove the test:
1) this test is not reliable.
2) the target process can respond for "get_pid()", it must be
   kvm-tool. (at least it is more reliable)

Acked-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm-tools: remove unneed sprintf("%s")
Lai Jiangshan [Fri, 16 Dec 2011 09:12:07 +0000 (17:12 +0800)]
kvm-tools: remove unneed sprintf("%s")

it makes no sense.

Acked-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm-tools: Don't create existed ~/.kvm-tools/ directory
Lai Jiangshan [Fri, 16 Dec 2011 09:12:06 +0000 (17:12 +0800)]
kvm-tools: Don't create existed ~/.kvm-tools/ directory

it is created when the progam started(in main.c).

Acked-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm-tools: write the sandbox command exactly as expect
Lai Jiangshan [Fri, 16 Dec 2011 09:12:05 +0000 (17:12 +0800)]
kvm-tools: write the sandbox command exactly as expect

sandbox.sh is a shell script, it will translate its meta
chars to anather things.

example(before this patch applied):
./lkvm sandbox -- echo 'success; please try again!'
it fails with:
/virt/sandbox.sh: line 3: please: command not found

Acked-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm-tools: only one rootfs directory atmost
Lai Jiangshan [Fri, 16 Dec 2011 09:12:03 +0000 (17:12 +0800)]
kvm-tools: only one rootfs directory atmost

It makes no sense when we use several rootfs directories. Only the last
one works.

Acked-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm-tools: remove make_root_dir()
Lai Jiangshan [Fri, 16 Dec 2011 09:12:01 +0000 (17:12 +0800)]
kvm-tools: remove make_root_dir()

The root dir was already created by kvm__set_dir() which is in main().

Acked-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm-tools: Fix error path
Lai Jiangshan [Fri, 16 Dec 2011 09:12:00 +0000 (17:12 +0800)]
kvm-tools: Fix error path

don't closedir(NULL) and return 0 when dir == NULL

Acked-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm-tools: Create util/rbtree.d
Lai Jiangshan [Fri, 16 Dec 2011 09:11:59 +0000 (17:11 +0800)]
kvm-tools: Create util/rbtree.d

I found the program is always RE-created when I type 'make' even
it is new:

$ make
  LINK     lkvm
  LN       vm

I use 'make -d' to find the reason: rbtree.d is missing.

When I type 'make' after this patch applied(the lkvm is new):

$ make
make: Nothing to be done for `all'.

Acked-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Trivial cleanup
Sasha Levin [Fri, 16 Dec 2011 08:40:06 +0000 (10:40 +0200)]
kvm tools: Trivial cleanup

Acked-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools, qcow: Add support for growing refcount blocks
Lan Tianyu [Thu, 15 Dec 2011 13:40:44 +0000 (21:40 +0800)]
kvm tools, qcow: Add support for growing refcount blocks

This patch enables allocating new refcount blocks and so then kvm tools
could expand qcow2 image much larger.

Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Use kernel error check functions
Lan Tianyu [Thu, 15 Dec 2011 13:40:14 +0000 (21:40 +0800)]
kvm tools: Use kernel error check functions

Add compiler.h file to support using kernel error check funciotns(e.g
ERR_PTR, PTR_ERR and so on).

Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Fix rootfs name resolving when specified with image
Sasha Levin [Thu, 15 Dec 2011 12:15:10 +0000 (14:15 +0200)]
kvm tools: Fix rootfs name resolving when specified with image

Fix the case when using a rootfs combined with a virtio-blk disk.

Also, simplify custon rootfs name lookup.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Fix running with --initrd and no real discs/rootfs
Matt Evans [Thu, 15 Dec 2011 07:13:41 +0000 (18:13 +1100)]
kvm tools: Fix running with --initrd and no real discs/rootfs

It's useful to boot with no -d and no implicit 9p root, with --initrd.
Since commit eaf720b285947a6f4e29174d0eba1899de31d8ab, we die() failing
to create the 2nd stage custom rootfs.  This patch doesn't try to set up
a custom rootfs by default if user specifies an initrd on the commandline.

Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Get correct 64-bit types on PPC64 and link appropriately
Matt Evans [Fri, 9 Dec 2011 06:53:50 +0000 (17:53 +1100)]
kvm tools: Get correct 64-bit types on PPC64 and link appropriately

kvmtool's types.h includes <asm/types.h>, which by default on PPC64 brings in
int-l64.h; define __SANE_USERSPACE_TYPES__ to get LL64 types.

This patch also adds CFLAGS to the final link, so that any -m64 is obeyed
when linking, too.

Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agoPPC: Add __SANE_USERSPACE_TYPES__ to asm/types.h for LL64
Matt Evans [Thu, 8 Dec 2011 06:57:09 +0000 (17:57 +1100)]
PPC: Add __SANE_USERSPACE_TYPES__ to asm/types.h for LL64

PPC64 uses long long for u64 in the kernel, but powerpc's asm/types.h
prevents 64-bit userland from seeing this definition, instead defaulting
to u64 == long in userspace.  Some user programs (e.g. kvmtool) may actually
want LL64, so this patch adds a check for __SANE_USERSPACE_TYPES__ so that,
if defined, int-ll64.h is included instead.

Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Fix alaising errors in LINT assignment
Matt Evans [Wed, 14 Dec 2011 02:06:44 +0000 (13:06 +1100)]
kvm tools: Fix alaising errors in LINT assignment

I'm getting this on x86-32, gcc 4.4.3:

  CC       x86/kvm-cpu.o
cc1: warnings being treated as errors
x86/kvm-cpu.c: In function ‘kvm_cpu__set_lint’:
x86/kvm-cpu.c:89: error: dereferencing pointer ‘lapic’ does break strict-aliasing rules
x86/kvm-cpu.c:88: error: dereferencing pointer ‘lapic’ does break strict-aliasing rules
x86/kvm-cpu.c:83: note: initialized from here
make: *** [x86/kvm-cpu.o] Error 1

Removing the nasty aliasing seems to be a good way to go.

Acked-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agoRevert "kvm tools: Add kvm__has_cap() to check whether a cap is available on the...
Sasha Levin [Thu, 15 Dec 2011 06:02:55 +0000 (08:02 +0200)]
Revert "kvm tools: Add kvm__has_cap() to check whether a cap is available on the host"

We already had kvm__has_extension, no need for two functions that do the
same.

This reverts commit 42efb1abf4ebebeedd14af34c073e673923e2898.

Conflicts:

tools/kvm/include/kvm/kvm.h

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Use kvm__supports_extension instead of kvm__has_cap
Sasha Levin [Thu, 15 Dec 2011 06:02:54 +0000 (08:02 +0200)]
kvm tools: Use kvm__supports_extension instead of kvm__has_cap

kvm__supports_extension has been there before, and it's does it's job right
unlike kvm__has_cap.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Remove KVM_NR_CPUS
Matt Evans [Thu, 15 Dec 2011 05:06:57 +0000 (16:06 +1100)]
kvm tools: Remove KVM_NR_CPUS

The KVM_NR_CPUS define is only really used to statically size the global
kvm_cpus array, which can just as easily be allocated on startup.  There is
some checking of the -c <nr cpus> value given against NR_CPUs but this is
later again checked against a dynamically-determined limit from
KVM_CAP_MAX_VCPUS anyway.  The hardwired limit is arbitrary and not strictly
necessary.

This patch removes the #define, replacing the statically-sized array with
a malloc; the array is kvm->nrcpus+1 in size so that any iterator can halt
at the end (this is done in kvm_cpu__reboot, which doesn't have access to
a struct kvm* and therefore kvm->nrcpus).

An unused #define in x86/mptable.c is also removed.

Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Don't use ioeventfds if no KVM_CAP_IOEVENTFD
Sasha Levin [Wed, 14 Dec 2011 06:37:26 +0000 (08:37 +0200)]
kvm tools: Don't use ioeventfds if no KVM_CAP_IOEVENTFD

Check KVM_CAP_IOEVENTFD before using ioeventfds.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Add kvm__has_cap() to check whether a cap is available on the host
Sasha Levin [Wed, 14 Dec 2011 06:37:25 +0000 (08:37 +0200)]
kvm tools: Add kvm__has_cap() to check whether a cap is available on the host

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Fix MMIO ordering problem cause due to coalescing
Sasha Levin [Wed, 14 Dec 2011 13:11:22 +0000 (15:11 +0200)]
kvm tools: Fix MMIO ordering problem cause due to coalescing

If we took a MMIO exit, the data in the coalesced ring should be processes
before the data in the exit itself is processed.

Doing it wrong (like we did so far) will cause ordering issues.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Don't always coalesce MMIOs
Sasha Levin [Wed, 14 Dec 2011 13:11:21 +0000 (15:11 +0200)]
kvm tools: Don't always coalesce MMIOs

Coalescing MMIOs is only required when we really want avoid having to exit
to userspace for every MMIO write, usually it's not the case so no reason
to coalesce every MMIO zone (I was also pretty sure it didn't always coalesce
zones)..

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Add initial SPAPR PPC64 architecture support
Matt Evans [Tue, 13 Dec 2011 07:00:26 +0000 (18:00 +1100)]
kvm tools: Add initial SPAPR PPC64 architecture support

This patch adds a new arch directory, powerpc, basic file structure, register
setup and where necessary stubs out arch-specific functions (e.g. interrupts,
runloop exits) that later patches will provide.  The target is an
SPAPR-compliant PPC64 machine (i.e. pSeries); there is no support for PPC32 or
'bare metal' PPC64 guests as yet.  Subsequent patches implement the hcalls and
RTAS required to boot SPAPR pSeries kernels.

Memory is mapped from hugetlbfs (as that is currently required by upstream PPC64
HV-mode KVM).  The mapping of a VRMA region is yet to be implemented; this is
only necessary on processors that don't support VRMA, e.g. <= P6.  Work is
therefore needed to get this going on pre-P7 CPUs.

Processor state is set up as a guest kernel would expect (both primary and
secondaries), and SMP is fully supported.

Finally, support is added for simply loading flat binary kernels (plus initrd).
(bzImages are not used on PPC, and this series does not add zImage support or an
ELF loader.)  The intention is to later support loading firmware such as SLOF.

Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Fix build of util.c on 32bit machines
Matt Evans [Wed, 14 Dec 2011 01:10:03 +0000 (12:10 +1100)]
kvm tools: Fix build of util.c on 32bit machines

commit 378ee7e6dd301347c6bf2c740cb1fb40174bcb8b broke the -Werror build
on 32bit targets due to some variable typing in struct statfs:

On 14/12/11 11:03, David Evensky wrote:
> On an x86 32bit system (and using the 32bit CodeSourcery toolchain on
> a x86_64 system) I get:
>
> evensky@machine:~/.../linux-kvm/tools/kvm$ make
>   CC       util/util.o
> util/util.c: In function 'mmap_hugetlbfs':
> util/util.c:93:17: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
> util/util.c:99:7: error: format '%ld' expects argument of type 'long int', but argument 2 has type 'int' [-Werror=format]
> cc1: all warnings being treated as errors
>
> make: *** [util/util.o] Error 1

Fixes the build.

Reported-by: David Evensky <evensky@dancer.ca.sandia.gov>
Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Create arch-specific kvm_cpu__emulate_{mm}io()
Matt Evans [Tue, 13 Dec 2011 06:21:47 +0000 (17:21 +1100)]
kvm tools: Create arch-specific kvm_cpu__emulate_{mm}io()

Different architectures will deal with MMIO exits differently.  For example,
KVM_EXIT_IO is x86-specific, and I/O cycles are often synthesised by steering
into windows in PCI bridges on other architectures.

This patch calls arch-specific kvm_cpu__emulate_io() and kvm_cpu__emulate_mmio()
from the main runloop's IO and MMIO exit handlers.  For x86, these directly
call kvm__emulate_io() and kvm__emulate_mmio() but other architectures will
perform some address munging before passing on the call.

Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Add ability to map guest RAM from hugetlbfs
Matt Evans [Tue, 13 Dec 2011 06:21:46 +0000 (17:21 +1100)]
kvm tools: Add ability to map guest RAM from hugetlbfs

Add a --hugetlbfs commandline option to give a path to hugetlbfs-map guest
memory (down in kvm__arch_init()).  For x86, guest memory is a normal
ANON mmap() if this option is not provided, otherwise a hugetlbfs mmap.

This maps directly from a hugetlbfs temp file rather than using something
like MADV_HUGEPAGES so that, if the user asks for hugepages, we definitely
are using hugepages.  (This is particularly useful for architectures that
don't yet support KVM without hugepages, so we definitely need to use
them for the whole of guest RAM.)

Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: remove duplicated code
Lai Jiangshan [Mon, 12 Dec 2011 07:15:55 +0000 (15:15 +0800)]
kvm tools: remove duplicated code

Simple cleanup.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: protect shared global id in compat_mtx C.S.
Lai Jiangshan [Mon, 12 Dec 2011 07:15:54 +0000 (15:15 +0800)]
kvm tools: protect shared global id in compat_mtx C.S.

The global id is shared, protect it when access it.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: narrow the C.S. of compat_mtx
Lai Jiangshan [Mon, 12 Dec 2011 07:15:53 +0000 (15:15 +0800)]
kvm tools: narrow the C.S. of compat_mtx

The allocation and the copy are not required in the C.S.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: move strlcat() to util/strbuf.c
Lai Jiangshan [Mon, 12 Dec 2011 07:15:52 +0000 (15:15 +0800)]
kvm tools: move strlcat() to util/strbuf.c

strlcat() is a string related function.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: move util.c to util/
Lai Jiangshan [Mon, 12 Dec 2011 07:15:51 +0000 (15:15 +0800)]
kvm tools: move util.c to util/

util.c is a lib for kvm.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: move read-write.c to util/
Lai Jiangshan [Mon, 12 Dec 2011 07:15:50 +0000 (15:15 +0800)]
kvm tools: move read-write.c to util/

read-write.c contains no kvm related code, it is just a lib.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: add missing build output
Lai Jiangshan [Mon, 12 Dec 2011 07:15:49 +0000 (15:15 +0800)]
kvm tools: add missing build output

The missing "CC       util/rbtree.o" will be output when building.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: move rbtree.o to util/
Lai Jiangshan [Mon, 12 Dec 2011 07:15:48 +0000 (15:15 +0800)]
kvm tools: move rbtree.o to util/

rbtree.o is just a lib for kvm.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: move threadpool.c to util/
Lai Jiangshan [Mon, 12 Dec 2011 07:15:47 +0000 (15:15 +0800)]
kvm tools: move threadpool.c to util/

threadpool.c contains no kvm related code, it is just a lib.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: fix function name
Lai Jiangshan [Mon, 12 Dec 2011 07:15:46 +0000 (15:15 +0800)]
kvm tools: fix function name

In here, xxx_locked() should means "called with job_mutex locked",
the original funtion are opposite, fix them.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: check condition before wait
Lai Jiangshan [Mon, 12 Dec 2011 07:15:45 +0000 (15:15 +0800)]
kvm tools: check condition before wait

We should check the condition before wait it,
otherewise we may get deadlock.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
12 years agokvm tools: Clean up 'kvm debug'
Sasha Levin [Mon, 12 Dec 2011 09:19:49 +0000 (11:19 +0200)]
kvm tools: Clean up 'kvm debug'

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>