-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
I’ve noticed that many modern USB devices, especially USB 3 SSDs using the UAS protocol, cannot be mounted properly on VMs in UTM.
I am not a developer, but I’ve been reading through libusb/libusb#1014 and since I know that UTM uses QEMU (and I think QEMU uses libusb for USB passthrough), I think I’ve understood that proper passthrough cannot work on macOS since user-space apps/commands cannot tell the kernel to release a drive it has already claimed.
Since I’m not a developer and I’m actually pretty ignorant about how this kind of handout could happen on macOS I’ve asked Gemini about ways to obtain passthrough proposing Parallels USB passthrough as an example and it came out with different solutions a developer could achieve this. The different options it listed were these:
- The use of IOUSBHostObjectInitOptionsDeviceCapture API in app but it would need an apple entitlement they don’t give to open source programs (talk about respect for the open source code they use in a commercial product…)
- a driver kit extension (but it would have to work as a bridge for libusb) like parallels do but I think there would be the same problem with entitlement
- A PrivilegedHelperTool that can be enabled with Touch ID
Since getting a dedicated USBDriverKit entitlement from Apple is notoriously difficult for open-source projects, the only feasible option UTM could use seems the PrivilegedHelperTool (installed via SMJobBless) thing. Therefore I would like to propose the implementation of an "Advanced USB Passthrough" mode, at least in the non-AppStore distributed program.
How I imagine this could work.
- UTM could include a small helper tool that runs with root privileges.
- When a user wants to pass through an USB device such as a SSD drive, UTM would ask this helper (via XPC) to perform the detach.
- Because the helper runs as root, it should be able to use the IOUSBHostObjectInitOptionsDeviceCapture API (or a root-level libusb call) to force macOS to let go of the device.
- Once the device is freed from the macOS kernel, it could be handed over to the QEMU process.
Maybe something similar is already in use and I couldn’t manage to find any info about it but if the proposal is feasible it might solve many issue with USB 3 devices using standards such as "UAS/SCSI" (which is personally currently one of the biggest hurdles keeping me from actually using UTM as a daily driver).
This to me looks also like the only way to avoid these uber-restrictive entitlement limits, since using a privileged helper instead of a System Extension or whatnot UTM wouldn't be dependent on Apple granting rare VM-specific entitlements that they usually reserve only for large corporations.
This could be a completely opt-in feature through UTM settings therefore limiting also security concerns.
I realize I might be oversimplifying the coding effort involved, but I wanted to share this insight as it seems to be the "missing link" that keeps UTM's USB support from matching commercial alternatives. Thank you for all the work you do on this amazing project!