Commit Graph

10001 Commits

Author SHA1 Message Date
Anatol Belski
7dd1978fce performance-metrics: Add QCOW2 compressed read micro benchmark
Add micro_bench_qcow_compressed_read which reads clusters from a
zlib compressed QCOW2 image. Every cluster triggers decompression,
isolating the decompression overhead from the normal allocated cluster
read path.

Workloads: 128 and 256 clusters.
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-16 17:27:38 +00:00
Anatol Belski
aca64ced8f performance-metrics: Add compressed QCOW2 tempfile helper
Add compressed_qcow_tempfile() which creates a zlib compressed QCOW2
image by populating a RAW tempfile with data and converting it via
qemu-img convert -c.  Every cluster in the resulting image is stored
compressed so reads exercise the decompression path.

To be used by the compressed read benchmark.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-16 17:27:38 +00:00
Anatol Belski
b2430d701b performance-metrics: Add QCOW2 copy-on-write write micro benchmark
Add micro_bench_qcow_cow_write which writes clusters into a QCOW2
overlay backed by a raw file.  Each write triggers copy-on-write:
cluster allocation, L2 and refcount table updates, then the data
write.  This measures COW allocation overhead compared to writing
into a plain empty image.

Workloads: 128 and 256 clusters.
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-16 17:27:38 +00:00
Anatol Belski
79b58c0faf performance-metrics: Add QCOW2 backing file read micro benchmark
Add micro_bench_qcow_backing_read which reads clusters from a QCOW2
overlay where all data lives in a raw backing file.  Every read falls
through the L2 lookup to the backing file, exercising the backing
chain read path.

Workloads: 128 and 256 clusters.
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-16 17:27:38 +00:00
Anatol Belski
bdce007aac performance-metrics: Add QCOW2 overlay tempfile helper
Add qcow_overlay_tempfile() which creates a raw backing file with
pre-populated data and a QCOW2 overlay on top with no allocated
clusters.  The overlay is opened with backing file support via
QcowDiskSync so reads fall through to the backing file.

To be used by backing file read and copy-on-write write
benchmarks.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-16 17:27:38 +00:00
Anatol Belski
99b4320279 performance-metrics: Add qcow2 random read micro benchmark
Add micro_bench_qcow_random_read which reads clusters from a
prepopulated qcow2 image in a deterministic pseudo-random order.
Unlike the sequential read benchmark, this exercises L2 cache miss
and eviction behaviour under random access patterns.

Uses Fisher-Yates shuffle with DefaultHasher for reproducible
permutation across runs.

Two TEST_LIST entries: micro_block_qcow_random_read_128_us and
micro_block_qcow_random_read_256_us with 128 and 256 cluster
workloads.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-16 17:27:38 +00:00
Anatol Belski
638cb3d7f2 performance-metrics: Add deterministic permutation helper
Add deterministic_permutation() which produces a reproducible
pseudo random permutation of [0, n) using a Fisher-Yates shuffle
seeded by DefaultHasher. This is used by the random read micro
benchmarks to generate a fixed access pattern that is identical
across runs.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-16 17:27:38 +00:00
Anatol Belski
e802c0d8b9 performance-metrics: Add qcow2 fsync micro benchmark
Add micro_bench_qcow_fsync which writes num_ops clusters into an
empty qcow2 image to dirty L2 and refcount metadata then times a
single fsync call that flushes all dirty tables to disk. This
isolates the metadata flush cost which scales with the number of
dirty L2 table entries and refcount blocks.

Two TEST_LIST entries: micro_block_qcow_fsync_64_us and
micro_block_qcow_fsync_256_us with 64 and 256 cluster workloads.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-16 17:27:38 +00:00
Anatol Belski
c3312dca3f performance-metrics: Add qcow2 punch hole micro benchmark
Add micro_bench_qcow_punch_hole which times punch_hole calls through
QcowSync on a prepopulated qcow2 image. Each call deallocates one
cluster exercising deallocate_bytes with refcount decrement and
fallocate punch_hole on the host file.

