From patchwork Fri Feb 14 11:43:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 214301 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D716BC3B196 for ; Fri, 14 Feb 2020 11:43:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B5CFC222C4 for ; Fri, 14 Feb 2020 11:43:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728083AbgBNLnp (ORCPT ); Fri, 14 Feb 2020 06:43:45 -0500 Received: from mga04.intel.com ([192.55.52.120]:59063 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728004AbgBNLnp (ORCPT ); Fri, 14 Feb 2020 06:43:45 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Feb 2020 03:43:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,440,1574150400"; d="scan'208";a="228467752" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga008.fm.intel.com with ESMTP; 14 Feb 2020 03:43:41 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 8E46D24A; Fri, 14 Feb 2020 13:43:40 +0200 (EET) From: Andy Shevchenko To: Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, Sebastian Andrzej Siewior , Tony Lindgren Cc: Andy Shevchenko Subject: [PATCH v2 2/8] serial: core: Consolidate spin lock initialization code Date: Fri, 14 Feb 2020 13:43:33 +0200 Message-Id: <20200214114339.53897-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200214114339.53897-1-andriy.shevchenko@linux.intel.com> References: <20200214114339.53897-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org We have two times duplicated excerpt where we initialize spin lock for UART port. Consolidate it under uart_port_spin_lock_init() helper. Signed-off-by: Andy Shevchenko --- drivers/tty/serial/serial_core.c | 34 +++++++++++++++----------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index d956da0b6d9c..bb2287048108 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1913,6 +1913,19 @@ static inline bool uart_console_enabled(struct uart_port *port) return uart_console(port) && (port->cons->flags & CON_ENABLED); } +/* + * Ensure that the serial console lock is initialised early. + * If this port is a console, then the spinlock is already initialised. + */ +static inline void uart_port_spin_lock_init(struct uart_port *port) +{ + if (uart_console_enabled(port)) + return; + + spin_lock_init(&port->lock); + lockdep_set_class(&port->lock, &port_lock_key); +} + #if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL) /** * uart_console_write - write a console message to a serial port @@ -2065,16 +2078,7 @@ uart_set_options(struct uart_port *port, struct console *co, struct ktermios termios; static struct ktermios dummy; - /* - * Ensure that the serial console lock is initialised - * early. - * If this port is a console, then the spinlock is already - * initialised. - */ - if (!uart_console_enabled(port)) { - spin_lock_init(&port->lock); - lockdep_set_class(&port->lock, &port_lock_key); - } + uart_port_spin_lock_init(port); memset(&termios, 0, sizeof(struct ktermios)); @@ -2829,14 +2833,8 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport) goto out; } - /* - * If this port is a console, then the spinlock is already - * initialised. - */ - if (!uart_console_enabled(uport)) { - spin_lock_init(&uport->lock); - lockdep_set_class(&uport->lock, &port_lock_key); - } + uart_port_spin_lock_init(uport); + if (uport->cons && uport->dev) of_console_check(uport->dev->of_node, uport->cons->name, uport->line); From patchwork Fri Feb 14 11:43:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 214299 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AEE8C3B18F for ; Fri, 14 Feb 2020 11:43:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0022E24649 for ; Fri, 14 Feb 2020 11:43:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728036AbgBNLnp (ORCPT ); Fri, 14 Feb 2020 06:43:45 -0500 Received: from mga17.intel.com ([192.55.52.151]:20672 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727805AbgBNLnp (ORCPT ); Fri, 14 Feb 2020 06:43:45 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Feb 2020 03:43:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,440,1574150400"; d="scan'208";a="252614646" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 14 Feb 2020 03:43:41 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 9F78D393; Fri, 14 Feb 2020 13:43:40 +0200 (EET) From: Andy Shevchenko To: Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, Sebastian Andrzej Siewior , Tony Lindgren Cc: Andy Shevchenko Subject: [PATCH v2 4/8] serial: core: Allow detach and attach serial device for console Date: Fri, 14 Feb 2020 13:43:35 +0200 Message-Id: <20200214114339.53897-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200214114339.53897-1-andriy.shevchenko@linux.intel.com> References: <20200214114339.53897-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org In the future we would like to disable power management on the serial devices used as kernel consoles to avoid weird behaviour in some cases. However, disabling PM may prevent system to go to deep sleep states, which in its turn leads to the higher power consumption. Tony Lindgren proposed a work around, i.e. allow user to detach such consoles to make PM working again. In case user wants to see what's going on, it also provides a mechanism to attach console back. Link: https://lists.openwall.net/linux-kernel/2018/09/29/65 Suggested-by: Tony Lindgren Signed-off-by: Andy Shevchenko --- Documentation/ABI/testing/sysfs-tty | 7 ++++ drivers/tty/serial/serial_core.c | 60 +++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-tty b/Documentation/ABI/testing/sysfs-tty index 9eb3c2b6b040..e157130a6792 100644 --- a/Documentation/ABI/testing/sysfs-tty +++ b/Documentation/ABI/testing/sysfs-tty @@ -154,3 +154,10 @@ Description: device specification. For example, when user sets 7bytes on 16550A, which has 1/4/8/14 bytes trigger, the RX trigger is automatically changed to 4 bytes. + +What: /sys/class/tty/ttyS0/console +Date: February 2020 +Contact: Andy Shevchenko +Description: + Allows user to detach or attach back the given device as + kernel console. It shows and accepts a boolean variable. diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 7564bbd3061c..0415bb76efa0 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1919,7 +1919,7 @@ static inline bool uart_console_enabled(struct uart_port *port) */ static inline void uart_port_spin_lock_init(struct uart_port *port) { - if (uart_console_enabled(port)) + if (uart_console(port)) return; spin_lock_init(&port->lock); @@ -2749,6 +2749,56 @@ static ssize_t uart_get_attr_iomem_reg_shift(struct device *dev, return snprintf(buf, PAGE_SIZE, "%d\n", tmp.iomem_reg_shift); } +static ssize_t uart_get_attr_console(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct tty_port *port = dev_get_drvdata(dev); + struct uart_state *state = container_of(port, struct uart_state, port); + struct uart_port *uport; + bool console = false; + + mutex_lock(&port->mutex); + uport = uart_port_check(state); + if (uport) + console = uart_console_enabled(uport); + mutex_unlock(&port->mutex); + + return sprintf(buf, "%c\n", console ? 'Y' : 'N'); +} + +static ssize_t uart_set_attr_console(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct tty_port *port = dev_get_drvdata(dev); + struct uart_state *state = container_of(port, struct uart_state, port); + struct uart_port *uport; + bool oldconsole, newconsole; + int ret; + + ret = kstrtobool(buf, &newconsole); + if (ret) + return ret; + + mutex_lock(&port->mutex); + uport = uart_port_check(state); + if (uport) { + oldconsole = uart_console_enabled(uport); + if (oldconsole && !newconsole) { + ret = unregister_console(uport->cons); + } else if (!oldconsole && newconsole) { + if (uart_console(uport)) + register_console(uport->cons); + else + ret = -ENOENT; + } + } else { + ret = -ENXIO; + } + mutex_unlock(&port->mutex); + + return ret < 0 ? ret : count; +} + static DEVICE_ATTR(type, 0440, uart_get_attr_type, NULL); static DEVICE_ATTR(line, 0440, uart_get_attr_line, NULL); static DEVICE_ATTR(port, 0440, uart_get_attr_port, NULL); @@ -2762,6 +2812,7 @@ static DEVICE_ATTR(custom_divisor, 0440, uart_get_attr_custom_divisor, NULL); static DEVICE_ATTR(io_type, 0440, uart_get_attr_io_type, NULL); static DEVICE_ATTR(iomem_base, 0440, uart_get_attr_iomem_base, NULL); static DEVICE_ATTR(iomem_reg_shift, 0440, uart_get_attr_iomem_reg_shift, NULL); +static DEVICE_ATTR(console, 0640, uart_get_attr_console, uart_set_attr_console); static struct attribute *tty_dev_attrs[] = { &dev_attr_type.attr, @@ -2777,12 +2828,13 @@ static struct attribute *tty_dev_attrs[] = { &dev_attr_io_type.attr, &dev_attr_iomem_base.attr, &dev_attr_iomem_reg_shift.attr, - NULL, - }; + &dev_attr_console.attr, + NULL +}; static const struct attribute_group tty_dev_attr_group = { .attrs = tty_dev_attrs, - }; +}; /** * uart_add_one_port - attach a driver-defined port structure From patchwork Fri Feb 14 11:43:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 214297 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15562C47409 for ; Fri, 14 Feb 2020 11:43:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EA9A0222C2 for ; Fri, 14 Feb 2020 11:43:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728173AbgBNLnr (ORCPT ); Fri, 14 Feb 2020 06:43:47 -0500 Received: from mga14.intel.com ([192.55.52.115]:36654 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727805AbgBNLnp (ORCPT ); Fri, 14 Feb 2020 06:43:45 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Feb 2020 03:43:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,440,1574150400"; d="scan'208";a="281812027" Received: from black.fi.intel.com ([10.237.72.28]) by FMSMGA003.fm.intel.com with ESMTP; 14 Feb 2020 03:43:43 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id A72AB42D; Fri, 14 Feb 2020 13:43:40 +0200 (EET) From: Andy Shevchenko To: Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, Sebastian Andrzej Siewior , Tony Lindgren Cc: Andy Shevchenko , Russell King Subject: [PATCH v2 5/8] serial: 8250_port: Don't use power management for kernel console Date: Fri, 14 Feb 2020 13:43:36 +0200 Message-Id: <20200214114339.53897-6-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200214114339.53897-1-andriy.shevchenko@linux.intel.com> References: <20200214114339.53897-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Doing any kind of power management for kernel console is really bad idea. First of all, it runs in poll and atomic mode. This fact attaches a limitation on the functions that might be called. For example, pm_runtime_get_sync() might sleep and thus can't be used. This call needs, for example, to bring the device to powered on state on the system, where the power on sequence may require on-atomic operations, such as Intel Cherrytrail with ACPI enumerated UARTs. That said, on ACPI enabled platforms it might even call firmware for a job. On the other hand pm_runtime_get() doesn't guarantee that device will become powered on fast enough. Besides that, imagine the case when console is about to print a kernel Oops and it's powered off. In such an emergency case calling the complex functions is not the best what we can do, taking into consideration that user wants to see at least something of the last kernel word before it passes away. Here we modify the 8250 console code to prevent runtime power management. Link: https://lists.openwall.net/linux-kernel/2018/09/29/65 Suggested-by: Russell King Signed-off-by: Andy Shevchenko --- drivers/tty/serial/8250/8250_core.c | 9 +++++++++ drivers/tty/serial/8250/8250_port.c | 24 ++++++++++++++++++++---- include/linux/serial_8250.h | 1 + 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c index f2a33c9082a6..006d40853509 100644 --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -608,6 +608,14 @@ static int univ8250_console_setup(struct console *co, char *options) return retval; } +static int univ8250_console_exit(struct console *co) +{ + struct uart_port *port; + + port = &serial8250_ports[co->index].port; + return serial8250_console_exit(port); +} + /** * univ8250_console_match - non-standard console matching * @co: registering console @@ -666,6 +674,7 @@ static struct console univ8250_console = { .write = univ8250_console_write, .device = uart_console_device, .setup = univ8250_console_setup, + .exit = univ8250_console_exit, .match = univ8250_console_match, .flags = CON_PRINTBUFFER | CON_ANYTIME, .index = -1, diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index 0325f2e53b74..6307a04c0cd9 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -3127,6 +3127,9 @@ static void serial8250_console_restore(struct uart_8250_port *up) * any possible real use of the port... * * The console_lock must be held when we get here. + * + * Doing runtime PM is really a bad idea for the kernel console. + * Thus, we assume the function is called when device is powered up. */ void serial8250_console_write(struct uart_8250_port *up, const char *s, unsigned int count) @@ -3138,8 +3141,6 @@ void serial8250_console_write(struct uart_8250_port *up, const char *s, touch_nmi_watchdog(); - serial8250_rpm_get(up); - if (oops_in_progress) locked = spin_trylock_irqsave(&port->lock, flags); else @@ -3182,7 +3183,6 @@ void serial8250_console_write(struct uart_8250_port *up, const char *s, if (locked) spin_unlock_irqrestore(&port->lock, flags); - serial8250_rpm_put(up); } static unsigned int probe_baud(struct uart_port *port) @@ -3206,6 +3206,7 @@ int serial8250_console_setup(struct uart_port *port, char *options, bool probe) int bits = 8; int parity = 'n'; int flow = 'n'; + int ret; if (!port->iobase && !port->membase) return -ENODEV; @@ -3215,7 +3216,22 @@ int serial8250_console_setup(struct uart_port *port, char *options, bool probe) else if (probe) baud = probe_baud(port); - return uart_set_options(port, port->cons, baud, parity, bits, flow); + ret = uart_set_options(port, port->cons, baud, parity, bits, flow); + if (ret) + return ret; + + if (port->dev) + pm_runtime_get_noresume(port->dev); + + return 0; +} + +int serial8250_console_exit(struct uart_port *port) +{ + if (port->dev) + pm_runtime_put_noidle(port->dev); + + return 0; } #endif /* CONFIG_SERIAL_8250_CONSOLE */ diff --git a/include/linux/serial_8250.h b/include/linux/serial_8250.h index 6a8e8c48c882..8c7b16df7b09 100644 --- a/include/linux/serial_8250.h +++ b/include/linux/serial_8250.h @@ -176,6 +176,7 @@ void serial8250_set_defaults(struct uart_8250_port *up); void serial8250_console_write(struct uart_8250_port *up, const char *s, unsigned int count); int serial8250_console_setup(struct uart_port *port, char *options, bool probe); +int serial8250_console_exit(struct uart_port *port); extern void serial8250_set_isa_configurator(void (*v) (int port, struct uart_port *up, From patchwork Fri Feb 14 11:43:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 214298 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4F04C2BA83 for ; Fri, 14 Feb 2020 11:43:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A4AB0217F4 for ; Fri, 14 Feb 2020 11:43:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727754AbgBNLns (ORCPT ); Fri, 14 Feb 2020 06:43:48 -0500 Received: from mga09.intel.com ([134.134.136.24]:11576 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728261AbgBNLnr (ORCPT ); Fri, 14 Feb 2020 06:43:47 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Feb 2020 03:43:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,440,1574150400"; d="scan'208";a="234434013" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 14 Feb 2020 03:43:44 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id AE91845E; Fri, 14 Feb 2020 13:43:40 +0200 (EET) From: Andy Shevchenko To: Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, Sebastian Andrzej Siewior , Tony Lindgren Cc: Andy Shevchenko Subject: [PATCH v2 6/8] serial: 8250_port: Disable DMA operations for kernel console Date: Fri, 14 Feb 2020 13:43:37 +0200 Message-Id: <20200214114339.53897-7-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200214114339.53897-1-andriy.shevchenko@linux.intel.com> References: <20200214114339.53897-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org It would be too tricky and error prone to allow DMA operations on kernel console. One of the concern is when DMA is a separate device, for example on Intel CherryTrail platforms, and might need special work around to be functional, see the commit eebb3e8d8aaf ("ACPI / LPSS: override power state for LPSS DMA device") for more information. Another one is that kernel console is used in atomic context, e.g. when printing crucial information to the user (Oops or crash), and DMA may not serve due to power management complications including non-atomic ACPI calls but not limited to it (see above). Besides that, other concerns are described in the commit 84b40e3b57ee ("serial: 8250: omap: Disable DMA for console UART") done for OMAP UART and may be repeated here. Disable any kind of DMA operations on kernel console due to above concerns. Signed-off-by: Andy Shevchenko --- drivers/tty/serial/8250/8250_port.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index 6307a04c0cd9..8ed22aa31add 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -2294,10 +2294,14 @@ int serial8250_do_startup(struct uart_port *port) * Request DMA channels for both RX and TX. */ if (up->dma) { - retval = serial8250_request_dma(up); - if (retval) { - pr_warn_ratelimited("%s - failed to request DMA\n", - port->name); + const char *msg = NULL; + + if (uart_console(port)) + msg = "forbid DMA for kernel console"; + else if (serial8250_request_dma(up)) + msg = "failed to request DMA"; + if (msg) { + pr_warn_ratelimited("%s - %s\n", port->name, msg); up->dma = NULL; } }