title: "QEMU/KVM NVIDIA GPU Passthrough with AMD CPU in Arch Linux"
date: 2023-11-09T08:30:00+00:00
---
This document catalogs my working setup for configuring an Arch Linux host OS to run a Windows 10 VM while passing through a virtualised NVIDIA GPU with a AMD CPU.
# Requirements:
Make sure you have 2 or more GPUs
CPU with multiple cores and virtualization support, this can be checked with
```sh
lscpu | grep "Virtualization"
```
If not, go to BIOS and enable it
# Prerequisites
```sh
# Download the required packages
yay -S qemu-full libvirt virt-manager virt-viewer bridge-utils
# Add yourself into groups so to solve permission issues
At VM Manager, you may not see there is QEMU/KVM - User session. For that, click File->Add Connection. Choose **QEMU/KVM user session** and press connect.
## Creating the VM
Click plus symbol on top left corner
1. Choose Local install media
2. Choose the ISO file
3. Pass **half** of your RAM and **half** of CPU cores
4. If you choose to use qcow2 format, more than 50 GB is recommended, of course you can use a dedicated drive
5. Make sure to click **Customize confirmation before install**
This will create a new window with your VM configuration, make sure chipset is Q35 and boot firmware is UEFI (it should be like `UEFI x86_64: /usr/share/edk2/x64/OVMF_CODE.secboot.4m.fd`). After that, go to CPU section, untick copy host CPU configuration, make sure Model is host-passthrough. Open Topology sub-menu and click manually set CPU topology, then set **1 socket**, **half of your cores**, **1 thread**.
options vfio-pci ids=(ids you copied, without bracket)
# Example config
options vfio-pci ids=10de:1f95,10de:10fa
# After that run
sudo mkinitcpio -p linux
reboot
```
5. Prove that GPU have been isolated
```sh
lspci -k | grep -E "vfio-pci|NVIDIA"
# You should see output if it is successful
```
6. Download virtio Windows drivers
Go to [virtio Github README](https://github.com/virtio-win/virtio-win-pkg-scripts#downloads) and download **Stable virtio-win ISO**
7. Add virtio drivers
At VM Config, go to CDROM and import virtio drivers by selecting the ISO file.
8. Add PCI Host Devices
At VM Config, click "Add Hardware" and select PCI Host Device then choose both NVIDIA devices. Then run the VM, first you might encounter some permissions issue(I did), for that try edit `/etc/libvirt/qemu.conf`, add these lines
Run the VM and navigate to the mounted CD-ROM and run **virtio-win-guest-tools** and go through the menu
Reboot
After reboot, go to [NVIDIA](https://www.nvidia.co.uk/Download/index.aspx) and download official GPU drivers
Then go to task manager to see if GPU exist
10. Optimise VM
Shutdown the VM, go to VM configuration. At Video, normally "Video QXL", change QXL to virtio. Then click Add Hardware, navigate to **Channel** and add **org.qemu.guest_agent**.
Run the VM and check the State is connected at the guest agent channel
11. If mouse don't work
Navigate to CD-ROM using keyboard and execute **virtio-win-gt-x64** using spacebar to navigate menu