From nobody Fri Sep 20 11:48:50 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