2012-06-20 02:17:17

by Mandeep Baines

[permalink] [raw]
Subject: [PATCH] PM: Prevent waiting forever on asynchronous suspend after abort

__device_suspend() must always send a completion. Otherwise, parent
devices will wait forever.

Commit 1e2ef05b, "PM: Limit race conditions between runtime PM and
system sleep (v2)", introduced a regression by short-circuiting the
complete_all() for certain error cases.

This patch fixes the bug by always signalling a completion.

Addresses http://crosbug.com/31972

Tested by injecting an abort via the following patch:

diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index a004db3..e5a6fce 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -21,6 +21,7 @@
#include <linux/pci.h>
#include <linux/usb.h>
#include <linux/usb/hcd.h>
+#include <linux/string.h>

#include <asm/io.h>
#include <asm/irq.h>
@@ -477,6 +478,8 @@ static int resume_common(struct device *dev, int event)

static int hcd_pci_suspend(struct device *dev)
{
+ if (!strcmp("0000:00:1d.3", dev_name(dev)))
+ return -EBUSY;
return suspend_common(dev, device_may_wakeup(dev));
}

Signed-off-by: Mandeep Singh Baines <[email protected]>
Cc: Rafael J. Wysocki <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Pavel Machek <[email protected]>
Cc: Len Brown <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc: Alan Stern <[email protected]>
Cc: Colin Cross <[email protected]>
Cc: Sameer Nanda <[email protected]>
Cc: Olof Johansson <[email protected]>
---
drivers/base/power/main.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index e0fb5b0..9cb845e 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -1031,7 +1031,7 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
dpm_wait_for_children(dev, async);

if (async_error)
- return 0;
+ goto Complete;

pm_runtime_get_noresume(dev);
if (pm_runtime_barrier(dev) && device_may_wakeup(dev))
@@ -1040,7 +1040,7 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
if (pm_wakeup_pending()) {
pm_runtime_put_sync(dev);
async_error = -EBUSY;
- return 0;
+ goto Complete;
}

device_lock(dev);
@@ -1097,6 +1097,8 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
}

device_unlock(dev);
+
+ Complete:
complete_all(&dev->power.completion);

if (error) {
--
1.7.3.4


2012-06-20 14:58:28

by Alan Stern

[permalink] [raw]
Subject: Re: [PATCH] PM: Prevent waiting forever on asynchronous suspend after abort

On Tue, 19 Jun 2012, Mandeep Singh Baines wrote:

> __device_suspend() must always send a completion. Otherwise, parent
> devices will wait forever.
>
> Commit 1e2ef05b, "PM: Limit race conditions between runtime PM and
> system sleep (v2)", introduced a regression by short-circuiting the
> complete_all() for certain error cases.
>
> This patch fixes the bug by always signalling a completion.
>
> Addresses http://crosbug.com/31972
>
> Tested by injecting an abort via the following patch:
>
> diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
> index a004db3..e5a6fce 100644
> --- a/drivers/usb/core/hcd-pci.c
> +++ b/drivers/usb/core/hcd-pci.c
> @@ -21,6 +21,7 @@
> #include <linux/pci.h>
> #include <linux/usb.h>
> #include <linux/usb/hcd.h>
> +#include <linux/string.h>
>
> #include <asm/io.h>
> #include <asm/irq.h>
> @@ -477,6 +478,8 @@ static int resume_common(struct device *dev, int event)
>
> static int hcd_pci_suspend(struct device *dev)
> {
> + if (!strcmp("0000:00:1d.3", dev_name(dev)))
> + return -EBUSY;
> return suspend_common(dev, device_may_wakeup(dev));
> }

When you include one patch in front of another like this, doesn't it
confuse the automatic tools? You might end up getting both changes
include in the final commit. :-)

> drivers/base/power/main.c | 6 ++++--
> 1 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> index e0fb5b0..9cb845e 100644
> --- a/drivers/base/power/main.c
> +++ b/drivers/base/power/main.c
> @@ -1031,7 +1031,7 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
> dpm_wait_for_children(dev, async);
>
> if (async_error)
> - return 0;
> + goto Complete;
>
> pm_runtime_get_noresume(dev);
> if (pm_runtime_barrier(dev) && device_may_wakeup(dev))
> @@ -1040,7 +1040,7 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
> if (pm_wakeup_pending()) {
> pm_runtime_put_sync(dev);
> async_error = -EBUSY;
> - return 0;
> + goto Complete;
> }
>
> device_lock(dev);
> @@ -1097,6 +1097,8 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
> }
>
> device_unlock(dev);
> +
> + Complete:
> complete_all(&dev->power.completion);
>
> if (error) {

Otherwise this looks right to me.

Acked-by: Alan Stern <[email protected]>

2012-06-20 15:14:03

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH] PM: Prevent waiting forever on asynchronous suspend after abort

