使用PCI-Pass Through将video卡分配给KVM访客虚拟机

这是使用KVM的Ubuntu 12.04LTS。 系统有一个显卡,可以看到pipe理程序的内核,如下所示:

# virsh nodedev-dumpxml pci_0000_21_00_0 <device> <name>pci_0000_21_00_0</name> <parent>pci_0000_20_02_0</parent> <driver> <name>nvidia</name> </driver> <capability type='pci'> <domain>0</domain> <bus>33</bus> <slot>0</slot> <function>0</function> <product id='0x0a65'>GT218 [GeForce 210]</product> <vendor id='0x10de'>NVIDIA Corporation</vendor> <capability type='virt_functions'> </capability> </capability> </device> 

还有一个PCIfunction#1,它是我省略了dumpxml的卡的audio部分。

在我的域XML中,我有以下几点:

 <hostdev mode='subsystem' type='pci' managed='yes'> <source> <address domain='0x0000' bus='0x21' slot='0x00' function='0x0'/> </source> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0' multifunction='on'/> </hostdev> <hostdev mode='subsystem' type='pci' managed='yes'> <source> <address domain='0x0000' bus='0x21' slot='0x00' function='0x1'/> </source> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x1'/> </hostdev> 

如果没有这些hostdev标签,我的guest虚拟机启动就好了(这也是一个Ubuntu 12.04LTS内核)。 当我尝试启动虚拟机与他们时,我得到:

 # virsh nodedev-detach pci_0000_21_00_0 Device pci_0000_21_00_0 detached # virsh nodedev-detach pci_0000_21_00_1 Device pci_0000_21_00_1 detached # virsh start testv error: Failed to start domain testv error: Unable to read from monitor: Connection reset by peer 

谁能说出了什么问题?

更新:有点新的KVM我没有意识到有一个日志文件可用。 它说:

 Failed to assign device "hostdev0" : Device or resource busy *** The driver 'pci-stub' is occupying your device 0000:21:00.0. *** *** You can try the following commands to free it: *** *** $ echo "10de 0a65" > /sys/bus/pci/drivers/pci-stub/new_id *** $ echo "0000:21:00.0" > /sys/bus/pci/drivers/pci-stub/unbind *** $ echo "0000:21:00.0" > /sys/bus/pci/drivers/pci-stub/bind *** $ echo "10de 0a65" > /sys/bus/pci/drivers/pci-stub/remove_id *** kvm: -device pci-assign,host=21:00.0,id=hostdev0,configfd=30,bus=pci.0,multifunction=on,addr=0x4: Device 'pci-assign' could not be initialized 2014-12-17 19:15:52.368+0000: shutting down 

显然, nodedev-detatch命令会使存根驱动程序处于活动状态? build议的命令是否在虚拟机pipe理程序或虚拟机中运行?

您似乎在主机上安装了NVIDIA专有的graphics驱动程序。 如果您打算在客人身上使用此卡,并且您没有使用任何其他NVIDIA卡,请尝试卸载此驱动程序。

如果我没有错,你试图通过主机的当前VGA到VM。 坦率地说这有点棘手,有很多要求,从硬件开始。 首先,你需要

  • 一个支持英特尔VT-d(定向I / O)
  • 支持VT-d和iommu的Mobo。
  • 你的linux内核必须用intel_iommu编译(Fedora&Ubuntu默认支持)
  • 主机开始使用grub参数“intel_iommu = on”

然后KVM将能够使用你主机的graphics卡通过QEMU暴露给VM。 这里是一个很好的指导 。