Commit Graph

10363 Commits

Author SHA1 Message Date
Anatol Belski
ecffd9494c virtio-devices: Test consume_config_change semantics
Cover the three observable cases of consume_config_change. With
the flag set the counter advances by one and the flag is cleared.
With the flag clear the call is a no-op. A burst of flag sets
between two reads results in only one bump, which is the wrap
hazard mitigation the spec asks for.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-05-11 20:17:40 +00:00
Anatol Belski
1ba4298551 virtio-devices: Test trigger sets config_changed flag
A Config trigger must set the config_changed flag so the next
device specific configuration read can bump config_generation. A
Queue trigger must leave the flag alone.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-05-11 20:17:40 +00:00
Anatol Belski
90b9481745 virtio-devices: Bump config_generation on device config read
Set a config_changed flag in VirtioInterruptMsix when a Config
interrupt fires, and increment config_generation only when the
driver next reads the device specific configuration region. The
flag is cleared by that read so the driver observes a stable
value across the read and a fresh value on any later read.

This avoids the wrap hazard of incrementing on every Config
event, where a burst of interrupts could roll the 8 bit counter
back to its previous value between two driver reads.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-05-11 20:17:40 +00:00
Anatol Belski
e923f9a678 virtio-devices: Make config_generation an Arc<AtomicU8>
Convert the u8 field to Arc<AtomicU8> so the interrupt path can
mutate it without holding the common config mutex. Reads at
offset 0x15 use Acquire ordering. State serialization preserves
the value.

Update the three unit tests that construct
VirtioPciCommonConfig directly.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-05-11 20:17:40 +00:00
Rob Bradford
03025dee58 main: Drop the "Z" suffix from wallclock time in the log
This prints the time in the local time. The "Z" suffix usually indicates
UTC time. This is left over from when there was manual implementation
using libc::gmtime()

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-11 18:49:17 +00:00
Rob Bradford
e0e10b5971 tests: Disable tests on ARM64 that don't work with stock kernel
An edk2 boot is needed for ACPI support but the stock ARM64 kernel does
not support ACPI memory hotplug or virtio-pmem. For now disable those
tests but track them in #8187.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-11 17:52:00 +00:00
Rob Bradford
9b7260e630 tests: Adapt topology tests on ARM64 for new lscpu output
The lscpu output is now different on ARM64 (referencing clusters vs
sockets).

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-11 17:52:00 +00:00
Rob Bradford
c392274f09 tests: Streamline watchdog tests
This is a niche feature and we were overly testing it. Let's just switch
to two tests. One for live migration and one for plain watchdog. This
will reduce the CI time. As we are now running these tests sequentially
we can also reduce some the delays in the tests.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-11 17:52:00 +00:00
Rob Bradford
0f7e6a0d3a tests: Move watchdog tests to sequential
These tests are very timing dependent and so need to be run without high
levels of load.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-11 17:52:00 +00:00
Rob Bradford
55adcc27da tests: Replace last vestiges of focal use with jammy
Focal has served us well for many years but is now beyond EOL. Remove
all remaining use of focal images from the CI.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-11 17:52:00 +00:00
Dylan Reid
1b5c6d9977 vmm: device_manager: always tear down vfio_user DMA handlers on eject
The PciDeviceHandle::VfioUser arm in eject_device propagated dma_unmap
failures with ?, which short-circuited the subsequent
remove_dma_mapping_handler loop and left stale Arc<VfioUserDmaMapping>
entries in every virtio-mem device's handler map.  Log unmap errors
with warn! and continue so the handler map cleanup always runs.

This only happens if a vfio-user process crashes and the same device is
later removed. However, given we've seen similar issues on vhost-user
this is probably worth cleaning up.

Signed-off-by: Dylan Reid <dgreid@fb.com>
2026-05-11 17:40:28 +00:00
Dylan Reid
6111d549b7 vmm: device_manager: handle short ACPI hotplug MMIO width gracefully
The BusDevice read and write arms for B0EJ_FIELD_OFFSET and
PSEG_FIELD_OFFSET opened with assert!/assert_eq! on data.len(), so a
guest 1/2/8-byte MMIO access to either register panicked the vCPU
thread.  Replace each assert with a warn! and early return so unusual
access widths are logged and ignored instead of crashing the VMM.

