Commit Graph

9702 Commits

Author SHA1 Message Date
Rob Bradford
2fbb98e2c3 virtio-devices: vhost_user: Add common code for restoring state
Add a common method for validating the state (checking vrings &
device_state) and then restoring the backend state if present.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-03-27 14:18:27 +00:00
Rob Bradford
02688993a0 virtio-devices: vhost_user: Fetch and store the backend state/vring
Fetch the opaque device state from the backend and store it along with
the last vring used in the state used for the snapshot.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-03-27 14:18:27 +00:00
Rob Bradford
a6b9455402 virtio-devices: vhost_user: Add get/set of backend state support
The vhost-user protocol now has support for the backend to provide an
opaque blob of data (read or written through a pipe) that the VMM can
use to save/restore state after snapshot/restore or live migration.

It also adds a command for checking the backend accepts the uploaded
device state. One quirk of saving the state is that GET_VRING_BASE must
be used first to quiesce the state of the backend and flush any
in-flight requests. This then also requires saving that index for use on
the restore.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-03-27 14:18:27 +00:00
Rob Bradford
afc3cb8e1f virtio-devices: vhost_user: Rename update_supports_migration
Rename update_supports_migration() to update_supported_features() as
this method will be extended to track additional capability flags beyond
just migration support (e.g. DEVICE_STATE for snapshot/restore.)

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-03-27 14:18:27 +00:00
Rob Bradford
8536a2536e virtio-devices: vhost_user: Adapt state() to return Result
This is a refactoring step in preparation for fetching backend device
state via SET_DEVICE_STATE_FD which can fail.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-03-27 14:18:27 +00:00
Rob Bradford
3e233af654 virtio-devices: vhost_user: Access acked_protocol_features directly
In GenericVhostUser's read_config and write_config, access
vu_common.acked_protocol_features directly instead of going through
the state() method which creates a struct. This removes creating the
struct just to access two fields that are already directly accessible.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-03-27 14:18:27 +00:00
Rob Bradford
bd56214d54 virtio-devices: vhost_user: Add VhostUserCommon::state() helper
With a common state structure for all vhost-user devices the state()
methods can also be refactored for reuse. This will make it easier to
add new common fields in the future for snapshot/restore.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-03-27 14:18:27 +00:00
Rob Bradford
a77f89847e virtio-devices: vhost_user: Consolidate device State into VhostUserState
Each vhost-user device type had near identical State structs.
Deduplicate those by introducing a new common struct (and parameterising
it when it needs to embed a config member.) This will make it easier to
reuse more code in the future and to add more struct members to handle
the requirements of snapshot/restore.

These changes have been designed to have no impact on the existing
snapshot/restore state.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-03-27 14:18:27 +00:00
Alyssa Ross
e1e6d0a25b vmm: fix rebooting with landlock and pty console
When landlock support was added, creation of file descriptors was
moved out into a function called pre_create_console_devices, with the
idea being that this could be run before Landlock rules are applied
and access to all the necessary paths are dropped.

This idea didn't take reboots into account, though.  When a VM is
rebooted, pre_create_console_devices is called again, but now the
Landlock rules have been applied, so they need to allow access to all
those paths anyway.

I imagine the way this was intended to work was that file descriptors
would be preserved across reboot, but that's not currently the case,
and it's not a trivial change to make because they get dropped when
the VM is destroyed.  Longer term it would be ideal if Cloud
Hypervisor's implementation was more focused on file descriptors than
paths[1], and if created VMs only took references to file descriptors,
so they were easily preserved across reboots.

