mirror of https://gitlab.com/YuriAlek/vfio
libvirt update
parent
469e810e81
commit
0d25afdeb9
@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
## QEMU hooks. How to use.
|
||||
# chmod +x qemu
|
||||
# sudo ln -sf "$(pwd)/qemu" /etc/libvirt/hooks/qemu
|
||||
|
||||
## Virsh devices.
|
||||
VIRSH_GPU="pci_0000_06_00_0"
|
||||
VIRSH_GPU_AUDIO="pci_0000_06_00_1"
|
||||
|
||||
## Log file. Only tells if the GPU was un/binded correctly.
|
||||
LOG=/tmp/qemu_log.txt
|
||||
|
||||
if [[ "$1" == "GPU"* ]]; then
|
||||
if [ "$2" == "prepare" ]; then
|
||||
|
||||
## Kill the Window Manager. Yours may vary.
|
||||
killall i3 > /dev/null 2>&1
|
||||
sleep 5 ## Just in case
|
||||
|
||||
## Remove the framebuffer and console
|
||||
echo 0 > /sys/class/vtconsole/vtcon0/bind
|
||||
echo 0 > /sys/class/vtconsole/vtcon1/bind
|
||||
echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
|
||||
|
||||
## Detach the GPU and USB
|
||||
virsh nodedev-detach "$VIRSH_GPU" >> "$LOG" 2>&1
|
||||
virsh nodedev-detach "$VIRSH_GPU_AUDIO" >> "$LOG" 2>&1
|
||||
|
||||
## Load vfio.
|
||||
modprobe vfio-pci
|
||||
|
||||
## Start the network.
|
||||
if [[ $(virsh net-list --all | grep "virt1" | awk '{print $2}') != "active" ]]; then
|
||||
virsh net-start virt1
|
||||
fi
|
||||
|
||||
fi
|
||||
if [ "$2" == "release" ]; then
|
||||
|
||||
## Stop the network.
|
||||
if [ "$(virsh net-list --all | grep "virt1" | awk '{print $2}')" == "active" ]; then
|
||||
## "destroy" actually stops it.
|
||||
virsh net-destroy virt1
|
||||
fi
|
||||
|
||||
## Unload vfio module.
|
||||
modprobe -r vfio-pci
|
||||
modprobe -r vfio_iommu_type1
|
||||
modprobe -r vfio
|
||||
|
||||
## Reattach the GPU and USB.
|
||||
virsh nodedev-reattach "$VIRSH_GPU_AUDIO" >> "$LOG" 2>&1
|
||||
virsh nodedev-reattach "$VIRSH_GPU" >> "$LOG" 2>&1
|
||||
|
||||
## Reload the framebuffer and console.
|
||||
echo 1 > /sys/class/vtconsole/vtcon0/bind
|
||||
nvidia-xconfig --query-gpu-info > /dev/null 2>&1
|
||||
echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
|
||||
|
||||
fi
|
||||
fi
|
@ -0,0 +1,16 @@
|
||||
<network>
|
||||
<name>virt1</name>
|
||||
<uuid>c387430a-d3f9-4859-a9bd-3a25987de672</uuid>
|
||||
<forward dev='enp3s0' mode='nat'>
|
||||
<interface dev='enp3s0'/>
|
||||
</forward>
|
||||
<bridge name='virbr1' stp='on' delay='0'/>
|
||||
<mac address='52:54:00:c8:36:d2'/>
|
||||
<domain name='virt1'/>
|
||||
<ip address='192.168.100.1' netmask='255.255.255.0'>
|
||||
<dhcp>
|
||||
<range start='192.168.100.128' end='192.168.100.254'/>
|
||||
</dhcp>
|
||||
</ip>
|
||||
</network>
|
||||
|
@ -1,83 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
## IOMMU groups
|
||||
IOMMU_GPU=06:00.0
|
||||
IOMMU_GPU_AUDIO=06:00.1
|
||||
IOMMU_USB=07:00.3
|
||||
IOMMU_AUDIO=08:00.3
|
||||
|
||||
## Virsh devices
|
||||
VIRSH_GPU=pci_0000_06_00_0
|
||||
VIRSH_GPU_AUDIO=pci_0000_06_00_1
|
||||
VIRSH_USB=pci_0000_07_00_3
|
||||
VIRSH_AUDIO=pci_0000_08_00_3
|
||||
|
||||
## PCI BUS ID
|
||||
videoid="10de 1184"
|
||||
audioid="10de 0e0a"
|
||||
videobusid="0000:${IOMMU_GPU}"
|
||||
audiobusid="0000:${IOMMU_GPU_AUDIO}"
|
||||
|
||||
## QEMU options
|
||||
RAM=12G
|
||||
|
||||
## Ulimit
|
||||
ULIMIT=$(ulimit -a | grep "max locked memory" | awk '{print $6}')
|
||||
ULIMIT_TARGET=$(( $(echo $RAM | tr -d 'G') * 1048576 + 100000 ))
|
||||
|
||||
## Log file
|
||||
LOG=/tmp/passthrough.log
|
||||
|
||||
## Virtual interface name
|
||||
VIRTNAME=virt1
|
||||
|
||||
if [[ $1 == "win10" ]]; then
|
||||
if [[ $2 == "prepare" ]]; then
|
||||
## Memory lock limit
|
||||
[[ $ULIMIT != $ULIMIT_TARGET ]] && ulimit -l $ULIMIT_TAGET
|
||||
|
||||
## Kill the Window Manager
|
||||
killall i3 > /dev/null 2>&1
|
||||
sleep 5
|
||||
|
||||
## Remove the framebuffer and console
|
||||
echo 0 > /sys/class/vtconsole/vtcon0/bind
|
||||
echo 0 > /sys/class/vtconsole/vtcon1/bind
|
||||
echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
|
||||
|
||||
## Detach the GPU and USB
|
||||
virsh nodedev-detach $VIRSH_GPU >> $LOG 2>&1
|
||||
virsh nodedev-detach $VIRSH_GPU_AUDIO >> $LOG 2>&1
|
||||
virsh nodedev-detach $VIRSH_USB >> $LOG 2>&1
|
||||
|
||||
## Load vfio
|
||||
modprobe vfio-pci
|
||||
|
||||
## Start the network
|
||||
if [[ $(virsh net-list --all | grep $VIRTNAME | awk '{print $2}') != "active" ]]; then
|
||||
virsh net-start $VIRTNAME
|
||||
fi
|
||||
|
||||
fi
|
||||
if [[ $2 == 'release' ]]; then
|
||||
|
||||
## Unload vfio module
|
||||
modprobe -r vfio-pci
|
||||
modprobe -r vfio_iommu_type1
|
||||
modprobe -r vfio
|
||||
|
||||
## Reattach the GPU and USB
|
||||
virsh nodedev-reattach $VIRSH_USB >> $LOG 2>&1
|
||||
virsh nodedev-reattach $VIRSH_GPU_AUDIO >> $LOG 2>&1
|
||||
virsh nodedev-reattach $VIRSH_GPU >> $LOG 2>&1
|
||||
|
||||
## Reload the framebuffer and console
|
||||
echo 1 > /sys/class/vtconsole/vtcon0/bind
|
||||
nvidia-xconfig --query-gpu-info > /dev/null 2>&1
|
||||
echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind
|
||||
|
||||
## Restore ulimit
|
||||
ulimit -l $ULIMIT
|
||||
|
||||
fi
|
||||
fi
|
@ -1,13 +0,0 @@
|
||||
<network ipv6='yes'>
|
||||
<name>virt1</name>
|
||||
<uuid>046a1f8f-e46c-4517-8f8e-6c793a8b57a2</uuid>
|
||||
<bridge name='virbr1' stp='on' delay='0'/>
|
||||
<mac address='52:54:00:db:9d:9b'/>
|
||||
<domain name='virt1'/>
|
||||
<ip address='10.10.10.1' netmask='255.255.255.0'>
|
||||
<dhcp>
|
||||
<range start='10.10.10.128' end='10.10.10.254'/>
|
||||
</dhcp>
|
||||
</ip>
|
||||
</network>
|
||||
|
@ -1,141 +0,0 @@
|
||||
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
|
||||
<name>win10</name>
|
||||
<uuid>49a79759-dfa2-4670-a6f6-eab2d6794abd</uuid>
|
||||
<memory unit='KiB'>12582910</memory>
|
||||
<currentMemory unit='KiB'>12582910</currentMemory>
|
||||
<vcpu placement='static' cpuset='0-12'>12</vcpu>
|
||||
<iothreads>1</iothreads>
|
||||
<cputune>
|
||||
<vcpupin vcpu='0' cpuset='0'/>
|
||||
<vcpupin vcpu='1' cpuset='1'/>
|
||||
<vcpupin vcpu='2' cpuset='2'/>
|
||||
<vcpupin vcpu='3' cpuset='3'/>
|
||||
<vcpupin vcpu='4' cpuset='4'/>
|
||||
<vcpupin vcpu='5' cpuset='5'/>
|
||||
<vcpupin vcpu='6' cpuset='6'/>
|
||||
<vcpupin vcpu='7' cpuset='7'/>
|
||||
<vcpupin vcpu='8' cpuset='8'/>
|
||||
<vcpupin vcpu='9' cpuset='9'/>
|
||||
<vcpupin vcpu='10' cpuset='10'/>
|
||||
<vcpupin vcpu='11' cpuset='11'/>
|
||||
<emulatorpin cpuset='0-6'/>
|
||||
<iothreadpin iothread='1' cpuset='0-1'/>
|
||||
</cputune>
|
||||
<numatune>
|
||||
<memory mode='strict' nodeset='0'/>
|
||||
</numatune>
|
||||
<os>
|
||||
<type arch='x86_64' machine='pc-i440fx-3.1'>hvm</type>
|
||||
<loader readonly='yes' type='pflash'>/usr/share/ovmf/x64/OVMF_CODE.fd</loader>
|
||||
<nvram>/var/lib/libvirt/qemu/nvram/win10_VARS.fd</nvram>
|
||||
<boot dev='cdrom'/>
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<features>
|
||||
<acpi/>
|
||||
<apic/>
|
||||
<hyperv>
|
||||
<relaxed state='on'/>
|
||||
<vapic state='on'/>
|
||||
<spinlocks state='on' retries='8191'/>
|
||||
<vendor_id state='on' value='123456789ab'/>
|
||||
</hyperv>
|
||||
<kvm>
|
||||
<hidden state='on'/>
|
||||
</kvm>
|
||||
<vmport state='off'/>
|
||||
</features>
|
||||
<cpu mode='host-model' check='partial'>
|
||||
<model fallback='allow'/>
|
||||
<topology sockets='1' cores='6' threads='2'/>
|
||||
<cache level='3' mode='emulate'/>
|
||||
<feature name='ht'/>
|
||||
<feature name='xsaves'/>
|
||||
<feature name='cmp_legacy'/>
|
||||
<feature name='extapic'/>
|
||||
<feature name='skinit'/>
|
||||
<feature name='wdt'/>
|
||||
<feature name='tce'/>
|
||||
<feature policy='require' name='topoext'/>
|
||||
<feature name='perfctr_core'/>
|
||||
<feature name='perfctr_nb'/>
|
||||
<feature name='invtsc'/>
|
||||
<numa>
|
||||
<cell id='0' cpus='0-11' memory='12582912' unit='KiB'/>
|
||||
</numa>
|
||||
</cpu>
|
||||
<clock offset='localtime'>
|
||||
<timer name='rtc' tickpolicy='catchup'/>
|
||||
<timer name='pit' tickpolicy='delay'/>
|
||||
<timer name='hpet' present='no'/>
|
||||
<timer name='hypervclock' present='yes'/>
|
||||
</clock>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>destroy</on_crash>
|
||||
<pm>
|
||||
<suspend-to-mem enabled='no'/>
|
||||
<suspend-to-disk enabled='no'/>
|
||||
</pm>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='raw'/>
|
||||
<source file='/windows.raw'/>
|
||||
<target dev='sda' bus='scsi'/>
|
||||
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
|
||||
</disk>
|
||||
<disk type='file' device='cdrom'>
|
||||
<driver name='qemu' type='raw'/>
|
||||
<source file='/windows10.iso'/>
|
||||
<target dev='hda' bus='ide'/>
|
||||
<readonly/>
|
||||
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
|
||||
</disk>
|
||||
<disk type='file' device='cdrom'>
|
||||
<driver name='qemu' type='raw'/>
|
||||
<source file='/virtio-win.iso'/>
|
||||
<target dev='hdb' bus='ide'/>
|
||||
<readonly/>
|
||||
<address type='drive' controller='0' bus='0' target='0' unit='1'/>
|
||||
</disk>
|
||||
<controller type='usb' index='0' model='qemu-xhci' ports='15'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
|
||||
</controller>
|
||||
<controller type='scsi' index='0' model='virtio-scsi'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
|
||||
</controller>
|
||||
<controller type='pci' index='0' model='pci-root'/>
|
||||
<controller type='ide' index='0'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
|
||||
</controller>
|
||||
<interface type='network'>
|
||||
<mac address='50:50:50:48:5a:fc'/>
|
||||
<source network='virt1'/>
|
||||
<model type='virtio'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
|
||||
</interface>
|
||||
<hostdev mode='subsystem' type='pci' managed='yes'>
|
||||
<source>
|
||||
<address domain='0x0000' bus='0x06' slot='0x00' function='0x0'/>
|
||||
</source>
|
||||
<rom file='/GK104_80.04.C3.00.0F-MODED.rom'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
|
||||
</hostdev>
|
||||
<hostdev mode='subsystem' type='pci' managed='yes'>
|
||||
<source>
|
||||
<address domain='0x0000' bus='0x06' slot='0x00' function='0x1'/>
|
||||
</source>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
|
||||
</hostdev>
|
||||
<hostdev mode='subsystem' type='pci' managed='yes'>
|
||||
<source>
|
||||
<address domain='0x0000' bus='0x07' slot='0x00' function='0x3'/>
|
||||
</source>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
|
||||
</hostdev>
|
||||
<memballoon model='virtio'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
|
||||
</memballoon>
|
||||
</devices>
|
||||
</domain>
|
Loading…
Reference in New Issue