igd-assign.txt 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. Intel Graphics Device (IGD) assignment with vfio-pci
  2. ====================================================
  3. IGD has two different modes for assignment using vfio-pci:
  4. 1) Universal Pass-Through (UPT) mode:
  5. In this mode the IGD device is added as a *secondary* (ie. non-primary)
  6. graphics device in combination with an emulated primary graphics device.
  7. This mode *requires* guest driver support to remove the external
  8. dependencies generally associated with IGD (see below). Those guest
  9. drivers only support this mode for Broadwell and newer IGD, according to
  10. Intel. Additionally, this mode by default, and as officially supported
  11. by Intel, does not support direct video output. The intention is to use
  12. this mode either to provide hardware acceleration to the emulated graphics
  13. or to use this mode in combination with guest-based remote access software,
  14. for example VNC (see below for optional output support). This mode
  15. theoretically has no device specific handling dependencies on vfio-pci or
  16. the VM firmware.
  17. 2) "Legacy" mode:
  18. In this mode the IGD device is intended to be the primary and exclusive
  19. graphics device in the VM[1], as such QEMU does not facilitate any sort
  20. of remote graphics to the VM in this mode. A connected physical monitor
  21. is the intended output device for IGD. This mode includes several
  22. requirements and restrictions:
  23. * IGD must be given address 02.0 on the PCI root bus in the VM
  24. * The host kernel must support vfio extensions for IGD (v4.6)
  25. * vfio VGA support very likely needs to be enabled in the host kernel
  26. * The VM firmware must support specific fw_cfg enablers for IGD
  27. * The VM machine type must support a PCI host bridge at 00.0 (standard)
  28. * The VM machine type must provide or allow to be created a special
  29. ISA/LPC bridge device (vfio-pci-igd-lpc-bridge) on the root bus at
  30. PCI address 1f.0.
  31. * The IGD device must have a VGA ROM, either provided via the romfile
  32. option or loaded automatically through vfio (standard). rombar=0
  33. will disable legacy mode support.
  34. * Hotplug of the IGD device is not supported.
  35. * The IGD device must be a SandyBridge or newer model device.
  36. For either mode, depending on the host kernel, the i915 driver in the host
  37. may generate faults and errors upon re-binding to an IGD device after it
  38. has been assigned to a VM. It's therefore generally recommended to prevent
  39. such driver binding unless the host driver is known to work well for this.
  40. There are numerous ways to do this, i915 can be blacklisted on the host,
  41. the driver_override option can be used to ensure that only vfio-pci can bind
  42. to the device on the host[2], virsh nodedev-detach can be used to bind the
  43. device to vfio drivers and then managed='no' set in the VM xml to prevent
  44. re-binding to i915, etc. Also note that IGD is also typically the primary
  45. graphics in the host and special options may be required beyond simply
  46. blacklisting i915 or using pci-stub/vfio-pci to take ownership of IGD as a
  47. PCI class device. Lower level drivers exist that may still claim the device.
  48. It may therefore be necessary to use kernel boot options video=vesafb:off or
  49. video=efifb:off (depending on host BIOS/UEFI) or these can be combined to
  50. a catch-all, video=vesafb:off,efifb:off. Error messages such as:
  51. Failed to mmap 0000:00:02.0 BAR <>. Performance may be slow
  52. are a good indicator that such a problem exists. The host files /proc/iomem
  53. and /proc/ioports are often useful for identifying drivers consuming ranges
  54. of the device to cause such conflicts.
  55. Additionally, IGD device are known to generate small numbers of DMAR faults
  56. when initially assigned. It is believed that this is simply the IGD attempting
  57. to access the reserved GTT space after reset, which it no longer has access to
  58. when accessed from userspace. So long as the DMAR faults are small in number
  59. and most importantly, not ongoing, these are not an indication of an error.
  60. Additionally++, analog VGA output (as opposed to digital outputs like HDMI,
  61. DVI, or DisplayPort) may be unsupported in some use cases. In the author's
  62. experience, even DP to VGA adapters can be troublesome while adapters between
  63. digital formats work well.
  64. Usage
  65. =====
  66. The intention is for IGD assignment to be transparent for users and thus for
  67. management tools like libvirt. To make use of legacy mode, simply remove all
  68. other graphics options and use "-nographic" and either "-vga none" or
  69. "-nodefaults", along with adding the device using vfio-pci:
  70. -device vfio-pci,host=00:02.0,id=hostdev0,bus=pci.0,addr=0x2
  71. For UPT mode, retain the default emulated graphics and simply add the vfio-pci
  72. device making use of any other bus address other than 02.0. libvirt will
  73. default to assigning the device a UPT compatible address while legacy mode
  74. users will need to manually edit the XML if using a tool like virt-manager
  75. where the VM device address is not expressly specified.
  76. An experimental vfio-pci option also exists to enable OpRegion, and thus
  77. external monitor support, for UPT mode. This can be enabled by adding
  78. "x-igd-opregion=on" to the vfio-pci device options for the IGD device. As
  79. with legacy mode, this requires the host to support features introduced in
  80. the v4.6 kernel. If Intel chooses to embrace this support, the option may
  81. be made non-experimental in the future, opening it to libvirt support.
  82. Developer ABI
  83. =============
  84. Legacy mode IGD support imposes two fw_cfg requirements on the VM firmware:
  85. 1) "etc/igd-opregion"
  86. This fw_cfg file exposes the OpRegion for the IGD device. A reserved
  87. region should be created below 4GB (recommended 4KB alignment), sized
  88. sufficient for the fw_cfg file size, and the content of this file copied
  89. to it. The dword based address of this reserved memory region must also
  90. be written to the ASLS register at offset 0xFC on the IGD device. It is
  91. recommended that firmware should make use of this fw_cfg entry for any
  92. PCI class VGA device with Intel vendor ID. Multiple of such devices
  93. within a VM is undefined.
  94. 2) "etc/igd-bdsm-size"
  95. This fw_cfg file contains an 8-byte, little endian integer indicating
  96. the size of the reserved memory region required for IGD stolen memory.
  97. Firmware must allocate a reserved memory below 4GB with required 1MB
  98. alignment equal to this size. Additionally the base address of this
  99. reserved region must be written to the dword BDSM register in PCI config
  100. space of the IGD device at offset 0x5C. As this support is related to
  101. running the IGD ROM, which has other dependencies on the device appearing
  102. at guest address 00:02.0, it's expected that this fw_cfg file is only
  103. relevant to a single PCI class VGA device with Intel vendor ID, appearing
  104. at PCI bus address 00:02.0.
  105. Footnotes
  106. =========
  107. [1] Nothing precludes adding additional emulated or assigned graphics devices
  108. as non-primary, other than the combination typically not working. I only
  109. intend to set user expectations, others are welcome to find working
  110. combinations or fix whatever issues prevent this from working in the common
  111. case.
  112. [2] # echo "vfio-pci" > /sys/bus/pci/devices/0000:00:02.0/driver_override