All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Andrew Morton <akpm@osdl.org>
Cc: ntl@pobox.com, anton@au1.ibm.com, linux-kernel@vger.kernel.org,
	michael@ellerman.id.au, linuxppc64-dev@ozlabs.org,
	serue@us.ibm.com, paulus@au1.ibm.com, torvalds@osdl.org
Subject: [patch] turn on might_sleep() in early bootup code too
Date: Wed, 18 Jan 2006 10:18:34 +0100	[thread overview]
Message-ID: <20060118091834.GA21366@elte.hu> (raw)
In-Reply-To: <20060118002459.3bc8f75a.akpm@osdl.org>


Could we try the patch below in -mm, to get a feeling of how widespread 
the early bootup lock-atomicity assumptions are? I also added a .config 
option to add back the workaround, and turned it on for ppc64. (users 
can still select this manually on any other arch as well)

i found one such bug on x86: early-printk calls register_console(), 
which acquires console_sem. Since we can work such things around 
per-lock and per-assumption [see the printk.c changes], i think we 
should rather do the workarounds that way, and thus document the hacks 
we need - without impacting the ability of such platforms to boot - 
while still keeping might_sleep() checks widely enabled. (btw., x86 
still booted fine, despite the warning.)

	Ingo

--

enable might_sleep() checks even in early bootup code (when system_state 
!= SYSTEM_RUNNING). There's also a new config option to turn this off:
CONFIG_DEBUG_SPINLOCK_SLEEP_EARLY_BOOTUP_WORKAROUND
while most other architectures.

the patch also documents and works around an EARLY_PRINTK locking 
dependency. [which we might want to get rid of in the future.]

tested on x86.

Signed-off-by: Ingo Molnar <mingo@elte.hu>

----

 arch/powerpc/Kconfig.debug |    2 ++
 kernel/printk.c            |   11 ++++++++++-
 kernel/sched.c             |    7 +++++--
 lib/Kconfig.debug          |   11 +++++++++++
 4 files changed, 28 insertions(+), 3 deletions(-)

Index: linux/arch/powerpc/Kconfig.debug
===================================================================
--- linux.orig/arch/powerpc/Kconfig.debug
+++ linux/arch/powerpc/Kconfig.debug
@@ -2,6 +2,8 @@ menu "Kernel hacking"
 
 source "lib/Kconfig.debug"
 
+select CONFIG_DEBUG_SPINLOCK_SLEEP_EARLY_BOOTUP_WORKAROUND
+
 config DEBUG_STACKOVERFLOW
 	bool "Check for stack overflows"
 	depends on DEBUG_KERNEL && PPC64
Index: linux/kernel/printk.c
===================================================================
--- linux.orig/kernel/printk.c
+++ linux/kernel/printk.c
@@ -710,7 +710,16 @@ void acquire_console_sem(void)
 {
 	if (in_interrupt())
 		BUG();
-	down(&console_sem);
+	/*
+	 * Early-printk wants to acquire the console_sem in
+	 * register_console(). Make a special exception for them by
+	 * going via trylock first, which doesnt trigger the
+	 * might_sleep() atomicity check.
+	 */
+#ifdef CONFIG_EARLY_PRINTK
+	if (down_trylock(&console_sem))
+#endif
+		down(&console_sem);
 	console_locked = 1;
 	console_may_schedule = 1;
 }
Index: linux/kernel/sched.c
===================================================================
--- linux.orig/kernel/sched.c
+++ linux/kernel/sched.c
@@ -6285,8 +6285,11 @@ void __might_sleep(char *file, int line)
 #if defined(in_atomic)
 	static unsigned long prev_jiffy;	/* ratelimiting */
 
