High Sierra, qemu-kvm with gpu passthrough

System spec:

  • Intel core i5 8600k on Gigabyte z370m d3h motherboard with Bios version f10
    (didn’t work with f4 bios)
  • Sapphire AMD RX 560 daughter-board

Bios setting:

  • CSM on with UEFI for pci
  • Integrated gfx on and set as primary output

Host Os:

  • Fedora 28 on mainline 4.20 rc3 linux
  • Monitor plugged to motherboard’s hdmi output.

Kernel parameters:

In /etc/default/grub

GRUB_CMDLINE_LINUX="nouveau.blacklist=1 resume=/dev/mapper/fedora-swap rd.lvm.lv=fedora/root rd.lvm.lv=fedora/swap rhgb intel_iommu=on iommu=pt quiet splash"

Do sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg for effect.
Check output of lspci -k after reboot: look for VGA Comatible controller.
Under that kernel driver in use line shoud have vfio instead of amdgpu.

Software:

  1. Install virt-manager with
    sudo dnf install virt-manager.

  2. Get Kholia’s OSX-KVM repo with
    git clone https://github.com/kholia/OSX-KVM

  3. cd into OSX-KVM.

  4. Create a qcow2 image of greater than 20 GB size with
    qemu-img create -f qcow2 hdd.qcow2 25000M
    inside this folder.

  5. Copy High Sierra installation iso as installer.iso into this folder.
    (Try websearching for how to create High Sierra installer iso with clover)

  6. Modify macOS-HS-libvert.xml according to your location of OVMF_CODE.fd, OVMF_VARS.fd, Clover.qcow2 (this 3 comes with repo) and hdd.qcow2 and installer.iso (these 2 you have created).

  7. Create a vm instance for virt-manager with this command
    virsh --connect qemu:///system define macOS-HS-libvirt.xml

  8. Open virt-manager and open this vm instance and try to run it.

  9. In my case access is denied for OVMF_CODE.fd. I fixed it by adding OVMF_CODE.fd as new storage in device in virt-manager. That fixes ownership and permission of this file. (Something’s wrong with my /etc/libvirt/qemu.conf file).

  10. Run the system and install os.

  11. After Installation select vm on virt-manager. Open it(don’t run). Select show virtual hardware detaills tab(which looks like a light bulb). Add new device. Select host pci device and choose your graphics card.

  12. Similarly add mouse and keyboard (you need extra pair) to vm.

  13. Remove first Display Spice then Video QXL entry from there.

  14. Plug a monitor into your graphic cards output ( You need 2 monitors, or if your monitor has 2 input you can plug into their and switch between them).

  15. Run vm.

Problems:

  1. EFI_FSB_frequency issue: VM is superfast (10 times). Try watching a video.
    Potential fix: Adding following to EFI/CLOVER/config.plist inside EFI partition of VM
<key>CPU</key>
<dict>
    <key>BusSpeedkHz</key>
    <string>1000000</string>
    <key>QEMU</key>
    <true/>
</dict>

I’ve failed to do so because it’s impossible to type.

  1. Second issue is vm can be run once, then host has to reboot for subsequent usage.
    Without host reboot there is either no display output or stuck at fruit logo.