From: Tzung-Bi Shih <tzungbi@kernel.org>
To: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>,
linux-kernel@vger.kernel.org, tzungbi@kernel.org
Subject: [PATCH v2 2/2] reset: Fix circular locking dependency in reset_controller_unregister()
Date: Thu, 5 Nov 2026 00:20:38 +0800 [thread overview]
Message-ID: <20261104162038.48622-3-tzungbi@kernel.org> (raw)
In-Reply-To: <20261104162038.48622-1-tzungbi@kernel.org>
reset_control_acquire() and reset_control_put_internal() acquire
`rcdev->lock` inside the `rstc->srcu` read-side critical section
(`rstc->srcu` -> `rcdev->lock`).
However, reset_controller_unregister() holds `rcdev->lock` while calling
synchronize_srcu(&rstc->srcu) (`rcdev->lock` -> `rstc->srcu`), causing a
lockdep circular locking dependency warning and a potential ABBA
deadlock.
Run synchronize_srcu() outside `rcdev->lock`.
Fixes: 44a0acb2caca ("reset: protect struct reset_controller_dev with its own mutex")
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
Test:
With "[PATCH v3] reset: Add KUnit test cases"[1] applied:
$ ./tools/testing/kunit/kunit.py run \
--kconfig_add CONFIG_RESET_CONTROLLER=y \
--kconfig_add CONFIG_RESET_KUNIT_TEST=y \
--kconfig_add CONFIG_PROVE_LOCKING=y \
--kconfig_add CONFIG_DEBUG_KERNEL=y \
--kconfig_add CONFIG_KASAN=y \
--arch=x86_64 \
--raw_output=all \
reset_test
[1] https://lore.kernel.org/all/20261104160123.6784-1-tzungbi@kernel.org
---
v2:
- Use list_move() to make the intent clear.
- Defer reset_controller_remove() after synchronize_srcu() to avoid race.
- Drop lockdep_assert_held() and add comment for reset_controller_remove().
v1: https://lore.kernel.org/all/20261102155840.20376-3-tzungbi@kernel.org
---
drivers/reset/core.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index f0ab09795ae1..4a582721782f 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -163,11 +163,15 @@ EXPORT_SYMBOL_GPL(reset_controller_register);
static void __reset_control_release(struct kref *kref);
static void __reset_control_free(struct reset_control *rstc);
+/*
+ * Removes rstc from its list and drops the references on rcdev's owner module
+ * and device. The caller must ensure rstc->list access is serialized (e.g.,
+ * by holding rcdev->lock or moving rstc to a private list) and that no
+ * operations on rcdev via rstc are in flight.
+ */
static void reset_controller_remove(struct reset_controller_dev *rcdev,
struct reset_control *rstc)
{
- lockdep_assert_held(&rcdev->lock);
-
list_del(&rstc->list);
module_put(rcdev->owner);
put_device(rcdev->dev);
@@ -180,6 +184,7 @@ static void reset_controller_remove(struct reset_controller_dev *rcdev,
void reset_controller_unregister(struct reset_controller_dev *rcdev)
{
struct reset_control *rstc, *pos;
+ LIST_HEAD(reset_control_head);
scoped_guard(mutex, &reset_list_mutex)
list_del(&rcdev->list);
@@ -196,13 +201,22 @@ void reset_controller_unregister(struct reset_controller_dev *rcdev)
list_for_each_entry_safe(rstc, pos, &rcdev->reset_control_head, list) {
kref_get(&rstc->refcnt);
rcu_assign_pointer(rstc->rcdev, NULL);
- synchronize_srcu(&rstc->srcu);
- reset_controller_remove(rcdev, rstc);
- if (kref_put(&rstc->refcnt, __reset_control_release))
- __reset_control_free(rstc);
+ list_move(&rstc->list, &reset_control_head);
}
}
+ /*
+ * Run synchronize_srcu() outside rcdev->lock to avoid a circular
+ * locking dependency with paths that acquire rcdev->lock inside
+ * the rstc->srcu read-side critical section.
+ */
+ list_for_each_entry_safe(rstc, pos, &reset_control_head, list) {
+ synchronize_srcu(&rstc->srcu);
+ reset_controller_remove(rcdev, rstc);
+ if (kref_put(&rstc->refcnt, __reset_control_release))
+ __reset_control_free(rstc);
+ }
+
mutex_destroy(&rcdev->lock);
}
EXPORT_SYMBOL_GPL(reset_controller_unregister);
--
2.53.0
next prev parent reply other threads:[~2026-11-04 16:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 16:20 [PATCH v2 0/2] reset: Fix issues reported by Sashiko Tzung-Bi Shih
2026-11-04 16:20 ` [PATCH v2 1/2] reset: Fix reset_control leak when put after controller unregister Tzung-Bi Shih
2026-11-04 17:38 ` Markus Elfring
2026-11-05 10:40 ` Philipp Zabel
2026-11-04 16:20 ` Tzung-Bi Shih [this message]
2026-11-05 10:40 ` [PATCH v2 2/2] reset: Fix circular locking dependency in reset_controller_unregister() Philipp Zabel
2026-11-05 9:16 ` [PATCH v2 0/2] reset: Fix issues reported by Sashiko Bartosz Golaszewski
2026-11-05 11:08 ` Philipp Zabel
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=20261104162038.48622-3-tzungbi@kernel.org \
--to=tzungbi@kernel.org \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
/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.