IGVT-g: Difference between revisions

From NixOS Wiki
imported>Gnidorah
No edit summary
imported>Whazor
Add note about GVT-g removal and SR-IOV future
 
(43 intermediate revisions by 7 users not shown)
Line 1: Line 1:
Intel GVT-g is a full GPU virtualization solution with mediated pass-through which allows host and multiple guests to share same Intel integrated videocard. Guest gets a near-native graphics peformance.
Intel GVT-g is a technology that allows to "slice" an Intel GPU into virtualized GPUs that can be then passed into virtual machines.


Win7-32 / Win7-64 / Win8.1-64 /Win10-RS1-64 are validated. Install recent Intel driver into the guest.
Note that Intel GVT-g only supports Intel Broadwell (5th gen) to Comet Lake (10th gen), where in 10th gen support for IVGT-g was removed. For 11th gen, and 12th gen, there is SR-IOV coming up for virtualized GPUs, but that did not yet arrive in Linux mainline.


== Hardware Requirements ==
== Configuring GPU ==


For client platforms, 5th, 6th or 7th Generation Intel® Core Processor Graphics is required. For server platforms, E3_v4, E3_v5 or E3_v6 Xeon Processor Graphics is required.
First, enable iGVT-g with:


== NixOS configuration ==
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
  boot.kernelPackages = pkgs.linuxPackages_4_16;
virtualisation.kvmgt.enable = true;
  boot.kernelParams = [ "i915.enable_gvt=1" ];
</nowiki>}}
  nixpkgs.config.packageOverrides = super: let self = super.pkgs; in {
... then rebuild and reboot.
    linux_4_16 = super.linux_4_16.override {
 
      extraConfig = ''
 
  # since 4.16-rc1
After rebooting, check if the driver was successfully loaded:
  DRM_I915_GVT y
 
  DRM_I915_GVT_KVMGT m
   $ ls /sys/bus/pci/devices/0000:00:02.0/mdev_supported_types/
      '';
 
    };
... if you get <code>No such file or directory</code>, it means you might be using an older CPU that needs an extra configuration option:
   };
 
  environment.systemPackages = with pkgs; [
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
  virtmanager
boot.extraModprobeConfig = "options i915 enable_guc=2";
  virt-viewer
  libossp_uuid
  ];
  virtualisation.libvirtd.enable = true;
  users.extraUsers.user.extraGroups = [ "libvirtd" ];
</nowiki>}}
</nowiki>}}
== Create or destroy VGPU ==
... then rebuild and reboot once again (unless that previous <code>ls</code> succeeded, in which case you don't have to modify that <code>extraModprobeConfig</code> at all).
 
 
Now, using <code>ls</code> you can list which variants your Intel GPU is able to virtualise:
 
  $ ls /sys/bus/pci/devices/0000:00:02.0/mdev_supported_types/
  i915-GVTg_V5_4/  i915-GVTg_V5_8/
 
E.g.:


Show mode information
  $ cat /sys/bus/pci/devices/0000:00:02.0/mdev_supported_types/i915-GVTg_V5_8/description
  low_gm_size: 64MB
  high_gm_size: 384MB
  fence: 4
  resolution: 1024x768
  weight: 2


<pre>
Find some variant that matches your expectations (resolution, memory size etc.), note down its name, generate a random UUID:
$ cat /sys/bus/pci/devices/0000:00:02.0/mdev_supported_types/i915-GVTg_V5_8/description
low_gm_size: 64MB
high_gm_size: 384MB
fence: 4
resolution: 1024x768
weight: 2
</pre>


Create
  # If you're using Nix Flakes:
  $ nix shell nixpkgs#libossp_uuid -c uuid
  a297db4a-f4c2-11e6-90f6-d3b88d6c9525


<pre>
  # If you're not using Nix Flakes:
$ uuid
  $ nix run nixpkgs.libossp_uuid -c uuid
a297db4a-f4c2-11e6-90f6-d3b88d6c9525
  a297db4a-f4c2-11e6-90f6-d3b88d6c9525
# echo "a297db4a-f4c2-11e6-90f6-d3b88d6c9525" > "/sys/bus/pci/devices/0000:00:02.0/mdev_supported_types/i915-GVTg_V5_8/create"
</pre>


Destroy
... and add that variant's name into your configuration:


<pre>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
# echo 1 > /sys/bus/pci/devices/0000:00:02.0/a297db4a-f4c2-11e6-90f6-d3b88d6c9525/remove
virtualisation.kvmgt.enable = true;
</pre>
virtualisation.kvmgt.vgpus = {
  "i915-GVTg_V5_8" = {
    uuid = [ "a297db4a-f4c2-11e6-90f6-d3b88d6c9525" ];
  };
};


== Configure KVM ==
environment.systemPackages = with pkgs; [
  virtmanager
];


Support for local display is present in Qemu 2.12. Only BIOS (SeaBIOS) machine is supported, UEFI (OVMF) is not supported.
virtualisation.libvirtd.enable = true;
users.extraUsers.user.extraGroups = [ "libvirtd" ];
</nowiki>}}
 
