All of lore.kernel.org
 help / color / mirror / Atom feed
From: Todd E Brandt <todd.e.brandt@linux.intel.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: "linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
	Rafael Wysocki <rafael.j.wysocki@intel.com>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	todd.e.brandt@intel.com
Subject: Re: [PATCH v3] PM: check for complete cb before device lock in dpm_complete
Date: Fri, 16 Oct 2015 16:06:03 -0700	[thread overview]
Message-ID: <20151016230603.GA12639@linux.intel.com> (raw)
In-Reply-To: <CAJZ5v0gqUFWfUHRR3Y7t2bnrQjam3m_CHC0aHOSbJNLJZ5ctbQ@mail.gmail.com>

On Sat, Oct 17, 2015 at 12:49:04AM +0200, Rafael J. Wysocki wrote:
> Hi,
> 
> On Sat, Oct 17, 2015 at 12:45 AM, Todd Brandt
> <todd.e.brandt@linux.intel.com> wrote:
> > If a device has no pm_ops complete callback it shouldn't have
> > to be locked in order to skip it in the dpm_complete call. This causes
> > problems when a device without a complete callback has already begun
> > operation after its resume cb is called. It can end up holding up the
> > system resume as the pm subsystem tries to get a device lock just to
> > check for a callback that isn't there.
> >
> > This is basically the original v1 patch but updated for the latest kernel.
> >
> > Signed-off-by: Todd Brandt <todd.e.brandt@linux.intel.com>
> > ---
> >  drivers/base/power/main.c | 12 ++++++------
> >  1 file changed, 6 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> > index 1710c26..9bb8ff0 100644
> > --- a/drivers/base/power/main.c
> > +++ b/drivers/base/power/main.c
> > @@ -899,8 +899,6 @@ static void device_complete(struct device *dev, pm_message_t state)
> >         if (dev->power.syscore)
> >                 return;
> >
> > -       device_lock(dev);
> > -
> >         if (dev->pm_domain) {
> >                 info = "completing power domain ";
> >                 callback = dev->pm_domain->ops.complete;
> > @@ -920,13 +918,15 @@ static void device_complete(struct device *dev, pm_message_t state)
> >                 callback = dev->driver->pm->complete;
> >         }
> >
> > -       if (callback) {
> > -               pm_dev_dbg(dev, state, info);
> > -               callback(dev);
> > -       }
> > +       if (!callback)
> > +               goto Complete;
> >
> 
> Suppose that the devices is unregistered at this point and callback
> was pointing to the driver callback.
> 
> > +       device_lock(dev);
> > +       pm_dev_dbg(dev, state, info);
> > +       callback(dev);
> 
> I don't think it is correct to execute that callback here in that case, is it?

Ahh, so we *should* be worried about an unregister in between the check and the call.
I seem to remember a discussion where this was deemed a non-issue but I must have
misheard (it was a while back).

It sounds to me then that there's just no way to do this safely :(. I'll experiment 
with the i8042 driver to see if theres a way to fix this at a lower level. Thus far
it's the only driver which has this issue.

Thanks for the feedback.

> 
> >         device_unlock(dev);
> >
> > +Complete:
> >         pm_runtime_put(dev);
> >  }
> 
> Thanks,
> Rafael

  reply	other threads:[~2015-10-16 23:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-16 22:45 [PATCH v3] PM: check for complete cb before device lock in dpm_complete Todd Brandt
2015-10-16 22:49 ` Rafael J. Wysocki
2015-10-16 23:06   ` Todd E Brandt [this message]
2015-10-17 15:04     ` Alan Stern
2015-11-29  5:33   ` Dmitry Torokhov
2015-11-30  2:15     ` 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=20151016230603.GA12639@linux.intel.com \
    --to=todd.e.brandt@linux.intel.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rafael@kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=todd.e.brandt@intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.