From: Philipp Zabel <p.zabel@pengutronix.de>
To: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>,
Krzysztof Kozlowski <krzk@kernel.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 10/14] reset: protect struct reset_control with its own mutex
Date: Wed, 04 Mar 2026 11:57:01 +0100 [thread overview]
Message-ID: <e76693dd8a2c16bf6051a5ba0595d1e8081feba3.camel@pengutronix.de> (raw)
In-Reply-To: <20260223-reset-core-refactor-v2-10-5e5a7289190c@oss.qualcomm.com>
On Mo, 2026-02-23 at 11:06 +0100, Bartosz Golaszewski wrote:
> Currently we use a single, global mutex - misleadingly names
> reset_list_mutex - to protect the global list of reset devices,
> per-controller list of reset control handles and also internal fields of
> struct reset_control. Locking can be made a lot more fine-grained if we
> use a separate mutex for serializing operations on the list AND
> accessing the reset control handle.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
> ---
> drivers/reset/core.c | 38 ++++++++++++++------------------------
> 1 file changed, 14 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/reset/core.c b/drivers/reset/core.c
> index d4813c712abf3df7993b0c2be1fe292b89241d11..647e7112779517d2425f55728e1e7fb6e76a8045 100644
> --- a/drivers/reset/core.c
> +++ b/drivers/reset/core.c
> @@ -49,6 +49,7 @@ static DEFINE_IDA(reset_gpio_ida);
> * @triggered_count: Number of times this reset line has been reset. Currently
> * only used for shared resets, which means that the value
> * will be either 0 or 1.
> + * @lock: Serializes access to other fields of this structure
This is not correct, the lock only serializes reset_control_acquire().
> */
> struct reset_control {
> struct reset_controller_dev __rcu *rcdev;
> @@ -61,6 +62,7 @@ struct reset_control {
> bool array;
> atomic_t deassert_count;
> atomic_t triggered_count;
> + struct mutex lock;
> };
>
> /**
> @@ -707,7 +709,7 @@ int reset_control_acquire(struct reset_control *rstc)
> if (reset_control_is_array(rstc))
> return reset_control_array_acquire(rstc_to_array(rstc));
>
> - guard(mutex)(&reset_list_mutex);
> + guard(mutex)(&rstc->lock);
>
> if (rstc->acquired)
> return 0;
> @@ -859,6 +861,7 @@ __reset_control_get_internal(struct reset_controller_dev *rcdev,
> list_add(&rstc->list, &rcdev->reset_control_head);
> rstc->id = index;
> kref_init(&rstc->refcnt);
> + mutex_init(&rstc->lock);
> rstc->acquired = acquired;
> rstc->shared = shared;
> get_device(rcdev->dev);
> @@ -872,8 +875,6 @@ static void __reset_control_release(struct kref *kref)
> refcnt);
> struct reset_controller_dev *rcdev;
>
> - lockdep_assert_held(&reset_list_mutex);
> -
> scoped_guard(srcu, &rstc->srcu) {
> rcdev = rcu_replace_pointer(rstc->rcdev, NULL, true);
> if (rcdev) {
> @@ -882,15 +883,14 @@ static void __reset_control_release(struct kref *kref)
> }
> }
>
> + mutex_destroy(&rstc->lock);
> synchronize_srcu(&rstc->srcu);
> cleanup_srcu_struct(&rstc->srcu);
> kfree(rstc);
> }
>
> -static void __reset_control_put_internal(struct reset_control *rstc)
> +static void reset_control_put_internal(struct reset_control *rstc)
> {
> - lockdep_assert_held(&reset_list_mutex);
> -
With this, reset_control_put() is not serialized against
reset_control_get() anymore.
A __reset_control_get_internal(), running concurrently under rcdev-
>lock, might find this rstc right before __reset_control_release()
starts tearing it down.
regards
Philipp
next prev parent reply other threads:[~2026-03-04 10:57 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-23 10:06 [PATCH v2 00/14] reset: major reset core refactoring Bartosz Golaszewski
2026-02-23 10:06 ` [PATCH v2 01/14] reset: gpio: remove unneeded OF-node put Bartosz Golaszewski
2026-02-23 10:06 ` [PATCH v2 02/14] reset: gpio: add a devlink between reset-gpio and its consumer Bartosz Golaszewski
2026-02-23 10:06 ` [PATCH v2 03/14] reset: gpio: simplify fallback device matching Bartosz Golaszewski
2026-02-23 16:07 ` Philipp Zabel
2026-02-23 10:06 ` [PATCH v2 04/14] reset: gpio: remove unneeded auxiliary_set_drvdata() Bartosz Golaszewski
2026-02-23 10:06 ` [PATCH v2 05/14] reset: warn on reset-gpio release Bartosz Golaszewski
2026-02-23 16:07 ` Philipp Zabel
2026-02-23 10:06 ` [PATCH v2 06/14] reset: fold ida_alloc() into reset_create_gpio_aux_device() Bartosz Golaszewski
2026-02-23 10:06 ` [PATCH v2 07/14] reset: use lock guards in reset core Bartosz Golaszewski
2026-02-23 16:07 ` Philipp Zabel
2026-02-23 10:06 ` [PATCH v2 08/14] reset: handle removing supplier before consumers Bartosz Golaszewski
2026-03-04 10:56 ` Philipp Zabel
2026-03-05 11:11 ` Bartosz Golaszewski
2026-02-23 10:06 ` [PATCH v2 09/14] reset: protect struct reset_controller_dev with its own mutex Bartosz Golaszewski
2026-03-04 10:56 ` Philipp Zabel
2026-02-23 10:06 ` [PATCH v2 10/14] reset: protect struct reset_control " Bartosz Golaszewski
2026-03-04 10:57 ` Philipp Zabel [this message]
2026-02-23 10:06 ` [PATCH v2 11/14] reset: convert of_reset_control_get_count() to using firmware nodes Bartosz Golaszewski
2026-03-04 11:05 ` Philipp Zabel
2026-02-23 10:06 ` [PATCH v2 12/14] reset: convert the core API " Bartosz Golaszewski
2026-03-04 11:10 ` Philipp Zabel
2026-02-23 10:06 ` [PATCH v2 13/14] reset: convert reset core " Bartosz Golaszewski
2026-03-04 11:34 ` Philipp Zabel
2026-02-23 10:06 ` [PATCH v2 14/14] reset: gpio: make the driver fwnode-agnostic Bartosz Golaszewski
2026-03-04 11:34 ` Philipp Zabel
2026-03-03 8:55 ` [PATCH v2 00/14] reset: major reset core refactoring Bartosz Golaszewski
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=e76693dd8a2c16bf6051a5ba0595d1e8081feba3.camel@pengutronix.de \
--to=p.zabel@pengutronix.de \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--cc=krzk@kernel.org \
--cc=linux-kernel@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®