Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4319737rdb; Thu, 14 Sep 2023 20:35:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHg+yIKCiAt2o5xNdpHJt71J/q+qBo5my7nxJC55qKcnWhRhIteHGa55+ODQICCRqiyYgpU X-Received: by 2002:a05:6a00:248a:b0:68e:496a:7852 with SMTP id c10-20020a056a00248a00b0068e496a7852mr548028pfv.27.1694748949672; Thu, 14 Sep 2023 20:35:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694748949; cv=none; d=google.com; s=arc-20160816; b=sKTjYoyKtuWGUc7IWbpK6cmFyaZGOLIaiwRMYcLbfsivzqsNqW3Xjee+PDac4vh6Np c/u/bscO5QcDjLA9eNoflDh7aXOjXVSisRHBiEokY5XjQdCFFXeoO0BCz0CuY9zImjxW wqB8YV9AICkpHEcI5CXTjjaNf1luEmigbTyvYxyniD08kSMw3KyOBQDoeez9usrkRMT5 BYgPmjCX9BzIjrpap1UsAD8YNeKLe2d4bxzlJflQlmk9GLG+IULQA2x/hDK1D4HDJKpZ g1YE8DnyvzUv2uDkXEJk8cn3Mws4geCsgqcbkm6WHmhYtJVNtnf/VwWQi3L38QEyf6gu G5WA== 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=/1APoFz57Q+j1ahdXqu2UFCMnpKF7KLxKqz0dVY4BD4=; fh=U1HhFEWRW0W5wfDgM07h8FUQ9qnQPia9Ge0QUyZtL6U=; b=j4KL3aWcVGqCJt5z7aiHPyORv0Y6eq7E0cmodHwL+1dbiwx3PRGIhKmkm2nc1SqlwJ KuWkKRL7Fs43hTJjdPEjFVSnprbVDfTXoQRo91i+71TlpcfdX9D8XvXrw9Z6hGrQqmRR tPtcclmcTfb0MweiM55+UzsDiuIvnjECeeCvl6Fqdk+BYceqb05uuVgwlEDlTKn31i/M a6MGaTzeNZ+BuWqtSQJ1wvCrsQ9wewkfimCJcAzDpm8ead84brUONrXXCE0RHiKvrDPx GOhMdzR3XAZUZ60BhzOHSKQA+YHCalAdvlEUgDo746JL2xJ7dMrwUmqfn4oXuC0qyl8j /UFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=LoSvbJvi; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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. [23.128.96.37]) by mx.google.com with ESMTPS id u20-20020a056a00125400b006901504b6a3si2672856pfi.153.2023.09.14.20.35.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 20:35:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=LoSvbJvi; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 D96CE82B487C; Thu, 14 Sep 2023 11:40:50 -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 S241870AbjINSkd (ORCPT + 99 others); Thu, 14 Sep 2023 14:40:33 -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: 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:40:51 -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/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 *data) if (unlikely(!(irqflag & UARTn_INT_RX))) return IRQ_NONE; - spin_lock(&port->lock); + uart_port_lock(port); mps2_uart_write8(port, UARTn_INT_RX, UARTn_INT); mps2_uart_rx_chars(port); - spin_unlock(&port->lock); + uart_port_unlock(port); return IRQ_HANDLED; } @@ -206,12 +206,12 @@ static irqreturn_t mps2_uart_txirq(int irq, void *data) if (unlikely(!(irqflag & UARTn_INT_TX))) return IRQ_NONE; - spin_lock(&port->lock); + uart_port_lock(port); mps2_uart_write8(port, UARTn_INT_TX, UARTn_INT); mps2_uart_tx_chars(port); - spin_unlock(&port->lock); + uart_port_unlock(port); return IRQ_HANDLED; } @@ -222,7 +222,7 @@ static irqreturn_t mps2_uart_oerrirq(int irq, void *data) struct uart_port *port = data; u8 irqflag = mps2_uart_read8(port, UARTn_INT); - spin_lock(&port->lock); + uart_port_lock(port); if (irqflag & UARTn_INT_RX_OVERRUN) { struct tty_port *tport = &port->state->port; @@ -244,7 +244,7 @@ static irqreturn_t mps2_uart_oerrirq(int irq, void *data) handled = IRQ_HANDLED; } - spin_unlock(&port->lock); + uart_port_unlock(port); return handled; } @@ -356,12 +356,12 @@ mps2_uart_set_termios(struct uart_port *port, struct ktermios *termios, bauddiv = DIV_ROUND_CLOSEST(port->uartclk, baud); - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); uart_update_timeout(port, termios->c_cflag, baud); mps2_uart_write32(port, bauddiv, UARTn_BAUDDIV); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); if (tty_termios_baud_rate(termios)) tty_termios_encode_baud_rate(termios, baud, baud); -- 2.39.2