Commit Graph

9584 Commits

Author SHA1 Message Date
Wei Liu
6e6127bbda tests: Make test_vdpa_block more flexible
We only care that the device exists under an IOMMU group but not which
one.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2026-03-19 23:11:17 +00:00
Wei Liu
5724a0189c tests: Make the IOMMU segment test case more flexible
Linux kernel's behavior changes overtime. The grouping can be different
across different versions and different architectures.

We only cares about the exact SBDF exists somewhere. It doesn't matter
which group it is under.

Change the check so that this test case is no longer tied to the
grouping behavior of a particular kernel.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2026-03-19 23:11:17 +00:00
Anatol Belski
0d062962ac block: qcow: Remove async_io::DiskFile impl from QcowDiskSync
QcowDiskSync now exclusively uses disk_file::DiskFile and
disk_file::AsyncDiskFile. The old async_io::DiskFile impl is removed
along with its unused imports (DiskFile, DiskFileError, DiskFileResult).

Tests are updated to import the new traits.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
b4dad66d35 virtio-devices: vmm: fuzz: Switch to DiskBackend
Change Block to hold DiskBackend instead of
Box<dyn async_io::DiskFile>. In device_manager, existing formats
(raw, vhd, vhdx) are wrapped in DiskBackend::Legacy while
QcowDiskSync uses DiskBackend::Next. The fuzz target is updated
accordingly.

The Error::DiskResize variant now carries BlockError instead of
DiskFileError, matching the BlockResult return type of
DiskBackend::resize().

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
264013b424 block: disk_file: Add DiskBackend dispatch enum
Introduce DiskBackend with two variants:
- Legacy: wraps Box<dyn async_io::DiskFile> for existing formats
- Next: wraps Box<dyn disk_file::AsyncFullDiskFile>

Methods return BlockResult, with DiskFileError converted up to
BlockError on the Legacy path. The Next path passes through
directly with zero conversion overhead.

This is a transitional type. Once all formats implement
AsyncFullDiskFile, DiskBackend and Legacy are removed and
callers hold Box<dyn AsyncFullDiskFile> directly.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
fe6e3e8fef block: qcow_sync: impl AsyncDiskFile for QcowDiskSync
Implement try_clone by sharing the metadata Arc and cloning the data
file descriptor. The new_async_io method creates a QcowSync worker
identical to the async_io::DiskFile version.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
1fc8e4adb6 block: qcow_sync: impl DiskFile for QcowDiskSync
Marker impl binding the DiskSize and HasTopology supertraits.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
f35bec19e8 block: qcow_sync: impl Resizable for QcowDiskSync
Add ErrorOp::Resize variant and implement the Resizable trait.
Resize is rejected when a backing file is present.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
554562fef2 block: qcow_sync: impl SparseCapable for QcowDiskSync
Advertise support for sparse operations and the zero flag. QCOW2
inherently supports both through cluster deallocation.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
63f5e6e97f block: qcow_sync: impl Geometry for QcowDiskSync
Uses the default DiskTopology (512B logical/physical) since
QCOW2 does not probe the underlying device geometry.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
b305a7670b block: qcow_sync: impl DiskFd for QcowDiskSync
Borrows the raw file descriptor from the underlying QcowRawFile
for fcntl() operations. Uses &self for shared access.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
4b731ee771 block: qcow_sync: impl PhysicalSize for QcowDiskSync
Delegate to QcowRawFile::physical_size() which returns the actual
host allocation size of the QCOW2 container file.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
0a7b6b089b block: qcow_sync: impl DiskSize for QcowDiskSync
Delegate to QcowMetadata::virtual_size() which returns the guest
visible capacity stored in the QCOW2 header.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
ad789024f9 block: qcow_sync: Add Debug impl for QcowDiskSync
The new composable traits require Debug. Implement it manually since
QcowMetadata contains RwLock state that cannot auto derive.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
dac8707c35 block: disk_file: Add AsyncFullDiskFile trait
Marker trait combining FullDiskFile and AsyncDiskFile. Blanket impl
covers any type implementing both supertraits.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
8623edb8aa block: disk_file: Add FullDiskFile trait
Marker trait bundling all optional capabilities (PhysicalSize, DiskFd,
SparseCapable, Resizable) on top of DiskFile. Blanket impl covers any
type implementing all constituent traits.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
50741cca2a block: disk_file: Add AsyncDiskFile trait
Extend DiskFile with async I/O construction for virtio queue workers.

AsyncDiskFile adds try_clone() for creating independent handles to
the same backing storage, and new_async_io() for constructing an
async I/O engine at the given ring depth.