Rebuild & voilá - your virtualized GPU is ready; now you just have to attach it to some virtual machine.
 
== Attaching GPU ==


=== Bare Qemu ===
=== Bare Qemu ===
<syntaxHighlight lang="sh">
 
   qemu-system-x86_64 \
   qemu-system-x86_64 \
     -enable-kvm \
     -enable-kvm \
     -m 1G \
     -m 1G \
     -nodefaults \
     -nodefaults \
    -M graphics=off \
    -serial stdio \
     -display gtk,gl=on \
     -display gtk,gl=on \
     -device vfio-pci,sysfsdev=/sys/bus/mdev/devices/a297db4a-f4c2-11e6-90f6-d3b88d6c9525,x-igd-opregion=on
     -device vfio-pci,sysfsdev=/sys/bus/mdev/devices/'''a297db4a-f4c2-11e6-90f6-d3b88d6c9525''',display=on,x-igd-opregion=on,driver=vfio-pci-nohotplug,ramfb=on,xres=1920,yres=1080
</syntaxHighlight>
 
=== libvirt ===


=== libvirtd ===
If using virt-manager, create new or open existing VM. Change existing <code><graphics></code> and <code><video></code> sections.
If using virt-manager, create new or open existing VM.


sudo -E virsh edit win10
sudo -E virsh edit win10
<pre>
<syntaxHighlight lang="xml" highlight="1,12">
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<devices>
  <devices>
<graphics type='spice'>
    <graphics type='spice'>
  <listen type='none'/>
      <listen type='none'/>
  <gl enable='yes'/>
      <gl enable='yes'/>
</graphics>
    </graphics>
<hostdev mode='subsystem' type='mdev' managed='no' model='vfio-pci'>
    <video>
  <source>
      <model type='none'/>
    <address uuid='a297db4a-f4c2-11e6-90f6-d3b88d6c9525'/>
    </video>
  </source>
    <hostdev mode='subsystem' type='mdev' managed='no' model='vfio-pci' display='on'>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
      <source>
</hostdev>
        <address uuid='a297db4a-f4c2-11e6-90f6-d3b88d6c9525'/>
</devices>
      </source>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </hostdev>
  </devices>
   <qemu:commandline>
   <qemu:commandline>
  <qemu:arg value='-set'/>
    <qemu:arg value='-set'/>
  <qemu:arg value='device.hostdev0.x-igd-opregion=on'/>
    <qemu:arg value='device.hostdev0.x-igd-opregion=on'/>
    <qemu:arg value='-set'/>
    <qemu:arg value='device.hostdev0.ramfb=on'/>
    <qemu:arg value='-set'/>
    <qemu:arg value='device.hostdev0.driver=vfio-pci-nohotplug'/>
    <qemu:arg value='-set'/>
    <qemu:arg value='device.hostdev0.xres=1920'/>
    <qemu:arg value='-set'/>
    <qemu:arg value='device.hostdev0.yres=1080'/>
    <qemu:env name="MESA_LOADER_DRIVER_OVERRIDE" value="i965"/>
   </qemu:commandline>
   </qemu:commandline>
</domain>
</domain>
</pre>
</syntaxHighlight>
Finally use sudo virt-viewer --attach win10


