utmapp / UTM

Virtual machines for iOS and macOS
https://getutm.app
Apache License 2.0
26.31k stars 1.31k forks source link

DriverKit PCI for PCI passthrough to Virtual Machines #4579

Open IComplainInComments opened 1 year ago

IComplainInComments commented 1 year ago

With macOS Ventura (And possibly on iOS as well) Apple is allowing the creation of PCI drivers using Driver-kit: https://developer.apple.com/documentation/pcidriverkit

From browsing over the API's and code references, it is looking like it would be possible to create a Driver-kit virtual Driver to allow a PCI pass-through of GPU's on thunderbolt connected devices (Like eGPUs).

This would allow Linux Virtual Machines to have near-NATIVE graphics performance as NVIDIA and AMD support ARM64 drivers for a lot of there cards already.

Now I personally have NEVER written a driver before, but I do know enough about them on how they work and where I could begin in writing one, but to integrate it into a virtual environment by say -- virtio, it stops there for me.

Eitherway. I think UTM has the possibility of beating VMware/Parallels to the punch, and making this possible.

Thoughts?

osy commented 1 year ago

This is possible in theory but apple needs to grant you specific entitlements for a specific vendor id to use driverkit in production.

IComplainInComments commented 1 year ago

This is possible in theory but apple needs to grant you specific entitlements for a specific vendor id to use driverkit in production.

In what way? As in we would need one per-device that would plug into our driver, or as in, one for the driver itself?

osy commented 1 year ago

As in apple won’t sign a wildcard driver

IComplainInComments commented 1 year ago

As in apple won’t sign a wildcard driver

I see... what if we would say, have members on eGPU.io dump their enclosures IDs, and do it that way? As the entitlement is just for the enclosure correct?

osy commented 1 year ago

You need apple to either sign a wildcard entitlement driver (currently not possible) or to register a vendor id with apple which is for the pci device (not enclosure).

IComplainInComments commented 1 year ago

You need apple to either sign a wildcard entitlement driver (currently not possible) or to register a vendor id with apple which is for the pci device (not enclosure).

Thats the thing though, those vendor ID's that are already native to macOS -- well AMD graphics cards that is. So wouldn't that mean that is already taken care of, AMD cards that is?

As ive plugged my eGPU into my Intel mac that supports macOS 13.0 and the AMD drivers were updated to support Metal 3, so its clear Apple hasnt given up on the drivers for AMD.

osy commented 1 year ago

Let's take a step back. There are built in drivers for PCI devices. You're proposing we write a shim driver for the same device such that the kernel will pick our shim and then we use that to tunnel the PCI traffic to QEMU. Now in theory this could work (although I'm not exactly sure how hard it would be). But in order for it to work outside a development environment, Apple has to sign this driver. And to do that you fill in a form with Apple with your vendor ID.

IComplainInComments commented 1 year ago

Let's take a step back. There are built in drivers for PCI devices. You're proposing we write a shim driver for the same device such that the kernel will pick our shim and then we use that to tunnel the PCI traffic to QEMU. Now in theory this could work (although I'm not exactly sure how hard it would be). But in order for it to work outside a development environment, Apple has to sign this driver. And to do that you fill in a form with Apple with your vendor ID.

I do understand that apple requires the entitlement, I completely do, I read the documentation on the entitlement.

What the purpose of this thread is, how can we use this. Its clear that people who use this software are fine with going outside of Apple's walled garden approach. So what if we did the same thing with the Mac, and made this driver (not so much as complete package), but an optional one that someone may compile and use it for their own? As in, keep it in the development enviorment, and let the user choose to either get it signed themselves with a developer account or run the driver in debug mode on Xcode then run UTM.

Its not a perfect solution, but it enables an AMAZING features that someone may use if they're willing to go through the steps. As I personally -- and considering how hardcore some of the eGPU.io users are, and the hackintosh community is, would be freaking fantastic!

osy commented 1 year ago

It would be a lot of time commitment for a feature that the majority of users won't be able to use. I welcome someone to try this and see how far they can get but it's unlikely I'll work on it.

IComplainInComments commented 1 year ago

It would be a lot of time commitment for a feature that the majority of users won't be able to use. I welcome someone to try this and see how far they can get but it's unlikely I'll work on it.

Then the next question would be, is there something similar like this. That we can use as a template for a PoC to see whether this would work. I cannot think of anything offhand, but maybe you do, or someone else chimes in, maybe we can start there.

osy commented 1 year ago

On Linux KVM there's PCI pass through. Look at the vhost code in QEMU. There is also support directly in the kernel.

artemreshetilo54 commented 1 year ago

any move?

IComplainInComments commented 1 year ago

any move?

Ive been looking into it more now the semester is over. I was waiting for the latest macOS beta documentation to come out to see if maybe apple would listen to my pleas that i've been submitting while i've been in class, looks like i've remained ignored (Love that, thanks Apple).

Ill be looking into this more now that I have free time.

On Linux KVM there's PCI pass through. Look at the vhost code in QEMU. There is also support directly in the kernel.

Im assuming youre talking about the XNU kernel yes?

jacksoneyton commented 8 months ago

I have an M2 macbook and a thunderbolt egpu enclosure. I would love to run a windowsVM that has direct access to the eGPU. If I can help in anyway please let me know. I have a BS:CS (software Development) and know some C# but I am not what I would consider fluent. I would still love to help, this would save me from buying another machine just for eGPU gaming and keep my desk free of more clutter than is necessary.