Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2268054pxb; Mon, 18 Jan 2021 12:55:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJy2ze1wdKbhMbbHl8iMDp9YJxmVsrL/knEJgw2wf0YW4wYAED0viYQxfKk7fVJL4UUCrPLP X-Received: by 2002:a17:906:4d19:: with SMTP id r25mr937837eju.148.1611003331274; Mon, 18 Jan 2021 12:55:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611003331; cv=none; d=google.com; s=arc-20160816; b=OLQCBWhIRShie0yUowqLY5I7GqVn8tTQ84Eci/v3pQYscmDZqLMq0AqjqGuKwqn1dE iytaLtKSoiv+yd9z0Ole2Yb1tyBdTZbKfydbvP9mDJFJaXrZ+rUlpzXV3I9/qZQAefjo iMgHl4u284h6gZjth+BItMrRHEt0JnN7hhnnMxMcm2jI3hzzMTyv8vWH3cp60mmQjEbQ 9I2W7qFn+iQMbceK1bWwfnKN1iqqkZ3GvGfGU1y1aKgwCAYtFcSQCyMG7mdQStlDYN+5 p7BuwajIkYuVYa6D1ZRZelKqB2L9323iNfiOpqrktFoQ896xtsRZDngMFp3pM2BzpabV Q0mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=QxjAMzXlHwQ1aMmNP10fPAec/Ssmv9xxoI9SiIW1ZPM=; b=OJGswBGdHpso6wgNBlM4R537UfGn9eXm1LeISqbPFXaPSxDBDMf8qlkoX9YUA5pp9+ H768GX6xQact7JetIOvHU0UBJZ884yqSYzqvRjFPYaaURFOoWvRvcTIgScfVtlguR/6q DPULhyEQuOsvIWpKv8aad5LTtceoPKXmmGiQx/ZecE7GH/DFo9Ou8hA5nHEzjne/VILm 7oiJP2O0nBrc8E1g2S2z2KPqznWdkCqJ2KZ/cPOcZgcb9ACT5XhurWRpNV8A4dbCg7jX 1rFiPMLe/aVyn2+IN9/jP+p9OoHCrOBzY1jIshVREOyRnuHfCWZvLF4z5eVEeLxq5GKK /Ghg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CkmLWexm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p19si4002483eji.91.2021.01.18.12.55.06; Mon, 18 Jan 2021 12:55:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CkmLWexm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S2393981AbhARUw2 (ORCPT + 99 others); Mon, 18 Jan 2021 15:52:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:57256 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394500AbhARUvQ (ORCPT ); Mon, 18 Jan 2021 15:51:16 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 514F922472; Mon, 18 Jan 2021 20:50:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611003035; bh=H6UA6H2/Zi55Qt8ytYHm/E7q9Vp1onaV0E/AF6oYJYQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=CkmLWexmoNM7iPlrtWvRf55xgaUNPBhx7/k2XhbW86TVkljF2qhTHgM3VDUndPL8r LdkZ++eR/I/JL9F9EcfLTTyBuW3i+La/Wvru/ZbrT69zddCz9sHZKnvm3RSUFLJf9C SC2lF4H/ouOBMX1DaaiWYEsenI7YulPX7ZWig6XQ+26CsNr6olDtXRyRHo4Qe1101U 7TN95vCrEI+2e4HUD62ZzDmkIiM1RRIPsDq0v5AEx4Q1WoIAxDkgsLrsaOdBmSQChV ypDJHmdWeN/9Hs8bS9Hvcz5MIlcyjSR/zXpBAkxswhBpHqYDGTMO6hUKrccRdPBFjH CevvUYW+zIzVw== Date: Mon, 18 Jan 2021 20:49:58 +0000 From: Mark Brown To: Marek Szyprowski Cc: David Collins , Liam Girdwood , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, 'Linux Samsung SOC' Subject: Re: [PATCH] regulator: core: avoid regulator_resolve_supply() race condition Message-ID: <20210118204958.GS4455@sirena.org.uk> References: <1610068562-4410-1-git-send-email-collinsd@codeaurora.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="GIP5y49pbaVPin6k" Content-Disposition: inline In-Reply-To: X-Cookie: Huh? User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --GIP5y49pbaVPin6k Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jan 12, 2021 at 10:34:19PM +0100, Marek Szyprowski wrote: > =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 > 5.11.0-rc1-00008-geaa7995c529b #10095 Not tainted > ------------------------------------------------------ > swapper/0/1 is trying to acquire lock: > c12e1b80 (regulator_list_mutex){+.+.}-{3:3}, at:=20 > regulator_lock_dependent+0x4c/0x2b0 If you're sending backtraces or other enormous reports like this please run them through addr2line first so that things are a bit more leigible. > but task is already holding lock: > df7190c0 (regulator_ww_class_mutex){+.+.}-{3:3}, at:=20 > regulator_resolve_supply+0x44/0x318 >=20 > which lock already depends on the new lock. Does this help (completely untested): diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 3ae5ccd9277d..7d1422b00974 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1823,17 +1823,6 @@ static int regulator_resolve_supply(struct regulator= _dev *rdev) if (rdev->supply) return 0; =20 - /* - * Recheck rdev->supply with rdev->mutex lock held to avoid a race - * between rdev->supply null check and setting rdev->supply in - * set_supply() from concurrent tasks. - */ - regulator_lock(rdev); - - /* Supply just resolved by a concurrent task? */ - if (rdev->supply) - goto out; - r =3D regulator_dev_lookup(dev, rdev->supply_name); if (IS_ERR(r)) { ret =3D PTR_ERR(r); @@ -1885,10 +1874,23 @@ static int regulator_resolve_supply(struct regulato= r_dev *rdev) goto out; } =20 + /* + * Recheck rdev->supply with rdev->mutex lock held to avoid a race + * between rdev->supply null check and setting rdev->supply in + * set_supply() from concurrent tasks. + */ + regulator_lock(rdev); + + /* Supply just resolved by a concurrent task? */ + if (rdev->supply) { + put_device(&r->dev); + goto out_rdev_lock; + } + ret =3D set_supply(rdev, r); if (ret < 0) { put_device(&r->dev); - goto out; + goto out_rdev_lock; } =20 /* @@ -1901,12 +1903,13 @@ static int regulator_resolve_supply(struct regulato= r_dev *rdev) if (ret < 0) { _regulator_put(rdev->supply); rdev->supply =3D NULL; - goto out; + goto out_rdev_lock; } } =20 -out: +out_rdev_lock: regulator_unlock(rdev); +out: return ret; } =20 --GIP5y49pbaVPin6k Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAmAF9HUACgkQJNaLcl1U h9CSgQf/WxGUC0HwPneU+4CSzLkNnmCkeRj+XD5gX0Z/KEo/1EnY6cg10Cq3ZqBY /OSiMjeamYYf8cALIMT8h5CGcOGiBtQL7AtDP8jtH7+F1hj382DT3wCQQDfjXFgq Wl/NY99d44dNioksuJtz0nGrSOysUmk6UZPLUHSNE4yTZpa6H2m46JMYJ5iBeW44 pF1xsyxsrnPPuuYIY0yZw4CsNmxDAGo/83DWLV+UV9dmjWoL06l9yPWhynCdzcgL LPVM45ZU4+De5CcRlFIH9oAaqzsKHV/Si57rxfdX57GoI/9VYmA2NQXmy0PnNI2h zhUqUHMq71tzxt8AXknhhSk54oVjYw== =1Wmm -----END PGP SIGNATURE----- --GIP5y49pbaVPin6k--