From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796021789; b=uvpgTmm/lhzY9GX7uGtZ9U2TOX7GBcgKqZW2yuClBbUtuJ7eI8xyPRvENtSkun0fBfht ldS82aXQFfLznPpc9hPqfrC3EHz6AXF38eRQqlDJCOV1IDkrhcVNWCxnY45QCBCZvDSkr gJuf1lq1/hFyo+WwxIVOHjiTLTA1z50l3OZaa65mBmICyZ/xCfqQWDDss0NbDaQQ4k2vc YttB05YNWzU1A2xMmE1y3b4MjYfyIqsJbc5sSl6U+ecNgAQi9iHfOzELN28M3sEJyWBpr wM6FaRrPquz/a6bvWnXuqauyqAkjtv2volfRP4cToZ4Sd9G7q8vepZ09D+n4QuhFzLw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796021789; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:Content-Transfer-Encoding:User-Agent:MIME-Version; bh=QADLE/xTOgxUFYLwwP6oBnev+U5U6gM8SMTPoFgQNrs=; b=GS3wVfvQKsAqelPPXOUEGAYElH8+pJOYe4SDcypb1/7vXwA120YYf6VTxgI3i7RmgMYV ryc9UDbkvplVB1LtnK8IsFi5wQTZywT6F3yEYEV9GNIGPHSRGA7ct3zt0YP5xe1pvk/aU vXGAZVAVFLvW1uYaOB9LpyA6npl1AKnZdW45bkWrxbPloG+1ebiOru1OIp25hMg1MQtd7 reuMuO7Morl+b2H4yA2faYJdpDNztitdQfQgdg9/X2VjjoUGjNhmZO5HVDT18a6DMHrCD w9QT0GgP75749M7LVOhk3Bs+g7q3Hn4clV1wUjnL/mT6kXKSKTxC4Bzle6iUIaX32rA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=GJ2AtAbC; arc=none smtp.remote-ip=209.85.128.47 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6E77606A327 for ; Mon, 30 Nov 2026 06:56:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D6E77606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=GJ2AtAbC Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4bb9d8e8e90so71589745e9.3 for ; Sun, 29 Nov 2026 22:56:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1796021787; x=1796626587; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:from:to :cc:subject:date:message-id:reply-to:content-type; bh=QADLE/xTOgxUFYLwwP6oBnev+U5U6gM8SMTPoFgQNrs=; b=GJ2AtAbCMr+7LrrpDI/TLBS3mrCYZ8OWGgG520wX9S7Qx5WVJDxQv7ZFlM4CI+YQtV zgcUoi07AIrLQ8aw2OxR8aQgdpLETMAQIeHIvfXpfvk3/8bSityljcTVmgFJEwrKOUVo 1EEtlh1n0jQmIzArIcLboWcmmmE0OPH0my6VFAxduykpQZwkru0vHyBnhaDrMrk4uF6J HtD3KiZCIu0Cp/+bmuAx2sPiNU7DktjKaxlscbmyAvBf1g1h5daZytmU5bvFghA1m7D0 a8c5I5t4DdG3vixVQ3FnmjOanFjuxYgWnRaSwQkPDz1QVUa7ctjrZ6GGKNiZ2LyXY2gm Udwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796021787; x=1796626587; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=QADLE/xTOgxUFYLwwP6oBnev+U5U6gM8SMTPoFgQNrs=; b=yCDh5QQNWq87qLtTps0B+aQX7ISxu5aJVO4plCwb/InBG+Qll8VDLA8tFYvKzbanH5 XkH4gm174r3sdgUofyETZZ4BTjggvoUm8eBiZ0J9Kogtv+mH7J1tEg3w4t07N4MNCgvl m4D3aCdKxwNY4BDJipiic2IhagDXFZoY4EbNhy++Us2kpPGZMHdpWOg42WzdvmGA4VEN PMPazSXHYDHnEmvAhYWIS8GLvAKLLLSfLtbA/S7F4xuv+iCu6s1dyITcfYB5dDDnndRW hvhycEdvGP6m0YYQvaruR4LDmw0n2V4po/UBL+Z6eLFDq5dXQKDsoDkIn/aiZKE0B+DK enxQ== X-Forwarded-Encrypted: i=1; AL+hErG3jXtoOW4pimrd1S6EmLhxDS9Rsb6cYXVA/YfNVXm4L6jteZyb2DRB5V5wtZya/90tRgRlS1j0Or03Q2Y=@vger.kernel.org X-Gm-Message-State: APuU4Z+B7i45sCXTW/2qNeQWNFg5/Qd5X9HXcN+d+7BWuai2/+DXjlwH 7rPI+A0LpGvAIxR+De0RAYvJemt3q87P/2isPpYqA7uNw4edLSVe8YKleuyAzErs9nY= X-Gm-Gg: AZFdTZeNRE36EbDrvkCQEA4E5z1fV+SGILFcZUA0YqaVEG8EuFWi06roOVGKuyGgMqm MCmxsJ5CoPVRzNqXziW+qmTfHBg01/kbqitTctD2X4X+wRDRXk3QS84FY4kXfBZFkJ3UfrOyDVF 0ZULumOo6Lo44aX2Zw6VzmSALJc91+TClYjxPravdQFmYzspOPiBIE5FJgsERp+B2q0KbrDHvfv zdNRi/ERxK40acODVNKdVSgUHfHSt617sV8qHi1Vufhgn/Tp34KTX/o+a6lVc9moRIxZFNxpVw2 X85sfP0N/k+PGMLOOmYVheuAULgNgBtGzcuyEARNY6SW8t160LL8fynQA0h/nIuoDAG+Zqzp0pI z2i+6Pu57t238JB77MIxJc/cP4QnVAhBnsFL8jxsmCQ1liiMVaw1Qk6VI/OSds7PFg+/UMSF9QK McHrqG7oVBwAbCPnqyF9E0a1vllTdpG+Hv9AziH2olUaS8KY1Dl8sZzc7GKlsnMo/+LcgfABigF IMez8ub2ORD0Umc+uEwIG+p2dyLLYMRZ6hHgFhlI8KWWe1wxycyerW6tvx/Xno3bgdNy1uWBhaQ tlaKr2tkk92SZXQeUPBG/T47BLVSSrWMhw== X-Received: by 2002:a05:600c:a115:b0:4bb:a5e1:7257 with SMTP id 5b1f17b1804b1-4bba5e19362mr248298425e9.33.1796021787236; Sun, 29 Nov 2026 22:56:27 -0800 (PST) Received: from draszik.lan ([109.255.181.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb906635c7sm601810065e9.2.2026.11.29.22.56.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 22:56:26 -0800 (PST) Message-ID: <5a5bcabce1341b955a15dea5e8bfb86c77a50f7d.camel@linaro.org> Subject: Re: [PATCH v2] power: supply: core: give each supply's epc_sem its own lockdep class From: =?ISO-8859-1?Q?Andr=E9?= Draszik To: Ryan Brue , Sebastian Reichel , Sebastian Reichel , Hang Nan <2122295973@qq.com> Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 30 Nov 2026 06:56:42 +0000 In-Reply-To: <20261129-power-supply-epc-lockdep-key-v2-1-0aeb53501340@gmail.com> References: <20261129-power-supply-epc-lockdep-key-v2-1-0aeb53501340@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2-9+build1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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. >=20 > 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: >=20 > =C2=A0 WARNING: possible circular locking dependency detected > =C2=A0 kworker/2:1/60 is trying to acquire lock: > =C2=A0=C2=A0 (mutex_#2){+.+.}-{4:4}, at: mt6397_battery_get_property+0x50= /0x23c > =C2=A0 but task is already holding lock: > =C2=A0=C2=A0 (&psy->epc_sem){.+.+}-{4:4}, at: power_supply_get_property+0= x34/0x80 >=20 > Lockdep then turns itself off for the rest of the boot. >=20 > 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. >=20 > Register a lockdep key for each supply, so that only a supply's own epc_s= em > 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. >=20 > Fixes: 9f7f7a859451 ("power_supply: serialize property access with unregi= ster") > Tested-by: Andr=C3=A9 Draszik > Signed-off-by: Ryan Brue > --- > 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. >=20 > 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=C3=A9 Draszik has also tested it on a Pixel 6, where it fixes the > recursive locking report. >=20 > 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 i= t > =C2=A0 &psy->epc_sem (Andr=C3=A9 Draszik). > - Name the "possible recursive locking detected" report in the commit > =C2=A0 message too (Andr=C3=A9 Draszik). > - Picked up Andr=C3=A9's Tested-by. > - Link to v1: https://lore.kernel.org/r/20261125-power-supply-epc-lockdep= -key-v1-1-c8a41b8a4470@gmail.com >=20 > 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 > --- > =C2=A0drivers/power/supply/power_supply_core.c | 4 +++- > =C2=A0include/linux/power_supply.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 3 +++ > =C2=A02 files changed, 6 insertions(+), 1 deletion(-) Reviewed-by: Andr=C3=A9 Draszik