mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "André Draszik" <andre.draszik@linaro.org>
To: Ryan Brue <ryanbrue.dev@gmail.com>,
	Sebastian Reichel <sre@kernel.org>,
	 Sebastian Reichel <sebastian.reichel@collabora.com>,
	Hang Nan <2122295973@qq.com>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND] power: supply: core: give each supply's epc_sem its own lockdep class
Date: Thu, 26 Nov 2026 10:27:29 +0000	[thread overview]
Message-ID: <f203e85c22e97363a220fc09b45ff6ba33c3f59d.camel@linaro.org> (raw)
In-Reply-To: <20261125-power-supply-epc-lockdep-key-v1-1-c8a41b8a4470@gmail.com>

Hi Ryan,

On Wed, 2026-11-25 at 17:23 -0600, Ryan Brue wrote:
> Since commit 9f7f7a859451 ("power_supply: serialize property access with
> unregister"), power_supply_get_property() takes the target supply's
> epc_sem for read. Every supply's epc_sem is initialised at the same site,
> so they all share one lockdep class.
> 
> A driver that reads another supply while holding a lock that its
> get_property() callback also takes is then reported as a circular
> dependency, even though the two semaphores belong to different supplies.
> sc27xx_fgu_get_property() does this with data->lock and the charger, and
> a fuel gauge driver in preparation did the same with its charger:
> 
>   WARNING: possible circular locking dependency detected
>   kworker/2:1/60 is trying to acquire lock:
>    (mutex_#2){+.+.}-{4:4}, at: mt6397_battery_get_property+0x50/0x23c
>   but task is already holding lock:
>    (&psy->epc_sem){.+.+}-{4:4}, at: power_supply_get_property+0x34/0x80
> 
> Lockdep then turns itself off for the rest of the boot.
> 
> Register a lockdep key for each supply, so that only a supply's own epc_sem
> is ordered against its own locks.
> 
> Fixes: 9f7f7a859451 ("power_supply: serialize property access with unregister")
> Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>

Thanks for the patch — I hit the same shared-class issue on Pixel 6 (Oriole)
with max77759-charger reading properties from its TCPM supplier via
power_supply_get_property_from_supplier(), which triggers a "possible
recursive locking detected" splat.

Two minor suggestions:

1. It would be helpful to also mention the "possible recursive locking
   detected" case in the commit message (e.g. consumer callbacks calling
   power_supply_get_property_from_supplier() or power_supply_get_property()
   on another supply), so people hitting that variant can easily find this
   fix.


> [...]
> diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
> index de15314ef954..76bbe8772143 100644
> --- a/drivers/power/supply/power_supply_core.c
> +++ b/drivers/power/supply/power_supply_core.c
> @@ -1662,6 +1662,7 @@ static void power_supply_dev_release(struct device *dev)
>  	struct power_supply *psy = to_power_supply(dev);
>  
>  	dev_dbg(dev, "%s\n", __func__);
> +	lockdep_unregister_key(&psy->epc_key);
>  	kfree(psy);
>  }
>  
> @@ -1765,6 +1766,7 @@ __power_supply_register(struct device *parent,
>  	if (!psy)
>  		return ERR_PTR(-ENOMEM);
>  
> +	lockdep_register_key(&psy->epc_key);
>  	dev = &psy->dev;
>  
>  	device_initialize(dev);
> @@ -1810,6 +1812,7 @@ __power_supply_register(struct device *parent,
>  
>  	spin_lock_init(&psy->changed_lock);
>  	init_rwsem(&psy->epc_sem);
> +	lockdep_set_class(&psy->epc_sem, &psy->epc_key);

2. Because lockdep_set_class() stringifies the key argument, the lock shows
   up in /proc/lockdep (and any future splats) as "&psy->epc_key" instead of
   "&psy->epc_sem":

     ffff0008068e26e0 FD:  167 BD:   13 .+.+: &psy->epc_key#2
      -> [ffff000816c3eee0] &psy->epc_key

   Replacing init_rwsem() + lockdep_set_class() with:

     __init_rwsem(&psy->epc_sem, "&psy->epc_sem", &psy->epc_key);

   like block/blk-crypto-profile.c does, preserves the lock name while
   using the per-supply key.

Tested-by: André Draszik <andre.draszik@linaro.org>

Cheers,
Andre'

      reply	other threads:[~2026-11-26 10:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 23:23 Ryan Brue
2026-11-26 10:27 ` André Draszik [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=f203e85c22e97363a220fc09b45ff6ba33c3f59d.camel@linaro.org \
    --to=andre.draszik@linaro.org \
    --cc=2122295973@qq.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=ryanbrue.dev@gmail.com \
    --cc=sebastian.reichel@collabora.com \
    --cc=sre@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®