Skip to content

Virtio device with features#3445

Open
asherkariv wants to merge 7 commits intomicrosoft:mainfrom
asherkariv:virtio-with-features
Open

Virtio device with features#3445
asherkariv wants to merge 7 commits intomicrosoft:mainfrom
asherkariv:virtio-with-features

Conversation

@asherkariv
Copy link
Copy Markdown
Contributor

Virtio: allow specifying device features at creation.

Add the ability to customize VirtIO device features based on host configuration.
For example, this is required for environments utilizing SWIOTLB, where the device
must advertise VIRTIO_F_ACCESS_PLATFORM to ensure proper memory access through
the IOMMU/bounce buffers.

The missing reply may have caused the crash in the guest, during unmount of a virtiofs mount,
since the guest is waiting indefinitely for the fuse_destroy request reply, such as
demonstrated by the captured stack below.

Process: 1583 (parent:  1569)
cmd:
stat:
1583 (weston) Z 1569 1 1 58624 1 4228364 5042 0 0 0 12 2 0 0 20 0 2 0 16448 0 0 18446744073709551615 0 0 0 0 0 0 84480 0 2 0 0 0 17 6 0 0 0 0 0 0 0 0 0 0 0 0 9
tid: 1583 - weston
tid: 1585 - weston
[<0>] request_wait_answer+0x138/0x220
[<0>] fuse_simple_request+0x189/0x2d0
[<0>] fuse_send_destroy+0x66/0x70
[<0>] fuse_conn_destroy+0xae/0xc0
[<0>] virtio_kill_sb+0xc2/0x180
[<0>] deactivate_locked_super+0x39/0xb0
[<0>] deactivate_super+0x44/0x50
[<0>] cleanup_mnt+0xc3/0x160
[<0>] __cleanup_mnt+0x16/0x20
[<0>] task_work_run+0x65/0xa0
[<0>] do_exit+0x37a/0xb30
[<0>] do_group_exit+0x39/0x90
[<0>] get_signal+0xa9a/0xaa0
Update the backend fuse protocol to version 7.39, and use FUSE_DIRECT_IO_ALLOW_MMAP
to enable memory backed files with VirtioFS.

Related work items: https://microsoft.visualstudio.com/OS/_workitems/edit/61002501
Add the ability to customize VirtIO device features based on host configuration.
For example, this is required for environments utilizing SWIOTLB, where the device
must advertise VIRTIO_F_ACCESS_PLATFORM to ensure proper memory access through
the IOMMU/bounce buffers.
@asherkariv asherkariv requested a review from a team as a code owner May 8, 2026 18:53
Copilot AI review requested due to automatic review settings May 8, 2026 18:53
@benhillis benhillis requested a review from Brian-Perkins May 8, 2026 18:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for specifying transport-level VirtIO feature bits at device creation time, enabling host-driven configuration like advertising VIRTIO_F_ACCESS_PLATFORM (e.g., for SWIOTLB/IOMMU environments).

Changes:

  • Introduces new_with_transport_features constructors for MMIO and PCI transports, while keeping new() as a default (VIRTIO_F_VERSION_1) wrapper.
  • Extends VirtioTransportCore creation to merge caller-supplied transport features with device-specific features.
  • Adds MMIO-focused tests to validate VIRTIO_F_ACCESS_PLATFORM propagation (and absence by default).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
vm/devices/virtio/virtio/src/transport/pci.rs Adds PCI constructor that accepts transport feature bits and wires them into the core.
vm/devices/virtio/virtio/src/transport/mmio.rs Adds MMIO constructor that accepts transport feature bits and wires them into the core.
vm/devices/virtio/virtio/src/transport/core.rs Implements merging of transport features into device-advertised feature bits.
vm/devices/virtio/virtio/src/tests.rs Adds tests validating VIRTIO_F_ACCESS_PLATFORM behavior for MMIO.
Comments suppressed due to low confidence (1)

vm/devices/virtio/virtio/src/transport/core.rs:1

  • The new new_with_transport_features path no longer guarantees VIRTIO_F_VERSION_1 is set (previously it was forced via with_version_1(true)), so a caller passing an “empty” transport_features can accidentally create a device that doesn’t advertise VERSION_1. If the implementation requires modern VirtIO, consider enforcing VERSION_1 inside the core (e.g., always OR it in regardless of caller input), or validating and returning an error when VERSION_1 is absent. This avoids a footgun and keeps new_with_transport_features safe-by-default.
// Copyright (c) Microsoft Corporation.

Comment thread vm/devices/virtio/virtio/src/transport/core.rs
Comment thread vm/devices/virtio/virtio/src/transport/pci.rs
Comment thread vm/devices/virtio/virtio/src/tests.rs
@github-actions github-actions Bot added the unsafe Related to unsafe code label May 8, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

Copilot AI review requested due to automatic review settings May 8, 2026 20:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants