Commit Graph

10383 Commits

Author SHA1 Message Date
Bo Chen
05b8464295 build: Add .editorconfig to REUSE dep5
Signed-off-by: Bo Chen <bchen@crusoe.ai>
2026-05-13 21:14:47 +00:00
Bo Chen
88d3eaa509 build: Temporarily make windows integration job non-blocking
See: #8211

Signed-off-by: Bo Chen <bchen@crusoe.ai>
2026-05-13 21:14:47 +00:00
Bo Chen
3645d916f3 tests: Stabilize VFIO NVIDIA memory hotplug check
Bump the wait_until timeout for the guest-visible memory growth in
test_nvidia_card_memory_hotplug from 5s to 15s. The hot-add path inside
the guest kernel can take longer than 5s particularly when using
virtio-mem, which has been a source of flakes for this test.

Drop the trailing assert!(guest.get_total_memory() > 5_760_000), as it
is redundant.

See: #8160

Signed-off-by: Bo Chen <bchen@crusoe.ai>
2026-05-13 21:14:47 +00:00
Bo Chen
9ca5f63fe0 scripts: namespace dev_cli tmp dir per user and drop dead BUILD_DIR
The shared /tmp/cloud-hypervisor/ path is created by the first user to
run dev_cli.sh and owned by them, so other users on the same host fail
the +x+w check and cannot chmod it back. Move both tmp paths under
/tmp/cloud-hypervisor-${USER}/ so each user gets their own tree.

While here, fold the local BUILD_DIR in build_container() into the
existing (previously unused) CLH_CTR_BUILD_DIR, which ensure_build_dir()
already creates.

Assisted-by: Claude:Opus-4.7
Signed-off-by: Bo Chen <bchen@crusoe.ai>
2026-05-13 21:14:47 +00:00
Philipp Schuster
0638b38d60 misc: sort .gitignore alphabetically
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-05-13 16:58:47 +00:00
Philipp Schuster
9ad057bd14 misc: add LLM agent artifacts to .gitignore
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-05-13 16:58:47 +00:00
Philipp Schuster
117ed4e9bc misc: fix formatting in a couple of *.toml files
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-05-13 16:58:47 +00:00
Philipp Schuster
fc8fd3682a misc: sync .taplo with .editorconfig
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-05-13 16:58:47 +00:00
Philipp Schuster
96700bbfc7 misc: init .editorconfig
TL;DR: Improved developer productivity for many contributors

Add a shared .editorconfig so contributors get lightweight,
editor-native hints while writing code instead of only discovering
formatting issues later in style checks.

This is advisory, but useful: editors can already guide indentation,
whitespace, line endings, and final newlines as you type. They can also
show a visual guide at the 80-character line width, which is one of the
main motivations here. Most LLM-generated code and contributions over
the past year have already conventionally followed the 80-character
limit, so this makes the expected style visible and consistent for
everyone.

.editorconfig is a decade-old standard, and virtually every editor or
IDE supports it.

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-05-13 16:58:47 +00:00
Philipp Schuster
cde761a90d misc: add AGENTS.md for easier LLM use
Initial attempt for a lightweight AGENTS.md to improve working with
LLMs on this repository and avoid common pitfalls.

Assisted-by: Codex:GPT-5.5
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-05-13 16:49:47 +00:00
JP Kobryn
ced3762a67 vmm: create memfd for private mappings
User-defined zones may be mapped private. Create a memfd for private
zones so that fallocate operations are available on all regions, not
just shared ones. This prepares for zone management via hole punching.

The MAP_ANONYMOUS flag is now omitted since the memory becomes
tmpfs-backed via memfd.

Signed-off-by: JP Kobryn <inwardvessel@gmail.com>
2026-05-12 11:47:18 +00:00
Anatol Belski
534aaaceb2 virtio-devices: Require at least one ready queue for activation
When a guest resets a device by writing status=0 and reinitializes
without enabling queues before writing DRIVER_OK, the activation
path would collect zero ready queues and treat that as a fatal
error, killing the entire VMM process.

The PCI transport now checks that at least one queue is ready
before reporting that the device needs activation. This prevents
a spurious activation attempt that would fatally fail when no
queues are enabled.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-05-12 13:53:33 +01:00
Philipp Schuster
9a46affc33 vmm: add missing ID validation for virtio-rng device
On-behalf-of: Philipp Schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-05-11 20:18:03 +00:00
Philipp Schuster
cecd16a84f openapi: update schemas for ConsoleConfig and SerialConfig
On-behalf-of: Philipp Schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-05-11 20:18:03 +00:00
Philipp Schuster
0e67f27546 tests: extend test_pci_device_id() to also test virtio-console
On-behalf-of: Philipp Schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-05-11 20:18:03 +00:00
Philipp Schuster
e793353bfb vmm, main: make PCI BDF configurable for ConsoleConfig
Add common PCI device configuration to the virtio-console device
configuration. This allows setting the device ID (the name), ID, the
PCI segment, and the PCI device ID (BDF), which were previously not
configurable for the virtio-console device.

This gives management software, such as libvirt, more control over PCI
resource assignment and aligns virtio-console with other devices that
already support this functionality [0].

[0] https://github.com/cloud-hypervisor/cloud-hypervisor/issues/8175

On-behalf-of: Philipp Schuster <philipp.schuster@sap.com>
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-05-11 20:18:03 +00:00
Philipp Schuster
36a3369802 vmm: drop misleading iommu option from serial config
`--serial` still accepted `iommu=on|off` from the shared serial/console
configuration shape, even though only virtio-console has a meaningful
IOMMU connection.

Cloud Hypervisor wires virtio-iommu support through DMA-capable
virtio/VFIO PCI endpoints. The serial devices are legacy UARTs accessed
through PIO or MMIO registers, so exposing an IOMMU option there is
misleading.

On-behalf-of: Philipp Schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-05-11 20:18:03 +00:00
Philipp Schuster
04bc6b3ccc vmm, main: split ConsoleConfig and SerialConfig into separate structs
This commit introduces a new struct `CommonConsoleConfig` which is the
base for the split into `ConsoleConfig` and `SerialConfig`. This is a
pre-requisite for allowing more configurable PCI options for the
virtio-console device.

The commit doesn't change or add any functionality.

On-behalf-of: Philipp Schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-05-11 20:18:03 +00:00
Philipp Schuster
a56f49787c option_parser: add add_all_valueless() helper
Helpful to prevent repetitions.

On-behalf-of: Philipp Schuster@sap.com
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2026-05-11 20:18:03 +00:00
Anatol Belski
fcfae4cc4b virtio-devices: Test config_generation wraps at u8 max
config_generation is a u8 and the spec mandates wrap around.
Verify the increment past 0xff lands on 0x00 without panicking
under overflow checks.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-05-11 20:17:40 +00:00
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