public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC] apm-emulation: apm_mutex breaks ACK; remove it
@ 2011-05-13  1:46 Paul Parsons
  2011-05-17 12:26 ` Jiri Kosina
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Parsons @ 2011-05-13  1:46 UTC (permalink / raw)
  To: linux-pm; +Cc: jkosina

apm_mutex is locked by a process (e.g. apm -s) at the start of apm_ioctl() and remains locked while pm_suspend() is called. Any subsequent process trying to ACK the suspend (e.g. apmd) is then blocked at the start of apm_ioctl(), causing the suspend to be delayed for 5 seconds in apm_suspend_notifier() while the ACK times out. In short, ACKs don't work.

The driver's data structures are sufficiently protected by assorted locks. And pm_suspend() has its own mutex to prevent reentrancy. Consequently there is no obvious requirement for apm_mutex, which evolved from earlier BKL calls. So let's remove it.

Signed-off-by: Paul Parsons <lost.distance@yahoo.com>
---
This patch supersedes my previous "apm-emulation: Fix mutex race condition" patch; this patch fixes that earlier bug too.
--- clean-2.6.39-rc7/drivers/char/apm-emulation.c	2011-03-15 01:20:32.000000000 +0000
+++ linux-2.6.39-rc7/drivers/char/apm-emulation.c	2011-05-13 01:40:02.068822695 +0100
@@ -126,7 +126,6 @@ struct apm_user {
 /*
  * Local variables
  */
-static DEFINE_MUTEX(apm_mutex);
 static atomic_t suspend_acks_pending = ATOMIC_INIT(0);
 static atomic_t userspace_notification_inhibit = ATOMIC_INIT(0);
 static int apm_disabled;
@@ -275,7 +274,6 @@ apm_ioctl(struct file *filp, u_int cmd,
 	if (!as->suser || !as->writer)
 		return -EPERM;
 
-	mutex_lock(&apm_mutex);
 	switch (cmd) {
 	case APM_IOC_SUSPEND:
 		mutex_lock(&state_lock);
@@ -336,7 +334,6 @@ apm_ioctl(struct file *filp, u_int cmd,
 		mutex_unlock(&state_lock);
 		break;
 	}
-	mutex_unlock(&apm_mutex);
 
 	return err;
 }
@@ -371,7 +368,6 @@ static int apm_open(struct inode * inode
 {
 	struct apm_user *as;
 
-	mutex_lock(&apm_mutex);
 	as = kzalloc(sizeof(*as), GFP_KERNEL);
 	if (as) {
 		/*
@@ -391,7 +387,6 @@ static int apm_open(struct inode * inode
 
 		filp->private_data = as;
 	}
-	mutex_unlock(&apm_mutex);
 
 	return as ? 0 : -ENOMEM;
 }

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

* Re: [PATCH RFC] apm-emulation: apm_mutex breaks ACK; remove it
  2011-05-13  1:46 [PATCH RFC] apm-emulation: apm_mutex breaks ACK; remove it Paul Parsons
@ 2011-05-17 12:26 ` Jiri Kosina
  2011-05-17 12:29   ` Jiri Kosina
  0 siblings, 1 reply; 4+ messages in thread
From: Jiri Kosina @ 2011-05-17 12:26 UTC (permalink / raw)
  To: Paul Parsons; +Cc: linux-pm

On Fri, 13 May 2011, Paul Parsons wrote:

> apm_mutex is locked by a process (e.g. apm -s) at the start of 
> apm_ioctl() and remains locked while pm_suspend() is called. Any 
> subsequent process trying to ACK the suspend (e.g. apmd) is then blocked 
> at the start of apm_ioctl(), causing the suspend to be delayed for 5 
> seconds in apm_suspend_notifier() while the ACK times out. In short, 
> ACKs don't work.
> 
> The driver's data structures are sufficiently protected by assorted 
> locks. And pm_suspend() has its own mutex to prevent reentrancy. 
> Consequently there is no obvious requirement for apm_mutex, which 
> evolved from earlier BKL calls. So let's remove it.
>
> 
> Signed-off-by: Paul Parsons <lost.distance@yahoo.com>
> ---
> This patch supersedes my previous "apm-emulation: Fix mutex race condition" patch; this patch fixes that earlier bug too.

Looks good to me (and sorry for the delay). Thanks Paul, will apply.

-- 
Jiri Kosina
SUSE Labs

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

* Re: [PATCH RFC] apm-emulation: apm_mutex breaks ACK; remove it
  2011-05-17 12:26 ` Jiri Kosina
