From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Waiman Long <longman@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
"Rafael J. Wysocki" <rjw@rjwysocki.net>,
Viresh Kumar <viresh.kumar@linaro.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Linux PM <linux-pm@vger.kernel.org>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Subject: Re: [PATCH 2/2] cpufreq: Fix a circular lock dependency problem
Date: Tue, 24 Jul 2018 10:36:13 +0200 [thread overview]
Message-ID: <CAJZ5v0jJzXsKUH+SH5_Qs8C-A2=AdOL_RgOonuv62rx1FBjaYA@mail.gmail.com> (raw)
In-Reply-To: <0306d1b7-85d2-5e50-2b7c-466f0e978afa@redhat.com>
On Mon, Jul 23, 2018 at 9:27 PM, Waiman Long <longman@redhat.com> wrote:
> On 07/23/2018 03:16 PM, Peter Zijlstra wrote:
>> On Mon, Jul 23, 2018 at 01:49:39PM -0400, Waiman Long wrote:
>>> drivers/cpufreq/cpufreq.c | 16 +++++++++++++++-
>>> 1 file changed, 15 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
>>> index b0dfd32..9cf02d7 100644
>>> --- a/drivers/cpufreq/cpufreq.c
>>> +++ b/drivers/cpufreq/cpufreq.c
>>> @@ -922,8 +922,22 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
>>> struct cpufreq_policy *policy = to_policy(kobj);
>>> struct freq_attr *fattr = to_attr(attr);
>>> ssize_t ret = -EINVAL;
>>> + int retries = 3;
>>>
>>> - cpus_read_lock();
>>> + /*
>>> + * cpus_read_trylock() is used here to work around a circular lock
>>> + * dependency problem with respect to the cpufreq_register_driver().
>>> + * With a simple retry loop, the chance of not able to get the
>>> + * read lock is extremely small.
>>> + */
>>> + while (!cpus_read_trylock()) {
>>> + if (retries-- <= 0)
>>> + return -EBUSY;
>>> + /*
>>> + * Sleep for about 50ms and retry again.
>>> + */
>>> + msleep(50);
>>> + }
>> That's atrocious.
>>
>>
> I had thought about just returning an error if the trylock fails as CPU
> hotplug rarely happened. I can revert to that simple case if others have
> no objection.
Yes, you can return -EBUSY or -EAGAIN right away from here if the
cpus_read_trylock() is not successful. There is not much reason for
the sysfs operation to continue in that case.
next prev parent reply other threads:[~2018-07-24 8:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-23 17:49 [PATCH 0/2] cpufreq: Fix a circular lock dependency problem Waiman Long
2018-07-23 17:49 ` [PATCH 1/2] cpu/hotplug: Add a cpus_read_trylock() function Waiman Long
2018-07-23 17:49 ` [PATCH 2/2] cpufreq: Fix a circular lock dependency problem Waiman Long
2018-07-23 19:16 ` Peter Zijlstra
2018-07-23 19:27 ` Waiman Long
2018-07-24 8:36 ` Rafael J. Wysocki [this message]
2018-07-24 8:31 ` Rafael J. Wysocki
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='CAJZ5v0jJzXsKUH+SH5_Qs8C-A2=AdOL_RgOonuv62rx1FBjaYA@mail.gmail.com' \
--to=rafael@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=konrad.wilk@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=rjw@rjwysocki.net \
--cc=tglx@linutronix.de \
--cc=viresh.kumar@linaro.org \
/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).