Search code examples
macosmacos-catalinaiokitkernel-extensiondriverkit

Can a DriverKit System Extension match a hot pluggable device at boot time?


I have a DriverKit extension that can match a usb audio device just fine, but if I leave the device plugged in during a reboot, the AppleUSBAudio kernel extension matches it instead.

Unplugging and replugging load my dext instead.

Is this to be expected? Do all System Extensions have this shortcoming? How can I remedy this?


Solution

  • On macOS 11, if one of Apple's kexts matches your device, and their driver is in the "boot" or "sys" collections (see man kmutil), which it normally will be, then their driver will win matching against yours, even if yours has a higher probe score.

    On macOS 10.15, it should depend on whether or not their kext is in the prelinked kernel/kext cache. Third party kexts can also be included here so it's a little more democratic at least. Dexts can't be in the kextcache though.

    I've filed an Apple DTS TSI about this issue and they've acknowledged it as a bug. I strongly recommend you file it as a bug as well to increase chances of it being fixed.

    You should be able to work around it in a rather ugly way by explicitly force resetting the device from a user space daemon if your driver didn't manage to grab it. This will cause it to be re-enumerated by the USB subsystem, and for I/O Kit matching to be repeated, at which point your dext hopefully manages to win!