From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034000AbcJRRQZ (ORCPT ); Tue, 18 Oct 2016 13:16:25 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:50107 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752675AbcJRRQX (ORCPT ); Tue, 18 Oct 2016 13:16:23 -0400 Message-Id: <20161018171513.734367391@infradead.org> User-Agent: quilt/0.63-1 Date: Tue, 18 Oct 2016 19:08:33 +0200 From: Peter Zijlstra To: Sergey Senozhatsky , Petr Mladek , Andrew Morton Cc: Jan Kara , Tejun Heo , Calvin Owens , Thomas Gleixner , Mel Gorman , Steven Rostedt , Ingo Molnar , Peter Zijlstra , linux-kernel@vger.kernel.org Subject: [PATCH 3/3] early_printk: Add simple serialization to early_vprintk() References: <20161018170830.405990950@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline; filename=peterz-early_printk-serialize.patch Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -356,14 +356,28 @@ 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(); + for (;;) { + old = cmpxchg(&early_printk_cpu, -1, cpu); + if (old == -1 || old == cpu) + break; + + cpu_relax(); + } n = vscnprintf(buf, sizeof(buf), fmt, args); early_console->write(early_console, buf, n); + smp_store_release(&early_printk_cpu, old); + put_cpu(); + return n; }