On Wed, Jun 20, 2012 at 10:58:25AM -0400, Alan Stern wrote:
> On Tue, 19 Jun 2012, Mandeep Singh Baines wrote:
>
> > __device_suspend() must always send a completion. Otherwise, parent
> > devices will wait forever.
> >
> > Commit 1e2ef05b, "PM: Limit race conditions between runtime PM and
> > system sleep (v2)", introduced a regression by short-circuiting the
> > complete_all() for certain error cases.
> >
> > This patch fixes the bug by always signalling a completion.
> >
> > Addresses http://crosbug.com/31972
> >
> > Tested by injecting an abort via the following patch:
> >
> > diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
> > index a004db3..e5a6fce 100644
> > --- a/drivers/usb/core/hcd-pci.c
> > +++ b/drivers/usb/core/hcd-pci.c
> > @@ -21,6 +21,7 @@
> > #include <linux/pci.h>
> > #include <linux/usb.h>
> > #include <linux/usb/hcd.h>
> > +#include <linux/string.h>
> >
> > #include <asm/io.h>
> > #include <asm/irq.h>
> > @@ -477,6 +478,8 @@ static int resume_common(struct device *dev, int event)
> >
> > static int hcd_pci_suspend(struct device *dev)
> > {
> > + if (!strcmp("0000:00:1d.3", dev_name(dev)))
> > + return -EBUSY;
> > return suspend_common(dev, device_may_wakeup(dev));
> > }
>
> When you include one patch in front of another like this, doesn't it
> confuse the automatic tools? You might end up getting both changes
> include in the final commit. :-)

Yeah, that's going to mess with quilt big time, I don't know what git is
going to do with it, it should be interesting to see...

greg k-h

2012-06-20 16:13:35

by Mandeep Baines

[permalink] [raw]
Subject: [PATCH] PM: Prevent waiting forever on asynchronous suspend after abort

From: Mandeep Singh Baines <[email protected]>

__device_suspend() must always send a completion. Otherwise, parent
devices will wait forever.

Commit 1e2ef05b, "PM: Limit race conditions between runtime PM and
system sleep (v2)", introduced a regression by short-circuiting the
complete_all() for certain error cases.

This patch fixes the bug by always signalling a completion.

Addresses http://crosbug.com/31972

Tested by injecting an abort.

Signed-off-by: Mandeep Singh Baines <[email protected]>
Cc: Rafael J. Wysocki <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Pavel Machek <[email protected]>
Cc: Len Brown <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc: Alan Stern <[email protected]>
Cc: Colin Cross <[email protected]>
Cc: Sameer Nanda <[email protected]>
Cc: Olof Johansson <[email protected]>
---
drivers/base/power/main.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index e0fb5b0..9cb845e 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -1031,7 +1031,7 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
dpm_wait_for_children(dev, async);

if (async_error)
- return 0;
+ goto Complete;

pm_runtime_get_noresume(dev);
if (pm_runtime_barrier(dev) && device_may_wakeup(dev))
@@ -1040,7 +1040,7 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
if (pm_wakeup_pending()) {
pm_runtime_put_sync(dev);
async_error = -EBUSY;
- return 0;
+ goto Complete;
}

device_lock(dev);
@@ -1097,6 +1097,8 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
}

device_unlock(dev);
+
+ Complete:
complete_all(&dev->power.completion);

if (error) {
--
1.7.3.4

2012-06-20 16:47:28

by Mandeep Baines

[permalink] [raw]
Subject: Re: [PATCH] PM: Prevent waiting forever on asynchronous suspend after abort

On Wed, Jun 20, 2012 at 7:58 AM, Alan Stern <[email protected]> wrote:
> On Tue, 19 Jun 2012, Mandeep Singh Baines wrote:
>
>> __device_suspend() must always send a completion. Otherwise, parent
>> devices will wait forever.
>>
>> Commit 1e2ef05b, "PM: Limit race conditions between runtime PM and
>> system sleep (v2)", introduced a regression by short-circuiting the
>> complete_all() for certain error cases.
>>
>> This patch fixes the bug by always signalling a completion.
>>
>> Addresses http://crosbug.com/31972
>>
>> Tested by injecting an abort via the following patch:
>>
>> diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
>> index a004db3..e5a6fce 100644
>> --- a/drivers/usb/core/hcd-pci.c
>> +++ b/drivers/usb/core/hcd-pci.c
>> @@ -21,6 +21,7 @@
>> ?#include <linux/pci.h>
>> ?#include <linux/usb.h>
>> ?#include <linux/usb/hcd.h>
>> +#include <linux/string.h>
>>
>> ?#include <asm/io.h>
>> ?#include <asm/irq.h>
>> @@ -477,6 +478,8 @@ static int resume_common(struct device *dev, int event)
>>
>> ?static int hcd_pci_suspend(struct device *dev)
>> ?{
>> + ? ? ? if (!strcmp("0000:00:1d.3", dev_name(dev)))
>> + ? ? ? ? ? ? ? return -EBUSY;
>> ? ? ? ? return suspend_common(dev, device_may_wakeup(dev));
>> ?}
>
> When you include one patch in front of another like this, doesn't it
> confuse the automatic tools? ?You might end up getting both changes
> include in the final commit. ?:-)
>

Ah. Good point. Removed the test code and re-sent.

>> ?drivers/base/power/main.c | ? ?6 ++++--
>> ?1 files changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
>> index e0fb5b0..9cb845e 100644
>> --- a/drivers/base/power/main.c
>> +++ b/drivers/base/power/main.c
>> @@ -1031,7 +1031,7 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
>> ? ? ? dpm_wait_for_children(dev, async);
>>
>> ? ? ? if (async_error)
>> - ? ? ? ? ? ? return 0;
>> + ? ? ? ? ? ? goto Complete;
>>
>> ? ? ? pm_runtime_get_noresume(dev);
>> ? ? ? if (pm_runtime_barrier(dev) && device_may_wakeup(dev))
>> @@ -1040,7 +1040,7 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
>> ? ? ? if (pm_wakeup_pending()) {
>> ? ? ? ? ? ? ? pm_runtime_put_sync(dev);
>> ? ? ? ? ? ? ? async_error = -EBUSY;
>> - ? ? ? ? ? ? return 0;
>> + ? ? ? ? ? ? goto Complete;
>> ? ? ? }
>>
>> ? ? ? device_lock(dev);
>> @@ -1097,6 +1097,8 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
>> ? ? ? }
>>
>> ? ? ? device_unlock(dev);
>> +
>> + Complete:
>> ? ? ? complete_all(&dev->power.completion);
>>
>> ? ? ? if (error) {
>
> Otherwise this looks right to me.
>
> Acked-by: Alan Stern <[email protected]>
>

2012-06-21 20:38:09

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH] PM: Prevent waiting forever on asynchronous suspend after abort

On Wednesday, June 20, 2012, [email protected] wrote:
> From: Mandeep Singh Baines <[email protected]>
>
> __device_suspend() must always send a completion. Otherwise, parent
> devices will wait forever.
>
> Commit 1e2ef05b, "PM: Limit race conditions between runtime PM and
> system sleep (v2)", introduced a regression by short-circuiting the
> complete_all() for certain error cases.
>
> This patch fixes the bug by always signalling a completion.
>
> Addresses http://crosbug.com/31972
>
> Tested by injecting an abort.
>
> Signed-off-by: Mandeep Singh Baines <[email protected]>
> Cc: Rafael J. Wysocki <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Cc: Pavel Machek <[email protected]>
> Cc: Len Brown <[email protected]>
> Cc: Greg Kroah-Hartman <[email protected]>
> Cc: Kevin Hilman <[email protected]>
> Cc: Alan Stern <[email protected]>
> Cc: Colin Cross <[email protected]>
> Cc: Sameer Nanda <[email protected]>
> Cc: Olof Johansson <[email protected]>

Applied to linux-pm/linux-next, will be pushed to Linus in a couple of days.

Thanks,
Rafael


> ---
> drivers/base/power/main.c | 6 ++++--
> 1 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> index e0fb5b0..9cb845e 100644
> --- a/drivers/base/power/main.c
> +++ b/drivers/base/power/main.c
> @@ -1031,7 +1031,7 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
> dpm_wait_for_children(dev, async);
>
> if (async_error)
> - return 0;
> + goto Complete;
>
> pm_runtime_get_noresume(dev);
> if (pm_runtime_barrier(dev) && device_may_wakeup(dev))
> @@ -1040,7 +1040,7 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
> if (pm_wakeup_pending()) {
> pm_runtime_put_sync(dev);
> async_error = -EBUSY;
> - return 0;
> + goto Complete;
> }
>
> device_lock(dev);
> @@ -1097,6 +1097,8 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
> }
>
> device_unlock(dev);
> +
> + Complete:
> complete_all(&dev->power.completion);
>
> if (error) {
>