mfd: syscon: Give each syscon its own lockdep class
Subsystems (5)
v3 cover mfd: syscon: Give each syscon its own lockdep class
All syscon regmaps share one lockdep class, so on RK3588 lockdep reports a false circular dependency and turns itself off. Patch 1 adds an optional lockdep key to regmap_config, patch 2 gives each syscon one.
Patch 2 needs patch 1, so both could go through regmap with Lee's ack, or through mfd with Mark's. Based on regmap for-next; patch 2 also merges cleanly with for-mfd-next.
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 series lockdep reports the cycle during boot. With it there is no report and lockdep stays on.
Developed with Claude (Anthropic), which wrote the code and the commit messages. I reviewed every change.
---
Changes in v3:
- Move the fix into regmap: new regmap_config.lock_key; syscon passes a per-syscon key and drops its own lock (Lee).
- Drop the prerequisite, it is in for-mfd-next.
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- __acquires/__releases: name the argument, not a local (Sashiko).
- Link to v1: https://patch.msgid.link/[email protected]
---
Arun Iyengar (2):
regmap: Add an optional lockdep class to struct regmap_config
mfd: syscon: Give each syscon its own lockdep class
drivers/base/regmap/regmap.c | 3 +++ drivers/mfd/syscon.c | 6 ++++++ include/linux/regmap.h | 3 +++ 3 files changed, 12 insertions(+)
---
base-commit: 222b61e9c570dac6c7a786d039e4c226624b426d
change-id: 20261115-syscon-lockdep-d133fb58c2be
Best regards,
Signature · 1 line
Arun Iyengar <[email protected]>
PATCH v3 1/2 regmap: Add an optional lockdep class to struct regmap_config
The lockdep class of regmap's own lock is per regmap_init_*() call site. Maps made at one call site, such as all syscons, share it, so lockdep mixes up their unrelated lock chains.
Let the caller give each map its own class with config->lock_key.
--- drivers/base/regmap/regmap.c | 3 +++ include/linux/regmap.h | 3 +++ 2 files changed, 6 insertions(+)
drivers/base/regmap/regmap.c +3 -0
@@ -720,6 +720,9 @@ static int regmap_set_lock(struct regmap *map, const struct regmap_config *confireturn 0 ; } +if (config->lock_key) + lock_key = config->lock_key; +if (fast_io) {if (config->use_raw_spinlock) {raw_spin_lock_init (&map->raw_spinlock);
include/linux/regmap.h +3 -0
@@ -347,6 +347,8 @@ typedef void (*regmap_unlock)(void *);* @lock_arg: This field is passed as the only argument of lock/unlock * functions (ignored in case regular lock/unlock functions * are not overridden). +* @lock_key: Optional lockdep class for regmap's own lock, instead of +* one per call site. Must stay registered while the map exists. * @max_register: Optional, specifies the maximum valid register address. * @max_register_is_0: Optional, specifies that zero value in @max_register * should be taken into account. This is a workaround to
@@ -445,6 +447,7 @@ struct regmap_config {regmap_lock lock;regmap_unlock unlock;void *lock_arg; +struct lock_class_key *lock_key;unsigned int max_register;bool max_register_is_0;
Signature · 1 line
2.55.0
PATCH v3 2/2 mfd: syscon: Give each syscon its own lockdep class
In reply to Arun IyengarAll syscon regmaps share the lockdep class of the regmap_init_mmio() call site. On RK3588 the VO1 GRF calls clk_enable() under its regmap lock, while the CRU's GRF gates take the SYS GRF regmap lock under enable_lock. Lockdep reports a circular dependency and turns itself off.
Give each syscon its own class.
--- drivers/mfd/syscon.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/mfd/syscon.c +6 -0
@@ -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>
@@ -29,6 +30,7 @@ struct syscon {struct regmap *regmap;struct reset_control *reset;struct list_head list; +struct lock_class_key lock_key; };static const struct regmap_config syscon_regmap_config = {
@@ -62,6 +64,9 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)if (!base)return ERR_PTR (-ENOMEM ); +lockdep_register_key (&syscon->lock_key); + syscon_config.lock_key = &syscon->lock_key; +/* Parse the device's DT node for an endianness specification */ if (of_property_read_bool (np,"big-endian" )) syscon_config.val_format_endian =REGMAP_ENDIAN_BIG ;
@@ -162,6 +167,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)regmap_exit (regmap); err_regmap:iounmap (base); +lockdep_unregister_key (&syscon->lock_key);return ERR_PTR (ret); }
Signature · 1 line
2.55.0
[email protected]
AI reviewSashiko has reviewed this 2-patch series and found no issues.
Sashiko has reviewed this 2-patch series and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]