Intel GVT-g:virt-manager 上的图形混乱

Intel GVT-g:virt-manager 上的图形混乱

在此处输入图片描述

在配置为使用英特尔 GVT-g GPU 直通的这台虚拟机上,virt-manager 视频被打乱了。屏幕可以正常工作,我可以登录,操作桌面上的内容。但我什么都读不清。

有谁对 GVT-g 很了解,能帮助我吗?

背景:

英特尔移植物抗凝剂是第 5 代至第 9 代核心处理器内置的一项功能,允许 Xen 和 KVM 等虚拟化环境同时向多个虚拟客户端展示主机主板上的英特尔图形处理器。这反过来又允许客户端以接近硬件的速度运行 3D 加速应用程序。

解释:

我已经按照ArchLinux 维基在 Ubuntu 22.04 vm 主机 (Coffee Lake/UHD Graphics 630) 上。涉及的虚拟机是 Windows 10 和 2019,尽管有 virt-manager,我仍可以使用 RDP (Remmina) 登录它们。

在虚拟机上,主机 GPU 确实会传递到设备管理器。驱动程序安装非常简单。 在此处输入图片描述

真正酷的是,即使我在 RDP 会话中,我的 3D 应用程序也能加速。而且我最多可以同时在 8 个虚拟机上使用它!

在此处输入图片描述

virt-manager 中除视频外一切正常!

细节:

主机配置

inxi -Fj
System:
  Host: cview Kernel: 5.15.0-56-generic x86_64 bits: 64 Desktop: MATE 1.26.0
    Distro: Ubuntu 22.04.1 LTS (Jammy Jellyfish)
Machine:
  Type: Desktop Mobo: ASUSTeK model: PRIME B360M-A v: Rev X.0x
    serial: <superuser required> UEFI: American Megatrends v: 3202
    date: 07/10/2021
CPU:
  Info: 6-core model: Intel Core i5-9600K bits: 64 type: MCP cache:
    L2: 1.5 MiB
  Speed (MHz): avg: 800 min/max: 800/4600 cores: 1: 800 2: 800 3: 800
    4: 800 5: 800 6: 800
Graphics:
  Device-1: Intel CoffeeLake-S GT2 [UHD Graphics 630] driver: i915 v: kernel
  Device-2: NVIDIA GM107GL [Quadro K1200] driver: nouveau v: kernel
  Display: x11 server: X.Org v: 1.21.1.3 driver: X: loaded: modesetting
    unloaded: fbdev,vesa gpu: nouveau resolution: 1: 1920x1080~60Hz
    2: 1080x1920~60Hz 3: 1080x1920~60Hz 4: 1920x1080~60Hz
  OpenGL: renderer: NV117 v: 4.3 Mesa 22.0.5
Audio:
  Device-1: Intel Cannon Lake PCH cAVS driver: snd_hda_intel
  Device-2: NVIDIA GM107 High Definition Audio [GeForce 940MX]
    driver: snd_hda_intel
  Sound Server-1: ALSA v: k5.15.0-56-generic running: yes
  Sound Server-2: PulseAudio v: 15.99.1 running: yes
  Sound Server-3: PipeWire v: 0.3.48 running: yes
Network:
  Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet
    driver: r8169
  IF: enp4s0 state: up speed: 1000 Mbps duplex: full mac: a8:5e:45:53:72:dd
  IF-ID-1: br0 state: up speed: 1000 Mbps duplex: unknown
    mac: 86:cf:5b:e2:98:aa
  IF-ID-2: br2 state: down mac: 16:e4:81:03:54:b3
  IF-ID-3: br257 state: down mac: d6:38:d7:30:2f:c5
  IF-ID-4: br258 state: down mac: ae:87:82:f8:88:d7
  IF-ID-5: br259 state: down mac: 7a:29:2d:9e:5d:ce
  IF-ID-6: br260 state: down mac: da:0b:81:1d:66:c2
  IF-ID-7: br261 state: down mac: 16:8f:e2:9c:de:43
  IF-ID-8: br262 state: down mac: fa:de:05:71:7a:2b
  IF-ID-9: virbr0 state: down mac: 52:54:00:83:4d:49
  IF-ID-10: vlan2 state: up speed: 1000 Mbps duplex: full
    mac: a8:5e:45:53:72:dd
  IF-ID-11: vlan257 state: up speed: 1000 Mbps duplex: full
    mac: a8:5e:45:53:72:dd
  IF-ID-12: vlan258 state: up speed: 1000 Mbps duplex: full
    mac: a8:5e:45:53:72:dd
  IF-ID-13: vlan259 state: up speed: 1000 Mbps duplex: full
    mac: a8:5e:45:53:72:dd
  IF-ID-14: vlan260 state: up speed: 1000 Mbps duplex: full
    mac: a8:5e:45:53:72:dd
  IF-ID-15: vlan261 state: up speed: 1000 Mbps duplex: full
    mac: a8:5e:45:53:72:dd
  IF-ID-16: vlan262 state: up speed: 1000 Mbps duplex: full
    mac: a8:5e:45:53:72:dd
  IF-ID-17: vnet13 state: unknown speed: 10 Mbps duplex: full
    mac: fe:54:00:1c:29:2c
  IF-ID-18: vnet7 state: unknown speed: 10 Mbps duplex: full
    mac: fe:54:00:ab:cb:b0
