This patchset adds a new virt-pci driver to UML that allows users to pass through host PCI devices to UML via VFIO. Currently, only MSI-X capable devices are supported, and drivers are assumed to use MSI-X.
This driver has been tested with virtio-net-pci, virtio-blk-pci and nvme in a QEMU virtual machine with virtual IOMMU enabled. Regression testing for virtio_pcidev has only covered compile tests and partial virtio probe/remove tests with a dummy vhost-user backend. Here are some steps to try out this driver: 1. Enable IOMMU and bind PCI devices to the vfio-pci driver. 2. Launch a UML instance directly (assuming that the PCI devices to be passed through to UML are 0000:02:00.0 and 0000:03:00.0). $ ./linux mem=2G init=/bin/sh ubd0=$your_rootfs_image \ vfio_uml.device=0000:02:00.0 \ vfio_uml.device=0000:03:00.0 Note that, currently, it's not possible to allocate a large amount of "physical" memory to the UML instance; otherwise, it may overlap with IOMMU-reserved IOVA ranges (e.g. [0xfee00000, 0xfef00000)), causing DMA mapping failures. This patchset is based on the following patchset: https://lore.kernel.org/all/20250306150747.2926434-1-tiwei....@antgroup.com/ v1: - Add more details in the commit log; RFC: https://lore.kernel.org/all/20250310074057.3977758-1-tiwei....@antgroup.com/ Tiwei Bie (3): um: Rewrite the sigio workaround based on epoll and tgkill um: virt-pci: Refactor virtio_pcidev into its own module um: Add VFIO-based virtual PCI driver arch/um/drivers/Kconfig | 20 +- arch/um/drivers/Makefile | 5 +- arch/um/drivers/random.c | 2 +- arch/um/drivers/rtc_user.c | 2 +- arch/um/drivers/vfio_kern.c | 648 +++++++++++++++++++++++++++++ arch/um/drivers/vfio_user.c | 323 +++++++++++++++ arch/um/drivers/vfio_user.h | 44 ++ arch/um/drivers/virt-pci.c | 699 ++++++-------------------------- arch/um/drivers/virt-pci.h | 41 ++ arch/um/drivers/virtio_pcidev.c | 628 ++++++++++++++++++++++++++++ arch/um/include/shared/os.h | 2 +- arch/um/include/shared/sigio.h | 1 - arch/um/kernel/sigio.c | 26 -- arch/um/os-Linux/sigio.c | 330 ++------------- 14 files changed, 1866 insertions(+), 905 deletions(-) create mode 100644 arch/um/drivers/vfio_kern.c create mode 100644 arch/um/drivers/vfio_user.c create mode 100644 arch/um/drivers/vfio_user.h create mode 100644 arch/um/drivers/virt-pci.h create mode 100644 arch/um/drivers/virtio_pcidev.c -- 2.34.1