75 Commits
Author SHA1 Message Date
Pekka Enberg 9667701c38 kvm tools: Use kvm__get_dir() helper function
This patch adds a kvm__get_dir() helper function that replaces open-coded uses
of HOME_DIR and KVM_PID_FILE_PATH.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Amerigo Wang f6677a1dec kvm tools: implement "help xxx" command
'kvm run --help' works fine but 'kvm help run' shows nothing,
this patch implements it.

Acked-by: Prasad Joshi <prasadjoshi124@gmail.com>
Signed-off-by: WANG Cong <amwang@redhat.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:44 +01:00
Prasad Joshi f967c427ec kvm tools: Use the Gitish freamwork to run the virtual machine
- kvm-run.[ch] Adds a new kvm command called 'run'. The most of the code is
  copied from main.c.

- main.c is modified to use the functionality provided by framework.
  The old code from main.c is moved to kvm-run.c.

Signed-off-by: Prasad Joshi <prasadjoshi124@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:42 +01:00
Asias He 416b2c2dd8 kvm tools: Unify virtio code file names
- rename {blk,console}-virtio.* to virtio-{blk,console}.*
- change the virtio block device PCI io space operation callback names

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Ingo Molnar dfa78ed0dd kvm tools: Indicate the end of a KVM session
Right now when a KVM session ends with an incomplete line printk'd
without a newline, kvm exits in an ugly way:

  [    4.638016] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
  [    4.641668] Rebooting in 1 seconds..spirit:~/tip/tools/kvm>
  spirit:~/tip/tools/kvm>

See the shell prompt intermixed with the last line of kernel output.

There's also no indication to the user that everything is fine on the
kvm tool side.

This is somewhat of a beauty wart and also a bit confusing to users.

To clarify and clean up things, add a final printout on normal exits:

  [    4.654814] Please append a correct "root=" boot option; here are the available partitions:
  [    4.584390] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
  [    4.662243] Rebooting in 1 seconds..
    # KVM session ended normally.
  spirit:~/tip/tools/kvm>

This delimits the kernel output properly and gives feedback to the user
that (despite the scary kernel messages) all fine from the KVM POV.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg a428f72ec3 kvm tools: Send SysRq-P to guest kernel on SIGQUIT
This patch makes SIGQUIT to the host hypervisor send 'SysRq-P' to the guest
kernel via 8250 serial console to make debugging stuck guests easier.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 8a628d5a54 kvm tools: Don't exit() on SIGQUIT
The point of SIGQUIT is to dump relevant information of a running guest, not to
stop it.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Asias He c067c5c17f kvm tools: Introduce --enable-virtio-console option
This option enables virtio console and disables serial console.
At this time, the virtio and serial console can not work simultaneously.
Becasue we can not put both console's output to user at the same time.
However, once we redirect the virtio console to a pipe or socket. We can
use both console simultaneously.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Asias He 9bd8ac5c92 kvm tools: Virtio console support
This patch adds simple virtio console support to the hypervisor.

NOTE, NOTE, NOTE: Please add something like this to your /etc/inittab file:

    T2:23:respawn:/sbin/getty -L hvc0 9600 vt100

to get a virtio console login.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Asias He 05d1a2a69d kvm tools: Make 8250 serial use infrastructure provided by term.c
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Asias He b4405289e6 kvm tools: Move terminal related code to a new file term.c
This patch is a preparational step for virtio console and 8250 serial console
code consolidation.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Sasha Levin fbfe68b74e kvm tools: Free memory and FDs on exit
Following patch adds more cleanup code when exiting.
Close disk image, free msrs array and destroy the timer fd.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg a3c485144c kvm tools: Drop hard-coded 'nosmp' kernel parameter
As noted by Cyrill, there's no need to pass 'nosmp' to the guest kernel because
it'll switch to PIC after noticing APIC is not available.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Cyrill Gorcunov b3594ec7e0 kvm tools: Separate BIOS specifics into own file
Instead of calling various BIOS routines from kvm.c better to have all BIOS
specifics sit in bios.c.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Cyrill Gorcunov 9d850b3760 kvm tools: Setup BIOS for both bzImage and flat image
There is no differences in terms of BIOS what kind of kernel is loaded so we
have to setup BIOS for both bzImage and flat image.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 7e8625445b kvm tools: Cleanup strstr() in expression
Cleanup use of strstr() in an expression in main() function.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
David Ahern 79fafcf1d3 kvm tools: do not append root=/dev/vda if passed via command line
Hardcoding the root= option prevents an existing qemu-kvm based disk
image using LVM from booting. It fails to find the root filesystem.
By making the root parameter optional if given on the command line, the
image boots correctly. For example,

  ./kvm --kernel=/tmp/vmlinuz-2.6.38 \
        --initrd=/tmp/initramfs-2.6.38.img \
        --image=/home/dsa/vm/images/f14/nkvm-f14.img \
        --mem=1024
        --params="ro root=/dev/mapper/vg_f14vm-lv_root"

works now.

Signed-off-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 8315b1925c tools/kvm: Exit gracefully upon KVM_EXIT_SHUTDOWN
This patch changes the userspace hypervisor to exit gracefully upon
KVM_EXIT_SHUTDOWN which is triggered when guest userspace is shut down.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg bc4b0ffef3 kvm,8250: Fix device initial state
This patch fixes 8250 device initial state for registers and IRQ based on what
Qemu does.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 279ba8253e kvm tools: Cleanup termios handling
This patch cleans up the confused termios handling to do what Lguest does.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg ce79f1ca45 kvm: Cleanup interrupt timer logic
This patch moves the interrupt timer logic to kvm.c and cleans it up.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 0b8e1a675d kvm: Use disk name for mounting root
Use disk name for kernel "root=" parameter rather than the dynamic major and
minor numbers that vary from system to system.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Cyrill Gorcunov 176db3d6c9 kvm: save/restore std ttys
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:41 +01:00
Pekka Enberg 7c3b4e4b0d kvm: Put terminal in canonical mode
As suggested by Ingo Molnar, put terminal in canonical mode. This makes poll()
on stdin to react to keystrokes insted of return key and fixes the double
echo'd character problem for input.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 352d3a66db kvm: Use serial console by default
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg e557eef9b6 kvm,8250: Inject interrupts to guest
This patch fixes 8250 emulation to inject interrupts to guest so we actually
see what's sent to the serial console.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 899fe06304 kvm: Rename early_printk.c to 8250-serial.c
The 8250 emulation is no longer there to just support early_printk() so rename
the source file to reflect that.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 8bb34e0dfa kvm: Implement support interrupt injection
This patch implement support for injecting interrupts from the userspace
hypervisor to the guest.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Asias He ceba1fad4c kvm: Add rw to default kernel command line parameters
As reported by Asias He, guest kernels mount filesystems as readonly under our
hypervisor:

  without rw:
  [    0.909000] EXT3-fs: mounted filesystem with writeback data mode.
  [    0.909000] VFS: Mounted root (ext3 filesystem) readonly on device 253:1.

  /dev/root on / type ext3 (ro,relatime,errors=continue,data=writeback)

by passing the "rw" kernel parameter, guest kernels are able to mount as
read-write:

  [    0.891000] EXT3 FS on vda1, internal journal
  [    0.891000] EXT3-fs: recovery complete.
  [    0.892000] EXT3-fs: mounted filesystem with writeback data mode.
  [    0.892000] VFS: Mounted root (ext3 filesystem) on device 253:1.

  /dev/root on / type ext3 (rw,relatime,errors=continue,data=writeback)

There's some real problem hiding here but as we've done with other parts of the
kernel (PCI, SMP), just bypass the problem for now.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 1f84889767 kvm: Enable virtio block device if disk image specified
This patch removes the "--enable-virtion" command line option and enable virtio
block device when a disk image is specified.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Cyrill Gorcunov ca7c891bfe kvm: Setup disk geometry if needed
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:41 +01:00
Pekka Enberg 5a24a9f279 kvm: Use disk image API from virtio block device
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 9f532d0016 kvm: Add support for disk images
This patch implements "--image" command line option that can be used to specify
a disk image. It supports raw images and it needs to be integrated to the
hypervisor block layer.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg dc53a427d0 Revert "kvm: Fix virtio block PCI device IRQ configuration"
This reverts commit 00b793d98754629f833d5a3003554f841e64ec45.
2015-06-01 16:39:40 +01:00
Pekka Enberg 406f1a89c8 kvm: Fix virtio block PCI device IRQ configuration
This patch fixes up hang when guest kernel tries to setup virtio block device.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:40 +01:00
Pekka Enberg 8b1ff07e1f kvm: Virtio block device emulation
This patch implements a rough first version of virtio block device emulation.
You can enable it with the '--enable-virtio' command line option. We're still
missing virtio queue handling so enabling virtio will cause a guest kernel to
hang.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:40 +01:00
Pekka Enberg b30d05ad0a kvm: Extract virtio-blk driver to separate file
This patch extracts virtio-blk driver to a separate file.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:40 +01:00
Cyrill Gorcunov 2065a6f762 kvm: Support loading initrd image
The start address of initrd image is set properly
but it seems we need /dev tuning since kernel issue
panic still.

Suggested-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:40 +01:00
Pekka Enberg 886c5381fc kvm: Add KVM ABI headers
This patch adds KVM ABI headers to the source tree. We can no longer include
<linux/kvm.h> directly because someone added a "#warning" to <linux/types.h>
that prevents kernel header inclusion from userspace.

We can switch back to using kernel headers if we ever make it to Linux
mainline.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:40 +01:00
Pekka Enberg 60742802dc kvm: Initial PCI probe emulation
This patch adds simple PCI Configuration Mechanism 1 probing emulation. It
doesn't expose any actual PCI devices yet.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 46365b263c kvm: Force PCI Configuration Mechanism 1
This patch forces the guest Linux kernel to use PCI Configuration Mechanism 1.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 4508ee7398 kvm: Enable Linux kernel PCI probing
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg b487c53e37 kvm: Fix usage command line format
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Cyrill Gorcunov 192a99d1d7 kvm: Add --mem= option
Which allow an user to specify the amount of memory
he would like to provide for kernel.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:40 +01:00
Pekka Enberg 2f3976eeee kvm: BIOS E820 memory map emulation
This patch adds BIOS E820 memory map emulation to KVM.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 6d7c36ceea kvm: Introduce '--kvm-dev' command line option
This patch introduces a '--kvm-dev' command line option for debugging purposes.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 11e9d907bb kvm: Fix compilation warning
This patch fixes the following compilation warning:

  main.c: In function ‘main’:
  main.c:149: warning: label ‘out’ defined but not used

Reported-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 62ef45dc93 kvm: Don't stop on ioport errors by default
This patch introduces a '--ioport-debug' option that preserves the old
stop-on-error behavior and changes the default to keep on running despite of
ioport errors. This allows Linux kernel to boot to VFS mount phase.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg 3ae4f82b7c kvm: Add '--params' to usage
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00
Pekka Enberg cb046752e8 kvm: Add proper 00E0 ioport handling
We use 00E0 ioport for trapping to the hypervisor. This patch cleans up
handling of the ioport to call exit() in ioport emulation handler.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
2015-06-01 16:39:40 +01:00