iommu

Playing Around With QEMU and VT-d

Blog post by pfoetchen on Sat, 2012-04-07 21:38

Yesterday I played a bit with qemu and the VT-d/IOMMU extension. The Vt-d extension present in many modern processors allows you to forward a PCI-device directly to your virtual machine so you can access it from the virtual machine as if it were a real device. This can be very helpful to develop drivers for PCI-devices without having to reboot the whole computer all the time.

For example in my PC I use my Intel-onboard graphic as my main graphics card but I also have a Radeon in the PCI-express slot so I tried to forward it to my Haiku VM and it was more or less successful ;). To do that under Linux you have to detach the card from its real driver (probably the radeon kernel module under linux) and give it to the pci-stub module (you might have to load it first). To get the PCI-IDs and all the other information use lspci.

# where 1002 is the vendor ID and 68f9 is the device ID of the Radeon card
echo "68f9 1002" > /sys/bus/pci/drivers/pci-stub/new_id
#unbind the device from the driver "0000:01:00.0" is the first device on the PCI-express-bus
echo 0000:01:00.0 > /sys/bus/pci/devices/0000:01:00.0/driver/unbind
# unbinding might take some time so better be save than sorry ;)
sleep 5
#and finaly bind it to pci-stub
echo 0000:01:00.0 > /sys/bus/pci/drivers/pci-stub/bind

Now the Radeon card should be assigned to the pci-stub driver (you might have to rebind the audio part, too). This threw some errors for me but it still worked ;)

So we can come to the interesting part of it all: starting qemu with the new device I used the following comandline:

qemu-system-x86_64  -m 1024  -cdrom haiku-nightly-anyboot.image -device pci-assign,host=01:00.0  -serial file:log.txt

The thing that does all the work is the -device pci-assign,host=01:00.0 part that assigns the radeon card we just bound to the pci-stub driver to the virtual machine. Qemu should now start and boot on the normal qemu window but as soon as it loads the (Haiku) radeon</