Skip to content

Instantly share code, notes, and snippets.

@WMP
Last active March 29, 2024 08:50
Show Gist options
  • Save WMP/14df1f8c220f0315342906479fa1984d to your computer and use it in GitHub Desktop.
Save WMP/14df1f8c220f0315342906479fa1984d to your computer and use it in GitHub Desktop.

I run this on Intel CPU with integrated GPU with suppport for face recognision - i3-8100T . Your CPU need to support JPEG encoding: https://en.wikipedia.org/wiki/Intel_Quick_Sync_Video#Hardware_decoding_and_encoding . The best choice is a processor from the Coffee Lake series.

To run kernel with GPU virtualization you need to boot with params:

init_on_alloc=0 i915.enable_gvt=1 kvm.ignore_msrs=1 intel_iommu=on i915.enable_guc=0

Next, you need this hook to libvirt,

Variables:

GVT_PCI - REF: https://wiki.archlinux.org/title/Intel_GVT-g#Prerequisite

GVT_GUID - you must generate UID by command uuidgen.

MDEV_TYPE - REF: https://wiki.archlinux.org/title/Intel_GVT-g#Prerequisite

DOMAIN - libvirt DOMAIN which need to use virtual GPU.

cat /etc/libvirt/hooks/qemu 
#!/bin/bash
GVT_PCI='0000:00:02.0'
GVT_GUID='UUID_GENERATED'
MDEV_TYPE='i915-GVTg_V5_4'
DOMAIN='LIBVIRT_DOMAIN'
echo "\$1: $1 \$2: $2 \$3: $3 \$4: $4" >> /var/log/hook
if [ $1 == $DOMAIN ]; then
        if [ $# -ge 3 ]; then
                echo "3" >> /var/log/hook
            if [ $2 = "prepare" -a $3 = "begin" ]; then
                echo "add" >> /var/log/hook
                echo "$GVT_GUID" > "/sys/bus/pci/devices/$GVT_PCI/mdev_supported_types/$MDEV_TYPE/create"
            elif [ $2 = "release" -a $3 = "end" ]; then
                echo "end" >> /var/log/hook
                echo 1 > /sys/bus/pci/devices/$GVT_PCI/$GVT_GUID/remove
            fi
        fi
fi
echo "endscript" >> /var/log/hook

Then, you must generate redpill image, i use this: https://github.com/tossp/redpill-tool-chain/blob/master/README_EN.md Next, i use GUI virt-manager app to settings this VM, follow my screenshots. In few screenshots, i show you XML code, because this settings cannot set with GUI:

Screenshot_20220513_162720 Screenshot_20220513_162759 Screenshot_20220513_162831 Screenshot_20220513_162823 Screenshot_20220513_162839 Screenshot_20220513_162857 Screenshot_20220513_162905 Screenshot_20220513_162930 Screenshot_20220513_162943 Screenshot_20220513_162950 Screenshot_20220513_162955 Screenshot_20220513_163025 In this address field you must use variable GVT_GUID from hook script.

<hostdev mode="subsystem" type="mdev" managed="no" model="vfio-pci" display="off">
  <source>
    <address uuid="GVT_GUID"/>
  </source>
  <alias name="hostdev0"/>
  <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x0"/>
</hostdev>

Screenshot_20220513_163031

<video>
  <model type="cirrus" vram="16384" heads="1" primary="yes"/>
  <alias name="video0"/>
  <address type="pci" domain="0x0000" bus="0x00" slot="0x17" function="0x0"/>
</video>

Screenshot_20220513_163037

<video>
  <model type="virtio" heads="1"/>
  <alias name="video1"/>
  <address type="pci" domain="0x0000" bus="0x00" slot="0x06" function="0x0"/>
</video>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment