All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ohad Ben-Cohen <ohad@wizery.com>
To: linux-pm@lists.linux-foundation.org
Cc: linux-mmc@vger.kernel.org, Ido Yariv <ido@wizery.com>
Subject: subtle pm_runtime_put_sync race and sdio functions
Date: Fri, 10 Dec 2010 01:37:02 +0200	[thread overview]
Message-ID: <AANLkTi=6fUeDAJut5tZmB+h9qmEt7gZ13UaOqhAW3XE1__35698.6059145585$1291938007$gmane$org@mail.gmail.com> (raw)

When pm_runtime_put_sync() returns, the _put operation is completed,
and if needed (zero usage_count, children are ignored or their count
is zero, ->runtime_idle() called pm_runtime_suspend(), no
runtime_error, no disable_depth, etc...) the device is powered down.

This behavior is sometimes desirable and even required: drivers may
call pm_runtime_put_sync() and rely on PM core to synchronously power
down the device.

This is usually all good, but when we combine this requirement with
logical sub-devices that cannot be power-managed on their own (e.g.
SDIO functions), things get a bit racy, since their parent is not
suspended synchronously (the sub-device is rpm_suspend()'ed
synchronously, but its parent is pm_request_idle()ed, which is
asynchronous in nature).

Since drivers might rely on pm_runtime_put_sync() to synchronously
power down the device, if that doesn't happen, a rapid subsequent
pm_runtime_get{_sync} might cancel the suspend. This can lead the
driver, e.g., to reinitialize a device that wasn't powered down, and
the results can be fatal.

One possible solution is to call pm_runtime_idle(parent), instead of
pm_request_idle(parent), when a no_callbacks device is suspended:

diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 02c652b..d7659d3 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -407,7 +407,10 @@ static int rpm_suspend(struct device *dev, int rpmflags)
        if (parent && !parent->power.ignore_children) {
                spin_unlock_irq(&dev->power.lock);

-               pm_request_idle(parent);
+               if (dev->power.no_callbacks)
+                       pm_runtime_idle(parent);
+               else
+                       pm_request_idle(parent);

                spin_lock_irq(&dev->power.lock);
        }

This solution assumes that such sub-devices don't really need to have
callbacks of their own. It would work for SDIO, since we are
effectively no_callbacks devices anyway, and it only seems reasonable
to set SDIO functions as no_callbacks devices.

A different, bolder solution, will always call pm_runtime_idle instead
of pm_request_idle (see below): when a device is runtime suspended, it
can't be too bad to immediately send idle notification to its parent,
too. I'm aware this might not always be desirable, but I'm bringing
this up even just for the sake of discussion:

diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 02c652b..9719811 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -407,7 +407,7 @@ static int rpm_suspend(struct device *dev, int rpmflags)
        if (parent && !parent->power.ignore_children) {
                spin_unlock_irq(&dev->power.lock);

-               pm_request_idle(parent);
+               pm_runtime_idle(parent);

                spin_lock_irq(&dev->power.lock);
        }

             reply	other threads:[~2010-12-09 23:37 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-09 23:37 Ohad Ben-Cohen [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-01-27 19:49 [linux-pm] subtle pm_runtime_put_sync race and sdio functions Alan Stern
2011-01-27 20:15 ` Kevin Hilman
2011-01-27 22:18   ` Vitaly Wool
2011-01-27 23:21   ` [linux-pm] " Rafael J. Wysocki
2011-01-27 23:49     ` Kevin Hilman
2011-01-27 23:21   ` Rafael J. Wysocki
2011-01-27 20:15 ` Kevin Hilman
2011-01-27 19:22 [linux-pm] " Kevin Hilman
2011-01-27 19:49 ` Alan Stern
2011-01-27 18:13 [linux-pm] " Alan Stern
2011-01-27 19:22 ` Kevin Hilman
2011-01-27 23:11 ` Rafael J. Wysocki
2010-12-29  8:01 [linux-pm] " Ohad Ben-Cohen
2010-12-30  4:30 ` Alan Stern
2010-12-29  6:34 [linux-pm] " Ohad Ben-Cohen
2010-12-30  4:25 ` Alan Stern
2010-12-28 19:04 [linux-pm] " Ohad Ben-Cohen
2010-12-28 21:46 ` Alan Stern
2010-12-28 21:46 ` [linux-pm] " Alan Stern
2010-12-29  6:34   ` Ohad Ben-Cohen
2010-12-29  8:01   ` Ohad Ben-Cohen
2010-12-25  7:34 [linux-pm] " Ohad Ben-Cohen
2010-12-25 16:21 ` Alan Stern
2010-12-25 20:58   ` Ohad Ben-Cohen
2010-12-25 21:50     ` Vitaly Wool
2010-12-25 21:50     ` [linux-pm] " Vitaly Wool
2010-12-26  5:27       ` Ohad Ben-Cohen
2010-12-25 21:54     ` Vitaly Wool
2010-12-26  2:48     ` [linux-pm] " Alan Stern
2010-12-26  5:55       ` Ohad Ben-Cohen
2010-12-26 11:45         ` Rafael J. Wysocki
2010-12-26 12:43           ` Ohad Ben-Cohen
2010-12-26 12:43           ` [linux-pm] " Ohad Ben-Cohen
2010-12-26 18:35             ` Rafael J. Wysocki
2010-12-28 19:11               ` Ohad Ben-Cohen
2010-12-28 19:11               ` [linux-pm] " Ohad Ben-Cohen
2010-12-28 19:21                 ` Rafael J. Wysocki
2010-12-28 19:21                 ` [linux-pm] " Rafael J. Wysocki
2010-12-28 19:34                   ` Ohad Ben-Cohen
2010-12-28 20:36                     ` Rafael J. Wysocki
2010-12-28 19:34                   ` Ohad Ben-Cohen
2010-12-26 18:35             ` Rafael J. Wysocki
2010-12-26 14:53           ` [linux-pm] " Ohad Ben-Cohen
2010-12-26 18:37             ` Rafael J. Wysocki
2010-12-28 19:15               ` Ohad Ben-Cohen
2010-12-28 20:04                 ` Rafael J. Wysocki
2010-12-28 20:04                 ` [linux-pm] " Rafael J. Wysocki
2010-12-28 20:41                   ` Ohad Ben-Cohen
2010-12-28 19:15               ` Ohad Ben-Cohen
2010-12-26 18:37             ` Rafael J. Wysocki
2010-12-26 14:53           ` Ohad Ben-Cohen
2010-12-26 11:45         ` Rafael J. Wysocki
2010-12-26 17:00         ` [linux-pm] " Alan Stern
2010-12-28 19:04           ` Ohad Ben-Cohen
2010-12-26 17:00         ` Alan Stern
2010-12-26  5:55       ` Ohad Ben-Cohen
2010-12-26  2:48     ` Alan Stern
2010-12-25 20:58   ` Ohad Ben-Cohen
2010-12-25 16:21 ` Alan Stern
2010-12-23  7:51 [linux-pm] " Ohad Ben-Cohen
2010-12-23 16:03 ` Alan Stern
2010-12-23 16:03 ` [linux-pm] " Alan Stern
2010-12-25  7:34   ` Ohad Ben-Cohen
2010-12-22  1:42 [linux-pm] " Alan Stern
2010-12-22 12:29 ` Rafael J. Wysocki
2011-01-26 23:28   ` Kevin Hilman
2011-01-27 18:13     ` Alan Stern
2011-01-27 18:20     ` Vitaly Wool
2011-01-27 18:20     ` [linux-pm] " Vitaly Wool
2011-01-27 18:54       ` Kevin Hilman
2010-12-22 12:29 ` Rafael J. Wysocki
2010-12-21 22:23 [linux-pm] " Kevin Hilman
2010-12-22  1:48 ` Alan Stern
2010-12-21 21:31 [linux-pm] " Rafael J. Wysocki
2010-12-22  1:42 ` Alan Stern
2010-12-21  0:57 [linux-pm] " Alan Stern
2010-12-21 21:31 ` Rafael J. Wysocki
2010-12-20 21:17 [linux-pm] " Rafael J. Wysocki
2010-12-21  0:57 ` Alan Stern
2010-12-20  3:37 [linux-pm] " Alan Stern
2010-12-20 21:17 ` Rafael J. Wysocki
2010-12-18 21:30 [linux-pm] " Alan Stern
2010-12-18 22:57 ` Rafael J. Wysocki
2010-12-11  1:17 [linux-pm] " Ohad Ben-Cohen
2010-12-11 14:53 ` Alan Stern
2010-12-10  0:00 [linux-pm] " Rafael J. Wysocki
2010-12-10 17:24 ` Alan Stern
2010-12-10 17:24 ` [linux-pm] " Alan Stern
2010-12-10 22:01   ` Rafael J. Wysocki
2010-12-10 22:01   ` [linux-pm] " Rafael J. Wysocki
2010-12-10 23:02     ` Ohad Ben-Cohen
2010-12-10 22:59   ` Ohad Ben-Cohen
2010-12-10 22:59   ` [linux-pm] " Ohad Ben-Cohen
2010-12-11  1:17     ` Ohad Ben-Cohen
2010-12-11 14:50     ` Alan Stern
2010-12-18 13:29       ` Ohad Ben-Cohen
2010-12-18 13:29       ` [linux-pm] " Ohad Ben-Cohen
2010-12-18 14:16         ` David Vrabel
2010-12-18 15:12           ` Ohad Ben-Cohen
2010-12-18 14:16         ` David Vrabel
2010-12-18 15:07         ` [linux-pm] " Rafael J. Wysocki
2010-12-18 16:00           ` Ohad Ben-Cohen
2010-12-18 16:00           ` [linux-pm] " Ohad Ben-Cohen
2010-12-18 16:40             ` Johannes Berg
2010-12-18 19:08               ` Ohad Ben-Cohen
2010-12-18 21:30                 ` Alan Stern
2010-12-18 22:52                 ` Rafael J. Wysocki
2010-12-18 19:08               ` Ohad Ben-Cohen
2010-12-18 21:29               ` Alan Stern
2010-12-18 22:50               ` Rafael J. Wysocki
2010-12-18 16:40             ` Johannes Berg
2010-12-18 22:47             ` [linux-pm] " Rafael J. Wysocki
2010-12-19  7:48               ` Ohad Ben-Cohen
2010-12-19 10:22               ` Rafael J. Wysocki
2010-12-19 10:22               ` [linux-pm] " Rafael J. Wysocki
2010-12-20  3:37                 ` Alan Stern
2010-12-21 22:23                 ` Kevin Hilman
2010-12-23  7:51                 ` Ohad Ben-Cohen
2010-12-18 22:47             ` Rafael J. Wysocki
2010-12-18 15:07         ` Rafael J. Wysocki
2010-12-18 21:20         ` [linux-pm] " Alan Stern
2010-12-18 23:03           ` Rafael J. Wysocki
2010-12-19 10:00           ` Ohad Ben-Cohen
2010-12-18 21:20         ` Alan Stern
2010-12-09 23:37 Ohad Ben-Cohen
2010-12-10  0:00 ` 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='AANLkTi=6fUeDAJut5tZmB+h9qmEt7gZ13UaOqhAW3XE1__35698.6059145585$1291938007$gmane$org@mail.gmail.com' \
    --to=ohad@wizery.com \
    --cc=ido@wizery.com \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.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 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.