* Re: [PATCH] PM / Runtime: Fix the twice judgement in rpm_suspend/resume()
2013-01-14 17:48 [PATCH] PM / Runtime: Fix the twice judgement in rpm_suspend/resume() Chuansheng Liu
@ 2013-01-14 12:32 ` Rafael J. Wysocki
2013-01-14 15:30 ` Alan Stern
0 siblings, 1 reply; 5+ messages in thread
From: Rafael J. Wysocki @ 2013-01-14 12:32 UTC (permalink / raw)
To: Chuansheng Liu; +Cc: linux-pm, linux-kernel
On Tuesday, January 15, 2013 01:48:18 AM Chuansheng Liu wrote:
>
> In function rpm_suspend/resume(), when going into the for(;;),
> the pre-condition judgement has been done, and the variable runtime_status
> are always protected by &power.lock, so it is not necessary to judge
> them again before unlock_irq &power.lock in for(;;).
>
> This patch clean them up.
Well, I don't really think this fixes anything. Yes, we may save one check
here and there, but the current code follows the wait_event() convention.
Thanks,
Rafael
> Signed-off-by: liu chuansheng <chuansheng.liu@intel.com>
> ---
> drivers/base/power/runtime.c | 18 +++++++++---------
> 1 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> index 3148b10..32d6497 100644
> --- a/drivers/base/power/runtime.c
> +++ b/drivers/base/power/runtime.c
> @@ -377,14 +377,14 @@ static int rpm_suspend(struct device *dev, int rpmflags)
> for (;;) {
> prepare_to_wait(&dev->power.wait_queue, &wait,
> TASK_UNINTERRUPTIBLE);
> - if (dev->power.runtime_status != RPM_SUSPENDING)
> - break;
>
> spin_unlock_irq(&dev->power.lock);
>
> schedule();
>
> spin_lock_irq(&dev->power.lock);
> + if (dev->power.runtime_status != RPM_SUSPENDING)
> + break;
> }
> finish_wait(&dev->power.wait_queue, &wait);
> goto repeat;
> @@ -557,15 +557,15 @@ static int rpm_resume(struct device *dev, int rpmflags)
> for (;;) {
> prepare_to_wait(&dev->power.wait_queue, &wait,
> TASK_UNINTERRUPTIBLE);
> - if (dev->power.runtime_status != RPM_RESUMING
> - && dev->power.runtime_status != RPM_SUSPENDING)
> - break;
>
> spin_unlock_irq(&dev->power.lock);
>
> schedule();
>
> spin_lock_irq(&dev->power.lock);
> + if (dev->power.runtime_status != RPM_RESUMING
> + && dev->power.runtime_status != RPM_SUSPENDING)
> + break;
> }
> finish_wait(&dev->power.wait_queue, &wait);
> goto repeat;
> @@ -989,15 +989,15 @@ static void __pm_runtime_barrier(struct device *dev)
> for (;;) {
> prepare_to_wait(&dev->power.wait_queue, &wait,
> TASK_UNINTERRUPTIBLE);
> - if (dev->power.runtime_status != RPM_SUSPENDING
> - && dev->power.runtime_status != RPM_RESUMING
> - && !dev->power.idle_notification)
> - break;
> spin_unlock_irq(&dev->power.lock);
>
> schedule();
>
> spin_lock_irq(&dev->power.lock);
> + if (dev->power.runtime_status != RPM_SUSPENDING
> + && dev->power.runtime_status != RPM_RESUMING
> + && !dev->power.idle_notification)
> + break;
> }
> finish_wait(&dev->power.wait_queue, &wait);
> }
>
--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] PM / Runtime: Fix the twice judgement in rpm_suspend/resume()
2013-01-14 12:32 ` Rafael J. Wysocki
@ 2013-01-14 15:30 ` Alan Stern
2013-01-15 1:20 ` Liu, Chuansheng
0 siblings, 1 reply; 5+ messages in thread
From: Alan Stern @ 2013-01-14 15:30 UTC (permalink / raw)
To: Rafael J. Wysocki; +Cc: Chuansheng Liu, linux-pm, linux-kernel
On Mon, 14 Jan 2013, Rafael J. Wysocki wrote:
> On Tuesday, January 15, 2013 01:48:18 AM Chuansheng Liu wrote:
> >
> > In function rpm_suspend/resume(), when going into the for(;;),
> > the pre-condition judgement has been done, and the variable runtime_status
> > are always protected by &power.lock, so it is not necessary to judge
> > them again before unlock_irq &power.lock in for(;;).
> >
> > This patch clean them up.
>
> Well, I don't really think this fixes anything. Yes, we may save one check
> here and there, but the current code follows the wait_event() convention.
Indeed, this patch introduces a race. If runtime_status changes from
RPM_SUSPENDING and power.wait_queue is signalled in between the test at
the end of the loop and the prepare_to_wait() call, the loop will never
end.
Alan Stern
> Thanks,
> Rafael
>
>
> > Signed-off-by: liu chuansheng <chuansheng.liu@intel.com>
> > ---
> > drivers/base/power/runtime.c | 18 +++++++++---------
> > 1 files changed, 9 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> > index 3148b10..32d6497 100644
> > --- a/drivers/base/power/runtime.c
> > +++ b/drivers/base/power/runtime.c
> > @@ -377,14 +377,14 @@ static int rpm_suspend(struct device *dev, int rpmflags)
> > for (;;) {
> > prepare_to_wait(&dev->power.wait_queue, &wait,
> > TASK_UNINTERRUPTIBLE);
> > - if (dev->power.runtime_status != RPM_SUSPENDING)
> > - break;
> >
> > spin_unlock_irq(&dev->power.lock);
> >
> > schedule();
> >
> > spin_lock_irq(&dev->power.lock);
> > + if (dev->power.runtime_status != RPM_SUSPENDING)
> > + break;
> > }
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] PM / Runtime: Fix the twice judgement in rpm_suspend/resume()
@ 2013-01-14 17:48 Chuansheng Liu
2013-01-14 12:32 ` Rafael J. Wysocki
0 siblings, 1 reply; 5+ messages in thread
From: Chuansheng Liu @ 2013-01-14 17:48 UTC (permalink / raw)
To: rjw; +Cc: linux-pm, linux-kernel, chuansheng.liu
In function rpm_suspend/resume(), when going into the for(;;),
the pre-condition judgement has been done, and the variable runtime_status
are always protected by &power.lock, so it is not necessary to judge
them again before unlock_irq &power.lock in for(;;).
This patch clean them up.
Signed-off-by: liu chuansheng <chuansheng.liu@intel.com>
---
drivers/base/power/runtime.c | 18 +++++++++---------
1 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 3148b10..32d6497 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -377,14 +377,14 @@ static int rpm_suspend(struct device *dev, int rpmflags)
for (;;) {
prepare_to_wait(&dev->power.wait_queue, &wait,
TASK_UNINTERRUPTIBLE);
- if (dev->power.runtime_status != RPM_SUSPENDING)
- break;
spin_unlock_irq(&dev->power.lock);
schedule();
spin_lock_irq(&dev->power.lock);
+ if (dev->power.runtime_status != RPM_SUSPENDING)
+ break;
}
finish_wait(&dev->power.wait_queue, &wait);
goto repeat;
@@ -557,15 +557,15 @@ static int rpm_resume(struct device *dev, int rpmflags)
for (;;) {
prepare_to_wait(&dev->power.wait_queue, &wait,
TASK_UNINTERRUPTIBLE);
- if (dev->power.runtime_status != RPM_RESUMING
- && dev->power.runtime_status != RPM_SUSPENDING)
- break;
spin_unlock_irq(&dev->power.lock);
schedule();
spin_lock_irq(&dev->power.lock);
+ if (dev->power.runtime_status != RPM_RESUMING
+ && dev->power.runtime_status != RPM_SUSPENDING)
+ break;
}
finish_wait(&dev->power.wait_queue, &wait);
goto repeat;
@@ -989,15 +989,15 @@ static void __pm_runtime_barrier(struct device *dev)
for (;;) {
prepare_to_wait(&dev->power.wait_queue, &wait,
TASK_UNINTERRUPTIBLE);
- if (dev->power.runtime_status != RPM_SUSPENDING
- && dev->power.runtime_status != RPM_RESUMING
- && !dev->power.idle_notification)
- break;
spin_unlock_irq(&dev->power.lock);
schedule();
spin_lock_irq(&dev->power.lock);
+ if (dev->power.runtime_status != RPM_SUSPENDING
+ && dev->power.runtime_status != RPM_RESUMING
+ && !dev->power.idle_notification)
+ break;
}
finish_wait(&dev->power.wait_queue, &wait);
}
--
1.7.0.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* RE: [PATCH] PM / Runtime: Fix the twice judgement in rpm_suspend/resume()
2013-01-14 15:30 ` Alan Stern
@ 2013-01-15 1:20 ` Liu, Chuansheng
2013-01-15 15:50 ` Alan Stern
0 siblings, 1 reply; 5+ messages in thread
From: Liu, Chuansheng @ 2013-01-15 1:20 UTC (permalink / raw)
To: Alan Stern, Rafael J. Wysocki
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
> -----Original Message-----
> From: Alan Stern [mailto:stern@rowland.harvard.edu]
> Sent: Monday, January 14, 2013 11:30 PM
> To: Rafael J. Wysocki
> Cc: Liu, Chuansheng; linux-pm@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] PM / Runtime: Fix the twice judgement in
> rpm_suspend/resume()
>
> On Mon, 14 Jan 2013, Rafael J. Wysocki wrote:
>
> > On Tuesday, January 15, 2013 01:48:18 AM Chuansheng Liu wrote:
> > >
> > > In function rpm_suspend/resume(), when going into the for(;;),
> > > the pre-condition judgement has been done, and the variable
> runtime_status
> > > are always protected by &power.lock, so it is not necessary to judge
> > > them again before unlock_irq &power.lock in for(;;).
> > >
> > > This patch clean them up.
> >
> > Well, I don't really think this fixes anything. Yes, we may save one check
> > here and there, but the current code follows the wait_event() convention.
OK, thanks.
>
> Indeed, this patch introduces a race. If runtime_status changes from
> RPM_SUSPENDING and power.wait_queue is signalled in between the test at
> the end of the loop and the prepare_to_wait() call, the loop will never
> end.
Checking the race case, it should not happen?
Updating runtime_status and wake_up wait_queue are protected by power.lock.
spin_lock(&power.lock)
...
__update_runtime_status()
...
wake_up_all(&dev->power.wait_queue)
...
spin_unlock(&power.lock)
>
> Alan Stern
>
> > Thanks,
> > Rafael
> >
> >
> > > Signed-off-by: liu chuansheng <chuansheng.liu@intel.com>
> > > ---
> > > drivers/base/power/runtime.c | 18 +++++++++---------
> > > 1 files changed, 9 insertions(+), 9 deletions(-)
> > >
> > > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> > > index 3148b10..32d6497 100644
> > > --- a/drivers/base/power/runtime.c
> > > +++ b/drivers/base/power/runtime.c
> > > @@ -377,14 +377,14 @@ static int rpm_suspend(struct device *dev, int
> rpmflags)
> > > for (;;) {
> > > prepare_to_wait(&dev->power.wait_queue, &wait,
> > > TASK_UNINTERRUPTIBLE);
> > > - if (dev->power.runtime_status != RPM_SUSPENDING)
> > > - break;
> > >
> > > spin_unlock_irq(&dev->power.lock);
> > >
> > > schedule();
> > >
> > > spin_lock_irq(&dev->power.lock);
> > > + if (dev->power.runtime_status != RPM_SUSPENDING)
> > > + break;
> > > }
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH] PM / Runtime: Fix the twice judgement in rpm_suspend/resume()
2013-01-15 1:20 ` Liu, Chuansheng
@ 2013-01-15 15:50 ` Alan Stern
0 siblings, 0 replies; 5+ messages in thread
From: Alan Stern @ 2013-01-15 15:50 UTC (permalink / raw)
To: Liu, Chuansheng
Cc: Rafael J. Wysocki, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org
On Tue, 15 Jan 2013, Liu, Chuansheng wrote:
> > Indeed, this patch introduces a race. If runtime_status changes from
> > RPM_SUSPENDING and power.wait_queue is signalled in between the test at
> > the end of the loop and the prepare_to_wait() call, the loop will never
> > end.
> Checking the race case, it should not happen?
> Updating runtime_status and wake_up wait_queue are protected by power.lock.
> spin_lock(&power.lock)
> ...
> __update_runtime_status()
> ...
> wake_up_all(&dev->power.wait_queue)
> ...
> spin_unlock(&power.lock)
You're right, the lock prevents this race from happening.
On the other hand, with your change we would end up calling finish_wait()
without calling prepare_to_wait() first. And as Rafael mentioned, the
current code fits the pattern that people expect to see.
Alan Stern
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-01-15 15:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-14 17:48 [PATCH] PM / Runtime: Fix the twice judgement in rpm_suspend/resume() Chuansheng Liu
2013-01-14 12:32 ` Rafael J. Wysocki
2013-01-14 15:30 ` Alan Stern
2013-01-15 1:20 ` Liu, Chuansheng
2013-01-15 15:50 ` Alan Stern
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).