Assigning video card to KVM guest VM with PCI-Pass Through

kvm-virtualizationvirsh

This is on Ubuntu 12.04LTS using KVM. The system has a graphics card which is visible to the hypervisor's kernel shown as follows:

# 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>

There is also a PCI Function #1 which is the audio portion of the card for which I omitted the dumpxml.

In my domain XML, I have the following:

<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>

Without these hostdev tags my guest VM boots up just fine (it is also an Ubuntu 12.04LTS kernel). When I try to start the VM with them I get:

# 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

Can anyone say what is going wrong?

UPDATE: Being somewhat new to KVM I didn't realize there was a log file available. It says this:

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

So apparently the nodedev-detatch command leaves a stub driver active? Are the suggested commands to be run in the hypervisor or the VM?

Best Answer

You seem to have installed the NVIDIA proprietary graphics drivers on the host. If you mean to use this card on the guest, and you aren't using any other NVIDIA cards, try uninstalling this driver.