sickcodes / Docker-OSX

Run macOS VM in a Docker! Run near native OSX-KVM in Docker! X11 Forwarding! CI/CD for OS X Security Research! Docker mac Containers.
https://hub.docker.com/r/sickcodes/docker-osx
GNU General Public License v3.0
36.08k stars 1.78k forks source link

GPU Acceleration & Passthrough #45

Open sickcodes opened 4 years ago

sickcodes commented 4 years ago

As per the virt-manager xml on king @kholia's repo:

https://github.com/kholia/OSX-KVM/blob/master/macOS-libvirt-Catalina.xml

I have an iGPU and it's difficult for me to test

    <!-- If you wanna passthrough GPU, make sure the gfx and audio are in the same bus (like 0x01) but different function (0x00 and 0x01)-->
    <!-- <hostdev mode='subsystem' type='pci' managed='yes'>
      <driver name='vfio'/>
      <source>
        <address domain='0x0000' bus='0x2d' slot='0x00' function='0x0'/>
      </source>
      <rom file='/mnt/disks/backups/BIOS/RX580/Ellesmere.rom'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0' multifunction='on'/>
    </hostdev>
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <driver name='vfio'/>
      <source>
        <address domain='0x0000' bus='0x2d' slot='0x00' function='0x1'/>
      </source>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x1'/>
    </hostdev> -->
    <!-- If you wanna passthrough onboard audio(like 30:00.4), make sure you put it in bus 0x00 and slot 0x0y(y is numeric), otherwise AppleALC won't recognized it -->
    <!-- <hostdev mode='subsystem' type='pci' managed='yes'>
      <driver name='vfio'/>
      <source>
        <address domain='0x0000' bus='0x30' slot='0x00' function='0x4'/>
      </source>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </hostdev> -->
aaronjensen commented 4 years ago

I'd be happy to try this out, but I'm not sure what to do with this xml... does this need to be converted to qemu command line parameters somehow and added to the dockerfile?

sickcodes commented 3 years ago

Yes, or use the Catalina xml file in the OSX-KVM directory and directly import it into virt-manager.

You will find the commented lines above in that file.

sickcodes commented 3 years ago

I have an Nvidia 1660 now, plus the integrated AMD graphics, so I might test this

AdamMomen commented 3 years ago

@sickcodes any updates on GPU passthrough. Thanks

sickcodes commented 3 years ago

I couldn't get it to work but OSX-KVM upstream is testing

sickcodes commented 3 years ago

Some additional GPU based docs here, thanks to @cephasara

https://github.com/sickcodes/Docker-OSX/blob/master/helm/INSTALL-QEMU-AND-GPU-IOMMU.md

clsx524 commented 2 years ago

I have used OSX-KVM with virt manager and my Big Sur can work with GPU (RX580) passthrough smoothly. So my system qcow2 file and custom OpenCore file should be fine. However when I tried it with docker, the screen can show the menu and I can pick the system from the list, but it will start to load the system and freeze/stuck after a few seconds. Does anyone know how to solve this?

This is the actual qemu command it executes

+ exec qemu-system-x86_64 
-m 16000 
-cpu max,kvm=on,hypervisor=on,vmx=on,vendor=GenuineIntel,vmware-cpuid-freq=on,+pcid,+popcnt,+xsave,rdtscp=on,+sse3,+sse4.2,+aes,+xsave,+avx,+xsaveopt,+xsavec,+xgetbv1,+avx2,+bmi2,+smep,+bmi1,+fma,+movbe,+invtsc 
-machine q35,accel=kvm,kernel-irqchip=on 
-smp 4,cores=4 
-usb 
-device usb-kbd 
-device usb-tablet 
-device 'isa-applesmc,osk=ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc' 
-drive if=pflash,format=raw,readonly=on,file=/home/arch/OSX-KVM/OVMF_CODE.fd 
-drive if=pflash,format=raw,file=/home/arch/OSX-KVM/OVMF_VARS-1024x768.fd 
-smbios type=2 
-audiodev alsa,id=hda -device ich9-intel-hda 
-device hda-duplex,audiodev=hda 
-device ich9-ahci,id=sata 
-drive id=OpenCoreBoot,if=none,snapshot=on,format=qcow2,file=/home/arch/OSX-KVM/OpenCore.qcow2 
-device ide-hd,bus=sata.2,drive=OpenCoreBoot 
-device ide-hd,bus=sata.3,drive=InstallMedia -drive id=InstallMedia,if=none,file=/home/arch/OSX-KVM/BaseSystem.img,format=qcow2 
-drive id=MacHDD,if=none,file=/home/arch/OSX-KVM/BigSur.qcow2,format=qcow2 
-device ide-hd,bus=sata.4,drive=MacHDD 
-netdev user,id=net0,hostfwd=tcp::10022-:22,hostfwd=tcp::5900-:5900, 
-device vmxnet3,netdev=net0,id=net0,mac=52:54:00:09:49:17 
-monitor stdio -nodefaults -enable-kvm -boot menu=on 
-vga none -nographic -display none 
-device pcie-root-port,id=pcie.1,bus=pcie.0,addr=1c.0,slot=1,chassis=5,multifunction=on 
-device vfio-pci,host=02:00.0,bus=pcie.1,addr=00.0 
-device vfio-pci,host=02:00.1,bus=pcie.1 
-device vfio-pci,host=04:00.0,bus=pcie.1 
-device vfio-pci,host=06:00.0,bus=pcie.1

and the docker run command

docker run -it --privileged \
 --device /dev/kvm --device /dev/vfio \
 -v "${PWD}/BigSur.qcow2:/home/arch/OSX-KVM/BigSur.qcow2" \
 -v "${PWD}/OpenCore.qcow2:/home/arch/OSX-KVM/OpenCore.qcow2" \
 -e "NOPICKER=false" \
 -e "RAM=16" \
 -e "BOOTDISK=/home/arch/OSX-KVM/OpenCore.qcow2" \
 -e "IMAGE_PATH=/home/arch/OSX-KVM/BigSur.qcow2" \
 docker-osx-custom

Or is it possible to start it with virt manager within docker?

sickcodes commented 2 years ago

It is possible, I had planned to add a virt-manager version and it will not be difficult to do so. I personally don't have a detached GPU to test with, only an iGPU, but we should be able to do it with Docker as well, just a matter of passing through the right permissions and devices.

ghost commented 2 years ago

I have a mobile 2060 and an Intel cpu with integrated GPU, is there something I can do to get better performance? I honestly don't have a good understanding of how it works that's why I ask where to look for.

pwltr commented 2 years ago

Haven't seen anyone mention it but as far as I know MacOS only supports AMD GPUs and Intel iGPUs.

This information comes from the OpenCore Install Guide which is for building "Hackintosh" systems. Full support table here: https://dortania.github.io/OpenCore-Install-Guide/macos-limits.html#gpu-support

I don't know anything about virtualization but I don't assume it would be different for this project?

aspauldingcode commented 9 months ago

It is possible, I had planned to add a virt-manager version and it will not be difficult to do so. I personally don't have a detached GPU to test with, only an iGPU, but we should be able to do it with Docker as well, just a matter of passing through the right permissions and devices.

Where are we on this?

Has GPU-Passthrough worked for anyone? Did you figure this out, add/test this yet?