From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751525AbdJCWY0 (ORCPT ); Tue, 3 Oct 2017 18:24:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:46726 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751171AbdJCWYY (ORCPT ); Tue, 3 Oct 2017 18:24:24 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A8C2D214E0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=goodmis.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=rostedt@goodmis.org Date: Tue, 3 Oct 2017 18:24:22 -0400 From: Steven Rostedt To: Peter Zijlstra Cc: pmladek@suse.com, sergey.senozhatsky@gmail.com, linux-kernel@vger.kernel.org, mingo@kernel.org, tglx@linutronix.de Subject: Re: [PATCH 3/3] early_printk: Add simple serialization to early_vprintk() Message-ID: <20171003182422.025d0a67@gandalf.local.home> In-Reply-To: <20170928122513.431444176@infradead.org> References: <20170928121823.430053219@infradead.org> <20170928122513.431444176@infradead.org> X-Mailer: Claws Mail 3.14.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 28 Sep 2017 14:18:26 +0200 Peter Zijlstra wrote: > In order to avoid multiple CPUs banging on the serial port at the same > time, add simple serialization. This explicitly deals with nested > contexts (like IRQs etc.). > > Signed-off-by: Peter Zijlstra (Intel) > --- > kernel/printk/printk.c | 35 ++++++++++++++++++++++++++++++++++- > 1 file changed, 34 insertions(+), 1 deletion(-) > > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -378,14 +378,47 @@ static int __init force_early_printk_set > } > early_param("force_early_printk", force_early_printk_setup); > > +static int early_printk_cpu = -1; > + > static int early_vprintk(const char *fmt, va_list args) > { > + int n, cpu, old; > char buf[512]; > - int n; > + > + cpu = get_cpu(); > + /* > + * Test-and-Set inter-cpu spinlock with recursion. > + */ > + for (;;) { > + /* > + * c-cas to avoid the exclusive bouncing on spin. > + * Depends on the memory barrier implied by cmpxchg > + * for ACQUIRE semantics. > + */ > + old = READ_ONCE(early_printk_cpu); > + if (old == -1) { If old != -1 and old != cpu, is it possible that the CPU could have fetched an old value, and never try to fetch it again? The cmpxchg memory barrier only happens when old == -1. -- Steve > + old = cmpxchg(&early_printk_cpu, -1, cpu); > + if (old == -1) > + break; > + } > + /* > + * Allow recursion for interrupts and the like. > + */ > + if (old == cpu) > + break; > + > + cpu_relax(); > + } > > n = vscnprintf(buf, sizeof(buf), fmt, args); > early_console->write(early_console, buf, n); > > + /* > + * Unlock -- in case @old == @cpu, this is a no-op. > + */ > + smp_store_release(&early_printk_cpu, old); > + put_cpu(); > + > return n; > } > >