public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH -mm] PM: Prevent frozen user mode helpers from failing the freezing of tasks
@ 2007-06-25 10:43 Oleg Nesterov
  2007-06-25 14:58 ` Paul E. McKenney
  2007-06-25 15:03 ` [PATCH -mm] PM: Prevent frozen user mode helpers from failing the freezing of tasks Rafael J. Wysocki
  0 siblings, 2 replies; 10+ messages in thread
From: Oleg Nesterov @ 2007-06-25 10:43 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Andrew Morton, Nigel Cunningham, Paul E. McKenney, Pavel Machek,
	Uli Luckas, linux-kernel

Rafael J. Wysocki wrote:
>
>  static int usermodehelper_pm_callback(struct notifier_block *nfb,
>  					unsigned long action,
>  					void *ignored)
>  {
> +	long retval;
> +
>  	switch (action) {
>  	case PM_HIBERNATION_PREPARE:
>  	case PM_SUSPEND_PREPARE:
>  		usermodehelper_disabled = 1;
> -		return NOTIFY_OK;
> +		/*
> +		 * From now on call_usermodehelper_exec() won't start any new
> +		 * helpers, so it is sufficient if running_helpers turns out to
> +		 * be zero at one point (it may be increased later, but that
> +		 * doesn't matter).
> +		 */
> +		retval = wait_event_timeout(running_helpers_waitq,
> +					atomic_read(&running_helpers) == 0,
> +					RUNNING_HELPERS_TIMEOUT);
> +		if (retval) {
> +			return NOTIFY_OK;
> +		} else {
> +			usermodehelper_disabled = 0;
> +			return NOTIFY_BAD;

I think this is racy. First, this needs smp_mb() between "usermodehelper_disabled = 1"
and wait_event_timeout().

Second, call_usermodehelper's path should first increment the counter, and only
then check usermodehelper_disabled, and it needs an mb() in between too. Otherwise,
the helper can see usermodehelper_disabled == 0, then PM_SUSPEND_PREPARE comes and
returns NOTIFY_OK, then the helper increments the counter and starts application.

Sadly, you can't use srcu/qrcu because it doesn't handle timeouts.	

Oleg.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2007-06-27 20:45 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-25 10:43 [PATCH -mm] PM: Prevent frozen user mode helpers from failing the freezing of tasks Oleg Nesterov
2007-06-25 14:58 ` Paul E. McKenney
2007-06-25 15:20   ` synchronize_qrcu_timeout() Oleg Nesterov
2007-06-25 15:49     ` synchronize_qrcu_timeout() Oleg Nesterov
2007-06-25 21:42       ` synchronize_qrcu_timeout() Pavel Machek
2007-06-26 14:53       ` synchronize_qrcu_timeout() Paul E. McKenney
2007-06-27 11:18         ` synchronize_qrcu_timeout() Oleg Nesterov
2007-06-27 20:52           ` synchronize_qrcu_timeout() Rafael J. Wysocki
2007-06-25 15:03 ` [PATCH -mm] PM: Prevent frozen user mode helpers from failing the freezing of tasks Rafael J. Wysocki
2007-06-25 15:27   ` Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox