Commit Graph

9634 Commits

Author SHA1 Message Date
Muminul Islam
aead6dd59f tests: use basic_regular_guest macro in test_virtio_vsock_hotplug
Replace manual UbuntuDiskConfig and GuestFactory guest
creation with the basic_regular_guest! macro in
test_virtio_vsock_hotplug. The aarch64 variant chains
with_kernel_path for EDK2 firmware support.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
b9c9e7265d tests: use basic_regular_guest macro in test_virtio_vsock
Replace manual UbuntuDiskConfig and GuestFactory guest
creation with the basic_regular_guest! macro in
test_virtio_vsock for consistency and reduced boilerplate.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
a6724ba79f tests: use basic_regular_guest macro in test_direct_kernel_boot
Replace manual UbuntuDiskConfig and GuestFactory guest
creation with the basic_regular_guest! macro in
test_direct_kernel_boot for consistency and reduced
boilerplate.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
84951127b7 tests: use basic_regular_guest macro in test_pci_multiple_segments
Replace manual UbuntuDiskConfig and GuestFactory guest
creation with the basic_regular_guest! macro in
test_pci_multiple_segments for consistency and reduced
boilerplate.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
54c91b0281 tests: use basic_regular_guest macro in test_virtio_net_ctrl_queue
Replace manual UbuntuDiskConfig and GuestFactory guest
creation with the basic_regular_guest! macro in
test_virtio_net_ctrl_queue for consistency and reduced
boilerplate.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
4c4cf940ec tests: use basic_regular_guest macro in test_pci_msi
Replace manual UbuntuDiskConfig and GuestFactory guest
creation with the basic_regular_guest! macro in
test_pci_msi for consistency and reduced boilerplate.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
43731149c8 tests: use basic_regular_guest macro in test_power_button
Replace manual UbuntuDiskConfig and GuestFactory guest
creation with the basic_regular_guest! macro in
test_power_button for consistency and reduced boilerplate.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
43fb142afb tests: use basic_regular_guest macro in test_virtio_queue_affinity
Replace manual UbuntuDiskConfig and GuestFactory guest
creation with the basic_regular_guest! macro in
test_virtio_queue_affinity, chaining with_cpu(4) for the
required CPU count configuration.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
bcdbc875be tests: use basic_regular_guest macro in test_cpu_affinity
Replace manual UbuntuDiskConfig and GuestFactory guest
creation with the basic_regular_guest! macro in
test_cpu_affinity, chaining with_cpu(2) for the required
CPU count configuration.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
b1a0ab4d1f tests: use basic_regular_guest macro in test_multi_cpu
Replace manual UbuntuDiskConfig and GuestFactory guest
creation with the basic_regular_guest! macro in
test_multi_cpu for consistency and reduced boilerplate.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
5f4ad4bb1e tests: extract _test_dmi_serial_number to tests_wrappers
Move the DMI serial number test logic from integration.rs
into a shared _test_dmi_serial_number() function in
tests_wrappers.rs. The original test now delegates to
this shared function, enabling reuse by CVM tests.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
b65a3a58f3 tests: add CVM test for split_irqchip
Add a CVM variant of the split IRQ chip test in
integration_cvm.rs. This test creates a confidential
guest and invokes the shared _test_split_irqchip()
wrapper to validate split IRQ chip behavior under CVM.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
56696ed901 tests: extract _test_split_irqchip to tests_wrappers
Move the split IRQ chip test logic from integration.rs
into a shared _test_split_irqchip() function in
tests_wrappers.rs. The original test now delegates to
this shared function, enabling reuse by CVM tests.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
2929cc9d16 tests: add CVM test for virtio_block_dynamic_vhdx_expand
Add a CVM variant of the virtio block dynamic VHDX expand
test in integration_cvm.rs. This test creates a
confidential guest and invokes the shared
_test_virtio_block_dynamic_vhdx_expand() wrapper to
validate VHDX expansion under CVM.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
ac8d4c2953 tests: extract _test_virtio_block_dynamic_vhdx_expand
Move the virtio block dynamic VHDX expand test logic from
integration.rs into a shared _test_virtio_block_dynamic_
vhdx_expand() function in tests_wrappers.rs. The original
test in integration.rs now calls this shared function,
enabling reuse by CVM tests.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
6aad6e40c8 tests: use basic_regular_guest macro in OVMF test
Refactor test_focal_ovmf to use the basic_regular_guest!
macro with the with_kernel() builder instead of manually
constructing UbuntuDiskConfig and setting kernel_path.
This also removes leftover unused disk_config in
test_focal_hypervisor_fw.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
0fc0f2bd0e tests: add basic_regular_guest macro and with_kernel
Introduce a basic_regular_guest! macro in integration.rs
to reduce boilerplate when creating regular (non-CVM)
guest instances. Also add a with_kernel() builder method
to Guest in test_infra, allowing fluent configuration of
the kernel path.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
7802470906 tests: add basic_cvm_guest macro for CVM tests
Introduce a basic_cvm_guest! macro in integration_cvm.rs
to reduce boilerplate when creating confidential VM guest
instances. This replaces repetitive UbuntuDiskConfig and
GuestFactory::new_confidential_guest_factory() calls
across multiple CVM test functions.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Muminul Islam
c75504c833 tests: move CVM tests to integration_cvm.rs
Move all CVM (Confidential VM) integration tests from
integration.rs into a dedicated integration_cvm.rs file.
This separation improves code organization and makes it
easier to manage CVM-specific test cases independently
from regular integration tests.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-25 13:34:59 +00:00
Philipp Schuster
56771a0f4c docs: remove trailing spaces in CONTRIBUTING.md
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
2026-03-25 10:08:17 +00:00
Philipp Schuster
00b3a48900 docs: revisit AI/LLM policy in CONTRIBUTING.md
This summarizes the latest state all relevant parties have agreed on
in the last meeting.

