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>
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>
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>
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>
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>
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>
Marker trait combining FullDiskFile and AsyncDiskFile. Blanket impl
covers any type implementing both supertraits.
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Add an option that can be used when restoring to resume the VM. This is
particularly useful when restoring the VM via the direct VMM command
line, when you might not want/have an API socket configured.
Signed-off-by: Rob Bradford <rbradford@meta.com>
Skip micro_ prefixed tests in the metrics CI workflow to avoid
dashboard pollution. They can still be run on demand via
--test-filter micro_.
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
Add --test-exclude to process_common_args in test-util.sh and forward
it to the performance-metrics binary from run_metrics.sh.
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
Add a --test-exclude flag that excludes tests matching the provided
keywords. Both --test-filter and --test-exclude are now applied before
--list-tests, so listing respects the active filters.
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
Add test_virtio_block_write_zeroes_unmap_raw to verify that the
VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP code path works correctly with
raw disk images.
The test creates a 128M raw disk and writes 64M of random data,
then uses fallocate --punch-hole on the guest block device, which
the Linux virtio-blk driver translates to VIRTIO_BLK_T_WRITE_ZEROES
with VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP set. It then verifies:
- the zeroed region reads back as zero from the guest
- the host file became sparse (punch_hole succeeded)
- FIEMAP confirms the file has holes
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
The write zeroes segment descriptor (struct
virtio_blk_discard_write_zeroes, virtio spec v1.2 section 5.2.6)
includes a flags field with an unmap bit. Per section 5.2.6.2, if
unmap is set, the device MAY deallocate the specified range of
sectors in the device backend storage, as if the discard command
had been sent.
Read the flags field and when the unmap bit is set, use punch_hole
to deallocate the range. Otherwise continue using write_zeroes via
ZERO_RANGE which preserves allocation.
This allows the guest to reclaim host disk space through write
zeroes requests on thin provisioned images.
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
The virtio vhost-user device backend prefers to use externally-provided
eventfds as irqfds. This allows the frontend VM to notify the backend
VM directly, without the need for a userspace proxy process. Since the
frontend can provide irqfds at any time, the backend needs to register
and unregister irqfds dynamically.
This is tricky because the functions that access the irqfd table all
take `&self`, not `&mut self`. The obvious solution to this problem is
to wrap the table in a mutex. Most of these functions are not called on
hot paths, but `.notifier()` is called whenever Cloud Hypervisor needs
to inject an interrupt into a guest. Most devices don't need to
register irqfds at runtime, and for them, slowing down interrupt
injection would be wasteful.
Instead, require devices to opt-in to irqfd registration. The irqfd
table now comes in two forms: one that contains a mutex and one that
does not. The one containing a mutex can be mutated freely, while
attempting to mutate the one that does not will panic.
Right now, no code registeres irqfds at runtime, but this will change in
subsequent commits.
Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
This allows creating an InterruptSourceGroup with an externally provided
file descriptor. It also allows changing the file descriptor
afterwards.
Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>