Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3913588imj; Tue, 12 Feb 2019 06:50:55 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib0/AebLkGOW1WDnMU7BkOzcqPIZWSlUCdfxiJ+xhvTI1/NQdNZH2y9IXqD9FWof3uB9EWY X-Received: by 2002:a63:4a4d:: with SMTP id j13mr4050000pgl.127.1549983055398; Tue, 12 Feb 2019 06:50:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549983055; cv=none; d=google.com; s=arc-20160816; b=Mpd5tISrveu6R5QFXRxrhXBndcX4P9+9GuVEJj67564ibLKe/IzH3oa0KsJ3Tqy/qi fqJ/Qj5YxV8fe2ZFymQz0LrMj1uTdQj1W6jdGN6K4eVa06yQHSbDPZDPuL5i4kpShCI/ Tzgwz2B8F614HX6qcvRm8eTsTjpx8XzpHxsIHGPThRvb51QvubqA9Yp4rfo5tCBXN6qW qXIj+5e6IfxYrVwjKy/VFx5a4azfPh2Zd/eRjxZ8rUPtkVPUcxXcm2YGQs/XiJ8b7c28 rH90tIIvd7mGHnlGiIaRbnm/tz8c4yGcqqXwLAEArwpHryjsQzSoOKjc+koLHJucv2nd sdfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=NMuu+2ZbroHpdLTACTk+ToyaaBiT3ltYvRG56EhvTuk=; b=w8Z5kgoEigYPNsLFPW+VAJtOMfkMhBs0W8srT+9c9KI4r8CPUwfZApbbE0jw7VpZz+ tUYOGgOUTtkLyg1tYxEd77maXh+Lt4zb1OeB/zQy6uW8fwCV2tH9NkP4w+gEqh6hoQT/ enUwXmr5K6OyULJkWSqywkWG8RMC7igoKFcn3SyTKCLQv0OX/EyKCe/ud77n3QlR1L8P n57gJVMYfAVi7/Raq9AzmHSfPg8yhyoqkfnS1WMQf8g1qUpnaZ+KwuBFMGZElHe1619n 3hbcVArti7kpZOq/wWQVFEWPSbjaJ6Jizly6HWgq6fGgaB+ygBHL/mvuLJAnkAfGeA6k e+eA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n80si3309210pfj.177.2019.02.12.06.50.38; Tue, 12 Feb 2019 06:50:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728683AbfBLObu (ORCPT + 99 others); Tue, 12 Feb 2019 09:31:50 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:43809 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730218AbfBLOai (ORCPT ); Tue, 12 Feb 2019 09:30:38 -0500 Received: from [5.158.153.53] (helo=linux.lab.linutronix.de.) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1gtZ4q-0005Af-Ja; Tue, 12 Feb 2019 15:30:24 +0100 From: John Ogness To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Petr Mladek , Sergey Senozhatsky , Steven Rostedt , Daniel Wang , Andrew Morton , Linus Torvalds , Greg Kroah-Hartman , Alan Cox , Jiri Slaby , Peter Feiner , linux-serial@vger.kernel.org, Sergey Senozhatsky Subject: [RFC PATCH v1 18/25] console: add write_atomic interface Date: Tue, 12 Feb 2019 15:29:56 +0100 Message-Id: <20190212143003.48446-19-john.ogness@linutronix.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190212143003.48446-1-john.ogness@linutronix.de> References: <20190212143003.48446-1-john.ogness@linutronix.de> X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a write_atomic callback to the console. This is an optional function for console drivers. The function must be atomic (including NMI safe) for writing to the console. Console drivers must still implement the write callback. The write_atomic callback will only be used for emergency messages. Creating an NMI safe write_atomic that must synchronize with write requires a careful implementation of the console driver. To aid with the implementation, a set of console_atomic_* functions are provided: void console_atomic_lock(unsigned int *flags); void console_atomic_unlock(unsigned int flags); These functions synchronize using the processor-reentrant cpu lock of the printk buffer. Signed-off-by: John Ogness --- include/linux/console.h | 4 ++++ kernel/printk/printk.c | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/linux/console.h b/include/linux/console.h index 633fb741e871..13482565c08c 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -145,6 +145,7 @@ static inline int con_debug_leave(void) struct console { char name[16]; void (*write)(struct console *, const char *, unsigned); + void (*write_atomic)(struct console *, const char *, unsigned); int (*read)(struct console *, char *, unsigned); struct tty_driver *(*device)(struct console *, int *); void (*unblank)(void); @@ -231,4 +232,7 @@ extern void console_init(void); void dummycon_register_output_notifier(struct notifier_block *nb); void dummycon_unregister_output_notifier(struct notifier_block *nb); +extern void console_atomic_lock(unsigned int *flags); +extern void console_atomic_unlock(unsigned int flags); + #endif /* _LINUX_CONSOLE_H */ diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index cde036d8487a..0ff7c3942464 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2984,3 +2984,15 @@ void kmsg_dump_rewind(struct kmsg_dumper *dumper) } EXPORT_SYMBOL_GPL(kmsg_dump_rewind); #endif + +void console_atomic_lock(unsigned int *flags) +{ + prb_lock(&printk_cpulock, flags); +} +EXPORT_SYMBOL(console_atomic_lock); + +void console_atomic_unlock(unsigned int flags) +{ + prb_unlock(&printk_cpulock, flags); +} +EXPORT_SYMBOL(console_atomic_unlock); -- 2.11.0