public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: pm list <linux-pm@lists.linux-foundation.org>,
	ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
	Greg KH <greg@kroah.com>, Len Brown <lenb@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Alexey Starikovskiy <astarikovskiy@suse.de>,
	David Brownell <david-b@pacbell.net>, Pavel Machek <pavel@ucw.cz>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>
Subject: Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 3)
Date: Mon, 24 Mar 2008 22:18:46 +0100	[thread overview]
Message-ID: <200803242218.47898.rjw@sisk.pl> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0803241519090.24400-100000@iolanthe.rowland.org>

On Monday, 24 of March 2008, Alan Stern wrote:
> On Mon, 24 Mar 2008, Rafael J. Wysocki wrote:
> 
> > Hi,
> > 
> > This is the 3rd revision of the patch introducing new callbacks for suspend
> > and hibernation.  It has been tested on x86-64.
> ...
> > * The registrations of parentless devices are disabled before the first
> >   ->prepare() method is called and enabled before the first ->resume() method
> >   is called
> 
> It would be okay to wait until after the last prepare() method is
> called.  I don't know if it makes any difference in the end, however.
> 
> > +enum dpm_state {
> > +	DPM_ON,
> > +	DPM_RESUMING,
> > +	DPM_SUSPENDING,
> > +	DPM_OFF,
> > +	DPM_OFF_IRQ,
> > +};
> 
> Can we also have a DPM_PREPARING state, set when ->prepare() is about
> to be called?  The PM core wouldn't make use of it but some drivers
> would.  (I can't think of any use at all for the analogous
> DPM_COMPLETING state, however.)

Hmm.  dev->power.status is protected by dpm_list_mtx.  Do you think it would be
useful to have an accessor function for reading it under the lock?

> > @@ -68,22 +59,30 @@ int device_pm_add(struct device *dev)
> ...
> > +	if (dev->parent) {
> > +		if (dev->parent->power.status > DPM_RESUMING) {
> 
> Clearer to say: if (dev->parent->power.status >= DPM_SUSPENDING) {

OK

> ...
> > +	} else if (transition_started) {
> > +		/*
> > +		 * We refuse to register parentless devices while a PM
> > +		 * transition is in progress in order to avoid leaving them
> > +		 * unhandled down the road
> > +		 */
> 
> Log a warning here?  If this ever happened, it would be the sort of 
> unexpected regression that people get all excited about.

The WARN_ON() below 'Refuse' will trigger.  I think that's sufficient.

> > +		goto Refuse;
> >  	}
> ...
> 
> > +static void dpm_resume(pm_message_t state)
> > +{
> > +	struct list_head list;
> > +
> > +	INIT_LIST_HEAD(&list);
> > +	mutex_lock(&dpm_list_mtx);
> > +	transition_started = false;
> > +	while (!list_empty(&dpm_list)) {
> > +		struct device *dev = to_device(dpm_list.next);
> > +
> > +		if (dev->power.status > DPM_SUSPENDING) {
> 
> Clearer to say: if (dev->power.status >= DPM_OFF) {

OK
 
> Note that if dev->power.status is equal to DPM_SUSPENDING then you 
> don't want to call resume_device(), but you still do want to change 
> dev->power.status to DPM_RESUMING so that new children can be 
> registered.

Ah, I overlooked that.  Will fix.

> > +			dev->power.status = DPM_RESUMING;
> > +			get_device(dev);
> > +			mutex_unlock(&dpm_list_mtx);
> > +
> > +			resume_device(dev, state);
> > +
> > +			mutex_lock(&dpm_list_mtx);
> > +			put_device(dev);
> > +		}
> > +		if (!list_empty(&dev->power.entry))
> > +			list_move_tail(&dev->power.entry, &list);
> 
> A little problem here: You refer to dev after calling put_device().

The device can't be removed at this point, because we hold dpm_list_mtx, which
is needed by device_del().  Still, I'll move the put_device() to avoid
confusion (as well as in all of the other places).

> > +	}
> > +	list_splice(&list, &dpm_list);
> 
> This isn't the way I imagined doing it (your extra "list"), but it's 
> fine.
> 
> ...
> > +static void dpm_complete(pm_message_t state)
> >  {
> ...
> > +			complete_device(dev, state);
> > +
> > +			mutex_lock(&dpm_list_mtx);
> > +			put_device(dev);
> > +		}
> > +		if (!list_empty(&dev->power.entry))
> > +			list_move(&dev->power.entry, &list);
> 
> Same problem with use-after-put.  Also present in dpm_prepare().
> 
> >  	}
> > +	list_splice(&list, &dpm_list);
> >  	mutex_unlock(&dpm_list_mtx);
> >  }
> 
> ...
> >  static int dpm_suspend(pm_message_t state)
> >  {
> ...
> >  		error = suspend_device(dev, state);
> > +
> >  		mutex_lock(&dpm_list_mtx);
> > +		put_device(dev);
> >  		if (error) {
> >  			printk(KERN_ERR "Could not suspend device %s: "
> > -					"error %d%s\n",
> > -					kobject_name(&dev->kobj),
> > -					error,
> > -					(error == -EAGAIN ?
> > -					" (please convert to suspend_late)" :
> > -					""));
> > -			dev->power.sleeping = false;
> > +				"error %d\n", kobject_name(&dev->kobj), error);
> > +			list_splice_init(&dpm_list, &list);
> >  			break;
> >  		}
> > -		if (!list_empty(&dev->power.entry))
> > -			list_move(&dev->power.entry, &dpm_off);
> > +		if (!list_empty(&dev->power.entry)) {
> > +			dev->power.status = DPM_OFF;
> > +			list_move(&dev->power.entry, &list);
> > +		}
> 
> Use-after-put again.
> 
> >  	}
> > -	if (!error)
> > -		all_sleeping = true;
> > +	list_splice(&list, &dpm_list);
> 
> Instead you could eliminate the list_splice_init() above and put here:
> 
> 	list_splice(&list, dpm_list->prev);
> 
> This will move the entries from list to the end of dpm_list.

dpm_list may be empty at this point.  Wouldn't that cause any trouble?

> >  	mutex_unlock(&dpm_list_mtx);
> > +	return error;
> > +}
> 
> On the whole it looks quite good.

Okay, thanks for the comments.

Rafael

  reply	other threads:[~2008-03-24 21:19 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-24 17:39 [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 3) Rafael J. Wysocki
2008-03-24 20:14 ` Alan Stern
2008-03-24 21:18   ` Rafael J. Wysocki [this message]
2008-03-25 15:06     ` Alan Stern
2008-03-25 20:35       ` Rafael J. Wysocki
2008-03-26 14:03         ` Alan Stern
2008-03-26 20:26           ` Rafael J. Wysocki
2008-03-26 20:36             ` Alan Stern
2008-03-26 20:54               ` Rafael J. Wysocki
2008-03-24 22:18   ` Rafael J. Wysocki
2008-03-25 11:55     ` Oliver Neukum
2008-03-25 12:40       ` Rafael J. Wysocki
2008-03-25 13:37         ` Oliver Neukum
2008-03-25 14:24           ` Alan Stern
2008-03-25 14:29         ` Alan Stern
2008-03-25 15:12     ` Alan Stern
2008-03-25 20:39       ` 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=200803242218.47898.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=astarikovskiy@suse.de \
    --cc=benh@kernel.crashing.org \
    --cc=david-b@pacbell.net \
    --cc=greg@kroah.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=pavel@ucw.cz \
    --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