Skip to content

Instantly share code, notes, and snippets.

@sar
Last active May 23, 2021 20:14
Show Gist options
  • Save sar/ca807f7b5fa21686662a65e3cf6fa58b to your computer and use it in GitHub Desktop.
Save sar/ca807f7b5fa21686662a65e3cf6fa58b to your computer and use it in GitHub Desktop.
Common settings for USB and PCI-E device passthrough using libvirt qemu kvm

Common settings for USB and PCI-E device passthrough using libvirt qemu kvm

Editing QEMU KVM domain

Insert desired props in XML format using $ sudo virsh edit <domain>

Passthrough USB Device

To query usb devices reported on host system, run lsusb -v | grep ${target_name}

    <hostdev mode='subsystem' type='usb' managed='yes'>
      <source>
        <vendor id='0x0000'/>
        <product id='0x0000'/>
      </source>
      <address type='usb' bus='0' port='10'/>
    </hostdev>

Passthrough GPU on PCI-E lane

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

Passthrough Disk

Ensure that the disk is not mounted on host for filesystems such as XFS, EXT4 to avoid write path and cache conflicts.

Disk or Disk Partition

    <disk type='block' device='disk'>
      <driver name='qemu' type='raw' io='threads'/>
      <source dev='/dev/nvme0'/>
      <target dev='vdb' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x10' slot='0x00' function='0x0'/>
    </disk>

Host Direct Networking

Exposes Guest VMs to local network (versus default behind NAT) for attaching IP address.

    <interface type='direct'>
      <mac address='<<MAC_ADDRESS>>'/>
      <source dev='enp10s0' mode='vepa'/>
      <model type='rtl8139'/>
      <address type='pci' domain='0x0000' bus='0x12' slot='0x01' function='0x0'/>
    </interface>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment