Re: [patch update] PM: Introduce core framework for run-time PM of I/O devices (rev. 6)

Alan Stern
2009-06-27T01:25:46Z

On Sat, 27 Jun 2009, Rafael J. Wysocki wrote:

> > Speaking of races, have you noticed that the way power.work_done gets
> > used is racy?
>
> Not really. :-)
>
> > You can't wait for the completion before releasing the
> > lock, but then anything could happen.
> >
> > A safer approach would be to use a wait_queue.
>
> I'm not sure what you mean exactly. What's the race?

Somebody calls pm_runtime_suspend when a suspend is already in
progress. The routine sees that the status is RPM_SUSPENDING, so it
prepares to wait until the suspend is finished. It drops the lock and
calls wait_for_completion.

But in between those last two steps, the suspend could finish and
a resume could start up. Then the wait_for_completion wouldn't return
until the device was fully resumed!

Now I admit this isn't as bad as it sounds. The same sort of thing
could happen even if there weren't two suspends going on at the same
time; a resume could occur between when the routine drops the lock and
when it returns. So okay, forget I mentioned it.

Alan Stern