From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91034CE7B0E for ; Thu, 28 Sep 2023 08:44:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231329AbjI1Iox (ORCPT ); Thu, 28 Sep 2023 04:44:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229605AbjI1Iou (ORCPT ); Thu, 28 Sep 2023 04:44:50 -0400 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0D5313A for ; Thu, 28 Sep 2023 01:44:48 -0700 (PDT) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qlmdS-0008UJ-69; Thu, 28 Sep 2023 10:44:38 +0200 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qlmdR-009XKe-5K; Thu, 28 Sep 2023 10:44:37 +0200 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1qlmdQ-005ah3-S5; Thu, 28 Sep 2023 10:44:36 +0200 Date: Thu, 28 Sep 2023 10:44:36 +0200 From: Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= To: Vinod Koul Cc: festevam@gmail.com, linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, s.hauer@pengutronix.de, linux-kernel@vger.kernel.org, Chengfeng Ye , sorganov@gmail.com, kernel@pengutronix.de, ilpo.jarvinen@linux.intel.com, dmaengine@vger.kernel.org, shawnguo@kernel.org, jirislaby@kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH RESEND] serial: imx: Fix potential deadlock on sport->port.lock Message-ID: <20230928084436.fftw5sk4sixaedck@pengutronix.de> References: <20230927181939.60554-1-dg573847474@gmail.com> <20230928060749.qzs6qgcesstclqqk@pengutronix.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="r6y5twzpb32i5htn" Content-Disposition: inline In-Reply-To: X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: dmaengine@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org --r6y5twzpb32i5htn Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello Vinod, thanks for your quick answer! On Thu, Sep 28, 2023 at 01:08:15PM +0530, Vinod Koul wrote: > On 28-09-23, 08:07, Uwe Kleine-K=F6nig wrote: > > [Cc +=3D Vinod Koul, dmaengine@vger.kernel.org] > >=20 > > Hello, > >=20 > > On Wed, Sep 27, 2023 at 06:19:39PM +0000, Chengfeng Ye wrote: > > > As &sport->port.lock is acquired under irq context along the following > > > call chain from imx_uart_rtsint(), other acquisition of the same lock > > > inside process context or softirq context should disable irq avoid do= uble > > > lock. > > >=20 > > > > > >=20 > > > imx_uart_dma_rx_callback() > > > --> spin_lock(&sport->port.lock) > > > > > > --> imx_uart_rtsint() > > > --> spin_lock(&sport->port.lock) > > >=20 > > > This flaw was found by an experimental static analysis tool I am > > > developing for irq-related deadlock. > >=20 > > Ah, I understood before that you really experienced that deadlock (or a > > lockdep splat). I didn't test anything, but I think the > > imx_uart_dma_rx_callback() is called indirectly by > > sdma_update_channel_loop() which is called in irq context. I don't know > > if this is the case for all dma drivers?! > >=20 > > @Vinod: Maybe you can chime in here: Is a dma callback always called in > > irq context? >=20 > Not in callback but a tasklet context. The DMA irq handler is supposed > to use a tasklet for invoking the callback So drivers/dma/imx-sdma.c is bogous as it calls -> sdma_int_handler() -> sdma_update_channel_loop() -> dmaengine_desc_get_callback_invoke() resulting in imx_uart_dma_rx_callback() (and others) being called in irq context, right? In that case: Acked-by: Uwe Kleine-K=F6nig (for the imx-UART patch that stops assuming imx_uart_dma_rx_callback() is called with irqs off). Best regards Uwe --=20 Pengutronix e.K. | Uwe Kleine-K=F6nig | Industrial Linux Solutions | https://www.pengutronix.de/ | --r6y5twzpb32i5htn Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEP4GsaTp6HlmJrf7Tj4D7WH0S/k4FAmUVPPIACgkQj4D7WH0S /k7vNwgAhb4pKXKJbH9aBhcqanU4xb1tK0/f8VK6sZW0aeeWi7M4Ix1HQFdLg9va AS2/DwTdV7PHtMX5NJhPkqyUupi2SIJ7fXQo5pkN4p0sHBCzNIYrgpCtvXi/azSC qKXuOOTw8A9HvoeTKNbKQm6n2Va/AaPORzE/uzZq/m7ni4JHuCSqZMEIzRtJ05/O m6c2cs6FDkGfPE3B8WRWK4ClF5hFZ7mhdQr118Y8tb/cAQ6eG8BzGNMQJt555Rrn plV5TSK5mnbmW/B2psEEVmQcBrwZz+vfbsoAvd45B8Lnstey+e9DX+Fmvs8I3Pse rJmz4QDc2grxnjlCvVSBHtj4jEBOKQ== =p5nE -----END PGP SIGNATURE----- --r6y5twzpb32i5htn-- From mboxrd@z Thu Jan 1 00:00:00 1970 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 77459CE7B0E for ; Thu, 28 Sep 2023 08:45:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=UxBT/rttO1Uc0rhgnHK3a9v8t1bg46LO4c/grHDZ7Y4=; b=tttnMJYYWCFRtfKlQMwuJ5t7R0 w6ui9MiwmrgCWcnaNqB//DY6rInyWkdbqIydNXj0YXVjk75aJIuZoKlDYh6h/4zMWM3wi6E3xGPL5 /CRg3DeKhPtau58l3jcRCTxowWDthc0trei649nvNRBR9BLZEd1Fa6TQ8795RH0GGfYLnWEw1zJmz s1OT3Ke2wWkEXd3vJhcbaN5/PgOEQhHJ2DI5siSYfDWXJWVaqQtT/vdF2x3+PzYQdVzOdZyXz1sm6 FJtwPVwdvUTrwoDYFiUJwu8B1yQb1xEJNTN+GdGwqw55Xwh0URVh1t8QxY49j6PPhSdCj9RXEEyWB suzQyVVg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qlmdo-002eCW-1h; Thu, 28 Sep 2023 08:45:00 +0000 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qlmdl-002eBh-35 for linux-arm-kernel@lists.infradead.org; Thu, 28 Sep 2023 08:44:59 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qlmdS-0008UJ-69; Thu, 28 Sep 2023 10:44:38 +0200 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qlmdR-009XKe-5K; Thu, 28 Sep 2023 10:44:37 +0200 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1qlmdQ-005ah3-S5; Thu, 28 Sep 2023 10:44:36 +0200 Date: Thu, 28 Sep 2023 10:44:36 +0200 From: Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= To: Vinod Koul Cc: festevam@gmail.com, linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, s.hauer@pengutronix.de, linux-kernel@vger.kernel.org, Chengfeng Ye , sorganov@gmail.com, kernel@pengutronix.de, ilpo.jarvinen@linux.intel.com, dmaengine@vger.kernel.org, shawnguo@kernel.org, jirislaby@kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH RESEND] serial: imx: Fix potential deadlock on sport->port.lock Message-ID: <20230928084436.fftw5sk4sixaedck@pengutronix.de> References: <20230927181939.60554-1-dg573847474@gmail.com> <20230928060749.qzs6qgcesstclqqk@pengutronix.de> MIME-Version: 1.0 In-Reply-To: X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230928_014458_003228_4BF2AEB8 X-CRM114-Status: GOOD ( 23.26 ) 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: , Content-Type: multipart/mixed; boundary="===============7973115481712854806==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============7973115481712854806== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="r6y5twzpb32i5htn" Content-Disposition: inline --r6y5twzpb32i5htn Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello Vinod, thanks for your quick answer! On Thu, Sep 28, 2023 at 01:08:15PM +0530, Vinod Koul wrote: > On 28-09-23, 08:07, Uwe Kleine-K=F6nig wrote: > > [Cc +=3D Vinod Koul, dmaengine@vger.kernel.org] > >=20 > > Hello, > >=20 > > On Wed, Sep 27, 2023 at 06:19:39PM +0000, Chengfeng Ye wrote: > > > As &sport->port.lock is acquired under irq context along the following > > > call chain from imx_uart_rtsint(), other acquisition of the same lock > > > inside process context or softirq context should disable irq avoid do= uble > > > lock. > > >=20 > > > > > >=20 > > > imx_uart_dma_rx_callback() > > > --> spin_lock(&sport->port.lock) > > > > > > --> imx_uart_rtsint() > > > --> spin_lock(&sport->port.lock) > > >=20 > > > This flaw was found by an experimental static analysis tool I am > > > developing for irq-related deadlock. > >=20 > > Ah, I understood before that you really experienced that deadlock (or a > > lockdep splat). I didn't test anything, but I think the > > imx_uart_dma_rx_callback() is called indirectly by > > sdma_update_channel_loop() which is called in irq context. I don't know > > if this is the case for all dma drivers?! > >=20 > > @Vinod: Maybe you can chime in here: Is a dma callback always called in > > irq context? >=20 > Not in callback but a tasklet context. The DMA irq handler is supposed > to use a tasklet for invoking the callback So drivers/dma/imx-sdma.c is bogous as it calls -> sdma_int_handler() -> sdma_update_channel_loop() -> dmaengine_desc_get_callback_invoke() resulting in imx_uart_dma_rx_callback() (and others) being called in irq context, right? In that case: Acked-by: Uwe Kleine-K=F6nig (for the imx-UART patch that stops assuming imx_uart_dma_rx_callback() is called with irqs off). Best regards Uwe --=20 Pengutronix e.K. | Uwe Kleine-K=F6nig | Industrial Linux Solutions | https://www.pengutronix.de/ | --r6y5twzpb32i5htn Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEP4GsaTp6HlmJrf7Tj4D7WH0S/k4FAmUVPPIACgkQj4D7WH0S /k7vNwgAhb4pKXKJbH9aBhcqanU4xb1tK0/f8VK6sZW0aeeWi7M4Ix1HQFdLg9va AS2/DwTdV7PHtMX5NJhPkqyUupi2SIJ7fXQo5pkN4p0sHBCzNIYrgpCtvXi/azSC qKXuOOTw8A9HvoeTKNbKQm6n2Va/AaPORzE/uzZq/m7ni4JHuCSqZMEIzRtJ05/O m6c2cs6FDkGfPE3B8WRWK4ClF5hFZ7mhdQr118Y8tb/cAQ6eG8BzGNMQJt555Rrn plV5TSK5mnbmW/B2psEEVmQcBrwZz+vfbsoAvd45B8Lnstey+e9DX+Fmvs8I3Pse rJmz4QDc2grxnjlCvVSBHtj4jEBOKQ== =p5nE -----END PGP SIGNATURE----- --r6y5twzpb32i5htn-- --===============7973115481712854806== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============7973115481712854806==--