-	if ((in_atomic() || irqs_disabled()) &&
-	    system_state == SYSTEM_RUNNING && !oops_in_progress) {
+#ifdef CONFIG_DEBUG_SPINLOCK_SLEEP_EARLY_BOOTUP_WORKAROUND
+	if (system_state != SYSTEM_RUNNING)
+		return;
+#endif
+	if ((in_atomic() || irqs_disabled()) && !oops_in_progress) {
 		if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy)
 			return;
 		prev_jiffy = jiffies;
Index: linux/lib/Kconfig.debug
===================================================================
--- linux.orig/lib/Kconfig.debug
+++ linux/lib/Kconfig.debug
@@ -128,6 +128,17 @@ config DEBUG_SPINLOCK_SLEEP
 	  If you say Y here, various routines which may sleep will become very
 	  noisy if they are called with a spinlock held.
 
+config DEBUG_SPINLOCK_SLEEP_EARLY_BOOTUP_WORKAROUND
+	bool "Work around sleep-inside-spinlock checking in early bootup code"
+	depends on DEBUG_SPINLOCK_SLEEP
+	help
+	  If you say Y here, then early bootup code will not check for
+	  "do not call potentially sleeping functions in atomic sections"
+	  rule, that the DEBUG_SPINLOCK_SLEEP option enforces.
+
+	  You want to say N here, unless your system does not boot with
+	  "Y" here.
+
 config DEBUG_KOBJECT
 	bool "kobject debugging"
 	depends on DEBUG_KERNEL

  parent reply	other threads:[~2006-01-18  9:18 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-16  6:35 2.6.15-mm4 failure on power5 Serge E. Hallyn
2006-01-16  7:05 ` Andrew Morton
2006-01-16 13:00   ` Michael Ellerman
2006-01-16 15:37     ` Serge E. Hallyn
2006-01-16 21:52       ` Dave C Boutcher
2006-01-17  1:09         ` Andrew Morton
2006-01-17  8:17           ` Ingo Molnar
2006-01-17  8:47             ` Andrew Morton
2006-01-17 16:52             ` Dave C Boutcher
2006-01-17 16:55               ` Dave C Boutcher
2006-01-18  6:40                 ` Nathan Lynch
2006-01-18  7:07                   ` Ingo Molnar
2006-01-18  7:53                     ` Nathan Lynch
2006-01-18  8:08                   ` Nathan Lynch
2006-01-17 12:22         ` Serge E. Hallyn
2006-01-17 13:32         ` Michael Ellerman
2006-01-17 14:00           ` Ingo Molnar
2006-01-18  0:19             ` Michael Ellerman
2006-01-18  3:32               ` Dave C Boutcher
2006-01-18  6:37                 ` Ingo Molnar
2006-01-18  6:53                   ` Andrew Morton
2006-01-18  7:04                     ` Ingo Molnar
2006-01-18  7:28                     ` Nathan Lynch
2006-01-18  7:37                       ` Andrew Morton
2006-01-18  8:08                         ` Ingo Molnar
2006-01-18  8:24                           ` Andrew Morton
2006-01-18  9:02                             ` [patch] work around ppc64 bootup bug by making mutex-debugging save/restore irqs Ingo Molnar
2006-01-18  9:18                             ` Ingo Molnar [this message]
2006-01-18 10:35                               ` [patch] turn on might_sleep() in early bootup code too Andrew Morton
2006-01-18 10:43                                 ` Ingo Molnar
2006-01-18 11:15                                   ` [patch] make bug messages more consistent Ingo Molnar
2006-01-19  4:39                                   ` [patch] turn on might_sleep() in early bootup code too Zwane Mwaikambo
2006-01-18 10:46                                 ` Nick Piggin
2006-01-18 11:07                                   ` Ingo Molnar
2006-01-18 12:53                                     ` [patch] add trylock_kernel() Ingo Molnar
2006-01-18  7:38                       ` 2.6.15-mm4 failure on power5 Arjan van de Ven

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=20060118091834.GA21366@elte.hu \
    --to=mingo@elte.hu \
    --cc=akpm@osdl.org \
    --cc=anton@au1.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc64-dev@ozlabs.org \
    --cc=michael@ellerman.id.au \
    --cc=ntl@pobox.com \
    --cc=paulus@au1.ibm.com \
    --cc=serue@us.ibm.com \
    --cc=torvalds@osdl.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.