From patchwork Thu Sep 14 18:37:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 139934 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp708908vqi; Thu, 14 Sep 2023 17:18:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEEbdTgXM0SCzaj5j0w6ZhClFNU4IaomFOqPPIf7jEZvnhocGK9yfvr0XvyUxQ/n7ord4nh X-Received: by 2002:a17:90a:2bc8:b0:274:694c:167d with SMTP id n8-20020a17090a2bc800b00274694c167dmr97280pje.5.1694737087307; Thu, 14 Sep 2023 17:18:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694737087; cv=none; d=google.com; s=arc-20160816; b=Ph1QnA3mDGt/qeVhYYmoVPcKsfM7I2vca3n81SiPh8qtuXS02rQX3V/SYZNphdBqsl tNVGMPoFX+Fx31Dgdnm+Ie/JD8LLtzG5+kgTgBLWafyzCneBBxDKeybYaYBkoqTtVOZH dnOsRxky/pf44GPKZ2pc/Aur4yok/W7JAjAttLCHDBf3jU3SaCIoGrwoI+1qBT+jeIBs Cfvpyr4SQTuV9BQzO1S1bwYWEAQu2NsT5ihOWBCJ4OuyeKzHtb5Q4vHykbtA8wWWPYtL Tv+u11Zjoj6Ze0Zxj8dByd9ZyBCoLOrornodfuMf1TS69K543AFNgLY5Yf1Osg4bWWKO b7Lg== 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=k7D9LsjqZuZo5dBqqfv/ExL4revQqVd4yA1Xdog29cQ=; fh=rxGBgvkhlWzzmI/aI3J48f1ay17BdfhCuypL/fS/7YU=; b=ok20IlowdF9sC6LOb7TWo4cGmWsICq8wuA6ATJl9AlXuHDrif8sZ3xPiylJd/Yz7LN B9aIp/hVRRuYZ5EmsH1ERQvIYrokC4dtUe8BeNfYHl2NEDY9fHQDIbs1SGoNPEKr+7P+ koSSNxxvNiHuNoLoHUC4xKJ/RKmwSeB42q57O/hB7uTWu7WL1KSdZjguzFTOdi7zWQQB +ByqHo/ntAwmnbgTH+YVpC7gaSRP7L68HABuwvTUFC8WZWJ+yy3exgrMOqM6hVdS7SAQ mZ445nVr3FeMlewgNgYveXE2Cd/bUeh9wWMl7dqvzrJ5Kt3wHgz8jTl52VOEkIoFbtVM M+qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=eDObBDkc; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id s21-20020a63e815000000b005775a0cd009si2316715pgh.331.2023.09.14.17.18.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 17:18:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=eDObBDkc; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id D2AB883F38C9; Thu, 14 Sep 2023 11:39:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241759AbjINSjj (ORCPT + 33 others); Thu, 14 Sep 2023 14:39:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241675AbjINSix (ORCPT ); Thu, 14 Sep 2023 14:38:53 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C03E72115; Thu, 14 Sep 2023 11:38:48 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716727; 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=k7D9LsjqZuZo5dBqqfv/ExL4revQqVd4yA1Xdog29cQ=; b=eDObBDkcYp97Vikc2x/bBgVaipIN82wI+Nuxdvnn0VQ5FmGbVViHzrJviSZS3c25s+4h+o 642QV53qKfKLNBrjn6a+eNzVD1LPnjU0sW39bfdFCMwBwgBG9fdOCZLCzKcUriqCWjqwbh BeAHFIXIldQIEPNy4vHBC7/h1V5LisXKjDGO7I7VdtzhYYL0/AP/0QLTq+Qj2bsqtwFyLJ suFwkXQ1A9qFxfCbgIf48XqyuByw4g2nBe3DgYMzSq/d1c2xLHltB1I4pvoIqhnS8q4uRL bl3KL8ZDICk/1vUnGDd5JyRcfmjFCl+COv8nMyQDWl1p0/6ty60eHiJGbo99Vw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716727; 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=k7D9LsjqZuZo5dBqqfv/ExL4revQqVd4yA1Xdog29cQ=; b=wahnM7I+mOzIehgyY6oKhLre/DDgS5f9aweqXQAddREo15iBbFTZTQIhhZSzWLdmRNpBEN ZOE1ovRXuOSTwVCQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Richard Genoud , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , linux-arm-kernel@lists.infradead.org Subject: [PATCH tty v1 21/74] serial: atmel: Use port lock wrappers Date: Thu, 14 Sep 2023 20:43:38 +0206 Message-Id: <20230914183831.587273-22-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 (howler.vger.email [0.0.0.0]); Thu, 14 Sep 2023 11:39:40 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777060636111574726 X-GMAIL-MSGID: 1777060636111574726 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/atmel_serial.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index 88cdafa5ac54..1946fafc3f3e 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -861,7 +861,7 @@ static void atmel_complete_tx_dma(void *arg) struct dma_chan *chan = atmel_port->chan_tx; unsigned long flags; - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); if (chan) dmaengine_terminate_all(chan); @@ -893,7 +893,7 @@ static void atmel_complete_tx_dma(void *arg) atmel_port->tx_done_mask); } - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } static void atmel_release_tx_dma(struct uart_port *port) @@ -1711,9 +1711,9 @@ static void atmel_tasklet_rx_func(struct tasklet_struct *t) struct uart_port *port = &atmel_port->uart; /* The interrupt handler does not take the lock */ - spin_lock(&port->lock); + uart_port_lock(port); atmel_port->schedule_rx(port); - spin_unlock(&port->lock); + uart_port_unlock(port); } static void atmel_tasklet_tx_func(struct tasklet_struct *t) @@ -1723,9 +1723,9 @@ static void atmel_tasklet_tx_func(struct tasklet_struct *t) struct uart_port *port = &atmel_port->uart; /* The interrupt handler does not take the lock */ - spin_lock(&port->lock); + uart_port_lock(port); atmel_port->schedule_tx(port); - spin_unlock(&port->lock); + uart_port_unlock(port); } static void atmel_init_property(struct atmel_uart_port *atmel_port, @@ -2175,7 +2175,7 @@ static void atmel_set_termios(struct uart_port *port, } else mode |= ATMEL_US_PAR_NONE; - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); port->read_status_mask = ATMEL_US_OVRE; if (termios->c_iflag & INPCK) @@ -2377,22 +2377,22 @@ static void atmel_set_termios(struct uart_port *port, else atmel_disable_ms(port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } static void atmel_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); atmel_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); atmel_disable_ms(port); - spin_unlock_irq(&port->lock); + uart_port_unlock_irq(port); } } }