From patchwork Thu Sep 14 18:38:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 139870 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp655153vqi; Thu, 14 Sep 2023 15:11:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEjyhBUGPnLifrWQp1uDqynOaqh8sdXH4oEYKivjPr9Jj4hP0uAjhmDW2sL1w9CzwugyRNG X-Received: by 2002:a05:6870:2d1:b0:1b7:4521:14b6 with SMTP id r17-20020a05687002d100b001b7452114b6mr7401454oaf.5.1694729491541; Thu, 14 Sep 2023 15:11:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694729491; cv=none; d=google.com; s=arc-20160816; b=y05b8BevQ6rcUBmH+iU7pyyS8q6eZvpSZONb0Kg7iqpsQgtv1MVpqPQDz4oHkS5Tsr G2RJJOZ8kYPLUvOsUFMM/9XXfwMuC1mAKiccCAJD7IK/KRCm72BZnGcF8DbcQmlQSt7U aoSz5IKDi2gjyMdszjytgU8sV2LdroNrTA6vlj0lddvtpa58cmhVskKNczNvPHcXmAEY ug9YEK6vvAIzH22fJjxfILBS7pKwdhXolm8nEgGg2BuDRK+3F6Md/f4NT/lv1tfdqfmt RwfNPL4/IKgbj+2Dx0wwRu4rAcL6m+8jvpr5QsCh+QRqSToS7cJH9y14ER2BWFU1H5Dv E1Sw== 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=scaU8Ke6aOSrJaDl+5gO/v/Oetd46gqnVkH3I+dMdgg=; fh=iD9IPHmIjHEyjotGeWacNQqSU9sb8zaltRMmpITIsIk=; b=Z1bSz8VVzSo1hGnprlNiYJ/qHutZiSdc/a5lk5GE3VIOP94c3gVJmJx3XWNKupQzCx xIQ49kl/kdcZcvrXwSyUnnao7Jrey8afKaRkkLlH1qIsE4wwYrmYX1aT/XlvmNNPacgS s0GS1UaPPGBavuwSdLx+0F4tckTNjdMI5tB8G6CdvWSQOi5AiRUoi5i3iqKCApyJeeNW +QEZ/Vzq/dpOQRfKpsyg8o9N+M97rqXTQ7/aAp4wdTKPXakZPsoUe1HbwBjaG305PJ9W UIV2ihF5j0HpgWr+9EWAl4LFoadX4pCIZpnurjVWkMCv+q7nczIA4a/9tkNbu1mIGGL/ i5/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Mj0+Pe00; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 by33-20020a056a0205a100b00563796a3ec6si2401948pgb.570.2023.09.14.15.11.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 15:11:31 -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=Mj0+Pe00; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 2032181BDA6B; Thu, 14 Sep 2023 11:43:21 -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 S242077AbjINSmv (ORCPT + 33 others); Thu, 14 Sep 2023 14:42:51 -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 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:43:21 -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: 1777052671733277466 X-GMAIL-MSGID: 1777052671733277466 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 = ptr; u32 status; - spin_lock(&port->lock); + uart_port_lock(port); status = asc_in(port, ASC_STA); @@ -334,7 +334,7 @@ static irqreturn_t asc_interrupt(int irq, void *ptr) asc_transmit_chars(port); } - spin_unlock(&port->lock); + uart_port_unlock(port); return IRQ_HANDLED; } @@ -452,10 +452,10 @@ static void asc_pm(struct uart_port *port, unsigned int 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 = 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, struct ktermios *termios, baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); cflag = termios->c_cflag; - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); /* read control register */ ctrl_val = asc_in(port, ASC_CTL); @@ -594,7 +594,7 @@ static void asc_set_termios(struct uart_port *port, struct ktermios *termios, /* write final value and enable port */ asc_out(port, ASC_CTL, (ctrl_val | ASC_CTL_RUN)); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } 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 = 0; /* asc_interrupt has already claimed the lock */ else if (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); /* * 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); if (locked) - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } static int asc_console_setup(struct console *co, char *options)