Two TEST_LIST entries: micro_block_qcow_punch_hole_64_us and
micro_block_qcow_punch_hole_256_us with 64 and 256 cluster workloads.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-16 17:27:38 +00:00
Anatol Belski
f7e40eec9a performance-metrics: Add QCOW2 write micro benchmark
Add micro_bench_qcow_write which times write_vectored calls through
QcowSync on an empty QCOW2 image. Each write allocates a new cluster
exercising map_cluster_for_write with L2 entry allocation and refcount
updates followed by pwrite_all.

Two TEST_LIST entries: micro_block_qcow_write_128_us and
micro_block_qcow_write_256_us with 128 and 256 cluster workloads.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-16 17:27:38 +00:00
Anatol Belski
9f317895b5 performance-metrics: Add submit_writes helper
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-16 17:27:38 +00:00
Anatol Belski
0854c3e082 performance-metrics: Add empty QCOW2 tempfile helper
Add empty_qcow_tempfile() which creates a QCOW2 v3 image with no
allocated clusters so every write triggers the full cluster allocation
path including L2 entry allocation and refcount updates.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-16 17:27:38 +00:00
Anatol Belski
6cd3395a55 performance-metrics: Add QCOW2 read micro benchmark
Add micro_bench_qcow_read which times read_vectored calls through
QcowSync on a prepopulated QCOW2 image. This exercises the hot
read path including L2 lookup, pread64 for allocated clusters and
iovec scatter.

Two TEST_LIST entries: micro_block_qcow_read_128_us and
micro_block_qcow_read_256_us with 128 and 256 cluster workloads.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-16 17:27:38 +00:00
Anatol Belski
beaa98728c performance-metrics: Add iovec construction helpers
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-16 17:27:38 +00:00
Anatol Belski
f8deeb8a1c performance-metrics: Add submit_reads helper
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-16 17:27:38 +00:00
Anatol Belski
97b109bc89 performance-metrics: Add sync drain completions helper
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-16 17:27:38 +00:00
Anatol Belski
ab1dddb62a performance-metrics: Add QCOW2 tempfile helpers
Add qcow_tempfile() which creates a QCOW2 v3 image with all clusters
allocated via QcowFile::new plus sequential writes, then reopens it
as QcowDiskSync. Add QCOW_CLUSTER_SIZE constant for the default
64 KiB cluster size.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-16 17:27:38 +00:00
Anatol Belski
4a607ed82d performance-metrics: Enable io_uring feature on block crate
Enable the io_uring feature so that QcowDiskAsync and QcowAsync are
available for async path micro benchmarks.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-16 17:27:38 +00:00
Dylan Reid
c1b4fcc750 virtio-devices: More detailed vhost user errors
Make it easier to chase down which vhost user socket failed and why in
systems that have many vhost user devices.

Signed-off-by: Dylan Reid <dgreid@fb.com>
2026-04-16 19:18:00 +01:00
Keith Adler
07b77b0f4b ci: remove pinned cross version from quality.yaml
Remove the pinned cross-version commit hash from all
houseabsolute/actions-rust-cross usages. The pin was added as a
workaround for virtio-bindings build issues that have since been
resolved upstream.

Closes #7180

Signed-off-by: Keith Adler <kadler@cloudflare.com>
2026-04-16 14:32:48 +01:00
Anirudh Rayabharam
c7a152ee79 performance-metrics: fix overly broad process cleanup
Drop the -f flag from the process termination command in
cleanup_stale_processes() so it matches by process name only, not the
full command line. This prevents terminating unrelated processes whose
arguments happen to contain target strings (e.g., the test runner
invoked with --report-file /cloud-hypervisor/report.json).

Use the truncated name 'cloud-hyperviso' because Linux limits process
names to 15 characters.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Anirudh Rayabharam <anrayabh@microsoft.com>
2026-04-16 14:12:48 +01:00
Leander Kohler
005ce38ffd main: add --no-shutdown
Add a CLI-only --no-shutdown flag that keeps the VMM process alive
after a guest-triggered shutdown.

Management software may still need the Cloud Hypervisor process
after the guest has powered off. Exposing this separately lets
management software, for example libvirt, keep the VMM around in a
way that is closer to QEMU.

The flag only affects the GuestExit path. Fatal exits and other
existing VMM shutdown paths remain unchanged.

