Thanks again, Quinn. As you suggested, I prototyped first. Here's what I found, good and bad. All testing is on macOS 27.2.1, with a Developer ID app on my paid team, not sandboxed.
What works
QEMU's usb-host takes a granted device with no root process. A USB flash drive reaches Windows at 5000 Mb/s, and Windows reads its files. A USB microphone reaches Windows at 480 Mb/s.
Grants are remembered. When AVM starts listening again, macOS hands over a device it granted before, right away.
A child process that was already running when a device was granted can open it. It doesn't need the XPC representation hand-off. I tested the hand-off too, and it works, but a non-sandboxed child doesn't need it.
Giving a device back works cleanly if QEMU lets go of it first. A flash drive goes back to Finder, and a microphone goes back to being a Mac sound device.
What surprised me
Grants are per app, not per listener. A listener for one device doesn't stop another device's grant from arriving.
Giving one device back means unregistering, so every other granted device leaves and comes back too. They're gone for about 1 to 1.6 seconds.
A device given back gets a new registry entry and a new sessionID. A grant keeps the same registry entry and sessionID.
The Virtual Machine Accessories panel behaves differently from one Command-Tab to the next. Sometimes it stays open, and sometimes it closes.
A stale user client, and a libusb fix
This one took a while to find. A QEMU that was running before a device was granted couldn't open it. QEMU uses libusb, and libusb makes a device interface (an IOUSBLib user client) when it first sees a device, then keeps it.
When the grant happens, accessoryaccessd takes exclusive ownership of the device. UsbExclusiveOwner changes to accessoryaccessd. The registry entry and sessionID stay the same, so no arrival or departure notification fires. But the user client made before the grant stops working. USBDeviceOpenSeize returns 0xe00002c0 (kIOReturnNoDevice).
I patched libusb so that when the open fails that way, it releases the interface, makes a fresh one from the same io_service, and tries once more. With that, a device granted while QEMU is running reaches Windows at full speed. I'll send the fix to libusb too.
Two questions
I filed FB25694587 about this.
Is it intended that user clients made before a grant stop working when the grant happens?
If so, is there a notification a process can watch for, so it knows to make a new one?
Thanks for pointing me down this path. It means AVM can send USB drives to Windows with no root helper.
Allison
Topic:
App & System Services
SubTopic:
Core OS
Tags: