From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S265881AbTGDI4z (ORCPT ); Fri, 4 Jul 2003 04:56:55 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S265883AbTGDI4z (ORCPT ); Fri, 4 Jul 2003 04:56:55 -0400 Received: from pub237.cambridge.redhat.com ([213.86.99.237]:54210 "EHLO warthog.warthog") by vger.kernel.org with ESMTP id S265881AbTGDI4y (ORCPT ); Fri, 4 Jul 2003 04:56:54 -0400 From: David Howells To: torvalds@transmeta.com cc: linux-kernel@vger.kernel.org Subject: [PATCH] anti-cross-CPU printk/oops interleaving User-Agent: EMH/1.14.1 SEMI/1.14.4 (Hosorogi) FLIM/1.14.4 (=?ISO-8859-4?Q?Kashiharajing=FE-mae?=) APEL/10.4 Emacs/21.2 (i386-redhat-linux-gnu) MULE/5.0 (SAKAKI) MIME-Version: 1.0 (generated by SEMI 1.14.4 - "Hosorogi") Content-Type: text/plain; charset=US-ASCII Date: Fri, 04 Jul 2003 10:11:18 +0100 Message-ID: <27637.1057309878@warthog.warthog> Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Hi Linus, This patch prevents an oops on one CPU being interleaved char-by-char with printks being performed on other CPUs, thus rendering them actually readable under those circumstances. David diff -ur linux-2.5.74/kernel/printk.c linux-2.5.74-auto/kernel/printk.c --- linux-2.5.74/kernel/printk.c 2003-07-03 15:37:24.000000000 +0100 +++ linux-2.5.74-auto/kernel/printk.c 2003-07-03 15:41:15.000000000 +0100 @@ -378,6 +378,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. * @@ -400,8 +403,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); @@ -409,6 +413,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);