@ 2011-05-17 12:29   ` Jiri Kosina
  2011-05-17 19:13     ` Rafael J. Wysocki
  0 siblings, 1 reply; 4+ messages in thread
From: Jiri Kosina @ 2011-05-17 12:29 UTC (permalink / raw)
  To: Paul Parsons; +Cc: linux-pm

On Tue, 17 May 2011, Jiri Kosina wrote:

> On Fri, 13 May 2011, Paul Parsons wrote:
> 
> > apm_mutex is locked by a process (e.g. apm -s) at the start of 
> > apm_ioctl() and remains locked while pm_suspend() is called. Any 
> > subsequent process trying to ACK the suspend (e.g. apmd) is then blocked 
> > at the start of apm_ioctl(), causing the suspend to be delayed for 5 
> > seconds in apm_suspend_notifier() while the ACK times out. In short, 
> > ACKs don't work.
> > 
> > The driver's data structures are sufficiently protected by assorted 
> > locks. And pm_suspend() has its own mutex to prevent reentrancy. 
> > Consequently there is no obvious requirement for apm_mutex, which 
> > evolved from earlier BKL calls. So let's remove it.
> >
> > 
> > Signed-off-by: Paul Parsons <lost.distance@yahoo.com>
> > ---
> > This patch supersedes my previous "apm-emulation: Fix mutex race condition" patch; this patch fixes that earlier bug too.
> 
> Looks good to me (and sorry for the delay). Thanks Paul, will apply.

(unless Rafael sees any potential issue there of course ... but I myself 
don't).

-- 
Jiri Kosina
SUSE Labs

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

* Re: [PATCH RFC] apm-emulation: apm_mutex breaks ACK; remove it
  2011-05-17 12:29   ` Jiri Kosina
@ 2011-05-17 19:13     ` Rafael J. Wysocki
  0 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2011-05-17 19:13 UTC (permalink / raw)
  To: Jiri Kosina; +Cc: linux-pm

On Tuesday, May 17, 2011, Jiri Kosina wrote:
> On Tue, 17 May 2011, Jiri Kosina wrote:
> 
> > On Fri, 13 May 2011, Paul Parsons wrote:
> > 
> > > apm_mutex is locked by a process (e.g. apm -s) at the start of 
> > > apm_ioctl() and remains locked while pm_suspend() is called. Any 
> > > subsequent process trying to ACK the suspend (e.g. apmd) is then blocked 
> > > at the start of apm_ioctl(), causing the suspend to be delayed for 5 
> > > seconds in apm_suspend_notifier() while the ACK times out. In short, 
> > > ACKs don't work.
> > > 
> > > The driver's data structures are sufficiently protected by assorted 
> > > locks. And pm_suspend() has its own mutex to prevent reentrancy. 
> > > Consequently there is no obvious requirement for apm_mutex, which 
> > > evolved from earlier BKL calls. So let's remove it.
> > >
> > > 
> > > Signed-off-by: Paul Parsons <lost.distance@yahoo.com>
> > > ---
> > > This patch supersedes my previous "apm-emulation: Fix mutex race condition" patch; this patch fixes that earlier bug too.
> > 
> > Looks good to me (and sorry for the delay). Thanks Paul, will apply.
> 
> (unless Rafael sees any potential issue there of course ... but I myself 
> don't).

No, I don't.

Thanks,
Rafael

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

end of thread, other threads:[~2011-05-17 19:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-13  1:46 [PATCH RFC] apm-emulation: apm_mutex breaks ACK; remove it Paul Parsons
2011-05-17 12:26 ` Jiri Kosina
2011-05-17 12:29   ` Jiri Kosina
2011-05-17 19:13     ` Rafael J. Wysocki

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