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 v2] power: supply: core: give each supply's epc_sem its own lockdep class
Date: Mon, 30 Nov 2026 06:56:42 +0000 [thread overview]
Message-ID: <5a5bcabce1341b955a15dea5e8bfb86c77a50f7d.camel@linaro.org> (raw)
In-Reply-To: <20261129-power-supply-epc-lockdep-key-v2-1-0aeb53501340@gmail.com>
On Sun, 2026-11-29 at 23:19 -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.
>
> The shared class also makes a get_property() callback that reads another
> supply, for instance through power_supply_get_property_from_supplier(),
> report "possible recursive locking detected". max77759-charger does this
> with its TCPM supplier.
>
> Register a lockdep key for each supply, so that only a supply's own epc_sem
> is ordered against its own locks. Initialise epc_sem with __init_rwsem(),
> so that lockdep still names it &psy->epc_sem rather than after the key.
>
> Fixes: 9f7f7a859451 ("power_supply: serialize property access with unregister")
> Tested-by: André Draszik <andre.draszik@linaro.org>
> Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>
> ---
> Since v7.4-rc1 power_supply_get_property() takes the target supply's
> epc_sem, and every supply's epc_sem shares one lockdep class. A driver
> that reads another supply under a lock its own get_property() takes is
> then reported as a circular dependency, and lockdep switches itself off.
>
> Tested on an MT8173 tablet (Amazon Fire HD 10, 2017) with PROVE_LOCKING:
> the report came at boot with a fuel gauge that reads its charger under
> its own mutex, and doesn't come with this patch (debug_locks stays 1).
> André Draszik has also tested it on a Pixel 6, where it fixes the
> recursive locking report.
>
> This patch was developed with the help of an LLM coding assistant.
> ---
> Changes in v2:
> - Initialise epc_sem with __init_rwsem(), so that lockdep keeps calling it
> &psy->epc_sem (André Draszik).
> - Name the "possible recursive locking detected" report in the commit
> message too (André Draszik).
> - Picked up André's Tested-by.
> - Link to v1: https://lore.kernel.org/r/20261125-power-supply-epc-lockdep-key-v1-1-c8a41b8a4470@gmail.com
>
> Changes in v1 RESEND:
> - Added Sebastian's Collabora address; no code change.
> - Link to v1: https://lore.kernel.org/r/20261110-power-supply-epc-lockdep-key-v1-1-39bd0a237a6c@gmail.com
> ---
> drivers/power/supply/power_supply_core.c | 4 +++-
> include/linux/power_supply.h | 3 +++
> 2 files changed, 6 insertions(+), 1 deletion(-)
Reviewed-by: André Draszik <andre.draszik@linaro.org>
prev parent reply other threads:[~2026-11-30 6:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 5:19 Ryan Brue
2026-11-30 6:56 ` 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=5a5bcabce1341b955a15dea5e8bfb86c77a50f7d.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®