This commit was rephrased and improved with the help of Claude Code
using the Sonnet 4.6 model.

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
2026-03-25 10:08:17 +00:00
Philipp Schuster
81495241eb tests: reduce memory pressure, fix ARM tests in CI
Mosts tests used 4GB of RAM, although the VM is mostly idling. In CI, we
experienced OOM issues on the ARM runners. If we reduce the VM memory of
the parallel live migration tests to 1.5GB RAM, we still have enough
capacity in the VM so that everything succeeds while reducing resource
usage.

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
2026-03-24 15:01:47 +00:00
Philipp Schuster
98fd139111 tests: add integration tests
This adds two new integration tests for the new functionality:

- VM under load, downtime=1ms, timeout=1s, timeout_strategy=cancel
- VM under load, downtime=1ms, timeout=1s, timeout_strategy=force

By using a short downtime and timeout plus adding a stress worker in the
guest, we can prevent quick migration. Therefore, we can nicely test the
timeout_strategy.

Testing for a specific downtime is cumbersome to do and highly depends
on CPU/host utilization. To prevent flakiness, there is no such test
integration test. I did, however, manual testing of that functionality.

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
2026-03-24 15:01:47 +00:00
Philipp Schuster
c8cee779b0 docs: update live_migration.md
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
2026-03-24 15:01:47 +00:00
Philipp Schuster
49868f483e vmm: update openapi spec
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
2026-03-24 15:01:47 +00:00
Philipp Schuster
49e03c8bc5 vmm: migration: Converge based on user-provided downtime and timeout
Wire the new `downtime_ms`, `timeout_s`, and `timeout_strategy` fields
from `VmSendMigrationData` into the precopy loop, replacing the previous
hard-coded 5-iteration cap.

Each iteration now evaluates three convergence criteria in order:
- no dirty pages remain;
- the estimated final-iteration downtime is within the configured budget
- or the overall migration timeout has elapsed.

On timeout, `TimeoutStrategy::Cancel` aborts and keeps the VM live on
the source, while `TimeoutStrategy::Force` proceeds regardless of the
downtime target. The convergence callback is updated to return a Result
to propagate the cancel error cleanly up the call stack.

With the recent changes [0], it is fairly easy to implement the new
checks and operate on actual metrics.

These changes are inspired by [1] but differ significantly in details.

[0] https://github.com/cloud-hypervisor/cloud-hypervisor/pull/7799
[1] https://github.com/cloud-hypervisor/cloud-hypervisor/pull/7033

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
2026-03-24 15:01:47 +00:00
Philipp Schuster
bbb0f083b0 vmm: api: add configurable downtime and timeout to VmSendMigrationData
Management software needs fine-grained control over live migration to
meet QoS requirements for VM guests. Add `downtime_ms`, `timeout_s`, and
`timeout_strategy` fields to `VmSendMigrationData`, exposed via API.