Fixes: b3e5738b4 ("vmm: Introduce ApplyLandlock trait")
Closes: https://github.com/cloud-hypervisor/cloud-hypervisor/issues/7547
Link: https://github.com/cloud-hypervisor/cloud-hypervisor/issues/7704 [1]
Signed-off-by: Alyssa Ross <hi@alyssa.is>
2026-03-27 11:11:26 +00:00
Anatol Belski
c21d6bb856 block: Add unit tests for query_device_size()
Test regular file with odd size (not page/sector aligned), sparse
file with punch hole verifying physical < logical, and char device
rejection, etc.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-27 11:05:07 +00:00
Anatol Belski
a21b9588ec virtio-devices: block: Use logical_size() for advisory lock range
Use logical_size() instead of physical_size() for the byte-range
advisory lock. physical_size() returns st_blocks*512 which is the
actual host allocation and can be smaller than the guest visible
extent on sparse files, leaving part of the range unprotected.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-27 11:05:07 +00:00
Anatol Belski
8b6eb83f2a block: qcow: raw_file: Use query_device_size() for size queries
Use query_device_size() instead of metadata().len() to correctly
handle block device and regular file handles.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-27 11:05:07 +00:00
Anatol Belski
1b92af5534 block: raw_async_aio: Use query_device_size() for size queries
Use query_device_size() instead of seek(End(0)) and metadata().len()
to correctly handle block device and regular file handles.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-27 11:05:07 +00:00
Anatol Belski
290f57a6e3 block: raw_sync: Use query_device_size() for size queries
Use query_device_size() instead of seek(End(0)) and metadata().len()
to correctly handle block device and regular file handles.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-27 11:05:07 +00:00
Anatol Belski
f14e2d2b40 block: raw_async: Use query_device_size() for size queries
Use query_device_size() instead of seek(End(0)) and metadata().len()
to correctly handle block device and regular file handles.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-27 11:05:07 +00:00
Anatol Belski
051a6eff5c block: Add query_device_size() for file and block device size
Add a shared helper that returns the logical size in bytes for both
regular files and block devices using an immutable &File reference.

Regular files use metadata().len(). Block devices use the BLKGETSIZE64
ioctl. Any other file type returns an InvalidInput error.

This avoids seek(SeekFrom::End(0)) which requires &mut self and can
return incorrect results for block devices when the file position is
in an unexpected state.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-27 11:05:07 +00:00
Anatol Belski
c5dba9ea3b vmm: seccomp: Allow BLKGETSIZE64 ioctl
Add BLKGETSIZE64 0x80081272 to the VMM seccomp ioctl allow list
alongside the existing BLK* ioctls. This is needed for querying
block device size without seeking.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-27 11:05:07 +00:00
Saravanan D
9156758828 pci: clamp sparse mmap holes to physical BAR
For VFIO devices with non page aligned MSI-X offsets,
fixup_msix_region() relocates MSI-X table and PBA offsets
into an enlarged virtual BAR by mutating msix.cap in place.
generate_sparse_areas() later reads those relocated offsets
to carve mmap holes, but receives the physical BAR size as
region_size. The relocated offsets exceed the physical BAR
boundary, and the kernel rejects the mmap with EINVAL.

Guard inter_ranges insertion with an offset < region_size
check so relocated entries are skipped. The full physical
BAR is mmapped as a single region. The relocated MSI-X in
the upper half of the virtual BAR remains trapped because
it has no mmap backing.

