From patchwork Fri Nov 27 11:09:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Mladek X-Patchwork-Id: 7712891 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 41CA39F4F5 for ; Fri, 27 Nov 2015 11:12:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 78A02205E5 for ; Fri, 27 Nov 2015 11:12:20 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9F3EA205E4 for ; Fri, 27 Nov 2015 11:12:19 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1a2GvA-0005rD-NR; Fri, 27 Nov 2015 11:10:32 +0000 Received: from mx2.suse.de ([195.135.220.15]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1a2Gum-0004TS-Bi for linux-arm-kernel@lists.infradead.org; Fri, 27 Nov 2015 11:10:10 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 8CFB6AD74; Fri, 27 Nov 2015 11:08:07 +0000 (UTC) From: Petr Mladek To: Andrew Morton Subject: [PATCH v2 2/5] printk/nmi: Use IRQ work only when ready Date: Fri, 27 Nov 2015 12:09:29 +0100 Message-Id: <1448622572-16900-3-git-send-email-pmladek@suse.com> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1448622572-16900-1-git-send-email-pmladek@suse.com> References: <1448622572-16900-1-git-send-email-pmladek@suse.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151127_031008_788230_24E65974 X-CRM114-Status: GOOD ( 12.67 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mips@linux-mips.org, Daniel Thompson , Jiri Kosina , linux-cris-kernel@axis.com, linux-s390@vger.kernel.org, Peter Zijlstra , x86@kernel.org, linux-kernel@vger.kernel.org, Steven Rostedt , adi-buildroot-devel@lists.sourceforge.net, Ingo Molnar , linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, Russell King , Thomas Gleixner , linuxppc-dev@lists.ozlabs.org, Petr Mladek , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP NMIs could happen at any time. This patch makes sure that the safe printk() in NMI will schedule IRQ work only when the related structs are initialized. All pending messages are flushed when the IRQ work is being initialized. Signed-off-by: Petr Mladek --- kernel/printk/nmi.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kernel/printk/nmi.c b/kernel/printk/nmi.c index 3989e13a0021..05b4c09110f9 100644 --- a/kernel/printk/nmi.c +++ b/kernel/printk/nmi.c @@ -36,6 +36,7 @@ * were handled or when IRQs are blocked. */ DEFINE_PER_CPU(printk_func_t, printk_func) = vprintk_default; +static int printk_nmi_irq_ready; struct nmi_seq_buf { atomic_t len; /* length of written data */ @@ -80,8 +81,11 @@ again: goto again; /* Get flushed in a more safe context. */ - if (add) + if (add && printk_nmi_irq_ready) { + /* Make sure that IRQ work is really initialized. */ + smp_rmb(); irq_work_queue(&s->work); + } return add; } @@ -187,6 +191,13 @@ void __init printk_nmi_init(void) init_irq_work(&s->work, __printk_nmi_flush); } + + /* Make sure that IRQ works are initialized before enabling. */ + smp_wmb(); + printk_nmi_irq_ready = 1; + + /* Flush pending messages that did not have scheduled IRQ works. */ + printk_nmi_flush(); } void printk_nmi_enter(void)