Re: [PATCH] PM: Acquire device locks on suspend

Alan Stern
2008-01-09T22:46:21Z

On Wed, 9 Jan 2008, Rafael J. Wysocki wrote:

> > In dpm_resume() you shouldn't need to use dpm_list_mtx at all, because
> > the list_move_tail() comes before the resume_device(). It's the same
> > as in dpm_power_up().
>
> Still, device_pm_schedule_removal() can (in theory) be called concurrently
> with dpm_resume() by another thread and this might corrupt the list without
> the locking.

Any thread doing that would be in violation of the restrictions you're
going to add to the kerneldoc for destroy_suspended_device().

However the overhead for the locking isn't critical. There won't be
any contention (if everything is working right) and it isn't a hot path
anyway. So you can leave the extra locking in if you want. But then
you should put it in all the routines where the lists get manipulated,
not just some of them. That is: device_power_down(), dpm_power_up(),
and even unregister_dropped_devices().

> > Also, the kerneldoc for destroy_suspended_device() should contain an
> > extra paragraph warning that the routine should never be called except
> > within the scope of a system sleep transition. In practice this means
> > it has to be directly or indirectly invoked by a suspend or resume
> > method.
>
> Or by a CPU hotplug notifier (that will be the majority of cases, IMO).

In your patch the call is made in response to a CPU_UP_CANCELED_FROZEN
notification. Isn't it true that this notification is issued only as
part of a system sleep transition? We wouldn't want to allow
destroy_suspended_device() to be called when an arbitrary CPU hotplug
notification occurs.

Alan Stern