Bounds: DiskFile + Unpin. Unpin ensures trait objects can be moved
freely (all concrete disk file types are naturally Unpin since they
hold no self referential state).

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
5d50d64671 block: disk_file: Add DiskFile supertrait
Bundles DiskSize and Geometry as the universal disk
capabilities every format must implement. Adds Sync so
that Arc<dyn DiskFile> can be shared across threads for
concurrent readonly access.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
da1b104493 block: disk_file: Add Resizable trait
Live disk resize support. Single method resize() taking
&mut self and the new size in bytes. Implementations may
return an error if the backend does not support resizing.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
a0a5718b42 block: disk_file: Add SparseCapable trait
Sparse and zero flag support for thin provisioned disk
images. Two methods with false defaults: sparse operations
(punch hole, write zeroes, discard) and zero flag
optimization in WRITE_ZEROES.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
b98a5cc58d block: disk_file: Add Geometry trait
Sector and cluster geometry of a disk image. Returns
DiskTopology with a default implementation providing
512B logical and physical block sizes. Formats that
probe the underlying device override this.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
2fa877e087 block: disk_file: Add DiskFd trait
Backing file descriptor access for disk images backed by
a file. Returns a BorrowedDiskFd that wraps the raw fd
with lifetime tracking. Not available for network or
memory backed disk formats.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
2df731b8d3 block: disk_file: Add PhysicalSize trait
Host allocation size for file-backed disk images. Reports
actual bytes occupied on the host filesystem. Not every
format supports this, e.g. network or memory backed disks.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
85e4e5027c block: disk_file: Add DiskSize trait
Reported capacity of a disk image. Every format, be it
file backed, network, memory, exposes a logical size.
Single method logical_size() returning the virtual size
in bytes.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Anatol Belski
a15bfcfee6 block: Add disk_file module skeleton
Composable disk capability traits with DiskFile as a supertrait
bundling DiskSize and Geometry. Optional capabilities are
separate traits: PhysicalSize, DiskFd, SparseCapable, Resizable.
AsyncDiskFile extends DiskFile with async I/O construction.

Empty module with doc comment, trait definitions follow.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 22:29:27 +00:00
Muminul Islam
297b683fcb tests: Add virtio block tests for confidential VMs
Add a full suite of test_virtio_block_* tests to the common_cvm
integration test module to verify virtio block functionality in
confidential guest environments.

The following tests are added, all using 4-vCPU confidential
VMs created via GuestFactory:
- test_virtio_block_io_uring (Raw image, io_uring backend)
- test_virtio_block_aio (Raw image, AIO backend)
- test_virtio_block_sync (Raw image, sync backend)
- test_virtio_block_qcow2 (QCOW2 image)
- test_virtio_block_qcow2_zlib (QCOW2 with zlib compression)
- test_virtio_block_qcow2_zstd (QCOW2 with zstd compression)
- test_virtio_block_qcow2_backing_zstd_file
- test_virtio_block_qcow2_backing_uncompressed_file
- test_virtio_block_qcow2_backing_raw_file

This extends CVM test coverage to all virtio block I/O backends
and disk image formats.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
ec730fde21 tests: Refactor _test_virtio_block and utilities to module scope
Move _test_virtio_block to module-level scope, accepting a
Guest reference instead of an image name string. Replace
hardcoded CPU, kernel, and cmdline arguments with default_cpus
and default_kernel_cmdline.

Promote all supporting disk utilities to module-level scope:
compute_backing_checksum, disk_check_consistency, run_qemu_img,
get_image_info, get_qcow2_v3_info, check_dirty_flag,
check_corrupt_flag, set_corrupt_flag, resolve_disk_path, and
compute_file_checksum.

Update all test_virtio_block_* call sites in common_parallel
to create guests via GuestFactory::new_regular_guest_factory()
with 4 vCPUs and pass them to the helper. This enables reuse
with different guest types such as confidential VMs.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
af4a14fa70 tests: Add direct kernel boot test for confidential VMs
Add test_direct_kernel_boot to the common_cvm integration test
module to verify that boot, CPU, memory, and MSI interrupt
functionality work correctly in confidential guest environments.

The test creates an Ubuntu Jammy-based confidential VM using
GuestFactory and delegates to the existing
_test_direct_kernel_boot helper.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
3b56ec240a tests: Refactor test_direct_kernel_boot into reusable helper
Extract direct kernel boot test logic into a standalone
_test_direct_kernel_boot helper that accepts a Guest reference.
The helper boots a VM, validates CPU count and memory using
generic validate_cpu_count and validate_memory methods, and
asserts 12 MSI interrupts in /proc/interrupts.

