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

AlanObject asked:

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
  <capability type='pci'>
    <product id='0x0a65'>GT218 [GeForce 210]</product>
    <vendor id='0x10de'>NVIDIA Corporation</vendor>
    <capability type='virt_functions'>

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'>
    <address domain='0x0000' bus='0x21' slot='0x00' function='0x0'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0' multifunction='on'/>
<hostdev mode='subsystem' type='pci' managed='yes'>
    <address domain='0x0000' bus='0x21' slot='0x00' function='0x1'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x1'/>

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?

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

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.