Commit Graph

153 Commits

Author SHA1 Message Date
Samuel Ortiz
9c5135da7a vmm: Simplify the VM start flow
We can integrate the kernel loading into the VM start method.
The VM start flow is then: Vm::new() -> vm.start(), which feels more
natural.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2019-09-24 10:12:04 +02:00
Samuel Ortiz
b79c1f7722 vmm: Derive the clone trait for VmConfig
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2019-09-24 08:39:39 +01:00
Samuel Ortiz
acc60b0ad5 vmm: Make VsockConfig owned
Convert Path to PathBuf and remove the associated lifetime.
Now we can remove the VmConfig associated lifetime.

Fixes #298

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2019-09-24 08:39:39 +01:00
Samuel Ortiz
3dc7aff00e vmm: Make vhost-user configuration owned
Convert Path to PathBuf, &str to String and remove the associated lifetime.

Fixes #298

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2019-09-24 08:39:39 +01:00
Samuel Ortiz
5f8a62f3d0 vmm: Make DeviceConfig owned
Convert Path to PathBuf and remove the associated lifetime.

Fixes #298

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2019-09-24 08:39:39 +01:00
Samuel Ortiz
36137232f0 vmm: Make ConsoleConfig owned
Convert Path to PathBuf and remove the associated lifetime.

Fixes #298

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2019-09-24 08:39:39 +01:00
Samuel Ortiz
79a02f9171 vmm: Make PmemConfig owned
Convert Path to PathBuf and remove the associated lifetime.

Fixes #298

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2019-09-24 08:39:39 +01:00
Samuel Ortiz
00674cd850 vmm: Make FsConfig owned
Convert Path to PathBuf, &str to String and remove the associated lifetime.

Fixes #298

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2019-09-24 08:39:39 +01:00
Samuel Ortiz
5323da031c vmm: Make RngConfig owned
Convert Path to PathBuf and remove the associated lifetime.

Fixes #298

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2019-09-24 08:39:39 +01:00
Samuel Ortiz
0688bec298 vmm: Make NetConfig owned
Convert str to String and remove the associated lifetime.

Fixes #298

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2019-09-24 08:39:39 +01:00
Samuel Ortiz
675e46355c vmm: Make DiskConfig owned
Convert Path to PathBuf and remove the associated lifetime.

Fixes #298

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2019-09-24 08:39:39 +01:00
Samuel Ortiz
036890e5be vmm: Make KernelConfig owned
Convert Path to PathBuf and remove the associated lifetime.

Fixes #298

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2019-09-24 08:39:39 +01:00
Samuel Ortiz
9c5bfb8e13 vmm: Make MemoryConfig owned
Convert Path to PathBuf and remove the associated lifetime.

Fixes #298

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2019-09-24 08:39:39 +01:00
Yang Zhong
4164853ec6 vmm: add vhost-user-blk support
Update vm configuration and device initial process to add
vhost-user-blk support.

Signed-off-by: Yang Zhong <yang.zhong@intel.com>
2019-09-20 15:56:51 +02:00
Yang Zhong
c7559bb7a4 config: make error definition common
Since vhost-user-blk use same error definition with vhost-user-net,
those errors need define to common usage.

Signed-off-by: Yang Zhong <yang.zhong@intel.com>
2019-09-20 15:56:51 +02:00
Rob Bradford
5b3ca78dac vmm: Use the full host physical address range
Probe for the size of the host physical address range and use that to
establish the address range for the VM. This removes the limitation on
the size of the VM RAM and gives more space for the devices.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-19 10:43:55 +01:00
Rob Bradford
f0360c92d9 arch: acpi: Set the upper device range based on RAM levels
After the 32-bit gap the memory is shared between the devices and the
RAM. Ensure that the ACPI tables correctly indicate where the RAM ends
and the device area starts by patching the precompiled tables. We get
the following valid output now from the PCI bus probing (8GiB guest)

[    0.317757] pci_bus 0000:00: resource 4 [io  0x0000-0x0cf7 window]
[    0.319035] pci_bus 0000:00: resource 5 [io  0x0d00-0xffff window]
[    0.320215] pci_bus 0000:00: resource 6 [mem 0x000a0000-0x000bffff window]
[    0.321431] pci_bus 0000:00: resource 7 [mem 0xc0000000-0xfebfffff window]
[    0.322613] pci_bus 0000:00: resource 8 [mem 0x240000000-0xfffffffff window]

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-19 10:43:55 +01:00
Rob Bradford
3bc11a4a2e vmm: Make the "mmio" only build generate no errors
Rerrange "use" statements and make rename variables and fields to
indicate they might be unused.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-16 08:55:35 -07:00
Rob Bradford
4df5ebea12 vmm: Add devices to IO/MMIO bus closer to creation
This removes the register_devices() function with all that functionality
spread across the places where the devices are created.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-16 08:55:35 -07:00
Rob Bradford
7358144f09 vmm: Cleanup warning from "pci" feature only build
Mark exit_evt with an underscore it may be unused (it is ignored if the
"acpi" feature is not turned on.)

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-16 08:55:35 -07:00
Rob Bradford
1099f0726b vmm: Add MMIO support
Add (non-default) support for using MMIO for virtio devices. This can be
tested by:

