From patchwork Thu Sep 14 18:38:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 139902 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp689253vqi; Thu, 14 Sep 2023 16:31:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGYIYFMY4pf0nqZYoO3wKZsOPEujV8Fn+Z2rEX0M8EiMenoyGB28ThR23q+Rk2IpKPDJuhU X-Received: by 2002:a17:902:c949:b0:1bb:b86e:8d60 with SMTP id i9-20020a170902c94900b001bbb86e8d60mr76980pla.46.1694734298790; Thu, 14 Sep 2023 16:31:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694734298; cv=none; d=google.com; s=arc-20160816; b=zCNgU7mcnsZlkupLflUqp5kY28Y8SQNeIL0PD58DGkMeVVAUeT83LmBADPjJ9oRIyS hYo8UbRdm8cwNpJ6mhEm2GxGYFLNvCTfdGFVZBCkjhDOQaf1Q9hFfjjStTL5OIuum0b1 IoZoOs2eJAZLxUfA+r9FDvQ2vz2OZOLnxj1XAuJuhwJqyfoJ7VsBh/PQzGD0hmggSsTS 3yf3+PZz54DoL4X9sw5fGLkgGZq1PoFPOJvpMnrpBBmxsv3wHn4a9DeDUInAtUx0swng qeCPJ9fmKo3heHHlDnUn8ENyKcYNQQRyKNgY71lulCB9trjdV5vrWMI3epA9hT1+1hi6 kiQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=Rtu6oqE59dzKnOzbdNG30qc4om/oIgRr8S/zbKifFdc=; fh=sLoG8GGafWMoIzrhP1zWZJios2vAvoRmN96U51FUg/o=; b=KIEagjRGa26H6I76pxnQ/3fKjYYcngFKfMVdOhpv7a94n3z+XjjQTU5xVGRQKsqNeu ReXaHl5dIkw86HCfw8Ln9m4IMU5gkycSc73qr2KgOhWcSR5YTPzpXbHovYnWd+FZQbVS UYijl3EueIUCMilctYnk82seGoBqp+6HiaIJ142gtPnvKjGbn1yH9pDXCCygdrEniPPX IeMXKC7SCq78NZAKN2qDQ9TAYLrCK7QmHzRbGEHiTnDy13n5AXf6xfBOVBXvgu3yA01D ZrVXKguESZvi0Hc/i/ogN3e+cmuOnXUpmf+sMwUutTvUwbRSlukD/xANknIzzdwDcf8N P/sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Ox3AVx2d; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id h12-20020a170902f54c00b001b892a54d89si2546985plf.629.2023.09.14.16.31.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 16:31:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Ox3AVx2d; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 22C8C825E48C; Thu, 14 Sep 2023 11:44:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241870AbjINSnF (ORCPT + 33 others); Thu, 14 Sep 2023 14:43:05 -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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 14 Sep 2023 11:44:02 -0700 (PDT) X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INVALID_DATE_TZ_ABSURD, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777057712340190839 X-GMAIL-MSGID: 1777057712340190839 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; - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); tport = receive_chars(port); transmit_chars(port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); if (tport) tty_flip_buffer_push(tport); @@ -271,7 +271,7 @@ static void sunhv_send_xchar(struct uart_port *port, char ch) if (ch == __DISABLED_CHAR) return; - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); while (limit-- > 0) { long status = sun4v_con_putchar(ch); @@ -280,7 +280,7 @@ static void sunhv_send_xchar(struct uart_port *port, char ch) udelay(1); } - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } /* 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 = 10000; - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); while (limit-- > 0) { long status = sun4v_con_putchar(CON_BREAK); @@ -304,7 +304,7 @@ static void sunhv_break_ctl(struct uart_port *port, int break_state) udelay(1); } - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } } @@ -328,7 +328,7 @@ static void sunhv_set_termios(struct uart_port *port, struct ktermios *termios, unsigned int iflag, cflag; unsigned long flags; - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); iflag = termios->c_iflag; cflag = termios->c_cflag; @@ -343,7 +343,7 @@ static void sunhv_set_termios(struct uart_port *port, struct ktermios *termios, uart_update_timeout(port, cflag, (port->uartclk / (16 * quot))); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } static const char *sunhv_type(struct uart_port *port) @@ -437,9 +437,9 @@ static void sunhv_console_write_paged(struct console *con, const char *s, unsign int locked = 1; if (port->sysrq || oops_in_progress) - locked = spin_trylock_irqsave(&port->lock, flags); + locked = uart_port_trylock_irqsave(port, &flags); else - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); while (n > 0) { unsigned long ra = __pa(con_write_page); @@ -470,7 +470,7 @@ static void sunhv_console_write_paged(struct console *con, const char *s, unsign } if (locked) - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } 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 = 1; if (port->sysrq || oops_in_progress) - locked = spin_trylock_irqsave(&port->lock, flags); + locked = uart_port_trylock_irqsave(port, &flags); else - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); for (i = 0; i < n; i++) { if (*s == '\n') @@ -503,7 +503,7 @@ static void sunhv_console_write_bychar(struct console *con, const char *s, unsig } if (locked) - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } static struct console sunhv_console = {