Replace hardcoded kernel and cmdline arguments with
default_kernel_cmdline(). Update the test call site in
common_parallel to use GuestFactory and delegate to the new
helper, enabling reuse with different guest types.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
38dc35cc33 tests: Add PCI multiple segments test for confidential VMs
Add test_pci_multiple_segments to the common_cvm integration
test module to verify multiple PCI segment support in
confidential guest environments.

The test uses 8 PCI segments, which exceeds the Linux default
of 6 and matches the maximum supported by the IGVM file for
SEV-SNP guests. A test disk is placed on segment 5 to validate
cross-segment device functionality.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
62bb7bfe45 tests: Refactor _test_pci_multiple_segments
Extract common PCI multiple segment disk test logic into
_test_pci_multiple_segments() and reuse it from the test case.

Switch guest creation to GuestFactory in test_pci_multiple_segments
and pass segment values through helper parameters.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
2aa92bf4b4 tests: Add platform argument support to kernel cmdline builder
Introduce default_kernel_cmdline_with_platform() in GuestCommand
that accepts an optional platform parameter. For confidential
VMs, the platform arg is prepended to sev_snp=on. For regular
VMs, it is passed via --platform if provided.

Retain default_kernel_cmdline() as a convenience wrapper that
calls the new method with None, preserving backward
compatibility.

This enables tests to pass additional platform configuration
such as num_pci_segments alongside the default kernel and
cmdline setup.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
6f8776ac50 tests: Add virtio net ctrl queue test for confidential VMs
Add test_virtio_net_ctrl_queue to the common_cvm integration
test module to verify that virtio net control queue functionality
works correctly in confidential guest environments.

The test creates an Ubuntu Jammy-based confidential VM using
GuestFactory and delegates to the existing
_test_virtio_net_ctrl_queue helper to validate MTU configuration
and ethtool offload settings.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
5378f8d614 tests: Refactor test_virtio_net_ctrl_queue into reusable helper
Extract virtio net control queue test logic into a standalone
_test_virtio_net_ctrl_queue helper that accepts a Guest
reference. The helper boots a VM with MTU 3000, verifies
ethtool can disable rx-gro-hw, and asserts the guest interface
MTU is correctly set.

Replace hardcoded kernel and cmdline arguments with
default_kernel_cmdline(). Update the test call site in
common_parallel to use GuestFactory and delegate to the new
helper, enabling reuse with different guest types.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
31f1e67be7 tests: Add PCI MSI interrupt test for confidential VMs
Add test_pci_msi to the common_cvm integration test module to
verify that PCI MSI interrupt functionality works correctly in
confidential guest environments.

The test creates an Ubuntu Jammy-based confidential VM using
GuestFactory and delegates to the existing _test_pci_msi helper
to validate MSI interrupts.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
acec5b00d6 tests: Refactor test_pci_msi into reusable helper
Extract PCI MSI interrupt test logic from test_pci_msi into a
standalone _test_pci_msi helper that accepts a Guest reference.
The helper boots a VM, waits for boot, and asserts that 12 MSI
interrupts are present in /proc/interrupts.

Replace hardcoded kernel and cmdline arguments with
default_kernel_cmdline(). Update the test call site in
common_parallel to use GuestFactory and delegate to the new
helper, enabling reuse with different guest types.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
bad5da622e tests: Add virtio queue affinity test for confidential VMs
Add test_virtio_queue_affinity to the common_cvm integration
test module to verify that per-queue CPU pinning works correctly
in confidential guest environments.

The test creates a 4-vCPU Ubuntu Jammy-based confidential VM
using GuestFactory and delegates to the existing
_test_virtio_queue_affinity helper to validate queue-to-core
affinity settings.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
c761d741bf tests: Refactor test_virtio_queue_affinity into reusable helper
Extract virtio queue affinity test logic into a standalone
_test_virtio_queue_affinity helper that accepts a Guest
reference. The helper verifies the host has at least 4 CPUs,
boots a VM with per-queue affinity on the cloud-init disk,
and asserts each disk queue thread is pinned to the expected
cores.

Replace hardcoded kernel and cmdline arguments with
default_cpus() and default_kernel_cmdline(). Update the
test call site in common_parallel to use GuestFactory and
delegate to the new helper, enabling reuse with different
guest types.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
7bf439975f tests: Add CPU affinity test for confidential VMs
Add test_cpu_affinity to the common_cvm integration test module
to verify that CPU pinning works correctly in confidential
guest environments.

