Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4254172rdb; Thu, 14 Sep 2023 17:26:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGkxDx9m1fQTFS3eC/3N1FiXd+3j0eN9wCU6SKQ1+9BW6vgYAANdWqaL06ytUO8YkRjgDWV X-Received: by 2002:a05:6870:fb8a:b0:1bf:51f2:94bd with SMTP id kv10-20020a056870fb8a00b001bf51f294bdmr312758oab.18.1694737571220; Thu, 14 Sep 2023 17:26:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694737571; cv=none; d=google.com; s=arc-20160816; b=qPx15wikSxSZAHkni/mUKVPVBO37EnjqAvVrb6lmi8Hr6TxgYNKSpKC+Ka1mtGgDH0 xKbb4AkiWUK5bvu1FZZAJQlrmyfOWodao+2PTtYNE3wsr+ISWqZKaOf8nfoKOFI+AUBT SB2DH5jNggKnL2MYRRI1qywUilEZqM3yQSQggkpUKRkDPb34A/1ciTqIXhhADha41d7y NiZmQlVBgZ5oN20CPOrGrBCP6KsTDIv4LyBRflp/wdUGewB+ZYHpMG59oAGzN1v095OJ d0wuKut2o6rldgTWKtPDsQio7PHsA0mbH3/dxFAqQoYESFbkZd19snqWTqYnQn31CEFR tQXQ== 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=/hVBmOc1UZslIEApH7wM7XsxUFX5t/MGHE6BhKB/8dE=; fh=773BV7jTB2E4Qbx5+4wSZDJgI4CuDY5VmeVh6+B1K5w=; b=sH3aG8a4MEZhwVqEh5XJSAs5i3iKMBlm/+Af67Ue8jMhPfJBlPAakWb5A+4hq/nSXq pBgFZN7lieuueNia5RpjAgJcsWKzOhvcAYUcPe14GpZwpJX771CpNlTzMQbmdN2P5nPN Jpnb1HzXZAZrA6uHOTCqElP1s32DdCIJwRsn4wWebdSI6nnng55D1D4/IxppakzHluVI gBW05vWZW1fBxjvpdQIJ4iU0WXNL1Mcfi1lUWLwPcmkF17oo4T+F6gzAP+lZ7QFn2jEf CgTH2zawUY5z+0sy2pwaWdJJEWzfFPOXMSkHkZMFL4Gi9Z3QiAYN063WywVhgJ0hPg80 zdTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=AIzFnxKF; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=niG5LYzV; 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 Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id bv189-20020a632ec6000000b00564929df8besi2196600pgb.568.2023.09.14.17.26.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 17:26:11 -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=AIzFnxKF; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=niG5LYzV; 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 B45A5829C31D; Thu, 14 Sep 2023 11:44:51 -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 S242026AbjINSo0 (ORCPT + 99 others); Thu, 14 Sep 2023 14:44:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241678AbjINSmZ (ORCPT ); Thu, 14 Sep 2023 14:42:25 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26BB530E9; Thu, 14 Sep 2023 11:39:10 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716749; 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=/hVBmOc1UZslIEApH7wM7XsxUFX5t/MGHE6BhKB/8dE=; b=AIzFnxKF/HftpM563b/45gzbyhppoKPbb3WOngQIYKnzlm7KcT5/Vybf6MzS/v4xTyrK12 JvVsV7QJKVZmGnUgn0nEsruFmzmI0iHzv7T2p4MUocmRSBeVYG0ELH8B4/txM0fw4T+ixV lkebqhdVNlhxQEUzcC9685DeWUMGTAQWYHU1B7EL33hSjhmbOCzOgPg5i3t7KZYO9xzrGu tF96nxkf7bokQ+mLuVNIw5VGKvd/PFRAs5YqLSiPIqp3L5gD3+RzL7IoTCUsow58bfI95o 5BXOs9LfStTFfZ5nqYktxvrhIK4e39BAV9k56VfuHOgNduxbcOg1LoRWWgPLwQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716749; 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=/hVBmOc1UZslIEApH7wM7XsxUFX5t/MGHE6BhKB/8dE=; b=niG5LYzVOKr5LrHsGiYGWQ9Up9n4rYw0JaYgiLqr+u7qKMNYRJ0vmgV8KfsJV9UMV9dgdQ 1ddFUyocepCE1YAQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Peter Korsgaard Subject: [PATCH tty v1 71/74] serial: uartlite: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:28 +0206 Message-Id: <20230914183831.587273-72-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 (agentk.vger.email [0.0.0.0]); Thu, 14 Sep 2023 11:44:51 -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 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/uartlite.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c index b225a78f6175..404c14acafa5 100644 --- a/drivers/tty/serial/uartlite.c +++ b/drivers/tty/serial/uartlite.c @@ -216,11 +216,11 @@ static irqreturn_t ulite_isr(int irq, void *dev_id) unsigned long flags; do { - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); stat = uart_in32(ULITE_STATUS, port); busy = ulite_receive(port, stat); busy |= ulite_transmit(port, stat); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); n++; } while (busy); @@ -238,9 +238,9 @@ static unsigned int ulite_tx_empty(struct uart_port *port) unsigned long flags; unsigned int ret; - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); ret = uart_in32(ULITE_STATUS, port); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); return ret & ULITE_STATUS_TXEMPTY ? TIOCSER_TEMT : 0; } @@ -323,7 +323,7 @@ static void ulite_set_termios(struct uart_port *port, termios->c_cflag |= pdata->cflags & (PARENB | PARODD | CSIZE); tty_termios_encode_baud_rate(termios, pdata->baud, pdata->baud); - spin_lock_irqsave(&port->lock, flags); + uart_port_lock_irqsave(port, &flags); port->read_status_mask = ULITE_STATUS_RXVALID | ULITE_STATUS_OVERRUN | ULITE_STATUS_TXFULL; @@ -346,7 +346,7 @@ static void ulite_set_termios(struct uart_port *port, /* update timeout */ uart_update_timeout(port, termios->c_cflag, pdata->baud); - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } static const char *ulite_type(struct uart_port *port) @@ -495,9 +495,9 @@ static void ulite_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); /* save and disable interrupt */ ier = uart_in32(ULITE_STATUS, port) & ULITE_STATUS_IE; @@ -512,7 +512,7 @@ static void ulite_console_write(struct console *co, const char *s, uart_out32(ULITE_CONTROL_IE, ULITE_CONTROL, port); if (locked) - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } static int ulite_console_setup(struct console *co, char *options) -- 2.39.2