VFIO based device assignment
RFC PATCH v2 1/1 VFIO based device assignment
This is an update to the original QEMU VFIO driver I sent several months ago. Since then, I've ported it to the qemu-kvm.git tree, and back, incorporated common msix and msi code, added irqfd support, created an irqfd-like mechanism for EOIs, and likely numerous other things that I've forgotten. I have quite a few outstanding patches that enable things needed here, so I thought it would be useful to see what the current code snapshot looks like. Please review and comment. Thanks,
Alex
--
This patch adds qemu device assignment support using the proposed VFIO/UIOMMU kernel interfaces. The existing KVM-only device assignment code makes use of various pci sysfs files for config space, MMIO BAR mapping, and misc other config items. It then jumps over to KVM-specific ioctls for enabling interrupts and assigning devices to IOMMU domains. Finally, IO-port support uses in/out directly. This is a messy model to support and causes numerous issues when we try to allow unprivileged users to access PCI devices.
VFIO/UIOMMU reduces this to two interfaces, /dev/vfioX and /dev/uiommu. The VFIO device file provides all the necessary support for accessing PCI config space, read/write/mmap BARs (including IO-port space), configuring INTx/MSI/MSI-X interupts and setting up DMA mapping. The UIOMMU interface allows iommu domains to be created, and via vfio, devices can be bound to a domain. This provides an easier model to support (IMHO) and removes the bindings that make current device assignment only useable for KVM enabled guests.
Usage is similar to KVM device assignment. Rather than binding the device to the pci-stub driver, vfio devices need to be bound to the vfio driver. From there, it's a simple matter of specifying the device as:
-device vfio,host=01:00.0
This example requires either root privileges or proper permissions on /dev/uiommu and /dev/vfioX. To support unprivileged operation, the options vfiofd= and uiommufd= are available. Depending on the usage of uiommufd, each guest device can be assigned to the same iommu domain, or to independent iommu domains. In the example above, each device is assigned to a separate iommu domain.
---
Makefile.target | 1 hw/linux-vfio.h | 273 +++++++++++ hw/vfio.c | 1398 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/vfio.h | 68 +++ 4 files changed, 1740 insertions(+), 0 deletions(-) create mode 100644 hw/linux-vfio.h create mode 100644 hw/vfio.c create mode 100644 hw/vfio.h
Makefile.target +1 -0
@@ -203,6 +203,7 @@ obj-i386-y += vmmouse.o vmport.o hpet.o applesmc.o obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o obj-i386-y += debugcon.o multiboot.o obj-i386-y += pc_piix.o +obj-i386-y += vfio.o # shared objects obj-ppc-y = ppc.o
hw/linux-vfio.h new file +273 -0
273 lines not on this page · raw message
hw/vfio.c new file +1398 -0
1,398 lines not on this page · raw message
hw/vfio.h new file +68 -0
68 lines not on this page · raw message