r/VFIO Mar 21 '21

Meta Help people help you: put some effort in

637 Upvotes

TL;DR: Put some effort into your support requests. If you already feel like reading this post takes too much time, you probably shouldn't join our little VFIO cult because ho boy are you in for a ride.

Okay. We get it.

A popular youtuber made a video showing everyone they can run Valorant in a VM and lots of people want to jump on the bandwagon without first carefully considering the pros and cons of VM gaming, and without wanting to read all the documentation out there on the Arch wiki and other written resources. You're one of those people. That's okay.

You go ahead and start setting up a VM, replicating the precise steps of some other youtuber and at some point hit an issue that you don't know how to resolve because you don't understand all the moving parts of this system. Even this is okay.

But then you come in here and you write a support request that contains as much information as the following sentence: "I don't understand any of this. Help." This is not okay. Online support communities burn out on this type of thing and we're not a large community. And the odds of anyone actually helping you when you do this are slim to none.

So there's a few things you should probably do:

  1. Bite the bullet and start reading. I'm sorry, but even though KVM/Qemu/Libvirt has come a long way since I started using it, it's still far from a turnkey solution that "just works" on everyone's systems. If it doesn't work, and you don't understand the system you're setting up, the odds of getting it to run are slim to none.

    Youtube tutorial videos inevitably skip some steps because the person making the video hasn't hit a certain problem, has different hardware, whatever. Written resources are the thing you're going to need. This shouldn't be hard to accept; after all, you're asking for help on a text-based medium. If you cannot accept this, you probably should give up on running Windows with GPU passthrough in a VM.

  2. Think a bit about the following question: If you're not already a bit familiar with how Linux works, do you feel like learning that and setting up a pretty complex VM system on top of it at the same time? This will take time and effort. If you've never actually used Linux before, start by running it in a VM on Windows, or dual-boot for a while, maybe a few months. Get acquainted with it, so that you understand at a basic level e.g. the permission system with different users, the audio system, etc.

    You're going to need a basic understanding of this to troubleshoot. And most people won't have the patience to teach you while trying to help you get a VM up and running. Consider this a "You must be this tall to ride"-sign.

  3. When asking for help, answer three questions in your post:

    • What exactly did you do?
    • What was the exact result?
    • What did you expect to happen?

    For the first, you can always start with a description of steps you took, from start to finish. Don't point us to a video and expect us to watch it; for one thing, that takes time, for another, we have no way of knowing whether you've actually followed all the steps the way we think you might have. Also provide the command line you're starting qemu with, your libvirt XML, etc. The config, basically.

    For the second, don't say something "doesn't work". Describe where in the boot sequence of the VM things go awry. Libvirt and Qemu give exact errors; give us the errors, pasted verbatim. Get them from your system log, or from libvirt's error dialog, whatever. Be extensive in your description and don't expect us to fish for the information.

    For the third, this may seem silly ("I expected a working VM!") but you should be a bit more detailed in this. Make clear what goal you have, what particular problem you're trying to address. To understand why, consider this problem description: "I put a banana in my car's exhaust, and now my car won't start." To anyone reading this the answer is obviously "Yeah duh, that's what happens when you put a banana in your exhaust." But why did they put a banana in their exhaust? What did they want to achieve? We can remove the banana from the exhaust but then they're no closer to the actual goal they had.

I'm not saying "don't join us".

I'm saying to consider and accept that the technology you want to use isn't "mature for mainstream". You're consciously stepping out of the mainstream, and you'll simply need to put some effort in. The choice you're making commits you to spending time on getting your system to work, and learning how it works. If you can accept that, welcome! If not, however, you probably should stick to dual-booting.


r/VFIO 4d ago

Tutorial I created a step-by-step guide for GPU Passthrough on KVM/QEMU.

36 Upvotes

Hey r/VFIO,

(First post on reddit) I decided to consolidate everything I’ve learned into a single, structured, and tested guide. The result is this repository: https://github.com/urbanyl/GPU-Passthrough-for-KVM-QEMU-on-Linux

Why this repository exists:

The information on GPU passthrough is scattered everywhere. This project is my attempt to create a "one-stop-shop" that works reliably, whether you are on Debian, Arch, or Fedora.

Key Features:

  • Step-by-step walkthrough: Covers everything from BIOS settings to Windows driver installation.
  • Hardware & Software requirements: Clear tables explaining what you need (and what is recommended).
  • Troubleshooting section: Covers common issues like NVIDIA Error Code 43, GPU reset bugs, and bad IOMMU groups.
  • Helper scripts: Includes scripts to detect your GPU, check IOMMU groups, and verify VFIO binding.
  • Single-GPU Passthrough section: For those brave souls trying to do it with only one graphics card.

The guide includes:

  • BIOS Configuration (Intel VT-d / AMD-Vi)
  • Kernel Parameters & VFIO Configuration (with proper initramfs updates)
  • Optimized VM Configuration (Hyper-V enlightenments, CPU pinning, and huge pages)
  • Remote Display Setup (Sunshine/Moonlight, Looking Glass, and Parsec)
  • Performance Tuning (CPU governors, I/O schedulers, and isolation)

Feel free to open issues or contribute !

Github Repo: https://github.com/urbanyl/GPU-Passthrough-for-KVM-QEMU-on-Linux

Let me know if you have any questions or if there is something specific you would like me to add to the guide!


r/VFIO 6d ago

sudden guest GPU driver failure after CMOS battery fail...

5 Upvotes

hello fellow virtuosi,

I've been running a game in a debloated win10 VM with an AMD RX6600 via VFIO for 4 years now, with no issues, till yesterday when the MoBo battery died, and the EFI config got reset. I hurriedly reset all settings that I could remember back how I thought they were (SR-IOV on, ReBAR "clever access memory" on, >4G decoding on, primary==iGPU, iGPU multi-monitor on), and continued to boot. The VM is set to auto-start (as I have found this the most convenient/reliable) and it still starts: just windows no longer manages to start the GPU driver (! in dm, code 43). reinstalling/updating/factory-resetting the driver removes the ! temporarily, but the monitor doesn't detect and it doesn't actually work, or even turn the fans off (a sign the driver isn't actually managing the device). after restart, the ! is back.

I also loaded some other windows images with that GPU installed that had previously worked, and they all behave the same.

I also play some other games via proton, the GPU in question is working fine in Linux.

I have also been attempting to get the game in question to run in proton, and it did once... just once... I prefer using the VM anyway. having a separate mouse/kb is just less clunky when doing non-game things alongside.