== Issues with libvirtd ==
== FAQ ==


* No video output
* No video output


Change main adapter type from QXL to say Cirrus
** use BIOS (SeaBIOS) machine, EFI (OVMF) is not supported. You may use the following workarounds https://wiki.archlinux.org/index.php/Intel_GVT-g#Using_DMA-BUF_with_UEFI/OVMF
 
** ensure that the recent Intel graphics driver is installed in the guest


* Still no video output
* (libvirtd) "Element domain has extra content: qemu:commandline" error after editing via virsh


Ensure that mdev's hostdev device is the first or bump device.hostdev0 index
** you forgot to add <nowiki>xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'</nowiki>


* "Element domain has extra content: qemu:commandline" error after editing via virsh
* (libvirtd) "no drm render node available" error in virt-manager


You forgot to add <nowiki>xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'</nowiki>
** in virt-manager change SPICE display render node from auto to available one


* no drm render node available
* "write_loop: No space left on device" error when creating mdev device


in virt-manager change spice display render node from auto to available one
** check whether available instances are left
  $ cat /sys/bus/pci/devices/0000\:00\:02.0/mdev_supported_types/i915-GVTg_V5_4/available_instances
  1
also check dmesg output for gvt related error, most likely there is not enough VRAM


== Used sources ==
* (libvirtd) VM stops immediately with no error other than "internal error: process exited while connecting to monitor"


