From patchwork Thu Sep 14 18:38:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 139815 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp596365vqi; Thu, 14 Sep 2023 13:06:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFfxR8XplZo046ySFH0c1VHJFlsyyscs3ynjpEOjtCG1/ZesOBa4gXdJvdYI3gVGSqMT9lZ X-Received: by 2002:a17:902:e5cd:b0:1c4:5a9:a45e with SMTP id u13-20020a170902e5cd00b001c405a9a45emr3541169plf.27.1694721998916; Thu, 14 Sep 2023 13:06:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694721998; cv=none; d=google.com; s=arc-20160816; b=YWFLzxk0irPcrGQ5ogDJY+7yx39ZuAaC6M/wR6uG/Nw2yOQRGeVGOoN2OKKz1BUwMQ X+udUq2fhwVndm9968zeZowomZ4ptE6q8bVNiaz94C3+ZJN7jKQnUVNpOcrjDkUn6mET dq30wQGXPlhFSWWzHsw+loEwJj2x/dklHSx3GC24ogJXz0Wvia1yp80+k4iIXMTb9jSA ExjgWVQC1T9f/9T3cuoByKf0+N2VT9+iJJvkrIu97ZuMfYpr7KhO+aX/PHkehjUlJDWL 0wP6CUM+Vd5azVHgPu9JKrwj40Yzj3zvj5vD6Pk3iUDjlOltzhewAyAPp+iAK18shUHs w+Xg== 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=fQN7epFxbwh1qF9A3vKlWoOOC6pmuH30heIRIdUdCsw=; fh=9L1ViD0S56AkSRNSwes62XgoaIAK5K8Qs7XnpA5ZCD4=; b=c9sNf21wufz7tgci+w9KWe6+JiBLZQ1tEOYKFwm7EFBA2hct1NpLCLZxNxF/UTrvKA fEfs9oGsvnICIFyeyC00Wz4onOHtj/griP5By6H3MdwZlgQLgUv2BFQ+uCiO/l+MsMsY GzIqtZ2NxaDLg86Hg1ds8yhiJ8A7TIlqzG9CCwz3i92mCL/ufcFEBRibyqLdyM1dMOal Ca7cTYOBC6wwP2sob3SYLH49zufeAuZn5FS1gxuMsyVRCMX+APX7HB4HT2QSp4J7RHOU 4sQIFv4XDNTfKgDHJpjEPCvCw5hcX2S9NjshGu5EDOgVIgoZKmtrWZCQ2b4pB5KtQ3Je YxEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=hmi62IBJ; dkim=neutral (no key) header.i=@linutronix.de; 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id e19-20020a170902e0d300b001bb96de922dsi2083965pla.140.2023.09.14.13.06.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:06:38 -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=hmi62IBJ; dkim=neutral (no key) header.i=@linutronix.de; 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 3D2198291532; Thu, 14 Sep 2023 11:43:29 -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 S241997AbjINSlq (ORCPT + 33 others); Thu, 14 Sep 2023 14:41:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241980AbjINSjo (ORCPT ); Thu, 14 Sep 2023 14:39:44 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD9A8270D; Thu, 14 Sep 2023 11:39:02 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694716741; 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=fQN7epFxbwh1qF9A3vKlWoOOC6pmuH30heIRIdUdCsw=; b=hmi62IBJprhrBskt+oHKNc4Krp4W/jSVkKbugl+EiEnzpg4bnHZL6tDuwSP35MvhOJqTBF Y2qIjTqZkiorNeiPqCopzo2FMj8YkX/23kq1/zgSju9fnqtV2cfdcWGQA/AtPwUxPW57Ab 4oVbbBmc8Z24NcuPQGwoujNWqBXYpC71pnzj679o/3ud01fI/bc+znMfqELboL6XUIYdP0 Px0Vb2U0dxClP0Y/t+BHowHcGm9a/kyfT4WJpf3gLYLaQD0U6oHrOsYQxdw2n//tEF5MEd 8Fi0Fy7EDg74h00xumLAfvfn2pLsMclcPViRc62XZEe6QTpNztkni3Jvpud+5A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694716741; 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=fQN7epFxbwh1qF9A3vKlWoOOC6pmuH30heIRIdUdCsw=; b=kfyQuSVNlXEbogFR65EguwGNHtAhOMowXzjYr76Qoe01RXQd/iZhZ694cqLNmiITysx3Ms BDxZXp3l3vPr59BQ== To: Greg Kroah-Hartman Cc: Jiri Slaby , linux-serial@vger.kernel.org, Petr Mladek , Thomas Gleixner , linux-kernel@vger.kernel.org, Richard GENOUD , Thierry Reding , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Lukas Bulwahn Subject: [PATCH tty v1 54/74] serial: sb1250-duart: Use port lock wrappers Date: Thu, 14 Sep 2023 20:44:11 +0206 Message-Id: <20230914183831.587273-55-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 (lipwig.vger.email [0.0.0.0]); Thu, 14 Sep 2023 11:43:29 -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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777044814917801531 X-GMAIL-MSGID: 1777044814917801531 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/sb1250-duart.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/tty/serial/sb1250-duart.c b/drivers/tty/serial/sb1250-duart.c index f3cd69346482..dbec29d9a6c3 100644 --- a/drivers/tty/serial/sb1250-duart.c +++ b/drivers/tty/serial/sb1250-duart.c @@ -610,7 +610,7 @@ static void sbd_set_termios(struct uart_port *uport, struct ktermios *termios, else aux &= ~M_DUART_CTS_CHNG_ENA; - spin_lock(&uport->lock); + uart_port_lock(uport); if (sport->tx_stopped) command |= M_DUART_TX_DIS; @@ -632,7 +632,7 @@ static void sbd_set_termios(struct uart_port *uport, struct ktermios *termios, write_sbdchn(sport, R_DUART_CMD, command); - spin_unlock(&uport->lock); + uart_port_unlock(uport); } @@ -839,22 +839,22 @@ static void sbd_console_write(struct console *co, const char *s, unsigned int mask; /* Disable transmit interrupts and enable the transmitter. */ - spin_lock_irqsave(&uport->lock, flags); + uart_port_lock_irqsave(uport, &flags); mask = read_sbdshr(sport, R_DUART_IMRREG((uport->line) % 2)); write_sbdshr(sport, R_DUART_IMRREG((uport->line) % 2), mask & ~M_DUART_IMR_TX); write_sbdchn(sport, R_DUART_CMD, M_DUART_TX_EN); - spin_unlock_irqrestore(&uport->lock, flags); + uart_port_unlock_irqrestore(uport, flags); uart_console_write(&sport->port, s, count, sbd_console_putchar); /* Restore transmit interrupts and the transmitter enable. */ - spin_lock_irqsave(&uport->lock, flags); + uart_port_lock_irqsave(uport, &flags); sbd_line_drain(sport); if (sport->tx_stopped) write_sbdchn(sport, R_DUART_CMD, M_DUART_TX_DIS); write_sbdshr(sport, R_DUART_IMRREG((uport->line) % 2), mask); - spin_unlock_irqrestore(&uport->lock, flags); + uart_port_unlock_irqrestore(uport, flags); } static int __init sbd_console_setup(struct console *co, char *options)