public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] printk simultaneous oops disentangling
@ 2002-08-22 12:09 David Howells
  2002-08-22 15:51 ` Benjamin LaHaise
  0 siblings, 1 reply; 3+ messages in thread
From: David Howells @ 2002-08-22 12:09 UTC (permalink / raw)
  To: torvalds; +Cc: linux-kernel, dhowells

Hi Linus,

Here's a patch to stop multiple simultaneous oopses on an SMP system from
interleaving with and overwriting bits of each other. It only permits lock
breaking if the printk lock is held by the same CPU.

David

--- linux-2.5.31/kernel/printk.c	Mon Jul 22 11:58:29 2002
+++ linux-trace-2531/kernel/printk.c	Thu Aug 22 12:51:24 2002
@@ -390,6 +390,9 @@
 		logged_chars++;
 }
 
+/* cpu currently holding logbuf_lock */
+static volatile int printk_cpu = -1;
+
 /*
  * This is printk.  It can be called from any context.  We want it to work.
  * 
@@ -412,8 +415,9 @@
 	static char printk_buf[1024];
 	static int log_level_unknown = 1;
 
-	if (oops_in_progress) {
-		/* If a crash is occurring, make sure we can't deadlock */
+	if (oops_in_progress && printk_cpu==smp_processor_id()) {
+		/* If a crash is occurring during printk() on this CPU,
+		 * make sure we can't deadlock */
 		spin_lock_init(&logbuf_lock);
 		/* And make sure that we print immediately */
 		init_MUTEX(&console_sem);
@@ -421,6 +425,7 @@
 
 	/* This stops the holder of console_sem just where we want him */
 	spin_lock_irqsave(&logbuf_lock, flags);
+	printk_cpu = smp_processor_id();
 
 	/* Emit the output into the temporary buffer */
 	va_start(args, fmt);
@@ -450,6 +455,7 @@
 		 * On some architectures, the consoles are not usable
 		 * on secondary CPUs early in the boot process.
 		 */
+		printk_cpu = -1;
 		spin_unlock_irqrestore(&logbuf_lock, flags);
 		goto out;
 	}
@@ -458,6 +464,7 @@
 		 * We own the drivers.  We can drop the spinlock and let
 		 * release_console_sem() print the text
 		 */
+		printk_cpu = -1;
 		spin_unlock_irqrestore(&logbuf_lock, flags);
 		console_may_schedule = 0;
 		release_console_sem();
@@ -467,6 +474,7 @@
 		 * allows the semaphore holder to proceed and to call the
 		 * console drivers with the output which we just produced.
 		 */
+		printk_cpu = -1;
 		spin_unlock_irqrestore(&logbuf_lock, flags);
 	}
 out:

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

* Re: [PATCH] printk simultaneous oops disentangling
  2002-08-22 12:09 [PATCH] printk simultaneous oops disentangling David Howells
@ 2002-08-22 15:51 ` Benjamin LaHaise
  2002-08-22 15:57   ` Benjamin LaHaise
  0 siblings, 1 reply; 3+ messages in thread
From: Benjamin LaHaise @ 2002-08-22 15:51 UTC (permalink / raw)
  To: David Howells; +Cc: torvalds, linux-kernel

On Thu, Aug 22, 2002 at 01:09:18PM +0100, David Howells wrote:
> Hi Linus,
> 
> Here's a patch to stop multiple simultaneous oopses on an SMP system from
> interleaving with and overwriting bits of each other. It only permits lock
> breaking if the printk lock is held by the same CPU.

This is still wrong.  It should attempt to acquire the locks with a timeout 
before trampling on them, as there may be a printk or other console output 
in progress on the other cpu.

		-ben
-- 
"You will be reincarnated as a toad; and you will be much happier."

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

* Re: [PATCH] printk simultaneous oops disentangling
  2002-08-22 15:51 ` Benjamin LaHaise
@ 2002-08-22 15:57   ` Benjamin LaHaise
  0 siblings, 0 replies; 3+ messages in thread
From: Benjamin LaHaise @ 2002-08-22 15:57 UTC (permalink / raw)
  To: David Howells; +Cc: torvalds, linux-kernel

On Thu, Aug 22, 2002 at 11:51:14AM -0400, Benjamin LaHaise wrote:
> On Thu, Aug 22, 2002 at 01:09:18PM +0100, David Howells wrote:
> > Hi Linus,
> > 
> > Here's a patch to stop multiple simultaneous oopses on an SMP system from
> > interleaving with and overwriting bits of each other. It only permits lock
> > breaking if the printk lock is held by the same CPU.
> 
> This is still wrong.  It should attempt to acquire the locks with a timeout 
> before trampling on them, as there may be a printk or other console output 
> in progress on the other cpu.

/me must be having a bad week

The patch is actually right, but bust_spinlocks still blindly stops on locks 
that may not need to be stomped on.

		-ben
-- 
"You will be reincarnated as a toad; and you will be much happier."

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

end of thread, other threads:[~2002-08-22 15:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-22 12:09 [PATCH] printk simultaneous oops disentangling David Howells
2002-08-22 15:51 ` Benjamin LaHaise
2002-08-22 15:57   ` Benjamin LaHaise

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