From: Prarit Bhargava <prarit@redhat.com>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: "Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
"Robert Schöne" <robert.schoene@tu-dresden.de>,
"Stephen Boyd" <sboyd@codeaurora.org>,
"Rafael J. Wysocki" <rjw@rjwysocki.net>,
"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>
Subject: Re: [PATCH 2/5] cpufreq, fix locking around CPUFREQ_GOV_POLICY_EXIT calls
Date: Tue, 11 Nov 2014 07:15:29 -0500 [thread overview]
Message-ID: <5461FDE1.2080302@redhat.com> (raw)
In-Reply-To: <CAKohpomeRivb3TwkeWALL_xsf4gOBPYOnfCNdz2oVvZSAGBP4g@mail.gmail.com>
On 11/10/2014 10:37 PM, Viresh Kumar wrote:
> On 10 November 2014 17:56, Prarit Bhargava <prarit@redhat.com> wrote:
>
>>> I still fail to understand why ? What will the _trylock() change ?
>>
>> viresh, afaict read_trylock will return 0 when busy with write:
>
> Yes..
>
>> static inline int queue_read_trylock(struct qrwlock *lock)
>> {
>> u32 cnts;
>>
>> cnts = atomic_read(&lock->cnts);
>> if (likely(!(cnts & _QW_WMASK))) {
>>
>> so the deadlock will not occur. the show() is opened, write lock is taken, and
>> if the thread is rescheduled and takes read lock the trylock will return 0, and
>> the thread will return -EBUSY to userspace avoiding the deadlock.
>
> Which deadlock?
the deadlock in commit 955ef4833574636819cd269cfbae12f79cbde63a
[ 75.471265] CPU0 CPU1
[ 75.476327] ---- ----
[ 75.481385] lock(&policy->rwsem);
[ 75.485307] lock(s_active#219);
[ 75.491857] lock(&policy->rwsem);
[ 75.498592] lock(s_active#219);
[ 75.502331]
[ 75.502331] *** DEADLOCK ***
And also your changelog talks about accessing invalid pointers
> without the trylock change, how can that be possible? After the read
> lock is taken,
> all the pointers should be valid.
consider the following very simple case:
the governor is ondemand. cpu 0 reads cpuinfo_cur_freq. cpu0 expects to get the
current cpu freq for the ondemand governor.
simultaneously, cpu1 changes the governor from ondemand to userspace.
the two threads will race for the policy->mutex
suppose cpu0 gets it first. then there is no problem. the userspace program
for cpu0 gets exactly the data it is expecting.
Now suppose cpu1 gets the lock and starts to write ... cpu0 is blocked.
cpu1 completes the governor change, and cpu0 gets the mutex ... and returns
bogus data at this point.
P.
>
next prev parent reply other threads:[~2014-11-11 12:15 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1415199239-19019-1-git-send-email-prarit@redhat.com>
2014-11-05 14:53 ` [PATCH 1/5] cpufreq, do not return stale data to userspace Prarit Bhargava
2014-11-05 14:53 ` [PATCH 2/5] cpufreq, fix locking around CPUFREQ_GOV_POLICY_EXIT calls Prarit Bhargava
2014-11-10 10:44 ` Viresh Kumar
2014-11-10 12:26 ` Prarit Bhargava
2014-11-11 3:37 ` Viresh Kumar
2014-11-11 12:15 ` Prarit Bhargava [this message]
2014-11-11 13:07 ` Viresh Kumar
2014-11-13 21:58 ` Saravana Kannan
2014-11-05 14:53 ` [PATCH 3/5] cpufreq, dbs_data->usage count must be atomic Prarit Bhargava
2014-11-08 1:57 ` Rafael J. Wysocki
2014-11-11 3:40 ` Viresh Kumar
2014-11-05 14:53 ` [PATCH 4/5] cpufreq, policy->initialized " Prarit Bhargava
2014-11-08 1:59 ` Rafael J. Wysocki
2014-11-11 3:55 ` Viresh Kumar
2014-11-05 14:53 ` [PATCH 5/5] cpufreq, add BUG() messages in critical paths to aid debugging failures Prarit Bhargava
2014-11-08 2:00 ` Rafael J. Wysocki
2014-11-08 13:33 ` Prarit Bhargava
2014-11-08 21:46 ` Rafael J. Wysocki
2014-11-09 14:12 ` Prarit Bhargava
2014-11-11 4:23 ` Viresh Kumar
2014-11-11 12:18 ` Prarit Bhargava
2014-11-11 13:11 ` Viresh Kumar
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=5461FDE1.2080302@redhat.com \
--to=prarit@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rjw@rjwysocki.net \
--cc=robert.schoene@tu-dresden.de \
--cc=sboyd@codeaurora.org \
--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).