Commit Graph

10316 Commits

Author SHA1 Message Date
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
Rob Bradford
521b15bda6 virtio-devices: console: Skip device-readable descriptors in input queue
The input queue handler wrote data to every descriptor without
checking the write-only flag. The device must not write to
device-readable buffers. 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
Rob Bradford
fe7745b472 virtio-devices: mem: Remove dead error variants and unused import
Remove UnknownRequestType (no longer returned after responding with
ERROR), EventFdWriteFail, EventFdTryCloneFail, MpscRecvFail, and
NotActivatedByGuest which have no call sites. Drop the now-unused
mpsc import.

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
6a1fe123c2 virtio-devices: mem: Handle descriptor parse errors gracefully
A malformed descriptor chain — wrong read/write flags, missing
descriptors, or undersized buffers — caused Request::parse to return
an error that killed the device thread. Log a warning, report the
chain as used with zero length, and continue processing.

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
dfee31a84c virtio-devices: mem: Use usize for block counts in internal bitmap APIs
is_range_state() and set_range() took nb_blocks as u16 to match the
wire format, but unplug_all() computed the total block count from
region_size / block_size and cast to u16, silently truncating for
regions larger than 128 GiB. Widen the internal parameter to usize
so unplug_all() resets the full bitmap.

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
1dd588fa6d virtio-devices: mem: Return early in state_request for invalid ranges
When is_valid_range() returns false, the handler still computed
offset = addr - config.addr which can underflow if addr is below the
region base, then queried the bitmap at a meaningless index. Return
(ERROR, 0) immediately so no arithmetic runs on invalid input.

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
97e16f249f virtio-devices: mem: Respond to unknown request types
An unknown request type caused process_queue to return an error that
killed the device thread. The request/response descriptors are already
parsed at this point, so respond with VIRTIO_MEM_RESP_ERROR and
continue processing.

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
ce74caa6c2 virtio-devices: balloon: Handle reporting queue errors gracefully
Address translation or memory release errors on the free page
reporting queue propagated up and killed the balloon device thread.
Log a warning and skip the offending descriptor so the device
continues operating.

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
c1b5b18d9c virtio-devices: balloon: Handle invalid inflate/deflate input
A single malformed descriptor — device-writable where device-readable
is expected, non-aligned length, overflowed address, unmapped PFN, or
a failed fallocate/madvise — propagated an error that killed the
balloon device thread. Skip bad descriptors and PFNs with a warning
so the device keeps operating.

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
52db3f8655 virtio-devices: balloon: Process all inflate/deflate descriptors
Only the first descriptor in each chain was processed. If the PFN
array spanned multiple chained descriptors the remaining PFNs were
silently dropped. Iterate the full chain so every descriptor is
validated and its PFNs are acted on.

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
ff78eb8fb4 virtio-devices: balloon: Report used length of 0 for inflate/deflate
The inflate and deflate queues carry device-readable PFN arrays: the
driver writes them and the device only reads. The device never writes
to the descriptor buffers, so the used ring entry should report 0
bytes written rather than the descriptor length.

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
7c8ee401d5 virtio-devices: balloon: Fix typo, comment, and dead variants
Fix "Fail tp signal" typo, replace copy-pasted "entropy" comment
with "balloon", and remove EventFdWriteFail and QueueIterator error
variants that have no call sites.

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
5702e9751c virtio-devices: rng: Preserve byte count on mid-chain errors
When address translation or the entropy read fails mid-chain the
handler reset total_len to zero before breaking out of the loop.
If earlier descriptors in the same chain were already filled, the
used ring entry under-reports the bytes actually written to guest
memory. Drop the reset so the used length reflects reality.

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
aee4fd6010 virtio-devices: rng: Skip device-readable descriptors
A device-readable descriptor anywhere in the chain caused the handler
to reset the byte count to zero and abandon the rest of the chain.
This discards valid device-writable descriptors that follow and
misreports bytes already written to earlier descriptors.

Skip device-readable and zero-length descriptors individually so
the remaining device-writable buffers still get filled with entropy.

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
f0bb79a3a9 build: Temporarily make VFIO job non-blocking
Don't block the CI passing if the VFIO integration tests fail.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-07 16:07:44 +01:00
Rob Bradford
05fd26b601 tests: Make ovs setup idempotent
Try and delete the bridge if it exists before setting up for the test.
This prevents cascading failures where if the test fails once any
subsequent run of the test will fail during the setup.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-07 16:07:00 +01:00
Keith Adler
1a74c666e5 vmm: trim qualified paths in uffd
Import common std types used by the userfaultfd wrapper instead of
spelling the full paths at every use site.

Signed-off-by: Keith Adler <kadler@cloudflare.com>
2026-05-07 08:52:42 +01:00
Keith Adler
3db4c0f7b4 tests: remove redundant hotplug sleep
The snapshot/restore hotplug path already waits for the exact
device-removed event through the event monitor. Drop the fixed sleep
before that poll so the test advances as soon as the event arrives.

Signed-off-by: Keith Adler <kadler@cloudflare.com>
2026-05-06 20:49:56 +00:00
Rob Bradford
8e7be74680 tests: Bump vfio integration test time to 25 minutes
This timeout is being reached and kicking jobs out of the MQ.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-06 23:03:40 +01:00
Anatol Belski
35609ff777 net_util: queue_pair: Surface malformed descriptors on the used ring
Several error paths in process_desc_chain returned the error before
calling queue.add_used for the offending descriptor. The affected
variants were DescriptorChainInvalid, DescriptorChainTooShort,
DescriptorInvalidHeader, and the GuestMemory variants raised during
descriptor chain translation, slice retrieval, or the num_buffers
write on the RX side.

Without an entry in the used ring the head descriptor remained owned
by the device. A guest that kept submitting bad chains could deplete
the queue over time.

Mark the head descriptor used with length 0 before propagating the
error to the caller, so the ring stays consistent regardless of how
the device decides to react to a guest induced failure.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-05-06 21:45:18 +01:00
Anatol Belski
945e1f2654 net_util: queue_pair: Handle RX short read gracefully
When readv returns fewer bytes than vnet_hdr_len the frame is
truncated. Report the truncated length to the guest in the used
ring instead of returning a fatal InvalidVirtioNetHeader error.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-05-06 21:45:18 +01:00
Anatol Belski
c71a8ea8dd net_util: queue_pair: Handle RX readv EINVAL gracefully
When readv from the TAP returns EINVAL the guest posted a buffer
too small for the vnet_hdr. Return len 0 to the used ring and
continue instead of killing the worker thread. Also move
go_to_previous_position into the appropriate error branches only.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-05-06 21:45:18 +01:00
Anatol Belski
02ea839838 net_util: queue_pair: Handle TX short tap write gracefully
When writev returns fewer bytes than vnet_hdr_len the packet is
truncated. Log the error and drop it instead of returning a fatal
InvalidVirtioNetHeader error that would crash the worker thread.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-05-06 21:45:18 +01:00
Anatol Belski
17fefa1e45 net_util: queue_pair: Handle TX writev EINVAL gracefully
When writev to the TAP returns EINVAL the guest submitted a
malformed packet. Drop it and continue instead of killing the
worker thread.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-05-06 21:45:18 +01:00
Anatol Belski
3402bc0762 virtio-devices: NEEDS_RESET on worker thread Err
Worker threads spawned through spawn_virtio_thread previously wrote to
exit_evt on any clean Err return, taking the whole VMM down on a single
failed device worker. A guest induced fault in any virtio device thus
propagated into a host wide failure.

Route the Err return through the shared mark_device_needs_reset helper
instead. The helper sets the DEVICE_NEEDS_RESET bit on device_status
and triggers a config change interrupt, so the device goes idle and
the guest is informed. The thread exits cleanly without killing the
rest of the VMM.

The panic and the seccomp filter apply paths keep writing to exit_evt.
A panicked worker may have left poisoned locks or partially mutated
state, so a hard exit remains the right policy there.

spawn_virtio_thread now takes the device_status and the interrupt
callback. Every native virtio and vhost-user call site is updated to
pass them in.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-05-06 21:45:18 +01:00
Anatol Belski
22856fffdd virtio-devices: Factor out NEEDS_RESET helpers
Both block and net implement the same DEVICE_NEEDS_RESET bookkeeping
when a corrupted virtqueue request is detected. They set the bit,
trigger a config change interrupt and log a warning. Move that logic
into shared device_needs_reset and mark_device_needs_reset helpers in
lib.rs and update both call sites to use them.

No functional change.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
2026-05-06 21:45:18 +01:00
Damian Barabonkov
4eb1717fb0 tests: Add VFIO mmap BAR exclusion coverage
Exercise the new VFIO BAR exclusion option with NVIDIA
passthrough tests so the integration suite checks that selected
BARs are skipped.

The tests cover both legacy VFIO and iommufd paths while
preserving the existing hardware availability guards.

Signed-off-by: Damian Barabonkov <dbctl@pm.me>
Assisted-by: OpenCode:gpt-5.5
2026-05-06 14:15:41 +00:00
Damian Barabonkov
a858a1f115 docs: Document VFIO mmap BAR exclusion
Explain how operators can exclude selected VFIO BARs from mmap
when they know their workloads do not require MMIO access to those
regions.

Documenting the option separately keeps the new device argument
discoverable and calls out the valid BAR index range.

Signed-off-by: Damian Barabonkov <dbctl@pm.me>
Assisted-by: OpenCode:gpt-5.5
2026-05-06 14:15:41 +00:00
Damian Barabonkov
41e12e9d6a vmm, pci, openapi: Add VFIO mmap BAR exclusion
Allow VFIO devices to list BAR indices that should not be
mmapped into the guest. This lets operators skip large BARs that
are known not to be used by their workload.

When a BAR is skipped, the log also calls out that P2P DMA
mapping is skipped because the VFIO DMA map path uses the same
mmap backing.

Signed-off-by: Damian Barabonkov <dbctl@pm.me>
Assisted-by: OpenCode:gpt-5.5
2026-05-06 14:15:41 +00:00
Rob Bradford
12f48700a2 tests: Wait for boot notification from test_vfio_user L2 guest
Reuse the boot notification method we have for the L1 guests for the L2
guest. This removes the need to use SSH based boot tracking for
connecfting to the L2 guest and should make the test more reliable.

This requires making the L2 guest use a different cloud-init
configuration to the L1.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-06 12:30:08 +00:00
Rob Bradford
9703971ae7 tests: Use separate IP address for guest -> host notification
This will allow an L2 guest to notify the L1 host.

Signed-off-by: Rob Bradford <rbradford@meta.com>
2026-05-06 12:30:08 +00:00
Muminul Islam
ad03b1b250 performance-metrics: Use default_cpus() across all tests
Replace explicit --cpus boot=N arguments with .default_cpus()
in all performance test functions. For confidential guests,
nested=on is not supported, so using default_cpus() ensures
nested=off is correctly set for confidential VMs.

The net throughput, net latency, and block I/O tests now set
guest.num_cpu to the number of queues before calling
default_cpus(), ensuring the correct vCPU count is used.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-05-06 11:40:42 +00:00
Muminul Islam
a5adc7014c performance-metrics: Pass full control to guest constructor
Refactor performance_test_new_guest to accept the full
PerformanceTestControl reference instead of just GuestVmType.
This allows the function to also set guest.num_cpu from
control.num_boot_vcpus, ensuring the guest is configured
with the correct number of vCPUs for the test.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-05-06 11:40:42 +00:00
Muminul Islam
d56c3ba320 scripts: Support confidential VM in run_metrics.sh
Use the VM_TYPE environment variable to conditionally enable
igvm and sev_snp features when building for confidential VMs.
Pass --vm-type confidential to the performance-metrics binary
so it can select the appropriate test configuration.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-05-06 11:40:42 +00:00
Muminul Islam
9f64400943 scripts: Add --vm-type argument to dev_cli.sh
Add a --vm-type argument to the tests command in dev_cli.sh to
allow specifying the type of VM (regular or confidential). The
value is passed to the container via the VM_TYPE environment
variable.

Also extract a prepare_igvm_files() helper function to reduce
duplication when copying IGVM files for confidential VM tests,
and call it from both integration_cvm and metrics paths.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-05-06 11:40:42 +00:00
Rob Bradford
eb8b10add0 virtio-devices: iommu: Cap number of domains per device
The per-domain mapping cap bounds memory inside one domain, but a
guest can still grow the domains map indefinitely with ATTACH
requests for distinct domain IDs. Reject ATTACH with
VIRTIO_IOMMU_S_NOMEM at 64K domains.

Signed-off-by: Rob Bradford <rbradford@meta.com>
Assisted-by: Claude:claude-opus-4-7
2026-05-06 08:58:03 +00:00
Rob Bradford
63a523b3f3 virtio-devices: iommu: Clamp bypass config field to 0 or 1
The virtio spec says the device must never present a value other
than 0 or 1 for bypass. Mask off the upper bits on write so a
later read does not return whatever the driver wrote.

Signed-off-by: Rob Bradford <rbradford@meta.com>
Assisted-by: Claude:claude-opus-4-7
2026-05-06 08:58:03 +00:00
Rob Bradford
efcc090811 virtio-devices: iommu: Enforce input_range on MAP requests
The device offers VIRTIO_IOMMU_F_INPUT_RANGE when the address
width is constrained, but never validates that guest MAP requests
fall inside the advertised range. The virtio spec requires such
requests to fail with VIRTIO_IOMMU_S_RANGE.

Signed-off-by: Rob Bradford <rbradford@meta.com>
Assisted-by: Claude:claude-opus-4-7
2026-05-06 08:58:03 +00:00
Rob Bradford
1376f6e9ef virtio-devices: iommu: Return NOENT for UNMAP on unknown domain
The virtio spec mandates VIRTIO_IOMMU_S_NOENT, not S_INVAL, when
the target domain does not exist.