Signed-off-by: Dylan Reid <dgreid@fb.com>
2026-05-11 17:40:28 +00:00
Dylan Reid
e1c2b179e7 vmm: device_manager: prune balloon and virtio_mem refs on eject
self.balloon and self.virtio_mem_devices are not updated when
eject_device removes the underlying device, leaving stale
Arc<Mutex<...>> entries that resize_balloon / balloon_size and the
virtio-mem DMA-handler iteration would dereference if reached after
eject. Clear self.balloon and retain-out the matching virtio-mem entry
in the PciDeviceHandle::Virtio eject arm, identifying the ejected
device by Arc pointer-equality against the already-resolved
Arc<Mutex<dyn VirtioDevice>>.

This change is defensive: DeviceManager::remove_device currently
rejects VirtioDeviceType::Balloon and VirtioDeviceType::Mem with
RemovalNotAllowed before pci_devices_down is set, so the guest never
sees an eject notification and eject_device is never reached for
either type today. If the allowlist is extended later, this cleanup
keeps the post-eject state consistent.

Signed-off-by: Dylan Reid <dgreid@fb.com>
2026-05-11 17:40:28 +00:00
Rob Bradford
87c546ea6a main: Add more log format options
Add {wallclock}, {pid}, and {tid} tokens to the log format system.

Assisted-by: Claude:Opus-4.7
Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-11 12:47:22 +00:00
Rob Bradford
d9b8f28f21 main: Add --log-format
Currently only the existing format options are supported and the default
format string is unchanged. This allows more fine grained logging
control.

Assisted-by: Claude:Opus-4.7
Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-11 12:47:22 +00:00
Rob Bradford
3bbf97c5e5 main: Add unit testing for logger infrastructure
Assisted-by: Claude:Opus-4.7
Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-11 12:47:22 +00:00
Rob Bradford
a440ea0b44 main: Create a format string parser and printer for log output
Introduces a custom format string parser for use for log entries. For
now only the existing format string entries are covered and the default
format string matches the existing behaviour.

The format string is tokenized once and then that token stream is used
for each log entry.

Assisted-by: Claude:Opus-4.7
Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-11 12:47:22 +00:00
Rob Bradford
661faf51fe main: Move logger into its own mod
In preparation for extending its functionality, refactor the Logger
struct and its implementation to a new file / module.

Assisted-by: Claude:Opus-4.6
Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-11 12:47:22 +00:00
Dylan Reid
3fc0ff00d5 vhost_user_block: fix process_queue unwraps
process_queue() unwrapped four guest-reachable Results.

Convert each unwrap to a logged error path. A failed status write is
demoted to len = 0 so the head is still retired via add_used; an
add_used failure breaks the batch (queue is in a bad state); a
needs_notification failure  signals; a signal failure is logged. The
daemon stays up.

Signed-off-by: Dylan Reid <dgreid@fb.com>
2026-05-11 11:48:55 +00:00
Dylan Reid
1f0a78b766 vhost_user_block: set_config tolerates partial sub-range writes
set_config() split the config slice at `offset` and copy_from_slice'd
the entire suffix, which asserts src.len() == self.len(). This panics if
the guest issues a write shorter than `config_len - offset`.

Signed-off-by: Dylan Reid <dgreid@fb.com>
2026-05-11 11:48:55 +00:00
Rob Bradford
5ca693495a vmm: api: Log HTTP API error responses
Although a response is sent to the client these errors are not logged in
the log file making it hard to cross reference these with other log
entries.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-11 11:22:32 +00:00
Rob Bradford
bca9b97919 virtio-devices: vhost-user: Log when attempting reconnection
Currently when the socket is disconnected by the other end there is no
logging of such an event. Add a log to aid identifying when this has
happened.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-11 11:22:10 +00:00
Rob Bradford
74bf0b4a55 virtio-devices: vhost-user: Abandon reconnection if kill event sent
Abandon the reconnection to the vhost-user socket if the kill_evt is
fired because e.g. a device removal request has come in during the
reconnection.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-11 11:22:10 +00:00
Rob Bradford
0f61655743 virtio-devices: vhost-user: Use TimerFd connect_vhost_user
Replace the use of sleeps with a TimerFd. Initially this is functionally
equivalent but it can be extended to also handle other events.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-11 11:22:10 +00:00
Wei Liu
f67d0569b4 block: fix cargo test -p block
`RawBackend::IoUring` is only available when `io_uring` feature is
defined.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2026-05-09 14:10:25 +00:00
dependabot[bot]
f7ebb0bedd build(deps): bump crate-ci/typos from 1.46.0 to 1.46.1
Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.46.0 to 1.46.1.
- [Release notes](https://github.com/crate-ci/typos/releases)
- [Changelog](https://github.com/crate-ci/typos/blob/master/CHANGELOG.md)
- [Commits](bbaefadf97...5374cbf686)

---
updated-dependencies:
- dependency-name: crate-ci/typos
  dependency-version: 1.46.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-05-09 00:36:06 +00:00
Anatol Belski
cfec130772 virtio-devices: balloon: Cap inflate and deflate descriptor length
Drop inflate or deflate descriptors whose len exceeds the Linux
driver maximum of VIRTIO_BALLOON_ARRAY_PFNS_MAX PFN entries of 4
bytes each. Without the cap, a guest can submit a descriptor with
a huge len over a small backing and drive an unbounded warn loop
in the device thread.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-05-08 22:11:54 +00:00
Philipp Schuster
bad10f3026 main, vmm: add explicit PCI BDF support for Rng device
This was missing in [0] but is required for proper explicit PCI BDF
management, e.g., when a VM is created via libvirt and each device has
an explicit BDF.

[0] https://github.com/cloud-hypervisor/cloud-hypervisor/pull/7965

On-behalf-of: SAP philipp.schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-05-08 19:39:18 +00:00
Philipp Schuster
18bbc71b59 hypervisor: fix typo
On-behalf-of: SAP philipp.schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>

xxx ci
2026-05-08 16:29:18 +00:00
Philipp Schuster
3ebd32844e vm-allocator, vmm: InterruptRoute: free GSIs on drop
These changes free GSIs when they are no longer used. That way we
won't exhaust the available GSIs anymore when attaching and
detaching devices.

Now, once can add devices and remove them hundreds of times, without
running out of GSIs.

Co-authored-by: Sebastian Eydam <sebastian.eydam@cyberus-technology.de>
On-behalf-of: SAP sebastian.eydam@sap.com
Signed-off-by: Sebastian Eydam <sebastian.eydam@cyberus-technology.de>

On-behalf-of: Philipp Schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-05-08 16:29:18 +00:00
Philipp Schuster
1ba2b34019 vm-allocator: free GSIs in GsiAllocator
The old implementation used an ever monotonically increasing u32 counter
to allocate new GSIs. The counter increased every time a new GSI was
allocated, and freeing GSIs was not possible. Thus, Cloud Hypervisor
can run out of GSIs and panics. This currently happened at the 1024th
GSI [0]. Further, this caused the `KVM_SET_GSI_ROUTING` ioctl to carry
much more payload than needed.

This new implementation uses a bitmap for proper tracking of resources
and can gracefully free GSIs - this is abstracted in type
InterruptAllocator.

Please note that this commit only replaces the old mechanism. The next
commit will introduce freeing used GSIs automatically when an
InterruptRoute is dropped.

While being on this, we also propagate the errors that the allocator may
throw where necessary.

Co-authored-by: Sebastian Eydam <sebastian.eydam@cyberus-technology.de>
On-behalf-of: SAP sebastian.eydam@sap.com
Signed-off-by: Sebastian Eydam <sebastian.eydam@cyberus-technology.de>

On-behalf-of: Philipp Schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-05-08 16:29:18 +00:00
Philipp Schuster
7c4fa04ea3 vm-allocator: introduce bitmap-backed InterruptAllocator
This introduces a bitmap-backed interrupt number allocator. The type is
not yet used but will be in the next commit and enable graceful
releasing of allocated interrupt numbers (GSIs).

Co-authored-by: Sebastian Eydam <sebastian.eydam@cyberus-technology.de>
On-behalf-of: SAP sebastian.eydam@sap.com
Signed-off-by: Sebastian Eydam <sebastian.eydam@cyberus-technology.de>

On-behalf-of: Philipp Schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-05-08 16:29:18 +00:00
dependabot[bot]
90859452ab build(deps): bump the non-rust-vmm group across 2 directories with 11 updates
Bumps the non-rust-vmm group with 5 updates in the / directory:

| Package | From | To |
| --- | --- | --- |
| [zbus](https://github.com/z-galaxy/zbus) | `5.14.0` | `5.15.0` |
| [digest](https://github.com/RustCrypto/traits) | `0.11.2` | `0.11.3` |
| [hybrid-array](https://github.com/RustCrypto/hybrid-array) | `0.4.10` | `0.4.11` |
| [js-sys](https://github.com/wasm-bindgen/wasm-bindgen) | `0.3.95` | `0.3.97` |
| [openssl-sys](https://github.com/rust-openssl/rust-openssl) | `0.9.114` | `0.9.115` |

Bumps the non-rust-vmm group with 1 update in the /fuzz directory: [js-sys](https://github.com/wasm-bindgen/wasm-bindgen).


Updates `zbus` from 5.14.0 to 5.15.0
- [Release notes](https://github.com/z-galaxy/zbus/releases)
- [Changelog](https://github.com/z-galaxy/zbus/blob/main/release-plz.toml)
- [Commits](https://github.com/z-galaxy/zbus/compare/zbus-5.14.0...zbus-5.15.0)

Updates `digest` from 0.11.2 to 0.11.3
- [Commits](https://github.com/RustCrypto/traits/compare/digest-v0.11.2...digest-v0.11.3)

Updates `hybrid-array` from 0.4.10 to 0.4.11
- [Changelog](https://github.com/RustCrypto/hybrid-array/blob/master/CHANGELOG.md)
- [Commits](https://github.com/RustCrypto/hybrid-array/compare/v0.4.10...v0.4.11)

Updates `js-sys` from 0.3.95 to 0.3.97
- [Release notes](https://github.com/wasm-bindgen/wasm-bindgen/releases)
- [Changelog](https://github.com/wasm-bindgen/wasm-bindgen/blob/main/CHANGELOG.md)
- [Commits](https://github.com/wasm-bindgen/wasm-bindgen/commits)

Updates `openssl-sys` from 0.9.114 to 0.9.115
- [Release notes](https://github.com/rust-openssl/rust-openssl/releases)
- [Commits](https://github.com/rust-openssl/rust-openssl/compare/openssl-sys-v0.9.114...openssl-sys-v0.9.115)

Updates `wasm-bindgen` from 0.2.118 to 0.2.121
- [Release notes](https://github.com/wasm-bindgen/wasm-bindgen/releases)
- [Changelog](https://github.com/wasm-bindgen/wasm-bindgen/blob/main/CHANGELOG.md)
- [Commits](https://github.com/wasm-bindgen/wasm-bindgen/compare/0.2.118...0.2.121)

Updates `wasm-bindgen-macro` from 0.2.118 to 0.2.121
- [Release notes](https://github.com/wasm-bindgen/wasm-bindgen/releases)
- [Changelog](https://github.com/wasm-bindgen/wasm-bindgen/blob/main/CHANGELOG.md)
- [Commits](https://github.com/wasm-bindgen/wasm-bindgen/compare/0.2.118...0.2.121)

Updates `wasm-bindgen-macro-support` from 0.2.118 to 0.2.121
- [Release notes](https://github.com/wasm-bindgen/wasm-bindgen/releases)
- [Changelog](https://github.com/wasm-bindgen/wasm-bindgen/blob/main/CHANGELOG.md)
- [Commits](https://github.com/wasm-bindgen/wasm-bindgen/compare/0.2.118...0.2.121)

Updates `wasm-bindgen-shared` from 0.2.118 to 0.2.121
- [Release notes](https://github.com/wasm-bindgen/wasm-bindgen/releases)
- [Changelog](https://github.com/wasm-bindgen/wasm-bindgen/blob/main/CHANGELOG.md)
- [Commits](https://github.com/wasm-bindgen/wasm-bindgen/compare/0.2.118...0.2.121)

Updates `winnow` from 0.7.15 to 1.0.0
- [Changelog](https://github.com/winnow-rs/winnow/blob/main/CHANGELOG.md)
- [Commits](https://github.com/winnow-rs/winnow/compare/v0.7.15...v1.0.0)

Updates `zbus_macros` from 5.14.0 to 5.15.0
- [Release notes](https://github.com/z-galaxy/zbus/releases)
- [Changelog](https://github.com/z-galaxy/zbus/blob/main/release-plz.toml)
- [Commits](https://github.com/z-galaxy/zbus/compare/zbus_macros-5.14.0...zbus_macros-5.15.0)

Updates `js-sys` from 0.3.95 to 0.3.97
- [Release notes](https://github.com/wasm-bindgen/wasm-bindgen/releases)
- [Changelog](https://github.com/wasm-bindgen/wasm-bindgen/blob/main/CHANGELOG.md)
- [Commits](https://github.com/wasm-bindgen/wasm-bindgen/commits)

Updates `wasm-bindgen` from 0.2.118 to 0.2.121
- [Release notes](https://github.com/wasm-bindgen/wasm-bindgen/releases)
- [Changelog](https://github.com/wasm-bindgen/wasm-bindgen/blob/main/CHANGELOG.md)
- [Commits](https://github.com/wasm-bindgen/wasm-bindgen/compare/0.2.118...0.2.121)

Updates `wasm-bindgen-macro` from 0.2.118 to 0.2.121
- [Release notes](https://github.com/wasm-bindgen/wasm-bindgen/releases)
- [Changelog](https://github.com/wasm-bindgen/wasm-bindgen/blob/main/CHANGELOG.md)
- [Commits](https://github.com/wasm-bindgen/wasm-bindgen/compare/0.2.118...0.2.121)

Updates `wasm-bindgen-macro-support` from 0.2.118 to 0.2.121
- [Release notes](https://github.com/wasm-bindgen/wasm-bindgen/releases)
- [Changelog](https://github.com/wasm-bindgen/wasm-bindgen/blob/main/CHANGELOG.md)
- [Commits](https://github.com/wasm-bindgen/wasm-bindgen/compare/0.2.118...0.2.121)

Updates `wasm-bindgen-shared` from 0.2.118 to 0.2.121
- [Release notes](https://github.com/wasm-bindgen/wasm-bindgen/releases)
- [Changelog](https://github.com/wasm-bindgen/wasm-bindgen/blob/main/CHANGELOG.md)
- [Commits](https://github.com/wasm-bindgen/wasm-bindgen/compare/0.2.118...0.2.121)

---
updated-dependencies:
- dependency-name: zbus
  dependency-version: 5.15.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: non-rust-vmm
- dependency-name: digest
  dependency-version: 0.11.3
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: hybrid-array
  dependency-version: 0.4.11
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: js-sys
  dependency-version: 0.3.97
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: openssl-sys
  dependency-version: 0.9.115
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: wasm-bindgen
  dependency-version: 0.2.121
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: wasm-bindgen-macro
  dependency-version: 0.2.121
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: wasm-bindgen-macro-support
  dependency-version: 0.2.121
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: wasm-bindgen-shared
  dependency-version: 0.2.121
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: winnow
  dependency-version: 1.0.0
  dependency-type: indirect
  update-type: version-update:semver-major
  dependency-group: non-rust-vmm
- dependency-name: zbus_macros
  dependency-version: 5.15.0
  dependency-type: indirect
  update-type: version-update:semver-minor
  dependency-group: non-rust-vmm
- dependency-name: js-sys
  dependency-version: 0.3.97
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: wasm-bindgen
  dependency-version: 0.2.121
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: wasm-bindgen-macro
  dependency-version: 0.2.121
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: wasm-bindgen-macro-support
  dependency-version: 0.2.121
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
- dependency-name: wasm-bindgen-shared
  dependency-version: 0.2.121
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: non-rust-vmm
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-05-08 00:48:40 +00:00
Rob Bradford
49259bb84f hypervisor: kvm: Punch holes in guest_memfd on shared transition
When an SEV-SNP guest transitions pages from private to shared via
KVM_HC_MAP_GPA_RANGE, punch holes in the corresponding guest_memfd
backing it. Without this the balloon driver's `set_memory_decrypted()`
path transitions the page attributes but the physical memory stays
pinned in guest_memfd, making virtio-balloon ineffective for memory
overcommit with confidential VMs. Even without ballooning these pages
are unused by the guest so consume resources. This mirrors the hole
punching that the balloon device does for releasing pages.

The memory_slots Arc is cloned into each KvmVcpu at creation so the
punch can happen in the vcpu thread.

Assisted-by: Claude:claude-opus-4-6
Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-07 22:48:06 +00:00
Rob Bradford
ebeef03192 hypervisor: kvm: Introduce KvmMemorySlot to track guest_memfd per slot
Replace the bare OwnedFd map (guest_memfds) with a KvmMemorySlot struct
wrapped in an Arc so it can later be shared with KvmVcpu. This is a
pure refactor with no functional change; KvmMemorySlot currently holds
only the guest_memfd OwnedFd.

Assisted-by: Claude:claude-opus-4-6
Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-07 22:48:06 +00:00
Anatol Belski
26ed2a98bc virtio-devices: block: Use Display when logging Error
block::Error implements Display via thiserror, so the user facing
log lines do not need the Debug formatter.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-05-07 22:00:32 +00:00
Anatol Belski
14dfd78f04 virtio-devices: Drop unused device_needs_reset helper
With the per handler needs_reset() gates removed from net and
block, nothing reads DEVICE_NEEDS_RESET anymore. Drop the
device_needs_reset helper and refresh the doc comment on
mark_device_needs_reset to reflect the central call site in
spawn_virtio_thread, where it runs after the worker has already
exited.

No functional change.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-05-07 22:00:32 +00:00
Anatol Belski
293672ea76 virtio-devices: block: Drop per handler NEEDS_RESET bookkeeping
With virtqueue iterator errors now killing the worker and
spawn_virtio_thread marking NEEDS_RESET centrally, the per
handler needs_reset() gate on process_queue_submit and
process_queue_complete is unreachable.

Drop needs_reset(), the two early returns, the unused
device_status field on BlockEpollHandler and its initializer,
and the device_needs_reset import.

No functional change.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-05-07 22:00:32 +00:00
Anatol Belski
0597e72974 virtio-devices: block: Surface virtqueue iterator errors to the worker
queue.iter() errors used to be swallowed by
handle_queue_iterator_error(), which marked the device as
NEEDS_RESET and returned Ok so the worker kept running while
disabled. spawn_virtio_thread now does the NEEDS_RESET marking
when the worker exits with an error.

Propagate the iterator error as Error::QueueIterator and escalate
it to EpollHelperError::HandleEvent in
process_queue_submit_and_signal so the worker exits. Per request
errors stay logged. Drop the now unused
handle_queue_iterator_error helper.

No functional change for the guest. NEEDS_RESET is still set and
the config interrupt is still raised on virtqueue corruption.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-05-07 22:00:32 +00:00
Anatol Belski
6669ec1b86 virtio-devices: net: Drop per handler NEEDS_RESET bookkeeping
spawn_virtio_thread now marks the device as NEEDS_RESET and notifies
the guest whenever the worker thread exits with an error, so the
per handler needs_reset() gate and the handle_queue_iterator_error()
helper in net are redundant.

Let virtqueue iterator errors propagate out of the worker thread
through DeviceError::NetQueuePair. Drop the unused device_status
field and the device_needs_reset and mark_device_needs_reset
imports.

No functional change for the guest. NEEDS_RESET is still set and
the config interrupt is still raised on virtqueue corruption.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-05-07 22:00:32 +00:00
Roberto Campesato
fff674a27d vmm: prefer /dev/userfaultfd over the syscall
Prefer /dev/userfaultfd (Linux 6.1+) over the userfaultfd(2) syscall
for obtaining userfaultfd file descriptors.  The device path bypasses
the capable(CAP_SYS_PTRACE) and vm.unprivileged_userfaultfd sysctl
checks that block the syscall in user-namespaced containers, using
file permissions instead.

Falls back to the syscall on older kernels or when the device node
does not exist.

Signed-off-by: Roberto Campesato <render@metalabs.org>
Assisted-by: Claude:claude-opus-4-6
2026-05-07 21:37:46 +00:00
Muminul Islam
df1809c1fa scripts: limit integration tests to cloud-hypervisor package
Pass `-p cloud-hypervisor` to all `cargo nextest run` invocations in
the integration test scripts so test discovery and execution are
scoped to the cloud-hypervisor package only, avoiding running tests
from other workspace crates.

This avoids flooding the output messages like below
`test result: ok. 0 passed; 0 failed; 0 ignored;
0 measured; 0 filtered out; finished in 0.00s
Running unittests src/lib.rs`

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-05-07 17:44:38 +00:00
Rob Bradford
0ca06517f8 tests: Cleanup macvtap interfaces
Clean up the macvtap interfaces that may have been left from a previous
failed run. Failure to clean those up guarantees that the subsequent
test runs will fail.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-07 17:30:53 +00:00
Keith Adler
26c9a54833 main: use path placeholders in help text
Use concise <path> placeholders in socket and console help strings
instead of wording every path as a file. This keeps the established
file= config key intact while making the user-facing help wording
match the path terminology requested in the issue.

Signed-off-by: Keith Adler <kadler@cloudflare.com>
2026-05-07 16:46:41 +00:00
Philipp Schuster
a67277b9cd hypervisor: kvm: improve logging for triple fault
When a triple fault happens [0], we now get at least a log message. This
helps to better understand the root cause of sudden reboots.

Broader context: We experience reboots caused by triple faults in
edk2 (6 months old as well as recent). They happen so early in the boot
that one doesn't really see them without looking at the VMM log. An
automatic system reset plus reboot often hides these situations - now
they are at least more visible in the log.

PS: Printing the registers to get more debugging help doesn't help, as
the guest already triple-faulted - the CPU state of the root cause
doesn't exist anymore.

[0] https://elixir.bootlin.com/linux/v6.18.6/source/arch/x86/kvm/x86.c#L11123

On-behalf-of: SAP philipp.schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-05-07 16:43:04 +00:00
Keith Adler
f3263d0988 block: preserve async queue push errors
Keep the underlying io_uring submission queue push error in raw async
I/O paths instead of replacing it with a generic full-queue message.

Signed-off-by: Keith Adler <kadler@cloudflare.com>
2026-05-07 16:37:57 +00:00
Rob Bradford
cd3aca91d3 virtio-devices: pmem: Respond to unknown request types
Request::parse rejected unknown request types with an error, causing
process_queue to report the chain as used with no response written.
The device should write an error response so the driver knows the
request was handled. Move type validation out of parse into
process_queue where a proper response can be constructed.

Signed-off-by: Rob Bradford <rbradford@meta.com>
Assisted-by: Claude:claude-opus-4-6
2026-05-07 16:27:18 +00:00
Rob Bradford
56c18b51cc virtio-devices: console: Handle output queue errors gracefully
Address translation, guest memory read, write, and flush failures on
the transmitq propagated errors that killed the console device thread.
A host-side I/O error such as a PTY disconnect would permanently
disable the console. Log warnings and continue processing instead.

Signed-off-by: Rob Bradford <rbradford@meta.com>
Assisted-by: Claude:claude-opus-4-6
2026-05-07 16:27:18 +00:00
Rob Bradford
4725a997cc virtio-devices: console: Handle input queue errors gracefully
Address translation or guest memory write failures on the receiveq
propagated errors that killed the console device thread. Log a
warning and break out of the descriptor loop instead.

Also fix a data-loss bug: bytes were drained from the input buffer
before the write to guest memory, so a failed write would silently
discard the data. Copy first, write, then drain only on success.

Signed-off-by: Rob Bradford <rbradford@meta.com>
Assisted-by: Claude:claude-opus-4-6
2026-05-07 16:27:18 +00:00
Rob Bradford
48123669b5 virtio-devices: console: Skip device-writable output descriptors
The output queue handler read data from every descriptor without
checking the write-only flag. The driver must not put device-writable
buffers in the transmitq. Skip them with a warning.

Signed-off-by: Rob Bradford <rbradford@meta.com>
Assisted-by: Claude:claude-opus-4-6
2026-05-07 16:27:18 +00:00