Skip to contentSkip to conversation

usb: dwc3: qcom: .shutdown = dwc3_qcom_remove double-remove hazard on guest unbind during shutdown

NOTE Felipe Infante de Castro 2 participants 4 messages Nov 29

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi Thinh, Greg, Bjorn, and Konrad,

While bringing up an out-of-tree USB4 host router driver on a Snapdragon X Elite laptop (Linux v7.3.6 arm64), we hit a reproducible (3/3) PID 1 kernel panic on reboot with a USB4 dock attached.

Scope note upfront: nothing in mainline Linux triggers this today. It requires a second driver that unbinds a bound dwc3-qcom device during system shutdown (which our USB4 host router driver initially did when tearing down its guest USB3 session). We have already fixed our USB4 driver to skip device_release_driver() during shutdown, so this is purely a hardening note for dwc3-qcom in case it is useful upstream.

What happened:

1. dwc3-qcom wires .shutdown = dwc3_qcom_remove.
2. When dwc3-qcom is re-bound as a guest after the USB4 router starts, it sits later on devices_kset, so device_shutdown() invokes dwc3_qcom_remove() on it *before* the USB4 router's .shutdown().
3. dwc3_qcom_remove() tears down dwc3_qcom and clears dev_set_drvdata(dev, NULL), while leaving dev->driver bound (normal for Linux ->shutdown()).
4. When the USB4 router's .shutdown() then called device_release_driver() on the guest dwc3-qcom device, driver core saw dev->driver still set and called dwc3_qcom_remove() a second time with NULL drvdata, faulting at fffffffffffffff0 (-0x10) in PID 1:

     Unable to handle kernel paging request at virtual address fffffffffffffff0
     pc : dwc3_qcom_remove+0x28/0x168 [dwc3_qcom]
       ...
       device_shutdown / kernel_restart
     Kernel panic - not syncing: Attempted to kill init!

Hardening thought:

Guarding dwc3_qcom_remove() with if (!qcom) return; (or using a dedicated idempotent .shutdown callback) would make dwc3-qcom safe against any future driver-core or parent-triggered teardown running after ->shutdown().

Details:
https://github.com/fidecastro/surface-laptop-7-15in-facts/blob/main/upstream-reports/dwc3-qcom-shutdown.md

Best regards,
Felipe Infante de Castro

#1 lore raw
Quoted 6 lines · Felipe Infante de Castro

Hi Thinh, Greg, Bjorn, and Konrad,

While bringing up an out-of-tree USB4 host router driver on a Snapdragon X Elite laptop (Linux v7.3.6 arm64), we hit a reproducible (3/3) PID 1 kernel panic on reboot with a USB4 dock attached.

Quoted 6 lines

Scope note upfront: nothing in mainline Linux triggers this today. It requires a second driver that unbinds a bound dwc3-qcom device during system shutdown (which our USB4 host router driver initially did when tearing down its guest USB3 session). We have already fixed our USB4 driver to skip device_release_driver() during shutdown, so this is purely a hardening note for dwc3-qcom in case it is useful upstream.

Then send a patch for the issue when your out-of-tree code is submitted. We really don't care, nor could we even possibly consider, interactions with out-of-tree code like this as that would mean we would go crazy over time.

thanks,

greg k-h

#3 lore raw
Quoted 2 lines · Felipe Infante de Castro

Understood, thanks. I will bring it up with the driver if it is ever submitted.

Sorry, I have no context here :(