How I set up Windows 7 (or Vista) GPU passthrough with libvirt/QEMU/KVM

Creating ultra fast virtual machines of old operating systems for fun and profit
User avatar
MattKC
Site Admin
Posts: 298
Joined: Mon Aug 22, 2022 1:05 am
Contact:

Re: How I set up Windows 7 (or Vista) GPU passthrough with libvirt/QEMU/KVM

Post by MattKC »

PortalPlayer wrote: Sat Jul 29, 2023 12:16 am Can anyone with an Nvidia GPU confirm if this guide works? I have one, and it didn't work for me, and it seems like that's probably why it also didn't work for gregory003.

EDIT: For more information, it just stays on a black screen, but I can hear audio via the passthrough audio.
UEFI virtual machines work for me, and I do have x-vga enabled, so it's probably something to do with Nvidia.
I can't confirm for sure right now, but just to be sure, have you set "kvm hidden" and "vendor id"? Those are necessary for NVIDIA cards to init on KVM, and I have a mini-guide here if you don't have those.
PortalPlayer
Posts: 2
Joined: Sat Jul 29, 2023 12:09 am

Re: How I set up Windows 7 (or Vista) GPU passthrough with libvirt/QEMU/KVM

Post by PortalPlayer »

MattKC wrote: Tue Aug 01, 2023 5:21 am I can't confirm for sure right now, but just to be sure, have you set "kvm hidden" and "vendor id"? Those are necessary for NVIDIA cards to init on KVM, and I have a mini-guide here if you don't have those.
I have both, but it still doesn't work. Still a black screen. I know the VM is working, since I hear audio, but that's pretty much it.

EDIT: Fixed it. I had to pass a patched ROM over. Despite not needing one on other VMs, I guess it was required here.

To get your GPU BIOS on Linux, you'll need to run this as root:

Code: Select all

echo 1 > /sys/bus/pci/devices/0000:01:00.0/rom
cat /sys/bus/pci/devices/0000:01:00.0/rom > path/to/dump/vbios.rom
echo 0 > /sys/bus/pci/devices/0000:01:00.0/rom
Replace 0000:01:00.0 with your PCI ID.

Note that the Linux method didn't work for me, but the Windows method did. Try the Windows method if this didn't work.

You can also extract it using GPU-Z on Windows.

Then, open it inside of a hex editor, and search for the string "VIDEO". Look a couple bytes back until you find the hex values "0x55 0xAA". Delete everything before those bytes, so the file starts with those two hex values. Don't worry, you're not going to break your GPU doing this, none of these changes are being made to it. Save the patched ROM to a location (I saved mine to /etc/nvidia.rom).

Finally, edit your VM XML, and add

Code: Select all

<rom file="/etc/nvidia.rom"/>
inside the hostdev for your GPU, replace "/etc/nvidia.rom" with the path you have your patched ROM in.

It should work now.

I'm not that good at explaining stuff, so if this doesn't actually work for you, then you can look up another guide on Google.
foxlet
Posts: 6
Joined: Wed Jul 19, 2023 7:34 pm

Re: How I set up Windows 7 (or Vista) GPU passthrough with libvirt/QEMU/KVM

Post by foxlet »

PortalPlayer wrote: Tue Aug 01, 2023 12:37 pm Note that the Linux method didn't work for me, but the Windows method did. Try the Windows method if this didn't work.
The Linux method won't work either way because (during boot) the kernel ends up modifying the shadow VBIOS that is resident in memory (to enable kernel modesetting, etc), and ultimately that's what you end up dumping from sysfs. It's a known "issue" that the NVIDIA Windows driver doesn't play well with the Linux-modified vbios, hence the fix being to dump it directly from the card's ROM using custom tools (either NVIDIA's own flash tool, or GPU-Z).

It's does help to use a copy of VBIOS by default though, you'll get a lot more consistency with QEMU's behavior.
Last edited by foxlet on Thu Aug 03, 2023 12:50 am, edited 1 time in total.
foxlet
Posts: 6
Joined: Wed Jul 19, 2023 7:34 pm

Re: How I set up Windows 7 (or Vista) GPU passthrough with libvirt/QEMU/KVM

Post by foxlet »

MattKC wrote: Sat Feb 04, 2023 9:12 pm At first, SeaBIOS + passthrough doesn't appear to work at all, which seemed to reinforce all the people who claimed it was problematic. My passed through GPU displayed no image whatsoever. Regardless, after all the frustration I had with UEFI, the handful of people saying SeaBIOS worked fine for them made me want to try it myself again.

It turns out there was one thing I was missing when trying to passthrough with SeaBIOS. You have to enable x-vga. For some reason I'd never come across this before, but this was the magic flag that made my GPU get picked up by the BIOS and subsequently Windows 7.
To add extra context, the reason why "x-vga" is needed is because it enables support for the Linux VGA arbitrator. Since legacy VGA calls (used to initialize the card) are still handled by writing to a fixed address (one decided back in the ISA days), the only way for the host and guest to share low-level VGA access is through the arbitrator. UEFI Class 3 hardware, on the other hand, use protected-mode drivers that don't require legacy VGA services 8-)
Last edited by foxlet on Wed Aug 16, 2023 4:50 am, edited 1 time in total.
foxlet
Posts: 6
Joined: Wed Jul 19, 2023 7:34 pm

Re: How I set up Windows 7 (or Vista) GPU passthrough with libvirt/QEMU/KVM

Post by foxlet »

Just for fun... I've managed to get early Vista previews (and Longhorn) working in QEMU through the right combination of hardware. This card is just about old enough that the NVIDIA drivers don't have any "Code 43" VM protection lol
LH-Desktop.png
User avatar
acidiclight
Posts: 88
Joined: Tue Dec 27, 2022 10:53 pm
Location: MeteoTech Premises
Contact:

Re: How I set up Windows 7 (or Vista) GPU passthrough with libvirt/QEMU/KVM

Post by acidiclight »

Hmmmm. I haven't read the full post yet since it's a lot of text but I'm very intrigued. I used to have a Windows 7 VM with full GPU passthrough working with an RTX 2060, but at the time I was also doing Single-GPU passthrough and needed to pass through USB controllers as well (so I could have keyboard/mouse support). Could never get it working though because my motherboard's chipset is too new for Win7 and thus it had no idea how to talk to any USB device I plugged in.

(I'm aware you can directly pass in USB devices instead of their controllers, and this is ultimately what I did, however it breaks hot-swap support which is fundamentally incompatible with things like external HDDs and thumbdrives.)

What I'm curious about now is how to get 8/8.1 working. Tried a few days ago, and it does natively support UEFI obviously....however I could NOT get nvidia drivers to install at all. I ended up giving up and upgrading the VM to Windows 10.
acidic light

I'm a blind game developer. I write code because it's fun.
User avatar
MattKC
Site Admin
Posts: 298
Joined: Mon Aug 22, 2022 1:05 am
Contact:

Re: How I set up Windows 7 (or Vista) GPU passthrough with libvirt/QEMU/KVM

Post by MattKC »

acidiclight wrote: Wed Aug 09, 2023 8:53 pm What I'm curious about now is how to get 8/8.1 working. Tried a few days ago, and it does natively support UEFI obviously....however I could NOT get nvidia drivers to install at all. I ended up giving up and upgrading the VM to Windows 10.
I managed to get Windows 8.1 working with no real trouble, though I was using an AMD GPU which are obviously much less hostile to KVM than NVIDIA GPUs are. If you didn't before, definitely try the "kvm hidden" and "vendor ID" patches, those tend to get NVIDIA cards cooperating, though someone here had to load a custom VBIOS to make it work.
Post Reply