* [https://www.kraxel.org/blog/2018/04/vgpu-display-support-finally-merged-upstream/ <em>vgpu display support</em> on a contributor (kraxel)'s blog] - this guide misses info that Windows guests do require x-igd-opregion=on parameter and also that QXL goes into conflict
** qemu might be exiting due to SIGSYS, which may be related to this bug: https://github.com/intel/gvt-linux/issues/47
* https://github.com/intel/gvt-linux/wiki/GVTg_Setup_Guide - obsoleted guide, but some parts are useful
Try disabling seccomp sandboxing in qemu like so:
* https://github.com/intel/gvt-linux/wiki/Dma_Buf_User_Guide - obsoleted guide, but some parts are useful
<syntaxHighlight lang="nix">
  virtualisation.libvirtd = {
    qemuVerbatimConfig = ''
      seccomp_sandbox = 0
    '';
  };
</syntaxHighlight>
== Useful sources ==


* https://www.kraxel.org/blog/2019/02/ramfb-display-in-qemu/ - Info about ramfb parameter
* https://lists.01.org/hyperkitty/list/igvt-g@lists.01.org/thread/LAB74CANVVRKGPBJMHULMMUFX43LRH55/ - Info about x-igd-opregion parameter
* https://www.kraxel.org/blog/2019/03/edid-support-for-qemu/ - Info about xres and yres parameters
[[Category:Video]]
[[Category:Video]]
[[Category:Virtualization]]
[[Category:Virtualization]]

Latest revision as of 18:58, 21 December 2022

Intel GVT-g is a technology that allows to "slice" an Intel GPU into virtualized GPUs that can be then passed into virtual machines.

Note that Intel GVT-g only supports Intel Broadwell (5th gen) to Comet Lake (10th gen), where in 10th gen support for IVGT-g was removed. For 11th gen, and 12th gen, there is SR-IOV coming up for virtualized GPUs, but that did not yet arrive in Linux mainline.

Configuring GPU

First, enable iGVT-g with:

/etc/nixos/configuration.nix
virtualisation.kvmgt.enable = true;

... then rebuild and reboot.


After rebooting, check if the driver was successfully loaded:

 $ ls /sys/bus/pci/devices/0000:00:02.0/mdev_supported_types/

... if you get No such file or directory, it means you might be using an older CPU that needs an extra configuration option:

/etc/nixos/configuration.nix
boot.extraModprobeConfig = "options i915 enable_guc=2";

... then rebuild and reboot once again (unless that previous ls succeeded, in which case you don't have to modify that extraModprobeConfig at all).


Now, using ls you can list which variants your Intel GPU is able to virtualise:

 $ ls /sys/bus/pci/devices/0000:00:02.0/mdev_supported_types/
 i915-GVTg_V5_4/  i915-GVTg_V5_8/

E.g.:

 $ cat /sys/bus/pci/devices/0000:00:02.0/mdev_supported_types/i915-GVTg_V5_8/description 
 low_gm_size: 64MB
 high_gm_size: 384MB
 fence: 4
 resolution: 1024x768
 weight: 2

Find some variant that matches your expectations (resolution, memory size etc.), note down its name, generate a random UUID:

 # If you're using Nix Flakes:
 $ nix shell nixpkgs#libossp_uuid -c uuid
 a297db4a-f4c2-11e6-90f6-d3b88d6c9525
 # If you're not using Nix Flakes:
 $ nix run nixpkgs.libossp_uuid -c uuid
 a297db4a-f4c2-11e6-90f6-d3b88d6c9525

... and add that variant's name into your configuration:

/etc/nixos/configuration.nix
virtualisation.kvmgt.enable = true; 
virtualisation.kvmgt.vgpus = {
  "i915-GVTg_V5_8" = {
    uuid = [ "a297db4a-f4c2-11e6-90f6-d3b88d6c9525" ];
  };
};

environment.systemPackages = with pkgs; [
  virtmanager
];

virtualisation.libvirtd.enable = true;
users.extraUsers.user.extraGroups = [ "libvirtd" ];

Rebuild & voilá - your virtualized GPU is ready; now you just have to attach it to some virtual machine.

Attaching GPU

Bare Qemu

 qemu-system-x86_64 \
    -enable-kvm \
    -m 1G \
    -nodefaults \
    -display gtk,gl=on \
    -device vfio-pci,sysfsdev=/sys/bus/mdev/devices/a297db4a-f4c2-11e6-90f6-d3b88d6c9525,display=on,x-igd-opregion=on,driver=vfio-pci-nohotplug,ramfb=on,xres=1920,yres=1080

libvirt

If using virt-manager, create new or open existing VM. Change existing <graphics> and <video> sections.

sudo -E virsh edit win10

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
  <devices>
    <graphics type='spice'>
      <listen type='none'/>
      <gl enable='yes'/>
    </graphics>
    <video>
      <model type='none'/>
    </video>
    <hostdev mode='subsystem' type='mdev' managed='no' model='vfio-pci' display='on'>
      <source>
        <address uuid='a297db4a-f4c2-11e6-90f6-d3b88d6c9525'/>
      </source>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </hostdev>
  </devices>
  <qemu:commandline>
    <qemu:arg value='-set'/>
    <qemu:arg value='device.hostdev0.x-igd-opregion=on'/>
    <qemu:arg value='-set'/>
    <qemu:arg value='device.hostdev0.ramfb=on'/>
    <qemu:arg value='-set'/>
    <qemu:arg value='device.hostdev0.driver=vfio-pci-nohotplug'/>
    <qemu:arg value='-set'/>
    <qemu:arg value='device.hostdev0.xres=1920'/>
    <qemu:arg value='-set'/>
    <qemu:arg value='device.hostdev0.yres=1080'/>
    <qemu:env name="MESA_LOADER_DRIVER_OVERRIDE" value="i965"/>
  </qemu:commandline>
</domain>

FAQ

  • No video output
    • ensure that the recent Intel graphics driver is installed in the guest
  • (libvirtd) "Element domain has extra content: qemu:commandline" error after editing via virsh
    • you forgot to add xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'
  • (libvirtd) "no drm render node available" error in virt-manager
    • in virt-manager change SPICE display render node from auto to available one
  • "write_loop: No space left on device" error when creating mdev device
    • check whether available instances are left
 $ cat /sys/bus/pci/devices/0000\:00\:02.0/mdev_supported_types/i915-GVTg_V5_4/available_instances 
 1

also check dmesg output for gvt related error, most likely there is not enough VRAM

  • (libvirtd) VM stops immediately with no error other than "internal error: process exited while connecting to monitor"

Try disabling seccomp sandboxing in qemu like so:

  virtualisation.libvirtd = {
    qemuVerbatimConfig = ''
      seccomp_sandbox = 0
    '';
  };

Useful sources