This commit contains the API changes only; the VMM does not yet act on
these values. This follows in the next commit.

For the JSON API, downtime and timeout are represented as plain integers
(downtime_ms and timeout_s) to make the units explicit. Using Duration
directly would require custom (de)serialization logic, so instead the
internal raw integers are exposed as Duration via getters. This
introduces minor conversion overhead but keeps the Rust API clear and
unambiguous.

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
2026-03-24 15:01:47 +00:00
Philipp Schuster
040fcaed92 vmm: add VmSendMigrationData::parse(); integrate with OptionParser
This change prepares upcoming options (following commit) that are added
to VmSendMigrationData.

VmSendMigrationData is a special case as it is currently the only
"rich configuration" type that lives outside `config.rs`, as it is
purely API-facing. Therefore, it isn't integrated into the existing
OptionParser infrastructure. We therefore introduce a `parse()` method
to use that in `ch-remote` in the following.

In `ch-remote`, we remove `--local` for `send-migration` and switch to
the new option string parsing constructor (breaking change!). This
prepares the addition of downtime and timeout options in the following
and streamlines the `ch-remote` command line interface with other
commands, such as `ch-remote add-net`.

Lastly, this commit updates the integration tests.

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
2026-03-24 15:01:47 +00:00
dependabot[bot]
7e0f8f7163 build: Bump the non-rust-vmm group across 2 directories with 10 updates
Bumps the non-rust-vmm group with 6 updates in the / directory:

