public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: Paul Parsons <lost.distance@yahoo.com>
To: linux-pm@lists.linux-foundation.org
Subject: [PATCH] apm-emulation: Fix mutex race condition
Date: Tue, 3 May 2011 01:16:30 +0100 (BST)	[thread overview]
Message-ID: <49798.52726.qm@web29017.mail.ird.yahoo.com> (raw)

A process suspending the system (e.g. apm -s) locks apm_mutex at the start of apm_ioctl() and keeps it locked while calling pm_suspend(). A second process trying to ACK the suspend (e.g. apmd) may then block in apm_ioctl() trying to lock the same mutex. The first process tries to freeze processes, but the ACK process cannot be frozen because mutex_lock() is uninterruptible. Consequently pm_suspend() will ultimately fail in try_to_freeze_tasks(). This patch allows the ACK process to be frozen if it is blocked in apm_ioctl().

Signed-off-by: Paul Parsons <lost.distance@yahoo.com>
---
--- clean-2.6.39-rc5/drivers/char/apm-emulation.c	2011-03-15 01:20:32.000000000 +0000
+++ linux-2.6.39-rc5/drivers/char/apm-emulation.c	2011-05-03 00:34:05.467660807 +0100
@@ -275,7 +275,8 @@ apm_ioctl(struct file *filp, u_int cmd, 
 	if (!as->suser || !as->writer)
 		return -EPERM;
 
-	mutex_lock(&apm_mutex);
+	while (mutex_lock_interruptible(&apm_mutex) < 0)
+		try_to_freeze();
 	switch (cmd) {
 	case APM_IOC_SUSPEND:
 		mutex_lock(&state_lock);

             reply	other threads:[~2011-05-03  0:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-03  0:16 Paul Parsons [this message]
2011-05-03 18:23 ` [PATCH] apm-emulation: Fix mutex race condition Rafael J. Wysocki
2011-05-03 19:19   ` Paul Parsons
2011-05-03 20:33     ` Rafael J. Wysocki
2011-05-04 11:44       ` Jiri Kosina
2011-05-04 16:43         ` Rafael J. Wysocki
2011-05-04 18:58           ` Jiri Kosina

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49798.52726.qm@web29017.mail.ird.yahoo.com \
    --to=lost.distance@yahoo.com \
    --cc=linux-pm@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox