From: Saravana Kannan <skannan@codeaurora.org>
To: Prarit Bhargava <prarit@redhat.com>
Cc: Viresh Kumar <viresh.kumar@linaro.org>,
Stephen Boyd <sboyd@codeaurora.org>,
"Rafael J. Wysocki" <rjw@rjwysocki.net>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Lenny Szubowicz <lszubowi@redhat.com>,
"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>
Subject: Re: [PATCH] cpufreq, store_scaling_governor requires policy->rwsem to be held for duration of changing governors [v2]
Date: Thu, 14 Aug 2014 11:16:40 -0700 [thread overview]
Message-ID: <53ECFD08.5060605@codeaurora.org> (raw)
In-Reply-To: <53EBC332.30507@redhat.com>
On 08/13/2014 12:57 PM, Prarit Bhargava wrote:
>
>
> On 08/05/2014 06:51 PM, Saravana Kannan wrote:
>
>>
>> I definitely have a fix for this and the original race you reported. It's
>> basically reverting that commit you reverted + a fix for the deadlock. That's
>> the only way to fix the scaling_governor issue.
>>
>> You fix the deadlock by moving the governor attribute group removing to the
>> framework code and doing it before STOP+EXIT to governor without holding the
>> policy lock. And the reverse for INIT+STOP.
>>
>
> I'm still not convinced of the deadlock so I did a bit of additional research
> and am pretty close to saying that this is a false positive from the lockdep
> code in the kernfs area.
>
> A few things that have caused me concern about the lockdep splat we're seeing:
>
> 1. The splat occurs when we hit __kernfs_remove+0x25b/0x360 which resolves to
>
> if (kernfs_lockdep(kn)) {
> rwsem_acquire(&kn->dep_map, 0, 0, _RET_IP_); <<< RIGHT HERE
> if (atomic_read(&kn->active) != KN_DEACTIVATED_BIAS)
> lock_contended(&kn->dep_map, _RET_IP_);
> }
>
> ie) the *ONLY* way we hit a "deadlock" in this code is if we have LOCKDEP
> configured in the kernfs.
>
> It should be noted, that having kernfs_lockdep() always return 0 [1], results in
> NO additional lockdep warnings.
>
> Additionally the splat contains
>
> [ 107.428421] CPU0 CPU1
> [ 107.433482] ---- ----
> [ 107.438544] lock(&policy->rwsem);
> [ 107.442459] lock(s_active#98);
> [ 107.448916] lock(&policy->rwsem);
> [ 107.455650] lock(s_active#98);
>
> which also points to the situation above (s_active is the default naming used in
> the kernfs lockdep code).
>
> In short -- there is no deadlock here. It only happens in the lockdep code
> itself, not because lockdep has identified a real problem.
>
> 2. I then started asking myself why this was occurring. The reason appears to
> be that the attribute for scaling_governor is deleting other sysfs attributes
> and that got me to wondering if there were other areas where this occurred and I
> remembered it does! In the USB code writing and reading to the bConfiguration
> of a device may lead to the removal of "down stream" attributes. The reading
> and writing of bConfiguration occurs in
> drivers/usb/core/sysfs.c:79
>
>
> /* configuration value is always present, and r/w */
> usb_actconfig_show(bConfigurationValue, "%u\n");
>
> static ssize_t bConfigurationValue_store(struct device *dev,
> struct device_attribute *attr,
> const char *buf, size_t count)
> {
> struct usb_device *udev = to_usb_device(dev);
> int config, value;
>
> if (sscanf(buf, "%d", &config) != 1 || config < -1 || config > 255)
> return -EINVAL;
> usb_lock_device(udev);
> value = usb_set_configuration(udev, config);
> usb_unlock_device(udev);
> return (value < 0) ? value : count;
> }
>
> ... and the next lines are IMO important here:
>
> static DEVICE_ATTR_IGNORE_LOCKDEP(bConfigurationValue, S_IRUGO | S_IWUSR,
> bConfigurationValue_show, bConfigurationValue_store);
>
> FWIW, it isn't *exactly* the same ... but commit
> 356c05d58af05d582e634b54b40050c73609617b explains a similarity between what is
> happening with our lockdep splat and the lockdep issues seen in USB.
This seems VERY different from our situation. I don't see an equivalent
of a policy lock that's grabbed from both threads, but in opposite order.
If I'm not mistaken, the sysfs entry here uses some wait/complete pair
to wait for something. But that's an equivalent of a semaphore with max
count of 1. Lockdep just seems to be making it obvious by adding
semaphore calls.
So, a semaphore equivalent deadlock with another semaphore. I believe
this is a read deadlock.
-Saravana
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
next prev parent reply other threads:[~2014-08-14 18:16 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-29 11:46 [PATCH] cpufreq, store_scaling_governor requires policy->rwsem to be held for duration of changing governors [v2] Prarit Bhargava
2014-07-30 0:03 ` Rafael J. Wysocki
2014-07-30 14:18 ` Prarit Bhargava
2014-07-30 21:40 ` Rafael J. Wysocki
2014-07-31 1:36 ` Saravana Kannan
2014-07-31 2:16 ` Rafael J. Wysocki
2014-07-31 2:07 ` Saravana Kannan
2014-07-31 10:16 ` Prarit Bhargava
2014-07-31 10:21 ` Prarit Bhargava
2014-07-31 10:23 ` Prarit Bhargava
2014-07-31 16:36 ` Rafael J. Wysocki
2014-07-31 17:57 ` Prarit Bhargava
2014-07-31 18:38 ` Rafael J. Wysocki
2014-07-31 18:26 ` Prarit Bhargava
2014-07-31 20:24 ` Saravana Kannan
2014-07-31 20:30 ` Prarit Bhargava
2014-07-31 20:38 ` Saravana Kannan
2014-07-31 21:08 ` Prarit Bhargava
2014-07-31 22:13 ` Saravana Kannan
2014-07-31 22:58 ` Prarit Bhargava
2014-08-01 0:55 ` Saravana Kannan
2014-08-01 10:24 ` Prarit Bhargava
2014-08-01 10:27 ` Prarit Bhargava
2014-08-01 17:18 ` Stephen Boyd
2014-08-01 19:15 ` Prarit Bhargava
2014-08-01 19:36 ` Stephen Boyd
2014-08-01 19:43 ` Prarit Bhargava
2014-08-01 19:54 ` Stephen Boyd
2014-08-01 21:25 ` Saravana Kannan
2014-08-04 10:11 ` Prarit Bhargava
2014-08-05 7:46 ` Viresh Kumar
2014-08-05 10:47 ` Prarit Bhargava
2014-08-05 10:53 ` Viresh Kumar
2014-08-05 22:06 ` Saravana Kannan
2014-08-05 22:20 ` Prarit Bhargava
2014-08-05 22:40 ` Saravana Kannan
2014-08-05 22:42 ` Prarit Bhargava
2014-08-05 22:51 ` Saravana Kannan
2014-08-13 19:57 ` Prarit Bhargava
2014-08-14 18:16 ` Saravana Kannan [this message]
2014-08-06 8:10 ` Viresh Kumar
2014-08-06 10:09 ` Prarit Bhargava
2014-08-06 15:08 ` Stephen Boyd
2014-08-07 6:36 ` Viresh Kumar
2014-08-07 10:12 ` Prarit Bhargava
2014-08-07 10:15 ` Viresh Kumar
2014-08-12 9:03 ` Viresh Kumar
2014-08-12 11:33 ` Prarit Bhargava
2014-08-13 7:39 ` Viresh Kumar
2014-08-13 9:58 ` Prarit Bhargava
2014-08-14 4:19 ` Viresh Kumar
2014-08-04 10:36 ` Viresh Kumar
2014-08-04 12:25 ` Prarit Bhargava
2014-08-04 13:38 ` Viresh Kumar
2014-08-04 14:00 ` Prarit Bhargava
2014-08-04 15:04 ` Prarit Bhargava
2014-08-04 20:16 ` Saravana Kannan
2014-08-05 6:14 ` Viresh Kumar
2014-08-05 6:29 ` skannan
2014-08-05 6:43 ` Viresh Kumar
2014-10-13 10:43 ` Viresh Kumar
2014-10-13 11:52 ` Prarit Bhargava
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=53ECFD08.5060605@codeaurora.org \
--to=skannan@codeaurora.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lszubowi@redhat.com \
--cc=prarit@redhat.com \
--cc=rjw@rjwysocki.net \
--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).