-
Notifications
You must be signed in to change notification settings - Fork 206
openvmm: Add VFIO PCI device assignment #3248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5b8df12
assigned_device_vfio: add VFIO PCI device assignment crate
will-j-wright df5f6ff
openvmm: add --vfio CLI arg and wire VFIO devices into PCIe topology
will-j-wright 4813305
Guide: add VFIO device assignment user guide
will-j-wright 2b093ea
assigned_device_vfio: add BAR MMIO proxy and MSI-X emulation
will-j-wright 803e645
assigned_device_vfio: add MSI-X emulation and MMIO registration
will-j-wright eee1577
assigned_device_vfio: replace event_or_proxy with irqfd
will-j-wright 886e0a3
assigned_device_vfio: rename crate to vfio_assigned_device
will-j-wright d0bdf2a
vfio: address code review feedback
will-j-wright 2d9ad3d
fix: VFIO lifetime handles, map_msix truncation check, Guide limitations
Copilot f058203
vfio: implement DMA mapping for VFIO IOMMU Type1v2
will-j-wright 6eb3864
pci_core: add MsixRoute trait for kernel-mediated MSI-X delivery
will-j-wright b6336ba
vfio: fix review feedback (route ordering, BAR write warnings, vector…
will-j-wright 0f40e95
vfio: model as PciDeviceHandleKind with resource resolver
will-j-wright 431e683
vfio: fix review feedback (cap walk limit, hotplug mem_layout, loggin…
will-j-wright 7307e9d
vfio: fix PCI ID examples, MSI-X cfg read intercept, clear_msi, set_p…
will-j-wright 336f636
fmt
will-j-wright 633139e
vfio: hardening (overflow checks, page alignment, set_routes cleanup,…
will-j-wright 44aef82
pci_core: move MsixRoute into MsiInterrupt for unified interrupt deli…
will-j-wright 7d1b1d3
vfio: use GuestMemory::sharing() instead of mem_layout for DMA mapping
will-j-wright cc8a0fe
review
will-j-wright 2427bf1
copilot review
will-j-wright 6712971
vfio: fix 64-bit BAR mask truncation, fold update_route into enable
will-j-wright File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| # VFIO Device Assignment | ||
|
|
||
| This page explains how to assign a physical PCI device to an OpenVMM guest using Linux VFIO. | ||
|
|
||
| VFIO device assignment lets a guest VM directly access a physical PCI device (such as an NVMe controller or GPU). The guest sees the real device in its PCI bus and can interact with its config space. | ||
|
|
||
| ```admonish warning | ||
| VFIO device assignment is experimental. PCI config space, BAR MMIO passthrough, MSI-X interrupts (via irqfd), and DMA are functional. Devices such as NVMe controllers work end-to-end. | ||
| ``` | ||
|
|
||
| ## Overview | ||
|
|
||
| OpenVMM running on a Linux host can assign physical PCI devices to guest VMs using VFIO. The device is bound to the `vfio-pci` kernel driver, then OpenVMM opens it via VFIO and presents it to the guest as a PCIe endpoint. | ||
|
|
||
| ```text | ||
| Linux Host | ||
| └── OpenVMM | ||
| └── Guest VM | ||
| └── sees physical PCI device on its PCI bus | ||
| ``` | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - A Linux host with IOMMU support enabled (Intel VT-d or AMD-Vi) | ||
| - A PCI device available for passthrough | ||
| - The `vfio-pci` kernel module loaded | ||
| - The `vfio_iommu_type1` kernel module loaded | ||
|
|
||
| ## Step 1: Identify the device | ||
|
|
||
| Find the PCI device you want to assign: | ||
|
|
||
| ```bash | ||
| lspci -D | ||
| ``` | ||
|
|
||
| Look for the device's PCI address in `domain:bus:device.function` format, for example `0000:01:00.0`. | ||
|
|
||
| ## Step 2: Enable unsafe interrupts | ||
|
will-j-wright marked this conversation as resolved.
|
||
|
|
||
| Some IOMMU implementations do not support interrupt remapping. If VFIO fails to set up the IOMMU with an "interrupt remapping" error, allow it to proceed without: | ||
|
|
||
| ```bash | ||
| echo 1 | sudo tee /sys/module/vfio_iommu_type1/parameters/allow_unsafe_interrupts | ||
| ``` | ||
|
|
||
| ```admonish note | ||
| This flag is required in environments where the IOMMU does not support interrupt remapping (e.g., some nested virtualization setups). The "unsafe" label means a device could theoretically forge interrupt messages. In practice, this is acceptable when the host platform already constrains device behavior. | ||
| ``` | ||
|
|
||
| To make this persistent across reboots, add a modprobe config: | ||
|
|
||
| ```bash | ||
| echo "options vfio_iommu_type1 allow_unsafe_interrupts=1" | sudo tee /etc/modprobe.d/vfio.conf | ||
| ``` | ||
|
|
||
| ## Step 3: Bind the device to vfio-pci | ||
|
|
||
| If the device is currently bound to another driver (e.g., `nvme`), unbind it first: | ||
|
|
||
| ```bash | ||
| echo "0000:01:00.0" | sudo tee /sys/bus/pci/devices/0000:01:00.0/driver/unbind | ||
| ``` | ||
|
|
||
| Then bind to `vfio-pci`: | ||
|
|
||
| ```bash | ||
| echo "vfio-pci" | sudo tee /sys/bus/pci/devices/0000:01:00.0/driver_override | ||
| echo "0000:01:00.0" | sudo tee /sys/bus/pci/drivers/vfio-pci/bind | ||
| ``` | ||
|
will-j-wright marked this conversation as resolved.
|
||
|
|
||
| Verify the binding: | ||
|
|
||
| ```bash | ||
| ls -la /sys/bus/pci/devices/0000:01:00.0/driver | ||
| # Should show: ... -> ../../../../bus/pci/drivers/vfio-pci | ||
| ``` | ||
|
|
||
| ```admonish warning | ||
| If the device is an NVMe controller backing a mounted filesystem, unbinding it will cause data loss. Make sure you are not using the device before unbinding. | ||
| ``` | ||
|
|
||
| ## Step 4: Verify VFIO group | ||
|
|
||
| Check that a VFIO group device was created: | ||
|
|
||
| ```bash | ||
| ls /dev/vfio/ | ||
| ``` | ||
|
|
||
| You should see a numbered group (e.g., `/dev/vfio/0`). An IOMMU group is required — NoIommu mode is not supported. | ||
|
|
||
| ## Step 5: Launch OpenVMM with the VFIO device | ||
|
|
||
| Use the `--vfio` flag to assign the device to a PCIe root port. You also need to create a PCIe root complex and root port for the device to attach to: | ||
|
|
||
| ```bash | ||
| sudo openvmm \ | ||
| --pcie-root-complex rc0 \ | ||
| --pcie-root-port rc0:rp0 \ | ||
| --vfio rp0:0000:01:00.0 \ | ||
| --kernel /path/to/vmlinux \ | ||
| --initrd /path/to/initrd \ | ||
| --cmdline "console=ttyS0" \ | ||
| --com1 console \ | ||
| --memory 256M \ | ||
| --processors 2 | ||
| ``` | ||
|
|
||
| The `--vfio` syntax is `<port_name>:<pci_bdf>`: | ||
|
|
||
| - `rp0` — the name of the PCIe root port to attach the device to (must match a `--pcie-root-port` name) | ||
| - `0000:01:00.0` — the PCI BDF of the VFIO device on the host | ||
|
|
||
|
will-j-wright marked this conversation as resolved.
|
||
| ```admonish tip | ||
| You can assign multiple devices by adding more root ports and `--vfio` flags: | ||
|
|
||
| --pcie-root-port rc0:rp0 \ | ||
| --pcie-root-port rc0:rp1 \ | ||
| --vfio rp0:0000:01:00.0 \ | ||
| --vfio rp1:334c:00:00.0 | ||
| ``` | ||
|
|
||
| ## Step 6: Verify in the guest | ||
|
|
||
| If the guest boots with PCI support, the assigned device should be visible: | ||
|
|
||
| ```bash | ||
| lspci | ||
| ``` | ||
|
|
||
| The device will appear with its real vendor and device ID from the physical hardware. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### "No such file or directory" for `/dev/vfio/*` | ||
|
|
||
| Make sure you completed Step 2 (allow unsafe interrupts) and that the device is bound to `vfio-pci`. An IOMMU must be available — NoIommu mode is not supported. | ||
|
|
||
| ### "No interrupt remapping" / ENODEV on IOMMU setup | ||
|
|
||
| Run Step 2 to enable `allow_unsafe_interrupts`. This is needed when the platform's IOMMU does not support interrupt remapping. | ||
|
|
||
| ### "failed to open VFIO device" / permission denied | ||
|
|
||
| Run OpenVMM with `sudo`, or add your user to the `vfio` group and set appropriate permissions on `/dev/vfio/` devices. | ||
|
|
||
| ### Device not visible in guest `lspci` | ||
|
|
||
| - Verify the device is bound to `vfio-pci` (Step 3) | ||
| - Verify the VFIO group exists in `/dev/vfio/` (Step 4) | ||
| - Verify the `--vfio` port name matches a `--pcie-root-port` name | ||
| - Check OpenVMM log output for errors during VFIO device initialization | ||
|
|
||
| ## Current Limitations | ||
|
|
||
| - **No save/restore** — VMs with VFIO devices cannot be saved or migrated. | ||
| - **No hot-plug** — VFIO devices must be specified at VM creation time and cannot be added or removed while the VM is running. | ||
| - **Linux only** — the `--vfio` flag is only available when OpenVMM is built and run on Linux. On Windows, use `--device` with WHP for device assignment. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.