cargo build --no-default-features --features "mmio"

All necessary options will be included injected into the kernel
commandline.

Fixes: #243

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-13 12:30:13 +01:00
Rob Bradford
c042483953 build: make PCI (virtio and vfio) disableable at build time
Although included by default it is now possible to build without PCI
support.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-13 12:30:13 +01:00
Rob Bradford
6d27ac9dfc vmm: Allow the DeviceManager to inject extra kernel commandline entries
This is useful for virtio-mmio to be able to provide the commandline
entries for the devices.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-13 12:30:13 +01:00
Rob Bradford
05b5115e67 vmm: Call DeviceManager's register_devices() on creation
Rather than calling it at the very start of the VM execution (i.e. when
the VCPUs are created) do it as part of the DeviceManager creation.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-10 20:04:00 +02:00
Rob Bradford
7edc46f492 vmm: Make virtio device creation independent of PCI
Create the virtio devices independently of adding them to the PCI bus.
Instead accrue the devices in a vector and add them to the bus en-masse.
This will allow the virtio device creation to be used independently of
PCI based transport.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-10 09:41:53 -07:00
Rob Bradford
8f37dec498 vmm: "close" the SIGWINCH signal handler
Rather than sending a signal to the signal handler used for handling
SIGWINCH calls instead use the crate provided termination method. This
also unregisters the signal handler which also means that there won't be
a leaked signal handler remaining.

This leaked signal handler is what was causing a failure to cleanup up
the thread on subsequent requests breaking two reboots in a row.

Fixes: #252

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-09 15:42:26 +02:00
Rob Bradford
eb46aa2b22 vmm: If acpi feature is disabled make "reboot" shutdown
With ACPI disabled there is no way to support both reset and shutdown so
make the VMM exit if the VM is rebootet (via i8042 or triple-fault
reset.)

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-06 11:03:44 -07:00
Sebastien Boeuf
475e487ac3 vmm: Create vsock backend
This commit relies on the new vsock::unix module to create the backend
that will be used from the virtio-vsock device.

The concept of backend is interesting here as it would allow for a vhost
kernel backend to be plugged if that was needed someday.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2019-09-06 10:51:25 -07:00
Sebastien Boeuf
4ccc81fdf9 vmm: Create virtio-vsock device
Based on previous patch introducing the new flag "--vsock", this commit
creates a new virtio-vsock device based on the presence of this flag.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2019-09-06 10:51:25 -07:00
Sebastien Boeuf
11e7ece9f5 vmm: Add new flag "--vsock"
The new flag vsock is meant to be used in order to create a VM with a
virtio-vsock device attached to it. Two parameters are needed with this
device, "cid" representing the guest context ID, and "sock" representing
the UNIX socket path which can be accessed from the host.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2019-09-06 10:51:25 -07:00
Sebastien Boeuf
69e27288a2 vmm: Allocate enough MSI-X vectors for multiqueue virtio devices
The default number of MSI-X vector allocated was 2, which is the minimum
defined by the virtio specification. The reason for this minimum is that
virtio needs at least one interrupt to signal that configuration changed
and at least one to specify something happened regarding the virtqueues.

But this current implementation is not optimal because our VMM supports
as many MSI-X vectors as allowed by the MSI-X specification (2048 max).
For that reason, the current patch relies on the number of virtqueues
needed by the virtio device to determine the right amount of MSI-X
vectors needed. It's important not to forget the dedicated vector for
any configuration change too.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2019-09-06 10:51:25 -07:00
Rob Bradford
d2db34edf2 vmm: Hide underlying console setup from VM
Refactor the underlying console details into the DeviceManager and
abstract away.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-06 09:26:37 -07:00
Rob Bradford
d089ee4e25 vmm: Move ownership of the exit/reset EventFd to Vm structure
It makes more sense there as it is used by more than just the
DeviceManager.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-06 09:26:37 -07:00
Rob Bradford
2f4de81175 vmm: Access ioapic/io_bus/mmio_bus from DeviceManager via accessor
This paves the way for introducing a trait for the DeviceManager.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-06 09:26:37 -07:00
Rob Bradford
9ac967e3d8 vmm: Split DeviceManager into it's own file
Refactor out DeviceManager into it's own file. This is part of a bigger
effort to reduce complexity in the vm.rs file but will also allow future
separation to allow making PCI support optional.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-06 09:26:37 -07:00
Rob Bradford
9661e8da5d build: Really make the acpi feature disableable
The command "cargo build --no-default-features" does not recursively
disable the default features across the workspace. Instead add an acpi
feature at the top-level, making it default, and then make that feature
conditional on all the crate acpi features.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-05 08:58:47 -07:00
Rob Bradford
1f06c5907f Revert "vmm, tests: Disable reboot support"
This reverts commit 8308e1bf25.
2019-09-05 10:38:14 +01:00
Rob Bradford
5dd675710b vmm: Call munmap() on regions that have been mmap()ed
For virtio-fs and virtio-pmem regions of memory are manually mapped into
the address space of the VMM. In order to cleanly reboot we need to
unmap those regions.

Fixes: #223

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-05 10:38:14 +01:00
Rob Bradford
f59cad15a3 vmm: Cleanup signal_handler thread used for console SIGWINCH handling
Do this by using the same mechanism as the vCPU threads by sending a
signal to the thread. As this is the same mechanism reuse the same code
and rename the "vcpus" member to "threads" to indicate this represents
both the vCPU threads and also the signal handler thread.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-04 09:21:01 -07:00
Rob Bradford
9e764fc091 vmm, arch, devices: Put ACPI support behind a default feature
Put the ACPI support behind a feature and ensure that the code compiles
without that feature by adding an extra build to Travis.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-03 19:18:49 +02:00
Rob Bradford
bb2e7bb942 vmm: Shutdown vCPU threads
As part of the cleanup of the VM shutdown all the vCPU threads. This is
achieved by toggling a shared atomic boolean variable which is checked
in the vCPU loop. To trigger the vCPU code to look at this boolean it is
necessary to send a signal to the vCPU which will interrupt the running
KVM_RUN ioctl.

Fixes: #229

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-03 19:18:49 +02:00
Rob Bradford
8308e1bf25 vmm, tests: Disable reboot support
Being able to reboot requires us to identify all the resources we are
leaking and cleaning those up before we can enable reboot. For now if
the user requests a reboot then shutdown instead.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-03 19:18:49 +02:00
Rob Bradford
ad128bf72d vmm: Give vCPU and signal handler thread useful names
Sadly only the first few characters of the thread name is preserved so
use a shorter name for the vCPU thread for now. Also give the signal
handling thread a name.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-03 19:18:49 +02:00
Rob Bradford
614eb68f16 vm: Make triple-fault and i8042 reset reboot the VM
Now we have ACPI shutdown we should reboot on these reset triggers.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-03 19:18:49 +02:00
Rob Bradford
5a187ee2c2 x86_64/devices: acpi: Add support for ACPI shutdown & reboot
Add an I/O port "device" to handle requests from the kernel to shutdown
or trigger a reboot, borrowing an I/O used for ACPI on the Q35 platform.
The details of this I/O port are included in the FADT
(SLEEP_STATUS_REG/SLEEP_CONTROL_REG/RESET_REG) with the details of the
value to write in the FADT for reset (RESET_VALUE) and in the DSDT for
shutdown (S5 -> 0x05)

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-03 19:18:49 +02:00
Rob Bradford
ae66a44d26 vmm: Support both reset and shutdown
Add a 2nd EventFd to the VM to control resetting (rebooting) the VM this
supplements the EventFd used for managing shutdown of the VM.

The default behaviour on i8042 or triple-fault based reset is currently
unchanged i.e. it will trigger a shutdown.

In order to support restarting the VM it was necessary to make start()
function take a reference to the config.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-03 19:18:49 +02:00
Rob Bradford
2610f4353d arch: acpi: Only add ACPI COM1 device if serial is turned on
Only add the ACPI PNP device for the COM1 serial port if it is not
turned off with "--serial off"

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-03 19:18:49 +02:00
Rob Bradford
451502b50b vm: If a VCPU thread errors out then exit the hypervisor
Currently when the VCPU thread exits on an error the VMM continues to
run with no way of shutting down the main thread.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-03 19:18:49 +02:00
Rob Bradford
eea6f1dc9e acpi_tables: Add initial ACPI tables support
Add a revision 2 RSDP table only supporting an XSDT along with support
for creating generic SDT based tables.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2019-09-03 19:18:49 +02:00
Sebastien Boeuf
b7d3ad9063 vm-virtio: fs: Factorize vhost-user setup
This patch factorizes the existing virtio-fs code by relying onto the
common code part of the vhost_user module in the vm-virtio crate.

In details, it factorizes the vhost-user setup, and reuses the error
types defined by the module instead of defining its own types.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2019-08-31 17:33:17 +01:00