Linux kernel commit a32295c612c5 ("vfio-pci: Allow mapping
MSIX BAR") allows mmapping the entire BAR including the
MSI-X region when VFIO_REGION_INFO_CAP_MSIX_MAPPABLE is
advertised. The actual security guarantees come from IOMMU
isolation and interrupt remapping, not from filtering
MSI-X table accesses. QEMU follows the same pattern,
mmapping the entire physical BAR when MsixMappable is
present.

Fixes: #7898

Signed-off-by: Saravanan D <saravanand@crusoe.ai>
2026-03-27 10:55:59 +00:00
Bo Chen
1bc49758a0 pci, vmm: Cleanup the naming and references to VFIO container
Following the `VfioContainer` to `VfioOps` trait switch, update the
remaining field names, method names, comments, and log messages to use
`vfio_ops` and "host IOMMU address space" consistently.

No fucntional changes.

Signed-off-by: Bo Chen <bchen@crusoe.ai>
2026-03-27 04:22:05 +00:00
Bo Chen
7360bfe33a pci, vmm: Switch to use more generic VfioOps trait
Replace the concrete `VfioContainer` type with the `VfioOps` trait
object for device passthrough. This decouples the VFIO DMA mapping
interface from the legacy VFIO container/group implementation, allowing
it to be extended to support VFIO cdev and iommufd in the future.

Signed-off-by: Bo Chen <bchen@crusoe.ai>
2026-03-27 04:22:05 +00:00
Muminul Islam
5bb4ea20a5 scripts: Fix volume argument splitting in dev_cli.sh
Use IFS-based splitting instead of parameter expansion to
correctly separate '#'-delimited volume paths in
process_volumes_args(). The previous approach placed all
volumes into a single array element, causing Docker to
receive malformed --volume arguments.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-27 03:39:10 +00:00
Rob Bradford
57e766bdbb virtio-devices: Only try and activate if the device became ready
Previously this code could lead to the device being trying to be
activated multiple times as the code to trigger the activation was based
on the state of the device (not yet activated and device being ready).
This could occur if anothe vCPU wrote to a PCI BAR on this device before
the device activation was completed by the VMM thread. Now we only
trigger the activation if the device readiness has changed as a result
of this BAR write (by checking that the readiness was originally
unready.)

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-03-26 17:20:09 +00:00
Dylan Reid
65073259c6 vmm: handle malformed balloon actual from guest
The actual size of the balloon is taken directly from the guest. A
misbehaving guest can set it to an arbitrary value and cause underflow
on the next vm.info call. Use a saturation_sub instead to avoid a panic
in a debug build or a crazy number in a release build.

Signed-off-by: Dylan Reid <dgreid@dylanreid.com>
2026-03-26 08:54:54 +00:00
Alyssa Ross
0b90180266 vmm: use UAPI name for PIDTYPE_PID
As far as I can tell, PIDTYPE_PID is a kernel-internal name, and
PR_SCHED_CORE_SCOPE_THREAD is the UAPI name.  There's no PIDTYPE_PID
in the UAPI headers, and the core scheduling documentation says that
the fourth prctl argument should be a "PR_SCHED_CORE_SCOPE_-prefixed
macro constant".

Link: https://www.kernel.org/doc/html/v6.19/admin-guide/hw-vuln/core-scheduling.html#usage
Fixes: 3f800d2bb ("vmm: Add core scheduling support for vCPU threads")
Signed-off-by: Alyssa Ross <hi@alyssa.is>
2026-03-25 16:36:29 +00:00
Rob Bradford
a8d962640f build: Use newer virtiofsd
Switch to a git hash of virtiofsd as unfortunately the last release is
some time ago and does not incorporate a dependency bump that enables it
to work with snapshot-restore.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-03-25 15:19:56 +00:00
Rob Bradford
11d8ac48cb build: Use released vfio & vhost crates
Replace the git dependencies with newly released versions

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-03-25 13:48:34 +00:00
Muminul Islam
80ce696006 tests: add CVM test for vdpa_block
Add a CVM integration test for vdpa_block that validates
the same functionality using a confidential guest with
the basic_cvm_guest macro and with_cpu(2).

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
7e62565cca tests: add CVM test for macvtap_hotplug
Add a CVM integration test for macvtap_hotplug that validates
the same functionality using a confidential guest with the
basic_cvm_guest macro and with_cpu(2).

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
b7bd19b24a tests: add CVM test for macvtap
Add a CVM integration test for macvtap that validates
the same functionality using a confidential guest with
the basic_cvm_guest macro and with_cpu(2).

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
6fa6ead2b3 tests: add CVM test for tap_from_fd
Add a CVM integration test for tap_from_fd that validates
the same functionality using a confidential guest with
the basic_cvm_guest macro and with_cpu(2).

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
7d672872d6 tests: add CVM test for pvpanic
Add a CVM integration test for pvpanic that validates
the same functionality using a confidential guest with
the basic_cvm_guest macro.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
5ad9822a50 tests: add CVM test for watchdog
Add a CVM integration test for watchdog that validates
the same functionality using a confidential guest with
the basic_cvm_guest macro and FOCAL_IMAGE_NAME.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
81f26bd995 tests: add CVM test for counters
Add a CVM integration test for counters that validates
the same functionality using a confidential guest with
the basic_cvm_guest macro.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
9a88b9a42e tests: add CVM test for net_hotplug
Add a CVM integration test for net_hotplug that validates
the same functionality using a confidential guest with
the basic_cvm_guest macro.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
60abdf0ea1 tests: add CVM test for disk_hotplug
Add a CVM integration test for disk_hotplug that validates
the same functionality using a confidential guest with
the basic_cvm_guest macro.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
9564b4f278 tests: add CVM test for landlock
Add a CVM integration test for landlock that validates
the same functionality using a confidential guest with
the basic_cvm_guest macro.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
833d1d39a5 tests: add CVM test for memory_overhead
Add a CVM integration test for memory_overhead that validates
the same functionality using a confidential guest with the
basic_cvm_guest macro and custom memory size.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
0c477c12ec tests: add CVM test for pci_bar_reprogramming
Add a CVM integration test for pci_bar_reprogramming that
validates the same functionality using a confidential guest
with the basic_cvm_guest macro.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
f4df95c142 tests: add CVM test for direct_kernel_boot_noacpi
Add a CVM integration test for direct_kernel_boot_noacpi
that validates the same functionality using a confidential
guest with the basic_cvm_guest macro.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
a4f1c65b14 tests: add CVM test for console_file
Add a CVM integration test for console_file that validates
the same functionality using a confidential guest with
the basic_cvm_guest macro.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
e9d8ecf38a tests: add CVM test for virtio_console
Add a CVM integration test for virtio_console that validates
the same functionality using a confidential guest with
the basic_cvm_guest macro.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
36871b3547 tests: add CVM test for serial_off
Add a CVM integration test for serial_off that validates
the same functionality using a confidential guest with
the basic_cvm_guest macro.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
108391f720 tests: add CVM test for multiple_network_interfaces
Add a CVM integration test for multiple_network_interfaces
that validates the same functionality using a confidential
guest with the basic_cvm_guest macro.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
e89b584694 tests: extract _test_vdpa_block to tests_wrappers
Extract test logic from test_vdpa_block into a shared
_test_vdpa_block wrapper function in tests_wrappers.rs.
The vdpa module check is kept in the parent test case.
Update the parent to use basic_regular_guest macro with
with_cpu(2). The wrapper uses default_kernel_cmdline()
for kernel/cmdline setup.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
205bb5ff5e tests: extract _test_macvtap to tests_wrappers
Extract test logic from _test_macvtap into a shared wrapper
function in tests_wrappers.rs. Update both test_macvtap and
test_macvtap_hotplug to use the basic_regular_guest macro
with with_cpu(2). The wrapper uses default_kernel_cmdline()
for kernel/cmdline setup.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
a3423a4483 tests: extract _test_tap_from_fd to tests_wrappers
Extract test logic from test_tap_from_fd into a shared
_test_tap_from_fd wrapper function in tests_wrappers.rs.
Update the parent test case to use the basic_regular_guest
macro with with_cpu(2). The wrapper uses
default_kernel_cmdline() for kernel/cmdline setup.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
17774ee564 tests: extract _test_pvpanic to tests_wrappers
Extract test logic from test_pvpanic into a shared
_test_pvpanic wrapper function in tests_wrappers.rs.
Update the parent test case to use the basic_regular_guest
macro. The wrapper uses default_kernel_cmdline() for
kernel/cmdline setup.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
93a3fc5b91 tests: extract _test_watchdog to tests_wrappers
Extract test logic from test_watchdog into a shared
_test_watchdog wrapper function in tests_wrappers.rs.
Update the parent test case to use the basic_regular_guest
macro with FOCAL_IMAGE_NAME. The wrapper uses
default_kernel_cmdline() for kernel/cmdline setup.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
4b77ac26d1 tests: extract _test_counters to tests_wrappers
Extract test logic from test_counters into a shared
_test_counters wrapper function in tests_wrappers.rs.
Update the parent test case to use the basic_regular_guest
macro. The wrapper uses default_kernel_cmdline() for
kernel/cmdline setup.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
7284c02d31 tests: extract _test_net_hotplug to tests_wrappers
Extract test logic from _test_net_hotplug into a shared
wrapper function in tests_wrappers.rs. Update both
test_net_hotplug and test_net_multi_segment_hotplug to
use the basic_regular_guest macro. The wrapper uses
default_kernel_cmdline() for kernel/cmdline setup.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00