From patchwork Thu Sep 14 18:37:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 139927 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp706018vqi; Thu, 14 Sep 2023 17:11:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHX99mUM3+IPhJmJ0aeU0XlNHGXaXTmxUCmhSS1vcBIyXLp1Usp0uJ5DMQI3poJfT3NEzlj X-Received: by 2002:a05:6a20:7d84:b0:138:2fb8:6a14 with SMTP id v4-20020a056a207d8400b001382fb86a14mr454209pzj.3.1694736670999; Thu, 14 Sep 2023 17:11:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694736670; cv=none; d=google.com; s=arc-20160816; b=XKa+/mz8n5TulQc8/N7kEar9k56RRTENSR5oJ7ziA32KKasVnBmXKzDSwu7uFPKJpi K9xRsEfGUZ2zl1sirl4RUyMN8j4tpYmJ1RajhZUxJv2YAaQLqRUmxgkisoI978/UfniQ Lbzn7S/briI8RattwKqiRQkNhd9VIdosHFEW42P3XTRQ+Tla/DhgHbtc4ugOMr1azhHm wIa8Y1jYLd1hdkmQR1DYlVromstRu3LFIAYOdLAMvjMHmNokfisBrj3NZHQbJS9PlGSR pfF7HiE4pJVayFN3BmKvJeoBDsVi6lLUudInLHXDyXowIZRQ8k3EZPVyvbp/1UaCrk5c z2xw== 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=C/K94+x3VFE0qetYCzTIZYxK3St4nQt/7CBPmZkbDy0=; fh=uxOC62Jz5HfodjEBkBiYMTf4Dtywpx/KWV/4FqX2keM=; b=PpEshTa/iUFEGIylItL0xkyoBTHUcsBT95ngZcIcOVrFwJnNLRSAsWfdI/B4ItrZUy ED1aFrTMKfCvRDaZbw5oR2jaHm2EzLqUduWF46OOFGBtFt4k4CMmg9eibjtmzjcnif0j 9bgWc91f5ut10wa4a5pyXiv+3qqlHhvYWJ3sNUjNlrLMeNyiHL4d8VVqDmTJ+bveMkln oohU3PWOuvrUvC/r9jMJT/hCtwGBzG03HucbBxsXsnI9POEJ1oDtdWNDq7skjoDoSVN1 arAto6/DtCJ6PWgs4MdQuhV33H8EsCakkekT9Wwz14EQRNHn2Z9uxlqU8EW+HrkB5pTg WAcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=uXRvCbL7; 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id ca7-20020a056a00418700b00690208f26d7si2353046pfb.295.2023.09.14.17.11.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 17:11:10 -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=uXRvCbL7; 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 C57D98331E13; Thu, 14 Sep 2023 11:39:26 -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 S241910AbjINSjZ (ORCPT + 33 others); Thu, 14 Sep 2023 14:39:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241641AbjINSix (ORCPT ); Thu, 14 Sep 2023 14:38:53 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABDB42108; Thu, 14 Sep 2023 11:38:46 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716725; 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=C/K94+x3VFE0qetYCzTIZYxK3St4nQt/7CBPmZkbDy0=; b=uXRvCbL7vfpBV5pZH3vtwjfrVzht6pNDjcB+IJ3mBgRurMU50xvCNJEblOFTzf5irLDRjL pK76Su5YXYdA96s7uTDL+TFhhIFShdvVvONxSYP8omoCujJKqeMxXR1eyZRSFbobsWrIUy PuruvXaJ+DSg6ucY45X9NISbI6TdO8NKvT7EaEN0vq/wjQpTOyIpE1dcb3b8Labtt7mgRP Z2gy2rBsZLF+77grTxPukz/I4i9bhDYeGjM164jFavZhuLVZBbvs1yKX5To7smV47VRwCg +pjT5c+alUEEPBMvhp2oaxk0qX/zXSVkiWZCDQktM/QzpgMdFU6AHyBmufwnTQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716725; 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=C/K94+x3VFE0qetYCzTIZYxK3St4nQt/7CBPmZkbDy0=; b=0eCUUL3vP8dQK2rfMC19TJ15tM6G1CJryy1OXDnP7smmbsbckCADcGIX4LYSmlXekjyfbx 1PiS2o1fQDOXmFCg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Russell King , Tobias Klauser , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , "Maciej W. Rozycki" Subject: [PATCH tty v1 16/74] serial: amba-pl010: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:33 +0206 Message-Id: <20230914183831.587273-17-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 (snail.vger.email [0.0.0.0]); Thu, 14 Sep 2023 11:39:26 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777060199378755555 X-GMAIL-MSGID: 1777060199378755555 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/amba-pl010.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/amba-pl010.c b/drivers/tty/serial/amba-pl010.c index b5a7404cbacb..eabbf8afc9b5 100644 --- a/drivers/tty/serial/amba-pl010.c +++ b/drivers/tty/serial/amba-pl010.c @@ -207,7 +207,7 @@ static irqreturn_t pl010_int(int irq, void *dev_id) unsigned int status, pass_counter = AMBA_ISR_PASS_LIMIT; int handled = 0; - spin_lock(&port->lock); + uart_port_lock(port); status = readb(port->membase + UART010_IIR); if (status) { @@ -228,7 +228,7 @@ static irqreturn_t pl010_int(int irq, void *dev_id) handled = 1; } - spin_unlock(&port->lock); + uart_port_unlock(port); return IRQ_RETVAL(handled); } @@ -270,14 +270,14 @@ static void pl010_break_ctl(struct uart_port *port, int break_state) unsigned long flags; unsigned int lcr_h; - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); lcr_h = readb(port->membase + UART010_LCRH); if (break_state == -1) lcr_h |= UART01x_LCRH_BRK; else lcr_h &= ~UART01x_LCRH_BRK; writel(lcr_h, port->membase + UART010_LCRH); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } static int pl010_startup(struct uart_port *port) @@ -385,7 +385,7 @@ pl010_set_termios(struct uart_port *port, struct ktermios *termios, if (port->fifosize > 1) lcr_h |= UART01x_LCRH_FEN; - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); /* * Update the per-port timeout. @@ -438,22 +438,22 @@ pl010_set_termios(struct uart_port *port, struct ktermios *termios, writel(lcr_h, port->membase + UART010_LCRH); writel(old_cr, port->membase + UART010_CR); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } static void pl010_set_ldisc(struct uart_port *port, struct ktermios *termios) { if (termios->c_line == N_PPS) { port->flags |= UPF_HARDPPS_CD; - spin_lock_irq(&port->lock); + uart_port_lock_irq(port); pl010_enable_ms(port); - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); } else { port->flags &= ~UPF_HARDPPS_CD; if (!UART_ENABLE_MS(port, termios->c_cflag)) { - spin_lock_irq(&port->lock); + uart_port_lock_irq(port); pl010_disable_ms(port); - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); } } }