From: Ilia Snezhkov <iasnezhkov@gmail.com>
To: heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org
Cc: hdegoede@redhat.com, sven@kernel.org, j@jannau.net,
Thinh.Nguyen@synopsys.com, asahi@lists.linux.dev,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v3 1/2] usb: dwc3: apple: unregister role switch outside appledwc->lock
Date: Mon, 30 Nov 2026 15:43:05 +0000 [thread overview]
Message-ID: <20261130154304.90482-2-iasnezhkov@gmail.com> (raw)
In-Reply-To: <20261130154304.90482-1-iasnezhkov@gmail.com>
dwc3_apple_remove() holds appledwc->lock across
usb_role_switch_unregister(), while both dwc3_usb_role_switch_set() and
dwc3_usb_role_switch_get() acquire appledwc->lock.
Calling usb_role_switch_unregister() under appledwc->lock creates an
ABBA lock-order inversion against both sysfs attribute teardown
(device_unregister() -> kernfs_drain() waiting on an active role_show /
role_store callback) and synchronizing usb_role_switch_unregister()
against in-flight callbacks under sw->lock.
appledwc->role_sw is assigned once during probe and never modified
afterwards. Unregister the role switch before acquiring appledwc->lock
for hardware teardown.
Fixes: 0ec946d32ef7 ("usb: dwc3: Add Apple Silicon DWC3 glue layer driver")
Cc: stable@vger.kernel.org
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
---
Changes in v3:
- Add Cc: stable@vger.kernel.org (per Heikki Krogerus).
- Move the AI coding assistant note below ---.
Found and drafted with an AI coding assistant.
drivers/usb/dwc3/dwc3-apple.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/dwc3/dwc3-apple.c b/drivers/usb/dwc3/dwc3-apple.c
index 1f474a8..035aeeb 100644
--- a/drivers/usb/dwc3/dwc3-apple.c
+++ b/drivers/usb/dwc3/dwc3-apple.c
@@ -487,10 +487,10 @@ static void dwc3_apple_remove(struct platform_device *pdev)
struct dwc3 *dwc = platform_get_drvdata(pdev);
struct dwc3_apple *appledwc = to_dwc3_apple(dwc);
- guard(mutex)(&appledwc->lock);
-
usb_role_switch_unregister(appledwc->role_sw);
+ guard(mutex)(&appledwc->lock);
+
/*
* If we're still in DWC3_APPLE_PROBE_PENDING we never got any cable connected event and
* dwc3_core_probe was never called and there's hence no need to call dwc3_core_remove.
--
2.54.0 (Apple Git-157)
WARNING: multiple messages have this Message-ID (diff)
From: Ilia Snezhkov via B4 Relay <devnull+iasnezhkov.gmail.com@kernel.org>
To: heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org
Cc: hdegoede@redhat.com, sven@kernel.org, j@jannau.net,
Thinh.Nguyen@synopsys.com, asahi@lists.linux.dev,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v3 1/2] usb: dwc3: apple: unregister role switch outside appledwc->lock
Date: Mon, 30 Nov 2026 15:43:05 +0000 [thread overview]
Message-ID: <20261130154304.90482-2-iasnezhkov@gmail.com> (raw)
In-Reply-To: <20261130154304.90482-1-iasnezhkov@gmail.com>
From: Ilia Snezhkov <iasnezhkov@gmail.com>
dwc3_apple_remove() holds appledwc->lock across
usb_role_switch_unregister(), while both dwc3_usb_role_switch_set() and
dwc3_usb_role_switch_get() acquire appledwc->lock.
Calling usb_role_switch_unregister() under appledwc->lock creates an
ABBA lock-order inversion against both sysfs attribute teardown
(device_unregister() -> kernfs_drain() waiting on an active role_show /
role_store callback) and synchronizing usb_role_switch_unregister()
against in-flight callbacks under sw->lock.
appledwc->role_sw is assigned once during probe and never modified
afterwards. Unregister the role switch before acquiring appledwc->lock
for hardware teardown.
Fixes: 0ec946d32ef7 ("usb: dwc3: Add Apple Silicon DWC3 glue layer driver")
Cc: stable@vger.kernel.org
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
---
Changes in v3:
- Add Cc: stable@vger.kernel.org (per Heikki Krogerus).
- Move the AI coding assistant note below ---.
Found and drafted with an AI coding assistant.
drivers/usb/dwc3/dwc3-apple.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/dwc3/dwc3-apple.c b/drivers/usb/dwc3/dwc3-apple.c
index 1f474a8..035aeeb 100644
--- a/drivers/usb/dwc3/dwc3-apple.c
+++ b/drivers/usb/dwc3/dwc3-apple.c
@@ -487,10 +487,10 @@ static void dwc3_apple_remove(struct platform_device *pdev)
struct dwc3 *dwc = platform_get_drvdata(pdev);
struct dwc3_apple *appledwc = to_dwc3_apple(dwc);
- guard(mutex)(&appledwc->lock);
-
usb_role_switch_unregister(appledwc->role_sw);
+ guard(mutex)(&appledwc->lock);
+
/*
* If we're still in DWC3_APPLE_PROBE_PENDING we never got any cable connected event and
* dwc3_core_probe was never called and there's hence no need to call dwc3_core_remove.
--
2.54.0 (Apple Git-157)
next prev parent reply other threads:[~2026-11-30 15:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 15:43 [PATCH v3 0/2] usb: roles: serialize unregister against callbacks and fix dwc3-apple lock order Ilia Snezhkov
2026-11-30 15:43 ` Ilia Snezhkov via B4 Relay
2026-11-30 15:43 ` Ilia Snezhkov [this message]
2026-11-30 15:43 ` [PATCH v3 1/2] usb: dwc3: apple: unregister role switch outside appledwc->lock Ilia Snezhkov via B4 Relay
2026-11-30 15:43 ` [PATCH v3 2/2] usb: roles: serialize registered checks and unregister under sw->lock Ilia Snezhkov
2026-11-30 15:43 ` Ilia Snezhkov via B4 Relay
2026-11-30 15:56 ` [PATCH v3 0/2] usb: roles: serialize unregister against callbacks and fix dwc3-apple lock order sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130154304.90482-2-iasnezhkov@gmail.com \
--to=iasnezhkov@gmail.com \
--cc=Thinh.Nguyen@synopsys.com \
--cc=asahi@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=hdegoede@redhat.com \
--cc=heikki.krogerus@linux.intel.com \
--cc=j@jannau.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=sven@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.