Signed-off-by: Rob Bradford <rbradford@meta.com>
Assisted-by: Claude:claude-opus-4-7
2026-05-06 08:58:03 +00:00
Rob Bradford
f74255f5e8 virtio-devices: iommu: Tighten MAP request validation
The handler accepted unknown flag bits, unaligned ranges, and
overlapping mappings, and returned the wrong status code when the
target domain did not exist. The virtio spec requires explicit
rejections for each of these.

Signed-off-by: Rob Bradford <rbradford@meta.com>
Assisted-by: Claude:claude-opus-4-7
2026-05-06 08:58:03 +00:00
Rob Bradford
024188cb7f virtio-devices: iommu: Validate ATTACH reserved field and flags
The virtio spec requires the device to reject ATTACH with a
non-zero reserved field, an unknown flag bit, or a bypass flag
that conflicts with an existing domain. The current handler
silently accepts all three.

Signed-off-by: Rob Bradford <rbradford@meta.com>
Assisted-by: Claude:claude-opus-4-7
2026-05-06 08:58:03 +00:00
Rob Bradford
8fb4aa61c7 virtio-devices: iommu: Drop unrecognised requests without writing reply
The virtio spec requires the device to leave the reply buffer
untouched and report a used length of zero for an unrecognised
request type, so the driver can tell the request was not handled.

Signed-off-by: Rob Bradford <rbradford@meta.com>
Assisted-by: Claude:claude-opus-4-7
2026-05-06 08:58:03 +00:00
Rob Bradford
59f9c7c08a virtio-devices: iommu: Cap mappings per domain
Domain::mappings only shrinks on UNMAP. Without a bound a guest can
issue MAP for arbitrarily many distinct virt_start values and drive
the VMM heap until the host runs out.

Reject MAP with VIRTIO_IOMMU_S_NOMEM at 1M entries per domain.

Signed-off-by: Rob Bradford <rbradford@meta.com>
Assisted-by: Claude:claude-opus-4-7
2026-05-06 08:58:03 +00:00
Rob Bradford
f77f168532 virtio-devices: iommu: Roll back partial MAP and fix DETACH panic
A concurrent DETACH between the read-lock check and the write-lock
get_mut().unwrap() in MAP/UNMAP would panic the worker. Replace the
unwrap with a let-else.

A failure on a later endpoint in the per-endpoint MAP loop, or a
DETACH that races the missing-domain branch, must roll back the
external mappings already installed; otherwise domain.mappings
diverges from VFIO state.

Signed-off-by: Rob Bradford <rbradford@meta.com>
Assisted-by: Claude:claude-opus-4-7
2026-05-06 08:58:03 +00:00
Rob Bradford
4d6c7c95c0 virtio-devices: iommu: Reject UNMAP that partially overlaps a mapping
An UNMAP that would split an existing mapping must be rejected with
VIRTIO_IOMMU_S_RANGE without removing anything. The previous start-only
retain silently left mappings that started outside the unmap range but
overlapped it.

Walk bookkeeping under a read lock and reject before touching VFIO so a
rejection cannot leave VFIO and bookkeeping out of sync.

Signed-off-by: Rob Bradford <rbradford@meta.com>
Assisted-by: Claude:claude-opus-4-7
2026-05-06 08:58:03 +00:00
Rob Bradford
7989e46f8b virtio-devices: iommu: Pass size to translate_gva/translate_gpa
The DmaRemapping translate_gva and translate_gpa entry points discarded
the size argument that AccessPlatform's signature already carries and
only checked the base address. A buffer beginning inside a mapping but
extending past it was treated as fully translated, allowing reads or
writes outside the IOMMU-authorized window.

Add `size` to the trait, validate the full span fits in a single
mapping, and propagate it through AccessPlatformMapping.

Signed-off-by: Rob Bradford <rbradford@meta.com>
Assisted-by: Claude:claude-opus-4-7
2026-05-06 08:58:03 +00:00
Rob Bradford
f9abcb8d9c virtio-devices: iommu: Use checked add for reply length
The reply length was `hdr_len + size_of::<tail>()`, computed twice.
Make it explicit via checked_add and reuse the result.

Signed-off-by: Rob Bradford <rbradford@meta.com>
Assisted-by: Claude:claude-opus-4-7
2026-05-06 08:58:03 +00:00
Muminul Islam
d552320f4f docs: remove CI workflow in the testing doc
Remove CI workflow description section as the yaml
files change often and the docs become stale quickly.

Assisted-by: Claude:Opus-4.6
Signed-off-by: Muminul Islam <muislam@microsoft.com>
2026-05-05 21:24:59 +00:00