[PATCH v3 2/2] regmap: Drop map lock during cache init and exit

Peng Fan peng.fan at oss.nxp.com
Thu Oct 8 03:55:07 PDT 2026


On Tue, Oct 06, 2026 at 06:03:16PM +1100, Michael Reeves wrote:
>On systems with CONFIG_PROVE_RAW_LOCK_NESTING enabled, Apple GPIO probe
>triggers an "Invalid wait context" lockdep warning.
>
>The driver uses a regmap with a raw spinlock and REGCACHE_FLAT. During
>regcache_init(), regcache_flat_init() allocates memory while holding the
>raw spinlock. The memory allocator can acquire a non-raw spinlock, which
>causes an invalid raw-to-non-raw lock nesting error. The abbreviated call
>chain is:
>
>  apple_gpio_pinctrl_probe
>    regcache_init
>      regcache_flat_init
>        __kmalloc_noprof
>          __pcs_replace_empty_main
>            refill_objects
>              _raw_spin_lock_irqsave
>
>Cache allocation occurs before the regmap is published, cache destruction
>occurs after users have stopped accessing it, and regmap_reinit_cache()
>requires callers to prevent concurrent access. Remove the outer map lock
>from cache initialization and destruction. Keep it for cache population
>and normal register access.
>
>The Maple cache still uses its internal spinlock during teardown. That
>lock can also be acquired from hard IRQ context during register access.
>Add Maple-state irqsave helpers and use them during teardown to preserve
>the lock's IRQ-safe lockdep state.
>
>Fixes: fd4ebc07b4df ("regmap: Hold the regmap lock when allocating and freeing the cache")
>Suggested-by: Mark Brown <broonie at kernel.org>
>Suggested-by: Liam R. Howlett <liam at infradead.org>
>Signed-off-by: Michael Reeves <michael.reeves077 at gmail.com>

Reviewed-by: Peng Fan <peng.fan at nxp.com>

BTW: patch [1]
     "regcache: extract locked helpers to replace open-coded lock/unlock pairs"
     has been accepted into Mark's regmap for-7.4 branch. So there will be conflicts(:

[1] https://lore.kernel.org/all/20261002-regmap-lock-2nd-v2-1-e172b0501c52@nxp.com/

Regards
Peng.



More information about the maple-tree mailing list