'Does QEMU emulate enough features for vfio to work in the guest?

I'm considering using vfio instead of uio to access a PCI device from userspace code within a QEMU guest.

Can Linux running as a x86_64 QEMU guest use the vfio driver to make an emulated PCI device accessible to a userspace program running in the guest?

It's not clear to me because vfio appears to make heavy use of hardware virtualisation features (such as the IOMMU) and I'm not sure whether QEMU emulates these to the degree required to make this work.

Note that I'm not trying to pass through real PCI devices to the QEMU guest, which is what vfio is traditionally used for (by QEMU itself). Instead I am investigating whether vfio is a suitable alternative to uio within the context of the guest.



Solution 1:[1]

The question doesn't mention any elaborations regarding vfio support within the guest which you may have already come across yourself. That said, it would be useful to address this in the answer.

QEMU does provide VT-d emulation (guest vIOMMU). However, enabling this demands that Q35 platform type be selected. For example, one may enable vIOMMU device in QEMU with the following options that need to be passed to x86_64-softmmu/qemu-system-x86_64 application on start:

-machine q35,accel=kvm,kernel-irqchip=split -device intel-iommu,intremap=on

This will provide a means to bind a device within the guest to vfio-pci. More info can be found on QEMU wiki: Features/VT-d .

If you did try following this approach and stuck with malfunction, it would be nice if you shed some light on your precise observations.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1