On-behalf-of: SAP leander.kohler@sap.com
Signed-off-by: Leander Kohler <leander.kohler@cyberus-technology.de>
2026-04-15 17:58:56 +00:00
Leander Kohler
a159152e41 devices: route guest shutdown via guest exit
Plumb ACPI S5 shutdown through guest_exit_evt instead of the shared
exit path.

This keeps guest-triggered shutdown separate from fatal VMM exit
handling. Management software, for example libvirt, expects that
distinction, and making it explicit aligns Cloud Hypervisor more
closely with QEMU.

Only the guest shutdown path is moved here. Reboot handling stays on
reset_evt and non-guest exit paths are left unchanged.

On-behalf-of: SAP leander.kohler@sap.com
Signed-off-by: Leander Kohler <leander.kohler@cyberus-technology.de>
2026-04-15 17:58:56 +00:00
Leander Kohler
c698075157 vmm: add guest exit event path
Introduce a dedicated guest_exit_evt and a matching epoll dispatch
path for guest-triggered shutdowns.

This series is needed because managment software such as libvirt may
still need the Cloud Hypervisor process to stay alive after the guest
has shut down.
Today a guest-triggered shutdown can make the VMM disappear immediately,
which means the managment software can lose track of the VM run-state.

This must only apply to guest-triggered shutdowns. Fatal error paths
and other internal exit paths must keep using the existing VMM exit
handling.

For now GuestExit still calls vmm_shutdown(), so this commit only adds
the separate plumbing and keeps the current behavior unchanged.

On-behalf-of: SAP leander.kohler@sap.com
Signed-off-by: Leander Kohler <leander.kohler@cyberus-technology.de>
2026-04-15 17:58:56 +00:00
Anatol Belski
dc0e003be0 block: qcow: Add AlignedBuf size rounding test
Verify that AlignedBuf rounds the allocation size up to the
requested alignment. Passes under miri.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-15 17:28:58 +00:00
Anatol Belski
a84a0b8b25 block: qcow: Add AlignedBuf allocation and access test
Test AlignedBuf with 512 and 4096 byte alignment. Verify pointer
alignment, zero initialization, and write/read round trip. Passes
under miri.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-15 17:28:58 +00:00
Anatol Belski
11cf332114 tests: Add Windows QCOW2 guest boot with direct I/O test
Boot a Windows guest from a qcow2 overlay with direct=on. After
boot, write 5 randomly filled files from 4MB to 20MB, copy each
file, and compare SHA256 hashes to verify data integrity through
the aligned bounce buffer path.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-15 17:28:58 +00:00
Anatol Belski
e5ad85d7de test_infra: Prepare QCOW2 overlay for Windows guests
WindowsDiskConfig now creates a qcow2 overlay backed by the raw
Windows image during prepare_files(). The overlay is placed under
~/workloads alongside the raw image. Writes go into the overlay
so the backing raw image stays unmodified, matching the CoW
semantics already provided by the dm snapshot for raw tests.

Drop removes the qcow2 file.

The DiskConfig trait gains a qcow2_disk() default method returning
None. WindowsDiskConfig overrides it to expose the overlay path.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-15 17:28:58 +00:00
Anatol Belski
ab81112618 block: qcow: Test aligned pread and pwrite with 4096 alignment
Exercise both aligned_pread and aligned_pwrite with 4096 byte
alignment instead of 512. Verify written data and that surrounding
regions are preserved.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-15 17:28:58 +00:00
Anatol Belski
7aa477936e block: qcow: Test aligned_pwrite unaligned offset
Write at offset 100 with alignment 512 so the read modify write
path is exercised. Verify the written region and that surrounding
data is preserved.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-15 17:28:58 +00:00
Anatol Belski
5ed9f2e3d8 block: qcow: Test aligned_pwrite bounce unaligned buffer
Write 4096 bytes via plain Vec<u8> whose address is not guaranteed
to be aligned. The bounce buffer path copies data into an aligned
allocation before the syscall. Read back with pread_exact to verify
data integrity.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-15 17:28:58 +00:00
Anatol Belski
32af2f2a22 block: qcow: Test aligned_pwrite pass through path
Write 4096 bytes of pattern data at offset 0 using AlignedBuf
and verify data integrity via plain pread_exact. All parameters
are naturally aligned to 512 so the fast path is exercised.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-15 17:28:58 +00:00
Anatol Belski
05d52d0353 block: qcow: Add aligned_pread unaligned offset test
Test that aligned_pread handles a non aligned offset by
rounding down, reading an aligned region, and returning the
correct slice from within the bounce buffer.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-15 17:28:58 +00:00
Anatol Belski
021838b63c block: qcow: Add aligned_pread bounce buffer test
Test that aligned_pread correctly uses a bounce buffer when
the caller buffer address is not aligned.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-15 17:28:58 +00:00
Anatol Belski
fe711b3a0b block: qcow: Add aligned_pread pass through test
Test that aligned_pread takes the fast path when buffer
address, length, and offset are all properly aligned.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-15 17:28:58 +00:00
Anatol Belski
7fd5e74f0e block: qcow: Add multi iovec read/write test
Exercise scatter/gather with multiple iovecs per operation,
covering both the standard and direct_io paths. Write uses
3 iovecs with distinct patterns, read uses 3 iovecs with
different sizes, then reassembles and compares.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-15 17:28:58 +00:00
Anatol Belski
b62525f792 block: qcow: Add direct_io test coverage for QcowSync
Add direct_io variants for suitable tests by extracting
test bodies into _impl(direct_io: bool) functions. Each
original test calls _impl(false) and a new _direct_io test
calls _impl(true).

When direct_io is true, RawFile probes alignment and QcowSync
exercises the AlignedBuf and bounce buffer paths in
read_vectored and write_vectored.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-15 17:28:58 +00:00
Anatol Belski
cfa60a95b9 block: qcow: Use aligned I/O in QcowAsync
Store the alignment from the data file in QcowAsync. Use
aligned_pread in scatter_read_sync and aligned_pwrite with
gather_from_iovecs_into in cow_write_sync, matching the
QcowSync approach.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-15 17:28:58 +00:00
Anatol Belski
fd8495b342 block: qcow: Use aligned I/O in QcowSync
Store the alignment from the data file in QcowSync. Use AlignedBuf
directly in read_vectored and write_vectored as the intermediate
buffer so that aligned_pread/aligned_pwrite can skip the bounce
copy when offset and length are naturally aligned.

Use gather_from_iovecs_into to gather iovec data directly into the
aligned buffer.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-15 17:28:58 +00:00
CMGS
f50b5ab1f2 block: qcow: Add aligned bounce buffers for O_DIRECT I/O
When the data file is opened with O_DIRECT, buffer address, length,
and file offset must satisfy the device alignment.

Add AlignedBuf RAII wrapper and aligned_pread/aligned_pwrite helpers
in qcow_common that use bounce buffers when alignment constraints
are not met. For writes with misaligned offset, a read modify write
is performed on the aligned region.

gather_from_iovecs_into gathers iovec data directly into a caller
provided buffer, avoiding an intermediate Vec allocation.

Fixes: #8007
Signed-off-by: CMGS <ilskdw@gmail.com>
Co-authored-by: Anatol Belski <anbelski@linux.microsoft.com>
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-15 17:28:58 +00:00
Anatol Belski
6c1da4f5c1 block: qcow: Expose RawFile alignment as a public accessor
Add pub fn alignment() to RawFile so that callers can
query the O_DIRECT buffer alignment requirement probed
at file open time.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-15 17:28:58 +00:00
Anatol Belski
c35749fb39 block: qcow: Rename Qcow2MetadataBacking to Qcow2Backing
The old name read as 'metadata for a QCOW2 backing file' rather
than what it actually is: a QCOW2 backing file reader. Rename to
Qcow2Backing to parallel RawBacking and clarify intent.

Suggested-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-15 14:40:14 +00:00
Philipp Schuster
39844e8839 docs: refine coding standards in CONTRIBUTING.md
TL;DR: Add note about how we expect code comments/documentation

This updates the coding standards as discussed [0]. The general
guideline is to write down as little process as possible and leave room
for pragmatic exceptions, maintainer and contributor preferences while
still striving for excellent code quality.

[0]: https://github.com/cloud-hypervisor/cloud-hypervisor/pull/7990#issuecomment-4245571054

On-behalf-of: SAP philipp.schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-04-15 15:06:46 +01:00
Philipp Schuster
edfd597993 tests: fix weird "console=ttyS0rw" string
On-behalf-of: SAP philipp.schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-04-15 11:57:23 +00:00
Philipp Schuster
7eab5901ad vmm: improve misc documentation
This improves the documentation at various places.

On-behalf-of: SAP philipp.schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-04-15 11:57:23 +00:00
Philipp Schuster
5ff4696cea vmm: introduce ACPI CPU hotplug controller (fix deadlock)
Extract AcpiCpuHotplugController from CpuManager and move the BusDevice
implementation to the new type. This separates VMM-internal vCPU
management from the guest-visible ACPI CPU hotplug MMIO interface.

Besides clarifying responsibilities and reducing technical debt, this
fixes a rare deadlock involving pause handling and MMIO access.

New responsibilities:
- CpuManager manages VMM-internal vCPU lifecycle and coordination
- AcpiCpuHotplugController implements the guest-visible ACPI CPU hotplug
  MMIO interface

A vCPU thread may exit KVM_RUN to perform an MMIO access previously
handled by CpuManager. If the VMM thread begins processing a `pause`
event before that MMIO operation acquires access to CpuManager,
CpuManager::pause() will block waiting for the vCPU thread to ACK
the pause, while the vCPU thread is blocked waiting to complete the MMIO
operation through the same CpuManager - which it can never lock - the
VMM is deadlocked.

This can occur during early boot or CPU hotplug when pause events race
with MMIO accesses. The issue is rare and timing-dependent, but real.
For reproducing: run `ch-remote pause|resume` in a loop while booting
a Linux VM (via direct kernel boot).

With the new design, these MMIO operations no longer depend on
CpuManager, which removes the deadlock path entirely.

On-behalf-of: SAP philipp.schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-04-15 11:57:23 +00:00
Philipp Schuster
6d0d4bc5e2 vmm: protect vcpu states in CpuManager with a mutex
This is a prerequisite for the next commit where we need shared access.

On-behalf-of: SAP philipp.schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-04-15 11:57:23 +00:00
dependabot[bot]
c657ea6e23 build(deps): bump softprops/action-gh-release from 2 to 3
Bumps [softprops/action-gh-release](https://github.com/softprops/action-gh-release) from 2 to 3.
- [Release notes](https://github.com/softprops/action-gh-release/releases)
- [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md)
- [Commits](https://github.com/softprops/action-gh-release/compare/v2...v3)

---
updated-dependencies:
- dependency-name: softprops/action-gh-release
  dependency-version: '3'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-15 00:43:47 +00:00
Dylan Reid
a6d3901f3e misc: return errors from IOMMU address translation instead of panicking
The address that is passed from the guest should be treated as
untrusted. Currently an invalid address will panic the VMM. This only
allows the guest to hurt itself, but we shouldn't have the VMM crashing.
Instead let's return an error if possible or invalidate the queue if it
happen during setup.

The data flow from guest to translate_gva/translate_gpa is:

  1. Guest writes a raw u64 address into a virtio descriptor in the
     shared descriptor table (guest memory).
  2. The virtio-queue crate reads this descriptor via read_obj() and
     returns the addr field as-is in a GuestAddress — no validation.
  3. Device code calls .translate_gva(access_platform, len) on the
     GuestAddress.
  4. With IOMMU (access_platform is Some): the address is an IOVA that
     must be translated to a GPA via the IOMMU mapping table. If the
     guest provides an unmapped IOVA, translation returns Err.
     Previously, .unwrap() here panicked the VMM.
  5. Without IOMMU (access_platform is None): translate_gva is a no-op
     (returns self). The raw address flows to GuestMemory::read_obj()
     which validates it — out-of-range addresses return
     Err(InvalidGuestAddress), so no host memory corruption is possible.

Signed-off-by: Dylan Reid <dgreid@fb.com>
2026-04-14 23:25:03 +00:00
Anatol Belski
d4fc1d38c8 scripts: dev_cli: Allow io_uring syscalls in unit tests
The unit test container runs with Docker default seccomp
profile which blocks io_uring_setup, io_uring_enter and
io_uring_register. This causes all qcow_async unit tests to
fail with EPERM when creating an io_uring instance.

Add --security-opt seccomp=unconfined to the unit test docker
run invocation. The container already has --device access and
cap_net_admin, so this does not materially change the security
posture.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-04-14 22:11:26 +00:00