Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4265311rdb; Thu, 14 Sep 2023 17:59:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1q2qSJFArmK5OtRWsYevnlQkApFtB6iMToWqBfjrAaHG8hRaWiL12j96mzJ1Z7Q9wIm9y X-Received: by 2002:a05:6a21:6d8d:b0:159:c3d5:40bc with SMTP id wl13-20020a056a216d8d00b00159c3d540bcmr519480pzb.1.1694739551670; Thu, 14 Sep 2023 17:59:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694739551; cv=none; d=google.com; s=arc-20160816; b=lOuqY3qgS48yaKHpxeTgZItOx5XinIV8aOi1d0yVEOMf9ca2dOe1AJjE+QcV2O0URs waOKnjKHvtw0t35h5jz/iNG0N4EYAZ6lIx9F02J5efmwycFCoUKD9zg82FMXtJiMtx60 w5o9WIVHfDSIMibcqj85/JO4FSz72TNtyiZVxip7TOAO91T/vY/tXr1AVxpQrkHXUDE2 +mxQ3i6A1mlz2U+4mkkgTdcZPjj74OQ4Fb1SLBMTUV3GA/ryK0Qo5KtT3i/dsj6+xcKC nhFQu1f1SnLyAfP+dAunIOuMVZNtW8k1t1BgjbWl+u0xCTXTQjyZENWDo7SA8DtbCP4w 9m3w== 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=H6vrAwcgKz7ylA3cRQUQRd1w5cbqa1m8ev1xxDaRFwE=; fh=mrNgMbNmHeZYRJ6lnC1kSOAOzrAFLc2CVziCJv1fDyM=; b=JHiDpZt9zQDN2tC0KiovCRkeQ2rSK9vZcip679YhEJBTC9NiG2NYiI5DT6+djiasRX LxNKTbFIIc6LtTzwaDYyJWc5KYsijM1F8LaDHbV/VBFKuJMsl3ose4o3AgJwjC96fARc 6FEwuXjXWNMzMEkpCL21807dd+3bTgnUvhHeZ6awh6H1bhPBLc+Npcc6a+K5QCD2o++M +i9YYaSMiRrJ3TW7M+Byybpx3l+1bM7OaaY+BAjvAbcMOT+6HQH9boDLc75xjqWKul79 R79BJp5WVoPZNOIScI8ZPFYVGFyLsOjzRhMEqU8W79xAJLK3EhGsZxZpDHh1xvUey40F imkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=muqVm7X9; dkim=neutral (no key) header.i=@linutronix.de header.b=qZFEim1m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id h14-20020a170902680e00b001bbd83490efsi2446017plk.138.2023.09.14.17.59.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 17:59:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=muqVm7X9; dkim=neutral (no key) header.i=@linutronix.de header.b=qZFEim1m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 66D1E82F9274; Thu, 14 Sep 2023 11:41:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242066AbjINSkn (ORCPT + 99 others); Thu, 14 Sep 2023 14:40:43 -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: 8bit 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 (snail.vger.email [0.0.0.0]); Thu, 14 Sep 2023 11:41:20 -0700 (PDT) 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-uart.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_port *port) unsigned long flags; unsigned int st; - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); st = readl(port->membase + UART_STAT); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); return (st & STAT_TX_EMP) ? TIOCSER_TEMT : 0; } @@ -249,14 +249,14 @@ static void mvebu_uart_break_ctl(struct uart_port *port, int brk) unsigned int ctl; unsigned long flags; - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); ctl = readl(port->membase + UART_CTRL(port)); if (brk == -1) ctl |= CTRL_SND_BRK_SEQ; else ctl &= ~CTRL_SND_BRK_SEQ; writel(ctl, port->membase + UART_CTRL(port)); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } static void mvebu_uart_rx_chars(struct uart_port *port, unsigned int status) @@ -540,7 +540,7 @@ static void mvebu_uart_set_termios(struct uart_port *port, unsigned long flags; unsigned int baud, min_baud, max_baud; - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); port->read_status_mask = 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 *port, uart_update_timeout(port, termios->c_cflag, baud); } - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } 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 = 1; 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); ier = readl(port->membase + UART_CTRL(port)) & CTRL_BRK_INT; intr = readl(port->membase + UART_INTR(port)) & @@ -758,7 +758,7 @@ static void mvebu_uart_console_write(struct console *co, const char *s, } if (locked) - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } static int mvebu_uart_console_setup(struct console *co, char *options) -- 2.39.2