From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 595F0EEAA6A for ; Thu, 14 Sep 2023 18:38:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241502AbjINSit (ORCPT ); Thu, 14 Sep 2023 14:38:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234957AbjINSiq (ORCPT ); Thu, 14 Sep 2023 14:38:46 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0A781FF9; Thu, 14 Sep 2023 11:38:41 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716719; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IRoapPsp3k8C9+cAJncEIUfgF6L1OgYHKNIWMNQArN8=; b=VAjKIhObU4Ecwzj1Ft23hUIFCg5wNU+ACZXfHOo/+M6G3rDdjIutIP/3dgKZphFycD7k0s l1K/shKjUF1xNDyqSV4Dkv1WCexNBS4t69JIncUEixls1YhZ/pLnSCgDpEory16tlJ3aaK cTsL9IOd8JYrt8dYej3n1jevYWZHoDYTaJtVMpwp/BHiRAyRsFxkoewey2tW8f/zXlHHoj eGxIhZNWggKOIC77flgOvFXuitF29LOz6qsVQG5nx2unbIXnsGYvp0nQHU7vFHpswVtoGd qFrRpKlOyVTIQm/uj3/xhPNHlPXIYSjTqnj+ukPYGxr4V79XY9RgkxxGqm6CVQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716719; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IRoapPsp3k8C9+cAJncEIUfgF6L1OgYHKNIWMNQArN8=; b=wGLW0CPqtjKXdq32BWOBlskt8IKEQHA9vLWBa4IeEQiBvGjl9GrE1AxJD/0KbuJjMJhKKB l4R6nV8mtg7pUYBQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH tty v1 01/74] serial: core: Provide port lock wrappers Date: Thu, 14 Sep 2023 20:43:18 +0206 Message-Id: <20230914183831.587273-2-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. Provide wrapper functions for spin_[un]lock*(port->lock) invocations so that the console mechanics can be applied later on at a single place and does not require to copy the same logic all over the drivers. Signed-off-by: Thomas Gleixner Reviewed-by: Ilpo J=C3=A4rvinen Reviewed-by: Petr Mladek --- include/linux/serial_core.h | 79 +++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index bb6f073bc159..f1d5c0d1568c 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -588,6 +588,85 @@ struct uart_port { void *private_data; /* generic platform data pointer */ }; =20 +/** + * uart_port_lock - Lock the UART port + * @up: Pointer to UART port structure + */ +static inline void uart_port_lock(struct uart_port *up) +{ + spin_lock(&up->lock); +} + +/** + * uart_port_lock_irq - Lock the UART port and disable interrupts + * @up: Pointer to UART port structure + */ +static inline void uart_port_lock_irq(struct uart_port *up) +{ + spin_lock_irq(&up->lock); +} + +/** + * uart_port_lock_irqsave - Lock the UART port, save and disable interrupts + * @up: Pointer to UART port structure + * @flags: Pointer to interrupt flags storage + */ +static inline void uart_port_lock_irqsave(struct uart_port *up, unsigned l= ong *flags) +{ + spin_lock_irqsave(&up->lock, *flags); +} + +/** + * uart_port_trylock - Try to lock the UART port + * @up: Pointer to UART port structure + * + * Returns: True if lock was acquired, false otherwise + */ +static inline bool uart_port_trylock(struct uart_port *up) +{ + return spin_trylock(&up->lock); +} + +/** + * uart_port_trylock_irqsave - Try to lock the UART port, save and disable= interrupts + * @up: Pointer to UART port structure + * @flags: Pointer to interrupt flags storage + * + * Returns: True if lock was acquired, false otherwise + */ +static inline bool uart_port_trylock_irqsave(struct uart_port *up, unsigne= d long *flags) +{ + return spin_trylock_irqsave(&up->lock, *flags); +} + +/** + * uart_port_unlock - Unlock the UART port + * @up: Pointer to UART port structure + */ +static inline void uart_port_unlock(struct uart_port *up) +{ + spin_unlock(&up->lock); +} + +/** + * uart_port_unlock_irq - Unlock the UART port and re-enable interrupts + * @up: Pointer to UART port structure + */ +static inline void uart_port_unlock_irq(struct uart_port *up) +{ + spin_unlock_irq(&up->lock); +} + +/** + * uart_port_lock_irqrestore - Unlock the UART port, restore interrupts + * @up: Pointer to UART port structure + * @flags: The saved interrupt flags for restore + */ +static inline void uart_port_unlock_irqrestore(struct uart_port *up, unsig= ned long flags) +{ + spin_unlock_irqrestore(&up->lock, flags); +} + static inline int serial_port_in(struct uart_port *up, int offset) { return up->serial_in(up, offset); --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0268AEEAA6B for ; Thu, 14 Sep 2023 18:38:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241553AbjINSiv (ORCPT ); Thu, 14 Sep 2023 14:38:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231881AbjINSiq (ORCPT ); Thu, 14 Sep 2023 14:38:46 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE7501FEB; Thu, 14 Sep 2023 11:38:41 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716719; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OtT3qcU2XT7sBWbeVRoS4eXwomdEnzl8JI54HpXjFPk=; b=16oMLXh+x41buwFBxm6MjmScUALYnbHnctuSlnCJImDb+hw6IInt0wo8Oz7A7El5VEtrzZ ehgyfKluVVW+QLIaiBAOsZTImLOShBkB8G9EBqB7JcGNn5k48TwECuTG4UlOTZH5MSdwHs hxvPohSSTULpW9tg9xJiFxOd0ZreLZGAH4KwMbCe9li0OELjCwmLocizmQc3bfTBXr768z NUkJytLfCrs+3V3XppweqwkkFWHFWXYIwVuw54Qr2Bn/SXld+NLkJHqZYJiI4IvtWPfEKz G8bmjzQrKvBcdEOeUtWsqI2QUQyyEqkFgml+Ze2Au7tqNhW1+CyrEjoNdPbf0w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716719; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OtT3qcU2XT7sBWbeVRoS4eXwomdEnzl8JI54HpXjFPk=; b=z6TexzG/00l02Fbtx0bPhdCI79PStLL0Fhn/0+ixK+c/BftQZOZ2PcUkUHXgDPVF8zvEno 3ft3BN8P50LrL+BQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH tty v1 02/74] serial: core: Use lock wrappers Date: Thu, 14 Sep 2023 20:43:19 +0206 Message-Id: <20230914183831.587273-3-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner Reviewed-by: Ilpo J=C3=A4rvinen --- include/linux/serial_core.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index f1d5c0d1568c..3091c62ec37b 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -1035,14 +1035,14 @@ static inline void uart_unlock_and_check_sysrq(stru= ct uart_port *port) u8 sysrq_ch; =20 if (!port->has_sysrq) { - spin_unlock(&port->lock); + uart_port_unlock(port); return; } =20 sysrq_ch =3D port->sysrq_ch; port->sysrq_ch =3D 0; =20 - spin_unlock(&port->lock); + uart_port_unlock(port); =20 if (sysrq_ch) handle_sysrq(sysrq_ch); @@ -1054,14 +1054,14 @@ static inline void uart_unlock_and_check_sysrq_irqr= estore(struct uart_port *port u8 sysrq_ch; =20 if (!port->has_sysrq) { - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); return; } =20 sysrq_ch =3D port->sysrq_ch; port->sysrq_ch =3D 0; =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 if (sysrq_ch) handle_sysrq(sysrq_ch); @@ -1077,12 +1077,12 @@ static inline int uart_prepare_sysrq_char(struct ua= rt_port *port, u8 ch) } static inline void uart_unlock_and_check_sysrq(struct uart_port *port) { - spin_unlock(&port->lock); + uart_port_unlock(port); } static inline void uart_unlock_and_check_sysrq_irqrestore(struct uart_port= *port, unsigned long flags) { - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } #endif /* CONFIG_MAGIC_SYSRQ_SERIAL */ =20 --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39FC4EEAA66 for ; Thu, 14 Sep 2023 18:38:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241674AbjINSix (ORCPT ); Thu, 14 Sep 2023 14:38:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237683AbjINSiq (ORCPT ); Thu, 14 Sep 2023 14:38:46 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB1341FFB; Thu, 14 Sep 2023 11:38:41 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716720; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rtv2ooAyzSE0YQWAS7XlGsZho6T7ZcwOVdsZs7LIu1E=; b=g+dINB6iW64ACyGaujJ1o1fmjmZZbggm+6IGvHEYyUBn1NzpRPs7TAlZjj6IsoY1R6uRqA l02QK0APIRRJEGEHzLmuA3KNxtug5g+ZiMeicDYNS16St1i3YebOJpD8Th+Ih0YDcly03Y 88NV2gWch783aKq55g9nJrpFBkOUi+kX5aDhtwbssvlMaTyqZEhO4g9OM0wPPxDm3k2Dd1 WLbM9DkVbWc/Pmo0rWfMA0lismVw25oXL6aNdf3ZGpKv2Oq7ytfCJtWuGu+AbLDTWO10uR b0MdDi4MZRShdMearsckOqhJOJsQAj23J0JWA6Mgza8OCdfmiqjky48X7C7X3g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716720; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rtv2ooAyzSE0YQWAS7XlGsZho6T7ZcwOVdsZs7LIu1E=; b=PhIqp92kh8QdxyU/WhDvrm3+buau2QJZp8tIjUyzIecq6jH+ypbOUQF51L77DTojwzBhYS 2sI3D1mGczaDbsBw== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Tobias Klauser , Thierry Reding Subject: [PATCH tty v1 03/74] serial: 21285: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:20 +0206 Message-Id: <20230914183831.587273-4-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/21285.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/21285.c b/drivers/tty/serial/21285.c index d756fcc884cb..4de0c975ebdc 100644 --- a/drivers/tty/serial/21285.c +++ b/drivers/tty/serial/21285.c @@ -185,14 +185,14 @@ static void serial21285_break_ctl(struct uart_port *p= ort, int break_state) unsigned long flags; unsigned int h_lcr; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); h_lcr =3D *CSR_H_UBRLCR; if (break_state) h_lcr |=3D H_UBRLCR_BREAK; else h_lcr &=3D ~H_UBRLCR_BREAK; *CSR_H_UBRLCR =3D h_lcr; - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static int serial21285_startup(struct uart_port *port) @@ -272,7 +272,7 @@ serial21285_set_termios(struct uart_port *port, struct = ktermios *termios, if (port->fifosize) h_lcr |=3D H_UBRLCR_FIFO; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* * Update the per-port timeout. @@ -309,7 +309,7 @@ serial21285_set_termios(struct uart_port *port, struct = ktermios *termios, *CSR_H_UBRLCR =3D h_lcr; *CSR_UARTCON =3D 1; =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *serial21285_type(struct uart_port *port) --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A927FEEAA69 for ; Thu, 14 Sep 2023 18:38:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241353AbjINSis (ORCPT ); Thu, 14 Sep 2023 14:38:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239212AbjINSiq (ORCPT ); Thu, 14 Sep 2023 14:38:46 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F17361FFC; Thu, 14 Sep 2023 11:38:41 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716720; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YzGTH7vi1woKgPlT+ew1GuAaXeqKELiHy4YX6FZB2Ws=; b=xI67S1N4oC7yZQ9a9pniupQBCdXgHbJJUonVJdWsOkhhnFOa3cgAIkwfV4vuJtXSyJwzGS ruLvaJ23/nSLO9Ctn9PW8PFVTJdY8yeVPHpSgQYp9ZF1TwlDTauZliU85WtWCbaMi3Rba5 Mts0uuFAMmVvXYE9ku+eTUZi159cnJ2SyratQjN1nGHBxeJKcn0vSj4TMO6ufnyaiVBCia 81rJQ7Sziv0cKeEYwa2pleTD3/xlhdfQVaC+br4A+ErFX3p2fkPjiXSkNPTpjycU317yLV fMbzRFn+93V2pSpx/IXHoYVxiv8Q7qYIOtQ5MbR5aobUJbuT7RGBBVpUF5sMgw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716720; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YzGTH7vi1woKgPlT+ew1GuAaXeqKELiHy4YX6FZB2Ws=; b=EMockjhcNy6AcG+UO3snhVjQB3YOEKFZrpHHn/aVPBYlDJ7RlYj5Zo30u0wb1oMlWhBLHQ GJWHincAnGHiCdDA== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Joel Stanley , Andrew Jeffery , linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org Subject: [PATCH tty v1 04/74] serial: 8250_aspeed_vuart: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:21 +0206 Message-Id: <20230914183831.587273-5-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/8250/8250_aspeed_vuart.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/8250/8250_aspeed_vuart.c b/drivers/tty/seri= al/8250/8250_aspeed_vuart.c index 4a9e71b2dbbc..021949f252f8 100644 --- a/drivers/tty/serial/8250/8250_aspeed_vuart.c +++ b/drivers/tty/serial/8250/8250_aspeed_vuart.c @@ -288,9 +288,9 @@ static void aspeed_vuart_set_throttle(struct uart_port = *port, bool throttle) struct uart_8250_port *up =3D up_to_u8250p(port); unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); __aspeed_vuart_set_throttle(up, throttle); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void aspeed_vuart_throttle(struct uart_port *port) @@ -340,7 +340,7 @@ static int aspeed_vuart_handle_irq(struct uart_port *po= rt) if (iir & UART_IIR_NO_INT) return 0; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 lsr =3D serial_port_in(port, UART_LSR); =20 --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93564EEAA68 for ; Thu, 14 Sep 2023 18:38:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241754AbjINSi6 (ORCPT ); Thu, 14 Sep 2023 14:38:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241396AbjINSis (ORCPT ); Thu, 14 Sep 2023 14:38:48 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 951AF1FEB; Thu, 14 Sep 2023 11:38:43 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716721; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Lt5U7bhcPdg54ZjyRgBGpBHomTbVhANlcjrKnJ+8kPw=; b=EjjUZZFHZ6JEVqxq3P4LuSHl7TGqgTOROKasaPekDARF8A49stqUSFmsqni7LyXpfAdYK7 CoqFh/m07XeKuCogjjsrSKzMDMa3snkU3tYDlm6BmNA45xZftvuf8O7GdAeNdLHnAaMyNC V9xtj2T6cQeDpuVnLeJbj+CYAOKwAxm526w1yemc7zGSgHftG8j4v2NuhwIBAdhjqXu+uM CgE+auOclmQkeboCagqSRFMlYyGQHm46H8sVsqHqWUshGt7HEpGNqRJIbFSEbEScEdjXpG A/htA9D3DQtniUYGBpEkCaKVP+IunLMmmA4wQMQzA1BVjwdYi1OZ7wyVrBA3bw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716721; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Lt5U7bhcPdg54ZjyRgBGpBHomTbVhANlcjrKnJ+8kPw=; b=EPAqhJ+RFWjFNq1J0uytEfmWnzRpERI45y4ct0hHAnM0cAa51LiN2tTTwocLooVVKkTvuu +nWAe6xeREHBzkBw== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Al Cooper , Broadcom internal kernel review list Subject: [PATCH tty v1 05/74] serial: 8250_bcm7271: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:22 +0206 Message-Id: <20230914183831.587273-6-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/8250/8250_bcm7271.c | 28 +++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/tty/serial/8250/8250_bcm7271.c b/drivers/tty/serial/82= 50/8250_bcm7271.c index aa5aff046756..ff0662c68725 100644 --- a/drivers/tty/serial/8250/8250_bcm7271.c +++ b/drivers/tty/serial/8250/8250_bcm7271.c @@ -567,7 +567,7 @@ static irqreturn_t brcmuart_isr(int irq, void *dev_id) if (interrupts =3D=3D 0) return IRQ_NONE; =20 - spin_lock_irqsave(&up->lock, flags); + uart_port_lock_irqsave(up, &flags); =20 /* Clear all interrupts */ udma_writel(priv, REGS_DMA_ISR, UDMA_INTR_CLEAR, interrupts); @@ -581,7 +581,7 @@ static irqreturn_t brcmuart_isr(int irq, void *dev_id) if ((rval | tval) =3D=3D 0) dev_warn(dev, "Spurious interrupt: 0x%x\n", interrupts); =20 - spin_unlock_irqrestore(&up->lock, flags); + uart_port_unlock_irqrestore(up, flags); return IRQ_HANDLED; } =20 @@ -608,10 +608,10 @@ static int brcmuart_startup(struct uart_port *port) * * Synchronize UART_IER access against the console. */ - spin_lock_irq(&port->lock); + uart_port_lock_irq(port); up->ier &=3D ~UART_IER_RDI; serial_port_out(port, UART_IER, up->ier); - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); =20 priv->tx_running =3D false; priv->dma.rx_dma =3D NULL; @@ -629,7 +629,7 @@ static void brcmuart_shutdown(struct uart_port *port) struct brcmuart_priv *priv =3D up->port.private_data; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); priv->shutdown =3D true; if (priv->dma_enabled) { stop_rx_dma(up); @@ -645,7 +645,7 @@ static void brcmuart_shutdown(struct uart_port *port) */ up->dma =3D NULL; =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); serial8250_do_shutdown(port); } =20 @@ -788,7 +788,7 @@ static int brcmuart_handle_irq(struct uart_port *p) * interrupt but there is no data ready. */ if (((iir & UART_IIR_ID) =3D=3D UART_IIR_RX_TIMEOUT) && !(priv->shutdown)= ) { - spin_lock_irqsave(&p->lock, flags); + uart_port_lock_irqsave(p, &flags); status =3D serial_port_in(p, UART_LSR); if ((status & UART_LSR_DR) =3D=3D 0) { =20 @@ -813,7 +813,7 @@ static int brcmuart_handle_irq(struct uart_port *p) =20 handled =3D 1; } - spin_unlock_irqrestore(&p->lock, flags); + uart_port_unlock_irqrestore(p, flags); if (handled) return 1; } @@ -831,7 +831,7 @@ static enum hrtimer_restart brcmuart_hrtimer_func(struc= t hrtimer *t) if (priv->shutdown) return HRTIMER_NORESTART; =20 - spin_lock_irqsave(&p->lock, flags); + uart_port_lock_irqsave(p, &flags); status =3D serial_port_in(p, UART_LSR); =20 /* @@ -855,7 +855,7 @@ static enum hrtimer_restart brcmuart_hrtimer_func(struc= t hrtimer *t) status |=3D UART_MCR_RTS; serial_port_out(p, UART_MCR, status); } - spin_unlock_irqrestore(&p->lock, flags); + uart_port_unlock_irqrestore(p, flags); return HRTIMER_NORESTART; } =20 @@ -1154,10 +1154,10 @@ static int __maybe_unused brcmuart_suspend(struct d= evice *dev) * This will prevent resume from enabling RTS before the * baud rate has been restored. */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); priv->saved_mctrl =3D port->mctrl; port->mctrl &=3D ~TIOCM_RTS; - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 serial8250_suspend_port(priv->line); clk_disable_unprepare(priv->baud_mux_clk); @@ -1196,10 +1196,10 @@ static int __maybe_unused brcmuart_resume(struct de= vice *dev) =20 if (priv->saved_mctrl & TIOCM_RTS) { /* Restore RTS */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); port->mctrl |=3D TIOCM_RTS; port->ops->set_mctrl(port, port->mctrl); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 return 0; --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DFCCEEAA62 for ; Thu, 14 Sep 2023 18:39:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241555AbjINSjD (ORCPT ); Thu, 14 Sep 2023 14:39:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237837AbjINSis (ORCPT ); Thu, 14 Sep 2023 14:38:48 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D8AE1FD7; Thu, 14 Sep 2023 11:38:43 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716721; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lTxTld72jsbFLwbI2RprxpQt/WT5K9+FgFLsAE2902M=; b=n0C85JkbazQQQqk994zwcXCFNCkWtviypeikAhkD4Peur7hNh9TfMzWdACRHIotOkc73y3 MM9dC2UwjT1uNPUSJ1rX/Wg0/KwQnC3OMYmWzI7QSX+ZyfRbJighMJm3ZK/4ER/3rdWuEz jJ+onkk8n4sltcqsJWtLI7/f7QQ7htklwmMl+vR3WK9yYr9e8uc6femPGqYMrr0TAnadFl 01okjELZl/Wt7n3p0koa/2v+3GAcCvIWvqe360+k7kYIf8JmcOpOvnLhBVNGFXKwtm7j37 yoI/UzcG03SZzeMS9ChkZZJQnWAGa44qb6a+iCaCrbovxd7HbrXSOCW5lqSfMA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716721; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lTxTld72jsbFLwbI2RprxpQt/WT5K9+FgFLsAE2902M=; b=4bDoaa+QazP1WDXkaSwXU2eQvkxKWr9YgMinglGoyPJplI2ioNYKHDKVT/2ieODghymWrW eZzEP+yP2UuKguBg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Tony Lindgren , Andy Shevchenko , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Florian Fainelli Subject: [PATCH tty v1 06/74] serial: 8250: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:23 +0206 Message-Id: <20230914183831.587273-7-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner Reviewed-by: Ilpo J=C3=A4rvinen --- drivers/tty/serial/8250/8250_core.c | 12 ++-- drivers/tty/serial/8250/8250_port.c | 100 ++++++++++++++-------------- 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/= 8250_core.c index 3449f8790e46..904e319e6b4a 100644 --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -259,7 +259,7 @@ static void serial8250_backup_timeout(struct timer_list= *t) unsigned int iir, ier =3D 0, lsr; unsigned long flags; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 /* * Must disable interrupts or else we risk racing with the interrupt @@ -292,7 +292,7 @@ static void serial8250_backup_timeout(struct timer_list= *t) if (up->port.irq) serial_out(up, UART_IER, ier); =20 - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =20 /* Standard timer interval plus 0.2s to keep the port running */ mod_timer(&up->timer, @@ -992,11 +992,11 @@ static void serial_8250_overrun_backoff_work(struct w= ork_struct *work) struct uart_port *port =3D &up->port; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); up->ier |=3D UART_IER_RLSI | UART_IER_RDI; up->port.read_status_mask |=3D UART_LSR_DR; serial_out(up, UART_IER, up->ier); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /** @@ -1194,9 +1194,9 @@ void serial8250_unregister_port(int line) if (uart->em485) { unsigned long flags; =20 - spin_lock_irqsave(&uart->port.lock, flags); + uart_port_lock_irqsave(&uart->port, &flags); serial8250_em485_destroy(uart); - spin_unlock_irqrestore(&uart->port.lock, flags); + uart_port_unlock_irqrestore(&uart->port, flags); } =20 uart_remove_one_port(&serial8250_reg, &uart->port); diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/= 8250_port.c index fb891b67968f..cd82bf7dd4f5 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -689,7 +689,7 @@ static void serial8250_set_sleep(struct uart_8250_port = *p, int sleep) =20 if (p->capabilities & UART_CAP_SLEEP) { /* Synchronize UART_IER access against the console. */ - spin_lock_irq(&p->port.lock); + uart_port_lock_irq(&p->port); if (p->capabilities & UART_CAP_EFR) { lcr =3D serial_in(p, UART_LCR); efr =3D serial_in(p, UART_EFR); @@ -703,7 +703,7 @@ static void serial8250_set_sleep(struct uart_8250_port = *p, int sleep) serial_out(p, UART_EFR, efr); serial_out(p, UART_LCR, lcr); } - spin_unlock_irq(&p->port.lock); + uart_port_unlock_irq(&p->port); } =20 serial8250_rpm_put(p); @@ -746,9 +746,9 @@ static void enable_rsa(struct uart_8250_port *up) { if (up->port.type =3D=3D PORT_RSA) { if (up->port.uartclk !=3D SERIAL_RSA_BAUD_BASE * 16) { - spin_lock_irq(&up->port.lock); + uart_port_lock_irq(&up->port); __enable_rsa(up); - spin_unlock_irq(&up->port.lock); + uart_port_unlock_irq(&up->port); } if (up->port.uartclk =3D=3D SERIAL_RSA_BAUD_BASE * 16) serial_out(up, UART_RSA_FRR, 0); @@ -768,7 +768,7 @@ static void disable_rsa(struct uart_8250_port *up) =20 if (up->port.type =3D=3D PORT_RSA && up->port.uartclk =3D=3D SERIAL_RSA_BAUD_BASE * 16) { - spin_lock_irq(&up->port.lock); + uart_port_lock_irq(&up->port); =20 mode =3D serial_in(up, UART_RSA_MSR); result =3D !(mode & UART_RSA_MSR_FIFO); @@ -781,7 +781,7 @@ static void disable_rsa(struct uart_8250_port *up) =20 if (result) up->port.uartclk =3D SERIAL_RSA_BAUD_BASE_LO * 16; - spin_unlock_irq(&up->port.lock); + uart_port_unlock_irq(&up->port); } } #endif /* CONFIG_SERIAL_8250_RSA */ @@ -1172,7 +1172,7 @@ static void autoconfig(struct uart_8250_port *up) * * Synchronize UART_IER access against the console. */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 up->capabilities =3D 0; up->bugs =3D 0; @@ -1211,7 +1211,7 @@ static void autoconfig(struct uart_8250_port *up) /* * We failed; there's nothing here */ - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); DEBUG_AUTOCONF("IER test failed (%02x, %02x) ", scratch2, scratch3); goto out; @@ -1235,7 +1235,7 @@ static void autoconfig(struct uart_8250_port *up) status1 =3D serial_in(up, UART_MSR) & UART_MSR_STATUS_BITS; serial8250_out_MCR(up, save_mcr); if (status1 !=3D (UART_MSR_DCD | UART_MSR_CTS)) { - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); DEBUG_AUTOCONF("LOOP test failed (%02x) ", status1); goto out; @@ -1304,7 +1304,7 @@ static void autoconfig(struct uart_8250_port *up) serial8250_clear_IER(up); =20 out_unlock: - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 /* * Check if the device is a Fintek F81216A @@ -1344,9 +1344,9 @@ static void autoconfig_irq(struct uart_8250_port *up) probe_irq_off(probe_irq_on()); save_mcr =3D serial8250_in_MCR(up); /* Synchronize UART_IER access against the console. */ - spin_lock_irq(&port->lock); + uart_port_lock_irq(port); save_ier =3D serial_in(up, UART_IER); - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); serial8250_out_MCR(up, UART_MCR_OUT1 | UART_MCR_OUT2); =20 irqs =3D probe_irq_on(); @@ -1359,9 +1359,9 @@ static void autoconfig_irq(struct uart_8250_port *up) UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2); } /* Synchronize UART_IER access against the console. */ - spin_lock_irq(&port->lock); + uart_port_lock_irq(port); serial_out(up, UART_IER, UART_IER_ALL_INTR); - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); serial_in(up, UART_LSR); serial_in(up, UART_RX); serial_in(up, UART_IIR); @@ -1372,9 +1372,9 @@ static void autoconfig_irq(struct uart_8250_port *up) =20 serial8250_out_MCR(up, save_mcr); /* Synchronize UART_IER access against the console. */ - spin_lock_irq(&port->lock); + uart_port_lock_irq(port); serial_out(up, UART_IER, save_ier); - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); =20 if (port->flags & UPF_FOURPORT) outb_p(save_ICP, ICP); @@ -1442,13 +1442,13 @@ static enum hrtimer_restart serial8250_em485_handle= _stop_tx(struct hrtimer *t) unsigned long flags; =20 serial8250_rpm_get(p); - spin_lock_irqsave(&p->port.lock, flags); + uart_port_lock_irqsave(&p->port, &flags); if (em485->active_timer =3D=3D &em485->stop_tx_timer) { p->rs485_stop_tx(p); em485->active_timer =3D NULL; em485->tx_stopped =3D true; } - spin_unlock_irqrestore(&p->port.lock, flags); + uart_port_unlock_irqrestore(&p->port, flags); serial8250_rpm_put(p); =20 return HRTIMER_NORESTART; @@ -1630,12 +1630,12 @@ static enum hrtimer_restart serial8250_em485_handle= _start_tx(struct hrtimer *t) struct uart_8250_port *p =3D em485->port; unsigned long flags; =20 - spin_lock_irqsave(&p->port.lock, flags); + uart_port_lock_irqsave(&p->port, &flags); if (em485->active_timer =3D=3D &em485->start_tx_timer) { __start_tx(&p->port); em485->active_timer =3D NULL; } - spin_unlock_irqrestore(&p->port.lock, flags); + uart_port_unlock_irqrestore(&p->port, flags); =20 return HRTIMER_NORESTART; } @@ -1918,7 +1918,7 @@ int serial8250_handle_irq(struct uart_port *port, uns= igned int iir) if (iir & UART_IIR_NO_INT) return 0; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 status =3D serial_lsr_in(up); =20 @@ -1985,9 +1985,9 @@ static int serial8250_tx_threshold_handle_irq(struct = uart_port *port) if ((iir & UART_IIR_ID) =3D=3D UART_IIR_THRI) { struct uart_8250_port *up =3D up_to_u8250p(port); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); serial8250_tx_chars(up); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 iir =3D serial_port_in(port, UART_IIR); @@ -2002,10 +2002,10 @@ static unsigned int serial8250_tx_empty(struct uart= _port *port) =20 serial8250_rpm_get(up); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); if (!serial8250_tx_dma_running(up) && uart_lsr_tx_empty(serial_lsr_in(up)= )) result =3D TIOCSER_TEMT; - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 serial8250_rpm_put(up); =20 @@ -2067,13 +2067,13 @@ static void serial8250_break_ctl(struct uart_port *= port, int break_state) unsigned long flags; =20 serial8250_rpm_get(up); - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); if (break_state =3D=3D -1) up->lcr |=3D UART_LCR_SBC; else up->lcr &=3D ~UART_LCR_SBC; serial_port_out(port, UART_LCR, up->lcr); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); serial8250_rpm_put(up); } =20 @@ -2208,7 +2208,7 @@ int serial8250_do_startup(struct uart_port *port) * * Synchronize UART_IER access against the console. */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); up->acr =3D 0; serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B); serial_port_out(port, UART_EFR, UART_EFR_ECB); @@ -2218,7 +2218,7 @@ int serial8250_do_startup(struct uart_port *port) serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B); serial_port_out(port, UART_EFR, UART_EFR_ECB); serial_port_out(port, UART_LCR, 0); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 if (port->type =3D=3D PORT_DA830) { @@ -2227,10 +2227,10 @@ int serial8250_do_startup(struct uart_port *port) * * Synchronize UART_IER access against the console. */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); serial_port_out(port, UART_IER, 0); serial_port_out(port, UART_DA830_PWREMU_MGMT, 0); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); mdelay(10); =20 /* Enable Tx, Rx and free run mode */ @@ -2344,7 +2344,7 @@ int serial8250_do_startup(struct uart_port *port) * * Synchronize UART_IER access against the console. */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 wait_for_xmitr(up, UART_LSR_THRE); serial_port_out_sync(port, UART_IER, UART_IER_THRI); @@ -2356,7 +2356,7 @@ int serial8250_do_startup(struct uart_port *port) iir =3D serial_port_in(port, UART_IIR); serial_port_out(port, UART_IER, 0); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 if (port->irqflags & IRQF_SHARED) enable_irq(port->irq); @@ -2379,7 +2379,7 @@ int serial8250_do_startup(struct uart_port *port) */ serial_port_out(port, UART_LCR, UART_LCR_WLEN8); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); if (up->port.flags & UPF_FOURPORT) { if (!up->port.irq) up->port.mctrl |=3D TIOCM_OUT1; @@ -2425,7 +2425,7 @@ int serial8250_do_startup(struct uart_port *port) } =20 dont_test_tx_en: - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 /* * Clear the interrupt registers again for luck, and clear the @@ -2496,17 +2496,17 @@ void serial8250_do_shutdown(struct uart_port *port) * * Synchronize UART_IER access against the console. */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); up->ier =3D 0; serial_port_out(port, UART_IER, 0); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 synchronize_irq(port->irq); =20 if (up->dma) serial8250_release_dma(up); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); if (port->flags & UPF_FOURPORT) { /* reset interrupts on the AST Fourport board */ inb((port->iobase & 0xfe0) | 0x1f); @@ -2515,7 +2515,7 @@ void serial8250_do_shutdown(struct uart_port *port) port->mctrl &=3D ~TIOCM_OUT2; =20 serial8250_set_mctrl(port, port->mctrl); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 /* * Disable break condition and FIFOs @@ -2751,14 +2751,14 @@ void serial8250_update_uartclk(struct uart_port *po= rt, unsigned int uartclk) quot =3D serial8250_get_divisor(port, baud, &frac); =20 serial8250_rpm_get(up); - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 uart_update_timeout(port, termios->c_cflag, baud); =20 serial8250_set_divisor(port, baud, quot, frac); serial_port_out(port, UART_LCR, up->lcr); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); serial8250_rpm_put(up); =20 out_unlock: @@ -2795,7 +2795,7 @@ serial8250_do_set_termios(struct uart_port *port, str= uct ktermios *termios, * Synchronize UART_IER access against the console. */ serial8250_rpm_get(up); - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 up->lcr =3D cval; /* Save computed LCR */ =20 @@ -2898,7 +2898,7 @@ serial8250_do_set_termios(struct uart_port *port, str= uct ktermios *termios, serial_port_out(port, UART_FCR, up->fcr); /* set fcr */ } serial8250_set_mctrl(port, port->mctrl); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); serial8250_rpm_put(up); =20 /* Don't rewrite B0 */ @@ -2921,15 +2921,15 @@ void serial8250_do_set_ldisc(struct uart_port *port= , struct ktermios *termios) { if (termios->c_line =3D=3D N_PPS) { port->flags |=3D UPF_HARDPPS_CD; - spin_lock_irq(&port->lock); + uart_port_lock_irq(port); serial8250_enable_ms(port); - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); } else { port->flags &=3D ~UPF_HARDPPS_CD; if (!UART_ENABLE_MS(port, termios->c_cflag)) { - spin_lock_irq(&port->lock); + uart_port_lock_irq(port); serial8250_disable_ms(port); - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); } } } @@ -3403,9 +3403,9 @@ void serial8250_console_write(struct uart_8250_port *= up, const char *s, touch_nmi_watchdog(); =20 if (oops_in_progress) - locked =3D spin_trylock_irqsave(&port->lock, flags); + locked =3D uart_port_trylock_irqsave(port, &flags); else - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* * First save the IER then disable the interrupts @@ -3475,7 +3475,7 @@ void serial8250_console_write(struct uart_8250_port *= up, const char *s, serial8250_modem_status(up); =20 if (locked) - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static unsigned int probe_baud(struct uart_port *port) --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85445EEAA63 for ; Thu, 14 Sep 2023 18:39:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241790AbjINSjS (ORCPT ); Thu, 14 Sep 2023 14:39:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241400AbjINSis (ORCPT ); Thu, 14 Sep 2023 14:38:48 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97BB21FF9; Thu, 14 Sep 2023 11:38:43 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716721; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CzZ2M7Ay+uoSpWDNXt2IF108PlOFaDB0Gl5ZSfxIoKA=; b=MN04YVr9XpiH+REY6l7sFIUGI/otQWeRx+CKe/J4+jMfCS0h0U6aIm01i3LOSc/jBKZ4lL XTInMSjAR/ywP2wrgbrAtW4+AKEkb/ExW/V2qne+n4kXbGFT1vswV4l3nARA/jtnvknOxh jiaUIX8aUYihEu7/LSXCaQcmM6LcClRkIv6ACbTowKQvmPN6ErddahwcH7LNL9ibjbD3gC 2MamTfJD3//3CTP1OMZtoXs5K/TWjqPaxcxAgxnf37Lgae3nJP3KXUPCSpx/q4BeLm11JQ l53K51Y5jNK1jpi/XFuhvi2+qzo/Sd/erXOzxvJplGgq4Qg4g9KImV9kXWNcqA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716721; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CzZ2M7Ay+uoSpWDNXt2IF108PlOFaDB0Gl5ZSfxIoKA=; b=7AP6OHdmQkAf45CIbcjDpOnJQIa7Mil7nBAtO0WArIZaqyFG/TyjfxMEofUIZB8/cnTr7G Cv7UMdHf9PI0DHCQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Andy Shevchenko Subject: [PATCH tty v1 07/74] serial: 8250_dma: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:24 +0206 Message-Id: <20230914183831.587273-8-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner Reviewed-by: Ilpo J=C3=A4rvinen --- drivers/tty/serial/8250/8250_dma.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/8250/8250_dma.c b/drivers/tty/serial/8250/8= 250_dma.c index 7fa66501792d..8b30ca8fdd3f 100644 --- a/drivers/tty/serial/8250/8250_dma.c +++ b/drivers/tty/serial/8250/8250_dma.c @@ -22,7 +22,7 @@ static void __dma_tx_complete(void *param) dma_sync_single_for_cpu(dma->txchan->device->dev, dma->tx_addr, UART_XMIT_SIZE, DMA_TO_DEVICE); =20 - spin_lock_irqsave(&p->port.lock, flags); + uart_port_lock_irqsave(&p->port, &flags); =20 dma->tx_running =3D 0; =20 @@ -35,7 +35,7 @@ static void __dma_tx_complete(void *param) if (ret || !dma->tx_running) serial8250_set_THRI(p); =20 - spin_unlock_irqrestore(&p->port.lock, flags); + uart_port_unlock_irqrestore(&p->port, flags); } =20 static void __dma_rx_complete(struct uart_8250_port *p) @@ -70,7 +70,7 @@ static void dma_rx_complete(void *param) struct uart_8250_dma *dma =3D p->dma; unsigned long flags; =20 - spin_lock_irqsave(&p->port.lock, flags); + uart_port_lock_irqsave(&p->port, &flags); if (dma->rx_running) __dma_rx_complete(p); =20 @@ -80,7 +80,7 @@ static void dma_rx_complete(void *param) */ if (!dma->rx_running && (serial_lsr_in(p) & UART_LSR_DR)) p->dma->rx_dma(p); - spin_unlock_irqrestore(&p->port.lock, flags); + uart_port_unlock_irqrestore(&p->port, flags); } =20 int serial8250_tx_dma(struct uart_8250_port *p) --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07AA7EEAA63 for ; Thu, 14 Sep 2023 18:39:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241863AbjINSjW (ORCPT ); Thu, 14 Sep 2023 14:39:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241416AbjINSis (ORCPT ); Thu, 14 Sep 2023 14:38:48 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99DC31FFB; Thu, 14 Sep 2023 11:38:43 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716722; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PXwtr2mW476CJCdf6sAfvEGFu2EeqfcOEBZTv7wDsVo=; b=c1gwWfZ3idwytcqe6fJhqyNiv3t6Pusd87FKIhNv0oWPhu+BmM/2E4anqWcY0na/ZUldT6 sNYbV/ZvM0mwNMtNCrB9B3dtS9jAB/5kD7pjTBcHsERisrEwuP05sjUSWF7jdDzztnH2YH 0ys8kB0nJxtqKp4R0XcMqieoKVpdlckgN+Qs/wk3NNJqdQYEJ2ZHvviXMwDJoiUOmmeqbt 29rEQUEoy1OZolPsESyuxTM99xwdU6EhKu1PmtdrDSbRtnPiHinMkVyA+QwsM/ByRbO0JQ iOSic1s5XDeQ4bW4bGiL3ht2jpP1EzluHoOQZ4X93cbrkcsx7HFi+lL1OJMgQw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716722; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PXwtr2mW476CJCdf6sAfvEGFu2EeqfcOEBZTv7wDsVo=; b=sjTEfi6dtWs2B6G3uIcUDZx1XVnxac0F5QU5fMLyrvnsap7tRuPup04Jh63unPNqP3+aoy wvUJL9BSJmK5UuAg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Andy Shevchenko Subject: [PATCH tty v1 08/74] serial: 8250_dw: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:25 +0206 Message-Id: <20230914183831.587273-9-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner Reviewed-by: Ilpo J=C3=A4rvinen --- drivers/tty/serial/8250/8250_dw.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/82= 50_dw.c index f4cafca1a7da..95d45dce0880 100644 --- a/drivers/tty/serial/8250/8250_dw.c +++ b/drivers/tty/serial/8250/8250_dw.c @@ -263,20 +263,20 @@ static int dw8250_handle_irq(struct uart_port *p) * so we limit the workaround only to non-DMA mode. */ if (!up->dma && rx_timeout) { - spin_lock_irqsave(&p->lock, flags); + uart_port_lock_irqsave(p, &flags); status =3D serial_lsr_in(up); =20 if (!(status & (UART_LSR_DR | UART_LSR_BI))) (void) p->serial_in(p, UART_RX); =20 - spin_unlock_irqrestore(&p->lock, flags); + uart_port_unlock_irqrestore(p, flags); } =20 /* Manually stop the Rx DMA transfer when acting as flow controller */ if (quirks & DW_UART_QUIRK_IS_DMA_FC && up->dma && up->dma->rx_running &&= rx_timeout) { - spin_lock_irqsave(&p->lock, flags); + uart_port_lock_irqsave(p, &flags); status =3D serial_lsr_in(up); - spin_unlock_irqrestore(&p->lock, flags); + uart_port_unlock_irqrestore(p, flags); =20 if (status & (UART_LSR_DR | UART_LSR_BI)) { dw8250_writel_ext(p, RZN1_UART_RDMACR, 0); --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F8D9EEAA64 for ; Thu, 14 Sep 2023 18:38:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241807AbjINSjA (ORCPT ); Thu, 14 Sep 2023 14:39:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241423AbjINSis (ORCPT ); Thu, 14 Sep 2023 14:38:48 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED74C1FFC; Thu, 14 Sep 2023 11:38:43 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716722; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VwAuYpYc3fWXqol8AKchJjd2gF2BZfWOXYVLA/beRQc=; b=vSKwIdxZS0Wy8y0+/xBxwuLThTEsw4FHoB6EHTIG1aUZ/vnNzHzcVNEuoBNexfguoPfsUG AuuyuU3K3dRpSywuVrx6WMcLVtPGSQeGW9r86rAxNTjYZ9IVPS27lt77osMrXyqSC1bvRm o4Ea6eBOgx0An5Xfej5rhguuAlR6FU3QURdKKa3w/qSU1NgHZ4hpp5ouzAH1P2Fjy8qS2v GvlBKyD32A4oDfzVMtEbAeSmNv6nrMJn/xfUL/8+6B9N6cUdThGb44P9DyJL96z3lvV1jh zOgajJ2htEmcYmbcCqvWAYjS13lgL7oWQG0+gr/0zGI25LwYeN0J4QzjWCjO8A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716722; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VwAuYpYc3fWXqol8AKchJjd2gF2BZfWOXYVLA/beRQc=; b=i5GRywZjHj1wrVT3sjOj3uMBjzzxZVwAf9xbXgkUxQ5dZtMNghRLuxeKwuRpV4hrBVCmwr meSdgbwTEVR38SAQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Andrew Davis , Andy Shevchenko , Matthew Howell Subject: [PATCH tty v1 09/74] serial: 8250_exar: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:26 +0206 Message-Id: <20230914183831.587273-10-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/8250/8250_exar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/8250/8250_exar.c b/drivers/tty/serial/8250/= 8250_exar.c index 077c3ba3539e..07ad21336301 100644 --- a/drivers/tty/serial/8250/8250_exar.c +++ b/drivers/tty/serial/8250/8250_exar.c @@ -201,9 +201,9 @@ static int xr17v35x_startup(struct uart_port *port) * * Synchronize UART_IER access against the console. */ - spin_lock_irq(&port->lock); + uart_port_lock_irq(port); serial_port_out(port, UART_IER, 0); - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); =20 return serial8250_do_startup(port); } --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD106EEAA5D for ; Thu, 14 Sep 2023 18:39:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241779AbjINSjI (ORCPT ); Thu, 14 Sep 2023 14:39:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241566AbjINSiw (ORCPT ); Thu, 14 Sep 2023 14:38:52 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D9591FFD; Thu, 14 Sep 2023 11:38:44 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716723; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wXz8JGMJt54lxBpqvVsLQWaGP0tVfnWkCc3ahu/OaTk=; b=vmCnTqOsrLD4owKMnmfvtt1mBVdB6YqBmGZYVNCuNttix45bbD9ZYBKfLxWRoBxQcBrNFS ULCYyVAqLXI4WuA9/BsruLgLGbEQI0qOqenpk/mUGPr+fPvVS+xGWUKS7kYFDYc0WhUm27 aVTjiT5owCNSXMMUD6DKhb7HMUIh7wEVB3Z5nSl559BN3e+O7kuLsiSfuog8zZMXDWHAjs 5zUaC5XtIkdT+69XNmr/KvqG8mTwRsZEuLyoS0zyLneujo8Xe6IZvjTY2OaCkQ9Dneu7rx rxPzEpc7LJxm0RT3M6KzjMRuQiQm6AL2MbwkL48z/fbQ2VixAGYrORAhlzhwFw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716723; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wXz8JGMJt54lxBpqvVsLQWaGP0tVfnWkCc3ahu/OaTk=; b=oELZSVWpujrqq3F+QVn6Xal+m55lYszHQlaRnpJvhYUD7X9S9LcC3ptf/FaXfToMUvP96p 2Q76arcWnsSNdHAg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Johan Hovold , Andy Shevchenko Subject: [PATCH tty v1 10/74] serial: 8250_fsl: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:27 +0206 Message-Id: <20230914183831.587273-11-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/8250/8250_fsl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/8250/8250_fsl.c b/drivers/tty/serial/8250/8= 250_fsl.c index 6af4e1c1210a..f522eb5026c9 100644 --- a/drivers/tty/serial/8250/8250_fsl.c +++ b/drivers/tty/serial/8250/8250_fsl.c @@ -30,11 +30,11 @@ int fsl8250_handle_irq(struct uart_port *port) unsigned int iir; struct uart_8250_port *up =3D up_to_u8250p(port); =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 iir =3D port->serial_in(port, UART_IIR); if (iir & UART_IIR_NO_INT) { - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); return 0; } =20 @@ -54,7 +54,7 @@ int fsl8250_handle_irq(struct uart_port *port) if (unlikely(up->lsr_saved_flags & UART_LSR_BI)) { up->lsr_saved_flags &=3D ~UART_LSR_BI; port->serial_in(port, UART_RX); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); return 1; } =20 --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 083D5EEAA62 for ; Thu, 14 Sep 2023 18:39:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241696AbjINSjP (ORCPT ); Thu, 14 Sep 2023 14:39:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241568AbjINSiw (ORCPT ); Thu, 14 Sep 2023 14:38:52 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C52C91FFE; Thu, 14 Sep 2023 11:38:44 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716723; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0zxTlKID9c7YEvuORrPXl2fVFncXh/KVCV6b0hRF+M0=; b=wpI9YdYscyP7QCk0acGuia//P2qYFkbm3gJQZYYqS49wM9ejXs+pjzQLph+Uzx69MOiUXl Dzd44jCbMLmFITkggEvIkAm9kK8h3TJ3NQYg+psnX8uBb8BKhZfFkfyBh2Wdw2kgXvorv9 eN+z9CFui2CBPIgGQZOQQF36x8utOP0y0fQJb3RGGFp+NBRyRz1c5xTbr38vbYxcOwYfRv QvucfHJ04RIkd0cer+j9B5cOhisDGPDz1KoBqFmjWrEcCcdOuAoLnYILixUcoY6Ny0O5C1 STlb6yGp3sbH9XbXZlR/i1R5QsvZxuS4ujVvU8GkDtrto5lcoxGddR9baDlKIQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716723; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0zxTlKID9c7YEvuORrPXl2fVFncXh/KVCV6b0hRF+M0=; b=3/nKE7xyHHA/3Sq2eQiSXccT5Z8HqEfiZ5GXPISOZOKMiLIeYRqscjaIjC5bCGvNvAVBW5 tSThvy+KQFyPJZCA== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Matthias Brugger , AngeloGioacchino Del Regno , Chen-Yu Tsai , Tony Lindgren , linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH tty v1 11/74] serial: 8250_mtk: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:28 +0206 Message-Id: <20230914183831.587273-12-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner Reviewed-by: Chen-Yu Tsai --- drivers/tty/serial/8250/8250_mtk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/8250/8250_mtk.c b/drivers/tty/serial/8250/8= 250_mtk.c index 74da5676ce67..23457daae8a1 100644 --- a/drivers/tty/serial/8250/8250_mtk.c +++ b/drivers/tty/serial/8250/8250_mtk.c @@ -102,7 +102,7 @@ static void mtk8250_dma_rx_complete(void *param) if (data->rx_status =3D=3D DMA_RX_SHUTDOWN) return; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state); total =3D dma->rx_size - state.residue; @@ -128,7 +128,7 @@ static void mtk8250_dma_rx_complete(void *param) =20 mtk8250_rx_dma(up); =20 - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 static void mtk8250_rx_dma(struct uart_8250_port *up) @@ -368,7 +368,7 @@ mtk8250_set_termios(struct uart_port *port, struct kter= mios *termios, * Ok, we're now changing the port state. Do it with * interrupts disabled. */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* * Update the per-port timeout. @@ -416,7 +416,7 @@ mtk8250_set_termios(struct uart_port *port, struct kter= mios *termios, if (uart_console(port)) up->port.cons->cflag =3D termios->c_cflag; =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); /* Don't rewrite B0 */ if (tty_termios_baud_rate(termios)) tty_termios_encode_baud_rate(termios, baud, baud); --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7CEEEEAA6B for ; Thu, 14 Sep 2023 18:39:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241857AbjINSjG (ORCPT ); Thu, 14 Sep 2023 14:39:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241583AbjINSix (ORCPT ); Thu, 14 Sep 2023 14:38:53 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 355011FFF; Thu, 14 Sep 2023 11:38:45 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716723; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hAr+aerifH023DidMwRy+ZYEUlrEnoz+OKihpPaW8nY=; b=ZBWN6bAoEsMIvv5W/jJ4EDfSl1dAC/OB5iblurdwDq8y0V7TbVWjf2XA/c934aAhcqz7bX byZ8vNKtfniaAThga7tGBMzSrYDGGxOGBuFoWsEsm218ceQFjCnQlOg9F5FilAX/+nj4Gk CEPinnAsgI3jlIaNd6DqHAROHBxgMbSGy61tdtrcgGThrUN4Bcvwc2I0/qgghDnUkBdBsb pjAJ84TurSEF2Oa6YZKazyE1OFY+s4LDvJxNBJQT+/IQ28IDBHdznoZ0gvqeaXTK99iy79 y/U/R2d49md0291fX9gxXYTKFP+5gHzfokS3EyeEfD7K2mEJ7A0mD+0VRtD5Ig== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716723; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hAr+aerifH023DidMwRy+ZYEUlrEnoz+OKihpPaW8nY=; b=vZunDEtB8skEixyIq4H1PIQQ1sq3NsaEoWeGUy3NEJjvv7DKOIq0BFIRwXGuDj/yi5iiPY I/fydBcCbGkj14Ag== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Tony Lindgren , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Lukas Wunner , Matthias Schiffer , Arnd Bergmann Subject: [PATCH tty v1 12/74] serial: 8250_omap: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:29 +0206 Message-Id: <20230914183831.587273-13-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/8250/8250_omap.c | 52 ++++++++++++++--------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/= 8250_omap.c index 26dd089d8e82..9ea38e2a6e23 100644 --- a/drivers/tty/serial/8250/8250_omap.c +++ b/drivers/tty/serial/8250/8250_omap.c @@ -401,7 +401,7 @@ static void omap_8250_set_termios(struct uart_port *por= t, * interrupts disabled. */ pm_runtime_get_sync(port->dev); - spin_lock_irq(&port->lock); + uart_port_lock_irq(port); =20 /* * Update the per-port timeout. @@ -504,7 +504,7 @@ static void omap_8250_set_termios(struct uart_port *por= t, } omap8250_restore_regs(up); =20 - spin_unlock_irq(&up->port.lock); + uart_port_unlock_irq(&up->port); pm_runtime_mark_last_busy(port->dev); pm_runtime_put_autosuspend(port->dev); =20 @@ -529,7 +529,7 @@ static void omap_8250_pm(struct uart_port *port, unsign= ed int state, pm_runtime_get_sync(port->dev); =20 /* Synchronize UART_IER access against the console. */ - spin_lock_irq(&port->lock); + uart_port_lock_irq(port); =20 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); efr =3D serial_in(up, UART_EFR); @@ -541,7 +541,7 @@ static void omap_8250_pm(struct uart_port *port, unsign= ed int state, serial_out(up, UART_EFR, efr); serial_out(up, UART_LCR, 0); =20 - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); =20 pm_runtime_mark_last_busy(port->dev); pm_runtime_put_autosuspend(port->dev); @@ -660,7 +660,7 @@ static irqreturn_t omap8250_irq(int irq, void *dev_id) unsigned long delay; =20 /* Synchronize UART_IER access against the console. */ - spin_lock(&port->lock); + uart_port_lock(port); up->ier =3D port->serial_in(port, UART_IER); if (up->ier & (UART_IER_RLSI | UART_IER_RDI)) { port->ops->stop_rx(port); @@ -670,7 +670,7 @@ static irqreturn_t omap8250_irq(int irq, void *dev_id) */ cancel_delayed_work(&up->overrun_backoff); } - spin_unlock(&port->lock); + uart_port_unlock(port); =20 delay =3D msecs_to_jiffies(up->overrun_backoff_time_ms); schedule_delayed_work(&up->overrun_backoff, delay); @@ -717,10 +717,10 @@ static int omap_8250_startup(struct uart_port *port) } =20 /* Synchronize UART_IER access against the console. */ - spin_lock_irq(&port->lock); + uart_port_lock_irq(port); up->ier =3D UART_IER_RLSI | UART_IER_RDI; serial_out(up, UART_IER, up->ier); - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); =20 #ifdef CONFIG_PM up->capabilities |=3D UART_CAP_RPM; @@ -733,9 +733,9 @@ static int omap_8250_startup(struct uart_port *port) serial_out(up, UART_OMAP_WER, priv->wer); =20 if (up->dma && !(priv->habit & UART_HAS_EFR2)) { - spin_lock_irq(&port->lock); + uart_port_lock_irq(port); up->dma->rx_dma(up); - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); } =20 enable_irq(up->port.irq); @@ -761,10 +761,10 @@ static void omap_8250_shutdown(struct uart_port *port) serial_out(up, UART_OMAP_EFR2, 0x0); =20 /* Synchronize UART_IER access against the console. */ - spin_lock_irq(&port->lock); + uart_port_lock_irq(port); up->ier =3D 0; serial_out(up, UART_IER, 0); - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); disable_irq_nosync(up->port.irq); dev_pm_clear_wake_irq(port->dev); =20 @@ -789,10 +789,10 @@ static void omap_8250_throttle(struct uart_port *port) =20 pm_runtime_get_sync(port->dev); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); port->ops->stop_rx(port); priv->throttled =3D true; - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 pm_runtime_mark_last_busy(port->dev); pm_runtime_put_autosuspend(port->dev); @@ -807,14 +807,14 @@ static void omap_8250_unthrottle(struct uart_port *po= rt) pm_runtime_get_sync(port->dev); =20 /* Synchronize UART_IER access against the console. */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); priv->throttled =3D false; if (up->dma) up->dma->rx_dma(up); up->ier |=3D UART_IER_RLSI | UART_IER_RDI; port->read_status_mask |=3D UART_LSR_DR; serial_out(up, UART_IER, up->ier); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 pm_runtime_mark_last_busy(port->dev); pm_runtime_put_autosuspend(port->dev); @@ -958,7 +958,7 @@ static void __dma_rx_complete(void *param) unsigned long flags; =20 /* Synchronize UART_IER access against the console. */ - spin_lock_irqsave(&p->port.lock, flags); + uart_port_lock_irqsave(&p->port, &flags); =20 /* * If the tx status is not DMA_COMPLETE, then this is a delayed @@ -967,7 +967,7 @@ static void __dma_rx_complete(void *param) */ if (dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state) !=3D DMA_COMPLETE) { - spin_unlock_irqrestore(&p->port.lock, flags); + uart_port_unlock_irqrestore(&p->port, flags); return; } __dma_rx_do_complete(p); @@ -978,7 +978,7 @@ static void __dma_rx_complete(void *param) omap_8250_rx_dma(p); } =20 - spin_unlock_irqrestore(&p->port.lock, flags); + uart_port_unlock_irqrestore(&p->port, flags); } =20 static void omap_8250_rx_dma_flush(struct uart_8250_port *p) @@ -1083,7 +1083,7 @@ static void omap_8250_dma_tx_complete(void *param) dma_sync_single_for_cpu(dma->txchan->device->dev, dma->tx_addr, UART_XMIT_SIZE, DMA_TO_DEVICE); =20 - spin_lock_irqsave(&p->port.lock, flags); + uart_port_lock_irqsave(&p->port, &flags); =20 dma->tx_running =3D 0; =20 @@ -1112,7 +1112,7 @@ static void omap_8250_dma_tx_complete(void *param) serial8250_set_THRI(p); } =20 - spin_unlock_irqrestore(&p->port.lock, flags); + uart_port_unlock_irqrestore(&p->port, flags); } =20 static int omap_8250_tx_dma(struct uart_8250_port *p) @@ -1278,7 +1278,7 @@ static int omap_8250_dma_handle_irq(struct uart_port = *port) return IRQ_HANDLED; } =20 - spin_lock(&port->lock); + uart_port_lock(port); =20 status =3D serial_port_in(port, UART_LSR); =20 @@ -1761,15 +1761,15 @@ static int omap8250_runtime_resume(struct device *d= ev) up =3D serial8250_get_port(priv->line); =20 if (up && omap8250_lost_context(up)) { - spin_lock_irq(&up->port.lock); + uart_port_lock_irq(&up->port); omap8250_restore_regs(up); - spin_unlock_irq(&up->port.lock); + uart_port_unlock_irq(&up->port); } =20 if (up && up->dma && up->dma->rxchan && !(priv->habit & UART_HAS_EFR2)) { - spin_lock_irq(&up->port.lock); + uart_port_lock_irq(&up->port); omap_8250_rx_dma(up); - spin_unlock_irq(&up->port.lock); + uart_port_unlock_irq(&up->port); } =20 priv->latency =3D priv->calc_latency; --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A602EEAA63 for ; Thu, 14 Sep 2023 18:39:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241878AbjINSjM (ORCPT ); Thu, 14 Sep 2023 14:39:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241609AbjINSix (ORCPT ); Thu, 14 Sep 2023 14:38:53 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 871682101; Thu, 14 Sep 2023 11:38:45 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716724; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LC6ee95LLgICXwmE0USSEBuHjBCWJtZsDUgyx/Ctu9I=; b=R1TuVbNostHa0wM4yepEE7v6WHYuLqdxHUqaYn+qB5pl6tCd4QoP0ouCPBj/gYuUjWU2Hl qZSxgx+XXc/VQiIbUuVilNn3nM35W92GRgdyC6GzHPzgXIzngraczIF+lQGD9zNMwJBoVE orO2MdWxWEsso3g+/W+4DPjj1PAxTEk4Ngx2Oi+rIWTZF+orsNP2nKu4Q3yVlYIW1gI/to QdnLyyvD3oIXml7AgZqrVHTRaq5qTQuWRRt2xEKRNBtXo5LM/raiC8Fp2QnzPPv8+4HCmj PiYmbhKFmSLs+5ksgnA4L6VU/drWEG5TNzjchepMiTwFo+4Ae8GZ2/3YVbPhzw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716724; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LC6ee95LLgICXwmE0USSEBuHjBCWJtZsDUgyx/Ctu9I=; b=CZYVJekgCab/O5x5km8To1UaDf+NZCMKRy3KHKXP+YTu0UQJ7PUVdCpMdSS2HphSeJTuVJ /2B0cSEgLlc3bHDA== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Kumaravel Thiagarajan , Tharun Kumar P Subject: [PATCH tty v1 13/74] serial: 8250_pci1xxxx: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:30 +0206 Message-Id: <20230914183831.587273-14-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/8250/8250_pci1xxxx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/8250/8250_pci1xxxx.c b/drivers/tty/serial/8= 250/8250_pci1xxxx.c index a3b25779d921..53e238c8cc89 100644 --- a/drivers/tty/serial/8250/8250_pci1xxxx.c +++ b/drivers/tty/serial/8250/8250_pci1xxxx.c @@ -225,10 +225,10 @@ static bool pci1xxxx_port_suspend(int line) if (port->suspended =3D=3D 0 && port->dev) { wakeup_mask =3D readb(up->port.membase + UART_WAKE_MASK_REG); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); port->mctrl &=3D ~TIOCM_OUT2; port->ops->set_mctrl(port, port->mctrl); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 ret =3D (wakeup_mask & UART_WAKE_SRCS) !=3D UART_WAKE_SRCS; } @@ -251,10 +251,10 @@ static void pci1xxxx_port_resume(int line) writeb(UART_WAKE_SRCS, port->membase + UART_WAKE_REG); =20 if (port->suspended =3D=3D 0) { - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); port->mctrl |=3D TIOCM_OUT2; port->ops->set_mctrl(port, port->mctrl); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } mutex_unlock(&tport->mutex); } --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BEAAEEAA5D for ; Thu, 14 Sep 2023 18:39:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241909AbjINSjY (ORCPT ); Thu, 14 Sep 2023 14:39:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241612AbjINSix (ORCPT ); Thu, 14 Sep 2023 14:38:53 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E76262103; Thu, 14 Sep 2023 11:38:45 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716724; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VtioS1TmKY7HP/T4E5ia6bLpeGsG2aqw7oKrLcODTps=; b=KzR11aI9gMRB+jNxh73zf08f5zfu/h94i8WcA/3/y5qkyCNVrXvChwPbdJM9x207DuYSdm 5TnoMRJFSM0tSm8kxtFH60dMK6ATrKgzPAOqhAs/T5VKADPi7G0F8X0rcZWIPSN7uXsNMf xSeERMiAJPhFGYUXTISrHOmpAwvkN4GxihRhtbV/aBe2bqoUhBydbMagg2zV6sBnhZsm8o 9VQ3VavmlDH64IhR4lxTvzRanxQk1621jItnGZdIz7FBiyYLIrfZMG5X73rfXfrAZyaA4O 0tNytbsl8jFu9CQaJmYt4hcEHUm3VIWtDCl7OqYda7AOsn2bA/cDl9csUv19dA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716724; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VtioS1TmKY7HP/T4E5ia6bLpeGsG2aqw7oKrLcODTps=; b=r8qMy4Di9mr9YJgshOb2oXJhJVt0iIfP10UKioSN1o0mLawjFrtLrNOaRqGeDH1l6nHA1q UsuEvV98gwDm4PAQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Tobias Klauser Subject: [PATCH tty v1 14/74] serial: altera_jtaguart: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:31 +0206 Message-Id: <20230914183831.587273-15-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/altera_jtaguart.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/tty/serial/altera_jtaguart.c b/drivers/tty/serial/alte= ra_jtaguart.c index 5fab4c978891..7090b251dd4d 100644 --- a/drivers/tty/serial/altera_jtaguart.c +++ b/drivers/tty/serial/altera_jtaguart.c @@ -147,14 +147,14 @@ static irqreturn_t altera_jtaguart_interrupt(int irq,= void *data) isr =3D (readl(port->membase + ALTERA_JTAGUART_CONTROL_REG) >> ALTERA_JTAGUART_CONTROL_RI_OFF) & port->read_status_mask; =20 - spin_lock(&port->lock); + uart_port_lock(port); =20 if (isr & ALTERA_JTAGUART_CONTROL_RE_MSK) altera_jtaguart_rx_chars(port); if (isr & ALTERA_JTAGUART_CONTROL_WE_MSK) altera_jtaguart_tx_chars(port); =20 - spin_unlock(&port->lock); + uart_port_unlock(port); =20 return IRQ_RETVAL(isr); } @@ -180,14 +180,14 @@ static int altera_jtaguart_startup(struct uart_port *= port) return ret; } =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Enable RX interrupts now */ port->read_status_mask =3D ALTERA_JTAGUART_CONTROL_RE_MSK; writel(port->read_status_mask, port->membase + ALTERA_JTAGUART_CONTROL_REG); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return 0; } @@ -196,14 +196,14 @@ static void altera_jtaguart_shutdown(struct uart_port= *port) { unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Disable all interrupts now */ port->read_status_mask =3D 0; writel(port->read_status_mask, port->membase + ALTERA_JTAGUART_CONTROL_REG); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 free_irq(port->irq, port); } @@ -264,33 +264,33 @@ static void altera_jtaguart_console_putc(struct uart_= port *port, unsigned char c unsigned long flags; u32 status; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); while (!altera_jtaguart_tx_space(port, &status)) { - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 if ((status & ALTERA_JTAGUART_CONTROL_AC_MSK) =3D=3D 0) { return; /* no connection activity */ } =20 cpu_relax(); - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); } writel(c, port->membase + ALTERA_JTAGUART_DATA_REG); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } #else static void altera_jtaguart_console_putc(struct uart_port *port, unsigned = char c) { unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); while (!altera_jtaguart_tx_space(port, NULL)) { - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); cpu_relax(); - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); } writel(c, port->membase + ALTERA_JTAGUART_DATA_REG); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } #endif =20 --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7AE3EEAA62 for ; Thu, 14 Sep 2023 18:39:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241899AbjINSj3 (ORCPT ); Thu, 14 Sep 2023 14:39:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241638AbjINSix (ORCPT ); Thu, 14 Sep 2023 14:38:53 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40EC52106; Thu, 14 Sep 2023 11:38:46 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716724; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EEsVj/D77ms6nq6XAzujZvjYPk4w6pPMN5gfYUu1uwE=; b=LA7fdwe+El9NWhgb0luA7qJcYedEH/jJ1J2ruvAn2QzhkX4ENhknKvcPfr6zsEzFKubTgS iV5QrvnCSUdmtnD1W3B1XpkzrL/5Ux7xf8qCJoQg9MGxwOwPwY73PV0oU1Ns5etfhEM7dN 22kvwKonDlSZiYUYffSMW2qcBg7eIs7r2Gbbvk4iyFNlfV+FqWI7eVvy4Tvlvq9EBEpuRl wAeVw2ocXlPOx5PkyCFcOKKZNe392UAjcjG8H0phFiTuw6JgoETyzNdCEi1EslSBrjjAX5 qW1lxJLPjZIhtUzmOG4rxi75fV/2TPwIIL2tlZ+fKhkF2P29vQY/7DKenK7/TQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716724; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EEsVj/D77ms6nq6XAzujZvjYPk4w6pPMN5gfYUu1uwE=; b=YwwhM9vN6g8+vsx/509OyoWLuq7JDeBCPnJ3cH+n7xiLAvO6j//gLDZ3bji5emR8fH05j1 UY8ZKgukj15DJdBQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Tobias Klauser Subject: [PATCH tty v1 15/74] serial: altera_uart: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:32 +0206 Message-Id: <20230914183831.587273-16-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/altera_uart.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/altera_uart.c b/drivers/tty/serial/altera_u= art.c index a9c41942190c..77835ac68df2 100644 --- a/drivers/tty/serial/altera_uart.c +++ b/drivers/tty/serial/altera_uart.c @@ -164,13 +164,13 @@ static void altera_uart_break_ctl(struct uart_port *p= ort, int break_state) struct altera_uart *pp =3D container_of(port, struct altera_uart, port); unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); if (break_state =3D=3D -1) pp->imr |=3D ALTERA_UART_CONTROL_TRBK_MSK; else pp->imr &=3D ~ALTERA_UART_CONTROL_TRBK_MSK; altera_uart_update_ctrl_reg(pp); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void altera_uart_set_termios(struct uart_port *port, @@ -187,10 +187,10 @@ static void altera_uart_set_termios(struct uart_port = *port, tty_termios_copy_hw(termios, old); tty_termios_encode_baud_rate(termios, baud, baud); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); uart_update_timeout(port, termios->c_cflag, baud); altera_uart_writel(port, baudclk, ALTERA_UART_DIVISOR_REG); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 /* * FIXME: port->read_status_mask and port->ignore_status_mask @@ -264,12 +264,12 @@ static irqreturn_t altera_uart_interrupt(int irq, voi= d *data) =20 isr =3D altera_uart_readl(port, ALTERA_UART_STATUS_REG) & pp->imr; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); if (isr & ALTERA_UART_STATUS_RRDY_MSK) altera_uart_rx_chars(port); if (isr & ALTERA_UART_STATUS_TRDY_MSK) altera_uart_tx_chars(port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return IRQ_RETVAL(isr); } @@ -313,13 +313,13 @@ static int altera_uart_startup(struct uart_port *port) } } =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Enable RX interrupts now */ pp->imr =3D ALTERA_UART_CONTROL_RRDY_MSK; altera_uart_update_ctrl_reg(pp); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return 0; } @@ -329,13 +329,13 @@ static void altera_uart_shutdown(struct uart_port *po= rt) struct altera_uart *pp =3D container_of(port, struct altera_uart, port); unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Disable all interrupts now */ pp->imr =3D 0; altera_uart_update_ctrl_reg(pp); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 if (port->irq) free_irq(port->irq, port); --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC7DFEEAA5D for ; Thu, 14 Sep 2023 18:39:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241912AbjINSj0 (ORCPT ); Thu, 14 Sep 2023 14:39:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241641AbjINSix (ORCPT ); Thu, 14 Sep 2023 14:38:53 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABDB42108; Thu, 14 Sep 2023 11:38:46 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716725; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C/K94+x3VFE0qetYCzTIZYxK3St4nQt/7CBPmZkbDy0=; b=uXRvCbL7vfpBV5pZH3vtwjfrVzht6pNDjcB+IJ3mBgRurMU50xvCNJEblOFTzf5irLDRjL pK76Su5YXYdA96s7uTDL+TFhhIFShdvVvONxSYP8omoCujJKqeMxXR1eyZRSFbobsWrIUy PuruvXaJ+DSg6ucY45X9NISbI6TdO8NKvT7EaEN0vq/wjQpTOyIpE1dcb3b8Labtt7mgRP Z2gy2rBsZLF+77grTxPukz/I4i9bhDYeGjM164jFavZhuLVZBbvs1yKX5To7smV47VRwCg +pjT5c+alUEEPBMvhp2oaxk0qX/zXSVkiWZCDQktM/QzpgMdFU6AHyBmufwnTQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716725; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C/K94+x3VFE0qetYCzTIZYxK3St4nQt/7CBPmZkbDy0=; b=0eCUUL3vP8dQK2rfMC19TJ15tM6G1CJryy1OXDnP7smmbsbckCADcGIX4LYSmlXekjyfbx 1PiS2o1fQDOXmFCg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Russell King , Tobias Klauser , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , "Maciej W. Rozycki" Subject: [PATCH tty v1 16/74] serial: amba-pl010: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:33 +0206 Message-Id: <20230914183831.587273-17-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/amba-pl010.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/amba-pl010.c b/drivers/tty/serial/amba-pl01= 0.c index b5a7404cbacb..eabbf8afc9b5 100644 --- a/drivers/tty/serial/amba-pl010.c +++ b/drivers/tty/serial/amba-pl010.c @@ -207,7 +207,7 @@ static irqreturn_t pl010_int(int irq, void *dev_id) unsigned int status, pass_counter =3D AMBA_ISR_PASS_LIMIT; int handled =3D 0; =20 - spin_lock(&port->lock); + uart_port_lock(port); =20 status =3D readb(port->membase + UART010_IIR); if (status) { @@ -228,7 +228,7 @@ static irqreturn_t pl010_int(int irq, void *dev_id) handled =3D 1; } =20 - spin_unlock(&port->lock); + uart_port_unlock(port); =20 return IRQ_RETVAL(handled); } @@ -270,14 +270,14 @@ static void pl010_break_ctl(struct uart_port *port, i= nt break_state) unsigned long flags; unsigned int lcr_h; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); lcr_h =3D readb(port->membase + UART010_LCRH); if (break_state =3D=3D -1) lcr_h |=3D UART01x_LCRH_BRK; else lcr_h &=3D ~UART01x_LCRH_BRK; writel(lcr_h, port->membase + UART010_LCRH); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static int pl010_startup(struct uart_port *port) @@ -385,7 +385,7 @@ pl010_set_termios(struct uart_port *port, struct ktermi= os *termios, if (port->fifosize > 1) lcr_h |=3D UART01x_LCRH_FEN; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* * Update the per-port timeout. @@ -438,22 +438,22 @@ pl010_set_termios(struct uart_port *port, struct kter= mios *termios, writel(lcr_h, port->membase + UART010_LCRH); writel(old_cr, port->membase + UART010_CR); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void pl010_set_ldisc(struct uart_port *port, struct ktermios *termi= os) { if (termios->c_line =3D=3D N_PPS) { port->flags |=3D UPF_HARDPPS_CD; - spin_lock_irq(&port->lock); + uart_port_lock_irq(port); pl010_enable_ms(port); - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); } else { port->flags &=3D ~UPF_HARDPPS_CD; if (!UART_ENABLE_MS(port, termios->c_cflag)) { - spin_lock_irq(&port->lock); + uart_port_lock_irq(port); pl010_disable_ms(port); - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); } } } --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44F53EEAA65 for ; Thu, 14 Sep 2023 18:39:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241936AbjINSjc (ORCPT ); Thu, 14 Sep 2023 14:39:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241654AbjINSix (ORCPT ); Thu, 14 Sep 2023 14:38:53 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2902F2109; Thu, 14 Sep 2023 11:38:47 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716725; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cGc9UCfp+vVEkunrrx4DZaVv0r5LexBlmCt7ramoht0=; b=hQSifniX2fTAxMhCkE1pqXlYGBR1xVgb9R+ito3n5qonTdAPSIFcljagweqMvuukvEvtV3 YQTpN5HAzEyJ/qRDAMcvlisf03CQJKG6vMxvuW71b0W7VlYumBJWpuiYm0jjmOBMekvkR8 dS7bP5XzSohOLnPeOdBxYbH/MQsT6QIm4T/D1BnoY+YFl7ZAcRRFvfS7+EhYdzGdOhtjma s2wmPcEtsF/CsNktfd4GvN3VrlUodBPcU13rWoDuvMj+zZFUFti0vJYaDWYIAVluSvmdAO gp0/YuV2L55Wf4fdfjw+yWbJ4QxFtHJo4B5azRKXtNz0sJIbWQkHgtzGTh+bjA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716725; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cGc9UCfp+vVEkunrrx4DZaVv0r5LexBlmCt7ramoht0=; b=8k/J+MqCVQhlhcnsuAIy5Q0/bh0afZbT4cuh43shtvv5GLvAolZfZlDw+CxZtsMBCHHS/I xWimy30q+dXLKpAQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Russell King , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Hongyu Xie , Jiamei Xie , Tobias Klauser , Rob Herring , delisun , Lino Sanfilippo Subject: [PATCH tty v1 17/74] serial: amba-pl011: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:34 +0206 Message-Id: <20230914183831.587273-18-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/amba-pl011.c | 72 ++++++++++++++++----------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl01= 1.c index 3dc9b0fcab1c..41eabad4c94b 100644 --- a/drivers/tty/serial/amba-pl011.c +++ b/drivers/tty/serial/amba-pl011.c @@ -345,9 +345,9 @@ static int pl011_fifo_to_tty(struct uart_amba_port *uap) flag =3D TTY_FRAME; } =20 - spin_unlock(&uap->port.lock); + uart_port_unlock(&uap->port); sysrq =3D uart_handle_sysrq_char(&uap->port, ch & 255); - spin_lock(&uap->port.lock); + uart_port_lock(&uap->port); =20 if (!sysrq) uart_insert_char(&uap->port, ch, UART011_DR_OE, ch, flag); @@ -550,7 +550,7 @@ static void pl011_dma_tx_callback(void *data) unsigned long flags; u16 dmacr; =20 - spin_lock_irqsave(&uap->port.lock, flags); + uart_port_lock_irqsave(&uap->port, &flags); if (uap->dmatx.queued) dma_unmap_sg(dmatx->chan->device->dev, &dmatx->sg, 1, DMA_TO_DEVICE); @@ -571,7 +571,7 @@ static void pl011_dma_tx_callback(void *data) if (!(dmacr & UART011_TXDMAE) || uart_tx_stopped(&uap->port) || uart_circ_empty(&uap->port.state->xmit)) { uap->dmatx.queued =3D false; - spin_unlock_irqrestore(&uap->port.lock, flags); + uart_port_unlock_irqrestore(&uap->port, flags); return; } =20 @@ -582,7 +582,7 @@ static void pl011_dma_tx_callback(void *data) */ pl011_start_tx_pio(uap); =20 - spin_unlock_irqrestore(&uap->port.lock, flags); + uart_port_unlock_irqrestore(&uap->port, flags); } =20 /* @@ -1009,7 +1009,7 @@ static void pl011_dma_rx_callback(void *data) * routine to flush out the secondary DMA buffer while * we immediately trigger the next DMA job. */ - spin_lock_irq(&uap->port.lock); + uart_port_lock_irq(&uap->port); /* * Rx data can be taken by the UART interrupts during * the DMA irq handler. So we check the residue here. @@ -1025,7 +1025,7 @@ static void pl011_dma_rx_callback(void *data) ret =3D pl011_dma_rx_trigger_dma(uap); =20 pl011_dma_rx_chars(uap, pending, lastbuf, false); - spin_unlock_irq(&uap->port.lock); + uart_port_unlock_irq(&uap->port); /* * Do this check after we picked the DMA chars so we don't * get some IRQ immediately from RX. @@ -1091,11 +1091,11 @@ static void pl011_dma_rx_poll(struct timer_list *t) if (jiffies_to_msecs(jiffies - dmarx->last_jiffies) > uap->dmarx.poll_timeout) { =20 - spin_lock_irqsave(&uap->port.lock, flags); + uart_port_lock_irqsave(&uap->port, &flags); pl011_dma_rx_stop(uap); uap->im |=3D UART011_RXIM; pl011_write(uap->im, uap, REG_IMSC); - spin_unlock_irqrestore(&uap->port.lock, flags); + uart_port_unlock_irqrestore(&uap->port, flags); =20 uap->dmarx.running =3D false; dmaengine_terminate_all(rxchan); @@ -1191,10 +1191,10 @@ static void pl011_dma_shutdown(struct uart_amba_por= t *uap) while (pl011_read(uap, REG_FR) & uap->vendor->fr_busy) cpu_relax(); =20 - spin_lock_irq(&uap->port.lock); + uart_port_lock_irq(&uap->port); uap->dmacr &=3D ~(UART011_DMAONERR | UART011_RXDMAE | UART011_TXDMAE); pl011_write(uap->dmacr, uap, REG_DMACR); - spin_unlock_irq(&uap->port.lock); + uart_port_unlock_irq(&uap->port); =20 if (uap->using_tx_dma) { /* In theory, this should already be done by pl011_dma_flush_buffer */ @@ -1374,9 +1374,9 @@ static void pl011_throttle_rx(struct uart_port *port) { unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); pl011_stop_rx(port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void pl011_enable_ms(struct uart_port *port) @@ -1394,7 +1394,7 @@ __acquires(&uap->port.lock) { pl011_fifo_to_tty(uap); =20 - spin_unlock(&uap->port.lock); + uart_port_unlock(&uap->port); tty_flip_buffer_push(&uap->port.state->port); /* * If we were temporarily out of DMA mode for a while, @@ -1419,7 +1419,7 @@ __acquires(&uap->port.lock) #endif } } - spin_lock(&uap->port.lock); + uart_port_lock(&uap->port); } =20 static bool pl011_tx_char(struct uart_amba_port *uap, unsigned char c, @@ -1555,7 +1555,7 @@ static irqreturn_t pl011_int(int irq, void *dev_id) unsigned int status, pass_counter =3D AMBA_ISR_PASS_LIMIT; int handled =3D 0; =20 - spin_lock_irqsave(&uap->port.lock, flags); + uart_port_lock_irqsave(&uap->port, &flags); status =3D pl011_read(uap, REG_RIS) & uap->im; if (status) { do { @@ -1585,7 +1585,7 @@ static irqreturn_t pl011_int(int irq, void *dev_id) handled =3D 1; } =20 - spin_unlock_irqrestore(&uap->port.lock, flags); + uart_port_unlock_irqrestore(&uap->port, flags); =20 return IRQ_RETVAL(handled); } @@ -1657,14 +1657,14 @@ static void pl011_break_ctl(struct uart_port *port,= int break_state) unsigned long flags; unsigned int lcr_h; =20 - spin_lock_irqsave(&uap->port.lock, flags); + uart_port_lock_irqsave(&uap->port, &flags); lcr_h =3D pl011_read(uap, REG_LCRH_TX); if (break_state =3D=3D -1) lcr_h |=3D UART01x_LCRH_BRK; else lcr_h &=3D ~UART01x_LCRH_BRK; pl011_write(lcr_h, uap, REG_LCRH_TX); - spin_unlock_irqrestore(&uap->port.lock, flags); + uart_port_unlock_irqrestore(&uap->port, flags); } =20 #ifdef CONFIG_CONSOLE_POLL @@ -1803,7 +1803,7 @@ static void pl011_enable_interrupts(struct uart_amba_= port *uap) unsigned long flags; unsigned int i; =20 - spin_lock_irqsave(&uap->port.lock, flags); + uart_port_lock_irqsave(&uap->port, &flags); =20 /* Clear out any spuriously appearing RX interrupts */ pl011_write(UART011_RTIS | UART011_RXIS, uap, REG_ICR); @@ -1825,7 +1825,7 @@ static void pl011_enable_interrupts(struct uart_amba_= port *uap) if (!pl011_dma_rx_running(uap)) uap->im |=3D UART011_RXIM; pl011_write(uap->im, uap, REG_IMSC); - spin_unlock_irqrestore(&uap->port.lock, flags); + uart_port_unlock_irqrestore(&uap->port, flags); } =20 static void pl011_unthrottle_rx(struct uart_port *port) @@ -1833,7 +1833,7 @@ static void pl011_unthrottle_rx(struct uart_port *por= t) struct uart_amba_port *uap =3D container_of(port, struct uart_amba_port, = port); unsigned long flags; =20 - spin_lock_irqsave(&uap->port.lock, flags); + uart_port_lock_irqsave(&uap->port, &flags); =20 uap->im =3D UART011_RTIM; if (!pl011_dma_rx_running(uap)) @@ -1841,7 +1841,7 @@ static void pl011_unthrottle_rx(struct uart_port *por= t) =20 pl011_write(uap->im, uap, REG_IMSC); =20 - spin_unlock_irqrestore(&uap->port.lock, flags); + uart_port_unlock_irqrestore(&uap->port, flags); } =20 static int pl011_startup(struct uart_port *port) @@ -1861,7 +1861,7 @@ static int pl011_startup(struct uart_port *port) =20 pl011_write(uap->vendor->ifls, uap, REG_IFLS); =20 - spin_lock_irq(&uap->port.lock); + uart_port_lock_irq(&uap->port); =20 cr =3D pl011_read(uap, REG_CR); cr &=3D UART011_CR_RTS | UART011_CR_DTR; @@ -1872,7 +1872,7 @@ static int pl011_startup(struct uart_port *port) =20 pl011_write(cr, uap, REG_CR); =20 - spin_unlock_irq(&uap->port.lock); + uart_port_unlock_irq(&uap->port); =20 /* * initialise the old status of the modem signals @@ -1933,12 +1933,12 @@ static void pl011_disable_uart(struct uart_amba_por= t *uap) unsigned int cr; =20 uap->port.status &=3D ~(UPSTAT_AUTOCTS | UPSTAT_AUTORTS); - spin_lock_irq(&uap->port.lock); + uart_port_lock_irq(&uap->port); cr =3D pl011_read(uap, REG_CR); cr &=3D UART011_CR_RTS | UART011_CR_DTR; cr |=3D UART01x_CR_UARTEN | UART011_CR_TXE; pl011_write(cr, uap, REG_CR); - spin_unlock_irq(&uap->port.lock); + uart_port_unlock_irq(&uap->port); =20 /* * disable break condition and fifos @@ -1950,14 +1950,14 @@ static void pl011_disable_uart(struct uart_amba_por= t *uap) =20 static void pl011_disable_interrupts(struct uart_amba_port *uap) { - spin_lock_irq(&uap->port.lock); + uart_port_lock_irq(&uap->port); =20 /* mask all interrupts and clear all pending ones */ uap->im =3D 0; pl011_write(uap->im, uap, REG_IMSC); pl011_write(0xffff, uap, REG_ICR); =20 - spin_unlock_irq(&uap->port.lock); + uart_port_unlock_irq(&uap->port); } =20 static void pl011_shutdown(struct uart_port *port) @@ -2102,7 +2102,7 @@ pl011_set_termios(struct uart_port *port, struct kter= mios *termios, =20 bits =3D tty_get_frame_size(termios->c_cflag); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* * Update the per-port timeout. @@ -2176,7 +2176,7 @@ pl011_set_termios(struct uart_port *port, struct kter= mios *termios, old_cr |=3D UART011_CR_RXE; pl011_write(old_cr, uap, REG_CR); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void @@ -2194,10 +2194,10 @@ sbsa_uart_set_termios(struct uart_port *port, struc= t ktermios *termios, termios->c_cflag &=3D ~(CMSPAR | CRTSCTS); termios->c_cflag |=3D CS8 | CLOCAL; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); uart_update_timeout(port, CS8, uap->fixed_baud); pl011_setup_status_masks(port, termios); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *pl011_type(struct uart_port *port) @@ -2336,9 +2336,9 @@ pl011_console_write(struct console *co, const char *s= , unsigned int count) if (uap->port.sysrq) locked =3D 0; else if (oops_in_progress) - locked =3D spin_trylock(&uap->port.lock); + locked =3D uart_port_trylock(&uap->port); else - spin_lock(&uap->port.lock); + uart_port_lock(&uap->port); =20 /* * First save the CR then disable the interrupts @@ -2364,7 +2364,7 @@ pl011_console_write(struct console *co, const char *s= , unsigned int count) pl011_write(old_cr, uap, REG_CR); =20 if (locked) - spin_unlock(&uap->port.lock); + uart_port_unlock(&uap->port); local_irq_restore(flags); =20 clk_disable(uap->clk); --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13A60EEAA5D for ; Thu, 14 Sep 2023 18:39:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241946AbjINSjf (ORCPT ); Thu, 14 Sep 2023 14:39:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241653AbjINSix (ORCPT ); Thu, 14 Sep 2023 14:38:53 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83451210A; Thu, 14 Sep 2023 11:38:47 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716726; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SN1m+sQgeewvT16dEWJcKSrjCp4ddLkdrzOmS932/1c=; b=T2+nJtqFHK05/tM4MSOXTG0QEMWzm7dci51Lnw0aYytoCX/b+7AuMkFiu1PbFgG9imA4uk B2kOwsnzIg07yBXTnAtEye+O1CWkfLiDiP4wioM6jGNZ3sXID24JoP3waGuQwzgiFaVSqo 5QVF6oI1wtFfzxrvHKA8vi9aU+u2T1eupWzb0RTs6XHvIJnrCz6J1TeJratDX4HI7KQKHU jr9bmor/75Bb4cnokJXTPSjpwtG5gBuZWs7Ue4KUkQutBWO/7cFMJo25ZWpH5ugDtjYINj fbduXBudQtprxvZRd/MIhyr4IZIww66j0DnbzrZn4I93U+828kcVZTn09qE5YQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716726; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SN1m+sQgeewvT16dEWJcKSrjCp4ddLkdrzOmS932/1c=; b=GQ4AT7dpwj6KdWTSvLHa6Iv58kWfyk7q6vILB5b0vKY5MPYKmqRhTOU1r+F/DfpZzSfmwk 0VrqhxSNFO63RJCA== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Tobias Klauser , Rob Herring , "Maciej W. Rozycki" Subject: [PATCH tty v1 18/74] serial: apb: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:35 +0206 Message-Id: <20230914183831.587273-19-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/apbuart.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/apbuart.c b/drivers/tty/serial/apbuart.c index d7658f380838..716cb014c028 100644 --- a/drivers/tty/serial/apbuart.c +++ b/drivers/tty/serial/apbuart.c @@ -133,7 +133,7 @@ static irqreturn_t apbuart_int(int irq, void *dev_id) struct uart_port *port =3D dev_id; unsigned int status; =20 - spin_lock(&port->lock); + uart_port_lock(port); =20 status =3D UART_GET_STATUS(port); if (status & UART_STATUS_DR) @@ -141,7 +141,7 @@ static irqreturn_t apbuart_int(int irq, void *dev_id) if (status & UART_STATUS_THE) apbuart_tx_chars(port); =20 - spin_unlock(&port->lock); + uart_port_unlock(port); =20 return IRQ_HANDLED; } @@ -228,7 +228,7 @@ static void apbuart_set_termios(struct uart_port *port, if (termios->c_cflag & CRTSCTS) cr |=3D UART_CTRL_FL; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Update the per-port timeout. */ uart_update_timeout(port, termios->c_cflag, baud); @@ -251,7 +251,7 @@ static void apbuart_set_termios(struct uart_port *port, UART_PUT_SCAL(port, quot); UART_PUT_CTRL(port, cr); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *apbuart_type(struct uart_port *port) --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B45CBEEAA63 for ; Thu, 14 Sep 2023 18:39:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241939AbjINSje (ORCPT ); Thu, 14 Sep 2023 14:39:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241649AbjINSix (ORCPT ); Thu, 14 Sep 2023 14:38:53 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF6B2210C; Thu, 14 Sep 2023 11:38:47 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716726; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XEd2RSJzhntSqK11XG0KTVZ8R/Gb2qOWG3w4Nfiax6M=; b=F7L7IR2eKfSOVFtuX4pQzhKiSs62AY/3etTgDhxEVqQIBaQVBBD+jnWGxhvpj3j/8Ufb5y uDdZnKOiQoUL/Kw8C3ieYB4aP2IFqldUQzXjM/wZhl7CEu8PqftaSW2pfakgw9azzENni4 CQeznE9cVGPo350Gj5199BAJ150xLfDJcvEWx1xkItuMkLrBywJDLYn0Dxm9cp4W6Dkd/Q Mnnm9LhFV4Of+kbmHSAuztVeAk31dfX+ESOSmQ8q60q6Euxy4CWDXMPBVtz7vMHvohQeZI 8sn/dvHyoYaee8iHprsz+iesZmucTBZjtDtFsWfcmJ4TN0FF/EoQkI3HJgIjZA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716726; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XEd2RSJzhntSqK11XG0KTVZ8R/Gb2qOWG3w4Nfiax6M=; b=NKcbiC3CuQI7grUBjp9Qs9w9XdzcJTBkNz781YXADwy6HZ43g3o02oPyyFKranKsUoRIwK ZyT+Wy/WXLcs/dAw== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Yangtao Li , Lukas Wunner Subject: [PATCH tty v1 19/74] serial: ar933x: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:36 +0206 Message-Id: <20230914183831.587273-20-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/ar933x_uart.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/tty/serial/ar933x_uart.c b/drivers/tty/serial/ar933x_u= art.c index 924c1a89347c..ffd234673177 100644 --- a/drivers/tty/serial/ar933x_uart.c +++ b/drivers/tty/serial/ar933x_uart.c @@ -133,9 +133,9 @@ static unsigned int ar933x_uart_tx_empty(struct uart_po= rt *port) unsigned long flags; unsigned int rdata; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); rdata =3D ar933x_uart_read(up, AR933X_UART_DATA_REG); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =20 return (rdata & AR933X_UART_DATA_TX_CSR) ? 0 : TIOCSER_TEMT; } @@ -220,14 +220,14 @@ static void ar933x_uart_break_ctl(struct uart_port *p= ort, int break_state) container_of(port, struct ar933x_uart_port, port); unsigned long flags; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); if (break_state =3D=3D -1) ar933x_uart_rmw_set(up, AR933X_UART_CS_REG, AR933X_UART_CS_TX_BREAK); else ar933x_uart_rmw_clear(up, AR933X_UART_CS_REG, AR933X_UART_CS_TX_BREAK); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 /* @@ -318,7 +318,7 @@ static void ar933x_uart_set_termios(struct uart_port *p= ort, * Ok, we're now changing the port state. Do it with * interrupts disabled. */ - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 /* disable the UART */ ar933x_uart_rmw_clear(up, AR933X_UART_CS_REG, @@ -352,7 +352,7 @@ static void ar933x_uart_set_termios(struct uart_port *p= ort, AR933X_UART_CS_IF_MODE_M << AR933X_UART_CS_IF_MODE_S, AR933X_UART_CS_IF_MODE_DCE << AR933X_UART_CS_IF_MODE_S); =20 - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =20 if (tty_termios_baud_rate(new)) tty_termios_encode_baud_rate(new, baud, baud); @@ -450,7 +450,7 @@ static irqreturn_t ar933x_uart_interrupt(int irq, void = *dev_id) if ((status & AR933X_UART_CS_HOST_INT) =3D=3D 0) return IRQ_NONE; =20 - spin_lock(&up->port.lock); + uart_port_lock(&up->port); =20 status =3D ar933x_uart_read(up, AR933X_UART_INT_REG); status &=3D ar933x_uart_read(up, AR933X_UART_INT_EN_REG); @@ -468,7 +468,7 @@ static irqreturn_t ar933x_uart_interrupt(int irq, void = *dev_id) ar933x_uart_tx_chars(up); } =20 - spin_unlock(&up->port.lock); + uart_port_unlock(&up->port); =20 return IRQ_HANDLED; } @@ -485,7 +485,7 @@ static int ar933x_uart_startup(struct uart_port *port) if (ret) return ret; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 /* Enable HOST interrupts */ ar933x_uart_rmw_set(up, AR933X_UART_CS_REG, @@ -498,7 +498,7 @@ static int ar933x_uart_startup(struct uart_port *port) /* Enable RX interrupts */ ar933x_uart_start_rx_interrupt(up); =20 - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =20 return 0; } @@ -632,9 +632,9 @@ static void ar933x_uart_console_write(struct console *c= o, const char *s, if (up->port.sysrq) locked =3D 0; else if (oops_in_progress) - locked =3D spin_trylock(&up->port.lock); + locked =3D uart_port_trylock(&up->port); else - spin_lock(&up->port.lock); + uart_port_lock(&up->port); =20 /* * First save the IER then disable the interrupts @@ -654,7 +654,7 @@ static void ar933x_uart_console_write(struct console *c= o, const char *s, ar933x_uart_write(up, AR933X_UART_INT_REG, AR933X_UART_INT_ALLINTS); =20 if (locked) - spin_unlock(&up->port.lock); + uart_port_unlock(&up->port); =20 local_irq_restore(flags); } --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0BE2EEAA65 for ; Thu, 14 Sep 2023 18:39:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241959AbjINSjh (ORCPT ); Thu, 14 Sep 2023 14:39:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241655AbjINSix (ORCPT ); Thu, 14 Sep 2023 14:38:53 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F11E2107; Thu, 14 Sep 2023 11:38:48 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716727; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vzsn2wLYsWS44Gbs24avQ4nqhzEXcoHpcp6KNR2u0GE=; b=PiJR5jMN7CVVZo8siH35FwnJFoSDfXaB7ytFHSQkwHRaQ+jVGAS45QDRTXT05uk0ubuWUR ypRaqKU5MiNEmIar0/k6pnSjYR7UZoP3tLOl1SWRLlPtvMAvuA2EWhBaxYg2PPa7frbNrq iW0FlJ1UVo03/8eHUfNsbc5INW1VgtLIFpmHtgZ5vzGMJSZfkGO+MrxULFEJ34hYUJqKPP IWsAFHssQ38VQeZn6VIF6MBsLqdxCWEQdJe5UHPrRiZtnI9mkk0TMLw7XyDWxJNc8IVj9X wTdog0tqfcGozCm07toBOvFNKPAaLuWTD75SD+cXvZr7wlaBeU/4eQMmdGpITA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716727; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vzsn2wLYsWS44Gbs24avQ4nqhzEXcoHpcp6KNR2u0GE=; b=MiF9n5qv0YK7IdQjzTI3Kbo1xwtqPynXg98RvBsu+Hr3Twlm6rN65Op6DLiw2hKFzDWYz1 gBCFTmnSTbNPWfAw== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Vineet Gupta , linux-snps-arc@lists.infradead.org Subject: [PATCH tty v1 20/74] serial: arc_uart: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:37 +0206 Message-Id: <20230914183831.587273-21-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/arc_uart.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/tty/serial/arc_uart.c b/drivers/tty/serial/arc_uart.c index ad4ae19b6ce3..1aa5b2b49c26 100644 --- a/drivers/tty/serial/arc_uart.c +++ b/drivers/tty/serial/arc_uart.c @@ -279,9 +279,9 @@ static irqreturn_t arc_serial_isr(int irq, void *dev_id) if (status & RXIENB) { =20 /* already in ISR, no need of xx_irqsave */ - spin_lock(&port->lock); + uart_port_lock(port); arc_serial_rx_chars(port, status); - spin_unlock(&port->lock); + uart_port_unlock(port); } =20 if ((status & TXIENB) && (status & TXEMPTY)) { @@ -291,12 +291,12 @@ static irqreturn_t arc_serial_isr(int irq, void *dev_= id) */ UART_TX_IRQ_DISABLE(port); =20 - spin_lock(&port->lock); + uart_port_lock(port); =20 if (!uart_tx_stopped(port)) arc_serial_tx_chars(port); =20 - spin_unlock(&port->lock); + uart_port_unlock(port); } =20 return IRQ_HANDLED; @@ -366,7 +366,7 @@ arc_serial_set_termios(struct uart_port *port, struct k= termios *new, uartl =3D hw_val & 0xFF; uarth =3D (hw_val >> 8) & 0xFF; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 UART_ALL_IRQ_DISABLE(port); =20 @@ -391,7 +391,7 @@ arc_serial_set_termios(struct uart_port *port, struct k= termios *new, =20 uart_update_timeout(port, new->c_cflag, baud); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *arc_serial_type(struct uart_port *port) @@ -521,9 +521,9 @@ static void arc_serial_console_write(struct console *co= , const char *s, struct uart_port *port =3D &arc_uart_ports[co->index].port; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); uart_console_write(port, s, count, arc_serial_console_putchar); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static struct console arc_console =3D { --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABDD8EEAA64 for ; Thu, 14 Sep 2023 18:39:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241963AbjINSjk (ORCPT ); Thu, 14 Sep 2023 14:39:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241675AbjINSix (ORCPT ); Thu, 14 Sep 2023 14:38:53 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C03E72115; Thu, 14 Sep 2023 11:38:48 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716727; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k7D9LsjqZuZo5dBqqfv/ExL4revQqVd4yA1Xdog29cQ=; b=eDObBDkcYp97Vikc2x/bBgVaipIN82wI+Nuxdvnn0VQ5FmGbVViHzrJviSZS3c25s+4h+o 642QV53qKfKLNBrjn6a+eNzVD1LPnjU0sW39bfdFCMwBwgBG9fdOCZLCzKcUriqCWjqwbh BeAHFIXIldQIEPNy4vHBC7/h1V5LisXKjDGO7I7VdtzhYYL0/AP/0QLTq+Qj2bsqtwFyLJ suFwkXQ1A9qFxfCbgIf48XqyuByw4g2nBe3DgYMzSq/d1c2xLHltB1I4pvoIqhnS8q4uRL bl3KL8ZDICk/1vUnGDd5JyRcfmjFCl+COv8nMyQDWl1p0/6ty60eHiJGbo99Vw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716727; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k7D9LsjqZuZo5dBqqfv/ExL4revQqVd4yA1Xdog29cQ=; b=wahnM7I+mOzIehgyY6oKhLre/DDgS5f9aweqXQAddREo15iBbFTZTQIhhZSzWLdmRNpBEN ZOE1ovRXuOSTwVCQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Richard Genoud , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , linux-arm-kernel@lists.infradead.org Subject: [PATCH tty v1 21/74] serial: atmel: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:38 +0206 Message-Id: <20230914183831.587273-22-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/atmel_serial.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_s= erial.c index 88cdafa5ac54..1946fafc3f3e 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -861,7 +861,7 @@ static void atmel_complete_tx_dma(void *arg) struct dma_chan *chan =3D atmel_port->chan_tx; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 if (chan) dmaengine_terminate_all(chan); @@ -893,7 +893,7 @@ static void atmel_complete_tx_dma(void *arg) atmel_port->tx_done_mask); } =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void atmel_release_tx_dma(struct uart_port *port) @@ -1711,9 +1711,9 @@ static void atmel_tasklet_rx_func(struct tasklet_stru= ct *t) struct uart_port *port =3D &atmel_port->uart; =20 /* The interrupt handler does not take the lock */ - spin_lock(&port->lock); + uart_port_lock(port); atmel_port->schedule_rx(port); - spin_unlock(&port->lock); + uart_port_unlock(port); } =20 static void atmel_tasklet_tx_func(struct tasklet_struct *t) @@ -1723,9 +1723,9 @@ static void atmel_tasklet_tx_func(struct tasklet_stru= ct *t) struct uart_port *port =3D &atmel_port->uart; =20 /* The interrupt handler does not take the lock */ - spin_lock(&port->lock); + uart_port_lock(port); atmel_port->schedule_tx(port); - spin_unlock(&port->lock); + uart_port_unlock(port); } =20 static void atmel_init_property(struct atmel_uart_port *atmel_port, @@ -2175,7 +2175,7 @@ static void atmel_set_termios(struct uart_port *port, } else mode |=3D ATMEL_US_PAR_NONE; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 port->read_status_mask =3D ATMEL_US_OVRE; if (termios->c_iflag & INPCK) @@ -2377,22 +2377,22 @@ static void atmel_set_termios(struct uart_port *por= t, else atmel_disable_ms(port); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void atmel_set_ldisc(struct uart_port *port, struct ktermios *termi= os) { if (termios->c_line =3D=3D N_PPS) { port->flags |=3D UPF_HARDPPS_CD; - spin_lock_irq(&port->lock); + uart_port_lock_irq(port); atmel_enable_ms(port); - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); } else { port->flags &=3D ~UPF_HARDPPS_CD; if (!UART_ENABLE_MS(port, termios->c_cflag)) { - spin_lock_irq(&port->lock); + uart_port_lock_irq(port); atmel_disable_ms(port); - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); } } } --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 871BAEEAA5D for ; Thu, 14 Sep 2023 18:40:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242014AbjINSkG (ORCPT ); Thu, 14 Sep 2023 14:40:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241712AbjINSi5 (ORCPT ); Thu, 14 Sep 2023 14:38:57 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31F101FFC; Thu, 14 Sep 2023 11:38:49 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716727; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W6B6UlYTFshG6RUwUjgz7+c8nYTltsRlBFw4dXdDaIc=; b=Ulo9afi/9JwAEtpEl3ZUs1+lGIMenRJFVgszhjNu6L2spjSDEOPQF8zwCH+5xN/11PJVc9 5xLX2VcVEITFFRc+mDSGZlyFSgGLSqRK2aZLwxuasSiRx8Fx7tefLvk2Ni6p9Kore8cTEL xPDiSOmddfwYTuU5a6p70NG6MdamMY3t4Ij4lcaEL7SRV8ANbX1qlixeyx3hB1MVZflFKl 5Mh/WiwwX41im6JXk6zVQQDS7rsDtZudzrbNkAwlMvUOM2xKdOowv1Hvp9z5AlXZX5FGXq cu43KLeiEpRDwU4gIYXRgOTKGKf4GZ9CkfByUJpYb3ECvOrZoY9CmEW8jCCFEA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716727; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W6B6UlYTFshG6RUwUjgz7+c8nYTltsRlBFw4dXdDaIc=; b=47jTyQrFEv1pP3sGvbZ8+7jaCouF0JKrnaWNtL6wtqAU1mfLoyiSVAJB5t6TTsdox9Y3VB G02+bnfuCsTBI3CQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Yangtao Li , Arend van Spriel Subject: [PATCH tty v1 22/74] serial: bcm63xx-uart: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:39 +0206 Message-Id: <20230914183831.587273-23-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner Reviewed-by: Florian Fainelli --- drivers/tty/serial/bcm63xx_uart.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/tty/serial/bcm63xx_uart.c b/drivers/tty/serial/bcm63xx= _uart.c index 0dd8cceb837c..4a08fd5ee61b 100644 --- a/drivers/tty/serial/bcm63xx_uart.c +++ b/drivers/tty/serial/bcm63xx_uart.c @@ -201,7 +201,7 @@ static void bcm_uart_break_ctl(struct uart_port *port, = int ctl) unsigned long flags; unsigned int val; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 val =3D bcm_uart_readl(port, UART_CTL_REG); if (ctl) @@ -210,7 +210,7 @@ static void bcm_uart_break_ctl(struct uart_port *port, = int ctl) val &=3D ~UART_CTL_XMITBRK_MASK; bcm_uart_writel(port, val, UART_CTL_REG); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /* @@ -332,7 +332,7 @@ static irqreturn_t bcm_uart_interrupt(int irq, void *de= v_id) unsigned int irqstat; =20 port =3D dev_id; - spin_lock(&port->lock); + uart_port_lock(port); =20 irqstat =3D bcm_uart_readl(port, UART_IR_REG); if (irqstat & UART_RX_INT_STAT) @@ -353,7 +353,7 @@ static irqreturn_t bcm_uart_interrupt(int irq, void *de= v_id) estat & UART_EXTINP_DCD_MASK); } =20 - spin_unlock(&port->lock); + uart_port_unlock(port); return IRQ_HANDLED; } =20 @@ -451,9 +451,9 @@ static void bcm_uart_shutdown(struct uart_port *port) { unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); bcm_uart_writel(port, 0, UART_IR_REG); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 bcm_uart_disable(port); bcm_uart_flush(port); @@ -470,7 +470,7 @@ static void bcm_uart_set_termios(struct uart_port *port= , struct ktermios *new, unsigned long flags; int tries; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Drain the hot tub fully before we power it off for the winter. */ for (tries =3D 3; !bcm_uart_tx_empty(port) && tries; tries--) @@ -546,7 +546,7 @@ static void bcm_uart_set_termios(struct uart_port *port= , struct ktermios *new, =20 uart_update_timeout(port, new->c_cflag, baud); bcm_uart_enable(port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /* @@ -712,9 +712,9 @@ static void bcm_console_write(struct console *co, const= char *s, /* bcm_uart_interrupt() already took the lock */ locked =3D 0; } else if (oops_in_progress) { - locked =3D spin_trylock(&port->lock); + locked =3D uart_port_trylock(port); } else { - spin_lock(&port->lock); + uart_port_lock(port); locked =3D 1; } =20 @@ -725,7 +725,7 @@ static void bcm_console_write(struct console *co, const= char *s, wait_for_xmitr(port); =20 if (locked) - spin_unlock(&port->lock); + uart_port_unlock(port); local_irq_restore(flags); } =20 --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38B65EEAA62 for ; Thu, 14 Sep 2023 18:39:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241989AbjINSjx (ORCPT ); Thu, 14 Sep 2023 14:39:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241716AbjINSi5 (ORCPT ); Thu, 14 Sep 2023 14:38:57 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87C912118; Thu, 14 Sep 2023 11:38:49 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YJInWHcVqt4j3eK/rdEfaKxcD8K2U9aP/8B1IuSlnT4=; b=WJ4kvtW/Klk/02gMpc/36dTKSEBiKrsPeyQpTm47TyugrlRa3xSvyphTVBdLWkj9HyCEXy Qe6cvcJeo0g78iUJIHJ59KvdU2Tzmku8IDNIqcDv98mhoyIy4h4P7uN8ZayAi7WW0zbV3S QLxLZhkPt7PiZqd3EdZYLSDFyPr+PkYSQDb4G7uhGDD3CMBUYreQygN79bpiL40W4Rs9Y6 ocWTdUS6+trFldWScC3epmB+dXCmQ4s+Q3VTeSUyjKard3ZefZVNEQbNoq/YVy7oXenGlw 1Yelc3nlPF6ymmmW123ooVQ6AUTo5qZjHXN+fLKHHED4EBKaYfKDxSp09jt9ww== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YJInWHcVqt4j3eK/rdEfaKxcD8K2U9aP/8B1IuSlnT4=; b=qzZ73KVlbH94C0/unIwHIzsufL+EDGFyJaBMYq/cOVMeReYLKBF1RMmw+o04bW9Lq3Rw26 oUJdipfVYni+ihDg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Christophe Leroy , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Subject: [PATCH tty v1 23/74] serial: cpm_uart: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:40 +0206 Message-Id: <20230914183831.587273-24-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/cpm_uart.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/cpm_uart.c b/drivers/tty/serial/cpm_uart.c index 626423022d62..be4af6eda4c2 100644 --- a/drivers/tty/serial/cpm_uart.c +++ b/drivers/tty/serial/cpm_uart.c @@ -569,7 +569,7 @@ static void cpm_uart_set_termios(struct uart_port *port, if ((termios->c_cflag & CREAD) =3D=3D 0) port->read_status_mask &=3D ~BD_SC_EMPTY; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 if (IS_SMC(pinfo)) { unsigned int bits =3D tty_get_frame_size(termios->c_cflag); @@ -609,7 +609,7 @@ static void cpm_uart_set_termios(struct uart_port *port, clk_set_rate(pinfo->clk, baud); else cpm_setbrg(pinfo->brg - 1, baud); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *cpm_uart_type(struct uart_port *port) @@ -1386,9 +1386,9 @@ static void cpm_uart_console_write(struct console *co= , const char *s, cpm_uart_early_write(pinfo, s, count, true); local_irq_restore(flags); } else { - spin_lock_irqsave(&pinfo->port.lock, flags); + uart_port_lock_irqsave(&pinfo->port, &flags); cpm_uart_early_write(pinfo, s, count, true); - spin_unlock_irqrestore(&pinfo->port.lock, flags); + uart_port_unlock_irqrestore(&pinfo->port, flags); } } =20 --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28425EEAA63 for ; Thu, 14 Sep 2023 18:39:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241984AbjINSjs (ORCPT ); Thu, 14 Sep 2023 14:39:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241739AbjINSi6 (ORCPT ); Thu, 14 Sep 2023 14:38:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1BFB1FFB; Thu, 14 Sep 2023 11:38:49 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lSEvjVL+BxuTqhoV6y++5iFzUZwHV0OnCUueADVyxEA=; b=IVquxk0Z+ro6LFHKJw51lwIPigfWCMfmclUU2+JcehI3LOaX5BkNwJRLblrY0cbagILQic RqiElXu91Wnj1AhvgvDxpBl8H4wZs16fjHk6JDxf7RHlZytj1RGhivPhRjLqRbQGhMxpEy vg/kQ1k3mVm1xZnPUIn7+mrqPqddMnw5g3lnvkbYeAfM5GK9kjiAKhJJO1cRKYHo3CMe2D bbcknb4FzDKQZjdNHh8XHtx01Lip0J/J3MtvXpgDJScQb8lF5ZDAXULO+IUJr1FN+XgeG5 WasYgGIMC0IPIVLI1Q5P/xd2hLixAvMXU+m/Fa8R6mu0GRkyln7ivVnmHKqBqA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lSEvjVL+BxuTqhoV6y++5iFzUZwHV0OnCUueADVyxEA=; b=r6+fh09oHfENkWCN4lF8MffdwEGUKNIjvSkxoPrQxnv1rhnu/nekiAEHappQ9NFpa+bmJT nA9poxy/eDhflsDg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Baruch Siach , Tobias Klauser , Richard GENOUD , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , linux-arm-kernel@lists.infradead.org Subject: [PATCH tty v1 24/74] serial: digicolor: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:41 +0206 Message-Id: <20230914183831.587273-25-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner Acked-by: Baruch Siach --- drivers/tty/serial/digicolor-usart.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/tty/serial/digicolor-usart.c b/drivers/tty/serial/digi= color-usart.c index 128b5479e813..5004125f3045 100644 --- a/drivers/tty/serial/digicolor-usart.c +++ b/drivers/tty/serial/digicolor-usart.c @@ -133,7 +133,7 @@ static void digicolor_uart_rx(struct uart_port *port) { unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 while (1) { u8 status, ch, ch_flag; @@ -172,7 +172,7 @@ static void digicolor_uart_rx(struct uart_port *port) ch_flag); } =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 tty_flip_buffer_push(&port->state->port); } @@ -185,7 +185,7 @@ static void digicolor_uart_tx(struct uart_port *port) if (digicolor_uart_tx_full(port)) return; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 if (port->x_char) { writeb_relaxed(port->x_char, port->membase + UA_EMI_REC); @@ -211,7 +211,7 @@ static void digicolor_uart_tx(struct uart_port *port) uart_write_wakeup(port); =20 out: - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static irqreturn_t digicolor_uart_int(int irq, void *dev_id) @@ -333,7 +333,7 @@ static void digicolor_uart_set_termios(struct uart_port= *port, port->ignore_status_mask |=3D UA_STATUS_OVERRUN_ERR | UA_STATUS_PARITY_ERR | UA_STATUS_FRAME_ERR; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 uart_update_timeout(port, termios->c_cflag, baud); =20 @@ -341,7 +341,7 @@ static void digicolor_uart_set_termios(struct uart_port= *port, writeb_relaxed(divisor & 0xff, port->membase + UA_HBAUD_LO); writeb_relaxed(divisor >> 8, port->membase + UA_HBAUD_HI); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *digicolor_uart_type(struct uart_port *port) @@ -398,14 +398,14 @@ static void digicolor_uart_console_write(struct conso= le *co, const char *c, int locked =3D 1; =20 if (oops_in_progress) - locked =3D spin_trylock_irqsave(&port->lock, flags); + locked =3D uart_port_trylock_irqsave(port, &flags); else - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 uart_console_write(port, c, n, digicolor_uart_console_putchar); =20 if (locked) - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 /* Wait for transmitter to become empty */ do { --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4060DEEAA5D for ; Thu, 14 Sep 2023 18:39:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241800AbjINSjn (ORCPT ); Thu, 14 Sep 2023 14:39:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241745AbjINSi6 (ORCPT ); Thu, 14 Sep 2023 14:38:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75A441FFD; Thu, 14 Sep 2023 11:38:50 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bAQMyCFi9PO4xpR/WPWLi4jhKKcsg8hehn8chVaaTl0=; b=n2xCF/DUjDRzahmUSJxlSWtqGEYnXikTuRJGO0brUgFo2xy+azTzwwyTkZQNjo2UtThea7 6Bj6FHVBCQWeV2ZRasFqBo0ev16KuZO4Z/2Dmh9F+/Uiy4YQqcvXCUKI9WXIJWy13kiOFV njJOY6stZWqb3FId6kBIv374vYa8WlyJvXiRxupEVrKfVO6HmihZfrUwaYlElGK8Avws4a KRYBVPxog9AXlkbsxYS+nBFZ3qtL5FhcNCgQXfqgfplsxw+PQ6yXHjleI2Ixi4sl/t+RFV vYvVuQKs//wBKHK7pFppuYNN0V74DEvdof27v/pzsUV1rUhJe6hwLZjED2PO+g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bAQMyCFi9PO4xpR/WPWLi4jhKKcsg8hehn8chVaaTl0=; b=KdZ4Z6jUDDh6cAqCYOcEnIuqTngw9Nw3VLNS+kOfej1f0HNVUKkr2RbnSjsqky7RxWlaNt 7pOCpZiPfAabqLDA== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, "Maciej W. Rozycki" Subject: [PATCH tty v1 25/74] serial: dz: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:42 +0206 Message-Id: <20230914183831.587273-26-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/dz.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/drivers/tty/serial/dz.c b/drivers/tty/serial/dz.c index 667f52e83277..6df7af9edc1c 100644 --- a/drivers/tty/serial/dz.c +++ b/drivers/tty/serial/dz.c @@ -268,9 +268,9 @@ static inline void dz_transmit_chars(struct dz_mux *mux) } /* If nothing to do or stopped or hardware stopped. */ if (uart_circ_empty(xmit) || uart_tx_stopped(&dport->port)) { - spin_lock(&dport->port.lock); + uart_port_lock(&dport->port); dz_stop_tx(&dport->port); - spin_unlock(&dport->port.lock); + uart_port_unlock(&dport->port); return; } =20 @@ -287,9 +287,9 @@ static inline void dz_transmit_chars(struct dz_mux *mux) =20 /* Are we are done. */ if (uart_circ_empty(xmit)) { - spin_lock(&dport->port.lock); + uart_port_lock(&dport->port); dz_stop_tx(&dport->port); - spin_unlock(&dport->port.lock); + uart_port_unlock(&dport->port); } } =20 @@ -415,14 +415,14 @@ static int dz_startup(struct uart_port *uport) return ret; } =20 - spin_lock_irqsave(&dport->port.lock, flags); + uart_port_lock_irqsave(&dport->port, &flags); =20 /* Enable interrupts. */ tmp =3D dz_in(dport, DZ_CSR); tmp |=3D DZ_RIE | DZ_TIE; dz_out(dport, DZ_CSR, tmp); =20 - spin_unlock_irqrestore(&dport->port.lock, flags); + uart_port_unlock_irqrestore(&dport->port, flags); =20 return 0; } @@ -443,9 +443,9 @@ static void dz_shutdown(struct uart_port *uport) int irq_guard; u16 tmp; =20 - spin_lock_irqsave(&dport->port.lock, flags); + uart_port_lock_irqsave(&dport->port, &flags); dz_stop_tx(&dport->port); - spin_unlock_irqrestore(&dport->port.lock, flags); + uart_port_unlock_irqrestore(&dport->port, flags); =20 irq_guard =3D atomic_add_return(-1, &mux->irq_guard); if (!irq_guard) { @@ -491,14 +491,14 @@ static void dz_break_ctl(struct uart_port *uport, int= break_state) unsigned long flags; unsigned short tmp, mask =3D 1 << dport->port.line; =20 - spin_lock_irqsave(&uport->lock, flags); + uart_port_lock_irqsave(uport, &flags); tmp =3D dz_in(dport, DZ_TCR); if (break_state) tmp |=3D mask; else tmp &=3D ~mask; dz_out(dport, DZ_TCR, tmp); - spin_unlock_irqrestore(&uport->lock, flags); + uart_port_unlock_irqrestore(uport, flags); } =20 static int dz_encode_baud_rate(unsigned int baud) @@ -608,7 +608,7 @@ static void dz_set_termios(struct uart_port *uport, str= uct ktermios *termios, if (termios->c_cflag & CREAD) cflag |=3D DZ_RXENAB; =20 - spin_lock_irqsave(&dport->port.lock, flags); + uart_port_lock_irqsave(&dport->port, &flags); =20 uart_update_timeout(uport, termios->c_cflag, baud); =20 @@ -631,7 +631,7 @@ static void dz_set_termios(struct uart_port *uport, str= uct ktermios *termios, if (termios->c_iflag & IGNBRK) dport->port.ignore_status_mask |=3D DZ_BREAK; =20 - spin_unlock_irqrestore(&dport->port.lock, flags); + uart_port_unlock_irqrestore(&dport->port, flags); } =20 /* @@ -645,12 +645,12 @@ static void dz_pm(struct uart_port *uport, unsigned i= nt state, struct dz_port *dport =3D to_dport(uport); unsigned long flags; =20 - spin_lock_irqsave(&dport->port.lock, flags); + uart_port_lock_irqsave(&dport->port, &flags); if (state < 3) dz_start_tx(&dport->port); else dz_stop_tx(&dport->port); - spin_unlock_irqrestore(&dport->port.lock, flags); + uart_port_unlock_irqrestore(&dport->port, flags); } =20 =20 @@ -811,7 +811,7 @@ static void dz_console_putchar(struct uart_port *uport,= unsigned char ch) unsigned short csr, tcr, trdy, mask; int loops =3D 10000; =20 - spin_lock_irqsave(&dport->port.lock, flags); + uart_port_lock_irqsave(&dport->port, &flags); csr =3D dz_in(dport, DZ_CSR); dz_out(dport, DZ_CSR, csr & ~DZ_TIE); tcr =3D dz_in(dport, DZ_TCR); @@ -819,7 +819,7 @@ static void dz_console_putchar(struct uart_port *uport,= unsigned char ch) mask =3D tcr; dz_out(dport, DZ_TCR, mask); iob(); - spin_unlock_irqrestore(&dport->port.lock, flags); + uart_port_unlock_irqrestore(&dport->port, flags); =20 do { trdy =3D dz_in(dport, DZ_CSR); --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4DD5EEAA65 for ; Thu, 14 Sep 2023 18:39:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241983AbjINSjp (ORCPT ); Thu, 14 Sep 2023 14:39:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241748AbjINSi6 (ORCPT ); Thu, 14 Sep 2023 14:38:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C049F1FFF; Thu, 14 Sep 2023 11:38:50 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LnvnRSzrP5woiUHdOlb0Xg3fIJh3UJCjsy6M4up7fns=; b=q3Pkc5q153R9B4lAEoaA19W6MCMs6e7mCMtjnfPCoSu5uskZO70YiNFkdi4cc2AiIdF44X xMN/yA0YBtf1rAThdjz4/pj0TN952tVmeDh4LfVuzsehKXBkDYjOjivfsFWjHiND1aoCDR vOZihjkxvwaVoFclY/TK4PPQec6xJixb03Sgeu8bZAxp2rNnEF/LwPJfUSJMiKC6sekAar DMNKKY5hA3CkE8EqATl34e8U6c3UqqVj7GF22fSwM5KGL8t90o0+uh92rOgF6yoH2pv3OJ JyFF3Qy8mEpw8dfdii/p/yOitx+q9v/ismffS6J7mEVMch28sWMu9yb7W2uvAw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LnvnRSzrP5woiUHdOlb0Xg3fIJh3UJCjsy6M4up7fns=; b=5doHq489JrJleGSPjVe5kdeivGhy0qLN1gSxtjdAKVkc4V0xuC8emnUqbt0JJUzhj7NGUS pfM2wQcP0bLD79Bw== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Yangtao Li , Rob Herring Subject: [PATCH tty v1 26/74] serial: linflexuart: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:43 +0206 Message-Id: <20230914183831.587273-27-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/fsl_linflexuart.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/tty/serial/fsl_linflexuart.c b/drivers/tty/serial/fsl_= linflexuart.c index 249cb380c3c6..7fa809a405e8 100644 --- a/drivers/tty/serial/fsl_linflexuart.c +++ b/drivers/tty/serial/fsl_linflexuart.c @@ -203,7 +203,7 @@ static irqreturn_t linflex_txint(int irq, void *dev_id) struct circ_buf *xmit =3D &sport->state->xmit; unsigned long flags; =20 - spin_lock_irqsave(&sport->lock, flags); + uart_port_lock_irqsave(sport, &flags); =20 if (sport->x_char) { linflex_put_char(sport, sport->x_char); @@ -217,7 +217,7 @@ static irqreturn_t linflex_txint(int irq, void *dev_id) =20 linflex_transmit_buffer(sport); out: - spin_unlock_irqrestore(&sport->lock, flags); + uart_port_unlock_irqrestore(sport, flags); return IRQ_HANDLED; } =20 @@ -230,7 +230,7 @@ static irqreturn_t linflex_rxint(int irq, void *dev_id) unsigned char rx; bool brk; =20 - spin_lock_irqsave(&sport->lock, flags); + uart_port_lock_irqsave(sport, &flags); =20 status =3D readl(sport->membase + UARTSR); while (status & LINFLEXD_UARTSR_RMB) { @@ -266,7 +266,7 @@ static irqreturn_t linflex_rxint(int irq, void *dev_id) } } =20 - spin_unlock_irqrestore(&sport->lock, flags); + uart_port_unlock_irqrestore(sport, flags); =20 tty_flip_buffer_push(port); =20 @@ -369,11 +369,11 @@ static int linflex_startup(struct uart_port *port) int ret =3D 0; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 linflex_setup_watermark(port); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 ret =3D devm_request_irq(port->dev, port->irq, linflex_int, 0, DRIVER_NAME, port); @@ -386,14 +386,14 @@ static void linflex_shutdown(struct uart_port *port) unsigned long ier; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* disable interrupts */ ier =3D readl(port->membase + LINIER); ier &=3D ~(LINFLEXD_LINIER_DRIE | LINFLEXD_LINIER_DTIE); writel(ier, port->membase + LINIER); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 devm_free_irq(port->dev, port->irq, port); } @@ -474,7 +474,7 @@ linflex_set_termios(struct uart_port *port, struct kter= mios *termios, cr &=3D ~LINFLEXD_UARTCR_PCE; } =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 port->read_status_mask =3D 0; =20 @@ -507,7 +507,7 @@ linflex_set_termios(struct uart_port *port, struct kter= mios *termios, =20 writel(cr1, port->membase + LINCR1); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *linflex_type(struct uart_port *port) @@ -646,14 +646,14 @@ linflex_console_write(struct console *co, const char = *s, unsigned int count) if (sport->sysrq) locked =3D 0; else if (oops_in_progress) - locked =3D spin_trylock_irqsave(&sport->lock, flags); + locked =3D uart_port_trylock_irqsave(sport, &flags); else - spin_lock_irqsave(&sport->lock, flags); + uart_port_lock_irqsave(sport, &flags); =20 linflex_string_write(sport, s, count); =20 if (locked) - spin_unlock_irqrestore(&sport->lock, flags); + uart_port_unlock_irqrestore(sport, flags); } =20 /* --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 039B9EEAA65 for ; Thu, 14 Sep 2023 18:39:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241986AbjINSjv (ORCPT ); Thu, 14 Sep 2023 14:39:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241752AbjINSi6 (ORCPT ); Thu, 14 Sep 2023 14:38:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E37E2101; Thu, 14 Sep 2023 11:38:51 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ipnrMGkMfXtAucrTg6CNX21I0VKKw9iDIsUZ6VX3lJI=; b=Ed/45K1nO5d/fubvArMFTb1KutTN1nRYHACbAPYM3Xj4T51JiSNUyJaRFVQcBV4QIlcJnl 6FnhpRQ7p39bvhQyw3gWpNyrlm3unBsMyAwA6asobEoqwxL37DohvDnbA4ivv0sNayq2ks 2Lr/YHUWMVsDTX3kcbnvhOwC8/QZhyePSKS5hCGlATYgy5YloC1v3q6YTja3eCwZ+m8I4B a0AMwtU/eoeztf4qYLK/u39BBCQPtSGRnNffhTaoJcfIL/Z/1ODMSH0BDOUqhDfZPKn65Z 6xupq9kNMpQ/lpNRm/ruhaLQkA51iJj+dxMc0p9L3DcNAQcYGJIcJRbmcda91A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ipnrMGkMfXtAucrTg6CNX21I0VKKw9iDIsUZ6VX3lJI=; b=R7eynNqc+WyUKnxgyl7XrqPIGm/keP6PNu5EwVQypQAK9lNq2RnhFkMTAZgRpQhA75BVpD UdMq3pk4m7IJprDA== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Sherry Sun , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Shenwei Wang Subject: [PATCH tty v1 27/74] serial: fsl_lpuart: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:44 +0206 Message-Id: <20230914183831.587273-28-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/fsl_lpuart.c | 88 ++++++++++++++++----------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuar= t.c index f72e1340b47d..6d0cfb2e86b4 100644 --- a/drivers/tty/serial/fsl_lpuart.c +++ b/drivers/tty/serial/fsl_lpuart.c @@ -532,9 +532,9 @@ static void lpuart_dma_tx_complete(void *arg) struct dma_chan *chan =3D sport->dma_tx_chan; unsigned long flags; =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); if (!sport->dma_tx_in_progress) { - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); return; } =20 @@ -543,7 +543,7 @@ static void lpuart_dma_tx_complete(void *arg) =20 uart_xmit_advance(&sport->port, sport->dma_tx_bytes); sport->dma_tx_in_progress =3D false; - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); =20 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) uart_write_wakeup(&sport->port); @@ -553,12 +553,12 @@ static void lpuart_dma_tx_complete(void *arg) return; } =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); =20 if (!lpuart_stopped_or_empty(&sport->port)) lpuart_dma_tx(sport); =20 - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); } =20 static dma_addr_t lpuart_dma_datareg_addr(struct lpuart_port *sport) @@ -651,7 +651,7 @@ static int lpuart_poll_init(struct uart_port *port) =20 sport->port.fifosize =3D 0; =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); /* Disable Rx & Tx */ writeb(0, sport->port.membase + UARTCR2); =20 @@ -675,7 +675,7 @@ static int lpuart_poll_init(struct uart_port *port) =20 /* Enable Rx and Tx */ writeb(UARTCR2_RE | UARTCR2_TE, sport->port.membase + UARTCR2); - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); =20 return 0; } @@ -703,7 +703,7 @@ static int lpuart32_poll_init(struct uart_port *port) =20 sport->port.fifosize =3D 0; =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); =20 /* Disable Rx & Tx */ lpuart32_write(&sport->port, 0, UARTCTRL); @@ -724,7 +724,7 @@ static int lpuart32_poll_init(struct uart_port *port) =20 /* Enable Rx and Tx */ lpuart32_write(&sport->port, UARTCTRL_RE | UARTCTRL_TE, UARTCTRL); - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); =20 return 0; } @@ -879,9 +879,9 @@ static unsigned int lpuart32_tx_empty(struct uart_port = *port) =20 static void lpuart_txint(struct lpuart_port *sport) { - spin_lock(&sport->port.lock); + uart_port_lock(&sport->port); lpuart_transmit_buffer(sport); - spin_unlock(&sport->port.lock); + uart_port_unlock(&sport->port); } =20 static void lpuart_rxint(struct lpuart_port *sport) @@ -890,7 +890,7 @@ static void lpuart_rxint(struct lpuart_port *sport) struct tty_port *port =3D &sport->port.state->port; unsigned char rx, sr; =20 - spin_lock(&sport->port.lock); + uart_port_lock(&sport->port); =20 while (!(readb(sport->port.membase + UARTSFIFO) & UARTSFIFO_RXEMPT)) { flg =3D TTY_NORMAL; @@ -956,9 +956,9 @@ static void lpuart_rxint(struct lpuart_port *sport) =20 static void lpuart32_txint(struct lpuart_port *sport) { - spin_lock(&sport->port.lock); + uart_port_lock(&sport->port); lpuart32_transmit_buffer(sport); - spin_unlock(&sport->port.lock); + uart_port_unlock(&sport->port); } =20 static void lpuart32_rxint(struct lpuart_port *sport) @@ -968,7 +968,7 @@ static void lpuart32_rxint(struct lpuart_port *sport) unsigned long rx, sr; bool is_break; =20 - spin_lock(&sport->port.lock); + uart_port_lock(&sport->port); =20 while (!(lpuart32_read(&sport->port, UARTFIFO) & UARTFIFO_RXEMPT)) { flg =3D TTY_NORMAL; @@ -1170,12 +1170,12 @@ static void lpuart_copy_rx_to_tty(struct lpuart_por= t *sport) =20 async_tx_ack(sport->dma_rx_desc); =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); =20 dmastat =3D dmaengine_tx_status(chan, sport->dma_rx_cookie, &state); if (dmastat =3D=3D DMA_ERROR) { dev_err(sport->port.dev, "Rx DMA transfer failed!\n"); - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); return; } =20 @@ -1244,7 +1244,7 @@ static void lpuart_copy_rx_to_tty(struct lpuart_port = *sport) dma_sync_sg_for_device(chan->device->dev, &sport->rx_sgl, 1, DMA_FROM_DEVICE); =20 - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); =20 tty_flip_buffer_push(port); if (!sport->dma_idle_int) @@ -1335,9 +1335,9 @@ static void lpuart_timer_func(struct timer_list *t) mod_timer(&sport->lpuart_timer, jiffies + sport->dma_rx_timeout); =20 - if (spin_trylock_irqsave(&sport->port.lock, flags)) { + if (uart_port_trylock_irqsave(&sport->port, &flags)) { sport->last_residue =3D state.residue; - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); } } =20 @@ -1802,14 +1802,14 @@ static void lpuart_hw_setup(struct lpuart_port *spo= rt) { unsigned long flags; =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); =20 lpuart_setup_watermark_enable(sport); =20 lpuart_rx_dma_startup(sport); lpuart_tx_dma_startup(sport); =20 - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); } =20 static int lpuart_startup(struct uart_port *port) @@ -1859,7 +1859,7 @@ static void lpuart32_hw_setup(struct lpuart_port *spo= rt) { unsigned long flags; =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); =20 lpuart32_hw_disable(sport); =20 @@ -1869,7 +1869,7 @@ static void lpuart32_hw_setup(struct lpuart_port *spo= rt) lpuart32_setup_watermark_enable(sport); lpuart32_configure(sport); =20 - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); } =20 static int lpuart32_startup(struct uart_port *port) @@ -1932,7 +1932,7 @@ static void lpuart_shutdown(struct uart_port *port) unsigned char temp; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* disable Rx/Tx and interrupts */ temp =3D readb(port->membase + UARTCR2); @@ -1940,7 +1940,7 @@ static void lpuart_shutdown(struct uart_port *port) UARTCR2_TIE | UARTCR2_TCIE | UARTCR2_RIE); writeb(temp, port->membase + UARTCR2); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 lpuart_dma_shutdown(sport); } @@ -1952,7 +1952,7 @@ static void lpuart32_shutdown(struct uart_port *port) unsigned long temp; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* clear status */ temp =3D lpuart32_read(&sport->port, UARTSTAT); @@ -1969,7 +1969,7 @@ static void lpuart32_shutdown(struct uart_port *port) UARTCTRL_TIE | UARTCTRL_TCIE | UARTCTRL_RIE | UARTCTRL_SBK); lpuart32_write(port, temp, UARTCTRL); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 lpuart_dma_shutdown(sport); } @@ -2069,7 +2069,7 @@ lpuart_set_termios(struct uart_port *port, struct kte= rmios *termios, if (old && sport->lpuart_dma_rx_use) lpuart_dma_rx_free(&sport->port); =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); =20 sport->port.read_status_mask =3D 0; if (termios->c_iflag & INPCK) @@ -2124,7 +2124,7 @@ lpuart_set_termios(struct uart_port *port, struct kte= rmios *termios, sport->lpuart_dma_rx_use =3D false; } =20 - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); } =20 static void __lpuart32_serial_setbrg(struct uart_port *port, @@ -2304,7 +2304,7 @@ lpuart32_set_termios(struct uart_port *port, struct k= termios *termios, if (old && sport->lpuart_dma_rx_use) lpuart_dma_rx_free(&sport->port); =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); =20 sport->port.read_status_mask =3D 0; if (termios->c_iflag & INPCK) @@ -2359,7 +2359,7 @@ lpuart32_set_termios(struct uart_port *port, struct k= termios *termios, sport->lpuart_dma_rx_use =3D false; } =20 - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); } =20 static const char *lpuart_type(struct uart_port *port) @@ -2477,9 +2477,9 @@ lpuart_console_write(struct console *co, const char *= s, unsigned int count) int locked =3D 1; =20 if (oops_in_progress) - locked =3D spin_trylock_irqsave(&sport->port.lock, flags); + locked =3D uart_port_trylock_irqsave(&sport->port, &flags); else - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); =20 /* first save CR2 and then disable interrupts */ cr2 =3D old_cr2 =3D readb(sport->port.membase + UARTCR2); @@ -2495,7 +2495,7 @@ lpuart_console_write(struct console *co, const char *= s, unsigned int count) writeb(old_cr2, sport->port.membase + UARTCR2); =20 if (locked) - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); } =20 static void @@ -2507,9 +2507,9 @@ lpuart32_console_write(struct console *co, const char= *s, unsigned int count) int locked =3D 1; =20 if (oops_in_progress) - locked =3D spin_trylock_irqsave(&sport->port.lock, flags); + locked =3D uart_port_trylock_irqsave(&sport->port, &flags); else - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); =20 /* first save CR2 and then disable interrupts */ cr =3D old_cr =3D lpuart32_read(&sport->port, UARTCTRL); @@ -2525,7 +2525,7 @@ lpuart32_console_write(struct console *co, const char= *s, unsigned int count) lpuart32_write(&sport->port, old_cr, UARTCTRL); =20 if (locked) - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); } =20 /* @@ -3089,7 +3089,7 @@ static int lpuart_suspend(struct device *dev) uart_suspend_port(&lpuart_reg, &sport->port); =20 if (lpuart_uport_is_active(sport)) { - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); if (lpuart_is_32(sport)) { /* disable Rx/Tx and interrupts */ temp =3D lpuart32_read(&sport->port, UARTCTRL); @@ -3101,7 +3101,7 @@ static int lpuart_suspend(struct device *dev) temp &=3D ~(UARTCR2_TE | UARTCR2_TIE | UARTCR2_TCIE); writeb(temp, sport->port.membase + UARTCR2); } - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); =20 if (sport->lpuart_dma_rx_use) { /* @@ -3114,7 +3114,7 @@ static int lpuart_suspend(struct device *dev) lpuart_dma_rx_free(&sport->port); =20 /* Disable Rx DMA to use UART port as wakeup source */ - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); if (lpuart_is_32(sport)) { temp =3D lpuart32_read(&sport->port, UARTBAUD); lpuart32_write(&sport->port, temp & ~UARTBAUD_RDMAE, @@ -3123,11 +3123,11 @@ static int lpuart_suspend(struct device *dev) writeb(readb(sport->port.membase + UARTCR5) & ~UARTCR5_RDMAS, sport->port.membase + UARTCR5); } - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); } =20 if (sport->lpuart_dma_tx_use) { - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); if (lpuart_is_32(sport)) { temp =3D lpuart32_read(&sport->port, UARTBAUD); temp &=3D ~UARTBAUD_TDMAE; @@ -3137,7 +3137,7 @@ static int lpuart_suspend(struct device *dev) temp &=3D ~UARTCR5_TDMAS; writeb(temp, sport->port.membase + UARTCR5); } - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); sport->dma_tx_in_progress =3D false; dmaengine_terminate_sync(sport->dma_tx_chan); } --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 691E5EEAA63 for ; Thu, 14 Sep 2023 18:39:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242006AbjINSkB (ORCPT ); Thu, 14 Sep 2023 14:40:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241757AbjINSi6 (ORCPT ); Thu, 14 Sep 2023 14:38:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 681ED2125; Thu, 14 Sep 2023 11:38:51 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716730; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j0GmIFy0BH/+UTBQ4ZgVoWD6SiHe6dj4MJtGxMeb4ws=; b=N3bXQSCuQqc8ZLKWNuSbsQh7s7GqgSxbmBWpOzM9sEk6QHKWFEbtJOQLKyhKgXthD9Z6vw ZqclHiaYgbzHM0EkyRHODr40EGhks6Ju4+uvFCoIRWJsyRuJYJpPhSHmQ6zqkXWlF18uyJ Lp3HCPZSY+gJOB8qgK+mgJr7AYWaFTDqMOzoJkrVkA0EQqiC65VBkRuYeSOpsPPovK9u2W 29CsI2YCrMnYaWb9KnFApf2pxhU3wohFLaS6s+2Fw/Bk1HVYtS4PMXZi3hQ2b0agOB9WHO C05OnXJBHopj2iAT5w8ofAESrUqG6Eg80MVy7P4n9F+iazL12dExxlWI+zVnnQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716730; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j0GmIFy0BH/+UTBQ4ZgVoWD6SiHe6dj4MJtGxMeb4ws=; b=BEtIV40ZqaqgdYy1xbSsLLBt/nj7SKd222LHGiscOOSPR6hoLSqDxmWjaHKcOd7VyYnEHr 2AjDPLb8eakwGnBw== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH tty v1 28/74] serial: icom: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:45 +0206 Message-Id: <20230914183831.587273-29-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/icom.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/tty/serial/icom.c b/drivers/tty/serial/icom.c index 819f957b6b84..a75eafbcbea3 100644 --- a/drivers/tty/serial/icom.c +++ b/drivers/tty/serial/icom.c @@ -929,7 +929,7 @@ static inline void check_modem_status(struct icom_port = *icom_port) char delta_status; unsigned char status; =20 - spin_lock(&icom_port->uart_port.lock); + uart_port_lock(&icom_port->uart_port); =20 /*modem input register */ status =3D readb(&icom_port->dram->isr); @@ -951,7 +951,7 @@ static inline void check_modem_status(struct icom_port = *icom_port) port.delta_msr_wait); old_status =3D status; } - spin_unlock(&icom_port->uart_port.lock); + uart_port_unlock(&icom_port->uart_port); } =20 static void xmit_interrupt(u16 port_int_reg, struct icom_port *icom_port) @@ -1093,7 +1093,7 @@ static void process_interrupt(u16 port_int_reg, struct icom_port *icom_port) { =20 - spin_lock(&icom_port->uart_port.lock); + uart_port_lock(&icom_port->uart_port); trace(icom_port, "INTERRUPT", port_int_reg); =20 if (port_int_reg & (INT_XMIT_COMPLETED | INT_XMIT_DISABLED)) @@ -1102,7 +1102,7 @@ static void process_interrupt(u16 port_int_reg, if (port_int_reg & INT_RCV_COMPLETED) recv_interrupt(port_int_reg, icom_port); =20 - spin_unlock(&icom_port->uart_port.lock); + uart_port_unlock(&icom_port->uart_port); } =20 static irqreturn_t icom_interrupt(int irq, void *dev_id) @@ -1186,14 +1186,14 @@ static unsigned int icom_tx_empty(struct uart_port = *port) int ret; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); if (le16_to_cpu(icom_port->statStg->xmit[0].flags) & SA_FLAGS_READY_TO_XMIT) ret =3D TIOCSER_TEMT; else ret =3D 0; =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); return ret; } =20 @@ -1276,7 +1276,7 @@ static void icom_send_xchar(struct uart_port *port, c= har ch) =20 /* wait .1 sec to send char */ for (index =3D 0; index < 10; index++) { - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); xdata =3D readb(&icom_port->dram->xchar); if (xdata =3D=3D 0x00) { trace(icom_port, "QUICK_WRITE", 0); @@ -1284,10 +1284,10 @@ static void icom_send_xchar(struct uart_port *port,= char ch) =20 /* flush write operation */ xdata =3D readb(&icom_port->dram->xchar); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); break; } - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); msleep(10); } } @@ -1307,7 +1307,7 @@ static void icom_break(struct uart_port *port, int br= eak_state) unsigned char cmdReg; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); trace(icom_port, "BREAK", 0); cmdReg =3D readb(&icom_port->dram->CmdReg); if (break_state =3D=3D -1) { @@ -1315,7 +1315,7 @@ static void icom_break(struct uart_port *port, int br= eak_state) } else { writeb(cmdReg & ~CMD_SND_BREAK, &icom_port->dram->CmdReg); } - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static int icom_open(struct uart_port *port) @@ -1365,7 +1365,7 @@ static void icom_set_termios(struct uart_port *port, = struct ktermios *termios, unsigned long offset; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); trace(icom_port, "CHANGE_SPEED", 0); =20 cflag =3D termios->c_cflag; @@ -1516,7 +1516,7 @@ static void icom_set_termios(struct uart_port *port, = struct ktermios *termios, trace(icom_port, "XR_ENAB", 0); writeb(CMD_XMIT_RCV_ENABLE, &icom_port->dram->CmdReg); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *icom_type(struct uart_port *port) --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B897EEEAA62 for ; Thu, 14 Sep 2023 18:40:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242010AbjINSkE (ORCPT ); Thu, 14 Sep 2023 14:40:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241762AbjINSi6 (ORCPT ); Thu, 14 Sep 2023 14:38:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2B0C212C; Thu, 14 Sep 2023 11:38:51 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716730; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4dWyZArXLuwNKhH3CiBToeEwUY+mI4MenFw8MF0ZHBA=; b=dwibDkJFXaxKsHlR3xKkhSnaJoDgHloNqLwJEaLzC/cnrsjxq+xIqruqJYuP3abMSNz0eh RIY8pcnT6W4HfUqBYbtt8hwyCoKVeaw8s9E/ZwBGVBw0tfFs/KNvxv2uztBXsCDcmXJAjl /SYQAJbo03EtwRvsx0OQrtpmIyz8UIsdf5YfHIuaVM2UtQ8ZHn95pMSo+n5VZwpwnFkaBT W3mLESyGzLi5sVxhuw35O5IEmKjPDHipy/ZDxZnLaveZkDPLmWMR2ghF/KLcfGEC5XQUOl rp1tAOnNFKZfWu1GSZAz3Oo9bDlrVngtvFnEKPe9gVDaNB1yIWm6kL1hzrdzIw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716730; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4dWyZArXLuwNKhH3CiBToeEwUY+mI4MenFw8MF0ZHBA=; b=JYpK0GSMLil3n6UtKftZcBhEKcmdJ1fNm1J1w7ztTpLwyI8T87WVSx51TsAbU0REBQtwWN vnsygyVjzlBPLkDw== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Sergey Organov , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Rob Herring , Tom Rix , Marek Vasut , linux-arm-kernel@lists.infradead.org Subject: [PATCH tty v1 29/74] serial: imx: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:46 +0206 Message-Id: <20230914183831.587273-30-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/imx.c | 84 ++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 13cb78340709..0fb679cdb15e 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -575,7 +575,7 @@ static void imx_uart_dma_tx_callback(void *data) unsigned long flags; u32 ucr1; =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); =20 dma_unmap_sg(sport->port.dev, sgl, sport->dma_tx_nents, DMA_TO_DEVICE); =20 @@ -600,7 +600,7 @@ static void imx_uart_dma_tx_callback(void *data) imx_uart_writel(sport, ucr4, UCR4); } =20 - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); } =20 /* called with port.lock taken and irqs off */ @@ -766,11 +766,11 @@ static irqreturn_t imx_uart_rtsint(int irq, void *dev= _id) struct imx_port *sport =3D dev_id; irqreturn_t ret; =20 - spin_lock(&sport->port.lock); + uart_port_lock(&sport->port); =20 ret =3D __imx_uart_rtsint(irq, dev_id); =20 - spin_unlock(&sport->port.lock); + uart_port_unlock(&sport->port); =20 return ret; } @@ -779,9 +779,9 @@ static irqreturn_t imx_uart_txint(int irq, void *dev_id) { struct imx_port *sport =3D dev_id; =20 - spin_lock(&sport->port.lock); + uart_port_lock(&sport->port); imx_uart_transmit_buffer(sport); - spin_unlock(&sport->port.lock); + uart_port_unlock(&sport->port); return IRQ_HANDLED; } =20 @@ -895,11 +895,11 @@ static irqreturn_t imx_uart_rxint(int irq, void *dev_= id) struct imx_port *sport =3D dev_id; irqreturn_t ret; =20 - spin_lock(&sport->port.lock); + uart_port_lock(&sport->port); =20 ret =3D __imx_uart_rxint(irq, dev_id); =20 - spin_unlock(&sport->port.lock); + uart_port_unlock(&sport->port); =20 return ret; } @@ -962,7 +962,7 @@ static irqreturn_t imx_uart_int(int irq, void *dev_id) unsigned int usr1, usr2, ucr1, ucr2, ucr3, ucr4; irqreturn_t ret =3D IRQ_NONE; =20 - spin_lock(&sport->port.lock); + uart_port_lock(&sport->port); =20 usr1 =3D imx_uart_readl(sport, USR1); usr2 =3D imx_uart_readl(sport, USR2); @@ -1032,7 +1032,7 @@ static irqreturn_t imx_uart_int(int irq, void *dev_id) ret =3D IRQ_HANDLED; } =20 - spin_unlock(&sport->port.lock); + uart_port_unlock(&sport->port); =20 return ret; } @@ -1115,7 +1115,7 @@ static void imx_uart_break_ctl(struct uart_port *port= , int break_state) unsigned long flags; u32 ucr1; =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); =20 ucr1 =3D imx_uart_readl(sport, UCR1) & ~UCR1_SNDBRK; =20 @@ -1124,7 +1124,7 @@ static void imx_uart_break_ctl(struct uart_port *port= , int break_state) =20 imx_uart_writel(sport, ucr1, UCR1); =20 - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); } =20 /* @@ -1137,9 +1137,9 @@ static void imx_uart_timeout(struct timer_list *t) unsigned long flags; =20 if (sport->port.state) { - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); imx_uart_mctrl_check(sport); - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); =20 mod_timer(&sport->timer, jiffies + MCTRL_TIMEOUT); } @@ -1169,9 +1169,9 @@ static void imx_uart_dma_rx_callback(void *data) status =3D dmaengine_tx_status(chan, sport->rx_cookie, &state); =20 if (status =3D=3D DMA_ERROR) { - spin_lock(&sport->port.lock); + uart_port_lock(&sport->port); imx_uart_clear_rx_errors(sport); - spin_unlock(&sport->port.lock); + uart_port_unlock(&sport->port); return; } =20 @@ -1200,9 +1200,9 @@ static void imx_uart_dma_rx_callback(void *data) r_bytes =3D rx_ring->head - rx_ring->tail; =20 /* If we received something, check for 0xff flood */ - spin_lock(&sport->port.lock); + uart_port_lock(&sport->port); imx_uart_check_flood(sport, imx_uart_readl(sport, USR2)); - spin_unlock(&sport->port.lock); + uart_port_unlock(&sport->port); =20 if (!(sport->port.ignore_status_mask & URXD_DUMMY_READ)) { =20 @@ -1460,7 +1460,7 @@ static int imx_uart_startup(struct uart_port *port) if (!uart_console(port) && imx_uart_dma_init(sport) =3D=3D 0) dma_is_inited =3D 1; =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); =20 /* Reset fifo's and state machines */ imx_uart_soft_reset(sport); @@ -1533,7 +1533,7 @@ static int imx_uart_startup(struct uart_port *port) =20 imx_uart_disable_loopback_rs485(sport); =20 - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); =20 return 0; } @@ -1558,21 +1558,21 @@ static void imx_uart_shutdown(struct uart_port *por= t) sport->dma_is_rxing =3D 0; } =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); imx_uart_stop_tx(port); imx_uart_stop_rx(port); imx_uart_disable_dma(sport); - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); imx_uart_dma_exit(sport); } =20 mctrl_gpio_disable_ms(sport->gpios); =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); ucr2 =3D imx_uart_readl(sport, UCR2); ucr2 &=3D ~(UCR2_TXEN | UCR2_ATEN); imx_uart_writel(sport, ucr2, UCR2); - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); =20 /* * Stop our timer. @@ -1583,7 +1583,7 @@ static void imx_uart_shutdown(struct uart_port *port) * Disable all interrupts, port and break condition. */ =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); =20 ucr1 =3D imx_uart_readl(sport, UCR1); ucr1 &=3D ~(UCR1_TRDYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_RXDMAEN | @@ -1605,7 +1605,7 @@ static void imx_uart_shutdown(struct uart_port *port) ucr4 &=3D ~UCR4_TCEN; imx_uart_writel(sport, ucr4, UCR4); =20 - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); =20 clk_disable_unprepare(sport->clk_per); clk_disable_unprepare(sport->clk_ipg); @@ -1668,7 +1668,7 @@ imx_uart_set_termios(struct uart_port *port, struct k= termios *termios, baud =3D uart_get_baud_rate(port, termios, old, 50, port->uartclk / 16); quot =3D uart_get_divisor(port, baud); =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); =20 /* * Read current UCR2 and save it for future use, then clear all the bits @@ -1796,7 +1796,7 @@ imx_uart_set_termios(struct uart_port *port, struct k= termios *termios, if (UART_ENABLE_MS(&sport->port, termios->c_cflag)) imx_uart_enable_ms(&sport->port); =20 - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); } =20 static const char *imx_uart_type(struct uart_port *port) @@ -1858,7 +1858,7 @@ static int imx_uart_poll_init(struct uart_port *port) =20 imx_uart_setup_ufcr(sport, TXTL_DEFAULT, RXTL_DEFAULT); =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); =20 /* * Be careful about the order of enabling bits here. First enable the @@ -1886,7 +1886,7 @@ static int imx_uart_poll_init(struct uart_port *port) imx_uart_writel(sport, ucr1 | UCR1_RRDYEN, UCR1); imx_uart_writel(sport, ucr2 | UCR2_ATEN, UCR2); =20 - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); =20 return 0; } @@ -2005,9 +2005,9 @@ imx_uart_console_write(struct console *co, const char= *s, unsigned int count) if (sport->port.sysrq) locked =3D 0; else if (oops_in_progress) - locked =3D spin_trylock_irqsave(&sport->port.lock, flags); + locked =3D uart_port_trylock_irqsave(&sport->port, &flags); else - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); =20 /* * First, save UCR1/2/3 and then disable interrupts @@ -2035,7 +2035,7 @@ imx_uart_console_write(struct console *co, const char= *s, unsigned int count) imx_uart_ucrs_restore(sport, &old_ucr); =20 if (locked) - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); } =20 /* @@ -2193,10 +2193,10 @@ static enum hrtimer_restart imx_trigger_start_tx(st= ruct hrtimer *t) struct imx_port *sport =3D container_of(t, struct imx_port, trigger_start= _tx); unsigned long flags; =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); if (sport->tx_state =3D=3D WAIT_AFTER_RTS) imx_uart_start_tx(&sport->port); - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); =20 return HRTIMER_NORESTART; } @@ -2206,10 +2206,10 @@ static enum hrtimer_restart imx_trigger_stop_tx(str= uct hrtimer *t) struct imx_port *sport =3D container_of(t, struct imx_port, trigger_stop_= tx); unsigned long flags; =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); if (sport->tx_state =3D=3D WAIT_AFTER_SEND) imx_uart_stop_tx(&sport->port); - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); =20 return HRTIMER_NORESTART; } @@ -2482,9 +2482,9 @@ static void imx_uart_restore_context(struct imx_port = *sport) { unsigned long flags; =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); if (!sport->context_saved) { - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); return; } =20 @@ -2499,7 +2499,7 @@ static void imx_uart_restore_context(struct imx_port = *sport) imx_uart_writel(sport, sport->saved_reg[2], UCR3); imx_uart_writel(sport, sport->saved_reg[3], UCR4); sport->context_saved =3D false; - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); } =20 static void imx_uart_save_context(struct imx_port *sport) @@ -2507,7 +2507,7 @@ static void imx_uart_save_context(struct imx_port *sp= ort) unsigned long flags; =20 /* Save necessary regs */ - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); sport->saved_reg[0] =3D imx_uart_readl(sport, UCR1); sport->saved_reg[1] =3D imx_uart_readl(sport, UCR2); sport->saved_reg[2] =3D imx_uart_readl(sport, UCR3); @@ -2519,7 +2519,7 @@ static void imx_uart_save_context(struct imx_port *sp= ort) sport->saved_reg[8] =3D imx_uart_readl(sport, UBMR); sport->saved_reg[9] =3D imx_uart_readl(sport, IMX21_UTS); sport->context_saved =3D true; - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); } =20 static void imx_uart_enable_wakeup(struct imx_port *sport, bool on) --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7A97EEAA5D for ; Thu, 14 Sep 2023 18:39:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241967AbjINSjz (ORCPT ); Thu, 14 Sep 2023 14:39:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241763AbjINSi7 (ORCPT ); Thu, 14 Sep 2023 14:38:59 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F209212E; Thu, 14 Sep 2023 11:38:52 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7MhPKCrB1dOunNZkyVt5zeAFdISPvOBlSvfyFnl5/7k=; b=YLqoO2CmXARRUlFLHeB2M6ukd+zU/nFFgFSlVGTgtOrax7oXV7pPL8cSmw/pZDAElhtrfi tg+qdkkRjdfFcje2e6txYb3BMdaIg9i7e0Mh+YxmElDly4kDa3NAjK/0UG6MgVfELywhT2 V8orxiw3OetQDrZZDTQXxy5+hqdFeJ1HEll+tEKleM5gcgTzDHcNQToDDydnseVBtkUdYG gytRSgchp+eOFJON+5pvNC6JQu0C+5Da8EUAAMJ6Xa4aUQIiDLgBOmaNvJOGFL+X0eB7l+ ajIq4J62gfzDnlJBiRb8IMfsMmRoi6quQ96kG6szLXiQ26KdUa+1MgJWGskI1w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7MhPKCrB1dOunNZkyVt5zeAFdISPvOBlSvfyFnl5/7k=; b=3ww4vlg4w6dOUA/vLaMXWEJhpTPQP9RtHU84xi6hn3BhuNTqmvAXu3TlTrY1SAXMKgY3m8 pzcqy8Uf8lJvCrBg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Thierry Reding , Tobias Klauser Subject: [PATCH tty v1 30/74] serial: ip22zilog: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:47 +0206 Message-Id: <20230914183831.587273-31-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/ip22zilog.c | 36 +++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/tty/serial/ip22zilog.c b/drivers/tty/serial/ip22zilog.c index 845ff706bc59..320b29cd4683 100644 --- a/drivers/tty/serial/ip22zilog.c +++ b/drivers/tty/serial/ip22zilog.c @@ -432,7 +432,7 @@ static irqreturn_t ip22zilog_interrupt(int irq, void *d= ev_id) unsigned char r3; bool push =3D false; =20 - spin_lock(&up->port.lock); + uart_port_lock(&up->port); r3 =3D read_zsreg(channel, R3); =20 /* Channel A */ @@ -448,7 +448,7 @@ static irqreturn_t ip22zilog_interrupt(int irq, void *d= ev_id) if (r3 & CHATxIP) ip22zilog_transmit_chars(up, channel); } - spin_unlock(&up->port.lock); + uart_port_unlock(&up->port); =20 if (push) tty_flip_buffer_push(&up->port.state->port); @@ -458,7 +458,7 @@ static irqreturn_t ip22zilog_interrupt(int irq, void *d= ev_id) channel =3D ZILOG_CHANNEL_FROM_PORT(&up->port); push =3D false; =20 - spin_lock(&up->port.lock); + uart_port_lock(&up->port); if (r3 & (CHBEXT | CHBTxIP | CHBRxIP)) { writeb(RES_H_IUS, &channel->control); ZSDELAY(); @@ -471,7 +471,7 @@ static irqreturn_t ip22zilog_interrupt(int irq, void *d= ev_id) if (r3 & CHBTxIP) ip22zilog_transmit_chars(up, channel); } - spin_unlock(&up->port.lock); + uart_port_unlock(&up->port); =20 if (push) tty_flip_buffer_push(&up->port.state->port); @@ -504,11 +504,11 @@ static unsigned int ip22zilog_tx_empty(struct uart_po= rt *port) unsigned char status; unsigned int ret; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 status =3D ip22zilog_read_channel_status(port); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 if (status & Tx_BUF_EMP) ret =3D TIOCSER_TEMT; @@ -664,7 +664,7 @@ static void ip22zilog_break_ctl(struct uart_port *port,= int break_state) else clear_bits |=3D SND_BRK; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 new_reg =3D (up->curregs[R5] | set_bits) & ~clear_bits; if (new_reg !=3D up->curregs[R5]) { @@ -674,7 +674,7 @@ static void ip22zilog_break_ctl(struct uart_port *port,= int break_state) write_zsreg(channel, R5, up->curregs[R5]); } =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void __ip22zilog_reset(struct uart_ip22zilog_port *up) @@ -735,9 +735,9 @@ static int ip22zilog_startup(struct uart_port *port) if (ZS_IS_CONS(up)) return 0; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); __ip22zilog_startup(up); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); return 0; } =20 @@ -775,7 +775,7 @@ static void ip22zilog_shutdown(struct uart_port *port) if (ZS_IS_CONS(up)) return; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 channel =3D ZILOG_CHANNEL_FROM_PORT(port); =20 @@ -788,7 +788,7 @@ static void ip22zilog_shutdown(struct uart_port *port) up->curregs[R5] &=3D ~SND_BRK; ip22zilog_maybe_update_regs(up, channel); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /* Shared by TTY driver and serial console setup. The port lock is held @@ -880,7 +880,7 @@ ip22zilog_set_termios(struct uart_port *port, struct kt= ermios *termios, =20 baud =3D uart_get_baud_rate(port, termios, old, 1200, 76800); =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 brg =3D BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR); =20 @@ -894,7 +894,7 @@ ip22zilog_set_termios(struct uart_port *port, struct kt= ermios *termios, ip22zilog_maybe_update_regs(up, ZILOG_CHANNEL_FROM_PORT(port)); uart_update_timeout(port, termios->c_cflag, baud); =20 - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 static const char *ip22zilog_type(struct uart_port *port) @@ -1016,10 +1016,10 @@ ip22zilog_console_write(struct console *con, const = char *s, unsigned int count) struct uart_ip22zilog_port *up =3D &ip22zilog_port_table[con->index]; unsigned long flags; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); uart_console_write(&up->port, s, count, ip22zilog_put_char); udelay(2); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 static int __init ip22zilog_console_setup(struct console *con, char *optio= ns) @@ -1034,13 +1034,13 @@ static int __init ip22zilog_console_setup(struct co= nsole *con, char *options) =20 printk(KERN_INFO "Console: ttyS%d (IP22-Zilog)\n", con->index); =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 up->curregs[R15] |=3D BRKIE; =20 __ip22zilog_startup(up); =20 - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =20 if (options) uart_parse_options(options, &baud, &parity, &bits, &flow); --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3ACAEEAA62 for ; Thu, 14 Sep 2023 18:39:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241823AbjINSj7 (ORCPT ); Thu, 14 Sep 2023 14:39:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241660AbjINSi7 (ORCPT ); Thu, 14 Sep 2023 14:38:59 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8A9A2134; Thu, 14 Sep 2023 11:38:52 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T/Nah8LG2arspIXC5ZdMzJ+r6t3A3nzbfwJRMCSZSCk=; b=oxmPK29NQ4j8pd2D01o8mg+K0yOiMZnw2YnzETzatx1/wERmCu0FosstZcHkoJEyLFX0EF NBnn4iN/bJRAYchCphv/ylN5T85we5IOkHknSeQb4eK/Eyk6W6q7qqYGuh9lJVEZoUDcn9 gf3F/rEY2Nbj6Hw1STCVl4kS7laZ5KCHpe3XUOlZdNyHPXtxhhOXiYBhimgDZESjHO3Vc6 ZuKGsiuxPnZoU1TGmDqDiZZY5fQqK8joUj0zmdRPnTUnQvnJbQKk69LyIdJHMtVlIQCifm NJHlIqap/7M6DJNuRcbx7VLrLka0K47uqTPGEuUtbT58rBVVZb1bZy05hx2EBA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T/Nah8LG2arspIXC5ZdMzJ+r6t3A3nzbfwJRMCSZSCk=; b=Ou4JXvI5/rF2X+xvNjTB7VuG7W/1UXFOV3B7seNGK+VIj2IC6C+6QxfRzjKVN/kAzeVGGR yu4a6caUgwydhoAg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH tty v1 31/74] serial: jsm: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:48 +0206 Message-Id: <20230914183831.587273-32-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/jsm/jsm_neo.c | 4 ++-- drivers/tty/serial/jsm/jsm_tty.c | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/jsm/jsm_neo.c b/drivers/tty/serial/jsm/jsm_= neo.c index 0c78f66276cd..2bd640428970 100644 --- a/drivers/tty/serial/jsm/jsm_neo.c +++ b/drivers/tty/serial/jsm/jsm_neo.c @@ -816,9 +816,9 @@ static void neo_parse_isr(struct jsm_board *brd, u32 po= rt) /* Parse any modem signal changes */ jsm_dbg(INTR, &ch->ch_bd->pci_dev, "MOD_STAT: sending to parse_modem_sigs\n"); - spin_lock_irqsave(&ch->uart_port.lock, lock_flags); + uart_port_lock_irqsave(&ch->uart_port, &lock_flags); neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr)); - spin_unlock_irqrestore(&ch->uart_port.lock, lock_flags); + uart_port_unlock_irqrestore(&ch->uart_port, lock_flags); } } =20 diff --git a/drivers/tty/serial/jsm/jsm_tty.c b/drivers/tty/serial/jsm/jsm_= tty.c index 222afc270c88..ce0fef7e2c66 100644 --- a/drivers/tty/serial/jsm/jsm_tty.c +++ b/drivers/tty/serial/jsm/jsm_tty.c @@ -152,14 +152,14 @@ static void jsm_tty_send_xchar(struct uart_port *port= , char ch) container_of(port, struct jsm_channel, uart_port); struct ktermios *termios; =20 - spin_lock_irqsave(&port->lock, lock_flags); + uart_port_lock_irqsave(port, &lock_flags); termios =3D &port->state->port.tty->termios; if (ch =3D=3D termios->c_cc[VSTART]) channel->ch_bd->bd_ops->send_start_character(channel); =20 if (ch =3D=3D termios->c_cc[VSTOP]) channel->ch_bd->bd_ops->send_stop_character(channel); - spin_unlock_irqrestore(&port->lock, lock_flags); + uart_port_unlock_irqrestore(port, lock_flags); } =20 static void jsm_tty_stop_rx(struct uart_port *port) @@ -176,13 +176,13 @@ static void jsm_tty_break(struct uart_port *port, int= break_state) struct jsm_channel *channel =3D container_of(port, struct jsm_channel, uart_port); =20 - spin_lock_irqsave(&port->lock, lock_flags); + uart_port_lock_irqsave(port, &lock_flags); if (break_state =3D=3D -1) channel->ch_bd->bd_ops->send_break(channel); else channel->ch_bd->bd_ops->clear_break(channel); =20 - spin_unlock_irqrestore(&port->lock, lock_flags); + uart_port_unlock_irqrestore(port, lock_flags); } =20 static int jsm_tty_open(struct uart_port *port) @@ -241,7 +241,7 @@ static int jsm_tty_open(struct uart_port *port) channel->ch_cached_lsr =3D 0; channel->ch_stops_sent =3D 0; =20 - spin_lock_irqsave(&port->lock, lock_flags); + uart_port_lock_irqsave(port, &lock_flags); termios =3D &port->state->port.tty->termios; channel->ch_c_cflag =3D termios->c_cflag; channel->ch_c_iflag =3D termios->c_iflag; @@ -261,7 +261,7 @@ static int jsm_tty_open(struct uart_port *port) jsm_carrier(channel); =20 channel->ch_open_count++; - spin_unlock_irqrestore(&port->lock, lock_flags); + uart_port_unlock_irqrestore(port, lock_flags); =20 jsm_dbg(OPEN, &channel->ch_bd->pci_dev, "finish\n"); return 0; @@ -307,7 +307,7 @@ static void jsm_tty_set_termios(struct uart_port *port, struct jsm_channel *channel =3D container_of(port, struct jsm_channel, uart_port); =20 - spin_lock_irqsave(&port->lock, lock_flags); + uart_port_lock_irqsave(port, &lock_flags); channel->ch_c_cflag =3D termios->c_cflag; channel->ch_c_iflag =3D termios->c_iflag; channel->ch_c_oflag =3D termios->c_oflag; @@ -317,7 +317,7 @@ static void jsm_tty_set_termios(struct uart_port *port, =20 channel->ch_bd->bd_ops->param(channel); jsm_carrier(channel); - spin_unlock_irqrestore(&port->lock, lock_flags); + uart_port_unlock_irqrestore(port, lock_flags); } =20 static const char *jsm_tty_type(struct uart_port *port) --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 611D8EEAA5D for ; Thu, 14 Sep 2023 18:40:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242018AbjINSkJ (ORCPT ); Thu, 14 Sep 2023 14:40:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241778AbjINSi7 (ORCPT ); Thu, 14 Sep 2023 14:38:59 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 148E8213A; Thu, 14 Sep 2023 11:38:53 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UlpF/H9lKMDrxmXTuNUKsAvkYnpqtMAZIidKoYfk2m8=; b=OvnQvp6FrSEUwDayVfCSyaTaDBzuc0qDHdbES+H9OAPO6Ha87bRKvDnKy+aUS4pdZFLLmB jDxwD/L3qDChRCkKs0q+jzzmJmJZiwqpSy8A1vQM9uRhSkNw2idhoRuvvgsJxrK+wZx4QG XqxrNYbAK6u7sE1Tzcyz/LRQvnyD2tzuxG6rvJL6EQObHJpanuV55slsCsY84hl6Zyio/3 pQD3+PfXQ3qkNC9MvbiF4uH2PApwczoZNDT9+YaqQDJfAN6RMTd8Q0wfobK08utaA6SImc QzGgZlJy1nebH8t5hloy88cBPuR+IEjxhUWo45LfVr3WtSj7eG3UDcwTb/G12w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UlpF/H9lKMDrxmXTuNUKsAvkYnpqtMAZIidKoYfk2m8=; b=NkoS64+YSQlVmh/kcYnHAvKRouOJW5bYLm3LDjq5+uZbRS0+LZRledqxXPhj4J2guP/ZOw dmliYWM9jDfA5hBA== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Karol Gugala , Mateusz Holenko , Gabriel Somlo , Joel Stanley Subject: [PATCH tty v1 32/74] serial: liteuart: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:49 +0206 Message-Id: <20230914183831.587273-33-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner Acked-by: Gabriel Somlo --- drivers/tty/serial/liteuart.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/liteuart.c b/drivers/tty/serial/liteuart.c index d881cdd2a58f..a25ab1efe38f 100644 --- a/drivers/tty/serial/liteuart.c +++ b/drivers/tty/serial/liteuart.c @@ -139,13 +139,13 @@ static irqreturn_t liteuart_interrupt(int irq, void *= data) * if polling, the context would be "in_serving_softirq", so use * irq[save|restore] spin_lock variants to cover all possibilities */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); isr =3D litex_read8(port->membase + OFF_EV_PENDING) & uart->irq_reg; if (isr & EV_RX) liteuart_rx_chars(port); if (isr & EV_TX) liteuart_tx_chars(port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return IRQ_RETVAL(isr); } @@ -195,10 +195,10 @@ static int liteuart_startup(struct uart_port *port) } } =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); /* only enabling rx irqs during startup */ liteuart_update_irq_reg(port, true, EV_RX); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 if (!port->irq) { timer_setup(&uart->timer, liteuart_timer, 0); @@ -213,9 +213,9 @@ static void liteuart_shutdown(struct uart_port *port) struct liteuart_port *uart =3D to_liteuart_port(port); unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); liteuart_update_irq_reg(port, false, EV_RX | EV_TX); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 if (port->irq) free_irq(port->irq, port); @@ -229,13 +229,13 @@ static void liteuart_set_termios(struct uart_port *po= rt, struct ktermios *new, unsigned int baud; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* update baudrate */ baud =3D uart_get_baud_rate(port, new, old, 0, 460800); uart_update_timeout(port, new->c_cflag, baud); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *liteuart_type(struct uart_port *port) @@ -382,9 +382,9 @@ static void liteuart_console_write(struct console *co, = const char *s, uart =3D (struct liteuart_port *)xa_load(&liteuart_array, co->index); port =3D &uart->port; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); uart_console_write(port, s, count, liteuart_putchar); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static int liteuart_console_setup(struct console *co, char *options) --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03564EEAA64 for ; Thu, 14 Sep 2023 18:40:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241833AbjINSkP (ORCPT ); Thu, 14 Sep 2023 14:40:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241785AbjINSi7 (ORCPT ); Thu, 14 Sep 2023 14:38:59 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78948213D; Thu, 14 Sep 2023 11:38:53 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716732; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6sKB+PLTgb55D62jcsgEwGhi+y+KWY1sggt5DCPfvKw=; b=CAomZRAW4ioAoHdhdXE1bVpyrGKaTnvn8Cq29md8PRBiDOnSBUbDSiMq137oB3HKlxwNEf R8HRvdEP5f14bu6O2Rr5/iz88OJF6VlrhJOlwQLCKLxm86UMAktCYEZ7bMUdHclHpVcZRs 2Qnrpu4EipFdUOiXbQdiJazGtYSUbNtN5CSQwHRnnFwq+0v1r5Uzl1fkRNB9eQzve1ZQmf 0tt4KFBW2Cj6a+XeqF+AQvrQWlwjnwqsjvlq4BRWMB//MDfRrDUYKiQlfW9Xb9IFwQkyVb qJZaZ3tQBAkXdIf3q2qdS75F933SGK3oPvdZexLcDwbHhA6yE8pDCVXMQAZIkg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716732; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6sKB+PLTgb55D62jcsgEwGhi+y+KWY1sggt5DCPfvKw=; b=omvzL+BfuAFX72SI72UqLTsm+PZORhrEQrnn9HysvZwhKfsA5pjsOE1v/su7/IqFmFA67i mfMeFlZPH2SMzoCA== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Vladimir Zapolskiy , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , linux-arm-kernel@lists.infradead.org Subject: [PATCH tty v1 33/74] serial: lpc32xx_hs: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:50 +0206 Message-Id: <20230914183831.587273-34-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/lpc32xx_hs.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/tty/serial/lpc32xx_hs.c b/drivers/tty/serial/lpc32xx_h= s.c index b38fe4728c26..5149a947b7fe 100644 --- a/drivers/tty/serial/lpc32xx_hs.c +++ b/drivers/tty/serial/lpc32xx_hs.c @@ -140,15 +140,15 @@ static void lpc32xx_hsuart_console_write(struct conso= le *co, const char *s, if (up->port.sysrq) locked =3D 0; else if (oops_in_progress) - locked =3D spin_trylock(&up->port.lock); + locked =3D uart_port_trylock(&up->port); else - spin_lock(&up->port.lock); + uart_port_lock(&up->port); =20 uart_console_write(&up->port, s, count, lpc32xx_hsuart_console_putchar); wait_for_xmit_empty(&up->port); =20 if (locked) - spin_unlock(&up->port.lock); + uart_port_unlock(&up->port); local_irq_restore(flags); } =20 @@ -298,7 +298,7 @@ static irqreturn_t serial_lpc32xx_interrupt(int irq, vo= id *dev_id) struct tty_port *tport =3D &port->state->port; u32 status; =20 - spin_lock(&port->lock); + uart_port_lock(port); =20 /* Read UART status and clear latched interrupts */ status =3D readl(LPC32XX_HSUART_IIR(port->membase)); @@ -333,7 +333,7 @@ static irqreturn_t serial_lpc32xx_interrupt(int irq, vo= id *dev_id) __serial_lpc32xx_tx(port); } =20 - spin_unlock(&port->lock); + uart_port_unlock(port); =20 return IRQ_HANDLED; } @@ -404,14 +404,14 @@ static void serial_lpc32xx_break_ctl(struct uart_port= *port, unsigned long flags; u32 tmp; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); tmp =3D readl(LPC32XX_HSUART_CTRL(port->membase)); if (break_state !=3D 0) tmp |=3D LPC32XX_HSU_BREAK; else tmp &=3D ~LPC32XX_HSU_BREAK; writel(tmp, LPC32XX_HSUART_CTRL(port->membase)); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /* port->lock is not held. */ @@ -421,7 +421,7 @@ static int serial_lpc32xx_startup(struct uart_port *por= t) unsigned long flags; u32 tmp; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 __serial_uart_flush(port); =20 @@ -441,7 +441,7 @@ static int serial_lpc32xx_startup(struct uart_port *por= t) =20 lpc32xx_loopback_set(port->mapbase, 0); /* get out of loopback mode */ =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 retval =3D request_irq(port->irq, serial_lpc32xx_interrupt, 0, MODNAME, port); @@ -458,7 +458,7 @@ static void serial_lpc32xx_shutdown(struct uart_port *p= ort) u32 tmp; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 tmp =3D LPC32XX_HSU_TX_TL8B | LPC32XX_HSU_RX_TL32B | LPC32XX_HSU_OFFSET(20) | LPC32XX_HSU_TMO_INACT_4B; @@ -466,7 +466,7 @@ static void serial_lpc32xx_shutdown(struct uart_port *p= ort) =20 lpc32xx_loopback_set(port->mapbase, 1); /* go to loopback mode */ =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 free_irq(port->irq, port); } @@ -491,7 +491,7 @@ static void serial_lpc32xx_set_termios(struct uart_port= *port, =20 quot =3D __serial_get_clock_div(port->uartclk, baud); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Ignore characters? */ tmp =3D readl(LPC32XX_HSUART_CTRL(port->membase)); @@ -505,7 +505,7 @@ static void serial_lpc32xx_set_termios(struct uart_port= *port, =20 uart_update_timeout(port, termios->c_cflag, baud); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 /* Don't rewrite B0 */ if (tty_termios_baud_rate(termios)) --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A54AFEEAA62 for ; Thu, 14 Sep 2023 18:40:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242023AbjINSkN (ORCPT ); Thu, 14 Sep 2023 14:40:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241789AbjINSi7 (ORCPT ); Thu, 14 Sep 2023 14:38:59 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D780D2109; Thu, 14 Sep 2023 11:38:53 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716732; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B/YEVP6mWwFo6/xhfhUTWYtdghju7JIkgzq7NY/TOjo=; b=0HDJH4mxjCm5HX8gWyLjpF6KeeBvYaaN9tDWvnW/Td7Yvq3ytL5x42DJcRx0Y3de7ueaod 87Eeu/kJ8jzEzJRQ8D3fpXGIz1xPrQr15ZVGFZxSgw/G/abw68XswubNUM/aSoimMwisDQ HbCWUM9OSAFllmMopxC5SzBqN0E6R57WC0fmxKib3z76SMx1H/xp2r8P/HgmrI3aSsXyxe Z1HCcW9uGLSaTMjd2ByXAb927zjGJDJFf4wrxXH6bTJ1l0+pJzrgKMw2aGVMqCJOOMqrfs Y/oUqNG7RbkeE+tnFDQkunt8PJjYDAXBmGZTgEa+WKxrTnYRF84EmJLDGU26PA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716732; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B/YEVP6mWwFo6/xhfhUTWYtdghju7JIkgzq7NY/TOjo=; b=THdCdqmkDOMQ6RV/8UcNabNFfW7AqzyKAXtxCI78QFQRSlvdfobIL3mXavhPEkaw7SKFQQ Q0MfUPqE9lVT2wCg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Jacky Huang , Shan-Chun Hung , linux-arm-kernel@lists.infradead.org Subject: [PATCH tty v1 34/74] serial: ma35d1: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:51 +0206 Message-Id: <20230914183831.587273-35-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/ma35d1_serial.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/tty/serial/ma35d1_serial.c b/drivers/tty/serial/ma35d1= _serial.c index 465b1def9e11..6fac924f7c12 100644 --- a/drivers/tty/serial/ma35d1_serial.c +++ b/drivers/tty/serial/ma35d1_serial.c @@ -269,16 +269,16 @@ static void receive_chars(struct uart_ma35d1_port *up) if (uart_handle_sysrq_char(&up->port, ch)) continue; =20 - spin_lock(&up->port.lock); + uart_port_lock(&up->port); uart_insert_char(&up->port, fsr, MA35_FSR_RX_OVER_IF, ch, flag); - spin_unlock(&up->port.lock); + uart_port_unlock(&up->port); =20 fsr =3D serial_in(up, MA35_FSR_REG); } while (!(fsr & MA35_FSR_RX_EMPTY) && (max_count-- > 0)); =20 - spin_lock(&up->port.lock); + uart_port_lock(&up->port); tty_flip_buffer_push(&up->port.state->port); - spin_unlock(&up->port.lock); + uart_port_unlock(&up->port); } =20 static irqreturn_t ma35d1serial_interrupt(int irq, void *dev_id) @@ -364,14 +364,14 @@ static void ma35d1serial_break_ctl(struct uart_port *= port, int break_state) unsigned long flags; u32 lcr; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); lcr =3D serial_in(up, MA35_LCR_REG); if (break_state !=3D 0) lcr |=3D MA35_LCR_BREAK; else lcr &=3D ~MA35_LCR_BREAK; serial_out(up, MA35_LCR_REG, lcr); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 static int ma35d1serial_startup(struct uart_port *port) @@ -441,7 +441,7 @@ static void ma35d1serial_set_termios(struct uart_port *= port, * Ok, we're now changing the port state. Do it with * interrupts disabled. */ - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 up->port.read_status_mask =3D MA35_FSR_RX_OVER_IF; if (termios->c_iflag & INPCK) @@ -475,7 +475,7 @@ static void ma35d1serial_set_termios(struct uart_port *= port, =20 serial_out(up, MA35_LCR_REG, lcr); =20 - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 static const char *ma35d1serial_type(struct uart_port *port) @@ -560,9 +560,9 @@ static void ma35d1serial_console_write(struct console *= co, const char *s, u32 co if (up->port.sysrq) locked =3D 0; else if (oops_in_progress) - locked =3D spin_trylock_irqsave(&up->port.lock, flags); + locked =3D uart_port_trylock_irqsave(&up->port, &flags); else - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 /* * First save the IER then disable the interrupts @@ -576,7 +576,7 @@ static void ma35d1serial_console_write(struct console *= co, const char *s, u32 co serial_out(up, MA35_IER_REG, ier); =20 if (locked) - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 static int __init ma35d1serial_console_setup(struct console *co, char *opt= ions) --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5DA7EEAA64 for ; Thu, 14 Sep 2023 18:40:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242035AbjINSkS (ORCPT ); Thu, 14 Sep 2023 14:40:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241724AbjINSi7 (ORCPT ); Thu, 14 Sep 2023 14:38:59 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E8532682; Thu, 14 Sep 2023 11:38:54 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716732; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9ljKUwev2UkcA8WCxS5wHB4jucft9QaueReQAnJLBgA=; b=4LBDpTPLhp3Mhhl4pVyJop8/w8YO125vIGMHFDGAc829iCRLFSl6X0mnCu86Xp0DKlykZQ MXfUoGbOklo8kZ7vno2kF6WSkEIFFIvGBTcq82frPQ1vcXYDd6OP7vg6a7cB6OoKGCAkfw fKDP6Ajv8OLwdQ319atwJb34QtjDpof9v9S7t56NLpZyAZyZJnQuNrxE05l8/g1GJoesLm lwGEKRQpPcSrqp5lU/Qczo2PqcPpFrhhih2JjfhMpnvo2acScgXq2FMPoFFKDsSCyfuCZw ocpglMKMTGaf/tHVHULGAUC4UImI8D22JCJD7t3sASdeP7gHPu23CWH7OKLk0g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716732; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9ljKUwev2UkcA8WCxS5wHB4jucft9QaueReQAnJLBgA=; b=DU48W/75T7f5tMYhQEpupILmuQfJztsBNWC4FVQumidZDa1Kg7GZ2XZ8GARLh976Uuhd0Q AFsq08hjfv2Li5Cg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, "Maciej W. Rozycki" , Richard GENOUD , Thierry Reding Subject: [PATCH tty v1 35/74] serial: mcf: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:52 +0206 Message-Id: <20230914183831.587273-36-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/mcf.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/mcf.c b/drivers/tty/serial/mcf.c index 1666ce012e5e..91b15243f6c6 100644 --- a/drivers/tty/serial/mcf.c +++ b/drivers/tty/serial/mcf.c @@ -135,12 +135,12 @@ static void mcf_break_ctl(struct uart_port *port, int= break_state) { unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); if (break_state =3D=3D -1) writeb(MCFUART_UCR_CMDBREAKSTART, port->membase + MCFUART_UCR); else writeb(MCFUART_UCR_CMDBREAKSTOP, port->membase + MCFUART_UCR); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /*************************************************************************= ***/ @@ -150,7 +150,7 @@ static int mcf_startup(struct uart_port *port) struct mcf_uart *pp =3D container_of(port, struct mcf_uart, port); unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Reset UART, get it into known state... */ writeb(MCFUART_UCR_CMDRESETRX, port->membase + MCFUART_UCR); @@ -164,7 +164,7 @@ static int mcf_startup(struct uart_port *port) pp->imr =3D MCFUART_UIR_RXREADY; writeb(pp->imr, port->membase + MCFUART_UIMR); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return 0; } @@ -176,7 +176,7 @@ static void mcf_shutdown(struct uart_port *port) struct mcf_uart *pp =3D container_of(port, struct mcf_uart, port); unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Disable all interrupts now */ pp->imr =3D 0; @@ -186,7 +186,7 @@ static void mcf_shutdown(struct uart_port *port) writeb(MCFUART_UCR_CMDRESETRX, port->membase + MCFUART_UCR); writeb(MCFUART_UCR_CMDRESETTX, port->membase + MCFUART_UCR); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /*************************************************************************= ***/ @@ -252,7 +252,7 @@ static void mcf_set_termios(struct uart_port *port, str= uct ktermios *termios, mr2 |=3D MCFUART_MR2_TXCTS; } =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); if (port->rs485.flags & SER_RS485_ENABLED) { dev_dbg(port->dev, "Setting UART to RS485\n"); mr2 |=3D MCFUART_MR2_TXRTS; @@ -273,7 +273,7 @@ static void mcf_set_termios(struct uart_port *port, str= uct ktermios *termios, port->membase + MCFUART_UCSR); writeb(MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE, port->membase + MCFUART_UCR); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /*************************************************************************= ***/ @@ -350,7 +350,7 @@ static irqreturn_t mcf_interrupt(int irq, void *data) =20 isr =3D readb(port->membase + MCFUART_UISR) & pp->imr; =20 - spin_lock(&port->lock); + uart_port_lock(port); if (isr & MCFUART_UIR_RXREADY) { mcf_rx_chars(pp); ret =3D IRQ_HANDLED; @@ -359,7 +359,7 @@ static irqreturn_t mcf_interrupt(int irq, void *data) mcf_tx_chars(pp); ret =3D IRQ_HANDLED; } - spin_unlock(&port->lock); + uart_port_unlock(port); =20 return ret; } --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69B96EEAA62 for ; Thu, 14 Sep 2023 18:40:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242041AbjINSkX (ORCPT ); Thu, 14 Sep 2023 14:40:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241740AbjINSjA (ORCPT ); Thu, 14 Sep 2023 14:39:00 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 997702683; Thu, 14 Sep 2023 11:38:54 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716733; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xu+MA3nvAGpQibJHqwBXfavhwazXxpOBvYT7SUXxurg=; b=VNedMCHdngMxNzKkI4Tk3e/Scyd10wBR9UsJz4Nv9l3mO40AvsIaYB5UO8o6dA/4/jwD5J iOCuPIyDf16h72BERJcVXy0VZ8a6A3zmwzjMPFpuLjj9OyfkzzeRQXOKaPMUpDV2fULhy8 cGnJl0BWhMxtQC9bl5QNvRo0WWzmM/QKhUAxbsaRPX/uxVCjwzMn6eCyLOAR9nnTZBLmGF VQD1UySg+AtbVJpq2cc+vjZB4BINNtIEFjbBtzLV5e4b7IH+k1u/ONNntwWMv8CEHhCQ7w s+awbpMjvgek91Sh+gVYrmY3I8Bui727eu0LEcRwRdJMrrXD97PtfYhQv0hLOQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716733; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xu+MA3nvAGpQibJHqwBXfavhwazXxpOBvYT7SUXxurg=; b=BDeS7WcDlvoxrWV5nRJyybaIh6Ix6LKXdIjVcLazyjC0Pcx+K4Imt04CGw4/ALxm62UPmZ PGHFzBpNpEyz6ECQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH tty v1 36/74] serial: men_z135_uart: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:53 +0206 Message-Id: <20230914183831.587273-37-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/men_z135_uart.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/men_z135_uart.c b/drivers/tty/serial/men_z1= 35_uart.c index d2502aaa3e8c..8048fa542fc4 100644 --- a/drivers/tty/serial/men_z135_uart.c +++ b/drivers/tty/serial/men_z135_uart.c @@ -392,7 +392,7 @@ static irqreturn_t men_z135_intr(int irq, void *data) if (!irq_id) goto out; =20 - spin_lock(&port->lock); + uart_port_lock(port); /* It's save to write to IIR[7:6] RXC[9:8] */ iowrite8(irq_id, port->membase + MEN_Z135_STAT_REG); =20 @@ -418,7 +418,7 @@ static irqreturn_t men_z135_intr(int irq, void *data) handled =3D true; } =20 - spin_unlock(&port->lock); + uart_port_unlock(port); out: return IRQ_RETVAL(handled); } @@ -708,7 +708,7 @@ static void men_z135_set_termios(struct uart_port *port, =20 baud =3D uart_get_baud_rate(port, termios, old, 0, uart_freq / 16); =20 - spin_lock_irq(&port->lock); + uart_port_lock_irq(port); if (tty_termios_baud_rate(termios)) tty_termios_encode_baud_rate(termios, baud, baud); =20 @@ -716,7 +716,7 @@ static void men_z135_set_termios(struct uart_port *port, iowrite32(bd_reg, port->membase + MEN_Z135_BAUD_REG); =20 uart_update_timeout(port, termios->c_cflag, baud); - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); } =20 static const char *men_z135_type(struct uart_port *port) --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09E2BEEAA5D for ; Thu, 14 Sep 2023 18:40:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242043AbjINSk0 (ORCPT ); Thu, 14 Sep 2023 14:40:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241811AbjINSjA (ORCPT ); Thu, 14 Sep 2023 14:39:00 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FC462121; Thu, 14 Sep 2023 11:38:55 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716733; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZKwcjqONapPvBsW0aTkz2Kp7R2CB0xqS9WOHGi5RTLM=; b=Kt9ejYSj4fzpuLKrmdHCO4TSEiJ/k3jgwyUpWk1q1izigsfhXbJNdawsDjEuyb0g7xiudP 5P2RvYHaXbxxKfeCu924OoVPUzrXS44G8idWC5xpML9kPCUqsyD5UGiR+UZG6NFm3vWCoa QmjX2nGB1M0UAQQsaVw27R0+8twOsyJI6MeWECfscxDXNzdugeuSaPjZj1LX0yQvjQJ13Q XD1YUOpaGjNWhxrMvqyEVmDAjvLlqXYSfJ5PLuuqBbmc2K/tvD+VhHf8aKGHV1PwPodQ57 V7JMFdjuZlNdwD2GbKI3Q5POclPeJfHlcOAEoP9k7ru7nC2A8x9Vxxs1X9rQrA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716733; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZKwcjqONapPvBsW0aTkz2Kp7R2CB0xqS9WOHGi5RTLM=; b=80ViDgQop2oPHtXmBSVsvdlF1xYlz0YuXbv4orRbO/DnNLH3DLm6EiwR/cHzJPMivGWEia MWrVuUucmyr3kEBw== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Dmitry Rokosov , Lucas Tanure , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org Subject: [PATCH tty v1 37/74] serial: meson: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:54 +0206 Message-Id: <20230914183831.587273-38-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner Acked-by: Neil Armstrong --- drivers/tty/serial/meson_uart.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uar= t.c index 790d910dafa5..45cc23e9e399 100644 --- a/drivers/tty/serial/meson_uart.c +++ b/drivers/tty/serial/meson_uart.c @@ -129,14 +129,14 @@ static void meson_uart_shutdown(struct uart_port *por= t) =20 free_irq(port->irq, port); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 val =3D readl(port->membase + AML_UART_CONTROL); val &=3D ~AML_UART_RX_EN; val &=3D ~(AML_UART_RX_INT_EN | AML_UART_TX_INT_EN); writel(val, port->membase + AML_UART_CONTROL); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void meson_uart_start_tx(struct uart_port *port) @@ -238,7 +238,7 @@ static irqreturn_t meson_uart_interrupt(int irq, void *= dev_id) { struct uart_port *port =3D (struct uart_port *)dev_id; =20 - spin_lock(&port->lock); + uart_port_lock(port); =20 if (!(readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY)) meson_receive_chars(port); @@ -248,7 +248,7 @@ static irqreturn_t meson_uart_interrupt(int irq, void *= dev_id) meson_uart_start_tx(port); } =20 - spin_unlock(&port->lock); + uart_port_unlock(port); =20 return IRQ_HANDLED; } @@ -284,7 +284,7 @@ static int meson_uart_startup(struct uart_port *port) u32 val; int ret =3D 0; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 val =3D readl(port->membase + AML_UART_CONTROL); val |=3D AML_UART_CLEAR_ERR; @@ -301,7 +301,7 @@ static int meson_uart_startup(struct uart_port *port) val =3D (AML_UART_RECV_IRQ(1) | AML_UART_XMIT_IRQ(port->fifosize / 2)); writel(val, port->membase + AML_UART_MISC); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 ret =3D request_irq(port->irq, meson_uart_interrupt, 0, port->name, port); @@ -341,7 +341,7 @@ static void meson_uart_set_termios(struct uart_port *po= rt, unsigned long flags; u32 val; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 cflags =3D termios->c_cflag; iflags =3D termios->c_iflag; @@ -401,7 +401,7 @@ static void meson_uart_set_termios(struct uart_port *po= rt, AML_UART_FRAME_ERR; =20 uart_update_timeout(port, termios->c_cflag, baud); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static int meson_uart_verify_port(struct uart_port *port, @@ -460,14 +460,14 @@ static int meson_uart_poll_get_char(struct uart_port = *port) u32 c; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 if (readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY) c =3D NO_POLL_CHAR; else c =3D readl(port->membase + AML_UART_RFIFO); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return c; } @@ -478,7 +478,7 @@ static void meson_uart_poll_put_char(struct uart_port *= port, unsigned char c) u32 reg; int ret; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Wait until FIFO is empty or timeout */ ret =3D readl_poll_timeout_atomic(port->membase + AML_UART_STATUS, reg, @@ -502,7 +502,7 @@ static void meson_uart_poll_put_char(struct uart_port *= port, unsigned char c) dev_err(port->dev, "Timeout waiting for UART TX EMPTY\n"); =20 out: - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 #endif /* CONFIG_CONSOLE_POLL */ @@ -559,9 +559,9 @@ static void meson_serial_port_write(struct uart_port *p= ort, const char *s, if (port->sysrq) { locked =3D 0; } else if (oops_in_progress) { - locked =3D spin_trylock(&port->lock); + locked =3D uart_port_trylock(port); } else { - spin_lock(&port->lock); + uart_port_lock(port); locked =3D 1; } =20 @@ -573,7 +573,7 @@ static void meson_serial_port_write(struct uart_port *p= ort, const char *s, writel(val, port->membase + AML_UART_CONTROL); =20 if (locked) - spin_unlock(&port->lock); + uart_port_unlock(port); local_irq_restore(flags); } =20 --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 226BFEEAA64 for ; Thu, 14 Sep 2023 18:40:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241771AbjINSk3 (ORCPT ); Thu, 14 Sep 2023 14:40:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241819AbjINSjB (ORCPT ); Thu, 14 Sep 2023 14:39:01 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F673211E; Thu, 14 Sep 2023 11:38:56 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716734; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E9wzJpM/hTGvGG40vNbVTUQjpkMtUAUxayMtXjZuHUE=; b=u8PiurzFnDC29q45800AqAXE7kZ5IcrLh5PgFkXFWnEqN2WMaBEoxskCMMi9QcukzjXvo8 zxNMY05yrq8L33TVpXER2JxgNUc1E/xhYJMwu4sd4HpsDc0MKIuaWzFMfoPsnme259Cobp iFCIpRAsH76Pf0EeGsYgvm7fR3aWBRfh1G80WueS2pdN+4BoyuaGhYWLdUKqmAySZCqsP5 xXwV5U0TC7WQVjC1oTM9nmcHz5iVLKEzG8NsdnzS8r8t1UW1grEEDkSSsaHK9ioYWVbh1d cPSA2ZtEx9keDZud6890yVfuNfEzSbJ1Ewwhyu4E/NT7s9FAi1m0qLuQ3yqVLw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716734; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E9wzJpM/hTGvGG40vNbVTUQjpkMtUAUxayMtXjZuHUE=; b=Z1W6hSbtxnVWbn5OWCbxj/FFJw4sMBXi9W6Yl6ggduNuUlI6W1LsbgMRHOWu1h1acXbZjn dfA/izrV71PNwOAw== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Taichi Sugaya , Takao Orito , Thierry Reding , Richard GENOUD , "Maciej W. Rozycki" , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , linux-arm-kernel@lists.infradead.org Subject: [PATCH tty v1 38/74] serial: milbeaut_usio: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:55 +0206 Message-Id: <20230914183831.587273-39-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/milbeaut_usio.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/tty/serial/milbeaut_usio.c b/drivers/tty/serial/milbea= ut_usio.c index 70a910085e93..db3b81f2aa57 100644 --- a/drivers/tty/serial/milbeaut_usio.c +++ b/drivers/tty/serial/milbeaut_usio.c @@ -207,9 +207,9 @@ static irqreturn_t mlb_usio_rx_irq(int irq, void *dev_i= d) { struct uart_port *port =3D dev_id; =20 - spin_lock(&port->lock); + uart_port_lock(port); mlb_usio_rx_chars(port); - spin_unlock(&port->lock); + uart_port_unlock(port); =20 return IRQ_HANDLED; } @@ -218,10 +218,10 @@ static irqreturn_t mlb_usio_tx_irq(int irq, void *dev= _id) { struct uart_port *port =3D dev_id; =20 - spin_lock(&port->lock); + uart_port_lock(port); if (readb(port->membase + MLB_USIO_REG_SSR) & MLB_USIO_SSR_TBI) mlb_usio_tx_chars(port); - spin_unlock(&port->lock); + uart_port_unlock(port); =20 return IRQ_HANDLED; } @@ -267,7 +267,7 @@ static int mlb_usio_startup(struct uart_port *port) escr =3D readb(port->membase + MLB_USIO_REG_ESCR); if (of_property_read_bool(port->dev->of_node, "auto-flow-control")) escr |=3D MLB_USIO_ESCR_FLWEN; - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); writeb(0, port->membase + MLB_USIO_REG_SCR); writeb(escr, port->membase + MLB_USIO_REG_ESCR); writeb(MLB_USIO_SCR_UPCL, port->membase + MLB_USIO_REG_SCR); @@ -282,7 +282,7 @@ static int mlb_usio_startup(struct uart_port *port) =20 writeb(MLB_USIO_SCR_TXE | MLB_USIO_SCR_RIE | MLB_USIO_SCR_TBIE | MLB_USIO_SCR_RXE, port->membase + MLB_USIO_REG_SCR); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return 0; } @@ -337,7 +337,7 @@ static void mlb_usio_set_termios(struct uart_port *port, else quot =3D 0; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); uart_update_timeout(port, termios->c_cflag, baud); port->read_status_mask =3D MLB_USIO_SSR_ORE | MLB_USIO_SSR_RDRF | MLB_USIO_SSR_TDRE; @@ -367,7 +367,7 @@ static void mlb_usio_set_termios(struct uart_port *port, writew(BIT(12), port->membase + MLB_USIO_REG_FBYTE); writeb(MLB_USIO_SCR_RIE | MLB_USIO_SCR_RXE | MLB_USIO_SCR_TBIE | MLB_USIO_SCR_TXE, port->membase + MLB_USIO_REG_SCR); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *mlb_usio_type(struct uart_port *port) --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8F34EEAA5D for ; Thu, 14 Sep 2023 18:40:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242054AbjINSkc (ORCPT ); Thu, 14 Sep 2023 14:40:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241837AbjINSjB (ORCPT ); Thu, 14 Sep 2023 14:39:01 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87F152101; Thu, 14 Sep 2023 11:38:56 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716735; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hpMKqxP39Aj1OlB9VqwDRJumN0r6uN84lHL1pDkCQeE=; b=Pp/OGmDj8bMmAT9eZ1ySXB//R2G1FfxBh2rCko4qVh2BdTqpXFvZH3XdSA8/Dt5Rmy8Xmf Au2vkXb+sOqd+lUM/wW0LbwmWUmMOItZJ8aipSq6my6kzxRdncDlAzKGX/5t978GKcPpId vZuu2M33td/NUSKgQytJNEGeKqPiPmbK4DA/bL/wwv3GrvnJEBHahKvpM5Yf3n4o/QOkdO m4wjj2Hih6J8cHfLNftCsYGbNH7EWimZgfNjdcCDHyZIyg2Fjvpwj4604kGsuT3NG6etBN JVkGl0gcbLCwXXpWEhYVVwheb41Efq8+HkhAIy2JqF9LjKS6d7HlbaqVUwU6mA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716735; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hpMKqxP39Aj1OlB9VqwDRJumN0r6uN84lHL1pDkCQeE=; b=uwgakoj7fG2f6H2ApkMwkAjT0yD56cfGqEkV4wd0dDYU1DBAjq1VStA47ABhHB07vJ5t/R jbBg9GaiGCJPACDg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Rob Herring Subject: [PATCH tty v1 39/74] serial: mpc52xx: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:56 +0206 Message-Id: <20230914183831.587273-40-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/mpc52xx_uart.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/tty/serial/mpc52xx_uart.c b/drivers/tty/serial/mpc52xx= _uart.c index 916507b8f31d..a252465e745f 100644 --- a/drivers/tty/serial/mpc52xx_uart.c +++ b/drivers/tty/serial/mpc52xx_uart.c @@ -1096,14 +1096,14 @@ static void mpc52xx_uart_break_ctl(struct uart_port *port, int ctl) { unsigned long flags; - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 if (ctl =3D=3D -1) psc_ops->command(port, MPC52xx_PSC_START_BRK); else psc_ops->command(port, MPC52xx_PSC_STOP_BRK); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static int @@ -1214,7 +1214,7 @@ mpc52xx_uart_set_termios(struct uart_port *port, stru= ct ktermios *new, } =20 /* Get the lock */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Do our best to flush TX & RX, so we don't lose anything */ /* But we don't wait indefinitely ! */ @@ -1250,7 +1250,7 @@ mpc52xx_uart_set_termios(struct uart_port *port, stru= ct ktermios *new, psc_ops->command(port, MPC52xx_PSC_RX_ENABLE); =20 /* We're all set, release the lock */ - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char * @@ -1477,11 +1477,11 @@ mpc52xx_uart_int(int irq, void *dev_id) struct uart_port *port =3D dev_id; irqreturn_t ret; =20 - spin_lock(&port->lock); + uart_port_lock(port); =20 ret =3D psc_ops->handle_irq(port); =20 - spin_unlock(&port->lock); + uart_port_unlock(port); =20 return ret; } --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C55C5EEAA5D for ; Thu, 14 Sep 2023 18:40:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242059AbjINSkf (ORCPT ); Thu, 14 Sep 2023 14:40:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241847AbjINSjC (ORCPT ); Thu, 14 Sep 2023 14:39:02 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07D3F268C; Thu, 14 Sep 2023 11:38:57 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716735; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/1APoFz57Q+j1ahdXqu2UFCMnpKF7KLxKqz0dVY4BD4=; b=LoSvbJvi7dssW2JKc94oMsZAFLXfAK/Rb1sCC2mWK8uh+9ZYV9D/a5kEfaoYUhCM020t3X 8VAk6PTMhH0fR6ef9sdetkn5Rqlk5QbJJ/jdge77vprEsMTZ8+yCwcWCQxV0J9AzRMeUaJ D+ThnuUYare4lYf6qM8fctIlDCe4pTsb8o9eKaPzbWWunoT7IhhM7FLW5c8SFDamCGSQMT JTi3NWz8DPT6NEPGCON9uNujqjQV0CABaoCbXRpGU4jnNBAAjhzPodJHV4Ed0Fx+SJy+07 YWpPrcbAHN0XaVZwf8W0lVylPa+2PjKpK05v2Y+0L4fi6puG3z/2PDpnwCQNlw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716735; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/1APoFz57Q+j1ahdXqu2UFCMnpKF7KLxKqz0dVY4BD4=; b=Sb3SseUkX2HguEt15WIpJgUWSaMG0vIbUQVv2UPnfIKeR+vVRbukPUTkHE8yvXjgc/A8KT hP5ARzkh26e3p1Bg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Liviu Dudau , Sudeep Holla , Lorenzo Pieralisi , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Yangtao Li , Rob Herring , linux-arm-kernel@lists.infradead.org Subject: [PATCH tty v1 40/74] serial: mps2-uart: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:57 +0206 Message-Id: <20230914183831.587273-41-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/mps2-uart.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/tty/serial/mps2-uart.c b/drivers/tty/serial/mps2-uart.c index ea5a7911cb15..2a4c09f3a834 100644 --- a/drivers/tty/serial/mps2-uart.c +++ b/drivers/tty/serial/mps2-uart.c @@ -188,12 +188,12 @@ static irqreturn_t mps2_uart_rxirq(int irq, void *dat= a) if (unlikely(!(irqflag & UARTn_INT_RX))) return IRQ_NONE; =20 - spin_lock(&port->lock); + uart_port_lock(port); =20 mps2_uart_write8(port, UARTn_INT_RX, UARTn_INT); mps2_uart_rx_chars(port); =20 - spin_unlock(&port->lock); + uart_port_unlock(port); =20 return IRQ_HANDLED; } @@ -206,12 +206,12 @@ static irqreturn_t mps2_uart_txirq(int irq, void *dat= a) if (unlikely(!(irqflag & UARTn_INT_TX))) return IRQ_NONE; =20 - spin_lock(&port->lock); + uart_port_lock(port); =20 mps2_uart_write8(port, UARTn_INT_TX, UARTn_INT); mps2_uart_tx_chars(port); =20 - spin_unlock(&port->lock); + uart_port_unlock(port); =20 return IRQ_HANDLED; } @@ -222,7 +222,7 @@ static irqreturn_t mps2_uart_oerrirq(int irq, void *dat= a) struct uart_port *port =3D data; u8 irqflag =3D mps2_uart_read8(port, UARTn_INT); =20 - spin_lock(&port->lock); + uart_port_lock(port); =20 if (irqflag & UARTn_INT_RX_OVERRUN) { struct tty_port *tport =3D &port->state->port; @@ -244,7 +244,7 @@ static irqreturn_t mps2_uart_oerrirq(int irq, void *dat= a) handled =3D IRQ_HANDLED; } =20 - spin_unlock(&port->lock); + uart_port_unlock(port); =20 return handled; } @@ -356,12 +356,12 @@ mps2_uart_set_termios(struct uart_port *port, struct = ktermios *termios, =20 bauddiv =3D DIV_ROUND_CLOSEST(port->uartclk, baud); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 uart_update_timeout(port, termios->c_cflag, baud); mps2_uart_write32(port, bauddiv, UARTn_BAUDDIV); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 if (tty_termios_baud_rate(termios)) tty_termios_encode_baud_rate(termios, baud, baud); --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70A00EEAA63 for ; Thu, 14 Sep 2023 18:40:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242063AbjINSki (ORCPT ); Thu, 14 Sep 2023 14:40:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241867AbjINSjI (ORCPT ); Thu, 14 Sep 2023 14:39:08 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75F7C2693; Thu, 14 Sep 2023 11:38:57 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716736; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lU9D8We8m4x72sUrLwTLFKudvB8THnTuYuyUkrl8N/A=; b=hAMHEMsgqejMT1XBX057U7gRX/U0TGRx3iue3x/BaIGP2roM1YCGjozN2L9FUjZkyFgPiO wNfTWFxb0/ZsMZt0RPpay2OdEU7JJs2RY/X4jt+EPSppHA6AWFVLL5/T6PrwgIMEeEqubC EYxKB7lM2J8v0TaCjrXRhAWNCjoiXfxeRwOVToCiZt2ch0bFJmBg+aMXDbzknRGYCju55k lRkHT77aZRlm4KXBzKvDseK8wwh+FN7CZ53u7vuDS1TKBclGeiDLNcGKKXu12nDDfRPWBC 0vzQIR61YbtQNGgDRyRvi+qk0aRx/DSdaGwbJsi3WyJ/sMuXwNbSbK0fyL7OCQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716736; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lU9D8We8m4x72sUrLwTLFKudvB8THnTuYuyUkrl8N/A=; b=w2ZDYAKVL3yIhf3zWrk2VoKWILS3vFbQnBzPcxXlGmzGcK+Zrii90SS8A7LT64OBqbAGcJ fmc4JyzXXOILh3Dw== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Andy Gross , Bjorn Andersson , Konrad Dybcio , linux-arm-msm@vger.kernel.org Subject: [PATCH tty v1 41/74] serial: msm: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:58 +0206 Message-Id: <20230914183831.587273-42-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner Reviewed-by: Bjorn Andersson --- drivers/tty/serial/msm_serial.c | 38 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_seria= l.c index 90953e679e38..597264b546fd 100644 --- a/drivers/tty/serial/msm_serial.c +++ b/drivers/tty/serial/msm_serial.c @@ -444,7 +444,7 @@ static void msm_complete_tx_dma(void *args) unsigned int count; u32 val; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Already stopped */ if (!dma->count) @@ -476,7 +476,7 @@ static void msm_complete_tx_dma(void *args) =20 msm_handle_tx(port); done: - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static int msm_handle_tx_dma(struct msm_port *msm_port, unsigned int count) @@ -549,7 +549,7 @@ static void msm_complete_rx_dma(void *args) unsigned long flags; u32 val; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Already stopped */ if (!dma->count) @@ -587,16 +587,16 @@ static void msm_complete_rx_dma(void *args) if (!(port->read_status_mask & MSM_UART_SR_RX_BREAK)) flag =3D TTY_NORMAL; =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); sysrq =3D uart_handle_sysrq_char(port, dma->virt[i]); - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); if (!sysrq) tty_insert_flip_char(tport, dma->virt[i], flag); } =20 msm_start_rx_dma(msm_port); done: - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 if (count) tty_flip_buffer_push(tport); @@ -762,9 +762,9 @@ static void msm_handle_rx_dm(struct uart_port *port, un= signed int misr) if (!(port->read_status_mask & MSM_UART_SR_RX_BREAK)) flag =3D TTY_NORMAL; =20 - spin_unlock(&port->lock); + uart_port_unlock(port); sysrq =3D uart_handle_sysrq_char(port, buf[i]); - spin_lock(&port->lock); + uart_port_lock(port); if (!sysrq) tty_insert_flip_char(tport, buf[i], flag); } @@ -824,9 +824,9 @@ static void msm_handle_rx(struct uart_port *port) else if (sr & MSM_UART_SR_PAR_FRAME_ERR) flag =3D TTY_FRAME; =20 - spin_unlock(&port->lock); + uart_port_unlock(port); sysrq =3D uart_handle_sysrq_char(port, c); - spin_lock(&port->lock); + uart_port_lock(port); if (!sysrq) tty_insert_flip_char(tport, c, flag); } @@ -951,7 +951,7 @@ static irqreturn_t msm_uart_irq(int irq, void *dev_id) unsigned int misr; u32 val; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); misr =3D msm_read(port, MSM_UART_MISR); msm_write(port, 0, MSM_UART_IMR); /* disable interrupt */ =20 @@ -983,7 +983,7 @@ static irqreturn_t msm_uart_irq(int irq, void *dev_id) msm_handle_delta_cts(port); =20 msm_write(port, msm_port->imr, MSM_UART_IMR); /* restore interrupt */ - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return IRQ_HANDLED; } @@ -1128,13 +1128,13 @@ static int msm_set_baud_rate(struct uart_port *port= , unsigned int baud, unsigned long flags, rate; =20 flags =3D *saved_flags; - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 entry =3D msm_find_best_baud(port, baud, &rate); clk_set_rate(msm_port->clk, rate); baud =3D rate / 16 / entry->divisor; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); *saved_flags =3D flags; port->uartclk =3D rate; =20 @@ -1266,7 +1266,7 @@ static void msm_set_termios(struct uart_port *port, s= truct ktermios *termios, unsigned long flags; unsigned int baud, mr; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 if (dma->chan) /* Terminate if any */ msm_stop_dma(port, dma); @@ -1338,7 +1338,7 @@ static void msm_set_termios(struct uart_port *port, s= truct ktermios *termios, /* Try to use DMA */ msm_start_rx_dma(msm_port); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *msm_type(struct uart_port *port) @@ -1620,9 +1620,9 @@ static void __msm_console_write(struct uart_port *por= t, const char *s, if (port->sysrq) locked =3D 0; else if (oops_in_progress) - locked =3D spin_trylock(&port->lock); + locked =3D uart_port_trylock(port); else - spin_lock(&port->lock); + uart_port_lock(port); =20 if (is_uartdm) msm_reset_dm_count(port, count); @@ -1661,7 +1661,7 @@ static void __msm_console_write(struct uart_port *por= t, const char *s, } =20 if (locked) - spin_unlock(&port->lock); + uart_port_unlock(port); =20 local_irq_restore(flags); } --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42DBAEEAA63 for ; Thu, 14 Sep 2023 18:40:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241960AbjINSko (ORCPT ); Thu, 14 Sep 2023 14:40:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241609AbjINSjM (ORCPT ); Thu, 14 Sep 2023 14:39:12 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0FBB212F; Thu, 14 Sep 2023 11:38:57 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716736; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H6vrAwcgKz7ylA3cRQUQRd1w5cbqa1m8ev1xxDaRFwE=; b=muqVm7X9tP6ID051yVCBhDgrs0kev7wg4hEKEteDt08L0usIg1siioIaPv90x2ZGm6h2Ws 9QNQtenqdH5eij4RXmczrpWLR3MO1arWnlxoaIcPFCBWxUJWODNMvZb4pStGZ/atT4IKMD R/jazeHrX+uwyAaX506eQogR4DJHMHYAUEiz9sF8/DHk1zMGBlJW3jqm3/KS/EWNEvWY4q zcFyZJjZ1YUu3uwJDQ2d+YN/ToDi5Hgo7t4Bya6+31CNsDGafDAe7q8ln0ZKHAGyrJ2n8y Cf9VmNeBu5MM7RNL6Y8TakEVktDuc99B3g2VRBGPPFCb4wmdkgAGeGBpqyjd1Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716736; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H6vrAwcgKz7ylA3cRQUQRd1w5cbqa1m8ev1xxDaRFwE=; b=qZFEim1mhdloYTQZZVPN8NbdSh3Tzog/vMVwwhRyGWfxWi+4OVib5huct2BIqmF6Z3N2gP mEZ/wxnI0iXWryBA== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, =?UTF-8?q?Pali=20Roh=C3=A1r?= Subject: [PATCH tty v1 42/74] serial: mvebu-uart: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:59 +0206 Message-Id: <20230914183831.587273-43-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/mvebu-uart.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/tty/serial/mvebu-uart.c b/drivers/tty/serial/mvebu-uar= t.c index ea924e9b913b..0255646bc175 100644 --- a/drivers/tty/serial/mvebu-uart.c +++ b/drivers/tty/serial/mvebu-uart.c @@ -187,9 +187,9 @@ static unsigned int mvebu_uart_tx_empty(struct uart_por= t *port) unsigned long flags; unsigned int st; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); st =3D readl(port->membase + UART_STAT); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return (st & STAT_TX_EMP) ? TIOCSER_TEMT : 0; } @@ -249,14 +249,14 @@ static void mvebu_uart_break_ctl(struct uart_port *po= rt, int brk) unsigned int ctl; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); ctl =3D readl(port->membase + UART_CTRL(port)); if (brk =3D=3D -1) ctl |=3D CTRL_SND_BRK_SEQ; else ctl &=3D ~CTRL_SND_BRK_SEQ; writel(ctl, port->membase + UART_CTRL(port)); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void mvebu_uart_rx_chars(struct uart_port *port, unsigned int statu= s) @@ -540,7 +540,7 @@ static void mvebu_uart_set_termios(struct uart_port *po= rt, unsigned long flags; unsigned int baud, min_baud, max_baud; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 port->read_status_mask =3D STAT_RX_RDY(port) | STAT_OVR_ERR | STAT_TX_RDY(port) | STAT_TX_FIFO_FUL; @@ -589,7 +589,7 @@ static void mvebu_uart_set_termios(struct uart_port *po= rt, uart_update_timeout(port, termios->c_cflag, baud); } =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *mvebu_uart_type(struct uart_port *port) @@ -735,9 +735,9 @@ static void mvebu_uart_console_write(struct console *co= , const char *s, int locked =3D 1; =20 if (oops_in_progress) - locked =3D spin_trylock_irqsave(&port->lock, flags); + locked =3D uart_port_trylock_irqsave(port, &flags); else - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 ier =3D readl(port->membase + UART_CTRL(port)) & CTRL_BRK_INT; intr =3D readl(port->membase + UART_INTR(port)) & @@ -758,7 +758,7 @@ static void mvebu_uart_console_write(struct console *co= , const char *s, } =20 if (locked) - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static int mvebu_uart_console_setup(struct console *co, char *options) --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBABEEEAA62 for ; Thu, 14 Sep 2023 18:40:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242074AbjINSkq (ORCPT ); Thu, 14 Sep 2023 14:40:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241889AbjINSjR (ORCPT ); Thu, 14 Sep 2023 14:39:17 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DB3F2699; Thu, 14 Sep 2023 11:38:58 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716736; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TM2lMzc0PZnA/sY8/z8U7YuTZ4e1IcuDY2kIfWsOpyQ=; b=FICjtyvsmwVqj44DyW1kMBUfwf68fgwbh15x8MwU/aTDMRJPKm4BZUOBzG0XBA7jWlIB+0 YKFyTSq8o42fJ/COoOhYyMT7EBDEP97Eb6JRrudzQyA7+zX61wXKdASBue+PapJhSE6S5j RyQm2yrliGyEaATky/kriWEYTuCbWCJWrVQFzrQMKRJOxSWrnl2GB/GqOVR7cyy1u1WfgD umlRMhKtB2vbUqECyRnuRE1iDF+5I1rOVDP2d3U+dh1+4IBfv72B5AHE98/jTuB+Eqh7D2 vEPkNs0ajk3mvU+NMgH2yAkiglQdHGWn1u7hIgFNTKx3qFP1cWqpPw3he5z/IA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716736; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TM2lMzc0PZnA/sY8/z8U7YuTZ4e1IcuDY2kIfWsOpyQ=; b=3mUyA4mjX/1njeJwzdLso8SNIMRFMezSZkikPVg02+JHQf5a1CWunGcOHq+55yvoNpG3we sREi4ItmDB13/HDA== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Andrew Morton , Andy Shevchenko , Lukas Wunner , Yangtao Li Subject: [PATCH tty v1 43/74] serial: omap: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:00 +0206 Message-Id: <20230914183831.587273-44-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/omap-serial.c | 38 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-ser= ial.c index 0ead88c5a19a..ad4c1c5d0a7f 100644 --- a/drivers/tty/serial/omap-serial.c +++ b/drivers/tty/serial/omap-serial.c @@ -390,10 +390,10 @@ static void serial_omap_throttle(struct uart_port *po= rt) struct uart_omap_port *up =3D to_uart_omap_port(port); unsigned long flags; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); up->ier &=3D ~(UART_IER_RLSI | UART_IER_RDI); serial_out(up, UART_IER, up->ier); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 static void serial_omap_unthrottle(struct uart_port *port) @@ -401,10 +401,10 @@ static void serial_omap_unthrottle(struct uart_port *= port) struct uart_omap_port *up =3D to_uart_omap_port(port); unsigned long flags; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); up->ier |=3D UART_IER_RLSI | UART_IER_RDI; serial_out(up, UART_IER, up->ier); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 static unsigned int check_modem_status(struct uart_omap_port *up) @@ -527,7 +527,7 @@ static irqreturn_t serial_omap_irq(int irq, void *dev_i= d) irqreturn_t ret =3D IRQ_NONE; int max_count =3D 256; =20 - spin_lock(&up->port.lock); + uart_port_lock(&up->port); =20 do { iir =3D serial_in(up, UART_IIR); @@ -563,7 +563,7 @@ static irqreturn_t serial_omap_irq(int irq, void *dev_i= d) } } while (max_count--); =20 - spin_unlock(&up->port.lock); + uart_port_unlock(&up->port); =20 tty_flip_buffer_push(&up->port.state->port); =20 @@ -579,9 +579,9 @@ static unsigned int serial_omap_tx_empty(struct uart_po= rt *port) unsigned int ret =3D 0; =20 dev_dbg(up->port.dev, "serial_omap_tx_empty+%d\n", up->port.line); - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); ret =3D serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0; - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =20 return ret; } @@ -647,13 +647,13 @@ static void serial_omap_break_ctl(struct uart_port *p= ort, int break_state) unsigned long flags; =20 dev_dbg(up->port.dev, "serial_omap_break_ctl+%d\n", up->port.line); - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); if (break_state =3D=3D -1) up->lcr |=3D UART_LCR_SBC; else up->lcr &=3D ~UART_LCR_SBC; serial_out(up, UART_LCR, up->lcr); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 static int serial_omap_startup(struct uart_port *port) @@ -701,13 +701,13 @@ static int serial_omap_startup(struct uart_port *port) * Now, initialize the UART */ serial_out(up, UART_LCR, UART_LCR_WLEN8); - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); /* * Most PC uarts need OUT2 raised to enable interrupts. */ up->port.mctrl |=3D TIOCM_OUT2; serial_omap_set_mctrl(&up->port, up->port.mctrl); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =20 up->msr_saved_flags =3D 0; /* @@ -742,10 +742,10 @@ static void serial_omap_shutdown(struct uart_port *po= rt) up->ier =3D 0; serial_out(up, UART_IER, 0); =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); up->port.mctrl &=3D ~TIOCM_OUT2; serial_omap_set_mctrl(&up->port, up->port.mctrl); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =20 /* * Disable break condition and FIFOs @@ -815,7 +815,7 @@ serial_omap_set_termios(struct uart_port *port, struct = ktermios *termios, * Ok, we're now changing the port state. Do it with * interrupts disabled. */ - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 /* * Update the per-port timeout. @@ -1013,7 +1013,7 @@ serial_omap_set_termios(struct uart_port *port, struc= t ktermios *termios, =20 serial_omap_set_mctrl(&up->port, up->port.mctrl); =20 - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); dev_dbg(up->port.dev, "serial_omap_set_termios+%d\n", up->port.line); } =20 @@ -1216,9 +1216,9 @@ serial_omap_console_write(struct console *co, const c= har *s, if (up->port.sysrq) locked =3D 0; else if (oops_in_progress) - locked =3D spin_trylock(&up->port.lock); + locked =3D uart_port_trylock(&up->port); else - spin_lock(&up->port.lock); + uart_port_lock(&up->port); =20 /* * First save the IER then disable the interrupts @@ -1245,7 +1245,7 @@ serial_omap_console_write(struct console *co, const c= har *s, check_modem_status(up); =20 if (locked) - spin_unlock(&up->port.lock); + uart_port_unlock(&up->port); local_irq_restore(flags); } =20 --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41611EEAA64 for ; Thu, 14 Sep 2023 18:40:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242083AbjINSk7 (ORCPT ); Thu, 14 Sep 2023 14:40:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241900AbjINSjU (ORCPT ); Thu, 14 Sep 2023 14:39:20 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C196426A0; Thu, 14 Sep 2023 11:38:58 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716737; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wEegAouA6je3osDZUCJlEv4gB4p0igZuWACS++cZC6E=; b=P6M8uOs7G9Yh2dc008zF0jwOKeRh+0hdHCSyzdlotOmY0uNzJhA9n/z2Ghgw0hLD3btQN0 LU0PJMIUqY+PNsWpCt8Fgdf7vWhYkHrdBWXJKxjWs1S5osrUX1XYS+GxDXNIcZv0LNbInJ KyKAiaExHWIPnNXtopgW1ACgnMGNr2MU4hazjKE35Jr75Mq5heJ3rQ7TobgjB2ZOy1WOTs yRaZhaIr9Eg0ziMUyc7mkzNOKXtx9BXRb+CFh6CXdTf2hX6pmnGMnuLJZ/wuwmsSBL9NnF 2KwNuGN7Ys5NqQfLHT5AFK9JO+piH7H+1QZoujzVSxRXEdHXdAdeCPR0oEouzA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716737; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wEegAouA6je3osDZUCJlEv4gB4p0igZuWACS++cZC6E=; b=uBA+txHp6Ix/jsJ7gls3Uu83I1iuB3Kr/xTO5a038wo1mz94ZF0uGirU+OK9B6vKmLEgmR viMGeXnBcms8HvDg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, =?UTF-8?q?Andreas=20F=C3=A4rber?= , Manivannan Sadhasivam , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , linux-arm-kernel@lists.infradead.org, linux-actions@lists.infradead.org Subject: [PATCH tty v1 44/74] serial: owl: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:01 +0206 Message-Id: <20230914183831.587273-45-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/owl-uart.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/tty/serial/owl-uart.c b/drivers/tty/serial/owl-uart.c index e99970a9437f..919f5e5aa0f1 100644 --- a/drivers/tty/serial/owl-uart.c +++ b/drivers/tty/serial/owl-uart.c @@ -125,12 +125,12 @@ static unsigned int owl_uart_tx_empty(struct uart_por= t *port) u32 val; unsigned int ret; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 val =3D owl_uart_read(port, OWL_UART_STAT); ret =3D (val & OWL_UART_STAT_TFES) ? TIOCSER_TEMT : 0; =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return ret; } @@ -232,7 +232,7 @@ static irqreturn_t owl_uart_irq(int irq, void *dev_id) unsigned long flags; u32 stat; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 stat =3D owl_uart_read(port, OWL_UART_STAT); =20 @@ -246,7 +246,7 @@ static irqreturn_t owl_uart_irq(int irq, void *dev_id) stat |=3D OWL_UART_STAT_RIP | OWL_UART_STAT_TIP; owl_uart_write(port, stat, OWL_UART_STAT); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return IRQ_HANDLED; } @@ -256,14 +256,14 @@ static void owl_uart_shutdown(struct uart_port *port) u32 val; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 val =3D owl_uart_read(port, OWL_UART_CTL); val &=3D ~(OWL_UART_CTL_TXIE | OWL_UART_CTL_RXIE | OWL_UART_CTL_TXDE | OWL_UART_CTL_RXDE | OWL_UART_CTL_EN); owl_uart_write(port, val, OWL_UART_CTL); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 free_irq(port->irq, port); } @@ -279,7 +279,7 @@ static int owl_uart_startup(struct uart_port *port) if (ret) return ret; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 val =3D owl_uart_read(port, OWL_UART_STAT); val |=3D OWL_UART_STAT_RIP | OWL_UART_STAT_TIP @@ -291,7 +291,7 @@ static int owl_uart_startup(struct uart_port *port) val |=3D OWL_UART_CTL_EN; owl_uart_write(port, val, OWL_UART_CTL); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return 0; } @@ -311,7 +311,7 @@ static void owl_uart_set_termios(struct uart_port *port, u32 ctl; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 ctl =3D owl_uart_read(port, OWL_UART_CTL); =20 @@ -371,7 +371,7 @@ static void owl_uart_set_termios(struct uart_port *port, =20 uart_update_timeout(port, termios->c_cflag, baud); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void owl_uart_release_port(struct uart_port *port) @@ -515,9 +515,9 @@ static void owl_uart_port_write(struct uart_port *port,= const char *s, if (port->sysrq) locked =3D 0; else if (oops_in_progress) - locked =3D spin_trylock(&port->lock); + locked =3D uart_port_trylock(port); else { - spin_lock(&port->lock); + uart_port_lock(port); locked =3D 1; } =20 @@ -541,7 +541,7 @@ static void owl_uart_port_write(struct uart_port *port,= const char *s, owl_uart_write(port, old_ctl, OWL_UART_CTL); =20 if (locked) - spin_unlock(&port->lock); + uart_port_unlock(port); =20 local_irq_restore(flags); } --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01582EEAA5D for ; Thu, 14 Sep 2023 18:40:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241937AbjINSlC (ORCPT ); Thu, 14 Sep 2023 14:41:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241792AbjINSjb (ORCPT ); Thu, 14 Sep 2023 14:39:31 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33BC526A9; Thu, 14 Sep 2023 11:38:59 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716737; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LIgEmBRygWlWYq6zDaryhqi8PdqWfUxAJ5u9Q//8KAY=; b=gRO2s7joD8nbugkWdaI7LOhIYz5xn3GZfDZuZpvpZ6MHdZJ26/SJzt0szg/AQ6E1v2+VAo Zoo3d7o/Jp5IxIBA7XGqE4dDWci3vhmUxUzNY5QIkkh99LwTRVQGyW7uKuF37sb9DIgawL Km/1GYpDRxXg7sjjee87eZP+FRGj139SDmrHpCy4VU8lQ0bskpyf8zKEUkpOKvMyoK7uw3 BkCLCALtZw3Beh9T69HF/g81VorzF918kB8WHO6wGYfRxfrCqFYpAKXSx0HvK9ZnS9sBZo wlBfbeAlYbSBWApl9lPqVUT1GkCHGAvS1BT80LcIbX12e+fGvVnusblf+94v3Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716737; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LIgEmBRygWlWYq6zDaryhqi8PdqWfUxAJ5u9Q//8KAY=; b=bK0I4A7t7020RZDbb5VCqF9wJQeobL5ue1tpocpk3N+yVYK2sg6AikqLjJrb9YGlY4lfZ0 ITrmNhRMS4dEwhDQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Xiongfeng Wang , Andy Shevchenko Subject: [PATCH tty v1 45/74] serial: pch: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:02 +0206 Message-Id: <20230914183831.587273-46-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/pch_uart.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c index cc83b772b7ca..436cc6d52a11 100644 --- a/drivers/tty/serial/pch_uart.c +++ b/drivers/tty/serial/pch_uart.c @@ -1347,7 +1347,7 @@ static void pch_uart_set_termios(struct uart_port *po= rt, baud =3D uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); =20 spin_lock_irqsave(&priv->lock, flags); - spin_lock(&port->lock); + uart_port_lock(port); =20 uart_update_timeout(port, termios->c_cflag, baud); rtn =3D pch_uart_hal_set_line(priv, baud, parity, bits, stb); @@ -1360,7 +1360,7 @@ static void pch_uart_set_termios(struct uart_port *po= rt, tty_termios_encode_baud_rate(termios, baud, baud); =20 out: - spin_unlock(&port->lock); + uart_port_unlock(port); spin_unlock_irqrestore(&priv->lock, flags); } =20 @@ -1581,10 +1581,10 @@ pch_console_write(struct console *co, const char *s= , unsigned int count) port_locked =3D 0; } else if (oops_in_progress) { priv_locked =3D spin_trylock(&priv->lock); - port_locked =3D spin_trylock(&priv->port.lock); + port_locked =3D uart_port_trylock(&priv->port); } else { spin_lock(&priv->lock); - spin_lock(&priv->port.lock); + uart_port_lock(&priv->port); } =20 /* @@ -1604,7 +1604,7 @@ pch_console_write(struct console *co, const char *s, = unsigned int count) iowrite8(ier, priv->membase + UART_IER); =20 if (port_locked) - spin_unlock(&priv->port.lock); + uart_port_unlock(&priv->port); if (priv_locked) spin_unlock(&priv->lock); local_irq_restore(flags); --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 198C9EEAA62 for ; Thu, 14 Sep 2023 18:41:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242092AbjINSlF (ORCPT ); Thu, 14 Sep 2023 14:41:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241928AbjINSjb (ORCPT ); Thu, 14 Sep 2023 14:39:31 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AC7E26AA; Thu, 14 Sep 2023 11:38:59 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716738; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V78gGTZqe9KNWC/CUJ6BLfJKVWn9CLRyUjSZ92RtJpw=; b=fGBpIGbVvU41G3c3jH4uC9Kf+WPal9GfMOGSjtwHx8pj9VJkIf2jyS2qhjqyY2kvBIBH2a fJFBS4YRD4Lec7LT3jdT4I6kAJ/XD/tDkVF28js99byvGT2pRvWDPsdFkwjQ1mAJ2VAZA+ EzO3qZ4gXT0E0izX1mgdRcP2ygi4Xc2SPKFkge93tAEbuM8rZsCdpNah8q+pEn4Q6kcHPh u4IQU7Eg50kEm8HBo9jV2p/b+Rp8BwRYxPR4be+6knxEFs4pn+cA9RtkuCQWx1/ECriMmr NutZwKIvWabi11rCBM14Bx0/uufKRaHTI1dw6s5xeYXKn8cYJiB5ib7oNx8Zdg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716738; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V78gGTZqe9KNWC/CUJ6BLfJKVWn9CLRyUjSZ92RtJpw=; b=UIKwNx3A/uOpnCQiUHjam24Sbl8xyJL+e1/nJr3ID5X44/dR8Oj36CbNDo2MMHYK8AZ/oJ Ahe3LqbJSguKWJBA== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Yuan Can , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Rob Herring Subject: [PATCH tty v1 46/74] serial: pic32: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:03 +0206 Message-Id: <20230914183831.587273-47-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/pic32_uart.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/pic32_uart.c b/drivers/tty/serial/pic32_uar= t.c index e308d5022b3f..3a95bf5d55d3 100644 --- a/drivers/tty/serial/pic32_uart.c +++ b/drivers/tty/serial/pic32_uart.c @@ -243,7 +243,7 @@ static void pic32_uart_break_ctl(struct uart_port *port= , int ctl) struct pic32_sport *sport =3D to_pic32_sport(port); unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 if (ctl) pic32_uart_writel(sport, PIC32_SET(PIC32_UART_STA), @@ -252,7 +252,7 @@ static void pic32_uart_break_ctl(struct uart_port *port= , int ctl) pic32_uart_writel(sport, PIC32_CLR(PIC32_UART_STA), PIC32_UART_STA_UTXBRK); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /* get port type in string format */ @@ -274,7 +274,7 @@ static void pic32_uart_do_rx(struct uart_port *port) */ max_count =3D PIC32_UART_RX_FIFO_DEPTH; =20 - spin_lock(&port->lock); + uart_port_lock(port); =20 tty =3D &port->state->port; =20 @@ -331,7 +331,7 @@ static void pic32_uart_do_rx(struct uart_port *port) =20 } while (--max_count); =20 - spin_unlock(&port->lock); + uart_port_unlock(port); =20 tty_flip_buffer_push(tty); } @@ -410,9 +410,9 @@ static irqreturn_t pic32_uart_tx_interrupt(int irq, voi= d *dev_id) struct uart_port *port =3D dev_id; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); pic32_uart_do_tx(port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return IRQ_HANDLED; } @@ -580,9 +580,9 @@ static void pic32_uart_shutdown(struct uart_port *port) unsigned long flags; =20 /* disable uart */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); pic32_uart_dsbl_and_mask(port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); clk_disable_unprepare(sport->clk); =20 /* free all 3 interrupts for this UART */ @@ -604,7 +604,7 @@ static void pic32_uart_set_termios(struct uart_port *po= rt, unsigned int quot; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* disable uart and mask all interrupts while changing speed */ pic32_uart_dsbl_and_mask(port); @@ -672,7 +672,7 @@ static void pic32_uart_set_termios(struct uart_port *po= rt, /* enable uart */ pic32_uart_en_and_unmask(port); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /* serial core request to claim uart iomem */ --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4DEFEEAA62 for ; Thu, 14 Sep 2023 18:41:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242098AbjINSlN (ORCPT ); Thu, 14 Sep 2023 14:41:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241934AbjINSjc (ORCPT ); Thu, 14 Sep 2023 14:39:32 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 189BB26AF; Thu, 14 Sep 2023 11:39:00 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716738; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FJW0TuhSdXUv9FTqZdQkgamZVGooxW5FNHg4lshg/t0=; b=b7yR++MwVrSn/oZyZAiFtiEqhu8NcXqsYfx3rC/XpO4EZC4l5KrgdrtxsgqwvyuxTMaR7k oSdj9dUk7NFQ+BFfCloJuU548l879b5L9FheE1cQ3gTo3ltCq2YlPCl/dNESytplQ3xBI5 sqMc5zikJ/QWSA41fnYP+BMaNx6vgjH9hLhc4B/5h+/MVluHgK13bFvOLvDkM2wBTqGkgz +Ax3E/cSzbm5VKAVC4asblEB+O0hFtsLIA9tJM8v3WBEcFwIRqIZ6JnK2Nt+I9VEVRecXz 2l1SEH/EGbna5YRWcFOtxN9XVe9HF3CeDUYBPgarRCC5BW8nw4VNiyBRU61ItQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716738; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FJW0TuhSdXUv9FTqZdQkgamZVGooxW5FNHg4lshg/t0=; b=Zhh9mXIgjMHMUzh4F4Pe2Bl3bw4SjfghqkK66A25GbHwssWjWIzB0B37CiHQnHnWaU8Y2k 8Rclrpq4v1Rb1JBQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Michael Ellerman , Nicholas Piggin , Christophe Leroy , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , linuxppc-dev@lists.ozlabs.org Subject: [PATCH tty v1 47/74] serial: pmac_zilog: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:04 +0206 Message-Id: <20230914183831.587273-48-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/pmac_zilog.c | 52 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/drivers/tty/serial/pmac_zilog.c b/drivers/tty/serial/pmac_zilo= g.c index 13668ffdb1e7..c8bf08c19c64 100644 --- a/drivers/tty/serial/pmac_zilog.c +++ b/drivers/tty/serial/pmac_zilog.c @@ -246,9 +246,9 @@ static bool pmz_receive_chars(struct uart_pmac_port *ua= p) #endif /* USE_CTRL_O_SYSRQ */ if (uap->port.sysrq) { int swallow; - spin_unlock(&uap->port.lock); + uart_port_unlock(&uap->port); swallow =3D uart_handle_sysrq_char(&uap->port, ch); - spin_lock(&uap->port.lock); + uart_port_lock(&uap->port); if (swallow) goto next_char; } @@ -435,7 +435,7 @@ static irqreturn_t pmz_interrupt(int irq, void *dev_id) uap_a =3D pmz_get_port_A(uap); uap_b =3D uap_a->mate; =20 - spin_lock(&uap_a->port.lock); + uart_port_lock(&uap_a->port); r3 =3D read_zsreg(uap_a, R3); =20 /* Channel A */ @@ -456,14 +456,14 @@ static irqreturn_t pmz_interrupt(int irq, void *dev_i= d) rc =3D IRQ_HANDLED; } skip_a: - spin_unlock(&uap_a->port.lock); + uart_port_unlock(&uap_a->port); if (push) tty_flip_buffer_push(&uap->port.state->port); =20 if (!uap_b) goto out; =20 - spin_lock(&uap_b->port.lock); + uart_port_lock(&uap_b->port); push =3D false; if (r3 & (CHBEXT | CHBTxIP | CHBRxIP)) { if (!ZS_IS_OPEN(uap_b)) { @@ -481,7 +481,7 @@ static irqreturn_t pmz_interrupt(int irq, void *dev_id) rc =3D IRQ_HANDLED; } skip_b: - spin_unlock(&uap_b->port.lock); + uart_port_unlock(&uap_b->port); if (push) tty_flip_buffer_push(&uap->port.state->port); =20 @@ -497,9 +497,9 @@ static inline u8 pmz_peek_status(struct uart_pmac_port = *uap) unsigned long flags; u8 status; =09 - spin_lock_irqsave(&uap->port.lock, flags); + uart_port_lock_irqsave(&uap->port, &flags); status =3D read_zsreg(uap, R0); - spin_unlock_irqrestore(&uap->port.lock, flags); + uart_port_unlock_irqrestore(&uap->port, flags); =20 return status; } @@ -685,7 +685,7 @@ static void pmz_break_ctl(struct uart_port *port, int b= reak_state) else clear_bits |=3D SND_BRK; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 new_reg =3D (uap->curregs[R5] | set_bits) & ~clear_bits; if (new_reg !=3D uap->curregs[R5]) { @@ -693,7 +693,7 @@ static void pmz_break_ctl(struct uart_port *port, int b= reak_state) write_zsreg(uap, R5, uap->curregs[R5]); } =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 #ifdef CONFIG_PPC_PMAC @@ -865,18 +865,18 @@ static void pmz_irda_reset(struct uart_pmac_port *uap) { unsigned long flags; =20 - spin_lock_irqsave(&uap->port.lock, flags); + uart_port_lock_irqsave(&uap->port, &flags); uap->curregs[R5] |=3D DTR; write_zsreg(uap, R5, uap->curregs[R5]); zssync(uap); - spin_unlock_irqrestore(&uap->port.lock, flags); + uart_port_unlock_irqrestore(&uap->port, flags); msleep(110); =20 - spin_lock_irqsave(&uap->port.lock, flags); + uart_port_lock_irqsave(&uap->port, &flags); uap->curregs[R5] &=3D ~DTR; write_zsreg(uap, R5, uap->curregs[R5]); zssync(uap); - spin_unlock_irqrestore(&uap->port.lock, flags); + uart_port_unlock_irqrestore(&uap->port, flags); msleep(10); } =20 @@ -896,9 +896,9 @@ static int pmz_startup(struct uart_port *port) * initialize the chip */ if (!ZS_IS_CONS(uap)) { - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); pwr_delay =3D __pmz_startup(uap); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); }=09 sprintf(uap->irq_name, PMACZILOG_NAME"%d", uap->port.line); if (request_irq(uap->port.irq, pmz_interrupt, IRQF_SHARED, @@ -921,9 +921,9 @@ static int pmz_startup(struct uart_port *port) pmz_irda_reset(uap); =20 /* Enable interrupt requests for the channel */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); pmz_interrupt_control(uap, 1); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return 0; } @@ -933,7 +933,7 @@ static void pmz_shutdown(struct uart_port *port) struct uart_pmac_port *uap =3D to_pmz(port); unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Disable interrupt requests for the channel */ pmz_interrupt_control(uap, 0); @@ -948,19 +948,19 @@ static void pmz_shutdown(struct uart_port *port) pmz_maybe_update_regs(uap); } =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 /* Release interrupt handler */ free_irq(uap->port.irq, uap); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 uap->flags &=3D ~PMACZILOG_FLAG_IS_OPEN; =20 if (!ZS_IS_CONS(uap)) pmz_set_scc_power(uap, 0); /* Shut the chip down */ =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /* Shared by TTY driver and serial console setup. The port lock is held @@ -1247,7 +1247,7 @@ static void pmz_set_termios(struct uart_port *port, s= truct ktermios *termios, struct uart_pmac_port *uap =3D to_pmz(port); unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags);=09 + uart_port_lock_irqsave(port, &flags);=09 =20 /* Disable IRQs on the port */ pmz_interrupt_control(uap, 0); @@ -1259,7 +1259,7 @@ static void pmz_set_termios(struct uart_port *port, s= truct ktermios *termios, if (ZS_IS_OPEN(uap)) pmz_interrupt_control(uap, 1); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *pmz_type(struct uart_port *port) @@ -1896,7 +1896,7 @@ static void pmz_console_write(struct console *con, co= nst char *s, unsigned int c struct uart_pmac_port *uap =3D &pmz_ports[con->index]; unsigned long flags; =20 - spin_lock_irqsave(&uap->port.lock, flags); + uart_port_lock_irqsave(&uap->port, &flags); =20 /* Turn of interrupts and enable the transmitter. */ write_zsreg(uap, R1, uap->curregs[1] & ~TxINT_ENAB); @@ -1908,7 +1908,7 @@ static void pmz_console_write(struct console *con, co= nst char *s, unsigned int c write_zsreg(uap, R1, uap->curregs[1]); /* Don't disable the transmitter. */ =20 - spin_unlock_irqrestore(&uap->port.lock, flags); + uart_port_unlock_irqrestore(&uap->port, flags); } =20 /* --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 729C5EEAA63 for ; Thu, 14 Sep 2023 18:41:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241955AbjINSl3 (ORCPT ); Thu, 14 Sep 2023 14:41:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241654AbjINSjc (ORCPT ); Thu, 14 Sep 2023 14:39:32 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92B1C26B1; Thu, 14 Sep 2023 11:39:00 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716739; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fK/nNCe+HXlWYA1jtYpFGX+8N5k+z0c1fSpVRQqc2rk=; b=KnxkI6k/hF3y8+W7O9QIvNc+adMKQ2QUGFZ/3lmm0NgHEN3IJhCZI78LauOIiQoHvQlCZO Hzf8efjpxWAdhzn3geATG+Ctps4UM/4ayr1bJAd+pMiRBgAzT5I7slfldiaNYEAA3Hb0ZV PSIK+TrTGd0T+7ceE12dD1dRtG+iDCwdCwwSDCXCKywKzqeLbiI+F8q8EaYoXWDU7KbhkE LTc9cu2kxwqZHLRnjMAk5W4nK3HAI5zhl1zFYvSb7/R67E1o7cdHd1wHEzI+YlHcMudCvv PEMH4V6QM5UlR1pumuKByd4XaSgO41p1UNNJmA+p50Nmtlk/SQ3Bxb7tz3PQqQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716739; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fK/nNCe+HXlWYA1jtYpFGX+8N5k+z0c1fSpVRQqc2rk=; b=EHf+GclZBZ+3/IXgMoulZgM+BxHIK+t+y68aErfnSuGEgMXJaijQwUu7quwfYkLzVhYlRF 9A2MKiFd4Q9sqNDA== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Thierry Reding , Richard GENOUD Subject: [PATCH tty v1 48/74] serial: pxa: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:05 +0206 Message-Id: <20230914183831.587273-49-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/pxa.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/tty/serial/pxa.c b/drivers/tty/serial/pxa.c index 73c60f5ea027..46e70e155aab 100644 --- a/drivers/tty/serial/pxa.c +++ b/drivers/tty/serial/pxa.c @@ -225,14 +225,14 @@ static inline irqreturn_t serial_pxa_irq(int irq, voi= d *dev_id) iir =3D serial_in(up, UART_IIR); if (iir & UART_IIR_NO_INT) return IRQ_NONE; - spin_lock(&up->port.lock); + uart_port_lock(&up->port); lsr =3D serial_in(up, UART_LSR); if (lsr & UART_LSR_DR) receive_chars(up, &lsr); check_modem_status(up); if (lsr & UART_LSR_THRE) transmit_chars(up); - spin_unlock(&up->port.lock); + uart_port_unlock(&up->port); return IRQ_HANDLED; } =20 @@ -242,9 +242,9 @@ static unsigned int serial_pxa_tx_empty(struct uart_por= t *port) unsigned long flags; unsigned int ret; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); ret =3D serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0; - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =20 return ret; } @@ -295,13 +295,13 @@ static void serial_pxa_break_ctl(struct uart_port *po= rt, int break_state) struct uart_pxa_port *up =3D (struct uart_pxa_port *)port; unsigned long flags; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); if (break_state =3D=3D -1) up->lcr |=3D UART_LCR_SBC; else up->lcr &=3D ~UART_LCR_SBC; serial_out(up, UART_LCR, up->lcr); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 static int serial_pxa_startup(struct uart_port *port) @@ -346,10 +346,10 @@ static int serial_pxa_startup(struct uart_port *port) */ serial_out(up, UART_LCR, UART_LCR_WLEN8); =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); up->port.mctrl |=3D TIOCM_OUT2; serial_pxa_set_mctrl(&up->port, up->port.mctrl); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =20 /* * Finally, enable interrupts. Note: Modem status interrupts @@ -383,10 +383,10 @@ static void serial_pxa_shutdown(struct uart_port *por= t) up->ier =3D 0; serial_out(up, UART_IER, 0); =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); up->port.mctrl &=3D ~TIOCM_OUT2; serial_pxa_set_mctrl(&up->port, up->port.mctrl); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =20 /* * Disable break condition and FIFOs @@ -434,7 +434,7 @@ serial_pxa_set_termios(struct uart_port *port, struct k= termios *termios, * Ok, we're now changing the port state. Do it with * interrupts disabled. */ - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 /* * Ensure the port will be enabled. @@ -504,7 +504,7 @@ serial_pxa_set_termios(struct uart_port *port, struct k= termios *termios, up->lcr =3D cval; /* Save LCR */ serial_pxa_set_mctrl(&up->port, up->port.mctrl); serial_out(up, UART_FCR, fcr); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 static void @@ -608,9 +608,9 @@ serial_pxa_console_write(struct console *co, const char= *s, unsigned int count) if (up->port.sysrq) locked =3D 0; else if (oops_in_progress) - locked =3D spin_trylock(&up->port.lock); + locked =3D uart_port_trylock(&up->port); else - spin_lock(&up->port.lock); + uart_port_lock(&up->port); =20 /* * First save the IER then disable the interrupts @@ -628,7 +628,7 @@ serial_pxa_console_write(struct console *co, const char= *s, unsigned int count) serial_out(up, UART_IER, ier); =20 if (locked) - spin_unlock(&up->port.lock); + uart_port_unlock(&up->port); local_irq_restore(flags); clk_disable(up->clk); =20 --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C658EEAA5D for ; Thu, 14 Sep 2023 18:41:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241968AbjINSld (ORCPT ); Thu, 14 Sep 2023 14:41:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241947AbjINSjf (ORCPT ); Thu, 14 Sep 2023 14:39:35 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D38CC26B3; Thu, 14 Sep 2023 11:39:00 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716739; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=17zj637DQkryRYGb4/9wkWuly22RRdW4LfXIGp3ap80=; b=gJJt8ECptIei3pjqa8XEVI+Fwjnumc3jdwgKHE1l8lrc9aoruj1uhfU5thGoUQktKtVykB i9R0cnq6YsLdnagbYQxc7STHZFFZgEdYBFjDL/zlU1nFx1KTdKV1QqmYZND5Suu3uV8NBj e5GZbEMgaCAS2mUB2re+7iJgGrmGCxjoDuVMlC5AiBvUn2LnOt/r+bI1n7lVDOxE2NPcll bGvchLP71BEje107RFPk4AJD8Nbi/r5tYyiUXkKmPxwGPVyD5j++W5xMPY1FyGWqKhncW2 wPHWMbjrp4EJyL6zrnGddSIClo6BeuWKR12+6RqpXNt2sS6CIYakWxIy9AFx1A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716739; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=17zj637DQkryRYGb4/9wkWuly22RRdW4LfXIGp3ap80=; b=trnfmLCq598rEijUt+3jLrOeWMN5bTzCu2nDNdwBc7BKdrhgvOzyjV0oc1f/S8ypF8LsKA gYEZTR+YnQA9qxDg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Andy Gross , Bjorn Andersson , Konrad Dybcio , linux-arm-msm@vger.kernel.org Subject: [PATCH tty v1 49/74] serial: qcom-geni: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:06 +0206 Message-Id: <20230914183831.587273-50-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner Reviewed-by: Bjorn Andersson --- drivers/tty/serial/qcom_geni_serial.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qco= m_geni_serial.c index b8aa4c1293ba..7e78f97e8f43 100644 --- a/drivers/tty/serial/qcom_geni_serial.c +++ b/drivers/tty/serial/qcom_geni_serial.c @@ -482,9 +482,9 @@ static void qcom_geni_serial_console_write(struct conso= le *co, const char *s, =20 uport =3D &port->uport; if (oops_in_progress) - locked =3D spin_trylock_irqsave(&uport->lock, flags); + locked =3D uart_port_trylock_irqsave(uport, &flags); else - spin_lock_irqsave(&uport->lock, flags); + uart_port_lock_irqsave(uport, &flags); =20 geni_status =3D readl(uport->membase + SE_GENI_STATUS); =20 @@ -520,7 +520,7 @@ static void qcom_geni_serial_console_write(struct conso= le *co, const char *s, qcom_geni_serial_setup_tx(uport, port->tx_remaining); =20 if (locked) - spin_unlock_irqrestore(&uport->lock, flags); + uart_port_unlock_irqrestore(uport, flags); } =20 static void handle_rx_console(struct uart_port *uport, u32 bytes, bool dro= p) @@ -970,7 +970,7 @@ static irqreturn_t qcom_geni_serial_isr(int isr, void *= dev) if (uport->suspended) return IRQ_NONE; =20 - spin_lock(&uport->lock); + uart_port_lock(uport); =20 m_irq_status =3D readl(uport->membase + SE_GENI_M_IRQ_STATUS); s_irq_status =3D readl(uport->membase + SE_GENI_S_IRQ_STATUS); --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE47DEEAA62 for ; Thu, 14 Sep 2023 18:41:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242124AbjINSlf (ORCPT ); Thu, 14 Sep 2023 14:41:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241950AbjINSjg (ORCPT ); Thu, 14 Sep 2023 14:39:36 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C32E26BB; Thu, 14 Sep 2023 11:39:01 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716739; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xbi6ZcqJKE3YV+23Qffw0pLz0RYvkutvE/pwCYcIpIU=; b=guscnvbH3xPwbP+aL/7s3SwmMOkW0zx82BWDQybOxwIoh5gxBCtzLIYRBPTU0J4ImsDnpw GCm9uxnJFnABZoJYWtcbcfS+vXjyYR69JgXDNNGeheTxL1KVVYbKARF8yIOPy09GlAmDIZ /q3e0pBeZijD4pzizelWQ10mScK0Fg1SM/85C+6j3dm8/gLnsoviyUvU3+SX+mIUUVvT0g 4saz5zi3uUwuPeiTtz6rsD6Xgklcb3HHCcOX8dk8Wskvk9TA0YlqXf+EVueVOqqj+Lmfsq k2Af4BW/P/zw+2ToyhhbsD04/LUKNXzkzNNNpaRGAnC+1+j5zHVZ7CjYWaR9rw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716739; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xbi6ZcqJKE3YV+23Qffw0pLz0RYvkutvE/pwCYcIpIU=; b=tYIvkFmNZnd02WfkkyrFWmB5h3JaSqh5akiZaq7FS7IXkXS/Q5AlBjqElEdr+dGcTigG2f nMeUnymk1/5FtFCw== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Manivannan Sadhasivam , linux-arm-kernel@lists.infradead.org, linux-unisoc@lists.infradead.org Subject: [PATCH tty v1 50/74] serial: rda: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:07 +0206 Message-Id: <20230914183831.587273-51-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/rda-uart.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/tty/serial/rda-uart.c b/drivers/tty/serial/rda-uart.c index be5c842b5ba9..d824c8318f33 100644 --- a/drivers/tty/serial/rda-uart.c +++ b/drivers/tty/serial/rda-uart.c @@ -139,12 +139,12 @@ static unsigned int rda_uart_tx_empty(struct uart_por= t *port) unsigned int ret; u32 val; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 val =3D rda_uart_read(port, RDA_UART_STATUS); ret =3D (val & RDA_UART_TX_FIFO_MASK) ? TIOCSER_TEMT : 0; =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return ret; } @@ -246,7 +246,7 @@ static void rda_uart_set_termios(struct uart_port *port, unsigned int baud; u32 irq_mask; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 baud =3D uart_get_baud_rate(port, termios, old, 9600, port->uartclk / 4); rda_uart_change_baudrate(rda_port, baud); @@ -325,7 +325,7 @@ static void rda_uart_set_termios(struct uart_port *port, /* update the per-port timeout */ uart_update_timeout(port, termios->c_cflag, baud); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void rda_uart_send_chars(struct uart_port *port) @@ -408,7 +408,7 @@ static irqreturn_t rda_interrupt(int irq, void *dev_id) unsigned long flags; u32 val, irq_mask; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Clear IRQ cause */ val =3D rda_uart_read(port, RDA_UART_IRQ_CAUSE); @@ -425,7 +425,7 @@ static irqreturn_t rda_interrupt(int irq, void *dev_id) rda_uart_send_chars(port); } =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return IRQ_HANDLED; } @@ -436,16 +436,16 @@ static int rda_uart_startup(struct uart_port *port) int ret; u32 val; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); rda_uart_write(port, 0, RDA_UART_IRQ_MASK); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 ret =3D request_irq(port->irq, rda_interrupt, IRQF_NO_SUSPEND, "rda-uart", port); if (ret) return ret; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 val =3D rda_uart_read(port, RDA_UART_CTRL); val |=3D RDA_UART_ENABLE; @@ -456,7 +456,7 @@ static int rda_uart_startup(struct uart_port *port) val |=3D (RDA_UART_RX_DATA_AVAILABLE | RDA_UART_RX_TIMEOUT); rda_uart_write(port, val, RDA_UART_IRQ_MASK); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return 0; } @@ -466,7 +466,7 @@ static void rda_uart_shutdown(struct uart_port *port) unsigned long flags; u32 val; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 rda_uart_stop_tx(port); rda_uart_stop_rx(port); @@ -475,7 +475,7 @@ static void rda_uart_shutdown(struct uart_port *port) val &=3D ~RDA_UART_ENABLE; rda_uart_write(port, val, RDA_UART_CTRL); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *rda_uart_type(struct uart_port *port) @@ -515,7 +515,7 @@ static void rda_uart_config_port(struct uart_port *port= , int flags) rda_uart_request_port(port); } =20 - spin_lock_irqsave(&port->lock, irq_flags); + uart_port_lock_irqsave(port, &irq_flags); =20 /* Clear mask, so no surprise interrupts. */ rda_uart_write(port, 0, RDA_UART_IRQ_MASK); @@ -523,7 +523,7 @@ static void rda_uart_config_port(struct uart_port *port= , int flags) /* Clear status register */ rda_uart_write(port, 0, RDA_UART_STATUS); =20 - spin_unlock_irqrestore(&port->lock, irq_flags); + uart_port_unlock_irqrestore(port, irq_flags); } =20 static void rda_uart_release_port(struct uart_port *port) @@ -597,9 +597,9 @@ static void rda_uart_port_write(struct uart_port *port,= const char *s, if (port->sysrq) { locked =3D 0; } else if (oops_in_progress) { - locked =3D spin_trylock(&port->lock); + locked =3D uart_port_trylock(port); } else { - spin_lock(&port->lock); + uart_port_lock(port); locked =3D 1; } =20 @@ -615,7 +615,7 @@ static void rda_uart_port_write(struct uart_port *port,= const char *s, rda_uart_write(port, old_irq_mask, RDA_UART_IRQ_MASK); =20 if (locked) - spin_unlock(&port->lock); + uart_port_unlock(port); =20 local_irq_restore(flags); } --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08AFEEEAA5D for ; Thu, 14 Sep 2023 18:41:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242128AbjINSli (ORCPT ); Thu, 14 Sep 2023 14:41:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241918AbjINSjg (ORCPT ); Thu, 14 Sep 2023 14:39:36 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A92DB2701; Thu, 14 Sep 2023 11:39:01 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716740; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wEqDaVJQVqGX9YVn2BD87JacVQ7J8Oaoh/OqCs9R0Bw=; b=M8E4l2ZSQCM+fzelBT40soSJQ49RE94oh76LR7unQ9Qr0D1BTamTJxsfaxIOrIyKsXqM4Q TZnzsgOR+e4jrE3czEBVY62d/bvRppdl/gMx1sZMzfhbJGm8ZD99i9YBq2wUB1FEMKug58 yEx4CnYWkntZEq66h9/jYqXVrpAOIVAAAFH2813wX+XmjlPWeQLOsmD29taNXz8+KmOS8y nKkXYxhsFzW9HpzVfZfzZ3huMy2RbFAb9ulGkycMpoOGPsUKY9rLN8sI+2PmvU1oxhglLy xttwahzwecqnnG5T4YCPFNyQucl9GVL7HK9hol4BmmUg5u7QjTwjiQZH1IRxnw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716740; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wEqDaVJQVqGX9YVn2BD87JacVQ7J8Oaoh/OqCs9R0Bw=; b=481xDhaTxt22pkHVkWf5eB+vMa1cJVph7J/xdQcvkLU87hhOwi8Og7JNujmxumwgWas9+5 p8Uaq4O5e8uTatBA== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Kevin Cernekee , Tobias Klauser , Thierry Reding , Richard GENOUD Subject: [PATCH tty v1 51/74] serial: rp2: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:08 +0206 Message-Id: <20230914183831.587273-52-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/rp2.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/rp2.c b/drivers/tty/serial/rp2.c index de220ac8ca54..d46a81cddfcd 100644 --- a/drivers/tty/serial/rp2.c +++ b/drivers/tty/serial/rp2.c @@ -276,9 +276,9 @@ static unsigned int rp2_uart_tx_empty(struct uart_port = *port) * But the TXEMPTY bit doesn't seem to work unless the TX IRQ is * enabled. */ - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); tx_fifo_bytes =3D readw(up->base + RP2_TX_FIFO_COUNT); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =20 return tx_fifo_bytes ? 0 : TIOCSER_TEMT; } @@ -323,10 +323,10 @@ static void rp2_uart_break_ctl(struct uart_port *port= , int break_state) { unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); rp2_rmw(port_to_up(port), RP2_TXRX_CTL, RP2_TXRX_CTL_BREAK_m, break_state ? RP2_TXRX_CTL_BREAK_m : 0); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void rp2_uart_enable_ms(struct uart_port *port) @@ -383,7 +383,7 @@ static void rp2_uart_set_termios(struct uart_port *port= , struct ktermios *new, if (tty_termios_baud_rate(new)) tty_termios_encode_baud_rate(new, baud, baud); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* ignore all characters if CREAD is not set */ port->ignore_status_mask =3D (new->c_cflag & CREAD) ? 0 : RP2_DUMMY_READ; @@ -391,7 +391,7 @@ static void rp2_uart_set_termios(struct uart_port *port= , struct ktermios *new, __rp2_uart_set_termios(up, new->c_cflag, new->c_iflag, baud_div); uart_update_timeout(port, new->c_cflag, baud); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void rp2_rx_chars(struct rp2_uart_port *up) @@ -440,7 +440,7 @@ static void rp2_ch_interrupt(struct rp2_uart_port *up) { u32 status; =20 - spin_lock(&up->port.lock); + uart_port_lock(&up->port); =20 /* * The IRQ status bits are clear-on-write. Other status bits in @@ -456,7 +456,7 @@ static void rp2_ch_interrupt(struct rp2_uart_port *up) if (status & RP2_CHAN_STAT_MS_CHANGED_MASK) wake_up_interruptible(&up->port.state->port.delta_msr_wait); =20 - spin_unlock(&up->port.lock); + uart_port_unlock(&up->port); } =20 static int rp2_asic_interrupt(struct rp2_card *card, unsigned int asic_id) @@ -516,10 +516,10 @@ static void rp2_uart_shutdown(struct uart_port *port) =20 rp2_uart_break_ctl(port, 0); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); rp2_mask_ch_irq(up, up->idx, 0); rp2_rmw(up, RP2_CHAN_STAT, 0, 0); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *rp2_uart_type(struct uart_port *port) --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CB99EEAA5D for ; Thu, 14 Sep 2023 18:41:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241975AbjINSlm (ORCPT ); Thu, 14 Sep 2023 14:41:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241971AbjINSjm (ORCPT ); Thu, 14 Sep 2023 14:39:42 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 235D52705; Thu, 14 Sep 2023 11:39:02 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716740; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4go78jqQjBoLjBGzmCHOv9NrC20UwwVa764/6PmFVf4=; b=KycCGl+Z0tSDZryL3lQvmTDKcENvZ0bElfbOFWqhLIP3byAP8mJeI8s7trSAyJ04mQsP2N 1/M3CFlEDWRY4Z5SF8LpTdGxlleEfdxtDAci9kbM93yX+OoCLRndlWnDkjX9SKjrnzp/5r lorsjYHtyFt5l2tvoeCNi95kjntjmBRR2DCVB41fw2zUWbr1VVIhrzZ9cEfdmvwIGCQfMN /tQ3hy7AwDUhqDzBhBfrALwSGfKsBc6a3fEJAD01Miv3D8x8TQnVNgKkBI7QOpEW0GQGtN DLVoatFnfmYeO9QruW6684ou7F878JmG8Kr9OaSmLDT6TYpvas/aNOo7t/Q32w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716740; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4go78jqQjBoLjBGzmCHOv9NrC20UwwVa764/6PmFVf4=; b=0CSYNn68lqfVz1Tm7+KGTJLruBkCCmjvrxg4X3MZa6H8cRhjyOQ8S2f5ycLq3ZJtfVSNjo aLXikOoIdOkjNHCA== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Thierry Reding , Tobias Klauser Subject: [PATCH tty v1 52/74] serial: sa1100: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:09 +0206 Message-Id: <20230914183831.587273-53-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/sa1100.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/sa1100.c b/drivers/tty/serial/sa1100.c index ad011f1e2f4d..be7bcd75d9f4 100644 --- a/drivers/tty/serial/sa1100.c +++ b/drivers/tty/serial/sa1100.c @@ -115,9 +115,9 @@ static void sa1100_timeout(struct timer_list *t) unsigned long flags; =20 if (sport->port.state) { - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); sa1100_mctrl_check(sport); - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); =20 mod_timer(&sport->timer, jiffies + MCTRL_TIMEOUT); } @@ -247,7 +247,7 @@ static irqreturn_t sa1100_int(int irq, void *dev_id) struct sa1100_port *sport =3D dev_id; unsigned int status, pass_counter =3D 0; =20 - spin_lock(&sport->port.lock); + uart_port_lock(&sport->port); status =3D UART_GET_UTSR0(sport); status &=3D SM_TO_UTSR0(sport->port.read_status_mask) | ~UTSR0_TFS; do { @@ -276,7 +276,7 @@ static irqreturn_t sa1100_int(int irq, void *dev_id) status &=3D SM_TO_UTSR0(sport->port.read_status_mask) | ~UTSR0_TFS; } while (status & (UTSR0_TFS | UTSR0_RFS | UTSR0_RID)); - spin_unlock(&sport->port.lock); + uart_port_unlock(&sport->port); =20 return IRQ_HANDLED; } @@ -321,14 +321,14 @@ static void sa1100_break_ctl(struct uart_port *port, = int break_state) unsigned long flags; unsigned int utcr3; =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); utcr3 =3D UART_GET_UTCR3(sport); if (break_state =3D=3D -1) utcr3 |=3D UTCR3_BRK; else utcr3 &=3D ~UTCR3_BRK; UART_PUT_UTCR3(sport, utcr3); - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); } =20 static int sa1100_startup(struct uart_port *port) @@ -354,9 +354,9 @@ static int sa1100_startup(struct uart_port *port) /* * Enable modem status interrupts */ - spin_lock_irq(&sport->port.lock); + uart_port_lock_irq(&sport->port); sa1100_enable_ms(&sport->port); - spin_unlock_irq(&sport->port.lock); + uart_port_unlock_irq(&sport->port); =20 return 0; } @@ -423,7 +423,7 @@ sa1100_set_termios(struct uart_port *port, struct kterm= ios *termios, =20 del_timer_sync(&sport->timer); =20 - spin_lock_irqsave(&sport->port.lock, flags); + uart_port_lock_irqsave(&sport->port, &flags); =20 sport->port.read_status_mask &=3D UTSR0_TO_SM(UTSR0_TFS); sport->port.read_status_mask |=3D UTSR1_TO_SM(UTSR1_ROR); @@ -485,7 +485,7 @@ sa1100_set_termios(struct uart_port *port, struct kterm= ios *termios, if (UART_ENABLE_MS(&sport->port, termios->c_cflag)) sa1100_enable_ms(&sport->port); =20 - spin_unlock_irqrestore(&sport->port.lock, flags); + uart_port_unlock_irqrestore(&sport->port, flags); } =20 static const char *sa1100_type(struct uart_port *port) --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E209DEEAA63 for ; Thu, 14 Sep 2023 18:41:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242155AbjINSlo (ORCPT ); Thu, 14 Sep 2023 14:41:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241753AbjINSjm (ORCPT ); Thu, 14 Sep 2023 14:39:42 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D2C42707; Thu, 14 Sep 2023 11:39:02 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716741; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qttz2Zye8dewxe2yu3IfFjIwUKo7e2lw5/ENF/e0X64=; b=NUjK3jpFQs7jZTpqBLqY3JsZANQlQqU0GVeQ01KgZT2ME3tLf8YM4mN3iv9+vfUyYsVQk4 n3JGkw1slr85vKv0kLDTkti5JMnJi9kzVAiMrysRVNQFL4k2xWiLQyKdtyIF4RXMBijXXe xwBIVXzc4HV8WBzR/WcSFSQvpHyZwI/4AuApR59K+0E6tR0L0+NI6U7BYxT+XDfZ/19HmN I5wu+gaqariEKjYv+AiB5R8862q8jy4rUXOYkc/pnMJRO8OGj7Rt3t+K9hHJ8qY7jld1OH gmMUQGcwO1NKRVypbl0dHj25WdQDlw1mS++aKLeBtCt9dQ48eunYvMh+R3yrQw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716741; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qttz2Zye8dewxe2yu3IfFjIwUKo7e2lw5/ENF/e0X64=; b=y/tx11EVlDAUgiMGP5zaCQwjkVqZtznCutfJOZCoohhre/Pmh+/qyBdzcJrnl1up58z/+r +pS246x0AzADL+Aw== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Krzysztof Kozlowski , Alim Akhtar , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org Subject: [PATCH tty v1 53/74] serial: samsung_tty: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:10 +0206 Message-Id: <20230914183831.587273-54-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/samsung_tty.c | 50 ++++++++++++++++---------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_= tty.c index 07fb8a9dac63..ee51a0368a55 100644 --- a/drivers/tty/serial/samsung_tty.c +++ b/drivers/tty/serial/samsung_tty.c @@ -248,7 +248,7 @@ static void s3c24xx_serial_rx_enable(struct uart_port *= port) unsigned int ucon, ufcon; int count =3D 10000; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 while (--count && !s3c24xx_serial_txempty_nofifo(port)) udelay(100); @@ -262,7 +262,7 @@ static void s3c24xx_serial_rx_enable(struct uart_port *= port) wr_regl(port, S3C2410_UCON, ucon); =20 ourport->rx_enabled =3D 1; - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void s3c24xx_serial_rx_disable(struct uart_port *port) @@ -271,14 +271,14 @@ static void s3c24xx_serial_rx_disable(struct uart_por= t *port) unsigned long flags; unsigned int ucon; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 ucon =3D rd_regl(port, S3C2410_UCON); ucon &=3D ~S3C2410_UCON_RXIRQMODE; wr_regl(port, S3C2410_UCON, ucon); =20 ourport->rx_enabled =3D 0; - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void s3c24xx_serial_stop_tx(struct uart_port *port) @@ -344,7 +344,7 @@ static void s3c24xx_serial_tx_dma_complete(void *args) dma->tx_transfer_addr, dma->tx_size, DMA_TO_DEVICE); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 uart_xmit_advance(port, count); ourport->tx_in_progress =3D 0; @@ -353,7 +353,7 @@ static void s3c24xx_serial_tx_dma_complete(void *args) uart_write_wakeup(port); =20 s3c24xx_serial_start_next_tx(ourport); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void enable_tx_dma(struct s3c24xx_uart_port *ourport) @@ -619,7 +619,7 @@ static void s3c24xx_serial_rx_dma_complete(void *args) received =3D dma->rx_bytes_requested - state.residue; async_tx_ack(dma->rx_desc); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 if (received) s3c24xx_uart_copy_rx_to_tty(ourport, t, received); @@ -631,7 +631,7 @@ static void s3c24xx_serial_rx_dma_complete(void *args) =20 s3c64xx_start_rx_dma(ourport); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void s3c64xx_start_rx_dma(struct s3c24xx_uart_port *ourport) @@ -722,7 +722,7 @@ static irqreturn_t s3c24xx_serial_rx_chars_dma(void *de= v_id) utrstat =3D rd_regl(port, S3C2410_UTRSTAT); rd_regl(port, S3C2410_UFSTAT); =20 - spin_lock(&port->lock); + uart_port_lock(port); =20 if (!(utrstat & S3C2410_UTRSTAT_TIMEOUT)) { s3c64xx_start_rx_dma(ourport); @@ -751,7 +751,7 @@ static irqreturn_t s3c24xx_serial_rx_chars_dma(void *de= v_id) wr_regl(port, S3C2410_UTRSTAT, S3C2410_UTRSTAT_TIMEOUT); =20 finish: - spin_unlock(&port->lock); + uart_port_unlock(port); =20 return IRQ_HANDLED; } @@ -849,9 +849,9 @@ static irqreturn_t s3c24xx_serial_rx_chars_pio(void *de= v_id) struct s3c24xx_uart_port *ourport =3D dev_id; struct uart_port *port =3D &ourport->port; =20 - spin_lock(&port->lock); + uart_port_lock(port); s3c24xx_serial_rx_drain_fifo(ourport); - spin_unlock(&port->lock); + uart_port_unlock(port); =20 return IRQ_HANDLED; } @@ -932,11 +932,11 @@ static irqreturn_t s3c24xx_serial_tx_irq(int irq, voi= d *id) struct s3c24xx_uart_port *ourport =3D id; struct uart_port *port =3D &ourport->port; =20 - spin_lock(&port->lock); + uart_port_lock(port); =20 s3c24xx_serial_tx_chars(ourport); =20 - spin_unlock(&port->lock); + uart_port_unlock(port); return IRQ_HANDLED; } =20 @@ -1033,7 +1033,7 @@ static void s3c24xx_serial_break_ctl(struct uart_port= *port, int break_state) unsigned long flags; unsigned int ucon; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 ucon =3D rd_regl(port, S3C2410_UCON); =20 @@ -1044,7 +1044,7 @@ static void s3c24xx_serial_break_ctl(struct uart_port= *port, int break_state) =20 wr_regl(port, S3C2410_UCON, ucon); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static int s3c24xx_serial_request_dma(struct s3c24xx_uart_port *p) @@ -1303,7 +1303,7 @@ static int s3c64xx_serial_startup(struct uart_port *p= ort) ourport->rx_enabled =3D 1; ourport->tx_enabled =3D 0; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 ufcon =3D rd_regl(port, S3C2410_UFCON); ufcon |=3D S3C2410_UFCON_RESETRX | S5PV210_UFCON_RXTRIG8; @@ -1313,7 +1313,7 @@ static int s3c64xx_serial_startup(struct uart_port *p= ort) =20 enable_rx_pio(ourport); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 /* Enable Rx Interrupt */ s3c24xx_clear_bit(port, S3C64XX_UINTM_RXD, S3C64XX_UINTM); @@ -1341,7 +1341,7 @@ static int apple_s5l_serial_startup(struct uart_port = *port) ourport->rx_enabled =3D 1; ourport->tx_enabled =3D 0; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 ufcon =3D rd_regl(port, S3C2410_UFCON); ufcon |=3D S3C2410_UFCON_RESETRX | S5PV210_UFCON_RXTRIG8; @@ -1351,7 +1351,7 @@ static int apple_s5l_serial_startup(struct uart_port = *port) =20 enable_rx_pio(ourport); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 /* Enable Rx Interrupt */ s3c24xx_set_bit(port, APPLE_S5L_UCON_RXTHRESH_ENA, S3C2410_UCON); @@ -1626,7 +1626,7 @@ static void s3c24xx_serial_set_termios(struct uart_po= rt *port, ulcon |=3D S3C2410_LCON_PNONE; } =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 dev_dbg(port->dev, "setting ulcon to %08x, brddiv to %d, udivslot %08x\n", @@ -1684,7 +1684,7 @@ static void s3c24xx_serial_set_termios(struct uart_po= rt *port, if ((termios->c_cflag & CREAD) =3D=3D 0) port->ignore_status_mask |=3D RXSTAT_DUMMY_READ; =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *s3c24xx_serial_type(struct uart_port *port) @@ -2376,14 +2376,14 @@ s3c24xx_serial_console_write(struct console *co, co= nst char *s, if (cons_uart->sysrq) locked =3D false; else if (oops_in_progress) - locked =3D spin_trylock_irqsave(&cons_uart->lock, flags); + locked =3D uart_port_trylock_irqsave(cons_uart, &flags); else - spin_lock_irqsave(&cons_uart->lock, flags); + uart_port_lock_irqsave(cons_uart, &flags); =20 uart_console_write(cons_uart, s, count, s3c24xx_serial_console_putchar); =20 if (locked) - spin_unlock_irqrestore(&cons_uart->lock, flags); + uart_port_unlock_irqrestore(cons_uart, flags); } =20 /* Shouldn't be __init, as it can be instantiated from other module */ --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DC6EEEAA5D for ; Thu, 14 Sep 2023 18:41:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242157AbjINSlr (ORCPT ); Thu, 14 Sep 2023 14:41:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241980AbjINSjo (ORCPT ); Thu, 14 Sep 2023 14:39:44 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD9A8270D; Thu, 14 Sep 2023 11:39:02 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716741; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fQN7epFxbwh1qF9A3vKlWoOOC6pmuH30heIRIdUdCsw=; b=hmi62IBJprhrBskt+oHKNc4Krp4W/jSVkKbugl+EiEnzpg4bnHZL6tDuwSP35MvhOJqTBF Y2qIjTqZkiorNeiPqCopzo2FMj8YkX/23kq1/zgSju9fnqtV2cfdcWGQA/AtPwUxPW57Ab 4oVbbBmc8Z24NcuPQGwoujNWqBXYpC71pnzj679o/3ud01fI/bc+znMfqELboL6XUIYdP0 Px0Vb2U0dxClP0Y/t+BHowHcGm9a/kyfT4WJpf3gLYLaQD0U6oHrOsYQxdw2n//tEF5MEd 8Fi0Fy7EDg74h00xumLAfvfn2pLsMclcPViRc62XZEe6QTpNztkni3Jvpud+5A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716741; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fQN7epFxbwh1qF9A3vKlWoOOC6pmuH30heIRIdUdCsw=; b=kfyQuSVNlXEbogFR65EguwGNHtAhOMowXzjYr76Qoe01RXQd/iZhZ694cqLNmiITysx3Ms BDxZXp3l3vPr59BQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Richard GENOUD , Thierry Reding , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Lukas Bulwahn Subject: [PATCH tty v1 54/74] serial: sb1250-duart: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:11 +0206 Message-Id: <20230914183831.587273-55-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/sb1250-duart.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/tty/serial/sb1250-duart.c b/drivers/tty/serial/sb1250-= duart.c index f3cd69346482..dbec29d9a6c3 100644 --- a/drivers/tty/serial/sb1250-duart.c +++ b/drivers/tty/serial/sb1250-duart.c @@ -610,7 +610,7 @@ static void sbd_set_termios(struct uart_port *uport, st= ruct ktermios *termios, else aux &=3D ~M_DUART_CTS_CHNG_ENA; =20 - spin_lock(&uport->lock); + uart_port_lock(uport); =20 if (sport->tx_stopped) command |=3D M_DUART_TX_DIS; @@ -632,7 +632,7 @@ static void sbd_set_termios(struct uart_port *uport, st= ruct ktermios *termios, =20 write_sbdchn(sport, R_DUART_CMD, command); =20 - spin_unlock(&uport->lock); + uart_port_unlock(uport); } =20 =20 @@ -839,22 +839,22 @@ static void sbd_console_write(struct console *co, con= st char *s, unsigned int mask; =20 /* Disable transmit interrupts and enable the transmitter. */ - spin_lock_irqsave(&uport->lock, flags); + uart_port_lock_irqsave(uport, &flags); mask =3D read_sbdshr(sport, R_DUART_IMRREG((uport->line) % 2)); write_sbdshr(sport, R_DUART_IMRREG((uport->line) % 2), mask & ~M_DUART_IMR_TX); write_sbdchn(sport, R_DUART_CMD, M_DUART_TX_EN); - spin_unlock_irqrestore(&uport->lock, flags); + uart_port_unlock_irqrestore(uport, flags); =20 uart_console_write(&sport->port, s, count, sbd_console_putchar); =20 /* Restore transmit interrupts and the transmitter enable. */ - spin_lock_irqsave(&uport->lock, flags); + uart_port_lock_irqsave(uport, &flags); sbd_line_drain(sport); if (sport->tx_stopped) write_sbdchn(sport, R_DUART_CMD, M_DUART_TX_DIS); write_sbdshr(sport, R_DUART_IMRREG((uport->line) % 2), mask); - spin_unlock_irqrestore(&uport->lock, flags); + uart_port_unlock_irqrestore(uport, flags); } =20 static int __init sbd_console_setup(struct console *co, char *options) --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25F98EEAA5D for ; Thu, 14 Sep 2023 18:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242125AbjINSlu (ORCPT ); Thu, 14 Sep 2023 14:41:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241993AbjINSj5 (ORCPT ); Thu, 14 Sep 2023 14:39:57 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D03EE2713; Thu, 14 Sep 2023 11:39:03 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zy6q0L16Kf/KS6E7GOqWz6KYdIr63xhUHPEN74PlZEE=; b=O92aHgkVbGKPJl2oWelrZRGt1hi4ABLEooGQ4nQ9fCBmHNvENAraqDtpqPzxFMlxHv2SYg vs16YS6VAZvUSjTum3CqnCHtjaiEHzehqMRfoTA8QZ8++r/yGaNP6Xb4+h+8T9WDfggheH 10H0J/LPuz9H4l1GiMulPxSc+OfDZycHKF+O10GVr9ypv2MGkwGIMmPn0GdBRRoGNpqDrT MVKX86GnRPFOPvsNuCxNN0KyYuuBiy8f/fxQHcRsFMI3GCUp+faWu11v4RJJ8MibW5K9+s ypVwnSHBmyq5LmbgpSg/l/Ek0mCkFRnVTV9T3t2z/cB7BbWlvkf8//sARgINeA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zy6q0L16Kf/KS6E7GOqWz6KYdIr63xhUHPEN74PlZEE=; b=xq0a3lU7Ye8KLD0iDn7GDbg27VseXJ6HbyT3vmZtU5JRykbFWRlis6URvJgMHHS34BCNDL YMeQ8ccCDr68/WDg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Lech Perczak , Hugo Villeneuve , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Andy Shevchenko , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Isaac True Subject: [PATCH tty v1 55/74] serial: sc16is7xx: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:12 +0206 Message-Id: <20230914183831.587273-56-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/sc16is7xx.c | 40 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c index f61d98e09dc3..9d8307f5fc36 100644 --- a/drivers/tty/serial/sc16is7xx.c +++ b/drivers/tty/serial/sc16is7xx.c @@ -667,9 +667,9 @@ static void sc16is7xx_handle_tx(struct uart_port *port) } =20 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); sc16is7xx_stop_tx(port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); return; } =20 @@ -695,13 +695,13 @@ static void sc16is7xx_handle_tx(struct uart_port *por= t) sc16is7xx_fifo_write(port, to_send); } =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) uart_write_wakeup(port); =20 if (uart_circ_empty(xmit)) sc16is7xx_stop_tx(port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static unsigned int sc16is7xx_get_hwmctrl(struct uart_port *port) @@ -733,7 +733,7 @@ static void sc16is7xx_update_mlines(struct sc16is7xx_on= e *one) =20 one->old_mctrl =3D status; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); if ((changed & TIOCM_RNG) && (status & TIOCM_RNG)) port->icount.rng++; if (changed & TIOCM_DSR) @@ -744,7 +744,7 @@ static void sc16is7xx_update_mlines(struct sc16is7xx_on= e *one) uart_handle_cts_change(port, status & TIOCM_CTS); =20 wake_up_interruptible(&port->state->port.delta_msr_wait); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static bool sc16is7xx_port_irq(struct sc16is7xx_port *s, int portno) @@ -823,9 +823,9 @@ static void sc16is7xx_tx_proc(struct kthread_work *ws) sc16is7xx_handle_tx(port); mutex_unlock(&s->efr_lock); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); sc16is7xx_ier_set(port, SC16IS7XX_IER_THRI_BIT); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void sc16is7xx_reconf_rs485(struct uart_port *port) @@ -836,14 +836,14 @@ static void sc16is7xx_reconf_rs485(struct uart_port *= port) struct serial_rs485 *rs485 =3D &port->rs485; unsigned long irqflags; =20 - spin_lock_irqsave(&port->lock, irqflags); + uart_port_lock_irqsave(port, &irqflags); if (rs485->flags & SER_RS485_ENABLED) { efcr |=3D SC16IS7XX_EFCR_AUTO_RS485_BIT; =20 if (rs485->flags & SER_RS485_RTS_AFTER_SEND) efcr |=3D SC16IS7XX_EFCR_RTS_INVERT_BIT; } - spin_unlock_irqrestore(&port->lock, irqflags); + uart_port_unlock_irqrestore(port, irqflags); =20 sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG, mask, efcr); } @@ -854,10 +854,10 @@ static void sc16is7xx_reg_proc(struct kthread_work *w= s) struct sc16is7xx_one_config config; unsigned long irqflags; =20 - spin_lock_irqsave(&one->port.lock, irqflags); + uart_port_lock_irqsave(&one->port, &irqflags); config =3D one->config; memset(&one->config, 0, sizeof(one->config)); - spin_unlock_irqrestore(&one->port.lock, irqflags); + uart_port_unlock_irqrestore(&one->port, irqflags); =20 if (config.flags & SC16IS7XX_RECONF_MD) { u8 mcr =3D 0; @@ -963,18 +963,18 @@ static void sc16is7xx_throttle(struct uart_port *port) * value set in MCR register. Stop reading data from RX FIFO so the * AutoRTS feature will de-activate RTS output. */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); sc16is7xx_ier_clear(port, SC16IS7XX_IER_RDI_BIT); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void sc16is7xx_unthrottle(struct uart_port *port) { unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); sc16is7xx_ier_set(port, SC16IS7XX_IER_RDI_BIT); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static unsigned int sc16is7xx_tx_empty(struct uart_port *port) @@ -1113,7 +1113,7 @@ static void sc16is7xx_set_termios(struct uart_port *p= ort, /* Setup baudrate generator */ baud =3D sc16is7xx_set_baud(port, baud); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Update timeout according to new baud rate */ uart_update_timeout(port, termios->c_cflag, baud); @@ -1121,7 +1121,7 @@ static void sc16is7xx_set_termios(struct uart_port *p= ort, if (UART_ENABLE_MS(port, termios->c_cflag)) sc16is7xx_enable_ms(port); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static int sc16is7xx_config_rs485(struct uart_port *port, struct ktermios = *termios, @@ -1208,9 +1208,9 @@ static int sc16is7xx_startup(struct uart_port *port) sc16is7xx_port_write(port, SC16IS7XX_IER_REG, val); =20 /* Enable modem status polling */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); sc16is7xx_enable_ms(port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return 0; } --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41363EEAA62 for ; Thu, 14 Sep 2023 18:42:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242025AbjINSmF (ORCPT ); Thu, 14 Sep 2023 14:42:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241998AbjINSj6 (ORCPT ); Thu, 14 Sep 2023 14:39:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A0CF2719; Thu, 14 Sep 2023 11:39:04 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xOwhgnLO7hOBwv7Kh3brBH5G3zRUgo+W3NYhrK110nQ=; b=MQF5Uzr7EmKQx14r1E/RhX/umHkyltViumcqQtzYlRu/cdZA5N1RelnJ4iu3xdbYGsublf AesvLXS2l1vgjY/3lJjgy3oS9Fa9CNIR9FdCDxd3xGmG0PqFn6mYkcJSIXcskbHkN10xH7 fjf6/nHuFw7FFrO4gx/WSOB8n7ykjp9NGoMsoeoOBZCgXHT+OEqemMupp1sBuPMJwRsuxf nU/nGrLUIfKTsfa4sHRdVUDDytrxtrfa0bYiOJQclsPYDWetbS6woG0hXVe80c083ykC0o LnHq5GziKgk/yioSaLz/v2WQTMBmpy3Te2MAeI6u0OokLmagDAUK+U749FyAYQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xOwhgnLO7hOBwv7Kh3brBH5G3zRUgo+W3NYhrK110nQ=; b=y4UPC3ayiwCpK2wUuae2l5tlzv/vgSHZnGxCpQZEdOHfUE6peDdmI2DaPnIbsoJ+GKOrLW l/Me65oUdGiBduAQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Laxman Dewangan , Thierry Reding , Jonathan Hunter , linux-tegra@vger.kernel.org Subject: [PATCH tty v1 56/74] serial: tegra: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:13 +0206 Message-Id: <20230914183831.587273-57-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/serial-tegra.c | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/drivers/tty/serial/serial-tegra.c b/drivers/tty/serial/serial-= tegra.c index d4ec943cb8e9..6d4006b41975 100644 --- a/drivers/tty/serial/serial-tegra.c +++ b/drivers/tty/serial/serial-tegra.c @@ -411,7 +411,7 @@ static int tegra_set_baudrate(struct tegra_uart_port *t= up, unsigned int baud) divisor =3D DIV_ROUND_CLOSEST(rate, baud * 16); } =20 - spin_lock_irqsave(&tup->uport.lock, flags); + uart_port_lock_irqsave(&tup->uport, &flags); lcr =3D tup->lcr_shadow; lcr |=3D UART_LCR_DLAB; tegra_uart_write(tup, lcr, UART_LCR); @@ -424,7 +424,7 @@ static int tegra_set_baudrate(struct tegra_uart_port *t= up, unsigned int baud) =20 /* Dummy read to ensure the write is posted */ tegra_uart_read(tup, UART_SCR); - spin_unlock_irqrestore(&tup->uport.lock, flags); + uart_port_unlock_irqrestore(&tup->uport, flags); =20 tup->current_baud =3D baud; =20 @@ -522,13 +522,13 @@ static void tegra_uart_tx_dma_complete(void *args) dmaengine_tx_status(tup->tx_dma_chan, tup->tx_cookie, &state); count =3D tup->tx_bytes_requested - state.residue; async_tx_ack(tup->tx_dma_desc); - spin_lock_irqsave(&tup->uport.lock, flags); + uart_port_lock_irqsave(&tup->uport, &flags); uart_xmit_advance(&tup->uport, count); tup->tx_in_progress =3D 0; if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) uart_write_wakeup(&tup->uport); tegra_uart_start_next_tx(tup); - spin_unlock_irqrestore(&tup->uport.lock, flags); + uart_port_unlock_irqrestore(&tup->uport, flags); } =20 static int tegra_uart_start_tx_dma(struct tegra_uart_port *tup, @@ -598,13 +598,13 @@ static unsigned int tegra_uart_tx_empty(struct uart_p= ort *u) unsigned int ret =3D 0; unsigned long flags; =20 - spin_lock_irqsave(&u->lock, flags); + uart_port_lock_irqsave(u, &flags); if (!tup->tx_in_progress) { unsigned long lsr =3D tegra_uart_read(tup, UART_LSR); if ((lsr & TX_EMPTY_STATUS) =3D=3D TX_EMPTY_STATUS) ret =3D TIOCSER_TEMT; } - spin_unlock_irqrestore(&u->lock, flags); + uart_port_unlock_irqrestore(u, flags); return ret; } =20 @@ -727,7 +727,7 @@ static void tegra_uart_rx_dma_complete(void *args) struct dma_tx_state state; enum dma_status status; =20 - spin_lock_irqsave(&u->lock, flags); + uart_port_lock_irqsave(u, &flags); =20 status =3D dmaengine_tx_status(tup->rx_dma_chan, tup->rx_cookie, &state); =20 @@ -749,7 +749,7 @@ static void tegra_uart_rx_dma_complete(void *args) set_rts(tup, true); =20 done: - spin_unlock_irqrestore(&u->lock, flags); + uart_port_unlock_irqrestore(u, flags); } =20 static void tegra_uart_terminate_rx_dma(struct tegra_uart_port *tup) @@ -836,7 +836,7 @@ static irqreturn_t tegra_uart_isr(int irq, void *data) bool is_rx_int =3D false; unsigned long flags; =20 - spin_lock_irqsave(&u->lock, flags); + uart_port_lock_irqsave(u, &flags); while (1) { iir =3D tegra_uart_read(tup, UART_IIR); if (iir & UART_IIR_NO_INT) { @@ -852,7 +852,7 @@ static irqreturn_t tegra_uart_isr(int irq, void *data) } else if (is_rx_start) { tegra_uart_start_rx_dma(tup); } - spin_unlock_irqrestore(&u->lock, flags); + uart_port_unlock_irqrestore(u, flags); return IRQ_HANDLED; } =20 @@ -969,11 +969,11 @@ static void tegra_uart_hw_deinit(struct tegra_uart_po= rt *tup) } } =20 - spin_lock_irqsave(&tup->uport.lock, flags); + uart_port_lock_irqsave(&tup->uport, &flags); /* Reset the Rx and Tx FIFOs */ tegra_uart_fifo_reset(tup, UART_FCR_CLEAR_XMIT | UART_FCR_CLEAR_RCVR); tup->current_baud =3D 0; - spin_unlock_irqrestore(&tup->uport.lock, flags); + uart_port_unlock_irqrestore(&tup->uport, flags); =20 tup->rx_in_progress =3D 0; tup->tx_in_progress =3D 0; @@ -1292,7 +1292,7 @@ static void tegra_uart_set_termios(struct uart_port *= u, int ret; =20 max_divider *=3D 16; - spin_lock_irqsave(&u->lock, flags); + uart_port_lock_irqsave(u, &flags); =20 /* Changing configuration, it is safe to stop any rx now */ if (tup->rts_active) @@ -1341,7 +1341,7 @@ static void tegra_uart_set_termios(struct uart_port *= u, baud =3D uart_get_baud_rate(u, termios, oldtermios, parent_clk_rate/max_divider, parent_clk_rate/16); - spin_unlock_irqrestore(&u->lock, flags); + uart_port_unlock_irqrestore(u, flags); ret =3D tegra_set_baudrate(tup, baud); if (ret < 0) { dev_err(tup->uport.dev, "Failed to set baud rate\n"); @@ -1349,7 +1349,7 @@ static void tegra_uart_set_termios(struct uart_port *= u, } if (tty_termios_baud_rate(termios)) tty_termios_encode_baud_rate(termios, baud, baud); - spin_lock_irqsave(&u->lock, flags); + uart_port_lock_irqsave(u, &flags); =20 /* Flow control */ if (termios->c_cflag & CRTSCTS) { @@ -1382,7 +1382,7 @@ static void tegra_uart_set_termios(struct uart_port *= u, if (termios->c_iflag & IGNBRK) tup->uport.ignore_status_mask |=3D UART_LSR_BI; =20 - spin_unlock_irqrestore(&u->lock, flags); + uart_port_unlock_irqrestore(u, flags); } =20 static const char *tegra_uart_type(struct uart_port *u) --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FEB9EEAA5D for ; Thu, 14 Sep 2023 18:41:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240003AbjINSmB (ORCPT ); Thu, 14 Sep 2023 14:42:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242002AbjINSj6 (ORCPT ); Thu, 14 Sep 2023 14:39:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB585271F; Thu, 14 Sep 2023 11:39:04 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716743; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+c8y3mlqvYbhVAUPi/vCATaSfboaR23i1Jls/9e1aPg=; b=Q681URTXCotnINxNsfU6XBYt6o0sruv6ZRxfFKZDlOJZUE1kstHevpliVOdpphOxGJ2uOs W0eLSK+EM61uowY9acpG0ezSua0bWlyO8jHgFicVk5SsB/7dAIr32VUcHuA9Lb/7pDB8oA fwaorOtNBNY1XJl8K3WaOP1+q4exjIMphMggX7wlKIRHYbb+fzK2K8FAVIKO/CxFxXL7+R jtx5jU7tH12Vl6jHU0eiAMIBjtfYn/3fGvXf76dPr7hBRx5CXWEkeQHM7qP4jcunb00L5I m53H5XyoUco7+6cUPFriXnBt+y/JjNZOA4O4i85FX5u2U8HSHgxBeJDt4hHLzw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716743; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+c8y3mlqvYbhVAUPi/vCATaSfboaR23i1Jls/9e1aPg=; b=oBmFRAFo6f9CalCedMFjJJUCCnHj86cDkknErjH64gqJGpKTameG0KfjSs+fpostkVlTPA jwr2NDsLNTzbd8Dg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Tony Lindgren , Lukas Wunner , Andy Shevchenko Subject: [PATCH tty v1 57/74] serial: core: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:14 +0206 Message-Id: <20230914183831.587273-58-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/serial_core.c | 88 ++++++++++++++++---------------- drivers/tty/serial/serial_port.c | 4 +- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_c= ore.c index 7bdc21d5e13b..b32bbd7aa3d3 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -79,7 +79,7 @@ static inline void uart_port_deref(struct uart_port *upor= t) ({ \ struct uart_port *__uport =3D uart_port_ref(state); \ if (__uport) \ - spin_lock_irqsave(&__uport->lock, flags); \ + uart_port_lock_irqsave(__uport, &flags); \ __uport; \ }) =20 @@ -87,7 +87,7 @@ static inline void uart_port_deref(struct uart_port *upor= t) ({ \ struct uart_port *__uport =3D uport; \ if (__uport) { \ - spin_unlock_irqrestore(&__uport->lock, flags); \ + uart_port_unlock_irqrestore(__uport, flags); \ uart_port_deref(__uport); \ } \ }) @@ -179,12 +179,12 @@ uart_update_mctrl(struct uart_port *port, unsigned in= t set, unsigned int clear) unsigned long flags; unsigned int old; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); old =3D port->mctrl; port->mctrl =3D (old & ~clear) | set; if (old !=3D port->mctrl && !(port->rs485.flags & SER_RS485_ENABLED)) port->ops->set_mctrl(port, port->mctrl); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 #define uart_set_mctrl(port, set) uart_update_mctrl(port, set, 0) @@ -219,7 +219,7 @@ static void uart_change_line_settings(struct tty_struct= *tty, struct uart_state /* * Set modem status enables based on termios cflag */ - spin_lock_irq(&uport->lock); + uart_port_lock_irq(uport); if (termios->c_cflag & CRTSCTS) uport->status |=3D UPSTAT_CTS_ENABLE; else @@ -240,7 +240,7 @@ static void uart_change_line_settings(struct tty_struct= *tty, struct uart_state else __uart_start(state); } - spin_unlock_irq(&uport->lock); + uart_port_unlock_irq(uport); } =20 /* @@ -702,11 +702,11 @@ static void uart_send_xchar(struct tty_struct *tty, c= har ch) if (port->ops->send_xchar) port->ops->send_xchar(port, ch); else { - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); port->x_char =3D ch; if (ch) port->ops->start_tx(port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } uart_port_deref(port); } @@ -1085,9 +1085,9 @@ static int uart_tiocmget(struct tty_struct *tty) =20 if (!tty_io_error(tty)) { result =3D uport->mctrl; - spin_lock_irq(&uport->lock); + uart_port_lock_irq(uport); result |=3D uport->ops->get_mctrl(uport); - spin_unlock_irq(&uport->lock); + uart_port_unlock_irq(uport); } out: mutex_unlock(&port->mutex); @@ -1223,16 +1223,16 @@ static int uart_wait_modem_status(struct uart_state= *state, unsigned long arg) uport =3D uart_port_ref(state); if (!uport) return -EIO; - spin_lock_irq(&uport->lock); + uart_port_lock_irq(uport); memcpy(&cprev, &uport->icount, sizeof(struct uart_icount)); uart_enable_ms(uport); - spin_unlock_irq(&uport->lock); + uart_port_unlock_irq(uport); =20 add_wait_queue(&port->delta_msr_wait, &wait); for (;;) { - spin_lock_irq(&uport->lock); + uart_port_lock_irq(uport); memcpy(&cnow, &uport->icount, sizeof(struct uart_icount)); - spin_unlock_irq(&uport->lock); + uart_port_unlock_irq(uport); =20 set_current_state(TASK_INTERRUPTIBLE); =20 @@ -1277,9 +1277,9 @@ static int uart_get_icount(struct tty_struct *tty, uport =3D uart_port_ref(state); if (!uport) return -EIO; - spin_lock_irq(&uport->lock); + uart_port_lock_irq(uport); memcpy(&cnow, &uport->icount, sizeof(struct uart_icount)); - spin_unlock_irq(&uport->lock); + uart_port_unlock_irq(uport); uart_port_deref(uport); =20 icount->cts =3D cnow.cts; @@ -1422,9 +1422,9 @@ static int uart_get_rs485_config(struct uart_port *po= rt, unsigned long flags; struct serial_rs485 aux; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); aux =3D port->rs485; - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 if (copy_to_user(rs485, &aux, sizeof(aux))) return -EFAULT; @@ -1451,7 +1451,7 @@ static int uart_set_rs485_config(struct tty_struct *t= ty, struct uart_port *port, uart_sanitize_serial_rs485(port, &rs485); uart_set_rs485_termination(port, &rs485); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); ret =3D port->rs485_config(port, &tty->termios, &rs485); if (!ret) { port->rs485 =3D rs485; @@ -1460,7 +1460,7 @@ static int uart_set_rs485_config(struct tty_struct *t= ty, struct uart_port *port, if (!(rs485.flags & SER_RS485_ENABLED)) port->ops->set_mctrl(port, port->mctrl); } - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); if (ret) return ret; =20 @@ -1479,9 +1479,9 @@ static int uart_get_iso7816_config(struct uart_port *= port, if (!port->iso7816_config) return -ENOTTY; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); aux =3D port->iso7816; - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 if (copy_to_user(iso7816, &aux, sizeof(aux))) return -EFAULT; @@ -1510,9 +1510,9 @@ static int uart_set_iso7816_config(struct uart_port *= port, if (iso7816.reserved[i]) return -EINVAL; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); ret =3D port->iso7816_config(port, &iso7816); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); if (ret) return ret; =20 @@ -1729,9 +1729,9 @@ static void uart_tty_port_shutdown(struct tty_port *p= ort) if (WARN(!uport, "detached port still initialized!\n")) return; =20 - spin_lock_irq(&uport->lock); + uart_port_lock_irq(uport); uport->ops->stop_rx(uport); - spin_unlock_irq(&uport->lock); + uart_port_unlock_irq(uport); =20 uart_port_shutdown(port); =20 @@ -1745,10 +1745,10 @@ static void uart_tty_port_shutdown(struct tty_port = *port) /* * Free the transmit buffer. */ - spin_lock_irq(&uport->lock); + uart_port_lock_irq(uport); buf =3D state->xmit.buf; state->xmit.buf =3D NULL; - spin_unlock_irq(&uport->lock); + uart_port_unlock_irq(uport); =20 free_page((unsigned long)buf); =20 @@ -1891,10 +1891,10 @@ static bool uart_carrier_raised(struct tty_port *po= rt) */ if (WARN_ON(!uport)) return true; - spin_lock_irq(&uport->lock); + uart_port_lock_irq(uport); uart_enable_ms(uport); mctrl =3D uport->ops->get_mctrl(uport); - spin_unlock_irq(&uport->lock); + uart_port_unlock_irq(uport); uart_port_deref(uport); =20 return mctrl & TIOCM_CAR; @@ -2011,9 +2011,9 @@ static void uart_line_info(struct seq_file *m, struct= uart_driver *drv, int i) pm_state =3D state->pm_state; if (pm_state !=3D UART_PM_STATE_ON) uart_change_pm(state, UART_PM_STATE_ON); - spin_lock_irq(&uport->lock); + uart_port_lock_irq(uport); status =3D uport->ops->get_mctrl(uport); - spin_unlock_irq(&uport->lock); + uart_port_unlock_irq(uport); if (pm_state !=3D UART_PM_STATE_ON) uart_change_pm(state, pm_state); =20 @@ -2352,9 +2352,9 @@ int uart_suspend_port(struct uart_driver *drv, struct= uart_port *uport) */ if (!console_suspend_enabled && uart_console(uport)) { if (uport->ops->start_rx) { - spin_lock_irq(&uport->lock); + uart_port_lock_irq(uport); uport->ops->stop_rx(uport); - spin_unlock_irq(&uport->lock); + uart_port_unlock_irq(uport); } goto unlock; } @@ -2369,7 +2369,7 @@ int uart_suspend_port(struct uart_driver *drv, struct= uart_port *uport) tty_port_set_suspended(port, true); tty_port_set_initialized(port, false); =20 - spin_lock_irq(&uport->lock); + uart_port_lock_irq(uport); ops->stop_tx(uport); if (!(uport->rs485.flags & SER_RS485_ENABLED)) ops->set_mctrl(uport, 0); @@ -2377,7 +2377,7 @@ int uart_suspend_port(struct uart_driver *drv, struct= uart_port *uport) mctrl =3D uport->mctrl; uport->mctrl =3D 0; ops->stop_rx(uport); - spin_unlock_irq(&uport->lock); + uart_port_unlock_irq(uport); =20 /* * Wait for the transmitter to empty. @@ -2449,9 +2449,9 @@ int uart_resume_port(struct uart_driver *drv, struct = uart_port *uport) uart_change_pm(state, UART_PM_STATE_ON); uport->ops->set_termios(uport, &termios, NULL); if (!console_suspend_enabled && uport->ops->start_rx) { - spin_lock_irq(&uport->lock); + uart_port_lock_irq(uport); uport->ops->start_rx(uport); - spin_unlock_irq(&uport->lock); + uart_port_unlock_irq(uport); } if (console_suspend_enabled) console_start(uport->cons); @@ -2462,10 +2462,10 @@ int uart_resume_port(struct uart_driver *drv, struc= t uart_port *uport) int ret; =20 uart_change_pm(state, UART_PM_STATE_ON); - spin_lock_irq(&uport->lock); + uart_port_lock_irq(uport); if (!(uport->rs485.flags & SER_RS485_ENABLED)) ops->set_mctrl(uport, 0); - spin_unlock_irq(&uport->lock); + uart_port_unlock_irq(uport); if (console_suspend_enabled || !uart_console(uport)) { /* Protected by port mutex for now */ struct tty_struct *tty =3D port->tty; @@ -2474,13 +2474,13 @@ int uart_resume_port(struct uart_driver *drv, struc= t uart_port *uport) if (ret =3D=3D 0) { if (tty) uart_change_line_settings(tty, state, NULL); - spin_lock_irq(&uport->lock); + uart_port_lock_irq(uport); if (!(uport->rs485.flags & SER_RS485_ENABLED)) ops->set_mctrl(uport, uport->mctrl); else uart_rs485_config(uport); ops->start_tx(uport); - spin_unlock_irq(&uport->lock); + uart_port_unlock_irq(uport); tty_port_set_initialized(port, true); } else { /* @@ -2583,13 +2583,13 @@ uart_configure_port(struct uart_driver *drv, struct= uart_state *state, * keep the DTR setting that is set in uart_set_options() * We probably don't need a spinlock around this, but */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); port->mctrl &=3D TIOCM_DTR; if (!(port->rs485.flags & SER_RS485_ENABLED)) port->ops->set_mctrl(port, port->mctrl); else uart_rs485_config(port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 /* * If this driver supports console, and it hasn't been diff --git a/drivers/tty/serial/serial_port.c b/drivers/tty/serial/serial_p= ort.c index 862423237007..88975a4df306 100644 --- a/drivers/tty/serial/serial_port.c +++ b/drivers/tty/serial/serial_port.c @@ -35,10 +35,10 @@ static int serial_port_runtime_resume(struct device *de= v) goto out; =20 /* Flush any pending TX for the port */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); if (__serial_port_busy(port)) port->ops->start_tx(port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 out: pm_runtime_mark_last_busy(dev); --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC06BEEAA5D for ; Thu, 14 Sep 2023 18:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242168AbjINSmI (ORCPT ); Thu, 14 Sep 2023 14:42:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242004AbjINSj6 (ORCPT ); Thu, 14 Sep 2023 14:39:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A88B2139; Thu, 14 Sep 2023 11:39:05 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716743; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0VJ6CgzcUt97Sq6jT/T/98yELCXXHkc/OLg8MuGFujM=; b=2Q8ZWVVt4nOO784XYJxgw1TUsfcdKAz0Y5+p60KtUyCRIsGYdCIskPFE+osS7+MkxwviQt UML2Y73woxFqdZHm6y94vd3WGC56kpgzzzbF2i5Ubc0Aro/OmrgD0CxWgcpFi347G+NQZH h90Lof0AlZsIu85LlPQevIPzRFfD7CrqttJtuQU3DYChU+D751il2UBumt99HaTKqunct/ 26LmtSeaqPDLr1pPNjDhaxBC8MMUkiG9VtRP+NG14Ke6NMcQ0DamBJBgpShKTO0+/7MQDj l510AATKDexz0xJw6MogQYOHDTzUhEwMvTmC02EXbku1B63xHHV0/JriASW0lA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716743; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0VJ6CgzcUt97Sq6jT/T/98yELCXXHkc/OLg8MuGFujM=; b=vwvzaothGm7O+kiuENFNt17TWnYKIc4YDYnd1sfg4ZHwAk6rFlSpEEbCz+oonZ6Z7p4V0g 2/A7G8m1pzZF8rBQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH tty v1 58/74] serial: mctrl_gpio: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:15 +0206 Message-Id: <20230914183831.587273-59-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/serial_mctrl_gpio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/serial_mctrl_gpio.c b/drivers/tty/serial/se= rial_mctrl_gpio.c index 7d5aaa8d422b..e51ca593ab86 100644 --- a/drivers/tty/serial/serial_mctrl_gpio.c +++ b/drivers/tty/serial/serial_mctrl_gpio.c @@ -184,7 +184,7 @@ static irqreturn_t mctrl_gpio_irq_handle(int irq, void = *context) =20 mctrl_gpio_get(gpios, &mctrl); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 mctrl_diff =3D mctrl ^ gpios->mctrl_prev; gpios->mctrl_prev =3D mctrl; @@ -205,7 +205,7 @@ static irqreturn_t mctrl_gpio_irq_handle(int irq, void = *context) wake_up_interruptible(&port->state->port.delta_msr_wait); } =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return IRQ_HANDLED; } --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85BA0EEAA5D for ; Thu, 14 Sep 2023 18:42:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242163AbjINSmO (ORCPT ); Thu, 14 Sep 2023 14:42:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232532AbjINSkO (ORCPT ); Thu, 14 Sep 2023 14:40:14 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 618CB2721; Thu, 14 Sep 2023 11:39:05 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716744; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ftoYF3ysXZRgd7029hIddGE6TugW7j1R0akznX06Mek=; b=AVsgLhp3emlP/RNgitQPW0uhlds6RD4TU4dct35DRx4bNvQKUbjV8C0drufMaiZ0wIihGa TWkE52zfn+HIgR6AuRGV2UrROOAZDWRb0IAuAbpAr5VC/Gh442FopUkwW7O+kRKLfTSHHx G/fv9sc1lIhZ7fEu2Oniebv2c8pgfU42cXr40v4cri1R0iln1kpbKNFOdKg4yETrJ64mJE kgAd6H3xwAKOH8C9w1FbP6P99Y8wCDfoYJ/vhVVOjjgenhJzWwGHEeZaBWZ/Thrlwi+1cQ 6/GmbmC7aQi/G43VolWTa3jdAOttDC56MXk9R4ZmUBXk9mAekCVd3QZoigP2EQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716744; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ftoYF3ysXZRgd7029hIddGE6TugW7j1R0akznX06Mek=; b=v+V76Qzo12KFfI6gBWpLLNJ0z4vydANWQYRetphYnTZH8vxTQOViwIGVEpH6m5HJPH43Ws Y+xUKDucxO8n7uCA== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Richard GENOUD , "Maciej W. Rozycki" , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH tty v1 59/74] serial: txx9: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:16 +0206 Message-Id: <20230914183831.587273-60-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/serial_txx9.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/tty/serial/serial_txx9.c b/drivers/tty/serial/serial_t= xx9.c index be08fb6f749c..eaa980722455 100644 --- a/drivers/tty/serial/serial_txx9.c +++ b/drivers/tty/serial/serial_txx9.c @@ -335,13 +335,13 @@ static irqreturn_t serial_txx9_interrupt(int irq, voi= d *dev_id) unsigned int status; =20 while (1) { - spin_lock(&up->lock); + uart_port_lock(up); status =3D sio_in(up, TXX9_SIDISR); if (!(sio_in(up, TXX9_SIDICR) & TXX9_SIDICR_TIE)) status &=3D ~TXX9_SIDISR_TDIS; if (!(status & (TXX9_SIDISR_TDIS | TXX9_SIDISR_RDIS | TXX9_SIDISR_TOUT))) { - spin_unlock(&up->lock); + uart_port_unlock(up); break; } =20 @@ -353,7 +353,7 @@ static irqreturn_t serial_txx9_interrupt(int irq, void = *dev_id) sio_mask(up, TXX9_SIDISR, TXX9_SIDISR_TDIS | TXX9_SIDISR_RDIS | TXX9_SIDISR_TOUT); - spin_unlock(&up->lock); + uart_port_unlock(up); =20 if (pass_counter++ > PASS_LIMIT) break; @@ -367,9 +367,9 @@ static unsigned int serial_txx9_tx_empty(struct uart_po= rt *up) unsigned long flags; unsigned int ret; =20 - spin_lock_irqsave(&up->lock, flags); + uart_port_lock_irqsave(up, &flags); ret =3D (sio_in(up, TXX9_SICISR) & TXX9_SICISR_TXALS) ? TIOCSER_TEMT : 0; - spin_unlock_irqrestore(&up->lock, flags); + uart_port_unlock_irqrestore(up, flags); =20 return ret; } @@ -399,12 +399,12 @@ static void serial_txx9_break_ctl(struct uart_port *u= p, int break_state) { unsigned long flags; =20 - spin_lock_irqsave(&up->lock, flags); + uart_port_lock_irqsave(up, &flags); if (break_state =3D=3D -1) sio_set(up, TXX9_SIFLCR, TXX9_SIFLCR_TBRK); else sio_mask(up, TXX9_SIFLCR, TXX9_SIFLCR_TBRK); - spin_unlock_irqrestore(&up->lock, flags); + uart_port_unlock_irqrestore(up, flags); } =20 #if defined(CONFIG_SERIAL_TXX9_CONSOLE) || defined(CONFIG_CONSOLE_POLL) @@ -517,9 +517,9 @@ static int serial_txx9_startup(struct uart_port *up) /* * Now, initialize the UART */ - spin_lock_irqsave(&up->lock, flags); + uart_port_lock_irqsave(up, &flags); serial_txx9_set_mctrl(up, up->mctrl); - spin_unlock_irqrestore(&up->lock, flags); + uart_port_unlock_irqrestore(up, flags); =20 /* Enable RX/TX */ sio_mask(up, TXX9_SIFLCR, TXX9_SIFLCR_RSDE | TXX9_SIFLCR_TSDE); @@ -541,9 +541,9 @@ static void serial_txx9_shutdown(struct uart_port *up) */ sio_out(up, TXX9_SIDICR, 0); /* disable all intrs */ =20 - spin_lock_irqsave(&up->lock, flags); + uart_port_lock_irqsave(up, &flags); serial_txx9_set_mctrl(up, up->mctrl); - spin_unlock_irqrestore(&up->lock, flags); + uart_port_unlock_irqrestore(up, flags); =20 /* * Disable break condition @@ -625,7 +625,7 @@ serial_txx9_set_termios(struct uart_port *up, struct kt= ermios *termios, * Ok, we're now changing the port state. Do it with * interrupts disabled. */ - spin_lock_irqsave(&up->lock, flags); + uart_port_lock_irqsave(up, &flags); =20 /* * Update the per-port timeout. @@ -676,7 +676,7 @@ serial_txx9_set_termios(struct uart_port *up, struct kt= ermios *termios, sio_out(up, TXX9_SIFCR, fcr); =20 serial_txx9_set_mctrl(up, up->mctrl); - spin_unlock_irqrestore(&up->lock, flags); + uart_port_unlock_irqrestore(up, flags); } =20 static void --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 917ABEEAA63 for ; Thu, 14 Sep 2023 18:42:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242177AbjINSmU (ORCPT ); Thu, 14 Sep 2023 14:42:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241841AbjINSkR (ORCPT ); Thu, 14 Sep 2023 14:40:17 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C85F2728; Thu, 14 Sep 2023 11:39:05 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716744; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JJqXttFgJz1o+g4eBfJScMI/XchlkOkBgsSlRKeNPuA=; b=geNM0FhgCOGoeOBNGt6FPlmpPdYxQua3VqM3C5V4/54UlAM68Le8U6SgMWLk/Z9BBDR225 oqAl/lCUHEDK2lWu1r9ruGG1EOAAY+gQrQxYxvJDFlYdFmYq5H3ShwEq86ZnoraE0TBDcX a+2MPqtqWclmIjULaU+gNvavGPc7z9IOvDVJzsAlD4DwHks3GU+3eu+zTliGUH+Q1yEc7Z konqxYwSudBlS5wMjE+UFOhsSiJrUuaf2iNX6fv9e0MNL4s+4hxVgVrGb+lChSeWdPNLd1 aUREM5MlnXBQcuvPCMxXz8M9TxKSXd0cEDJqSN670xSbHSfWLgF1e/dR7AGTtw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716744; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JJqXttFgJz1o+g4eBfJScMI/XchlkOkBgsSlRKeNPuA=; b=ipuV52qQ3Ii6VyO019DyBaS2uSpRYxwD4fQyMU2xQaxxolropoqi+GP1uzV2022g1oFfIh DZiIBiEFXX9TkyCw== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Biju Das , Geert Uytterhoeven , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Rob Herring , Krzysztof Kozlowski , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH tty v1 60/74] serial: sh-sci: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:17 +0206 Message-Id: <20230914183831.587273-61-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/sh-sci.c | 68 ++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index a560b729fa3b..84ab434c94ba 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -1205,7 +1205,7 @@ static void sci_dma_tx_complete(void *arg) =20 dev_dbg(port->dev, "%s(%d)\n", __func__, port->line); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 uart_xmit_advance(port, s->tx_dma_len); =20 @@ -1229,7 +1229,7 @@ static void sci_dma_tx_complete(void *arg) } } =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /* Locking: called with port lock held */ @@ -1320,7 +1320,7 @@ static void sci_dma_rx_complete(void *arg) dev_dbg(port->dev, "%s(%d) active cookie %d\n", __func__, port->line, s->active_rx); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 active =3D sci_dma_rx_find_active(s); if (active >=3D 0) @@ -1347,20 +1347,20 @@ static void sci_dma_rx_complete(void *arg) =20 dma_async_issue_pending(chan); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); dev_dbg(port->dev, "%s: cookie %d #%d, new active cookie %d\n", __func__, s->cookie_rx[active], active, s->active_rx); return; =20 fail: - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); dev_warn(port->dev, "Failed submitting Rx DMA descriptor\n"); /* Switch to PIO */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); dmaengine_terminate_async(chan); sci_dma_rx_chan_invalidate(s); sci_dma_rx_reenable_irq(s); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void sci_dma_tx_release(struct sci_port *s) @@ -1409,13 +1409,13 @@ static int sci_dma_rx_submit(struct sci_port *s, bo= ol port_lock_held) fail: /* Switch to PIO */ if (!port_lock_held) - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); if (i) dmaengine_terminate_async(chan); sci_dma_rx_chan_invalidate(s); sci_start_rx(port); if (!port_lock_held) - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); return -EAGAIN; } =20 @@ -1437,14 +1437,14 @@ static void sci_dma_tx_work_fn(struct work_struct *= work) * transmit till the end, and then the rest. Take the port lock to get a * consistent xmit buffer state. */ - spin_lock_irq(&port->lock); + uart_port_lock_irq(port); head =3D xmit->head; tail =3D xmit->tail; buf =3D s->tx_dma_addr + tail; s->tx_dma_len =3D CIRC_CNT_TO_END(head, tail, UART_XMIT_SIZE); if (!s->tx_dma_len) { /* Transmit buffer has been flushed */ - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); return; } =20 @@ -1452,7 +1452,7 @@ static void sci_dma_tx_work_fn(struct work_struct *wo= rk) DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); if (!desc) { - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); dev_warn(port->dev, "Failed preparing Tx DMA descriptor\n"); goto switch_to_pio; } @@ -1464,12 +1464,12 @@ static void sci_dma_tx_work_fn(struct work_struct *= work) desc->callback_param =3D s; s->cookie_tx =3D dmaengine_submit(desc); if (dma_submit_error(s->cookie_tx)) { - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); dev_warn(port->dev, "Failed submitting Tx DMA descriptor\n"); goto switch_to_pio; } =20 - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); dev_dbg(port->dev, "%s: %p: %d...%d, cookie %d\n", __func__, xmit->buf, tail, head, s->cookie_tx); =20 @@ -1477,10 +1477,10 @@ static void sci_dma_tx_work_fn(struct work_struct *= work) return; =20 switch_to_pio: - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); s->chan_tx =3D NULL; sci_start_tx(port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); return; } =20 @@ -1497,17 +1497,17 @@ static enum hrtimer_restart sci_dma_rx_timer_fn(str= uct hrtimer *t) =20 dev_dbg(port->dev, "DMA Rx timed out\n"); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 active =3D sci_dma_rx_find_active(s); if (active < 0) { - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); return HRTIMER_NORESTART; } =20 status =3D dmaengine_tx_status(s->chan_rx, s->active_rx, &state); if (status =3D=3D DMA_COMPLETE) { - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); dev_dbg(port->dev, "Cookie %d #%d has already completed\n", s->active_rx, active); =20 @@ -1525,7 +1525,7 @@ static enum hrtimer_restart sci_dma_rx_timer_fn(struc= t hrtimer *t) */ status =3D dmaengine_tx_status(s->chan_rx, s->active_rx, &state); if (status =3D=3D DMA_COMPLETE) { - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); dev_dbg(port->dev, "Transaction complete after DMA engine was stopped"); return HRTIMER_NORESTART; } @@ -1546,7 +1546,7 @@ static enum hrtimer_restart sci_dma_rx_timer_fn(struc= t hrtimer *t) =20 sci_dma_rx_reenable_irq(s); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return HRTIMER_NORESTART; } @@ -1770,9 +1770,9 @@ static irqreturn_t sci_tx_interrupt(int irq, void *pt= r) struct uart_port *port =3D ptr; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); sci_transmit_chars(port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return IRQ_HANDLED; } @@ -1786,11 +1786,11 @@ static irqreturn_t sci_tx_end_interrupt(int irq, vo= id *ptr) if (port->type !=3D PORT_SCI) return sci_tx_interrupt(irq, ptr); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); ctrl =3D serial_port_in(port, SCSCR); ctrl &=3D ~(SCSCR_TE | SCSCR_TEIE); serial_port_out(port, SCSCR, ctrl); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return IRQ_HANDLED; } @@ -2187,7 +2187,7 @@ static void sci_break_ctl(struct uart_port *port, int= break_state) return; } =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); scsptr =3D serial_port_in(port, SCSPTR); scscr =3D serial_port_in(port, SCSCR); =20 @@ -2201,7 +2201,7 @@ static void sci_break_ctl(struct uart_port *port, int= break_state) =20 serial_port_out(port, SCSPTR, scsptr); serial_port_out(port, SCSCR, scscr); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static int sci_startup(struct uart_port *port) @@ -2233,7 +2233,7 @@ static void sci_shutdown(struct uart_port *port) s->autorts =3D false; mctrl_gpio_disable_ms(to_sci_port(port)->gpios); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); sci_stop_rx(port); sci_stop_tx(port); /* @@ -2243,7 +2243,7 @@ static void sci_shutdown(struct uart_port *port) scr =3D serial_port_in(port, SCSCR); serial_port_out(port, SCSCR, scr & (SCSCR_CKE1 | SCSCR_CKE0 | s->hscif_tot)); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 #ifdef CONFIG_SERIAL_SH_SCI_DMA if (s->chan_rx_saved) { @@ -2545,7 +2545,7 @@ static void sci_set_termios(struct uart_port *port, s= truct ktermios *termios, serial_port_out(port, SCCKS, sccks); } =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 sci_reset(port); =20 @@ -2667,7 +2667,7 @@ static void sci_set_termios(struct uart_port *port, s= truct ktermios *termios, if ((termios->c_cflag & CREAD) !=3D 0) sci_start_rx(port); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 sci_port_disable(s); =20 @@ -3052,9 +3052,9 @@ static void serial_console_write(struct console *co, = const char *s, if (port->sysrq) locked =3D 0; else if (oops_in_progress) - locked =3D spin_trylock_irqsave(&port->lock, flags); + locked =3D uart_port_trylock_irqsave(port, &flags); else - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* first save SCSCR then disable interrupts, keep clock source */ ctrl =3D serial_port_in(port, SCSCR); @@ -3074,7 +3074,7 @@ static void serial_console_write(struct console *co, = const char *s, serial_port_out(port, SCSCR, ctrl); =20 if (locked) - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static int serial_console_setup(struct console *co, char *options) --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C092EEAA62 for ; Thu, 14 Sep 2023 18:42:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241849AbjINSmW (ORCPT ); Thu, 14 Sep 2023 14:42:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241761AbjINSkS (ORCPT ); Thu, 14 Sep 2023 14:40:18 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AAD3272D; Thu, 14 Sep 2023 11:39:06 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716745; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FNItZDOSVbjUj/GhN7qtDvHsswbZnbm/OUZHY8Hfuqo=; b=wknKwa1kLvdaAYCvkZu9Z81f2T8Ta+CKva4N8RP76TA/NcMmJlm+Kil2JepCpHxBw1BEJU K5pPqaYbTwLXrS3/UGwnuSoqeuuWpaEqqES2YbBrkQQJBM2jxPSbaryW3lTtByRM/tMtwh gLrH5uhCtN8myDHRj74sRARHv9IwiNLbYc/k8O+0uLooKYlN4mT5AxH563k4Ct6BKNLKBa 6sfWSVIRNQrC7RUyNp3GxrdgJpqbYtOp6pNuQ7JQPlbSa8eoVNCfaBWQPqRdeKSwo43PTo 78iMfhiAozSI/V0aIgMpjYRus2ommjIBSLG4FVydEquKML+4oWBSdSlxxdKnPA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716745; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FNItZDOSVbjUj/GhN7qtDvHsswbZnbm/OUZHY8Hfuqo=; b=HCL13mxdtEEBqe3txMOM+VDtV2848oD66CWe/CXn/8/B7TEVd4hlSi4SRJ+K0c3B4MuVs7 ZsMM+w8fmLRiVrBg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Palmer Dabbelt , Paul Walmsley , Richard GENOUD , Nick Hu , Ruan Jinjie , Samuel Holland , Yangtao Li , linux-riscv@lists.infradead.org Subject: [PATCH tty v1 61/74] serial: sifive: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:18 +0206 Message-Id: <20230914183831.587273-62-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/sifive.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/tty/serial/sifive.c b/drivers/tty/serial/sifive.c index d195c5de52e7..b296e57a9dee 100644 --- a/drivers/tty/serial/sifive.c +++ b/drivers/tty/serial/sifive.c @@ -521,11 +521,11 @@ static irqreturn_t sifive_serial_irq(int irq, void *d= ev_id) struct sifive_serial_port *ssp =3D dev_id; u32 ip; =20 - spin_lock(&ssp->port.lock); + uart_port_lock(&ssp->port); =20 ip =3D __ssp_readl(ssp, SIFIVE_SERIAL_IP_OFFS); if (!ip) { - spin_unlock(&ssp->port.lock); + uart_port_unlock(&ssp->port); return IRQ_NONE; } =20 @@ -534,7 +534,7 @@ static irqreturn_t sifive_serial_irq(int irq, void *dev= _id) if (ip & SIFIVE_SERIAL_IP_TXWM_MASK) __ssp_transmit_chars(ssp); =20 - spin_unlock(&ssp->port.lock); + uart_port_unlock(&ssp->port); =20 return IRQ_HANDLED; } @@ -653,7 +653,7 @@ static void sifive_serial_set_termios(struct uart_port = *port, ssp->port.uartclk / 16); __ssp_update_baud_rate(ssp, rate); =20 - spin_lock_irqsave(&ssp->port.lock, flags); + uart_port_lock_irqsave(&ssp->port, &flags); =20 /* Update the per-port timeout */ uart_update_timeout(port, termios->c_cflag, rate); @@ -670,7 +670,7 @@ static void sifive_serial_set_termios(struct uart_port = *port, if (v !=3D old_v) __ssp_writel(v, SIFIVE_SERIAL_RXCTRL_OFFS, ssp); =20 - spin_unlock_irqrestore(&ssp->port.lock, flags); + uart_port_unlock_irqrestore(&ssp->port, flags); } =20 static void sifive_serial_release_port(struct uart_port *port) @@ -795,9 +795,9 @@ static void sifive_serial_console_write(struct console = *co, const char *s, if (ssp->port.sysrq) locked =3D 0; else if (oops_in_progress) - locked =3D spin_trylock(&ssp->port.lock); + locked =3D uart_port_trylock(&ssp->port); else - spin_lock(&ssp->port.lock); + uart_port_lock(&ssp->port); =20 ier =3D __ssp_readl(ssp, SIFIVE_SERIAL_IE_OFFS); __ssp_writel(0, SIFIVE_SERIAL_IE_OFFS, ssp); @@ -807,7 +807,7 @@ static void sifive_serial_console_write(struct console = *co, const char *s, __ssp_writel(ier, SIFIVE_SERIAL_IE_OFFS, ssp); =20 if (locked) - spin_unlock(&ssp->port.lock); + uart_port_unlock(&ssp->port); local_irq_restore(flags); } =20 --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6F0CEEAA62 for ; Thu, 14 Sep 2023 18:42:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242050AbjINSmk (ORCPT ); Thu, 14 Sep 2023 14:42:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241867AbjINSkj (ORCPT ); Thu, 14 Sep 2023 14:40:39 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5B1A273D; Thu, 14 Sep 2023 11:39:06 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716745; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sl11dTCkNk9kJggQh18JDsFl9A3lJFdd+BsLFdknlKk=; b=rgWz1kP9jIWFi9w2kzGEWAnzKj4zW/p6BeYFI6vujEJ8TJ+n/nI6IcOom31t9SmV3DLIdx WH1k4F1QdvyO3cYrSyG04gVzITEWqZP47DwOPix0IdrWKedVLvFYMOp+IgggV9qDydlDob tckpucfIskKXLw4JcAWxdbmkSGKvjV4n2VWUGFzFQcv1UGDsrX35tvYAbeNdBWzlmLr+ii Bj8YzlbiNrjR5ii9fBhhQhBvUEIWJIRi96nXLCAYEMzDT0B1KxstSgEJiwzYq5SbEv+C0/ Fc4472IVK1SWMV47S+zt3VCr021TIv7AVPUbfWlXN/kszSxIBA3zoJ4AB7A6Wg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716745; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sl11dTCkNk9kJggQh18JDsFl9A3lJFdd+BsLFdknlKk=; b=FZ3tW60IrPICJ5oIIy/x5vlFhq4Em5jHfdSQaSC7grPVsyzX3HcfRr0P3977F4qGUqlY+H 2iWhKQjmXHTjfiAQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Orson Zhai , Baolin Wang , Chunyan Zhang , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Yangtao Li , Krzysztof Kozlowski Subject: [PATCH tty v1 62/74] serial: sprd: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:19 +0206 Message-Id: <20230914183831.587273-63-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/sprd_serial.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_ser= ial.c index f328fa57231f..f257525f9299 100644 --- a/drivers/tty/serial/sprd_serial.c +++ b/drivers/tty/serial/sprd_serial.c @@ -247,7 +247,7 @@ static void sprd_complete_tx_dma(void *data) struct circ_buf *xmit =3D &port->state->xmit; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); dma_unmap_single(port->dev, sp->tx_dma.phys_addr, sp->tx_dma.trans_len, DMA_TO_DEVICE); =20 @@ -260,7 +260,7 @@ static void sprd_complete_tx_dma(void *data) sprd_tx_dma_config(port)) sp->tx_dma.trans_len =3D 0; =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static int sprd_uart_dma_submit(struct uart_port *port, @@ -429,13 +429,13 @@ static void sprd_complete_rx_dma(void *data) enum dma_status status; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 status =3D dmaengine_tx_status(sp->rx_dma.chn, sp->rx_dma.cookie, &state); if (status !=3D DMA_COMPLETE) { sprd_stop_rx(port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); return; } =20 @@ -449,7 +449,7 @@ static void sprd_complete_rx_dma(void *data) if (sprd_start_dma_rx(port)) sprd_stop_rx(port); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static int sprd_start_dma_rx(struct uart_port *port) @@ -638,12 +638,12 @@ static irqreturn_t sprd_handle_irq(int irq, void *dev= _id) struct uart_port *port =3D dev_id; unsigned int ims; =20 - spin_lock(&port->lock); + uart_port_lock(port); =20 ims =3D serial_in(port, SPRD_IMSR); =20 if (!ims) { - spin_unlock(&port->lock); + uart_port_unlock(port); return IRQ_NONE; } =20 @@ -660,7 +660,7 @@ static irqreturn_t sprd_handle_irq(int irq, void *dev_i= d) if (ims & SPRD_IMSR_TX_FIFO_EMPTY) sprd_tx(port); =20 - spin_unlock(&port->lock); + uart_port_unlock(port); =20 return IRQ_HANDLED; } @@ -727,13 +727,13 @@ static int sprd_startup(struct uart_port *port) serial_out(port, SPRD_CTL1, fc); =20 /* enable interrupt */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); ien =3D serial_in(port, SPRD_IEN); ien |=3D SPRD_IEN_BREAK_DETECT | SPRD_IEN_TIMEOUT; if (!sp->rx_dma.enable) ien |=3D SPRD_IEN_RX_FULL; serial_out(port, SPRD_IEN, ien); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return 0; } @@ -793,7 +793,7 @@ static void sprd_set_termios(struct uart_port *port, st= ruct ktermios *termios, lcr |=3D SPRD_LCR_EVEN_PAR; } =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* update the per-port timeout */ uart_update_timeout(port, termios->c_cflag, baud); @@ -837,7 +837,7 @@ static void sprd_set_termios(struct uart_port *port, st= ruct ktermios *termios, fc |=3D RX_TOUT_THLD_DEF | RX_HFC_THLD_DEF; serial_out(port, SPRD_CTL1, fc); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 /* Don't rewrite B0 */ if (tty_termios_baud_rate(termios)) @@ -974,9 +974,9 @@ static void sprd_console_write(struct console *co, cons= t char *s, if (port->sysrq) locked =3D 0; else if (oops_in_progress) - locked =3D spin_trylock_irqsave(&port->lock, flags); + locked =3D uart_port_trylock_irqsave(port, &flags); else - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 uart_console_write(port, s, count, sprd_console_putchar); =20 @@ -984,7 +984,7 @@ static void sprd_console_write(struct console *co, cons= t char *s, wait_for_xmitr(port); =20 if (locked) - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static int sprd_console_setup(struct console *co, char *options) --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75AFFEEAA62 for ; Thu, 14 Sep 2023 18:42:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241786AbjINSmw (ORCPT ); Thu, 14 Sep 2023 14:42:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241893AbjINSkt (ORCPT ); Thu, 14 Sep 2023 14:40:49 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AE482D46; Thu, 14 Sep 2023 11:39:07 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716745; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=scaU8Ke6aOSrJaDl+5gO/v/Oetd46gqnVkH3I+dMdgg=; b=Mj0+Pe00fFVsZ6+hpkjEb3RIQOukUDP/nj1KpIONzsm0lww8nBluFaZ+8hIg2znuQmiWH4 vNAWfweVOIIC3hs2ouo/HTGnWFvKQTHnVTL06YlCaX7vMbezkTePgE6J74dkWomiuMqOQQ ru3qVZ30o2933msd35CcKWgDiDbRkpKnZ6kwgeMewj8MJZ46Z7eU9Rt60frRbKszO1uaTA hpQQwZs7tW5WJhj9LsMLqxu+1k4qsB1GmAK5HGTKrdsk7r+VxD8/eIDo1aoHemxCxRLDYZ g0ZJ1ORRCqncjJTriPe2+NnN37tZDQIFBOsGczeAAbY8U4yjZCiTZl5ndWA/ww== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716745; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=scaU8Ke6aOSrJaDl+5gO/v/Oetd46gqnVkH3I+dMdgg=; b=QKNzNzgHqgZN0A8MG25uklYWnJo/RRItn+QWlEUJLX2q9Iyh5vLVHi37d5Blz4HXcuFPVr fGe1OYlr4ZvZWSBQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Patrice Chotard , linux-arm-kernel@lists.infradead.org Subject: [PATCH tty v1 63/74] serial: st-asc: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:20 +0206 Message-Id: <20230914183831.587273-64-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/st-asc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/tty/serial/st-asc.c b/drivers/tty/serial/st-asc.c index 92b9f6894006..a821f5d76a26 100644 --- a/drivers/tty/serial/st-asc.c +++ b/drivers/tty/serial/st-asc.c @@ -319,7 +319,7 @@ static irqreturn_t asc_interrupt(int irq, void *ptr) struct uart_port *port =3D ptr; u32 status; =20 - spin_lock(&port->lock); + uart_port_lock(port); =20 status =3D asc_in(port, ASC_STA); =20 @@ -334,7 +334,7 @@ static irqreturn_t asc_interrupt(int irq, void *ptr) asc_transmit_chars(port); } =20 - spin_unlock(&port->lock); + uart_port_unlock(port); =20 return IRQ_HANDLED; } @@ -452,10 +452,10 @@ static void asc_pm(struct uart_port *port, unsigned i= nt state, * we can come to turning it off. Note this is not called with * the port spinlock held. */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); ctl =3D asc_in(port, ASC_CTL) & ~ASC_CTL_RUN; asc_out(port, ASC_CTL, ctl); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); clk_disable_unprepare(ascport->clk); break; } @@ -480,7 +480,7 @@ static void asc_set_termios(struct uart_port *port, str= uct ktermios *termios, baud =3D uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); cflag =3D termios->c_cflag; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* read control register */ ctrl_val =3D asc_in(port, ASC_CTL); @@ -594,7 +594,7 @@ static void asc_set_termios(struct uart_port *port, str= uct ktermios *termios, /* write final value and enable port */ asc_out(port, ASC_CTL, (ctrl_val | ASC_CTL_RUN)); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *asc_type(struct uart_port *port) @@ -849,9 +849,9 @@ static void asc_console_write(struct console *co, const= char *s, unsigned count) if (port->sysrq) locked =3D 0; /* asc_interrupt has already claimed the lock */ else if (oops_in_progress) - locked =3D spin_trylock_irqsave(&port->lock, flags); + locked =3D uart_port_trylock_irqsave(port, &flags); else - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* * Disable interrupts so we don't get the IRQ line bouncing @@ -869,7 +869,7 @@ static void asc_console_write(struct console *co, const= char *s, unsigned count) asc_out(port, ASC_INTEN, intenable); =20 if (locked) - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static int asc_console_setup(struct console *co, char *options) --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10B21EEAA62 for ; Thu, 14 Sep 2023 18:42:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242190AbjINSm5 (ORCPT ); Thu, 14 Sep 2023 14:42:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241802AbjINSlK (ORCPT ); Thu, 14 Sep 2023 14:41:10 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FC912D5E; Thu, 14 Sep 2023 11:39:08 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716746; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iKeNVbVjwksjd/VmSoAQYxVaHBv/5OG3sedFCpkRsng=; b=Zok7KIO1sf2sQrUBxCpReXcwNgovJJo3TQk9Va9ngMmNG3AryHhetikJI0GCmiS+5HryWM AQHRLPaFun5eJ+1hJABISNGyFPW2fywbBD7kfDu3ve3eTRBPmNoqKRqO3OAWanzuGraGk5 9bGD1E29Dfc/2gwzF1I2fyHss5YgnYj8SKem1Pj/SBu7hP7Zg96e19xdHVz+vobiJbb7Bw VwFXMtIbnnB4ROptIVv0X+93m71RN4tqVNHSBSdqPq1h73JiN2aMmBfhsQ+sdplfVWA+df vz/jdhf3G3YrtGlW4K4ySs6U9U1ncrkzc+y+SH2Yx2xLPu/osSaFASFu0J3OIg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716746; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iKeNVbVjwksjd/VmSoAQYxVaHBv/5OG3sedFCpkRsng=; b=o/uWRXq66VfgPaYRNsiMb5R1jUXjAc5caA9+Borc2nbah4BDfr9H2FCygUY0QSd0kIIvbX gzCljlqN20TtNfAg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Maxime Coquelin , Alexandre Torgue , Valentin Caron , Marek Vasut , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Sebastian Andrzej Siewior , Lukas Wunner , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH tty v1 64/74] serial: stm32: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:21 +0206 Message-Id: <20230914183831.587273-65-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/stm32-usart.c | 38 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-us= art.c index 5e9cf0c48813..8c51ec9433d6 100644 --- a/drivers/tty/serial/stm32-usart.c +++ b/drivers/tty/serial/stm32-usart.c @@ -537,7 +537,7 @@ static void stm32_usart_rx_dma_complete(void *arg) unsigned int size; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); size =3D stm32_usart_receive_chars(port, false); uart_unlock_and_check_sysrq_irqrestore(port, flags); if (size) @@ -643,9 +643,9 @@ static void stm32_usart_tx_dma_complete(void *arg) stm32_usart_tx_dma_terminate(stm32port); =20 /* Let's see if we have pending data to send */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); stm32_usart_transmit_chars(port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void stm32_usart_tx_interrupt_enable(struct uart_port *port) @@ -889,7 +889,7 @@ static irqreturn_t stm32_usart_interrupt(int irq, void = *ptr) if (!stm32_port->throttled) { if (((sr & USART_SR_RXNE) && !stm32_usart_rx_dma_started(stm32_port)) || ((sr & USART_SR_ERR_MASK) && stm32_usart_rx_dma_started(stm32_port))= ) { - spin_lock(&port->lock); + uart_port_lock(port); size =3D stm32_usart_receive_chars(port, false); uart_unlock_and_check_sysrq(port); if (size) @@ -898,14 +898,14 @@ static irqreturn_t stm32_usart_interrupt(int irq, voi= d *ptr) } =20 if ((sr & USART_SR_TXE) && !(stm32_port->tx_ch)) { - spin_lock(&port->lock); + uart_port_lock(port); stm32_usart_transmit_chars(port); - spin_unlock(&port->lock); + uart_port_unlock(port); } =20 /* Receiver timeout irq for DMA RX */ if (stm32_usart_rx_dma_started(stm32_port) && !stm32_port->throttled) { - spin_lock(&port->lock); + uart_port_lock(port); size =3D stm32_usart_receive_chars(port, false); uart_unlock_and_check_sysrq(port); if (size) @@ -993,7 +993,7 @@ static void stm32_usart_throttle(struct uart_port *port) const struct stm32_usart_offsets *ofs =3D &stm32_port->info->ofs; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* * Pause DMA transfer, so the RX data gets queued into the FIFO. @@ -1006,7 +1006,7 @@ static void stm32_usart_throttle(struct uart_port *po= rt) stm32_usart_clr_bits(port, ofs->cr3, stm32_port->cr3_irq); =20 stm32_port->throttled =3D true; - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /* Unthrottle the remote, the input buffer can now accept data. */ @@ -1016,7 +1016,7 @@ static void stm32_usart_unthrottle(struct uart_port *= port) const struct stm32_usart_offsets *ofs =3D &stm32_port->info->ofs; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); stm32_usart_set_bits(port, ofs->cr1, stm32_port->cr1_irq); if (stm32_port->cr3_irq) stm32_usart_set_bits(port, ofs->cr3, stm32_port->cr3_irq); @@ -1030,7 +1030,7 @@ static void stm32_usart_unthrottle(struct uart_port *= port) if (stm32_port->rx_ch) stm32_usart_rx_dma_start_or_resume(port); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /* Receive stop */ @@ -1158,7 +1158,7 @@ static void stm32_usart_set_termios(struct uart_port = *port, =20 baud =3D uart_get_baud_rate(port, termios, old, 0, port->uartclk / 8); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 ret =3D readl_relaxed_poll_timeout_atomic(port->membase + ofs->isr, isr, @@ -1349,7 +1349,7 @@ static void stm32_usart_set_termios(struct uart_port = *port, writel_relaxed(cr1, port->membase + ofs->cr1); =20 stm32_usart_set_bits(port, ofs->cr1, BIT(cfg->uart_enable_bit)); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 /* Handle modem control interrupts */ if (UART_ENABLE_MS(port, termios->c_cflag)) @@ -1399,9 +1399,9 @@ static void stm32_usart_pm(struct uart_port *port, un= signed int state, pm_runtime_get_sync(port->dev); break; case UART_PM_STATE_OFF: - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); stm32_usart_clr_bits(port, ofs->cr1, BIT(cfg->uart_enable_bit)); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); pm_runtime_put_sync(port->dev); break; } @@ -1884,9 +1884,9 @@ static void stm32_usart_console_write(struct console = *co, const char *s, int locked =3D 1; =20 if (oops_in_progress) - locked =3D spin_trylock_irqsave(&port->lock, flags); + locked =3D uart_port_trylock_irqsave(port, &flags); else - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Save and disable interrupts, enable the transmitter */ old_cr1 =3D readl_relaxed(port->membase + ofs->cr1); @@ -1900,7 +1900,7 @@ static void stm32_usart_console_write(struct console = *co, const char *s, writel_relaxed(old_cr1, port->membase + ofs->cr1); =20 if (locked) - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static int stm32_usart_console_setup(struct console *co, char *options) @@ -2035,7 +2035,7 @@ static int __maybe_unused stm32_usart_serial_en_wakeu= p(struct uart_port *port, * low-power mode. */ if (stm32_port->rx_ch) { - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); /* Poll data from DMA RX buffer if any */ if (!stm32_usart_rx_dma_pause(stm32_port)) size +=3D stm32_usart_receive_chars(port, true); --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95C87EEAA64 for ; Thu, 14 Sep 2023 18:43:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241794AbjINSnG (ORCPT ); Thu, 14 Sep 2023 14:43:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241825AbjINSlZ (ORCPT ); Thu, 14 Sep 2023 14:41:25 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6F192D65; Thu, 14 Sep 2023 11:39:08 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716747; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rtu6oqE59dzKnOzbdNG30qc4om/oIgRr8S/zbKifFdc=; b=Ox3AVx2dzryq88igCiD0iP3QWgUJkXiwaPj9FFyKP5obEHwDkRSJvaC6guX/ZIVT17C1E/ DqC8IIdrncfuOFDGqdJq/a9VZI5Mad2edRRgfFXaVbO1a1hiDFoXWWmzXdBEo/uxsv8TGu FcY7848+U1ZX0AyaqwTnxAoHCDuuAgmHLdiycdUBGHZxt/t/eS30/NVCfzcASGe/PyxnYy NVor/6R/yuNdiyuduDI+Uz7FEHRJWR5D9n4feEQHHvbp0QMFDRfJwnx/UK/skKtekEyZ7e kImmOywWdtYt3DZ6JsbdBGn9PPp91Snbi6gKxhaA89uomCON3arVYZsMhQGvOQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716747; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rtu6oqE59dzKnOzbdNG30qc4om/oIgRr8S/zbKifFdc=; b=NXJ+yaujVO6y/IuJtIGgaAgB0JGAz6vau/jQZ0o0D/rAnYe2xp0P7vUQxS89WFZpnZ3hlv 8pezu6YWNex7nZBQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, "David S. Miller" , sparclinux@vger.kernel.org Subject: [PATCH tty v1 65/74] serial: sunhv: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:22 +0206 Message-Id: <20230914183831.587273-66-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/sunhv.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/tty/serial/sunhv.c b/drivers/tty/serial/sunhv.c index c671d674bce4..5bfc0040f17b 100644 --- a/drivers/tty/serial/sunhv.c +++ b/drivers/tty/serial/sunhv.c @@ -217,10 +217,10 @@ static irqreturn_t sunhv_interrupt(int irq, void *dev= _id) struct tty_port *tport; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); tport =3D receive_chars(port); transmit_chars(port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 if (tport) tty_flip_buffer_push(tport); @@ -271,7 +271,7 @@ static void sunhv_send_xchar(struct uart_port *port, ch= ar ch) if (ch =3D=3D __DISABLED_CHAR) return; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 while (limit-- > 0) { long status =3D sun4v_con_putchar(ch); @@ -280,7 +280,7 @@ static void sunhv_send_xchar(struct uart_port *port, ch= ar ch) udelay(1); } =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /* port->lock held by caller. */ @@ -295,7 +295,7 @@ static void sunhv_break_ctl(struct uart_port *port, int= break_state) unsigned long flags; int limit =3D 10000; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 while (limit-- > 0) { long status =3D sun4v_con_putchar(CON_BREAK); @@ -304,7 +304,7 @@ static void sunhv_break_ctl(struct uart_port *port, int= break_state) udelay(1); } =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } } =20 @@ -328,7 +328,7 @@ static void sunhv_set_termios(struct uart_port *port, s= truct ktermios *termios, unsigned int iflag, cflag; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 iflag =3D termios->c_iflag; cflag =3D termios->c_cflag; @@ -343,7 +343,7 @@ static void sunhv_set_termios(struct uart_port *port, s= truct ktermios *termios, uart_update_timeout(port, cflag, (port->uartclk / (16 * quot))); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *sunhv_type(struct uart_port *port) @@ -437,9 +437,9 @@ static void sunhv_console_write_paged(struct console *c= on, const char *s, unsign int locked =3D 1; =20 if (port->sysrq || oops_in_progress) - locked =3D spin_trylock_irqsave(&port->lock, flags); + locked =3D uart_port_trylock_irqsave(port, &flags); else - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 while (n > 0) { unsigned long ra =3D __pa(con_write_page); @@ -470,7 +470,7 @@ static void sunhv_console_write_paged(struct console *c= on, const char *s, unsign } =20 if (locked) - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static inline void sunhv_console_putchar(struct uart_port *port, char c) @@ -492,9 +492,9 @@ static void sunhv_console_write_bychar(struct console *= con, const char *s, unsig int i, locked =3D 1; =20 if (port->sysrq || oops_in_progress) - locked =3D spin_trylock_irqsave(&port->lock, flags); + locked =3D uart_port_trylock_irqsave(port, &flags); else - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 for (i =3D 0; i < n; i++) { if (*s =3D=3D '\n') @@ -503,7 +503,7 @@ static void sunhv_console_write_bychar(struct console *= con, const char *s, unsig } =20 if (locked) - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static struct console sunhv_console =3D { --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5DAAEEAA63 for ; Thu, 14 Sep 2023 18:43:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240866AbjINSnd (ORCPT ); Thu, 14 Sep 2023 14:43:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242020AbjINSla (ORCPT ); Thu, 14 Sep 2023 14:41:30 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17E992D6A; Thu, 14 Sep 2023 11:39:09 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716747; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6rrbJT9gAkuxqhBetlwX4STkcn6NRVLcBqG1WOPdKag=; b=Hy4pmQwrWiTg/Sk0lCuQa1kxE8/nB3RMmlGgMlxSI4lXcb0kwyeuXW11S9xZyynbrGkP2i Kq157hQUg26F3mY45MSuS3gyTKwdGM+jOio00+H3bLYvmtG+KVEAuOsqaTaU9oloO/9SoT SCJYc97+M10VosKuPvrsTUISMdLr8tHwQWTBvEZhR+nJJvPgLsCK4EHWOXX4bn+cL3FGkL nkok45hZinNMFOON6+PzIsZ5/KAr0WUiF9nIVBoLFbxOj2oFhnvxc4lVAAkdIKq2fwUGgA DDd2T+3IkSyjLZAMwmLxpwZNWvytbf8ep+qgUcriMPH/X0jWRW9TgOeRHv2VXQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716747; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6rrbJT9gAkuxqhBetlwX4STkcn6NRVLcBqG1WOPdKag=; b=ufFE+TzqR1c1IghPpzdGrNrWlVOJW647t33n4zmoZiZkEaPOPWGTffgRmUipOkFmFsuWv2 iFh50QKCm7tCSWAw== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Hammer Hsieh Subject: [PATCH tty v1 66/74] serial: sunplus-uart: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:23 +0206 Message-Id: <20230914183831.587273-67-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/sunplus-uart.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/tty/serial/sunplus-uart.c b/drivers/tty/serial/sunplus= -uart.c index 3aacd5eb414c..4251f4e1ba99 100644 --- a/drivers/tty/serial/sunplus-uart.c +++ b/drivers/tty/serial/sunplus-uart.c @@ -184,7 +184,7 @@ static void sunplus_break_ctl(struct uart_port *port, i= nt ctl) unsigned long flags; unsigned int lcr; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 lcr =3D readl(port->membase + SUP_UART_LCR); =20 @@ -195,7 +195,7 @@ static void sunplus_break_ctl(struct uart_port *port, i= nt ctl) =20 writel(lcr, port->membase + SUP_UART_LCR); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void transmit_chars(struct uart_port *port) @@ -277,7 +277,7 @@ static irqreturn_t sunplus_uart_irq(int irq, void *args) struct uart_port *port =3D args; unsigned int isc; =20 - spin_lock(&port->lock); + uart_port_lock(port); =20 isc =3D readl(port->membase + SUP_UART_ISC); =20 @@ -287,7 +287,7 @@ static irqreturn_t sunplus_uart_irq(int irq, void *args) if (isc & SUP_UART_ISC_TX) transmit_chars(port); =20 - spin_unlock(&port->lock); + uart_port_unlock(port); =20 return IRQ_HANDLED; } @@ -302,14 +302,14 @@ static int sunplus_startup(struct uart_port *port) if (ret) return ret; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); /* isc define Bit[7:4] int setting, Bit[3:0] int status * isc register will clean Bit[3:0] int status after read * only do a write to Bit[7:4] int setting */ isc |=3D SUP_UART_ISC_RXM; writel(isc, port->membase + SUP_UART_ISC); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return 0; } @@ -318,13 +318,13 @@ static void sunplus_shutdown(struct uart_port *port) { unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); /* isc define Bit[7:4] int setting, Bit[3:0] int status * isc register will clean Bit[3:0] int status after read * only do a write to Bit[7:4] int setting */ writel(0, port->membase + SUP_UART_ISC); /* disable all interrupt */ - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 free_irq(port->irq, port); } @@ -372,7 +372,7 @@ static void sunplus_set_termios(struct uart_port *port, lcr |=3D UART_LCR_EPAR; } =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 uart_update_timeout(port, termios->c_cflag, baud); =20 @@ -407,7 +407,7 @@ static void sunplus_set_termios(struct uart_port *port, writel(div_l, port->membase + SUP_UART_DIV_L); writel(lcr, port->membase + SUP_UART_LCR); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void sunplus_set_ldisc(struct uart_port *port, struct ktermios *ter= mios) @@ -517,15 +517,15 @@ static void sunplus_console_write(struct console *co, if (sunplus_console_ports[co->index]->port.sysrq) locked =3D 0; else if (oops_in_progress) - locked =3D spin_trylock(&sunplus_console_ports[co->index]->port.lock); + locked =3D uart_port_trylock(&sunplus_console_ports[co->index]->port); else - spin_lock(&sunplus_console_ports[co->index]->port.lock); + uart_port_lock(&sunplus_console_ports[co->index]->port); =20 uart_console_write(&sunplus_console_ports[co->index]->port, s, count, sunplus_uart_console_putchar); =20 if (locked) - spin_unlock(&sunplus_console_ports[co->index]->port.lock); + uart_port_unlock(&sunplus_console_ports[co->index]->port); =20 local_irq_restore(flags); } --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEDC8EEAA5D for ; Thu, 14 Sep 2023 18:43:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242142AbjINSnn (ORCPT ); Thu, 14 Sep 2023 14:43:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242137AbjINSlk (ORCPT ); Thu, 14 Sep 2023 14:41:40 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81A5D2D79; Thu, 14 Sep 2023 11:39:09 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716748; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZmN9t/TOdcgFZ+bmPfvXJ91pUl/2gBg4MuuLLO43TiA=; b=lZZMwROiXF7iHdvpNl7+JZXd8JHRJxlrJO/O2a6l7jlyYnndDS3tbJpaC3zOhAM71f9XrS kcepKr8jfbkARy8zvIO9bEET/k6xLgj2yLmNwyxHjkw2RvlXdoPKqQXnONb/aNnxgpPan+ 9Xz/tRfiwxPA68mPgAGrVkTc+Tl4Fm4VNmw4Nn121e+n9hfCQj9x2IovyO/S2ZS4O7csnI wefbsvV230d8cvWK6HUe27OS7SVPRrn5o38LxRhS//3ha/xyhCazNacRZKLxK7JvVihT5r EPUApL/yX8DGaPnkiSmvn9GiANGQlCO0f0Q0IKmp1Z1vnA+Jz6FDNtHHFKUT1w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716748; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZmN9t/TOdcgFZ+bmPfvXJ91pUl/2gBg4MuuLLO43TiA=; b=W6elDBkcls6Us2UZ8xmu8+vQvXuShUMOnWGdO6CyEEv3LDCbm3pFnjCa1k2m7TDXeaA0rL zJhp0dPySNVny4Dg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, "David S. Miller" , sparclinux@vger.kernel.org Subject: [PATCH tty v1 67/74] serial: sunsab: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:24 +0206 Message-Id: <20230914183831.587273-68-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/sunsab.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/tty/serial/sunsab.c b/drivers/tty/serial/sunsab.c index 40eeaf835bba..6aa51a6f8063 100644 --- a/drivers/tty/serial/sunsab.c +++ b/drivers/tty/serial/sunsab.c @@ -310,7 +310,7 @@ static irqreturn_t sunsab_interrupt(int irq, void *dev_= id) unsigned long flags; unsigned char gis; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 status.stat =3D 0; gis =3D readb(&up->regs->r.gis) >> up->gis_shift; @@ -331,7 +331,7 @@ static irqreturn_t sunsab_interrupt(int irq, void *dev_= id) transmit_chars(up, &status); } =20 - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =20 if (port) tty_flip_buffer_push(port); @@ -473,12 +473,12 @@ static void sunsab_send_xchar(struct uart_port *port,= char ch) if (ch =3D=3D __DISABLED_CHAR) return; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 sunsab_tec_wait(up); writeb(ch, &up->regs->w.tic); =20 - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 /* port->lock held by caller. */ @@ -499,7 +499,7 @@ static void sunsab_break_ctl(struct uart_port *port, in= t break_state) unsigned long flags; unsigned char val; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 val =3D up->cached_dafo; if (break_state) @@ -512,7 +512,7 @@ static void sunsab_break_ctl(struct uart_port *port, in= t break_state) if (test_bit(SAB82532_XPR, &up->irqflags)) sunsab_tx_idle(up); =20 - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 /* port->lock is not held. */ @@ -527,7 +527,7 @@ static int sunsab_startup(struct uart_port *port) if (err) return err; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 /* * Wait for any commands or immediate characters @@ -582,7 +582,7 @@ static int sunsab_startup(struct uart_port *port) set_bit(SAB82532_ALLS, &up->irqflags); set_bit(SAB82532_XPR, &up->irqflags); =20 - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =20 return 0; } @@ -594,7 +594,7 @@ static void sunsab_shutdown(struct uart_port *port) container_of(port, struct uart_sunsab_port, port); unsigned long flags; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 /* Disable Interrupts */ up->interrupt_mask0 =3D 0xff; @@ -628,7 +628,7 @@ static void sunsab_shutdown(struct uart_port *port) writeb(tmp, &up->regs->rw.ccr0); #endif =20 - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); free_irq(up->port.irq, up); } =20 @@ -779,9 +779,9 @@ static void sunsab_set_termios(struct uart_port *port, = struct ktermios *termios, unsigned int baud =3D uart_get_baud_rate(port, termios, old, 0, 4000000); unsigned int quot =3D uart_get_divisor(port, baud); =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); sunsab_convert_to_sab(up, termios->c_cflag, termios->c_iflag, baud, quot); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 static const char *sunsab_type(struct uart_port *port) @@ -857,15 +857,15 @@ static void sunsab_console_write(struct console *con,= const char *s, unsigned n) int locked =3D 1; =20 if (up->port.sysrq || oops_in_progress) - locked =3D spin_trylock_irqsave(&up->port.lock, flags); + locked =3D uart_port_trylock_irqsave(&up->port, &flags); else - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 uart_console_write(&up->port, s, n, sunsab_console_putchar); sunsab_tec_wait(up); =20 if (locked) - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 static int sunsab_console_setup(struct console *con, char *options) @@ -914,7 +914,7 @@ static int sunsab_console_setup(struct console *con, ch= ar *options) */ sunsab_startup(&up->port); =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 /* * Finally, enable interrupts @@ -932,7 +932,7 @@ static int sunsab_console_setup(struct console *con, ch= ar *options) sunsab_convert_to_sab(up, con->cflag, 0, baud, quot); sunsab_set_mctrl(&up->port, TIOCM_DTR | TIOCM_RTS); =20 - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =09 return 0; } --=20 2.39.2 From nobody Fri Sep 20 10:01:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0204AEEAA62 for ; Thu, 14 Sep 2023 18:43:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242215AbjINSnr (ORCPT ); Thu, 14 Sep 2023 14:43:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242154AbjINSlo (ORCPT ); Thu, 14 Sep 2023 14:41:44 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAA022D7E; Thu, 14 Sep 2023 11:39:09 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716748; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2MuEzqV2MApXOIyUF4YBrB1B536nPDREowgJZ2d68qA=; b=xvmfPcPk/suTlgqjD+BtIaBilvzFLWj48bXIcjeOhIpaSNN1H51BfFuMizAILbEUldtvsc YaDKtOC+rApZKGI8x1tmVp1KAfLX01Ln/iNU4eFwmRs3PX/njFbvcr3pCSWZ96T+bQ+pLd muy+wsrO8q/xD8cB96W0qsqVxT4ekius3oPRBIpAmtZJhdRESWxv7o2v5+1J/Y3RDEiyal T+QO7GHlT/3XjKbEd+sFLgpx4SU0ddET0VFeVaiUvgMGt7QbETrlJynegjawUD9v9R1oL7 QRrQKtwgIjIVdhlILqLy5m14I2aIa9fxjX9DvpCu4t5q8GGEZ/1Bj9DeA3fJ9A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716748; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2MuEzqV2MApXOIyUF4YBrB1B536nPDREowgJZ2d68qA=; b=zpHOCNIL8h8OfyKvzvhHyDV0VPI+SPQvDTgYSCYX1wQ696ErtKnfs5fE9Kq+yyxSN2uQJa OaErNNxOxq2VSeBg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, "David S. Miller" , sparclinux@vger.kernel.org Subject: [PATCH tty v1 68/74] serial: sunsu: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:25 +0206 Message-Id: <20230914183831.587273-69-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/sunsu.c | 46 +++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/drivers/tty/serial/sunsu.c b/drivers/tty/serial/sunsu.c index 58a4342ad0f9..1e051cc2591c 100644 --- a/drivers/tty/serial/sunsu.c +++ b/drivers/tty/serial/sunsu.c @@ -212,9 +212,9 @@ static void enable_rsa(struct uart_sunsu_port *up) { if (up->port.type =3D=3D PORT_RSA) { if (up->port.uartclk !=3D SERIAL_RSA_BAUD_BASE * 16) { - spin_lock_irq(&up->port.lock); + uart_port_lock_irq(&up->port); __enable_rsa(up); - spin_unlock_irq(&up->port.lock); + uart_port_unlock_irq(&up->port); } if (up->port.uartclk =3D=3D SERIAL_RSA_BAUD_BASE * 16) serial_outp(up, UART_RSA_FRR, 0); @@ -234,7 +234,7 @@ static void disable_rsa(struct uart_sunsu_port *up) =20 if (up->port.type =3D=3D PORT_RSA && up->port.uartclk =3D=3D SERIAL_RSA_BAUD_BASE * 16) { - spin_lock_irq(&up->port.lock); + uart_port_lock_irq(&up->port); =20 mode =3D serial_inp(up, UART_RSA_MSR); result =3D !(mode & UART_RSA_MSR_FIFO); @@ -247,7 +247,7 @@ static void disable_rsa(struct uart_sunsu_port *up) =20 if (result) up->port.uartclk =3D SERIAL_RSA_BAUD_BASE_LO * 16; - spin_unlock_irq(&up->port.lock); + uart_port_unlock_irq(&up->port); } } #endif /* CONFIG_SERIAL_8250_RSA */ @@ -311,10 +311,10 @@ static void sunsu_enable_ms(struct uart_port *port) container_of(port, struct uart_sunsu_port, port); unsigned long flags; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); up->ier |=3D UART_IER_MSI; serial_out(up, UART_IER, up->ier); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 static void @@ -456,7 +456,7 @@ static irqreturn_t sunsu_serial_interrupt(int irq, void= *dev_id) unsigned long flags; unsigned char status; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 do { status =3D serial_inp(up, UART_LSR); @@ -470,7 +470,7 @@ static irqreturn_t sunsu_serial_interrupt(int irq, void= *dev_id) =20 } while (!(serial_in(up, UART_IIR) & UART_IIR_NO_INT)); =20 - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =20 return IRQ_HANDLED; } @@ -545,9 +545,9 @@ static unsigned int sunsu_tx_empty(struct uart_port *po= rt) unsigned long flags; unsigned int ret; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); ret =3D serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0; - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =20 return ret; } @@ -599,13 +599,13 @@ static void sunsu_break_ctl(struct uart_port *port, i= nt break_state) container_of(port, struct uart_sunsu_port, port); unsigned long flags; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); if (break_state =3D=3D -1) up->lcr |=3D UART_LCR_SBC; else up->lcr &=3D ~UART_LCR_SBC; serial_out(up, UART_LCR, up->lcr); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 static int sunsu_startup(struct uart_port *port) @@ -683,12 +683,12 @@ static int sunsu_startup(struct uart_port *port) */ serial_outp(up, UART_LCR, UART_LCR_WLEN8); =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 up->port.mctrl |=3D TIOCM_OUT2; =20 sunsu_set_mctrl(&up->port, up->port.mctrl); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =20 /* * Finally, enable interrupts. Note: Modem status interrupts @@ -731,7 +731,7 @@ static void sunsu_shutdown(struct uart_port *port) up->ier =3D 0; serial_outp(up, UART_IER, 0); =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); if (up->port.flags & UPF_FOURPORT) { /* reset interrupts on the AST Fourport board */ inb((up->port.iobase & 0xfe0) | 0x1f); @@ -740,7 +740,7 @@ static void sunsu_shutdown(struct uart_port *port) up->port.mctrl &=3D ~TIOCM_OUT2; =20 sunsu_set_mctrl(&up->port, up->port.mctrl); - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =20 /* * Disable break condition and FIFOs @@ -826,7 +826,7 @@ sunsu_change_speed(struct uart_port *port, unsigned int= cflag, * Ok, we're now changing the port state. Do it with * interrupts disabled. */ - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 /* * Update the per-port timeout. @@ -891,7 +891,7 @@ sunsu_change_speed(struct uart_port *port, unsigned int= cflag, =20 up->cflag =3D cflag; =20 - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 static void @@ -1038,7 +1038,7 @@ static void sunsu_autoconfig(struct uart_sunsu_port *= up) up->type_probed =3D PORT_UNKNOWN; up->port.iotype =3D UPIO_MEM; =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 if (!(up->port.flags & UPF_BUGGY_UART)) { /* @@ -1173,7 +1173,7 @@ static void sunsu_autoconfig(struct uart_sunsu_port *= up) serial_outp(up, UART_IER, 0); =20 out: - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 static struct uart_driver sunsu_reg =3D { @@ -1298,9 +1298,9 @@ static void sunsu_console_write(struct console *co, c= onst char *s, int locked =3D 1; =20 if (up->port.sysrq || oops_in_progress) - locked =3D spin_trylock_irqsave(&up->port.lock, flags); + locked =3D uart_port_trylock_irqsave(&up->port, &flags); else - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 /* * First save the UER then disable the interrupts @@ -1318,7 +1318,7 @@ static void sunsu_console_write(struct console *co, c= onst char *s, serial_out(up, UART_IER, ier); =20 if (locked) - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 /* --=20 2.39.2 From nobody Fri Sep 20 10:01:57 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E58AEEEAA62 for ; Thu, 14 Sep 2023 18:43:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242158AbjINSn7 (ORCPT ); Thu, 14 Sep 2023 14:43:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241107AbjINSl6 (ORCPT ); Thu, 14 Sep 2023 14:41:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F12C30CF; Thu, 14 Sep 2023 11:39:10 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716748; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZfmijAtC3g1oYJPusPmN4eARviwbFrdwcagGmP/zuzk=; b=R2v6uaMQ7CS6ZYHIZPSM59WMeA2cANUhi9CnTM0Q+Duf7YKQNnN2wOKSAsfEbnMWavbWDP Jb/eDeirjaQ1SF+YR+/rwnARnLUtPdjYWm0WQ3Z9y8oGIidSsdYMJQ1jL5Bzkc9+c9PrhJ Uec7tsI8SR8BZsy6G6Ntr48hN4RwmS5nRSZQMmcBKXUsEEBR1kABDz/PNircItNuiFC9Qw M+2Fz5V0TZYL5dV7wEdsX9ZAQwnYC5Yu87oebcBbKUZBJdG4kibVw51vb6T8Ze13MzAX7M RuK4JzT9fQ9xOR9hXdeFwQqP2NFtFJ5Z9HckO+QC+G0xaRLlWuu7LkgDQMc4hg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716748; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZfmijAtC3g1oYJPusPmN4eARviwbFrdwcagGmP/zuzk=; b=Pm8yyxP5/5v8PDUy4f7SgJldp6MTI6kgWYYQfNDw+CSvuHHQOu92wjI/bymXTaAvCPlf9d 1EX+IZ/ElO3HZ3BA== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, "David S. Miller" , sparclinux@vger.kernel.org Subject: [PATCH tty v1 69/74] serial: sunzilog: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:26 +0206 Message-Id: <20230914183831.587273-70-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/sunzilog.c | 42 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/drivers/tty/serial/sunzilog.c b/drivers/tty/serial/sunzilog.c index c8c71c56264c..d3b5e864b727 100644 --- a/drivers/tty/serial/sunzilog.c +++ b/drivers/tty/serial/sunzilog.c @@ -531,7 +531,7 @@ static irqreturn_t sunzilog_interrupt(int irq, void *de= v_id) struct tty_port *port; unsigned char r3; =20 - spin_lock(&up->port.lock); + uart_port_lock(&up->port); r3 =3D read_zsreg(channel, R3); =20 /* Channel A */ @@ -548,7 +548,7 @@ static irqreturn_t sunzilog_interrupt(int irq, void *de= v_id) if (r3 & CHATxIP) sunzilog_transmit_chars(up, channel); } - spin_unlock(&up->port.lock); + uart_port_unlock(&up->port); =20 if (port) tty_flip_buffer_push(port); @@ -557,7 +557,7 @@ static irqreturn_t sunzilog_interrupt(int irq, void *de= v_id) up =3D up->next; channel =3D ZILOG_CHANNEL_FROM_PORT(&up->port); =20 - spin_lock(&up->port.lock); + uart_port_lock(&up->port); port =3D NULL; if (r3 & (CHBEXT | CHBTxIP | CHBRxIP)) { writeb(RES_H_IUS, &channel->control); @@ -571,7 +571,7 @@ static irqreturn_t sunzilog_interrupt(int irq, void *de= v_id) if (r3 & CHBTxIP) sunzilog_transmit_chars(up, channel); } - spin_unlock(&up->port.lock); + uart_port_unlock(&up->port); =20 if (port) tty_flip_buffer_push(port); @@ -604,11 +604,11 @@ static unsigned int sunzilog_tx_empty(struct uart_por= t *port) unsigned char status; unsigned int ret; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 status =3D sunzilog_read_channel_status(port); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 if (status & Tx_BUF_EMP) ret =3D TIOCSER_TEMT; @@ -764,7 +764,7 @@ static void sunzilog_break_ctl(struct uart_port *port, = int break_state) else clear_bits |=3D SND_BRK; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 new_reg =3D (up->curregs[R5] | set_bits) & ~clear_bits; if (new_reg !=3D up->curregs[R5]) { @@ -774,7 +774,7 @@ static void sunzilog_break_ctl(struct uart_port *port, = int break_state) write_zsreg(channel, R5, up->curregs[R5]); } =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static void __sunzilog_startup(struct uart_sunzilog_port *up) @@ -800,9 +800,9 @@ static int sunzilog_startup(struct uart_port *port) if (ZS_IS_CONS(up)) return 0; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); __sunzilog_startup(up); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); return 0; } =20 @@ -840,7 +840,7 @@ static void sunzilog_shutdown(struct uart_port *port) if (ZS_IS_CONS(up)) return; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 channel =3D ZILOG_CHANNEL_FROM_PORT(port); =20 @@ -853,7 +853,7 @@ static void sunzilog_shutdown(struct uart_port *port) up->curregs[R5] &=3D ~SND_BRK; sunzilog_maybe_update_regs(up, channel); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /* Shared by TTY driver and serial console setup. The port lock is held @@ -945,7 +945,7 @@ sunzilog_set_termios(struct uart_port *port, struct kte= rmios *termios, =20 baud =3D uart_get_baud_rate(port, termios, old, 1200, 76800); =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 brg =3D BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR); =20 @@ -962,7 +962,7 @@ sunzilog_set_termios(struct uart_port *port, struct kte= rmios *termios, =20 uart_update_timeout(port, termios->c_cflag, baud); =20 - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 static const char *sunzilog_type(struct uart_port *port) @@ -1201,15 +1201,15 @@ sunzilog_console_write(struct console *con, const c= har *s, unsigned int count) int locked =3D 1; =20 if (up->port.sysrq || oops_in_progress) - locked =3D spin_trylock_irqsave(&up->port.lock, flags); + locked =3D uart_port_trylock_irqsave(&up->port, &flags); else - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 uart_console_write(&up->port, s, count, sunzilog_putchar); udelay(2); =20 if (locked) - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); } =20 static int __init sunzilog_console_setup(struct console *con, char *option= s) @@ -1244,7 +1244,7 @@ static int __init sunzilog_console_setup(struct conso= le *con, char *options) =20 brg =3D BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR); =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); =20 up->curregs[R15] |=3D BRKIE; sunzilog_convert_to_zs(up, con->cflag, 0, brg); @@ -1252,7 +1252,7 @@ static int __init sunzilog_console_setup(struct conso= le *con, char *options) sunzilog_set_mctrl(&up->port, TIOCM_DTR | TIOCM_RTS); __sunzilog_startup(up); =20 - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =20 return 0; } @@ -1333,7 +1333,7 @@ static void sunzilog_init_hw(struct uart_sunzilog_por= t *up) =20 channel =3D ZILOG_CHANNEL_FROM_PORT(&up->port); =20 - spin_lock_irqsave(&up->port.lock, flags); + uart_port_lock_irqsave(&up->port, &flags); if (ZS_IS_CHANNEL_A(up)) { write_zsreg(channel, R9, FHWRES); ZSDELAY_LONG(); @@ -1383,7 +1383,7 @@ static void sunzilog_init_hw(struct uart_sunzilog_por= t *up) write_zsreg(channel, R9, up->curregs[R9]); } =20 - spin_unlock_irqrestore(&up->port.lock, flags); + uart_port_unlock_irqrestore(&up->port, flags); =20 #ifdef CONFIG_SERIO if (up->flags & (SUNZILOG_FLAG_CONS_KEYB | --=20 2.39.2 From nobody Fri Sep 20 10:01:57 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69BF5EEAA5D for ; Thu, 14 Sep 2023 18:44:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241795AbjINSoL (ORCPT ); Thu, 14 Sep 2023 14:44:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241670AbjINSmM (ORCPT ); Thu, 14 Sep 2023 14:42:12 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A3A330DD; Thu, 14 Sep 2023 11:39:10 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716749; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pan/Otko80+kx5GwrdBzH5rqxtGnDYcelX/t2yRhZyw=; b=zpUU9dctskVd4WufCbynS94+Ovx8KK1h4oYx/VysK2/dpx9kiRW4O/QxyeZooQF1eBJlYg zU3LU+Bh7QFa5pfsMSJ8KHpSkpf/gsyL67K87tpZ6AJbvTog7UvJKenbn8hDcHEE9p+jFM FHVu3GMxb6FaLdoRVy1KsU/BkBLLsWVH2MakIP6ye29Hl9LWhxcFMDGUzhILqB6/Izolr4 jehJ0JjYJP4OsrVERl7wOiyFiw2ERZPHYR0zK3OIu4M0iKW7iKuXtPt25ngJMqCNPhC8Oc MaVs9NHEsal5rbJya1yYTrlxJsFtEhZUKqNx7kXV7SDtGvorFSTBlM6pivDgIA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716749; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pan/Otko80+kx5GwrdBzH5rqxtGnDYcelX/t2yRhZyw=; b=h4GrYv7OIG3dE8qwnp/pMYJXI0g1EyToxTcSzaqK+cHIYOtxHObwnYxOf/KaP9TALJI2vI I/ttHd7kyn1pyGAg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH tty v1 70/74] serial: timbuart: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:27 +0206 Message-Id: <20230914183831.587273-71-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/timbuart.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/timbuart.c b/drivers/tty/serial/timbuart.c index 0859394a78cd..0cc6524f5e8b 100644 --- a/drivers/tty/serial/timbuart.c +++ b/drivers/tty/serial/timbuart.c @@ -174,7 +174,7 @@ static void timbuart_tasklet(struct tasklet_struct *t) struct timbuart_port *uart =3D from_tasklet(uart, t, tasklet); u32 isr, ier =3D 0; =20 - spin_lock(&uart->port.lock); + uart_port_lock(&uart->port); =20 isr =3D ioread32(uart->port.membase + TIMBUART_ISR); dev_dbg(uart->port.dev, "%s ISR: %x\n", __func__, isr); @@ -189,7 +189,7 @@ static void timbuart_tasklet(struct tasklet_struct *t) =20 iowrite32(ier, uart->port.membase + TIMBUART_IER); =20 - spin_unlock(&uart->port.lock); + uart_port_unlock(&uart->port); dev_dbg(uart->port.dev, "%s leaving\n", __func__); } =20 @@ -295,10 +295,10 @@ static void timbuart_set_termios(struct uart_port *po= rt, tty_termios_copy_hw(termios, old); tty_termios_encode_baud_rate(termios, baud, baud); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); iowrite8((u8)bindex, port->membase + TIMBUART_BAUDRATE); uart_update_timeout(port, termios->c_cflag, baud); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *timbuart_type(struct uart_port *port) --=20 2.39.2 From nobody Fri Sep 20 10:01:57 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18BC5EEAA5D for ; Thu, 14 Sep 2023 18:44:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242100AbjINSo1 (ORCPT ); Thu, 14 Sep 2023 14:44:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241678AbjINSmZ (ORCPT ); Thu, 14 Sep 2023 14:42:25 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26BB530E9; Thu, 14 Sep 2023 11:39:10 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716749; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/hVBmOc1UZslIEApH7wM7XsxUFX5t/MGHE6BhKB/8dE=; b=AIzFnxKF/HftpM563b/45gzbyhppoKPbb3WOngQIYKnzlm7KcT5/Vybf6MzS/v4xTyrK12 JvVsV7QJKVZmGnUgn0nEsruFmzmI0iHzv7T2p4MUocmRSBeVYG0ELH8B4/txM0fw4T+ixV lkebqhdVNlhxQEUzcC9685DeWUMGTAQWYHU1B7EL33hSjhmbOCzOgPg5i3t7KZYO9xzrGu tF96nxkf7bokQ+mLuVNIw5VGKvd/PFRAs5YqLSiPIqp3L5gD3+RzL7IoTCUsow58bfI95o 5BXOs9LfStTFfZ5nqYktxvrhIK4e39BAV9k56VfuHOgNduxbcOg1LoRWWgPLwQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716749; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/hVBmOc1UZslIEApH7wM7XsxUFX5t/MGHE6BhKB/8dE=; b=niG5LYzVOKr5LrHsGiYGWQ9Up9n4rYw0JaYgiLqr+u7qKMNYRJ0vmgV8KfsJV9UMV9dgdQ 1ddFUyocepCE1YAQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Peter Korsgaard Subject: [PATCH tty v1 71/74] serial: uartlite: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:28 +0206 Message-Id: <20230914183831.587273-72-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/uartlite.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c index b225a78f6175..404c14acafa5 100644 --- a/drivers/tty/serial/uartlite.c +++ b/drivers/tty/serial/uartlite.c @@ -216,11 +216,11 @@ static irqreturn_t ulite_isr(int irq, void *dev_id) unsigned long flags; =20 do { - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); stat =3D uart_in32(ULITE_STATUS, port); busy =3D ulite_receive(port, stat); busy |=3D ulite_transmit(port, stat); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); n++; } while (busy); =20 @@ -238,9 +238,9 @@ static unsigned int ulite_tx_empty(struct uart_port *po= rt) unsigned long flags; unsigned int ret; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); ret =3D uart_in32(ULITE_STATUS, port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return ret & ULITE_STATUS_TXEMPTY ? TIOCSER_TEMT : 0; } @@ -323,7 +323,7 @@ static void ulite_set_termios(struct uart_port *port, termios->c_cflag |=3D pdata->cflags & (PARENB | PARODD | CSIZE); tty_termios_encode_baud_rate(termios, pdata->baud, pdata->baud); =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 port->read_status_mask =3D ULITE_STATUS_RXVALID | ULITE_STATUS_OVERRUN | ULITE_STATUS_TXFULL; @@ -346,7 +346,7 @@ static void ulite_set_termios(struct uart_port *port, /* update timeout */ uart_update_timeout(port, termios->c_cflag, pdata->baud); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *ulite_type(struct uart_port *port) @@ -495,9 +495,9 @@ static void ulite_console_write(struct console *co, con= st char *s, int locked =3D 1; =20 if (oops_in_progress) { - locked =3D spin_trylock_irqsave(&port->lock, flags); + locked =3D uart_port_trylock_irqsave(port, &flags); } else - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* save and disable interrupt */ ier =3D uart_in32(ULITE_STATUS, port) & ULITE_STATUS_IE; @@ -512,7 +512,7 @@ static void ulite_console_write(struct console *co, con= st char *s, uart_out32(ULITE_CONTROL_IE, ULITE_CONTROL, port); =20 if (locked) - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static int ulite_console_setup(struct console *co, char *options) --=20 2.39.2 From nobody Fri Sep 20 10:01:57 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42932EEAA5D for ; Thu, 14 Sep 2023 18:44:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242127AbjINSob (ORCPT ); Thu, 14 Sep 2023 14:44:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241770AbjINSm3 (ORCPT ); Thu, 14 Sep 2023 14:42:29 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B8CF30F0; Thu, 14 Sep 2023 11:39:11 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716749; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h4vNSSSfbKzMTl5dIaX+nKFLqtsf/7qFsjWyC6l0EH0=; b=Btvxqnk4X2os6S5PrOaEvdQj5QO8ypBR/vcabWe3Gj5lhywtI34HkX9oqmk/uN8pbMIMfW I36GzlO0wMYRThI7KH1lMM/7nxcrYd1F9UhOwQDEjh8Ro10ODzExtzippTDQ7xkrpGTQ8R /afpljVJSX4wsuCyOws5j7Ay2eYLJtPePh3JpHOCtohYDUa24cIVB6b+2rSG/THHGoxEo1 2yJvl9M2jPGFBw6rEt9JljlPfa80dVAzz7Tk3ynReIsFt0hbRYD3tY6LfhhqbzzK8gEI+b 2P2Z7R5JL0rdoozdGeXCuCLpQ6NHXbmemuyVTCAScZ9i7ZcbmJfp99qRUiG8Jw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716749; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h4vNSSSfbKzMTl5dIaX+nKFLqtsf/7qFsjWyC6l0EH0=; b=skOOWWSloirPh2qLF10hQ5qRfe3vdZMKCUw5YKRzGtn51G9SzuSd9vTdeNuK3ueDbstJiR QFsCirT45QgYgiBA== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Timur Tabi , linuxppc-dev@lists.ozlabs.org Subject: [PATCH tty v1 72/74] serial: ucc_uart: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:29 +0206 Message-Id: <20230914183831.587273-73-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner Acked-by: Timur Tabi --- drivers/tty/serial/ucc_uart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/ucc_uart.c b/drivers/tty/serial/ucc_uart.c index b06661b80f41..ed7a6bb5596a 100644 --- a/drivers/tty/serial/ucc_uart.c +++ b/drivers/tty/serial/ucc_uart.c @@ -931,7 +931,7 @@ static void qe_uart_set_termios(struct uart_port *port, baud =3D uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); =20 /* Do we really need a spinlock here? */ - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Update the per-port timeout. */ uart_update_timeout(port, termios->c_cflag, baud); @@ -949,7 +949,7 @@ static void qe_uart_set_termios(struct uart_port *port, qe_setbrg(qe_port->us_info.tx_clock, baud, 16); } =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /* --=20 2.39.2 From nobody Fri Sep 20 10:01:57 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AF5BEEAA5D for ; Thu, 14 Sep 2023 18:44:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242045AbjINSof (ORCPT ); Thu, 14 Sep 2023 14:44:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242184AbjINSmm (ORCPT ); Thu, 14 Sep 2023 14:42:42 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C532430F6; Thu, 14 Sep 2023 11:39:11 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716750; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rrDPhfR+hcH2ulqT+tmz0NkOOAInrrikJFQ9+rrgXq4=; b=KfjPbYSme07Uy0HtarpcBzSFQ1/rLTznLPx3w1c4fArr0Y5kGtKzI/Ul9ouwJRXdZeU/J2 nadN6L18ZJIEZd4/qd77a5MMYgHznr/VdEX4YaV6YEVQg226CMthIInseqEgsZrt2JU/SM hrvtG4v2A0Aab0JSgQ/X2uc19tg5cN7/KsBEEnvqHijZr/ddzu7OZp4NR0MuQksSw5xf4H 1FvccofeL0vCGlTQQkCd1W6zru71arQ7y6L7TSn3XqKLX1H/RoT2P0vGRJJ8EmEGrSaGYG fykGh54wuVQ019BCJGhN5qdhXCIQatyCIpCafbGGWbvjoPvfFCdXRsxKA0zSAQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716750; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rrDPhfR+hcH2ulqT+tmz0NkOOAInrrikJFQ9+rrgXq4=; b=zw8NaAfgbtDwAq7EKORtMTWehRQcY0jJ9It/03eZCA4UwTMGL31oJD/g86N0no8XkSo7er qKWevdh86PM28vAg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Rob Herring , Mukesh Ojha , Yangtao Li , =?UTF-8?q?Jonathan=20Neusch=C3=A4fer?= , linux-arm-kernel@lists.infradead.org Subject: [PATCH tty v1 73/74] serial: vt8500: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:30 +0206 Message-Id: <20230914183831.587273-74-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/vt8500_serial.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/vt8500_serial.c b/drivers/tty/serial/vt8500= _serial.c index c5d5c2765119..78a1c1eea11b 100644 --- a/drivers/tty/serial/vt8500_serial.c +++ b/drivers/tty/serial/vt8500_serial.c @@ -227,7 +227,7 @@ static irqreturn_t vt8500_irq(int irq, void *dev_id) struct uart_port *port =3D dev_id; unsigned long isr; =20 - spin_lock(&port->lock); + uart_port_lock(port); isr =3D vt8500_read(port, VT8500_URISR); =20 /* Acknowledge active status bits */ @@ -240,7 +240,7 @@ static irqreturn_t vt8500_irq(int irq, void *dev_id) if (isr & TCTS) handle_delta_cts(port); =20 - spin_unlock(&port->lock); + uart_port_unlock(port); =20 return IRQ_HANDLED; } @@ -342,7 +342,7 @@ static void vt8500_set_termios(struct uart_port *port, unsigned int baud, lcr; unsigned int loops =3D 1000; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* calculate and set baud rate */ baud =3D uart_get_baud_rate(port, termios, old, 900, 921600); @@ -410,7 +410,7 @@ static void vt8500_set_termios(struct uart_port *port, vt8500_write(&vt8500_port->uart, 0x881, VT8500_URFCR); vt8500_write(&vt8500_port->uart, vt8500_port->ier, VT8500_URIER); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 static const char *vt8500_type(struct uart_port *port) --=20 2.39.2 From nobody Fri Sep 20 10:01:57 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8EAAEEAA63 for ; Thu, 14 Sep 2023 18:44:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241825AbjINSon (ORCPT ); Thu, 14 Sep 2023 14:44:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242189AbjINSm5 (ORCPT ); Thu, 14 Sep 2023 14:42:57 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32C753583; Thu, 14 Sep 2023 11:39:12 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716750; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GJtXjFQWXKNeQs2nL2+qrP6FYwoUINI6rwVKVGPhbxU=; b=Smto3ilWRwjFAG931YsffW+HoqJKbQcMRTmOo7z5AAELHBSg1EK70rg26n1N24tEW9h+e/ WyTNOAXTUly60x5p5uadirORR1qp/dsQWOug1txsQnqoZamxcgSqxEx3AfakxgesEb41o0 91BJCHp14XxMViT/S/f+kxcaxPDfhNLp/4lyCeOzZ0rTSuamsc5VriJq2BohFJgIdmGgab UigtGSeCdKeJqh8qkx71ePFVifIAeTFyYCdNvSOnYDOuhHSXvpRUFcOYf/xvCcWWULGjS1 g8xkLUfrwFizQ9ZhuW11q2/BMcJCuNdGVdYdVDRGhhKQ8B5+g4JWyCWh9sOs7w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716750; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GJtXjFQWXKNeQs2nL2+qrP6FYwoUINI6rwVKVGPhbxU=; b=IfKwzLt6V2gvWeERQdlBb8no0cSJvFxrzZxTD5K9r1Vc7iPP+pkOgbr29JHUUcvkPDsqzN FUypfeRKCJff99CQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Michal Simek , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Ruan Jinjie , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , linux-arm-kernel@lists.infradead.org Subject: [PATCH tty v1 74/74] serial: xilinx_uartps: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:31 +0206 Message-Id: <20230914183831.587273-75-john.ogness@linutronix.de> In-Reply-To: <20230914183831.587273-1-john.ogness@linutronix.de> References: <20230914183831.587273-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner --- drivers/tty/serial/xilinx_uartps.c | 56 +++++++++++++++--------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx= _uartps.c index 2e5e86a00a77..9c13dac1d4d1 100644 --- a/drivers/tty/serial/xilinx_uartps.c +++ b/drivers/tty/serial/xilinx_uartps.c @@ -346,7 +346,7 @@ static irqreturn_t cdns_uart_isr(int irq, void *dev_id) struct uart_port *port =3D (struct uart_port *)dev_id; unsigned int isrstatus; =20 - spin_lock(&port->lock); + uart_port_lock(port); =20 /* Read the interrupt status register to determine which * interrupt(s) is/are active and clear them. @@ -369,7 +369,7 @@ static irqreturn_t cdns_uart_isr(int irq, void *dev_id) !(readl(port->membase + CDNS_UART_CR) & CDNS_UART_CR_RX_DIS)) cdns_uart_handle_rx(dev_id, isrstatus); =20 - spin_unlock(&port->lock); + uart_port_unlock(port); return IRQ_HANDLED; } =20 @@ -506,14 +506,14 @@ static int cdns_uart_clk_notifier_cb(struct notifier_= block *nb, return NOTIFY_BAD; } =20 - spin_lock_irqsave(&cdns_uart->port->lock, flags); + uart_port_lock_irqsave(cdns_uart->port, &flags); =20 /* Disable the TX and RX to set baud rate */ ctrl_reg =3D readl(port->membase + CDNS_UART_CR); ctrl_reg |=3D CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS; writel(ctrl_reg, port->membase + CDNS_UART_CR); =20 - spin_unlock_irqrestore(&cdns_uart->port->lock, flags); + uart_port_unlock_irqrestore(cdns_uart->port, flags); =20 return NOTIFY_OK; } @@ -523,7 +523,7 @@ static int cdns_uart_clk_notifier_cb(struct notifier_bl= ock *nb, * frequency. */ =20 - spin_lock_irqsave(&cdns_uart->port->lock, flags); + uart_port_lock_irqsave(cdns_uart->port, &flags); =20 locked =3D 1; port->uartclk =3D ndata->new_rate; @@ -533,7 +533,7 @@ static int cdns_uart_clk_notifier_cb(struct notifier_bl= ock *nb, fallthrough; case ABORT_RATE_CHANGE: if (!locked) - spin_lock_irqsave(&cdns_uart->port->lock, flags); + uart_port_lock_irqsave(cdns_uart->port, &flags); =20 /* Set TX/RX Reset */ ctrl_reg =3D readl(port->membase + CDNS_UART_CR); @@ -555,7 +555,7 @@ static int cdns_uart_clk_notifier_cb(struct notifier_bl= ock *nb, ctrl_reg |=3D CDNS_UART_CR_TX_EN | CDNS_UART_CR_RX_EN; writel(ctrl_reg, port->membase + CDNS_UART_CR); =20 - spin_unlock_irqrestore(&cdns_uart->port->lock, flags); + uart_port_unlock_irqrestore(cdns_uart->port, flags); =20 return NOTIFY_OK; default: @@ -652,7 +652,7 @@ static void cdns_uart_break_ctl(struct uart_port *port,= int ctl) unsigned int status; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 status =3D readl(port->membase + CDNS_UART_CR); =20 @@ -664,7 +664,7 @@ static void cdns_uart_break_ctl(struct uart_port *port,= int ctl) writel(CDNS_UART_CR_STOPBRK | status, port->membase + CDNS_UART_CR); } - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /** @@ -683,7 +683,7 @@ static void cdns_uart_set_termios(struct uart_port *por= t, unsigned long flags; unsigned int ctrl_reg, mode_reg; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Disable the TX and RX to set baud rate */ ctrl_reg =3D readl(port->membase + CDNS_UART_CR); @@ -794,7 +794,7 @@ static void cdns_uart_set_termios(struct uart_port *por= t, cval &=3D ~CDNS_UART_MODEMCR_FCM; writel(cval, port->membase + CDNS_UART_MODEMCR); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /** @@ -813,7 +813,7 @@ static int cdns_uart_startup(struct uart_port *port) =20 is_brk_support =3D cdns_uart->quirks & CDNS_UART_RXBS_SUPPORT; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Disable the TX and RX */ writel(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS, @@ -861,7 +861,7 @@ static int cdns_uart_startup(struct uart_port *port) writel(readl(port->membase + CDNS_UART_ISR), port->membase + CDNS_UART_ISR); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 ret =3D request_irq(port->irq, cdns_uart_isr, 0, CDNS_UART_NAME, port); if (ret) { @@ -889,7 +889,7 @@ static void cdns_uart_shutdown(struct uart_port *port) int status; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Disable interrupts */ status =3D readl(port->membase + CDNS_UART_IMR); @@ -900,7 +900,7 @@ static void cdns_uart_shutdown(struct uart_port *port) writel(CDNS_UART_CR_TX_DIS | CDNS_UART_CR_RX_DIS, port->membase + CDNS_UART_CR); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 free_irq(port->irq, port); } @@ -1050,7 +1050,7 @@ static int cdns_uart_poll_get_char(struct uart_port *= port) int c; unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Check if FIFO is empty */ if (readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_RXEMPTY) @@ -1058,7 +1058,7 @@ static int cdns_uart_poll_get_char(struct uart_port *= port) else /* Read a character */ c =3D (unsigned char) readl(port->membase + CDNS_UART_FIFO); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); =20 return c; } @@ -1067,7 +1067,7 @@ static void cdns_uart_poll_put_char(struct uart_port = *port, unsigned char c) { unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Wait until FIFO is empty */ while (!(readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_TXEMPTY)) @@ -1080,7 +1080,7 @@ static void cdns_uart_poll_put_char(struct uart_port = *port, unsigned char c) while (!(readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_TXEMPTY)) cpu_relax(); =20 - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } #endif =20 @@ -1232,9 +1232,9 @@ static void cdns_uart_console_write(struct console *c= o, const char *s, if (port->sysrq) locked =3D 0; else if (oops_in_progress) - locked =3D spin_trylock_irqsave(&port->lock, flags); + locked =3D uart_port_trylock_irqsave(port, &flags); else - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* save and disable interrupt */ imr =3D readl(port->membase + CDNS_UART_IMR); @@ -1257,7 +1257,7 @@ static void cdns_uart_console_write(struct console *c= o, const char *s, writel(imr, port->membase + CDNS_UART_IER); =20 if (locked) - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /** @@ -1325,7 +1325,7 @@ static int cdns_uart_suspend(struct device *device) if (console_suspend_enabled && uart_console(port) && may_wake) { unsigned long flags; =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); /* Empty the receive FIFO 1st before making changes */ while (!(readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_RXEMPTY)) @@ -1334,7 +1334,7 @@ static int cdns_uart_suspend(struct device *device) writel(1, port->membase + CDNS_UART_RXWM); /* disable RX timeout interrups */ writel(CDNS_UART_IXR_TOUT, port->membase + CDNS_UART_IDR); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 /* @@ -1372,7 +1372,7 @@ static int cdns_uart_resume(struct device *device) return ret; } =20 - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); =20 /* Set TX/RX Reset */ ctrl_reg =3D readl(port->membase + CDNS_UART_CR); @@ -1392,14 +1392,14 @@ static int cdns_uart_resume(struct device *device) =20 clk_disable(cdns_uart->uartclk); clk_disable(cdns_uart->pclk); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } else { - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); /* restore original rx trigger level */ writel(rx_trigger_level, port->membase + CDNS_UART_RXWM); /* enable RX timeout interrupt */ writel(CDNS_UART_IXR_TOUT, port->membase + CDNS_UART_IER); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } =20 return uart_resume_port(cdns_uart->cdns_uart_driver, port); --=20 2.39.2