| Package | From | To |
| --- | --- | --- |
| [env_logger](https://github.com/rust-cli/env_logger) | `0.11.9` | `0.11.10` |
| [arc-swap](https://github.com/vorner/arc-swap) | `1.8.2` | `1.9.0` |
| [env_filter](https://github.com/rust-cli/env_logger) | `1.0.0` | `1.0.1` |
| [terminal_size](https://github.com/eminence/terminal-size) | `0.4.3` | `0.4.4` |
| [toml_datetime](https://github.com/toml-rs/toml) | `1.0.1+spec-1.1.0` | `1.1.0+spec-1.1.0` |
| [toml_edit](https://github.com/toml-rs/toml) | `0.25.5+spec-1.1.0` | `0.25.8+spec-1.1.0` |

Bumps the non-rust-vmm group with 3 updates in the /fuzz directory: [arc-swap](https://github.com/vorner/arc-swap), [toml_datetime](https://github.com/toml-rs/toml) and [toml_edit](https://github.com/toml-rs/toml).


Updates `env_logger` from 0.11.9 to 0.11.10
- [Release notes](https://github.com/rust-cli/env_logger/releases)
- [Changelog](https://github.com/rust-cli/env_logger/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-cli/env_logger/compare/v0.11.9...v0.11.10)

Updates `arc-swap` from 1.8.2 to 1.9.0
- [Changelog](https://github.com/vorner/arc-swap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/vorner/arc-swap/compare/v1.8.2...v1.9.0)

Updates `anstream` from 0.6.21 to 1.0.0
- [Commits](https://github.com/rust-cli/anstyle/compare/anstream-v0.6.21...anstream-v1.0.0)

Updates `anstyle-parse` from 0.2.7 to 1.0.0
- [Commits](https://github.com/rust-cli/anstyle/compare/anstyle-parse-v0.2.7...anstyle-parse-v1.0.0)

Updates `env_filter` from 1.0.0 to 1.0.1
- [Release notes](https://github.com/rust-cli/env_logger/releases)
- [Changelog](https://github.com/rust-cli/env_logger/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-cli/env_logger/compare/env_filter-v1.0.0...env_filter-v1.0.1)

Updates `terminal_size` from 0.4.3 to 0.4.4
- [Release notes](https://github.com/eminence/terminal-size/releases)
- [Commits](https://github.com/eminence/terminal-size/compare/v0.4.3...v0.4.4)

Updates `toml_datetime` from 1.0.1+spec-1.1.0 to 1.1.0+spec-1.1.0
- [Commits](https://github.com/toml-rs/toml/compare/toml_datetime-v1.0.1...toml_datetime-v1.1.0)

Updates `toml_edit` from 0.25.5+spec-1.1.0 to 0.25.8+spec-1.1.0
- [Commits](https://github.com/toml-rs/toml/compare/v0.25.5...v0.25.8)

Updates `toml_parser` from 1.0.10+spec-1.1.0 to 1.1.0+spec-1.1.0
- [Commits](https://github.com/toml-rs/toml/compare/toml_parser-v1.0.10...toml_parser-v1.1.0)

Updates `windows-sys` from 0.60.2 to 0.61.2
- [Release notes](https://github.com/microsoft/windows-rs/releases)
- [Commits](https://github.com/microsoft/windows-rs/commits)

Updates `arc-swap` from 1.8.2 to 1.9.0
- [Changelog](https://github.com/vorner/arc-swap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/vorner/arc-swap/compare/v1.8.2...v1.9.0)

Updates `toml_datetime` from 1.0.1+spec-1.1.0 to 1.1.0+spec-1.1.0
- [Commits](https://github.com/toml-rs/toml/compare/toml_datetime-v1.0.1...toml_datetime-v1.1.0)

Updates `toml_edit` from 0.25.5+spec-1.1.0 to 0.25.8+spec-1.1.0
- [Commits](https://github.com/toml-rs/toml/compare/v0.25.5...v0.25.8)

Updates `toml_parser` from 1.0.10+spec-1.1.0 to 1.1.0+spec-1.1.0
- [Commits](https://github.com/toml-rs/toml/compare/toml_parser-v1.0.10...toml_parser-v1.1.0)

---
updated-dependencies:
- dependency-name: env_logger
  dependency-version: 0.11.10
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: arc-swap
  dependency-version: 1.9.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: non-rust-vmm
- dependency-name: anstream
  dependency-version: 1.0.0
  dependency-type: indirect
  update-type: version-update:semver-major
  dependency-group: non-rust-vmm
- dependency-name: anstyle-parse
  dependency-version: 1.0.0
  dependency-type: indirect
  update-type: version-update:semver-major
  dependency-group: non-rust-vmm
- dependency-name: env_filter
  dependency-version: 1.0.1
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: terminal_size
  dependency-version: 0.4.4
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: toml_datetime
  dependency-version: 1.1.0+spec-1.1.0
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: non-rust-vmm
- dependency-name: toml_edit
  dependency-version: 0.25.8+spec-1.1.0
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: toml_parser
  dependency-version: 1.1.0+spec-1.1.0
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: non-rust-vmm
- dependency-name: windows-sys
  dependency-version: 0.61.2
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: non-rust-vmm
- dependency-name: arc-swap
  dependency-version: 1.9.0
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: non-rust-vmm
- dependency-name: toml_datetime
  dependency-version: 1.1.0+spec-1.1.0
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: non-rust-vmm
- dependency-name: toml_edit
  dependency-version: 0.25.8+spec-1.1.0
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: toml_parser
  dependency-version: 1.1.0+spec-1.1.0
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: non-rust-vmm
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-24 01:06:16 +00:00
Sebastian Eydam
5aeb9f55d1 virtio-devices: fix barrier handling in virtio-blk
When configuring multiple queues for a virtio device, the guest can
activate between 1 and the configured amount of queues. The firmware,
for example, may activate only one queue, while a Linux guest would
likely activate all available queues.

The constructor of virtio-blk initializes the `paused_sync` barrier
using the configured queue count (plus one for the main thread). This
can be wrong if the guest enable a different number of queues at
activation time, which can make pause hang. Thus, we now recompute the
barrier size from the queues that are actually activated.

On-behalf-of: SAP sebastian.eydam@sap.com
Signed-off-by: Sebastian Eydam <sebastian.eydam@cyberus-technology.de>
2026-03-23 14:04:58 +00:00
Sebastian Eydam
882f82f04b virtio-devices: fix barrier handling in virtio-net
When configuring multiple queues for a virtio device, the guest can
activate between 1 and the configured amout of queues. The firmware,
for example, may activate only one queue, while a Linux guest would
likely activate all available queues.

The constructor of virtio-net initializes the `paused_sync` barrier
using the configured queue count (plus one for the main thread). This
can be wrong if the guest enables a different number of queues at
activation time, which can make pause hang. Thus, we now recompute the
barrier size from the queues that are actually activated.

On-behalf-of: SAP sebastian.eydam@sap.com
Signed-off-by: Sebastian Eydam <sebastian.eydam@cyberus-technology.de>
2026-03-23 14:04:58 +00:00
Anatol Belski
92109136f1 block: Include actual segment count in TooManySegments error
Include the number of segments found in the request payload in
the TooManySegments error variant so the logged message shows
both the actual and maximum values.

Suggested-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-23 13:27:20 +00:00
Anatol Belski
edfbb7e180 block: Add DISCARD_WZ_MAX_PAYLOAD constant
Introduce DISCARD_WZ_MAX_PAYLOAD as the precomputed product of
DISCARD_WZ_SEG_SIZE and MAX_DISCARD_WRITE_ZEROES_SEG. Use it in the
DISCARD and WRITE_ZEROES segment count checks instead of repeating
the multiplication inline.

Suggested-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-23 13:27:20 +00:00
Julian Schindel
27a40ed32b ci: remove net_gen from allowed titles
On-behalf-of: SAP julian.schindel@sap.com
Signed-off-by: Julian Schindel <julian.schindel@cyberus-technology.de>
2026-03-23 12:50:38 +00:00
Julian Schindel
2b28c5b15a net_gen: replace net_gen with libc
The libc crate provides all functionality provided by the net_gen crate.
Removing the net_gen crate reduces the maintenance burden.

The switch to libc required some fixes, most notably the switch from a
`Vec<u8>` to a `CString` for the `net_util::Tap.if_name` field.

On-behalf-of: SAP julian.schindel@sap.com
Signed-off-by: Julian Schindel <julian.schindel@cyberus-technology.de>
2026-03-23 12:50:38 +00:00
Rob Bradford
3a56f20ee1 vmm: seccomp: Add readlink/readlinkat to vcpu filter
Now needed for IOMMU group resolution with VFIO.

Fixes: #7876

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-03-23 10:04:07 +00:00
Rob Bradford
e05065f509 build: Bump rust-vmm dependencies
Bump to the released versions that are compatible wherever possible but
for the vhost and vfio crates they are git hashes as no releases with
compatible versions have yet been made.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-03-23 10:04:07 +00:00
Rob Bradford
4f52e9355e virtio-devices: seccomp: Allow fcntl unconditionally
This now required after Rust-VMM crate bumps. Also reorder some syscalls
so that they are now in alphabetical order.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-03-23 10:04:07 +00:00
Anatol Belski
c79f3acfab block: Validate sector range for DISCARD and WRITE_ZEROES requests
Add range validation for DISCARD and WRITE_ZEROES, matching the
existing check in the read/write path. Per virtio spec section
5.2.6.1, a driver must not submit a request which would cause a
read or write beyond capacity. Use checked_add to guard against
overflow, then compare against disk_nsectors.

Without this, requests beyond device capacity pass through to the
host punch_hole/write_zeroes calls, relying on backend specific
behavior rather than returning VIRTIO_BLK_S_IOERR consistently.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-22 19:12:52 +00:00
Anatol Belski
d3cad420a5 block: Validate segment count for DISCARD and WRITE_ZEROES requests
Split the data length check into two conditions:

- reject descriptors shorter than one
virtio_blk_discard_write_zeroes segment, and
- reject payloads exceeding MAX_DISCARD_WRITE_ZEROES_SEG segments

Previously only the minimum length was checked and extra segments
were silently dropped.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-22 17:55:24 +00:00
Anatol Belski
fc79d08d7d block: qcow: Remove From<qcow::Error> for BlockError
All public qcow functions now return BlockResult with explicit error
classification at every site. The temporary From impl introduced in
the first commit of this series is no longer needed and is removed.

Internal functions in header.rs and the rebuild_refcounts helpers
stay on qcow::Result. Classification happens at the call site
boundary where qcow::Result meets BlockResult.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-20 22:21:24 +00:00
Anatol Belski
5410d4b2d5 block: qcow: Switch detect_image_type to BlockResult
Switch detect_image_type from qcow::Result to BlockResult with
explicit error classification at every I/O site. This is the last
function migrated before the From scaffolding can be removed.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-20 22:21:24 +00:00
Anatol Belski
9daf1782a8 block: qcow: Switch rebuild_refcounts to BlockResult
Switch rebuild_refcounts from qcow::Result to BlockResult. The
inner helper functions remain on qcow::Result since they are purely
internal, and are wrapped with map_err at each call site where they
cross the BlockResult boundary.

InvalidRefcountTableSize errors are classified as CorruptImage since
they indicate inconsistent internal refcount structures rather than
a format violation.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-20 22:21:24 +00:00
Anatol Belski
f6ec817b9b block: qcow: Switch resize and grow_l1_table to BlockResult
Switch resize and grow_l1_table from qcow::Result to BlockResult.
All I/O error sites use explicit BlockError::new with the Io kind.
The write_to call in grow_l1_table rewraps WritingHeader as
ResizeIo to preserve the existing error semantics.

The two resize tests that check for ShrinkNotSupported and
ResizeWithBackingFile are updated to match on BlockErrorKind with
downcast to inspect the underlying variant.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-20 22:21:24 +00:00
Anatol Belski
524e620240 block: qcow: Classify errors in parse_qcow and BackingFile::new
Replace remaining automatic From conversions in parse_qcow and
BackingFile::new with explicit BlockError::new calls carrying the
appropriate BlockErrorKind at every error site.

Internal functions that still return qcow::Result (QcowHeader::new,
offset_is_cluster_boundary, clear_autoclear_features and others) are
wrapped with map_err at the boundary. These functions stay on
qcow::Result as they are internal to the qcow module and the
classification belongs at the call site rather than inside the
function itself.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-20 22:21:24 +00:00
Anatol Belski
be9ef116aa block: qcow: Switch parse_qcow and BackingFile::new to BlockResult
Switch parse_qcow and BackingFile::new from qcow::Result to
BlockResult. Every early return site now produces an explicit
BlockError with the appropriate kind. Remaining internal calls to
functions still on qcow::Result rely on the From scaffolding and
will be converted in subsequent commits.

Two helpers are added to BlockError. with_kind replaces the
classification on an existing error, used in QcowDiskSync::new to
avoid double wrapping when the caller needs a different kind.
into_source consumes the error and returns the boxed source, used
at the recursive BackingFile open to extract the qcow::Error for
BackingFileOpen without letting qcow::Error hold a BlockError.

The qcow_sync boundary is simplified to a single closure that
operates on the BlockError already returned by parse_qcow.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-20 22:21:24 +00:00
Anatol Belski
c4a5c7f843 block: qcow: Switch QcowFile constructors to BlockResult
Switch the public QcowFile constructors (new, new_from_backing,
new_from_header, from, from_backing, from_file_and_header) from
qcow::Result to BlockResult. Internal calls to header functions
that still return qcow::Result are wrapped with explicit error
classification at each call site.

Test assertions are updated to match on BlockErrorKind and use
downcast to inspect the underlying qcow::Error variant.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-20 22:21:24 +00:00
Anatol Belski
d77e3e7ca2 block: qcow: Add From<qcow::Error> for BlockError
Temporary From impl that classifies each qcow::Error variant into
the appropriate BlockErrorKind. This enables an incremental migration
of qcow functions from qcow::Result to BlockResult, where each
subsequent commit replaces bare ? sites with explicit BlockError::new
calls until this impl can be removed.

The mapping assigns InvalidFormat for structural header violations,
UnsupportedFeature for version and feature mismatches, CorruptImage
for internal inconsistencies, Overflow for nesting depth and Io for
everything else.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-03-20 22:21:24 +00:00
Muminul Islam
0c3249b14f tests: split integration helpers into common modules
Move shared integration test logic out of tests/integration.rs.
Add tests/common/{mod.rs,tests_wrappers.rs,utils.rs} and migrate
API, VM lifecycle, disk/net, and utility helpers.

Update integration.rs to import common modules and keep test
entrypoints thin.

Benefits:
 Reduces integration.rs size and duplication
 Groups reusable helpers by role
 Improves readability and future maintenance

Fixes: https://github.com/cloud-hypervisor/cloud-hypervisor/issues/7808

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-03-20 22:06:11 +00:00
Wei Liu
43642d8df8 tests: Make test_virtio_mmu more flexible
We only verify devices are under some group but not which one.

With the change, the acpi variable is only needed for aarch64. Add an
underscore prefix to avoid a compilation warning on x86_64.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2026-03-19 23:11:17 +00:00