From nobody Wed Sep 17 20:48:38 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D420BC4332F for ; Thu, 15 Dec 2022 10:46:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230176AbiLOKqj (ORCPT ); Thu, 15 Dec 2022 05:46:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229937AbiLOKqh (ORCPT ); Thu, 15 Dec 2022 05:46:37 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A77101F629; Thu, 15 Dec 2022 02:46:36 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4478161D78; Thu, 15 Dec 2022 10:46:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FD9DC433EF; Thu, 15 Dec 2022 10:46:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671101195; bh=McOhDbVk0JP93y4a1SmXb8+7y052zP6zdNJ92f0ueYY=; h=From:To:Cc:Subject:Date:From; b=p1bVSMqrrJ0RECFYWt4n/HzRckicS01Tm0Ej6X08MA9N1GvwIdNDgXmUU2HjcClFL jDwV9CIluaPuPWw+EIoHbmr/KiNnKI51kGSKYUncmoy4JsiIIHvl8dIsInvsaD+a/a wQ0joNp0ZdqGejIE4WPok8MmDS0PR1FwfAAe+A1bQ7T+2u8fYWQAm6+jykEsau6DHl qqQT0O1E43Eos6rfgMx+ruXGZq72sLGrPUyzyaDEBjB3h4ax6RvctsVJgSfdk2aMs3 BvhJtohpP2nj9NQPJgYbtlz2BC9sdixiv1dvYMA96pJG+ygIYoOdhpvlhcxpu4HpO9 WoAShiFXBBrsQ== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1p5llZ-00059t-To; Thu, 15 Dec 2022 11:47:06 +0100 From: Johan Hovold To: Mark Brown Cc: Liam Girdwood , Maciej Purski , Dmitry Osipenko , linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org Subject: [PATCH] regulator: core: fix deadlock on regulator enable Date: Thu, 15 Dec 2022 11:46:46 +0100 Message-Id: <20221215104646.19818-1-johan+linaro@kernel.org> X-Mailer: git-send-email 2.37.4 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When updating the operating mode as part of regulator enable, the caller has already locked the regulator tree and drms_uA_update() must not try to do the same in order not to trigger a deadlock. The lock inversion is reported by lockdep as: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D WARNING: possible circular locking dependency detected 6.1.0-next-20221215 #142 Not tainted ------------------------------------------------------ udevd/154 is trying to acquire lock: ffffc11f123d7e50 (regulator_list_mutex){+.+.}-{3:3}, at: regulator_lock_d= ependent+0x54/0x280 but task is already holding lock: ffff80000e4c36e8 (regulator_ww_class_acquire){+.+.}-{0:0}, at: regulator_= enable+0x34/0x80 which lock already depends on the new lock. ... Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock(regulator_ww_class_acquire); lock(regulator_list_mutex); lock(regulator_ww_class_acquire); lock(regulator_list_mutex); *** DEADLOCK *** just before probe of a Qualcomm UFS controller (occasionally) deadlocks when enabling one of its regulators. Fixes: 9243a195be7a ("regulator: core: Change voltage setting path") Fixes: f8702f9e4aa7 ("regulator: core: Use ww_mutex for regulators locking") Cc: stable@vger.kernel.org # 5.0 Signed-off-by: Johan Hovold --- drivers/regulator/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 729c45393803..ae69e493913d 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1002,7 +1002,7 @@ static int drms_uA_update(struct regulator_dev *rdev) /* get input voltage */ input_uV =3D 0; if (rdev->supply) - input_uV =3D regulator_get_voltage(rdev->supply); + input_uV =3D regulator_get_voltage_rdev(rdev->supply->rdev); if (input_uV <=3D 0) input_uV =3D rdev->constraints->input_uV; =20 --=20 2.37.4