The test creates a 2-vCPU Ubuntu Jammy-based confidential VM
using GuestFactory and delegates to the existing
_test_cpu_affinity helper to validate vCPU-to-core affinity.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
9059fb902d tests: Refactor test_cpu_affinity into reusable helper
Extract CPU affinity test logic from test_cpu_affinity into a
standalone _test_cpu_affinity helper that accepts a Guest
reference. The helper verifies the host has at least 4 CPUs,
boots a VM with affinity settings, and asserts vcpu0 is pinned
to cores 0,2 and vcpu1 to cores 1,3.

Add default_cpus_with_affinity_string() to Guest and
default_cpus_with_affinity() to GuestCommand in test_infra
to generate CPU arguments with affinity configuration.

Update the test_cpu_affinity call site in common_parallel to
use GuestFactory and delegate to the new helper, enabling
reuse with different guest types.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
848a280483 tests: Add multi-CPU test for confidential VMs
Add test_multi_cpu to the common_cvm integration test module
to verify that multi-CPU functionality works correctly in
confidential guest environments.

The test creates an Ubuntu Jammy-based confidential VM using
GuestFactory and delegates to the existing _test_multi_cpu
helper to validate SMP boot with multiple vCPUs.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
18ed8e61d2 tests: Refactor test_multi_cpu into reusable helper
Extract the multi-CPU test logic from the test_multi_cpu test
into a standalone _test_multi_cpu helper that accepts a Guest
reference as a parameter.

Update the test_multi_cpu call site in common_parallel to
create the guest via GuestFactory::new_regular_guest_factory()
and delegate to the new helper. This enables reuse of the test
logic with different guest types such as confidential VMs.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
c44b7679cf tests: Add virtio vsock test for confidential VMs
Add test_virtio_vsock to the common_cvm integration test module
to verify that virtio vsock functionality works correctly in
confidential guest environments.

The test creates an Ubuntu Jammy-based confidential VM using
GuestFactory and delegates to the existing _test_virtio_vsock
helper with hotplug disabled.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
dacc92a08f tests: Refactor _test_virtio_vsock to accept Guest parameter
Extract guest and kernel setup out of _test_virtio_vsock and
pass a Guest reference as a parameter instead. Replace explicit
kernel and cmdline arguments with default_kernel_cmdline().

Move guest creation to the test call sites using
GuestFactory::new_regular_guest_factory(), enabling reuse of
the helper with different guest types such as confidential VMs.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
b6d8df772d tests: Add power button test for confidential VMs
Add test_power_button to the common_cvm integration test module
to verify that power button functionality works correctly in
confidential guest environments.

The test creates an Ubuntu Jammy-based confidential VM using
GuestFactory and delegates to the existing _test_power_button
helper to validate the power button signal handling.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Muminul Islam
e278e5e931 tests: Refactor _test_power_button to accept Guest parameter
Remove the acpi bool parameter and internal guest and kernel
setup from _test_power_button. The function now accepts a Guest
reference and uses default_kernel_cmdline() instead of
hardcoded kernel paths.

Update test_power_button in common_parallel to create a regular
guest via GuestFactory. Update test_power_button_acpi in
aarch64_acpi to use with_kernel_path(edk2_path()) for ACPI
firmware support.

Add with_kernel_path() builder method on Guest in test_infra
to allow overriding the kernel path after guest creation.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-19 16:17:28 +00:00
Anatol Belski
19fa512f02 block: Batch drain AIO completions in next_completed_request
Collect up to 32 completions per io_getevents call instead of one
at a time, buffering them in the existing VecDeque. This reduces
syscalls from 128 to 4 per drain cycle at the default queue depth.
The stack cost is 1 KB per call.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 12:20:19 +00:00
Anatol Belski
0ee0441f2b virtio-devices: block: Derive discard alignment from topology
Set discard_sector_alignment from the logical block size
reported by the backend topology instead of hardcoding it
to 1 sector. This gives the guest accurate alignment hints
so it can avoid sub block discards that the filesystem
might silently ignore.

For example, on a 4K block filesystem the alignment is now
8 sectors (4096/512) instead of 1.

For image formats with their own allocation units (QCOW2
clusters, VHD/VHDX block sizes), the ideal alignment would
be derived from the format cluster/block size. This is
left for a followup that surfaces allocation granularity
through DiskTopology.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-19 01:07:49 +00:00
Anatol Belski
9655eaddd5 block: Use offset_of! for virtio_blk_discard_write_zeroes field offsets
Replace magic numeric offsets with mem::offset_of!() referencing the
virtio_blk_discard_write_zeroes struct from the virtio-bindings crate
when reading the sector, num_sectors and flags fields in the DISCARD
and WRITE_ZEROES request handlers.

No functional change.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-18 21:12:12 +00:00
Rob Bradford
54b27d8812 vmm: openapi: Add resume field to RestoreConfig
Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-03-18 16:36:55 +00:00