From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Len Brown <lenb@kernel.org>
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
"Arve Hjønnevåg" <arve@android.com>, "Greg KH" <gregkh@suse.de>,
"Ingo Molnar" <mingo@elte.hu>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"KOSAKI Motohiro" <kosaki.motohiro@jp.fujitsu.com>,
LKML <linux-kernel@vger.kernel.org>,
"Linus Torvalds" <torvalds@linux-foundation.org>,
"Pavel Machek" <pavel@ucw.cz>,
"pm list" <linux-pm@lists.linux-foundation.org>,
"Arjan van de Ven" <arjan@linux.intel.com>,
"Alan Jenkins" <alan-jenkins@tuffmail.co.uk>,
"Masami Hiramatsu" <mhiramat@redhat.com>,
"Andrey Borzenkov" <arvidjaar@mail.ru>
Subject: [PATCH 9/9] PM: Fix suspend_console and resume_console to use only one semaphore
Date: Sat, 14 Feb 2009 02:07:24 +0100 [thread overview]
Message-ID: <200902140207.25476.rjw@sisk.pl> (raw)
In-Reply-To: <200902140157.40869.rjw@sisk.pl>
From: Arve Hjønnevåg <arve@android.com>
This fixes a race where a thread acquires the console while the
console is suspended, and the console is resumed before this
thread releases it. In this case, the secondary console
semaphore would be left locked, and the primary semaphore would
be released twice. This in turn would cause the console switch
on suspend or resume to hang forever.
Note that suspend_console does not actually lock the console
for clients that use acquire_console_sem, it only locks it for
clients that use try_acquire_console_sem. If we change
suspend_console to fully lock the console, then the kernel
may deadlock on suspend. One client of try_acquire_console_sem
is acquire_console_semaphore_for_printk, which uses it to
prevent printk from using the console while it is suspended.
Signed-off-by: Arve Hjønnevåg <arve@android.com>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
kernel/printk.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
Index: linux-2.6/kernel/printk.c
===================================================================
--- linux-2.6.orig/kernel/printk.c
+++ linux-2.6/kernel/printk.c
@@ -73,7 +73,6 @@ EXPORT_SYMBOL(oops_in_progress);
* driver system.
*/
static DECLARE_MUTEX(console_sem);
-static DECLARE_MUTEX(secondary_console_sem);
struct console *console_drivers;
EXPORT_SYMBOL_GPL(console_drivers);
@@ -891,12 +890,14 @@ void suspend_console(void)
printk("Suspending console(s) (use no_console_suspend to debug)\n");
acquire_console_sem();
console_suspended = 1;
+ up(&console_sem);
}
void resume_console(void)
{
if (!console_suspend_enabled)
return;
+ down(&console_sem);
console_suspended = 0;
release_console_sem();
}
@@ -912,11 +913,9 @@ void resume_console(void)
void acquire_console_sem(void)
{
BUG_ON(in_interrupt());
- if (console_suspended) {
- down(&secondary_console_sem);
- return;
- }
down(&console_sem);
+ if (console_suspended)
+ return;
console_locked = 1;
console_may_schedule = 1;
}
@@ -926,6 +925,10 @@ int try_acquire_console_sem(void)
{
if (down_trylock(&console_sem))
return -1;
+ if (console_suspended) {
+ up(&console_sem);
+ return -1;
+ }
console_locked = 1;
console_may_schedule = 0;
return 0;
@@ -979,7 +982,7 @@ void release_console_sem(void)
unsigned wake_klogd = 0;
if (console_suspended) {
- up(&secondary_console_sem);
+ up(&console_sem);
return;
}
next prev parent reply other threads:[~2009-02-14 1:23 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-14 0:57 [PATCH 0/9] PM: Fixes related to suspend and hibernation for 2.6.29 Rafael J. Wysocki
2009-02-14 0:59 ` [PATCH 1/9] Consolidate driver_probe_done() loops into one place Rafael J. Wysocki
2009-02-14 1:47 ` Greg KH
2009-02-14 1:00 ` [PATCH 2/9] PM/resume: wait for device probing to finish Rafael J. Wysocki
2009-02-14 1:48 ` Greg KH
2009-02-14 1:01 ` [PATCH 3/9] PM/hibernate: fix "swap breaks after hibernation failures" Rafael J. Wysocki
2009-02-14 1:02 ` [PATCH 4/9] PM: fix build for CONFIG_PM unset Rafael J. Wysocki
2009-02-14 1:03 ` [PATCH 5/9] swsusp: dont fiddle with swappiness Rafael J. Wysocki
2009-02-14 1:04 ` [PATCH 6/9] swsusp: clean up shrink_all_zones() Rafael J. Wysocki
2009-02-14 1:05 ` [PATCH 7/9] PM: Fix pm_notifiers during user mode hibernation Rafael J. Wysocki
2009-02-14 1:06 ` [PATCH 8/9] PM: Wait for console in resume Rafael J. Wysocki
2009-02-14 1:07 ` Rafael J. Wysocki [this message]
2009-02-21 4:41 ` [PATCH 0/9] PM: Fixes related to suspend and hibernation for 2.6.29 Len Brown
2009-02-21 9:38 ` Rafael J. Wysocki
2009-02-21 18:29 ` Greg KH
2009-02-21 19:32 ` Arjan van de Ven
2009-02-21 19:48 ` Greg KH
2009-02-21 22:18 ` Linus Torvalds
2009-02-22 2:47 ` Len Brown
2009-02-22 10:07 ` Rafael J. Wysocki
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=200902140207.25476.rjw@sisk.pl \
--to=rjw@sisk.pl \
--cc=akpm@linux-foundation.org \
--cc=alan-jenkins@tuffmail.co.uk \
--cc=arjan@linux.intel.com \
--cc=arve@android.com \
--cc=arvidjaar@mail.ru \
--cc=gregkh@suse.de \
--cc=hannes@cmpxchg.org \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=lenb@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@lists.linux-foundation.org \
--cc=mhiramat@redhat.com \
--cc=mingo@elte.hu \
--cc=pavel@ucw.cz \
--cc=torvalds@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