Drives:
  Local Storage: total: 5.92 TiB used: 3.16 TiB (53.3%)
  ID-1: /dev/nvme0n1 vendor: Samsung model: SSD 970 EVO Plus 1TB
    size: 931.51 GiB
  ID-2: /dev/nvme1n1 vendor: Samsung model: SSD 970 EVO Plus 1TB
    size: 931.51 GiB
  ID-3: /dev/sda vendor: Samsung model: SSD 860 PRO 512GB size: 476.94 GiB
  ID-4: /dev/sdb vendor: Western Digital model: WD4003FZEX-00Z4SA0
    size: 3.64 TiB
Partition:
  ID-1: / size: 447.02 GiB used: 82.6 GiB (18.5%) fs: btrfs dev: /dev/sda3
  ID-2: /boot/efi size: 484 MiB used: 5.2 MiB (1.1%) fs: vfat
    dev: /dev/sda1
Swap:
  ID-1: swap-1 type: partition size: 29.8 GiB used: 17.2 MiB (0.1%)
    dev: /dev/sda2
Sensors:
  System Temperatures: cpu: 27.8 C mobo: N/A gpu: nouveau temp: 47.0 C
  Fan Speeds (RPM): N/A gpu: nouveau fan: 3840
Info:
  Processes: 371 Uptime: 1d 4h 19m Memory: 31.2 GiB used: 10.24 GiB (32.8%)
  Shell: Bash inxi: 3.3.13

Grub 命令行

GRUB_CMDLINE_LINUX="ipv6.disable=1"
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash intel_iommu=on i915.enable_gvt=1"

虚拟机配置示例(“mesa” libvirt 配置)

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
  <name>win10</name>
...
  <devices>
...
   <graphics type='spice'>
      <listen type='none'/>
      <gl enable='yes' rendernode='/dev/dri/by-path/pci-0000:00:02.0-render'/>
    </graphics>
...
    <video>
      <model type='none'/>
    </video>
    <hostdev mode='subsystem' type='mdev' managed='no' model='vfio-pci' display='on'>
      <source>
        <address uuid='f056b522-1c29-4efe-8032-41affa070017'/>
      </source>
      <address type='pci' domain='0x0000' bus='0x06' slot='0x00' 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>
...

Libvirt 钩子

使用以下 libvirt 钩子在 VM 启动/关闭时创建/销毁虚拟 GPU:

#!/bin/bash
#
# /etc/libvirt/hooks/qemu
# Automatically creates and destroys virtual GPUs on domain startup and shutdown
# Note: Libvirt will not pick up this file until restarted - reboot your system after creation.
#
GVT_PCI="0000:00:02.0"
MDEV_TYPE="i915-GVTg_V5_4"
fDevType="/sys/bus/pci/devices/$GVT_PCI/mdev_supported_types/$MDEV_TYPE"
domain=$1
cmd1=$2
cmd2=$3

function vGpuConfig {
    if [ -e "$fDevType/create" ]; then
        if [ "$cmd1" = "prepare" ] && [ "$cmd2" = "begin" ]; then
            if [ ! -e "$fDev" ]; then
                      echo "Starting GPU $GVT_GUID..."
                echo "$GVT_GUID" > "$fDevType/create"
            else
                echo "FAIL!! Device already running: $fDev"
            fi
        elif [ "$cmd1" = "release" ] && [ "$cmd2" = "end" ]; then
            if [ -e "$fDev/remove" ]; then
                echo "Stopping GPU $GVT_GUID..."
                echo 1 > "$fDev/remove"
            else
                echo "FAIL!! Device is not running: $fDev"
            fi
        fi
    else
        echo "FAIL!! Device type does not exist: $fDevType"
    fi
}

if [ $# -ge 3 ]; then
    if [ "$domain" = "win10" ]; then
        GVT_GUID="cb33ec6d-ad44-4702-b80f-c176f56afea1"
        fDev="/sys/bus/pci/devices/$GVT_PCI/$GVT_GUID"
        vGpuConfig
    elif [ "$domain" = "Win2k19" ]; then
        GVT_GUID="f056b522-1c29-4efe-8032-41affa070017"
        fDev="/sys/bus/pci/devices/$GVT_PCI/$GVT_GUID"
        vGpuConfig
    fi
else
          echo "usage: $0 <domain> prepare begin | release end"
fi

来宾扩展 在此处输入图片描述

概括:

尽管英特尔已经继续前进(后代将使用 SR-IOV 实现 GPU 直通),但这仍然是一项非常酷的技术。

我想发布如何实现 GVT-g 的过程。但是 virt-manager 无法工作(以及运行 lightdm 时 X 中出现 SIGABRT 的小问题)阻碍了我。如果能得到任何帮助,我将不胜感激。

相关内容