Commit Graph

449 Commits

Author SHA1 Message Date
Paul Bolle 8273302c5b kvm tools: Fix compilation on x86_64
Compilation on x86_64 failed with:
[...]
In file included from /usr/include/features.h:386:0,
                 from /usr/include/stdint.h:26,
                 from
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/include/stdint.h:3,
                 from include/kvm/e820.h:4,
                 from bios/e820.c:1:
/usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file
or directory
compilation terminated.
make: *** [bios/bios-rom.bin] Error 1

This is caused by a typo in the Makefile and because gnu/stubs.h (and
friends) expect to see __x86_64__. That's trivial to fix.

Acked-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Paul Bolle <pebolle@tiscali.nl>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg c4d7847b22 kvm tools: Fix large disk images on 32-bit
Use read()/write() instead of mmap() for virtio block device emulation to
support large disk images on 32-bit.

Reported-and-tested-by: Asias He <asias.hejun@gmail.com>
Tested-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg db34045c54 kvm tools, 8250: Don't set the UART_LSR_OE bit
User input is buffered anyway, so it's pointless to set the UART_LSR_OE bit.
Instead, wait for the guest kernel to consume the current input and send a new
character when the guest is ready.

This fixes the following warnings in guest kernels:

[  207.485000] ttyS0: 1 input overrun(s)

Reported-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 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
Asias He 03110ff36b kvm,virtio: add scatter-gather support v2
The size of the virtqueue(16) was smaller than scatter-gather(128)
which hypervisor tells the guest.  Under some circumstances,
if the guest uses scatter-gather which larger than 16 - 2, kernel panics.
That is why the scatter-gather support v1 breaks Cyrill's kernel boot.

Two descriptors are used as the header and status descriptors.
The remaining descriptors can be used as the real disk data descriptors.
So DISK_SEG_MAX should be VIRTIO_BLK_QUEUE_SIZE - 2.
VIRTIO_BLK_QUEUE_SIZE is 128 and DISK_SEG_MAX is 126 in this patch.

Tested-by: Cyrill Gorcunov <gorcunov@gmail.com>
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 76b6349f76 kvm tools: Cleanup virtqueue handling
This patch introduces some virtqueue handling helper functions and converts the
blk virtio device to use them.

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 20c64ecabe kvm: Remove duplicate headers
We're in the kernel source tree now so remove duplicate headers.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg a267e01b64 Revert "kvm,virtio: add scatter-gather support"
This reverts commit 87a53e99dad8b70decbc4d9744c3d272e51c3ceb.  It breaks
Cyrill's kernel boot.
2015-06-01 16:39:41 +01:00
Cyrill Gorcunov d18883188b virtio, block: Rename IOPORT_VIRTIO to IOPORT_VIRTIO_BLK
Since that is its only purpose, not the whole virtio
stuff.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Asias He a2c8c69686 kvm,virtio: add scatter-gather support
Publish VIRTIO_BLK_F_SEG_MAX feature to guest.

In disk I/O request, guest can use multiple buffers which are not physicall
contiguousy as the I/O request buffer.

[ penberg@kernel.org: cleanups ]
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 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 369c01c0e7 kvm,serial: Implement 16550A FIFO support
This patch implements 16550A FIFO support to the serial console emulation
layer. There's still a bug lurking somewhere which the hypervisor in some busy
loop taking up 100% of CPU. However, this patch is a definite improvement over
the previous hacks.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 19a2bb7d9f kvm,8250: Implement missing register emulation
This patch implements missing register emulation as per "UART register to port
conversion table" here:

  http://www.lammertbies.nl/comm/info/serial-uart.html

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Cyrill Gorcunov 855a637172 8250-serial: Emulate 8250 behaviour on autoprobing
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 251cf9a60d kvm,8250: Cleanup receive emulation
This patch cleans up receive emulation by separating the stdin polling and
reading logic from the interrupt logic. The patch also fixes the interrupt
injection code to inject one type of interrupt at a time.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 0bc4cf7872 kvm,8250: Fix ->counter clearing
We need to reset the counter to zero before we inject an interrupt to the
guest.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 133bedc1b8 kvm,8250: Fix "too much work for irq4" problems
This patch fixes the "too much work for irq4" problems caused by the fact that
we never set the UART_IIR_NO_INT flag in the emulation layer. This makes the
interrupt handler in the guest kernel process as much as possible which
triggers a warning.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg e62c18de54 kvm,8250: Make ttyS1 and ttyS2 disabled
This patch fixes the 8250 serial emulation to not have undefined ioports but
rather make them explicitly disabled.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg c6a69c614f kvm: Support for more than one serial ttys
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 934c193b93 kvm: Improve 8250 serial console interrupt handling
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 6d620acb66 8250-serial: Make transmitter being always ready to send data
Otherwise it causes kernel to do additional timeout
waiting for THR being empty.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:41 +01:00
Cyrill Gorcunov 4e49b05b43 8250-serial: Use linux/serial-reg.h with predefined constants
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-01 16:39:41 +01:00
Cyrill Gorcunov 6d54df7482 8250-serial: Simplify is_readable function
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
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 76b4a12288 kvm,8250: Implement serial input support
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Cyrill Gorcunov cfc5633322 make: Add TAGS, tags targets and tune cscope
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
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
Asias He a276ccb50a kvm,virtio: do not publish read only feature to guest
We support write operations 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
Asias He 2924f993ed kvm,virtio: move SECTOR_SHIFT and SECTOR_SIZE to disk-image.h
Suggested-by: Pekka Enberg <penberg@kernel.org>
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 900d32c15c kvm,serial: Enable THRI bit in IIR register
This patch enables the THRI ("transmission holding register empty") bit in the
IIR register to make sure the guest doesn't think we have data waiting for it.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 9a7428ddbb kvm: Fix magic numbers in 8250 support
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 46aa8d6918 kvm: Improve 8250 serial console support
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg b74755443f kvm: Redirect serial console to stdout, not stderr
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 258dd093dc kvm: Implement virtio block device write support
This patch implement virtio block device write support. The writes are not
persistent because we map the disk image with MAP_PRIVATE.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg ba021bc9d6 kvm: Kill debug logging from blk-virtio.c
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg a93ec68b66 kvm: Support MSR register for serial console
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 4155ba8cda kvm: Fix virtio block device support some more
This patch fixes the following issues in virtio block device support:

- Handle all requests in the virtqueue before signaling an interrupt.

- Initialize ->used vring elements properly.

- Handle non-read requests by injecting an I/O error to the guest.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg 93d18b7223 kvm: Fix virtqueue ring index check
This patch fixes the virtqueu ring index check that was totally wrong. The
->last_avail_idx is the index we've last seen but it doesn't need to match with
avail->idx.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Asias He 6160ab9d82 virtio: capacity should be in 512-byte sectors
struct virtio_blk_config {
        /* The capacity (in 512-byte sectors). */
        uint64_t capacity;
	...
}

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 5646450daa kvm: Fail if user specifies a QCOW disk image
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:41 +01:00
Pekka Enberg e907b83f28 kvm: Improve kvm__init() error message
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