From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Johannes Berg <johannes@sipsolutions.net>,
Greg KH <gregkh@suse.de>,
Andrew Morton <akpm@linux-foundation.org>,
Len Brown <lenb@kernel.org>, Ingo Molnar <mingo@elte.hu>,
ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
pm list <linux-pm@lists.linux-foundation.org>
Subject: Re: [PATCH] PM: Acquire device locks on suspend
Date: Mon, 7 Jan 2008 21:37:42 +0100 [thread overview]
Message-ID: <200801072137.43401.rjw@sisk.pl> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0801071412530.6739-100000@iolanthe.rowland.org>
On Monday, 7 of January 2008, Alan Stern wrote:
> On Mon, 7 Jan 2008, Rafael J. Wysocki wrote:
>
> > On Monday, 7 of January 2008, Alan Stern wrote:
> > > On Mon, 7 Jan 2008, Rafael J. Wysocki wrote:
> > >
> > > > Please see the patch at: http://lkml.org/lkml/2008/1/6/298 . It represents my
> > > > current idea about how to do that.
> > >
> > > It has some problems.
> > >
> > > First, note that the list manipulations in dpm_suspend(),
> > > device_power_down(), and so on aren't protected by dpm_list_mtx. So
> > > your patch could corrupt the list pointers.
> >
> > Yes, they need the locking. I have overlooked that, mostly because the locking
> > was removed by gregkh-driver-pm-acquire-device-locks-prior-to-suspending.patch
> > too (because you assumed there woundn't be any need to remove a device during
> > a suspend, right?).
>
> Right.
>
> > > Are you assuming that no other threads can be running at this time?
> >
> > No, I'm not.
> >
> > > Note also that device_pm_destroy_suspended() does up(&dev->sem), but it
> > > doesn't know whether or not dev->sem was locked to begin with.
> >
> > Do you mean it might have been released already by another thread
> > calling device_pm_destroy_suspended() on the same device?
>
> I was thinking that it might be called before lock_all_devices().
I've added pm_sleep_start_end_mtx and the locking dance in
device_pm_destroy_suspended() specifically to prevent this from happening.
> However let's ignore that possibility and simplify the discussion by
> assuming that destroy_suspended_device() is never called except by a
> suspend or resume method for that device or one of its ancestors.
It may also be called by one of the CPU hotplug notifiers.
> (This still leaves the possibility that it might get called by mistake
> during a runtime suspend or resume...)
>
> > > Do you want to rule out the possibility of a driver's suspend or remove
> > > methods calling destroy_suspended_device() on its own device? With
> > > your synchronous approach, this would mean that the suspend/resume
> > > method would indirectly end up calling the remove method. This is
> > > dangerous at best; with USB it would be a lockdep violation. With an
> > > asynchronous approach, on the other hand, this wouldn't be a problem.
> >
> > Well, the asynchronous apprach has the problem that the device may end up
> > on a wrong list when removed by one of the .suspend() callbacks (and I don't
> > see how to avoid that without extra complexity). Perhaps that's something we
> > can live with, though.
>
> The same problem affects the synchronous approach.
No, it doesn't as of the $subject patch (the list_empty() tests should help).
> We can fix it by having dpm_suspend() do the list_move() before calling
> suspend_device(). Then if the suspend fails move the device back.
Yes, we can.
> > One more question: is there any particular reason not to call
> > device_pm_remove() at the beginning of device_del()?
>
> I think it's done this way to avoid having a window where the device
> isn't on a PM list and is still owned by the bus and the driver. But
> if a suspend occurs during that window, it shouldn't matter that the
> device will be left unsuspended. After all, the same thing would have
> happened if the suspend occurred after bus_remove_device().
>
> So no, there shouldn't be a problem with moving the call.
Okay, well, now I'm leaning towards the asynchronous approach.
I'll prepare a new patch and send it later today.
Thanks,
Rafael
next prev parent reply other threads:[~2008-01-07 20:35 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-05 18:36 [PATCH] PM: Acquire device locks on suspend Rafael J. Wysocki
2008-01-05 20:08 ` Alan Stern
2008-01-05 20:19 ` Rafael J. Wysocki
2008-01-05 20:39 ` Alan Stern
2008-01-05 21:13 ` Rafael J. Wysocki
2008-01-05 21:41 ` Alan Stern
2008-01-05 21:58 ` Rafael J. Wysocki
2008-01-06 4:04 ` Alan Stern
2008-01-06 13:19 ` Rafael J. Wysocki
2008-01-06 17:06 ` Alan Stern
2008-01-06 19:05 ` Rafael J. Wysocki
2008-01-06 19:57 ` Rafael J. Wysocki
2008-01-06 22:19 ` Rafael J. Wysocki
2008-01-06 22:21 ` Alan Stern
2008-01-06 22:34 ` Rafael J. Wysocki
2008-01-06 22:39 ` Alan Stern
2008-01-06 22:47 ` Rafael J. Wysocki
2008-01-06 23:46 ` Johannes Berg
[not found] ` <49505.::ffff:91.5.86.36.1199663162.squirrel@secure.sipsolutions.net>
2008-01-06 23:59 ` [linux-pm] " Rafael J. Wysocki
2008-01-07 0:49 ` Rafael J. Wysocki
2008-01-07 16:16 ` Alan Stern
2008-01-07 16:51 ` Rafael J. Wysocki
2008-01-07 17:23 ` Alan Stern
2008-01-07 18:01 ` Rafael J. Wysocki
2008-01-07 19:29 ` Alan Stern
2008-01-07 20:37 ` Rafael J. Wysocki [this message]
2008-01-07 21:32 ` Alan Stern
2008-01-08 0:25 ` Rafael J. Wysocki
2008-01-09 21:01 ` Alan Stern
2008-01-09 22:14 ` Rafael J. Wysocki
2008-01-09 22:46 ` Alan Stern
2008-01-09 23:29 ` Rafael J. Wysocki
2008-01-10 15:35 ` Alan Stern
2008-01-10 16:59 ` Rafael J. Wysocki
2008-01-10 17:04 ` Alan Stern
2008-01-06 22:11 ` Alan Stern
2008-01-06 22:24 ` Rafael J. Wysocki
2008-01-06 22:31 ` Alan Stern
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=200801072137.43401.rjw@sisk.pl \
--to=rjw@sisk.pl \
--cc=akpm@linux-foundation.org \
--cc=gregkh@suse.de \
--cc=johannes@sipsolutions.net \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@lists.linux-foundation.org \
--cc=mingo@elte.hu \
--cc=stern@rowland.harvard.edu \
/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