I recently had the need to pass a PCI device - a USB controller - to a KVM guest so that the guest had exclusive use of it. The reason was that I needed to utilise a USB wireless device that connects to a Garmin Forerunner 405 that has tools and software only available in Windows. The windows tools include a driver to access the device. I do intend to work on ways to use the Garmin 405 in Linux only, but for the time being, I need to get some training done :)
Note that this blog post is discussing my specific solution - and workarounds to problems using Fedora 11 (F11) on my Lenovo T500. In particular I had to make sure of the following:
- BIOS has all Virt features enabled
- Running x86_64 (I don't waste time with 32 bit anymore)
- Must boot with intel_iommu=on kernel arg to enable VT-d
- Guest system should be 'kvm' type and using qemu-kvm emulator
The first thing I had to do was find the PCI USB controller, so in my Lenovo T500 I have exactly three USB ports on the left side. I detirmined that the two ports to the rear are attached to one PCI controller, while the front one appears to be attached to another - There are other PCI USB devices in this laptop but they are available via a docking station, or are used for internally attached devices. I found this out by trial and error, plugging in a Western Digital external USB disk into each port, and then running the command :
virsh nodedev-list --tree
I looked for the pci root that the scsi/Western Digital USB device appeared under when one port, then another, was used. I eventually found that the two USB ports toward the rear of the case are attached to one PCI device, pci_8086_293a only. So that PCI device was good one to assign exclusively to the guest.
I ran 'virsh edit win2k3' (win2k3 in the domain for my Windows guest system) and added a device entry in the
The numbers for domain, bus and function are available by dumping the XML like so:
# virsh nodedev-dumpxml pci_8086_293a
Simply convert slot and function values to HEX to get the PCI bus addreses, for example:
Once the guest system is configured to use the PCI address, we need to tell the host system to stop using it. The ehci driver is loaded by default for the USB PCI controller:
$ readlink /sys/bus/pci/devices/0000\:00\:1d.7/driver
../../../bus/pci/drivers/ehci_hcd
Detach the device:
$ virsh nodedev-dettach pci_8086_293a
Verify it is now under the control of pci_stub:
$ readlink /sys/bus/pci/devices/0000\:00\:1d.7/driver
../../../bus/pci/drivers/pci-stub
Set a sebool to allow the management of the PCI device from the guest:
$ setsebool -P virt_manage_sysfs 1
Start the guest system :
virsh start win2k3
No comments:
Post a Comment