host system is Ubuntu Unity (22.04 LTS base) with kernel upgraded to 6.14 mainline (for ntsync) a few months ago. there have been no updates of either the linux host or win10 in the meantime (windows update disabled in system policies since initial setup). looking-glass is installed since 4 years ago.

Intel 11400, 32Gb ddr4, asrock mobo.

anyone had any similar experiences? Ideas what might be broken and how to mend it? I'm at a loss.

from lspci -nnv:

03:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 23 [Radeon RX 6600/6600 XT/6600M] [1002:73ff] (rev c7) (prog-if 00 [VGA controller])

Subsystem: Micro-Star International Co., Ltd. \[MSI\] Navi 23 \[Radeon RX 6600/6600 XT/6600M\] \[1462:5022\]

Flags: bus master, fast devsel, latency 0, IRQ 157, IOMMU group 13

Memory at 6000000000 (64-bit, prefetchable) \[size=8G\]

Memory at 6200000000 (64-bit, prefetchable) \[size=256M\]

I/O ports at 3000 \[size=256\]

Memory at a0800000 (32-bit, non-prefetchable) \[size=1M\]

Expansion ROM at a0900000 \[disabled\] \[size=128K\]

Capabilities: <access denied>

Kernel driver in use: amdgpu

Kernel modules: amdgpu

03:00.1 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 21 HDMI Audio [Radeon RX 6800/6800 XT / 6900 XT] [1002:ab28]

Subsystem: Advanced Micro Devices, Inc. \[AMD/ATI\] Navi 21 HDMI Audio \[Radeon RX 6800/6800 XT / 6900 XT\] \[1002:ab28\]

Flags: bus master, fast devsel, latency 0, IRQ 155, IOMMU group 14

Memory at a0920000 (32-bit, non-prefetchable) \[size=16K\]

Capabilities: <access denied>

Kernel driver in use: snd_hda_intel

Kernel modules: snd_hda_intel

from virt-man: (xml of the pci pass-through)

<hostdev mode="subsystem" type="pci" managed="yes">

<source>

<address domain="0x0000" bus="0x03" slot="0x00" function="0x0"/>

</source>

<address type="pci" domain="0x0000" bus="0x03" slot="0x00" function="0x0"/>

</hostdev>

<hostdev mode="subsystem" type="pci" managed="yes">

<source>

<address domain="0x0000" bus="0x03" slot="0x00" function="0x1"/>

</source>

<address type="pci" domain="0x0000" bus="0x04" slot="0x00" function="0x0"/>

</hostdev>

I can provide logs, but they don't show any obvious difference between when it was working and now.


r/VFIO 6d ago

NIC issue on kvm vm

1 Upvotes

&#x200B;

Hi All,

I have a linux vm (appliance)and this was pushed from the veeam server(ovirt appliance for veeam backup).

It's successfully deployed and at the same time,the vm is not getting powered ON.

When I disable the VM nic,vm is powering ON.

When I enable the VM nic,vm goes to an unresponsive state.

VM nic is virtio only.

I deleted that nic and recreated a new nic with virtio but still the same issue persists.

Any suggestions to fix the issue?


r/VFIO 8d ago

Support Legion 5 Pro 16chach single gpu passthrough performance dip.

2 Upvotes

So I have set up single gpu passthrough on my Legion 5 Pro with Ryzen 7 5800H, 16Gb RAM and 3070 8 gb. My vm is windows 11 ltsc and I pass through pretty much everything, 14gb ram, 7 cores, audio. The vm itself is on its own nvme pcie ssd.

My problem is that the entire vm will periodically slow down when gaming. Like the vm loses priority and something else is going on in the cpu.

I isolate my cores during vm boot. I've tried 5c/10t, 6c/12t, 7c/14t and nothing fixes it. Last time I encountered this issue on my previous laptop the fix was to isolate and send in all but 1 core. Can't seem to understand whats happening this time.

XML


r/VFIO 8d ago

Tutorial Guide about Hardware Passthrough on openSUSE Tumbleweed (AMD + NVIDIA) + QoL. Need feedback

3 Upvotes

Hey.

I wrote long text about how I passthrough hardware + described some QoL features. It might be useful to someone. And I want to hear your opinion. Especially opinion of those who have been doing this for a long time, because I've never done this before.

It's really huge... I'm not asking you to read this entirely, though... I'd be very surprised if you did :D

Text: https://nzsh.cc/blog/en/windows-but-on-linux-hardware-passthrough/

If you want to view my XML: https://github.com/nozsh/vfio/blob/main/qemu-xml/full.xml

My hardware: https://nzsh.cc/bio/x/pc/

It's quite narrow path, openSUSE (tumbleweed), AMD + NVIDIA, iGPU + dGPU, and with perfect IOMMU groups out of box. That said, I'm pretty sure the scripts, XMLs, and QoL tweaks could still come in handy for a lot of people.

I don't have other hardware to test every scenario, so if you spot mistakes or have improvements (with sources/details), please let me know. I prefer to verify things hands‑on before adding them, so I might not include everything immediately, but all input is welcome and credited.

I'm also thinking about how to hide/mask QEMU and VirtIO devices (LG, Channel), as well as some processes - advice/information very welcome. And I'm probably not finished, I'll probably go even further.

PS: I know about YaST go down and will rewrite those points sometime in future.


r/VFIO 9d ago

Support can't run fall guys on vmware fusion

0 Upvotes

hi! total complete noob with all things computer, so ive been having a really hard time. is it just impossible?
im on a macOS Sequioa v15.7.5 using Windows 11 Home on vmware fusion.

i chased random forum threads and found that for the launch errors im seeing, either "HVCI is required to play" or "Code signing certificate validation timed out (2/2)"...i have to turn on something called memory integrity! and to turn on something called memory integrity, i have to go into settings and into core isolation. but oh no there's no memory integrity option in core isolation.

so to fix this i have to go into BIOS(???????) and turn on "Intel VT-x, AMD-V, or SVM Mode"...whatever that means. but those options arent here (in the pic i attached when i power on to firmware)!!! ive looked i swear.

