mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: aiyengar1990@gmail.com
Cc: Arnd Bergmann <arnd@arndb.de>,
	mfd@lists.linux.dev, linux-kernel@vger.kernel.org,
	Mark Brown <broonie@kernel.org>, Heiko Stuebner <heiko@sntech.de>,
	linux-rockchip@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2] mfd: syscon: Give each syscon its own lockdep class
Date: Fri, 27 Nov 2026 14:55:25 +0000	[thread overview]
Message-ID: <20261127145525.GV38590@joneslee-macbookpro.roam.internal> (raw)
In-Reply-To: <20261122-syscon-lockdep-v2-1-868056a6a808@gmail.com>

On Sun, 22 Nov 2026, Arun Iyengar via B4 Relay wrote:

> From: Arun Iyengar <aiyengar1990@gmail.com>
> 
> All syscon regmaps share one lockdep class, as regmap_init_mmio() uses a
> static key per call site. Lockdep then mixes up unrelated syscons: on
> RK3588 the clock-gated VO1 GRF calls clk_enable() under its regmap lock,
> while the CRU's GRF gates take the SYS GRF regmap lock under enable_lock.
> This is reported as a circular dependency and disables lockdep.

This needs fixing in Regmap, not Syscon!

Have you looked into __regmap_lockdep_wrapper()?

Or perhaps 'struct regmap_config' could take an optional 'lock_key'?

> Lock each syscon regmap with its own spinlock and lockdep class.
> 
> Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
> ---
> Tested on an Orange Pi 5 (RK3588S) with a 7.3 based kernel that has
> out-of-tree DisplayPort patches, lockdep and KASAN on. Without the patch
> lockdep reports the cycle during boot. With it /proc/lockdep shows one
> syscon lock -> enable_lock and enable_lock -> another syscon lock, there
> is no report and lockdep stays on. Build-tested on for-mfd-next.
> 
> Applies on top of "mfd: syscon: Put the clock after regmap_exit()":
> https://lore.kernel.org/r/20261119-syscon-clk-uaf-v1-1-dc4a4c1be353@gmail.com
> 
> Developed with Claude (Anthropic), which wrote the code and the commit
> message. I reviewed every change.
> ---
> Changes in v2:
> - __acquires/__releases: name the argument, not a local (Sashiko).
> - Link to v1: https://patch.msgid.link/20261120-syscon-lockdep-v1-1-aed779a004b8@gmail.com
> ---
>  drivers/mfd/syscon.c | 36 +++++++++++++++++++++++++++++++++++-
>  1 file changed, 35 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
> index 3ff4e024542b..480ac178968a 100644
> --- a/drivers/mfd/syscon.c
> +++ b/drivers/mfd/syscon.c
> @@ -13,6 +13,7 @@
>  #include <linux/err.h>
>  #include <linux/hwspinlock.h>
>  #include <linux/list.h>
> +#include <linux/lockdep.h>
>  #include <linux/mutex.h>
>  #include <linux/of.h>
>  #include <linux/of_address.h>
> @@ -20,6 +21,7 @@
>  #include <linux/reset.h>
>  #include <linux/mfd/syscon.h>
>  #include <linux/slab.h>
> +#include <linux/spinlock.h>
>  
>  static DEFINE_MUTEX(syscon_list_lock);
>  static LIST_HEAD(syscon_list);
> @@ -29,8 +31,29 @@ struct syscon {
>  	struct regmap *regmap;
>  	struct reset_control *reset;
>  	struct list_head list;
> +	spinlock_t lock;
> +	unsigned long lock_flags;
> +	struct lock_class_key lock_key;
>  };
>  
> +static void syscon_lock(void *arg)
> +__acquires(&((struct syscon *)arg)->lock)
> +{
> +	struct syscon *syscon = arg;
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&syscon->lock, flags);
> +	syscon->lock_flags = flags;
> +}
> +
> +static void syscon_unlock(void *arg)
> +__releases(&((struct syscon *)arg)->lock)
> +{
> +	struct syscon *syscon = arg;
> +
> +	spin_unlock_irqrestore(&syscon->lock, syscon->lock_flags);
> +}
> +
>  static const struct regmap_config syscon_regmap_config = {
>  	.reg_bits = 32,
>  	.val_bits = 32,
> @@ -114,12 +137,21 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
>  	if (!syscon_config.max_register)
>  		syscon_config.max_register_is_0 = true;
>  
> +	lockdep_register_key(&syscon->lock_key);
> +	spin_lock_init(&syscon->lock);
> +	lockdep_set_class(&syscon->lock, &syscon->lock_key);
> +	if (!syscon_config.use_hwlock) {
> +		syscon_config.lock = syscon_lock;
> +		syscon_config.unlock = syscon_unlock;
> +		syscon_config.lock_arg = syscon;
> +	}

Duplicating regmap's internal spinlock callbacks here just to give each syscon
its own 'lock_class_key' feels like working around regmap in the wrong layer.
Could we either pass a per-syscon key into __regmap_init_mmio_clk() or add an
optional 'lock_key' to 'struct regmap_config' so regmap core handles the lockdep
class directly without open-coding syscon_lock() and syscon_unlock() here?

> +
>  	regmap = regmap_init_mmio(NULL, base, &syscon_config);
>  	kfree(syscon_config.name);
>  	if (IS_ERR(regmap)) {
>  		pr_err("regmap init failed\n");
>  		ret = PTR_ERR(regmap);
> -		goto err_regmap;
> +		goto err_key;
>  	}
>  
>  	if (check_res) {
> @@ -159,6 +191,8 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
>  	regmap_exit(regmap);
>  	if (!IS_ERR(clk))
>  		clk_put(clk);
> +err_key:
> +	lockdep_unregister_key(&syscon->lock_key);
>  err_regmap:
>  	iounmap(base);
>  	return ERR_PTR(ret);
> 
> ---
> base-commit: 1cb7268b6638c411fc32f373e965eb8ba9e9b2b4
> change-id: 20261115-syscon-lockdep-d133fb58c2be
> prerequisite-message-id: <20261119-syscon-clk-uaf-v1-1-dc4a4c1be353@gmail.com>
> prerequisite-patch-id: 7cf33abeabb3eeaf1ba8ac6c461726fca87702cd
> 
> Best regards,
> --  
> Arun Iyengar <aiyengar1990@gmail.com>
> 
> 

-- 
Lee Jones

      reply	other threads:[~2026-11-27 14:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22  9:01 Arun Iyengar via B4 Relay
2026-11-27 14:55 ` Lee Jones [this message]

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=20261127145525.GV38590@joneslee-macbookpro.roam.internal \
    --to=lee@kernel.org \
    --cc=aiyengar1990@gmail.com \
    --cc=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=heiko@sntech.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=mfd@lists.linux.dev \
    /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®