Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4202981rdb; Thu, 14 Sep 2023 15:22:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFzWykdMNAHx4cPPLuwcWz6Dx9wjz029ovfku+w6TjaspA89n/AWRsP8rK9XNi6dO1gJ45L X-Received: by 2002:a05:6a20:8e12:b0:133:f0b9:856d with SMTP id y18-20020a056a208e1200b00133f0b9856dmr137530pzj.17.1694730168464; Thu, 14 Sep 2023 15:22:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694730168; cv=none; d=google.com; s=arc-20160816; b=h3xW+PH27dwlSWksuyEBqDDLQG/7Fpw1S0OHKoFng4wahwgewMELFm4YQA1GuzEy8Y BmHL5pMjmr3I9unw2takdkD8dSPGrOffyMmwTZQrN5jzk6e6HWKvpdwBFUvMi4yO0hvT 1xnhiovJhDdGkMwW1ygzItVgmDxxBRqKW7WeP4kUbxBFxUoavcWb4HR93MFw+QWYQGHM fOFwE9uHreeIpsyjzSYJFLoujpzTz7gqeHGaUvohDTfETABS5GcRVoXpPYiDGBfFohsF Ui77paLI6JHT4Hc8KnhBkvLevJW5ZKxHjkTID/NSyObfTen+wqvRAS8CnbvLd1FWIjVP LZRQ== 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=FNItZDOSVbjUj/GhN7qtDvHsswbZnbm/OUZHY8Hfuqo=; fh=l3Vu5ib2ggleA7iWQx5Mxds70t8jePhua+wZ79Dyc8E=; b=hF7BO1NPQ/0lrAhBjm81XDiXWJE7SuDDXi23IHRMwuaWQYFJN1ygpgTnSasyMzUzGT yk6oFhYQRFLTdrQ1MnwAtkwyT3C8PNoLKE+dg3Q3D0XoGWJA+2RhmxNe+p9lM0+mLRkA ivybsBU0/mQpzR6xBWR3jEY8FlpouwfE5CDEyIYeFTXB6a8zDZ/FKEpFgpEh6B1R92z0 EuwbFuXrmC97WpkLBVyCGqP3PF2zIz/tBGeZ6B6prZYgWH65M4G6Y9ELyMOSJS+siDfU HUwIETvXXdfqclrjs5TVVc9XTP2f9gSyGhWGxr+0rnJtHmD7XaOxyBOqzSN3Lba/WnCK GIIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=wknKwa1k; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=HCL13mxd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id g7-20020a056a0023c700b006902507d409si2409276pfc.174.2023.09.14.15.22.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 15:22:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=wknKwa1k; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=HCL13mxd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 91D39828E085; Thu, 14 Sep 2023 11:42:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242179AbjINSmV (ORCPT + 99 others); Thu, 14 Sep 2023 14:42:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241761AbjINSkS (ORCPT ); Thu, 14 Sep 2023 14:40:18 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AAD3272D; Thu, 14 Sep 2023 11:39:06 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716745; 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=FNItZDOSVbjUj/GhN7qtDvHsswbZnbm/OUZHY8Hfuqo=; b=wknKwa1kLvdaAYCvkZu9Z81f2T8Ta+CKva4N8RP76TA/NcMmJlm+Kil2JepCpHxBw1BEJU K5pPqaYbTwLXrS3/UGwnuSoqeuuWpaEqqES2YbBrkQQJBM2jxPSbaryW3lTtByRM/tMtwh gLrH5uhCtN8myDHRj74sRARHv9IwiNLbYc/k8O+0uLooKYlN4mT5AxH563k4Ct6BKNLKBa 6sfWSVIRNQrC7RUyNp3GxrdgJpqbYtOp6pNuQ7JQPlbSa8eoVNCfaBWQPqRdeKSwo43PTo 78iMfhiAozSI/V0aIgMpjYRus2ommjIBSLG4FVydEquKML+4oWBSdSlxxdKnPA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716745; 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=FNItZDOSVbjUj/GhN7qtDvHsswbZnbm/OUZHY8Hfuqo=; b=HCL13mxdtEEBqe3txMOM+VDtV2848oD66CWe/CXn/8/B7TEVd4hlSi4SRJ+K0c3B4MuVs7 ZsMM+w8fmLRiVrBg== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Palmer Dabbelt , Paul Walmsley , Richard GENOUD , Nick Hu , Ruan Jinjie , Samuel Holland , Yangtao Li , linux-riscv@lists.infradead.org Subject: [PATCH tty v1 61/74] serial: sifive: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:18 +0206 Message-Id: <20230914183831.587273-62-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 (lipwig.vger.email [0.0.0.0]); Thu, 14 Sep 2023 11:42:53 -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 lipwig.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/sifive.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/tty/serial/sifive.c b/drivers/tty/serial/sifive.c index d195c5de52e7..b296e57a9dee 100644 --- a/drivers/tty/serial/sifive.c +++ b/drivers/tty/serial/sifive.c @@ -521,11 +521,11 @@ static irqreturn_t sifive_serial_irq(int irq, void *dev_id) struct sifive_serial_port *ssp = dev_id; u32 ip; - spin_lock(&ssp->port.lock); + uart_port_lock(&ssp->port); ip = __ssp_readl(ssp, SIFIVE_SERIAL_IP_OFFS); if (!ip) { - spin_unlock(&ssp->port.lock); + uart_port_unlock(&ssp->port); return IRQ_NONE; } @@ -534,7 +534,7 @@ static irqreturn_t sifive_serial_irq(int irq, void *dev_id) if (ip & SIFIVE_SERIAL_IP_TXWM_MASK) __ssp_transmit_chars(ssp); - spin_unlock(&ssp->port.lock); + uart_port_unlock(&ssp->port); return IRQ_HANDLED; } @@ -653,7 +653,7 @@ static void sifive_serial_set_termios(struct uart_port *port, ssp->port.uartclk / 16); __ssp_update_baud_rate(ssp, rate); - spin_lock_irqsave(&ssp->port.lock, flags); + uart_port_lock_irqsave(&ssp->port, &flags); /* Update the per-port timeout */ uart_update_timeout(port, termios->c_cflag, rate); @@ -670,7 +670,7 @@ static void sifive_serial_set_termios(struct uart_port *port, if (v != old_v) __ssp_writel(v, SIFIVE_SERIAL_RXCTRL_OFFS, ssp); - spin_unlock_irqrestore(&ssp->port.lock, flags); + uart_port_unlock_irqrestore(&ssp->port, flags); } static void sifive_serial_release_port(struct uart_port *port) @@ -795,9 +795,9 @@ static void sifive_serial_console_write(struct console *co, const char *s, if (ssp->port.sysrq) locked = 0; else if (oops_in_progress) - locked = spin_trylock(&ssp->port.lock); + locked = uart_port_trylock(&ssp->port); else - spin_lock(&ssp->port.lock); + uart_port_lock(&ssp->port); ier = __ssp_readl(ssp, SIFIVE_SERIAL_IE_OFFS); __ssp_writel(0, SIFIVE_SERIAL_IE_OFFS, ssp); @@ -807,7 +807,7 @@ static void sifive_serial_console_write(struct console *co, const char *s, __ssp_writel(ier, SIFIVE_SERIAL_IE_OFFS, ssp); if (locked) - spin_unlock(&ssp->port.lock); + uart_port_unlock(&ssp->port); local_irq_restore(flags); } -- 2.39.2