From: David Collins <collinsd@codeaurora.org>
To: Mark Brown <broonie@kernel.org>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Krzysztof Kozlowski <krzk@kernel.org>,
Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
'Linux Samsung SOC' <linux-samsung-soc@vger.kernel.org>
Subject: Re: [PATCH] regulator: core: avoid regulator_resolve_supply() race condition
Date: Fri, 22 Jan 2021 17:54:56 -0800 [thread overview]
Message-ID: <5d02de1f-a6f4-c564-6738-2ca46b5d5cc0@codeaurora.org> (raw)
In-Reply-To: <e7e4b633-21cb-54e6-f75c-fac28147396c@samsung.com>
Hello Mark,
On 1/21/21 12:30 PM, Marek Szyprowski wrote:
> Hi Mark,
>
> On 21.01.2021 16:44, Mark Brown wrote:
>> On Thu, Jan 21, 2021 at 10:41:59AM +0100, Marek Szyprowski wrote:
>>> On 18.01.2021 21:49, Mark Brown wrote:
>>>> Does this help (completely untested):
>>> Sadly nope. I get same warning:
>> Try this instead:
>>
>> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
>> index 3ae5ccd9277d..31503776dbd7 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;
>>
>> - /*
>> - * 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 = regulator_dev_lookup(dev, rdev->supply_name);
>> if (IS_ERR(r)) {
>> ret = PTR_ERR(r);
>> @@ -1885,12 +1874,29 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
>> goto out;
>> }
>>
>> + /*
>> + * 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) {
>> + regulator_unlock(rdev);
>> + put_device(&r->dev);
>> + return ret;
>> + }
>> +
>> ret = set_supply(rdev, r);
>> if (ret < 0) {
>> + regulator_unlock(rdev);
>> put_device(&r->dev);
>> - goto out;
>> + return ret;
>> }
>>
>> + regulator_unlock(rdev);
>> +
>> /*
>> * In set_machine_constraints() we may have turned this regulator on
>> * but we couldn't propagate to the supply if it hadn't been resolved
>> @@ -1901,12 +1907,11 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
>> if (ret < 0) {
>> _regulator_put(rdev->supply);
>> rdev->supply = NULL;
>> - goto out;
>> + goto out_rdev_lock;
>
> drivers/regulator/core.c:1910:4: error: label ‘out_rdev_lock’ used but
> not defined
>
>> }
>> }
>>
>> out:
>> - regulator_unlock(rdev);
>> return ret;
>> }
>>
>
> It looks that it finally fixes the locking issue, with the above goto
> removed completely to fix build. Feel free to add:
>
> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
>
> Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Thank you for making this fix. I'm sorry that I missed the potential
deadlock issue resulting from the regulator_enable() call inside
regulator_resolve_supply() with rdev->mutex locked. Your fix avoids
deadlock while still ensuring that the there isn't a set supply race
condition.
Take care,
David
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
prev parent reply other threads:[~2021-01-23 1:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-08 1:16 [PATCH] regulator: core: avoid regulator_resolve_supply() race condition David Collins
2021-01-11 16:28 ` Mark Brown
[not found] ` <CGME20210112213419eucas1p24231e4d0ac11c31184f2f8f3f20cbd9d@eucas1p2.samsung.com>
2021-01-12 21:34 ` Marek Szyprowski
2021-01-18 11:41 ` Naresh Kamboju
2021-01-18 20:49 ` Mark Brown
2021-01-21 9:41 ` Marek Szyprowski
2021-01-21 15:44 ` Mark Brown
2021-01-21 20:30 ` Marek Szyprowski
2021-01-23 1:54 ` David Collins [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=5d02de1f-a6f4-c564-6738-2ca46b5d5cc0@codeaurora.org \
--to=collinsd@codeaurora.org \
--cc=b.zolnierkie@samsung.com \
--cc=broonie@kernel.org \
--cc=krzk@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
/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;
as well as URLs for NNTP newsgroup(s).