From patchwork Wed Sep 9 14:31:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 258060 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=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 49041C43461 for ; Wed, 9 Sep 2020 17:05:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0C4AB21919 for ; Wed, 9 Sep 2020 17:05:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599671121; bh=RcvdW5Wbw4qy2lBe4rstSsTHPZDNnLXT4NSX7F6cCe8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=v9fwgM8pp0/Z/KCRAO2Jp12vJaAr2HcGuoy/J+3mH3lp76DQwZVt9sABH3v+CIjQz Vy1v3OwVVTX58XS2dBDKcKTOLS835wXO+ceF9rIqHD6bfAola4PQ54wWrcb749sdmg hi4qbaQvGeQEp2ZGOZSn37sFf6vJQIsx071jXRzY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730551AbgIIRFT (ORCPT ); Wed, 9 Sep 2020 13:05:19 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:43031 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728443AbgIIPnJ (ORCPT ); Wed, 9 Sep 2020 11:43:09 -0400 Received: by mail-lj1-f196.google.com with SMTP id u4so4129289ljd.10; Wed, 09 Sep 2020 08:43:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mbZsg6zJ9YzguB6nUiWhHT7YZ4ojzslnf2Tm9G1IUuk=; b=RRZvhfOmZjPXeOoSewPmfTLRGlgj3Q+lfz6Tu73WDmMilhIlROcIyUTP3Yt/OrPgI3 nurEIkz+GV5w/+3j4nKYK18YylMKeXs69LdFOlxSDVoOwsAgpqrar7B26/XDM5takrB8 khk9MBrQUl7jHEL2Zvm4m9/apEkXZIn1+NVrmuEfJJe8SeV+f4YEuVaN/AE8DrdsPfhk qZIpKiZIlUBVHxNa8aalgc5VcBl2aZW9OtQxao3maAfh4xS2Ik7APp6cEJ4WrSog4G/Z 83h0dx0fmI6AP3bE8ZnnjMiSbQMFH1/6Twoib90IE8sPL8kuWpT+DXIyZ7DVUAqK/4J+ ThVw== X-Gm-Message-State: AOAM530OtwjqgkDg90Rd/lSwx5tANZOaSJ92OeHVNj4UGfur33vYZL7B Hp8a33tpXHfaSmOl33Z2H8YESKS5gFs= X-Google-Smtp-Source: ABdhPJwS3wrvbRTJ2zVlaE3xujZfh71HbLpExorB/edTGouYaURh6yY6hL4+gTtV9bo8bpSFq7F1lw== X-Received: by 2002:a2e:141d:: with SMTP id u29mr2062438ljd.243.1599661890371; Wed, 09 Sep 2020 07:31:30 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id u9sm514049lju.95.2020.09.09.07.31.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 07:31:29 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kG18A-000418-UP; Wed, 09 Sep 2020 16:31:26 +0200 From: Johan Hovold To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Andy Shevchenko , Johan Hovold , stable Subject: [PATCH 1/2] serial: core: fix port-lock initialisation Date: Wed, 9 Sep 2020 16:31:00 +0200 Message-Id: <20200909143101.15389-2-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200909143101.15389-1-johan@kernel.org> References: <20200909143101.15389-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Commit f743061a85f5 ("serial: core: Initialise spin lock before use in uart_configure_port()") tried to work around a breakage introduced by commit a3cb39d258ef ("serial: core: Allow detach and attach serial device for console") by adding a second initialisation of the port lock when registering the port. As reported by the build robots [1], this doesn't really solve the regression introduced by the console-detach changes and also adds a second redundant initialisation of the lock for normal ports. Start cleaning up this mess by removing the redundant initialisation and making sure that the port lock is again initialised once-only for ports that aren't already in use as a console. [1] https://lore.kernel.org/r/20200802054852.GR23458@shao2-debian Fixes: f743061a85f5 ("serial: core: Initialise spin lock before use in uart_configure_port()") Fixes: a3cb39d258ef ("serial: core: Allow detach and attach serial device for console") Cc: stable # 5.7 Cc: Andy Shevchenko Signed-off-by: Johan Hovold --- drivers/tty/serial/serial_core.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index f797c971cd82..53b79e1fcbc8 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -2378,13 +2378,6 @@ uart_configure_port(struct uart_driver *drv, struct uart_state *state, /* Power up port for set_mctrl() */ uart_change_pm(state, UART_PM_STATE_ON); - /* - * If this driver supports console, and it hasn't been - * successfully registered yet, initialise spin lock for it. - */ - if (port->cons && !(port->cons->flags & CON_ENABLED)) - __uart_port_spin_lock_init(port); - /* * Ensure that the modem control lines are de-activated. * keep the DTR setting that is set in uart_set_options() @@ -2900,7 +2893,12 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport) goto out; } - uart_port_spin_lock_init(uport); + /* + * If this port is in use as a console then the spinlock is already + * initialised. + */ + if (!uart_console_enabled(uport)) + __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 Wed Sep 9 14:31:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 297009 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=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 1D0AFC43461 for ; Wed, 9 Sep 2020 17:09:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C828E21941 for ; Wed, 9 Sep 2020 17:09:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599671394; bh=owyEgMcfPs68c15/bSVWTgCiIRzr/NN2Ga4Lbh82KXs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=k3H/yv8NxM9b9TgSHw1x09SXPLbIPzOv/jG5FccVrLEyIpUGzqNiixJzaIF8cekLE xLF/26CSdmaQME+shzL2jJc0TmwIGPqQD/oq+ilNo+JwOSDOGBAVrCMjeG44ZjBhv0 Vata1pIhzjjQ0c0fQ3y2C33N8ru1KUGjgsu5wqBw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730604AbgIIRJv (ORCPT ); Wed, 9 Sep 2020 13:09:51 -0400 Received: from mail-ej1-f66.google.com ([209.85.218.66]:42534 "EHLO mail-ej1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730224AbgIIPgB (ORCPT ); Wed, 9 Sep 2020 11:36:01 -0400 Received: by mail-ej1-f66.google.com with SMTP id q13so4179483ejo.9; Wed, 09 Sep 2020 08:35:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qP6O2ucn5KuDRC7RB2WRLd9myNrDAnc1ixV/2OFvSfA=; b=Cg4PLTB08yBHJQsQW/PfsBFiRrKA45GKvH1wRkcrGVceSxcdFgJBavweZraWzLk/bF 3PFxarALEuOZO9itpNOZEKOaK3XpquI4u6IywkKlb4vchMx1KazWyEhs24vyBGKNwHeV Gz5GTzI8N5coJMPg3lJZYPq5pC+a/rp0B0rKUHd4R6O+VviycAHYr6C8zk9VOXJEG8vk /GRaXZ8817J7CqF6LOhipPvSon0aJkdkV+O483k7P8xxk9h2rK3Oso9DykYDOF7PQ8bK 3r4ddQP7ji6BbQ+5NA5u9t5a4LAtapmcBiRcfu7h0kxNIL8x9o6n5HbdyVUR5Rlpwk2q w3Sg== X-Gm-Message-State: AOAM531Cvey5IbHb30HMnaeR7AuEenfpHRmL17e7s7UKBQL3Qbmred6Q E6I7eYzIzCVzUJx2JCC+2sdJLepcs68= X-Google-Smtp-Source: ABdhPJxkx0pKWo4zITjkUOd3XsCXmG/5wXI1KoHYWOKbmq1Yq+MSaAZNQZh7k9wsK9NWreIyeaSFVA== X-Received: by 2002:a19:4186:: with SMTP id o128mr1899570lfa.148.1599661891771; Wed, 09 Sep 2020 07:31:31 -0700 (PDT) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id 206sm612714lfd.72.2020.09.09.07.31.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 07:31:29 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kG18B-00041D-1O; Wed, 09 Sep 2020 16:31:27 +0200 From: Johan Hovold To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Andy Shevchenko , Johan Hovold , stable Subject: [PATCH 2/2] serial: core: fix console port-lock regression Date: Wed, 9 Sep 2020 16:31:01 +0200 Message-Id: <20200909143101.15389-3-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200909143101.15389-1-johan@kernel.org> References: <20200909143101.15389-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Fix the port-lock initialisation regression introduced by commit a3cb39d258ef ("serial: core: Allow detach and attach serial device for console") by making sure that the lock is again initialised during console setup. The console may be registered before the serial controller has been probed in which case the port lock needs to be initialised during console setup by a call to uart_set_options(). The console-detach changes introduced a regression in several drivers by effectively removing that initialisation by not initialising the lock when the port is used as a console (which is always the case during console setup). Add back the early lock initialisation and instead use a new console-reinit flag to handle the case where a console is being re-attached through sysfs. The question whether the console-detach interface should have been added in the first place is left for another discussion. Note that the console-enabled check in uart_set_options() is not redundant because of kgdboc, which can end up reinitialising an already enabled console (see commit 42b6a1baa3ec ("serial_core: Don't re-initialize a previously initialized spinlock.")). Fixes: a3cb39d258ef ("serial: core: Allow detach and attach serial device for console") Cc: stable # 5.7 Cc: Andy Shevchenko Signed-off-by: Johan Hovold --- drivers/tty/serial/serial_core.c | 32 +++++++++++++++----------------- include/linux/serial_core.h | 1 + 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 53b79e1fcbc8..124524ecfe26 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -1916,24 +1916,12 @@ static inline bool uart_console_enabled(struct uart_port *port) return uart_console(port) && (port->cons->flags & CON_ENABLED); } -static void __uart_port_spin_lock_init(struct uart_port *port) +static void uart_port_spin_lock_init(struct uart_port *port) { spin_lock_init(&port->lock); lockdep_set_class(&port->lock, &port_lock_key); } -/* - * 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(port)) - return; - - __uart_port_spin_lock_init(port); -} - #if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL) /** * uart_console_write - write a console message to a serial port @@ -2086,7 +2074,15 @@ uart_set_options(struct uart_port *port, struct console *co, struct ktermios termios; static struct ktermios dummy; - uart_port_spin_lock_init(port); + /* + * Ensure that the serial-console lock is initialised early. + * + * Note that the console-enabled check is needed because of kgdboc, + * which can end up calling uart_set_options() for an already enabled + * console via tty_find_polling_driver() and uart_poll_init(). + */ + if (!uart_console_enabled(port) && !port->console_reinit) + uart_port_spin_lock_init(port); memset(&termios, 0, sizeof(struct ktermios)); @@ -2794,10 +2790,12 @@ static ssize_t console_store(struct device *dev, if (oldconsole && !newconsole) { ret = unregister_console(uport->cons); } else if (!oldconsole && newconsole) { - if (uart_console(uport)) + if (uart_console(uport)) { + uport->console_reinit = 1; register_console(uport->cons); - else + } else { ret = -ENOENT; + } } } else { ret = -ENXIO; @@ -2898,7 +2896,7 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport) * initialised. */ if (!uart_console_enabled(uport)) - __uart_port_spin_lock_init(uport); + uart_port_spin_lock_init(uport); if (uport->cons && uport->dev) of_console_check(uport->dev->of_node, uport->cons->name, uport->line); diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 01fc4d9c9c54..8a99279a579b 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -248,6 +248,7 @@ struct uart_port { unsigned char hub6; /* this should be in the 8250 driver */ unsigned char suspended; + unsigned char console_reinit; const char *name; /* port name */ struct attribute_group *attr_group; /* port specific attributes */ const struct attribute_group **tty_groups; /* all attributes (serial core use only) */