From patchwork Thu Dec 15 10:46:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 33571 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp277949wrn; Thu, 15 Dec 2022 02:57:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf67ZkOcSwyfhVSSzO1BjyeTdebD4SkODpp8ghdc20quSuY4N//FBqy2ZjiExv9IJfZuTg69 X-Received: by 2002:a05:6402:1158:b0:46d:6f14:aec with SMTP id g24-20020a056402115800b0046d6f140aecmr24906217edw.0.1671101843502; Thu, 15 Dec 2022 02:57:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671101843; cv=none; d=google.com; s=arc-20160816; b=j1U2zE1E1pEzCZYiiNQB+AKYx+5KQK/ynk6fXR7MyjFTm6m/LTvYgAk0b2l+D6RMKX Ob/WwOiyk1aia4crGS/kOaerdw8U8z6uwK78wPW7Lc605Io2RF+IEvdCFtpXPiCPT7WB ZuqfxuyUfSRPSncRmV4nWg1sRaovtq4aVrWmmNhry+zWvpWMDFXJeQW3qNsumdvRc+R2 A+9PxYXLpNk5Emc4XfQpzEON5K8IwkGhDosDhAtbt6gt01EcJS2w5IW2vyrZyVv90BZD 4vf++7+lmTqy0UxGnF/7DfcEwxxLJJs5fGu1f+SbB89HlxjhA1mDrCfRXs3WwIKrASr5 te3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=m2539ZhaVRmakK2iyBTdlwPB6p0u6K8KOiTWWYuwMgg=; b=TtWIcvAkaoGF6y3HzUnBzQ7gAtfWIxjpv/WH7WCDpP75V0Vl9VkOnT7Y1J64asAIyT nIp4YUq4/TKMTPLmT0J0ZZ2QB0O9Ncs5p21029f6SP6yMMt8l6txgaWRXKngZDpy6qfs r2Vd/kOcvwidM4lz4OqJe358DKkOLiZP5owhxlpLmBiPkUfOmFlymWmqCwZLcVrbb7z+ NDKneS0vkZagmeymjhhflwB4sNBuiUj2DdnAhQSkPxq+wBDH/QZrF+hqXhzdoSujjXfn 6QxZKh2+FyJVR4cloR+V+AxCs8Qtr7hTUw8fLrRvbpGNuyPhjoavF7a69EfBI9shDEe3 YImg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=p1bVSMqr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w17-20020a056402269100b0046fbd0828aesi12210844edd.147.2022.12.15.02.57.00; Thu, 15 Dec 2022 02:57:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=p1bVSMqr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230161AbiLOKqi (ORCPT + 99 others); Thu, 15 Dec 2022 05:46:38 -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 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752277286760850854?= X-GMAIL-MSGID: =?utf-8?q?1752277286760850854?= 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: ====================================================== 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_dependent+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 = 0; if (rdev->supply) - input_uV = regulator_get_voltage(rdev->supply); + input_uV = regulator_get_voltage_rdev(rdev->supply->rdev); if (input_uV <= 0) input_uV = rdev->constraints->input_uV;