Skip to content

usb: roles: serialize unregister against callbacks and fix dwc3-apple lock order

Ilia Snezhkov asahi b4-sent linux-usb lkml 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest2 patches 0 repliesNew

Changes in v2 from the cover letter

- Audited all 15 in-tree usb_role_switch_unregister() callers and confirmed drivers/usb/dwc3/dwc3-apple.c is the sole caller holding a lock also acquired by ->set()/->get().
- Added patch 1/2 fixing dwc3_apple_remove() before patch 2/2 takes sw->lock in usb_role_switch_unregister().
- Documented the lock-ordering requirement in the kerneldoc of usb_role_switch_unregister().
- Link to v1: https://lore.kernel.org/r/[email protected]

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2usb: dwc3: apple: unregister role switch outside appledwc->lockdrivers/usb/dwc3/dwc3-apple.c+2 -20 replies
2/2usb: roles: serialize registered checks and unregister under sw->lockdrivers/usb/roles/class.c+14 -50 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/2] usb: roles: serialize unregister against callbacks and fix dwc3-apple lock order

This two-patch v2 series fixes the race between usb_role_switch_unregister() and concurrent usb_role_switch_{get,set}_role() callbacks without introducing an ABBA lock-order inversion in callers:

1. Move usb_role_switch_unregister() outside appledwc->lock in dwc3_apple_remove(), the only in-tree caller holding a mutex taken by its role switch callbacks.
2. Serialize sw->registered checks and teardown under sw->lock in drivers/usb/roles/class.c and document the locking contract on usb_role_switch_unregister().

Changes in v2:
- Audited all 15 in-tree usb_role_switch_unregister() callers and confirmed drivers/usb/dwc3/dwc3-apple.c is the sole caller holding a lock also acquired by ->set()/->get().
- Added patch 1/2 fixing dwc3_apple_remove() before patch 2/2 takes sw->lock in usb_role_switch_unregister().
- Documented the lock-ordering requirement in the kerneldoc of usb_role_switch_unregister().
- Link to v1: https://lore.kernel.org/r/[email protected]

Found and drafted with an AI coding assistant.

Ilia Snezhkov (2):
usb: dwc3: apple: unregister role switch outside appledwc->lock
usb: roles: serialize registered checks and unregister under sw->lock

 drivers/usb/dwc3/dwc3-apple.c |  4 ++--
 drivers/usb/roles/class.c     | 19 ++++++++++++++-----
 2 files changed, 16 insertions(+), 7 deletions(-)
Signature · 1 line
2.54.0 (Apple Git-157)