From patchwork Fri Sep 13 08:39:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Esben Haabendal X-Patchwork-Id: 13803138 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CF667FA3730 for ; Fri, 13 Sep 2024 08:42:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=WnHN7qMcG8tuD13zIADdEsVNMqZ34MUXlFCfvG8EYAs=; b=G54tb5ox54shTCOllJ8fAhr6CH E2uCfBZ3ginx3QYl8P4PO8FPZDKM5EP2rSdqzH9SNtFmLd5etRllkPI3K0ew82LHlpIBinfAG/Wi0 Kf6oxkNfJuMX7TqLMa3mpb1N5Sco/zvx3SQHPZV4++tdUqLXpbXkFk0GkkW0cJVDDBKmc7RQ0PdjF lW9z2cm0bDOB0LKaMETmBwyIH5IAk4zWUqUuJZ0FGgCjqKQflsp1cmYE/Ss5dFZ7HK98ntEWEyT4U Olkh1PHOnMK2Igfdb5wr6+6+mjhDpfW9ETQjWjl8wovVklkq7ukFbMf2fMmi4BZRinVeoBrCFj420 yGfFVBhw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sp1sd-0000000FNk2-1vh5; Fri, 13 Sep 2024 08:42:15 +0000 Received: from www530.your-server.de ([188.40.30.78]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sp1qN-0000000FNFu-1PXR for linux-arm-kernel@lists.infradead.org; Fri, 13 Sep 2024 08:40:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=geanix.com; s=default2211; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=WnHN7qMcG8tuD13zIADdEsVNMqZ34MUXlFCfvG8EYAs=; b=v6m0tedBbDqYDJdypQtCEzP5Tk NX869ilVDTik14Yg4COsDcbUTRsjv7j6Z7cahYnn+cqAIGqsCKJbUoJsjE7tnhhrP9IxS+VRazKky MnfraUBGmmqA8d2qiCB8OD24VrHACB5wbm08zaIxG16BDB+1s3cWN4qah2FUvCuM63Gbd7HcB+A99 K8+t6BVYspFipZl2hTsNmzyZM9LcGCjhD87zD5nhaOsuxBj9EkRl+67+ZOeoZ9pTcsZ4HJ1QekMmg AaWcviBkF8ZVoXqbqssFL2297ef8bU1RlK8CuE9W4MAhco33ikeNY2QZIyLk/20VXxAH/UFJJ6hB0 lyZFD1lQ==; Received: from sslproxy07.your-server.de ([78.47.199.104]) by www530.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sp1qL-000Dwj-Qa; Fri, 13 Sep 2024 10:39:53 +0200 Received: from [80.62.117.18] (helo=localhost) by sslproxy07.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sp1qK-0003Hn-2N; Fri, 13 Sep 2024 10:39:53 +0200 From: Esben Haabendal Date: Fri, 13 Sep 2024 10:39:49 +0200 Subject: [PATCH 1/2] serial: imx: Grab port lock in imx_uart_enable_wakeup() MIME-Version: 1.0 Message-Id: <20240913-serial-imx-lockfix-v1-1-4d102746c89d@geanix.com> References: <20240913-serial-imx-lockfix-v1-0-4d102746c89d@geanix.com> In-Reply-To: <20240913-serial-imx-lockfix-v1-0-4d102746c89d@geanix.com> To: Greg Kroah-Hartman , Jiri Slaby , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , John Ogness Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Esben Haabendal X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1726216791; l=1035; i=esben@geanix.com; s=20240523; h=from:subject:message-id; bh=st/YOUKHt7mTrSOi39Ic1qZPpt4tegKJFkaBdwH/HZY=; b=GFqRZZb5hDDFmJ6nfbHrxykfNuBZyqojtW8NnRHxTQ3JBPTqSRp/dkC2uZ/4pLH2hHycvCcL1 WSg8ALqwgcsBqQh4lfS7vA87Vvx309o1iWQM+w7fVzegMcDybDvrqxA X-Developer-Key: i=esben@geanix.com; a=ed25519; pk=PbXoezm+CERhtgVeF/QAgXtEzSkDIahcWfC7RIXNdEk= X-Authenticated-Sender: esben@geanix.com X-Virus-Scanned: Clear (ClamAV 0.103.10/27396/Thu Sep 12 10:46:40 2024) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240913_013955_411582_7EDC1761 X-CRM114-Status: UNSURE ( 9.33 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The port lock needs to be held when doing read-modify-write on UCR1 and UCR3. Signed-off-by: Esben Haabendal --- drivers/tty/serial/imx.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 67d4a72eda77..efa3eb3a2c57 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -2580,10 +2580,13 @@ static void imx_uart_save_context(struct imx_port *sport) uart_port_unlock_irqrestore(&sport->port, flags); } +/* called with irq off */ static void imx_uart_enable_wakeup(struct imx_port *sport, bool on) { u32 ucr3; + uart_port_lock(&sport->port); + ucr3 = imx_uart_readl(sport, UCR3); if (on) { imx_uart_writel(sport, USR1_AWAKE, USR1); @@ -2603,6 +2606,8 @@ static void imx_uart_enable_wakeup(struct imx_port *sport, bool on) } imx_uart_writel(sport, ucr1, UCR1); } + + uart_port_unlock(&sport->port); } static int imx_uart_suspend_noirq(struct device *dev) From patchwork Fri Sep 13 08:39:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Esben Haabendal X-Patchwork-Id: 13803137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3D90BFA372B for ; Fri, 13 Sep 2024 08:41:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Cn4kUwYeuytQMsE365PcfJ/lfyo4K65OPmJ3B2UpHak=; b=eUYmAWNHRcMLgHbAqJLk9t7xgA czOdxIhrXrPGulK36F8gAGlSm3tnuqScSIazmGB5vNiP7AF5iI/cPuGrs3kvSzh2RhJ8AoDW5hn6M wrSCNjl1kTM2qxa2DUWHklkhRtY+Mu6kOFQ2JWkI/iSjyQgxManWuzBfGxPeNypF67sr3sVXyRhBc fWIR+M+F3bgmJ1NJRrqWaajJOzwP3kYUJLkzv6wmd/QjaUw+xjw9e4cw87QqiQorgfoz6tiOjxH2s YgHCaXrnnH4eXBsUpKe4PWRLHMlxI56C5rdOL2pQe/g6tUHBsMFEkk5YTEAvkHESDrjlcLBvnfJkr lcxhqnxw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sp1rc-0000000FNU8-0eAC; Fri, 13 Sep 2024 08:41:12 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sp1qX-0000000FNId-3bgS for linux-arm-kernel@bombadil.infradead.org; Fri, 13 Sep 2024 08:40:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=Cn4kUwYeuytQMsE365PcfJ/lfyo4K65OPmJ3B2UpHak=; b=bBTlop06DJXY8VrPTMxZ3bWJUB dHatqD6ECJPTg8glNTWhRRR5F8dcxrOQgZ9A8lYBw7kvHMrRsSn7rINIqStC2YcxOkPWIqAPrQ2OD SbzVMS+Cdr4B8xs4uxcg64XhERJx2AA6zNo01qEFyYiEyavz1ARUKd2OkpfPUx1iumK8N+3CGVeum mLg5CK26/N/W+d2QYbFwBvTI0w+OwtZ2BW8dijXJSkWrxy8azmp032P8Vpr5BTsN5anEeU5NtiKEL 0ZDOP+urwsZGesrxV7WfPPRD+qEDbw4EKK6V8x6QKnu6DkJX4JIH6/0511TR2eephjRAvfqeAhucR y8FXenSg==; Received: from www530.your-server.de ([188.40.30.78]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sp1qU-00000000cgX-2z2O for linux-arm-kernel@lists.infradead.org; Fri, 13 Sep 2024 08:40:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=geanix.com; s=default2211; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=Cn4kUwYeuytQMsE365PcfJ/lfyo4K65OPmJ3B2UpHak=; b=FhBEH4dVFNOQBRMRZHZb4eqiIj LCLbWGFcapAevOvXliPBCb+AU2jQj7+2K9WHXJ5DAA01l7YWuvH8i8SnQl3YgX2JVePStIdRvKixO fZ2BwjSg42mEx3qsG1p3XLBf+vH+wGrssYzPpWlAhZ5Fz5J2bJjCSytYTYkBUauCgW9on87ukkkne eiMHRAULPYfvGHLkSdzY+aLlthac8OjrfEPSfBRVowstAWfdC+beauPbYv2C09+uB3dVWZRloHl3H niLiQIIlaJFwfZAnCWPDrIcOAmQ8CcbijjzU45OwF5zNCceifYnpNgECBlqn6eL40G8AJuq/6jQrD 2u5z5TSA==; Received: from sslproxy07.your-server.de ([78.47.199.104]) by www530.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sp1qM-000Dwt-ED; Fri, 13 Sep 2024 10:39:54 +0200 Received: from [80.62.117.18] (helo=localhost) by sslproxy07.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sp1qL-0003OG-14; Fri, 13 Sep 2024 10:39:53 +0200 From: Esben Haabendal Date: Fri, 13 Sep 2024 10:39:50 +0200 Subject: [PATCH 2/2] serial: imx: Add more comments on port lock status MIME-Version: 1.0 Message-Id: <20240913-serial-imx-lockfix-v1-2-4d102746c89d@geanix.com> References: <20240913-serial-imx-lockfix-v1-0-4d102746c89d@geanix.com> In-Reply-To: <20240913-serial-imx-lockfix-v1-0-4d102746c89d@geanix.com> To: Greg Kroah-Hartman , Jiri Slaby , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , John Ogness Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Esben Haabendal X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1726216791; l=2785; i=esben@geanix.com; s=20240523; h=from:subject:message-id; bh=a8ByUJ/uOEUjYWDnE/dtInA626JBUnf9q+ifF8JKvZE=; b=AMZZDzPDMOyiJ4EEnRXHPd4iG2IDMAY8tt+eJX/ZtFaPyLYNpgZWBCltOds8cFxRIf07u6wm5 QSYxm2nthw7BKVpn2JUzUKnjm2szURFzUudeE3uSAnPiQMB16eDMI4f X-Developer-Key: i=esben@geanix.com; a=ed25519; pk=PbXoezm+CERhtgVeF/QAgXtEzSkDIahcWfC7RIXNdEk= X-Authenticated-Sender: esben@geanix.com X-Virus-Scanned: Clear (ClamAV 0.103.10/27396/Thu Sep 12 10:46:40 2024) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240913_094003_040376_5F16CB62 X-CRM114-Status: GOOD ( 12.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Comments regarding status of port.lock on internal functions is useful when reviewing correct handling of registers that must be protected by this lock. Signed-off-by: Esben Haabendal --- drivers/tty/serial/imx.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index efa3eb3a2c57..bea4510743ef 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -370,6 +370,7 @@ static void imx_uart_soft_reset(struct imx_port *sport) sport->idle_counter = 0; } +/* called with port.lock taken and irqs off */ static void imx_uart_disable_loopback_rs485(struct imx_port *sport) { unsigned int uts; @@ -470,6 +471,7 @@ static void imx_uart_stop_tx(struct uart_port *port) } } +/* called with port.lock taken and irqs off */ static void imx_uart_stop_rx_with_loopback_ctrl(struct uart_port *port, bool loopback) { struct imx_port *sport = to_imx_port(port); @@ -803,6 +805,8 @@ static irqreturn_t imx_uart_txint(int irq, void *dev_id) * issuing soft reset to the UART (just stop/start of RX does not help). Note * that what we do here is sending isolated start bit about 2.4 times shorter * than it is to be on UART configured baud rate. + * + * Called with port.lock taken and irqs off. */ static void imx_uart_check_flood(struct imx_port *sport, u32 usr2) { @@ -838,6 +842,7 @@ static void imx_uart_check_flood(struct imx_port *sport, u32 usr2) } } +/* called with port.lock taken and irqs off */ static irqreturn_t __imx_uart_rxint(int irq, void *dev_id) { struct imx_port *sport = dev_id; @@ -916,6 +921,7 @@ static void imx_uart_clear_rx_errors(struct imx_port *sport); /* * We have a modem side uart, so the meanings of RTS and CTS are inverted. */ +/* called with port.lock taken and irqs off */ static unsigned int imx_uart_get_hwmctrl(struct imx_port *sport) { unsigned int tmp = TIOCM_DSR; @@ -938,6 +944,8 @@ static unsigned int imx_uart_get_hwmctrl(struct imx_port *sport) /* * Handle any change of modem status signal since we were last called. + * + * Called with port.lock taken and irqs off. */ static void imx_uart_mctrl_check(struct imx_port *sport) { @@ -1277,6 +1285,7 @@ static int imx_uart_start_rx_dma(struct imx_port *sport) return 0; } +/* called with port.lock taken and irqs off */ static void imx_uart_clear_rx_errors(struct imx_port *sport) { struct tty_port *port = &sport->port.state->port; @@ -1407,6 +1416,7 @@ static int imx_uart_dma_init(struct imx_port *sport) return ret; } +/* called with port.lock taken and irqs off */ static void imx_uart_enable_dma(struct imx_port *sport) { u32 ucr1;