at first i got a secure boot required message and i was able to fix that, but it was just error after error :(

ALSO ive been able to play peak with friends and house flippers successfully here!! ive been tweaking with fall guys

am i cooked? :( please lmk if you need any other details if theres a hope of this working


r/VFIO 10d ago

Support GPU passthrough allows DMA attack?

9 Upvotes

Hello, I am having trouble understanding when IOMMU is protecting the system against DMA attacks and other memory related issues.

My situation:
-In MSI bios "pre boot DMA protection" is enabled but "kernel DMA protection indicator" is disabled (if I enable it I always get "Firmware has requested this device have a 1:1 IOMMU mapping, rejecting configuring the device without a 1:1 mapping. Contact your platform vendor").
-dmesg reports: "amd_iommu=force_isolation", "iommu: Default domain type: Translated", "iommu: DMA domain TLB invalidation policy: strict mode".
-The GPU is in its own iommu group, no other devices are present in the same group as the GPU.
-I am passing the GPU to a VM using virtmanager.

I want the VM to be completely isolated from the host. I don't want the VM to gain access to system memory through the GPU or any other DMA attack.

My questions:

-Is it safe to have "kernel dma protection indicator" disabled in BIOS if "amd_iommu=force_isolation" kernel parameter is present?
-How do I know if the iommu is enforcing isolation?
-How do I know if a device is bypassing the iommu?
-Even if done correctly, are there still security concerns with GPU passthrough? (excluding 0 days, every software is not 100% secure, can't do much about that).
-When i enable "kernel DMA protection indicator" and i try to start the VM i get the error "Firmware has requested this device have a 1:1 IOMMU mapping, rejecting configuring the device without a 1:1 mapping. Contact your platform vendor", if I disable "kernel DMA protection indicator" in the BIOS, I don't get that error even with "amd_iommu=force_isolation", does that mean that the GPU is using 1:1 IOMMU mapping now? How do i verify?
-Is 1:1 IOMMU mapping safe?

Stupid question:
Is iommu=pt safe to enable in my grub config? How does it work? https://github.com/torvalds/linux/blob/20cf903a0c407cef19300e5c85a03c82593bde36/Documentation/admin-guide/kernel-parameters.txt#L2148 "Bypass the IOMMU for DMA", this doesn't sound safe.

Thanks for the help!


r/VFIO 11d ago

IOMMU groups on ASUS TUF Gaming B850-Plus WiFi

3 Upvotes

Hey, does anyone here have this board and could share its IOMMU groups?

I’m thinking of buying it for GPU passthrough. I’d use the Ryzen iGPU for the host and pass through a discrete GPU in the top x16 slot.

Mainly want to know if the GPU in the top PCIe slot has a clean IOMMU group. Thanks!


r/VFIO 11d ago

Dynamic RTX 5080 passthrough on Bazzite

9 Upvotes

I’m trying to dynamically pass my RTX 5080 through to a Windows VM while keeping Bazzite running on the iGPU from my 9800X3D.

The setup I want is:

- Normally, Bazzite uses the RTX 5080.
- When I start the VM, a libvirt hook detaches the 5080 from the NVIDIA driver and binds it to vfio-pci.
- The host stays running on the 9800X3D iGPU.
- When the VM shuts down, the 5080 gets rebound to the NVIDIA driver so Bazzite can use it again without rebooting.

Has anyone done something similar on Bazzite or another Fedora Atomic/immutable distro?

I’m mainly wondering how reliable it is to detach and reattach an RTX 50-series card, and whether Bazzite’s immutable filesystem causes any extra issues with libvirt hooks or VFIO scripts.


r/VFIO 12d ago

Has there been a kernel regression?

7 Upvotes

My 9060XT attaches and returns to the host completely fine on 6.18 but on 7.1.3 it wont reattach to the host. Anyone else also experience this, and has this been reported already?


r/VFIO 12d ago

Discussion Dynamic GPU handoff (nvidia idle → vfio gaming → back) on a single-GPU consolidation build

3 Upvotes

Thinking of building a single-machine consolidation machine with some spare parts and my current pc. Need to check on the one part I think decides whether it’ll all work or be a forever chore.

Hardware: i5-14400 (UHD 730 iGPU), RTX 5060 Ti 16GB, MSI PRO B760-P, Proxmox host.

iGPU drives the host + always-on LXCs (Immich/Jellyfin). The 5060 Ti is not bound to vfio at boot—I want the nvidia driver to hold it at idle so it drops to P8 and keeps idle power low. The dGPU then gets shared, one at a time, two ways:

•LLM LXC (Ollama, OpenwebUI, etc.) — borrows the card via device passthrough, no vfio involved.
• Windows gaming VM — full passthrough via a hookscript that does the swap.

So the loop I actually care about is:

nvidia (idle) → unbind → vfio → game → VM shutdown → unbind vfio → rebind nvidia → idle → AI LXC → release → idle

My main questions are:

  1. Is the post-stop rebind back to nvidia reliable in practice, or is that where it falls apart? Static vfio-at-boot is easy—it’s the round trip I’m worried about.
  2. Getting all the modules (nvidia, nvidia_uvm, nvidia_drm, nvidia_modeset) to release cleanly on every cycle — what actually holds a handle open? Persistence mode? Console framebuffer? How do you guarantee the card is free before the vfio bind?
  3. Anyone seeing reset-bug behavior specifically on the rebind (host lock/hang after VM shutdown) even when a one-shot passthrough works fine? 40-series and 50-series experiences both welcome.
  4. Making sure the AI LXC fully releases the card (no lingering VRAM/nvidia-uvm handle) before the gaming VM’s pre-start hook fires — do you script a verify/settle step, or does a clean container stop reliably free it?
  5. Does the nvidia driver actually let the card hit P8 at idle while loaded but unused, or did you need ASPM / C-state / persistence tuning to get real idle savings? Trying to confirm the power payoff is real before I build everything around it.

r/VFIO 13d ago

Crostini Debian 13 virtio-gpu detected but Mesa falls back to llvmpipe

4 Upvotes

Device:
ASUS Chromebook Plus CX34 i5-1335U

Linux container:
Debian 13 Trixie

lspci shows:

Virtio 1.0 GPU
Kernel driver: virtio-pci

dmesg:

[drm] features: +virgl +resource_blob

/dev/dri/renderD128 exists.

But:

glxinfo -B
Renderer: llvmpipe
Accelerated: no

vulkaninfo:

Failed to detect any valid GPUs

No virgl/gfxstream socket exists:

find /run -type s | grep -E "gpu|virgl|gfx"

returns nothing.

Is the ChromeOS host GPU service not exposing virgl/gfxstream, or is there a missing package/config?


r/VFIO 13d ago

GPU suddenly in the "wrong" iommu group

5 Upvotes

Hello, I have been passing my GPU to a VM using virtmanager for more than a year without any problems. Today I try to start the VM and i get the error:
"Error starting domain: internal error: QEMU unexpectedly closed the monitor (vm='VM3'): 2026-07-08 qemu-system-x86_64: warning: This family of AMD CPU doesn't support hyperthreading(2)

Please configure -smp options properly or try enabling topoext feature.

2026-07-08 qemu-system-x86_64: -device {"driver":"vfio-pci","host":"0000:01:00.0","id":"hostdev0","bus":"pci.4","addr":"0x0"}: vfio 0000:01:00.0: group 0 is not viable

Please ensure all devices within the iommu_group are bound to their vfio bus driver.".
Using "ls /sys/kernel/iommu_groups/0/devices/" i get
"0000:00:01.0 0000:00:01.1 0000:00:01.2 0000:01:00.0 0000:01:00.1 0000:01:00.2 0000:01:00.3 0000:02:00.0".
"0000:01:00.0 0000:01:00.1 0000:01:00.2 0000:01:00.3" this is the gpu so it is correct but the others are "Host bridge", "PCI bridge" and an SSD.

The groups are determined by the physical PCIe layout so I don't understand why now the GPU is grouped with other stuff since I haven't changed anything. I don't know much about this stuff so maybe it's just me being dumb lol.

EDIT: used an older kernel (from 6.8.0-134 to 6.8.0-124) and now my iommu groups are back, now I have 31 groups while before I had 6 and my GPU is correctly isolated. Works now but I need to get updates, I don't want to be stuck with the same kernel forever lol.

FIXED: there has been a kernel regression, https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2158934. Switch to the latest working kernel version (on Ubuntu it's version 6.8.0-124) and wait for a fix (on Ubuntu will be version 6.8.0-136). Thanks all for the help!


r/VFIO 13d ago

I cant recailm my gpu after vm

3 Upvotes

so i managed to pass my gpu to win10 vm but i cannot reclaim my gpu after vm stoped. modprobe nvidia returns modprobe: FATAL: Module nvidia not found in directory /lib/modules/7.0.11-76070011-generic. my host machine pop_os


r/VFIO 13d ago

Support Does any one have a more recent video or blog for single gpu passthroug on nixos

3 Upvotes

i've done it before on arch linux an i know the basics of what to do but am not sure how to get my hooks to work entirely since where the hooks need to be would be different on nixos


r/VFIO 16d ago

Another person getting No Signal.

0 Upvotes
bash
#!/usr/bin/env bash
set -euo pipefail

LOG="$PWD/boot-passthrough-$(date +%Y%m%d-%H%M%S).log"
exec > >(tee -a "$LOG") 2>&1
echo "Logging to: $LOG"

MY_OPTIONS="+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check"

ALLOCATED_RAM="16384"
CPU_SOCKETS="1"
CPU_CORES="4"
CPU_THREADS="8"

REPO_PATH="."
OVMF_DIR="."

GPU="0000:0d:00.0"
GPU_AUDIO="0000:0d:00.1"
GPU_ID="1002 73df"
GPU_AUDIO_ID="1002 ab28"

cleanup() {
  echo "Restoring GPU..."
  echo "$GPU" | sudo tee "/sys/bus/pci/devices/$GPU/driver/unbind" >/dev/null 2>&1 || true
  echo "$GPU_AUDIO" | sudo tee "/sys/bus/pci/devices/$GPU_AUDIO/driver/unbind" >/dev/null 2>&1 || true

  sudo modprobe amdgpu || true
  echo "$GPU" | sudo tee /sys/bus/pci/drivers/amdgpu/bind >/dev/null 2>&1 || true

  sudo systemctl start display-manager >/dev/null 2>&1 || true
}
trap cleanup EXIT

echo 1 | sudo tee /sys/module/kvm/parameters/ignore_msrs >/dev/null

echo "Stopping desktop..."
sudo systemctl stop display-manager
sleep 3

sudo modprobe vfio-pci

echo "Binding GPU to vfio-pci..."
echo vfio-pci | sudo tee "/sys/bus/pci/devices/$GPU/driver_override"
echo vfio-pci | sudo tee "/sys/bus/pci/devices/$GPU_AUDIO/driver_override"

echo "$GPU" | sudo tee "/sys/bus/pci/devices/$GPU/driver/unbind" || true
echo "$GPU_AUDIO" | sudo tee "/sys/bus/pci/devices/$GPU_AUDIO/driver/unbind" || true

sudo modprobe vfio-pci

echo "$GPU" | sudo tee /sys/bus/pci/drivers_probe
echo "$GPU_AUDIO" | sudo tee /sys/bus/pci/drivers_probe

lspci -nnk -s 0d:00.0
lspci -nnk -s 0d:00.1
ls -l /dev/vfio

sleep 2

args=(
  -enable-kvm
  -m "$ALLOCATED_RAM"
  -cpu Penryn,kvm=on,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,"$MY_OPTIONS"
  -machine q35
  -usb
  -device usb-kbd
  -device usb-tablet
  -device usb-mouse
  -smp "$CPU_THREADS",cores="$CPU_CORES",sockets="$CPU_SOCKETS"
  -device usb-ehci,id=ehci
  -vga virtio-vga

  -device vfio-pci,host=0d:00.0,multifunction=on,x-no-kvm-intx=on
  -device vfio-pci,host=0d:00.1

  -device isa-applesmc,osk="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"
  -drive if=pflash,format=raw,readonly=on,file="$REPO_PATH/$OVMF_DIR/OVMF_CODE_4M.fd"
  -drive if=pflash,format=raw,file="$REPO_PATH/$OVMF_DIR/OVMF_VARS-1024x768.fd"
  -smbios type=2

  -device ich9-intel-hda
  -device hda-duplex
  -device ich9-ahci,id=sata

  -drive id=OpenCoreBoot,if=none,snapshot=on,format=qcow2,file="$REPO_PATH/OpenCore/OpenCore.qcow2"
  -device ide-hd,bus=sata.2,drive=OpenCoreBoot

  #-drive id=InstallMedia,if=none,file="$REPO_PATH/#BaseSystem.img",format=raw
  #-device ide-hd,bus=sata.3,drive=InstallMedia

  -drive id=MacHDD,if=none,file="$REPO_PATH/mac_hdd_ng.img",format=qcow2
  -device ide-hd,bus=sata.4,drive=MacHDD

  -netdev user,id=net0
  -device vmxnet3,netdev=net0,id=net0,mac=52:54:00:c9:18:27

  -monitor stdio
  -vnc 0.0.0.0:1,password=off
  -k en-us
)

qemu-system-x86_64 "${args[@]}"

I have an AMD Radeon RX 6700 XT graphics card, and yes, I have NootRX. This is specifically for macOS 26 Tahoe

EDIT: Using this new XML

<domain type="kvm">

<name>macos-passthrough</name>
<memory unit="MiB">16384</memory>
<currentMemory unit="MiB">16384</currentMemory>
<vcpu placement="static">8</vcpu>
<cpu mode="custom" match="exact" check="none">
<model fallback="forbid">Penryn</model>
<vendor>GenuineIntel</vendor>
<feature policy="require" name="ssse3"/>
<feature policy="require" name="sse4.2"/>
<feature policy="require" name="popcnt"/>
<feature policy="require" name="avx"/>
<feature policy="require" name="aes"/>
<feature policy="require" name="xsave"/>
<feature policy="require" name="xsaveopt"/>
<feature policy="require" name="invtsc"/>
</cpu>
<os>
<type arch="x86_64" machine="q35">hvm</type>
<loader readonly="yes" type="pflash">/var/home/william/macos/OSX-KVM/OVMF_CODE_4M.fd</loader>
<nvram>/var/home/william/macos/OSX-KVM/OVMF_VARS-1024x768.fd</nvram>
<smbios mode="sysinfo"/>
</os>
<sysinfo type="smbios">
<system>
<entry name="manufacturer">Apple Inc.</entry>
<entry name="product">iMacPro1,1</entry>
</system>
</sysinfo>
<features>
<acpi/>
<apic/>
<vmport state="off"/>
</features>
<clock offset="utc">
<timer name="rtc" tickpolicy="catchup"/>
<timer name="pit" tickpolicy="delay"/>
<timer name="hpet" present="no"/>
</clock>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<controller type="pci" index="0" model="pcie-root"/>
<controller type="sata" index="0">
<address type="pci" bus="0x00" slot="0x1f" function="0x2"/>
</controller>
<controller type="usb" model="ehci">
<address type="pci" bus="0x00" slot="0x1d" function="0x0"/>
</controller>
<input type="keyboard" bus="usb"/>
<input type="mouse" bus="usb"/>
<input type="tablet" bus="usb"/>
<graphics type="vnc" port="5901" autoport="no" listen="0.0.0.0">
<listen type="address" address="0.0.0.0"/>
</graphics>
<video>
<model type="virtio"/>
</video>
<disk type="file" device="disk">
<driver name="qemu" type="qcow2" cache="writeback"/>
<source file="/var/home/william/macos/OSX-KVM/OpenCore/OpenCore.qcow2"/>
<target dev="sdc" bus="sata"/>
</disk>
<disk type="file" device="disk">
<driver name="qemu" type="qcow2" cache="writeback"/>
<source file="/var/home/william/macos/OSX-KVM/mac_hdd_ng.img"/>
<target dev="sde" bus="sata"/>
</disk>
<interface type="user">
<mac address="52:54:00:c9:18:27"/>
<model type="vmxnet3"/>
</interface>
<sound model="ich9">
<codec type="duplex"/>
</sound>
<hostdev mode="subsystem" type="pci" managed="yes">
<source>
<address domain="0x0000" bus="0x0d" slot="0x00" function="0x0"/>
</source>
<rom file="/var/home/william/macos/OSX-KVM/rx6700xt.rom"/>
<address type="pci" bus="0x01" slot="0x00" function="0x0" multifunction="on"/>
</hostdev>
<hostdev mode="subsystem" type="pci" managed="yes">
<source>
<address domain="0x0000" bus="0x0d" slot="0x00" function="0x1"/>
</source>
<address type="pci" bus="0x01" slot="0x00" function="0x1"/>
</hostdev>
<memballoon model="none"/>
</devices>
<qemu:commandline xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0">
<qemu:arg value="-device"/>
<qemu:arg value="isa-applesmc,osk=ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"/>
<qemu:arg value="-cpu"/>
<qemu:arg value="Penryn,kvm=on,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check"/>
<qemu:arg value="-global"/>
<qemu:arg value="kvm-pit.lost_tick_policy=discard"/>
</qemu:commandline>

</domain>

Hook:
#!/usr/bin/env bash

VM="$1"
ACTION="$2"

if [[ "$VM" != "macos-passthrough" ]]; then
 exit 0
fi

case "$ACTION" in
 prepare)
   systemctl stop display-manager

   modprobe vfio-pci

   echo vfio-pci > /sys/bus/pci/devices/0000:0d:00.0/driver_override
   echo vfio-pci > /sys/bus/pci/devices/0000:0d:00.1/driver_override

   echo 0000:0d:00.0 > /sys/bus/pci/devices/0000:0d:00.0/driver/unbind 2>/dev/null || true
   echo 0000:0d:00.1 > /sys/bus/pci/devices/0000:0d:00.1/driver/unbind 2>/dev/null || true

   echo 0000:0d:00.0 > /sys/bus/pci/drivers_probe
   echo 0000:0d:00.1 > /sys/bus/pci/drivers_probe
   ;;

 release)
   echo 0000:0d:00.0 > /sys/bus/pci/devices/0000:0d:00.0/driver/unbind 2>/dev/null || true
   echo 0000:0d:00.1 > /sys/bus/pci/devices/0000:0d:00.1/driver/unbind 2>/dev/null || true

   echo "" > /sys/bus/pci/devices/0000:0d:00.0/driver_override
   echo "" > /sys/bus/pci/devices/0000:0d:00.1/driver_override

   modprobe amdgpu
   echo 0000:0d:00.0 > /sys/bus/pci/drivers/amdgpu/bind 2>/dev/null || true

   systemctl start display-manager
   ;;
esac


r/VFIO 18d ago

Pop!_OS hanges after gpu passthrough

5 Upvotes

Well hello there i had this problem because i linked my single gpu to vm so after that the system hang when you boot and get to the Pop!_OS logo, it took me more then 2 Hours to figure out fix for it (I used the second fix)

First fix ( Easiest )

  1. Get your self USB 8GB atleast
  2. get pop os live flashed in it using another PC
  3. use it to boot then change the configuration of the vfio.config by reseting it
  4. then sudo update-initramfs -u
  5. then reboot : reboot -f
  6. Thats it !

SECOND FIX ( Hardest - Risky ) ( only if the First fix does not work or like me cant get USB and other pc )

  1. Reboot your pc / laptop
  2. Press and hold spacebar
  3. Pop os boot menu
  4. Choose Pop!_OS (current)
  5. Press ( e )
  6. There will be long line at the end Splash
  7. Go to the end of the line and make space
  8. Type init=/bin/bash
  9. The end should look like this splash init=/bin/bash
  10. Press enter
  11. Now there will be a black screen with this root@(none):/#
  12. Type this mount -o remount,rw /
  13. Then run this ls /etc/modprobe.d
  14. If you see files like: vfio.conf vfio-pci.conf
  15. Rename the file vfio.conf like this : mv /etc/modprobe.d/vfio.conf /etc/modprobe.d/vfio.conf.disabled
  16. Rebuild do this : update-initramfs -u
  17. Then reboot : reboot -f
  18. That it !

In many cases VM is not worth it just do DualBooting


r/VFIO 18d ago

9070 XT rebinding to amdgpu crashes the driver after vm shutdown.

5 Upvotes

[FIXED - START AND STOP HOOKS BELOW] Hi there lovely people.

I have been pulling my hair for the past 4 days. I am here asking for suggestions and a possible fix.

The vm (win 11) works and it runs as expected with the gpu passed through, installed amd gpu drivers on windows and all happy. Now, when i shutdown the vm, and try to rebinds the 9070 xt to the linux host to get my desktop back, it kind of rebinds to the amdgpu drivers but there is no display and nothing, the kernel messages that the amdgpu crashes. I cannot even reboot using the command line, I have to hard reset the pc with the powerbutton.

I do manual unbinding and rebinding of the gpu drivers and managed is off in the vm xml. I aslo echo the rebar to 8 tried with 3 as well but same results and also tried forcing d0 state... nothing helped.

Any suggestions?

Many thanks.

Update: I give up, dual booting it is... till this stupid damn bug gets fixed

Update 2: NEVEH GIV HUP..... the solution was a cheeky switch to the LATEST LTS kernel... in my case 6.18 I will provide my start and stop hooks below soon

start.sh:

start.shstop.sh:#!/usr/bin/env bash
set -x
GPU="0000:03:00.0"
AUD="0000:03:00.1"
echo "=== Stop display manager so amdgpu can release the card ==="
systemctl stop display-manager.service || true
sleep 2
echo "=== Unbind framebuffer consoles ==="
echo 0 > /sys/class/vtconsole/vtcon0/bind || true
echo 0 > /sys/class/vtconsole/vtcon1/bind || true
echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind || true
echo simple-framebuffer.0 > /sys/bus/platform/drivers/simple-framebuffer/unbind || true
sleep 1
echo "=== Unbind GPU from amdgpu, audio from snd_hda_intel ==="
echo "$GPU" > /sys/bus/pci/drivers/amdgpu/unbind || true
echo "$AUD" > /sys/bus/pci/drivers/snd_hda_intel/unbind || true
sleep 2
echo "=== Bind both to vfio-pci ==="
echo vfio-pci > /sys/bus/pci/devices/"$GPU"/driver_override
echo vfio-pci > /sys/bus/pci/devices/"$AUD"/driver_override
echo "$GPU" > /sys/bus/pci/drivers_probe
echo "$AUD" > /sys/bus/pci/drivers_probe
sleep 1
readlink /sys/bus/pci/devices/"$GPU"/driver || true
readlink /sys/bus/pci/devices/"$AUD"/driver || true

stop.sh:

#!/usr/bin/env bash
set -x
GPU="0000:03:00.0"
AUD="0000:03:00.1"
echo "=== Clear driver_override on both functions ==="
echo "" > /sys/bus/pci/devices/"$GPU"/driver_override
echo "" > /sys/bus/pci/devices/"$AUD"/driver_override
sleep 1
echo "=== Unbind both from vfio-pci ==="
echo "$GPU" > /sys/bus/pci/drivers/vfio-pci/unbind || true
echo "$AUD" > /sys/bus/pci/drivers/vfio-pci/unbind || true
sleep 2
echo "=== Bind GPU back to amdgpu ==="
modprobe amdgpu
echo "$GPU" > /sys/bus/pci/drivers/amdgpu/bind
sleep 2
echo "=== Bind audio back to snd_hda_intel ==="
modprobe snd_hda_intel
echo "$AUD" > /sys/bus/pci/drivers/snd_hda_intel/bind || true
sleep 1
echo "=== Rebind framebuffer consoles ==="
echo 1 > /sys/class/vtconsole/vtcon0/bind || true
echo 1 > /sys/class/vtconsole/vtcon1/bind || true
sleep 1
echo "=== Restart display manager ==="
systemctl start display-manager.service || true
echo "=== Status ==="
readlink /sys/bus/pci/devices/"$GPU"/driver || true
readlink /sys/bus/pci/devices/"$AUD"/driver || true
cat /sys/bus/pci/devices/"$GPU"/power_state || true

I had to pass both GPU and AUD to vm and also set managed to 'no' in the gpu/aud xml

I am on cachyos


r/VFIO 18d ago

Thinking of switching to Linux + Windows VM (single GPU) – need advice

8 Upvotes

Hi everyone,

I'm thinking about switching my laptop to Linux as my primary OS for software development and using a Windows VM with single-GPU passthrough only for Adobe Creative Cloud.

My main workflow would be:

  • Python development
  • Docker/containers
  • Virtual machines
  • AI/ML projects
  • General software development

Windows would only be used for Adobe apps like Premiere Pro, Photoshop, and Illustrator. Gaming is a nice bonus, but it's not my main priority.

Laptop specs:

  • Lenovo LOQ 15ARP9 (83JC0045IN / 83JC00EGIN)
  • AMD Ryzen 7 7435HS
  • NVIDIA RTX 4050 Laptop GPU (single GPU, no iGPU)
  • 24 GB DDR5 RAM

A few questions:

  • Has anyone successfully done single-GPU passthrough on this laptop or a similar Lenovo LOQ?
  • Does the RTX 4050 reset properly after shutting down the VM?
  • Are there any laptop-specific issues or firmware limitations I should know about?
  • If you've done something similar, which distro would you recommend (Fedora, EndeavourOS, Arch, etc.)?

Any advice or experiences would be greatly appreciated. Thanks!


r/VFIO 19d ago

Hello, Anyone in this community got apex legends working?

5 Upvotes

I'm asking cuz i (like most of you) i refuse to have windows on my pc bare-metal, Was wonderingg if its possible..


r/VFIO 19d ago

Pop!_OS hanges after gpu passthrough

Thumbnail
1 Upvotes

r/VFIO 19d ago

Discussion Elden Ring and Nightreign not longer launches in my VFIO VM (due to EAC)

6 Upvotes

I remembered that previously you can bypass EAC of both these two games by adding <smbios mode="host"/> to your Libvirt XML.

But it no longer works after Nightreign's update yesterday. Then I tried regular Elden Ring and it didn't work too.

If anyone can still play Elden Ring (and/or Nightreign) in a VFIO VM now, could you tell me what modification did you add to your Libvirt XML of the VFIO VM? Thanks!

(For now I can still play these games by dual booting, so not exactly a dealbreaker, but its still very annoying)


r/VFIO 20d ago

Discussion EAC and VM Gaming Tragedy

17 Upvotes

Man, I gotta say, I’m really bummed by the research I’ve uncovered the past week or so.

To make a long story short, I recently had the idea to make a “jack of all trades“ proxmox server, tasked with tackling all my home compute needs: 24/7 services like immich, jellyfin, and Tailscale, tinker with some local llms and ai, and of course, gaming. It was going to be a home server consolidating three machines into one lean, power-efficient beast—I was so pumped to build it and set it up.

However, after reading the countless posts about blocked vm gaming protocols by anti-cheat companies like EAC and BattleEye, its greatly diminished my desire to build my dream machine. I play multiple games that probably just wouldn‘t work in a vm, Elden Ring, Halo, Destiny, Arc Raiders.

I guess I’m just making this post to hear from others if there is any light at the end of the tunnel or something to hope for.


r/VFIO 20d ago

Black screen and then monitor no signal on single gpu passthrough. I tried dumping the vbios and removing the part of it that you need to remove but it didnt help

1 Upvotes
MY XML

<domain type="kvm">
  <name>win11</name>
  <uuid>60cd501b-b449-41a0-b8fa-25df375eb623</uuid>
  <metadata>
    <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
      <libosinfo:os id="http://microsoft.com/win/11"/>
    </libosinfo:libosinfo>
  </metadata>
  <memory unit="KiB">8388608</memory>
  <currentMemory unit="KiB">8388608</currentMemory>
  <vcpu placement="static">9</vcpu>
  <os firmware="efi">
    <type arch="x86_64" machine="pc-q35-11.0">hvm</type>
    <firmware>
      <feature enabled="no" name="enrolled-keys"/>
      <feature enabled="no" name="secure-boot"/>
    </firmware>
    <loader readonly="yes" type="pflash" format="raw">/usr/share/edk2/x64/OVMF_CODE.4m.fd</loader>
    <nvram template="/usr/share/edk2/x64/OVMF_VARS.4m.fd" templateFormat="raw" format="raw">/var/lib/libvirt/qemu/nvram/win11_VARS.fd</nvram>
    <boot dev="hd"/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <hyperv mode="custom">
      <relaxed state="on"/>
      <vapic state="on"/>
      <spinlocks state="on" retries="8191"/>
      <vpindex state="on"/>
      <runtime state="on"/>
      <synic state="on"/>
      <stimer state="on"/>
      <frequencies state="on"/>
      <tlbflush state="on"/>
      <ipi state="on"/>
      <evmcs state="on"/>
      <avic state="on"/>
    </hyperv>
    <vmport state="off"/>
    <smm state="on"/>
  </features>
  <cpu mode="host-passthrough" check="none" migratable="on"/>
  <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="cdrom">
      <driver name="qemu" type="raw"/>
      <source file="/home/user/Pulpit/Win11_25H2_Polish_x64_v2.iso"/>
      <target dev="sdb" bus="sata"/>
      <readonly/>
      <address type="drive" controller="0" bus="0" target="0" unit="1"/>
    </disk>
    <disk type="file" device="disk">
      <driver name="qemu" type="qcow2"/>
      <source file="/media/user/misc/libvirt/w11.qcow2"/>
      <target dev="sdc" bus="sata"/>
      <address type="drive" controller="0" bus="0" target="0" unit="2"/>
    </disk>
    <controller type="usb" index="0" model="qemu-xhci" ports="15">
      <address type="pci" domain="0x0000" bus="0x02" slot="0x00" function="0x0"/>
    </controller>
    <controller type="pci" index="0" model="pcie-root"/>
    <controller type="pci" index="1" model="pcie-root-port">
      <model name="pcie-root-port"/>
      <target chassis="1" port="0x10"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x0" multifunction="on"/>
    </controller>
    <controller type="pci" index="2" model="pcie-root-port">
      <model name="pcie-root-port"/>
      <target chassis="2" port="0x11"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x1"/>
    </controller>
    <controller type="pci" index="3" model="pcie-root-port">
      <model name="pcie-root-port"/>
      <target chassis="3" port="0x12"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x2"/>
    </controller>
    <controller type="pci" index="4" model="pcie-root-port">
      <model name="pcie-root-port"/>
      <target chassis="4" port="0x13"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x3"/>
    </controller>
    <controller type="pci" index="5" model="pcie-root-port">
      <model name="pcie-root-port"/>
      <target chassis="5" port="0x14"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x4"/>
    </controller>
    <controller type="pci" index="6" model="pcie-root-port">
      <model name="pcie-root-port"/>
      <target chassis="6" port="0x15"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x5"/>
    </controller>
    <controller type="pci" index="7" model="pcie-root-port">
      <model name="pcie-root-port"/>
      <target chassis="7" port="0x16"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x6"/>
    </controller>
    <controller type="pci" index="8" model="pcie-root-port">
      <model name="pcie-root-port"/>
      <target chassis="8" port="0x17"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x7"/>
    </controller>
    <controller type="pci" index="9" model="pcie-root-port">
      <model name="pcie-root-port"/>
      <target chassis="9" port="0x18"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x0" multifunction="on"/>
    </controller>
    <controller type="pci" index="10" model="pcie-root-port">
      <model name="pcie-root-port"/>
      <target chassis="10" port="0x19"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x1"/>
    </controller>
    <controller type="pci" index="11" model="pcie-root-port">
      <model name="pcie-root-port"/>
      <target chassis="11" port="0x1a"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x2"/>
    </controller>
    <controller type="pci" index="12" model="pcie-root-port">
      <model name="pcie-root-port"/>
      <target chassis="12" port="0x1b"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x3"/>
    </controller>
    <controller type="pci" index="13" model="pcie-root-port">
      <model name="pcie-root-port"/>
      <target chassis="13" port="0x1c"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x4"/>
    </controller>
    <controller type="pci" index="14" model="pcie-root-port">
      <model name="pcie-root-port"/>
      <target chassis="14" port="0x1d"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x03" function="0x5"/>
    </controller>
    <controller type="sata" index="0">
      <address type="pci" domain="0x0000" bus="0x00" slot="0x1f" function="0x2"/>
    </controller>
    <controller type="virtio-serial" index="0">
      <address type="pci" domain="0x0000" bus="0x03" slot="0x00" function="0x0"/>
    </controller>
    <interface type="network">
      <mac address="macadress"/>
      <source network="default"/>
      <model type="e1000e"/>
      <address type="pci" domain="0x0000" bus="0x01" slot="0x00" function="0x0"/>
    </interface>
    <serial type="pty">
      <target type="isa-serial" port="0">
        <model name="isa-serial"/>
      </target>
    </serial>
    <console type="pty">
      <target type="serial" port="0"/>
    </console>
    <input type="mouse" bus="ps2"/>
    <input type="keyboard" bus="ps2"/>
    <input type="tablet" bus="usb">
      <address type="usb" bus="0" port="1"/>
    </input>
    <tpm model="tpm-crb">
      <backend type="emulator" version="2.0">
        <profile name="default-v1"/>
      </backend>
    </tpm>
    <sound model="ich9">
      <address type="pci" domain="0x0000" bus="0x00" slot="0x1b" function="0x0"/>
    </sound>
    <audio id="1" type="none"/>
    <video>
      <model type="none"/>
    </video>
    <hostdev mode="subsystem" type="pci" managed="yes">
      <source>
        <address domain="0x0000" bus="0x01" slot="0x00" function="0x0"/>
      </source>
      <address type="pci" domain="0x0000" bus="0x05" slot="0x00" function="0x0"/>
    </hostdev>
    <hostdev mode="subsystem" type="pci" managed="yes">
      <source>
        <address domain="0x0000" bus="0x01" slot="0x00" function="0x1"/>
      </source>
      <address type="pci" domain="0x0000" bus="0x06" slot="0x00" function="0x0"/>
    </hostdev>
    <watchdog model="itco" action="reset"/>
    <memballoon model="virtio">
      <address type="pci" domain="0x0000" bus="0x04" slot="0x00" function="0x0"/>
    </memballoon>
  </devices>
</domain>

HOOK SCRIPTS

HOOK MANAGER
#!/usr/bin/env bash
#
# Author: SharkWipf
#
# Copy this file to /etc/libvirt/hooks, make sure it's called "qemu".
# After this file is installed, restart libvirt.
# From now on, you can easily add per-guest qemu hooks.
# Add your hooks in /etc/libvirt/hooks/qemu.d/vm_name/hook_name/state_name.
# For a list of available hooks, please refer to https://www.libvirt.org/hooks.html
#

GUEST_NAME="$1"
HOOK_NAME="$2"
STATE_NAME="$3"
MISC="${@:4}"

BASEDIR="$(dirname $0)"

HOOKPATH="$BASEDIR/qemu.d/$GUEST_NAME/$HOOK_NAME/$STATE_NAME"

STDIN=$(cat) # Buffer the entirety of stdin so we can pass it on to other scripts. Moderately bad idea, but if the Rust folks can do it so can I.

set -e # If a script exits with an error, we should as well.

# check if it's a non-empty executable file
if [ -f "$HOOKPATH" ] && [ -s "$HOOKPATH" ] && [ -x "$HOOKPATH" ]; then
    eval \"$HOOKPATH\" "$@" <<< "$STDIN" # Call the hook with all our arguments and a copy of stdin.
elif [ -d "$HOOKPATH" ]; then
    while read file; do
        # check for null string
        if [ ! -z "$file" ]; then
          eval \"$file\" "$@" <<< "$STDIN" # Call each hook with all our arguments and a copy of stdin.
        fi
    done <<< "$(find -L "$HOOKPATH" -maxdepth 1 -type f -executable -print;)"
fi

START.SH
#!/bin/bash
# Helpful to read output when debugging
set -x

# Load the config file with our environmental variables
source "/etc/libvirt/hooks/kvm.conf"

# Stop your display manager. If you're on kde it'll be sddm.service. Gnome users should use 'killall gdm-x-session' instead
systemctl stop lightdm.service

# Unbind VTconsoles
echo 0 > /sys/class/vtconsole/vtcon0/bind
# Some machines might have more than 1 virtual console. Add a line for each corresponding VTConsole
# echo 0 > /sys/class/vtconsole/vtcon1/bind

# Unbind EFI-Framebuffer
echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind

# Avoid a race condition by waiting a couple of seconds. This can be calibrated to be shorter or longer if required for your system
sleep 5

# Unload all Nvidia drivers
modprobe -r nvidia_drm
modprobe -r nvidia_modeset
modprobe -r drm_kms_helper
modprobe -r nvidia
modprobe -r i2c_nvidia_gpu
modprobe -r drm
modprobe -r nvidia_uvm

# Unbind the GPU from display driver
virsh nodedev-detach $VIRSH_GPU_VIDEO
virsh nodedev-detach $VIRSH_GPU_AUDIO


# Load VFIO kernel module
modprobe vfio
modprobe vfio_pci
modprobe vfio_iommu_type1

RELEASE.SH
#!/bin/bash
set -x

# Load the config file with our environmental variables
source "/etc/libvirt/hooks/kvm.conf"

# Unload VFIO-PCI Kernel Driver
modprobe -r vfio_pci
modprobe -r vfio_iommu_type1
modprobe -r vfio

# Re-Bind GPU to our display drivers
virsh nodedev-reattach $VIRSH_GPU_VIDEO
virsh nodedev-reattach $VIRSH_GPU_AUDIO

# Rebind VT consoles
echo 1 > /sys/class/vtconsole/vtcon0/bind
# echo 0 > /sys/class/vtconsole/vtcon1/bind

# Read our nvidia configuration when before starting our graphics
nvidia-xconfig --query-gpu-info > /dev/null 2>&1

# Re-Bind EFI-Framebuffer
echo "efi-framebuffer.0" > /sys/bus/platform/drivers/efi-framebuffer/bind

# Load nvidia drivers
modprobe nvidia_drm
modprobe nvidia_modeset
modprobe drm_kms_helper
modprobe nvidia
modprobe i2c_nvidia_gpu
modprobe drm
modprobe nvidia_uvm

# Restart Display Manager
systemctl start lightdm.service

KVM.CONF
VIRSH_GPU_VIDEO=pci_0000_01_00_0
VIRSH_GPU_AUDIO=pci_0000_01_00_1