From nobody Thu Apr 2 21:32:22 2026 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 CC565C6FA8E for ; Tue, 20 Sep 2022 14:04:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230337AbiITOEM (ORCPT ); Tue, 20 Sep 2022 10:04:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229655AbiITOEJ (ORCPT ); Tue, 20 Sep 2022 10:04:09 -0400 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60068.outbound.protection.outlook.com [40.107.6.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B03733A19; Tue, 20 Sep 2022 07:04:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b1s5EJumQTfH8u5+nQQdkhY2rGFBYYBG6ISx51O48nBSDXe+KsLJ+Ap5xpFBwZl9XpfCBlYX5WluAbzIl95QA3v6/JkKXsyB7LA2eYMkajIsOngc8pC72kkVw9s9DUB8QC+CQ+x3o22pS4RJpH/pmErSSem3inCwYncd1G9X6mxAb62ASXfsJosTVAs4KgUbpQ+ZwMk1hQ2ZYJ+DoVJQCaushhi0SmZosapFmLupaewYR9mkcpKsQ9DIMdI4qc47s7ZakQMoaF3SH+CBoMMN/wkYmKjefoNt+wccJ0FllaFneLZZ6IjBRJz6LM6C45n+yONYv0SQn0TkmBZ59tCb0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=khKyq+lMYw7Kf6HIAh+dkqrBhhZgYRstCCQ/oFZWHTA=; b=XoXpPL7NkD//dZe1VDNckMS30AQRpY0MXrKOgIaSPvDcxHnjPGaJvg286/B5KQvS4Y7mqTqGj7ZMykKUwALBTqkd8SsUx2K6OE7+kRQLqNe8QafU9yxQTM+yLHZfSAuW6FuhzPbBpM91OhYGUCKJhrCWoPB7FJO36XUH10sdLfbo8VOT0naUaHRpE0AqRV6sR/XvxEUqXY4+9DCeHGK1coc4PGPrVuQgtlTZSPgcLiXFwpgx99ZjeG5C+PZHJ0+1zIraImr2Juv/GC7iheOO563wq3EoViOzgiHP+msd3QegbkAWJpSZTZSW5DPSz/TRKxrwcsDMurOZEyM2xjQGuw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=khKyq+lMYw7Kf6HIAh+dkqrBhhZgYRstCCQ/oFZWHTA=; b=HLVrUB2gOuAOtA7GSgofALKTYfbehiUz46+Wo949XUV0AfYL4v/jmAG6bVEiEYN0pLotpkab6SLa8UlYtnOFrLRf5Gksu9warecyZN+epl8mPvubjzfg8ZagaElcLmkCsFOrIXszrthX3XUUVjumKOaS/NuaTANYYnkYLiq0QsY= Received: from AS8PR04MB8404.eurprd04.prod.outlook.com (2603:10a6:20b:3f8::7) by DB9PR04MB8187.eurprd04.prod.outlook.com (2603:10a6:10:24a::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.14; Tue, 20 Sep 2022 14:04:05 +0000 Received: from AS8PR04MB8404.eurprd04.prod.outlook.com ([fe80::121:6a2a:2d4b:cb8a]) by AS8PR04MB8404.eurprd04.prod.outlook.com ([fe80::121:6a2a:2d4b:cb8a%7]) with mapi id 15.20.5632.021; Tue, 20 Sep 2022 14:04:04 +0000 From: Sherry Sun To: =?utf-8?B?SWxwbyBKw6RydmluZW4=?= CC: "gregkh@linuxfoundation.org" , "jirislaby@kernel.org" , "bhuvanchandra.dv@toradex.com" , "linux-serial@vger.kernel.org" , "linux-kernel@vger.kernel.org" , dl-linux-imx Subject: RE: [PATCH] tty: serial: fsl_lpuart: disable dma rx/tx use flags in lpuart_dma_shutdown Thread-Topic: [PATCH] tty: serial: fsl_lpuart: disable dma rx/tx use flags in lpuart_dma_shutdown Thread-Index: AQHYzONQq3XMfMWY1E+X54tNGbt8Yq3oPm+AgAAaaXA= Date: Tue, 20 Sep 2022 14:04:04 +0000 Message-ID: References: <20220920111703.1532-1-sherry.sun@nxp.com> In-Reply-To: Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: AS8PR04MB8404:EE_|DB9PR04MB8187:EE_ x-ms-office365-filtering-correlation-id: c78dbc5d-f654-4c0f-9fa0-08da9b10fa6b x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: vsz5YwYO9O1G1zHmUZeSC6WMtSS2E0iUmzhzpgBtwGaMNZCSwh1R9N9SEJYN+igeNHzZo3gH3U2HZyGGyD8V8FHxW2z8utOooPtGqsyBk24ZpixXsPo1H0HhGVSnU8qEC5nDjywEuOYPF3XL0MFLp1ltaSziTFJCu0ZxEUvt1cC83PjOrPE/OcNDlwpcb5UXt2wWQEO2dxOjTdv//1bFMvtDL4Q6M64biCBKMK+ZvpMuJt3CSGJyuAllmrlFx5vqIXgQvVJq4h66cwDSxzUI9eGgCGEi/K2BFoyTdh3IytYy9aQTQJwjHPcOsW92RvDNWeJqrLfdh71y/dW2lhbTaIrEidQAzzPJd6zMPQqxIdQfzVJsJVIY+2VdQcsQz5qgk4Pkh2jHK3k3iam+zIhGNGxIonXpI5m4tvkQGAeOmo/MWFekPZMJUByYG6WoQaQhhAi8NZE+7p/Nac4Iv98a0+Q8gEXRJdJD1DVh2fw/eJvaioolAcctm/4sUQhhRuUAJq6wqmK3+96k912+NnVdcZb/3DZhHh8A5W1b3AgTjfyYQXe2MCaUbbqrlWTN2uKyUS5I/s5hJNVKxSWcxgOAfTEYJn56i6qpobFf3IVIQ2biIb+/2gzc13E2pzoxgSqrVaVn5V37kkn4QlLW/CZ6cSaEnUDrfN9f5AEatEJl/q86FnpAIaWA1rWkvcnQ0f11Lnuxj/Gpcg4WyFira9GoTpp8lziDLHn6BnzRDP5E8fbLeO3W1/juvR5Be8Hg1mEY5Ia8UR8q/3l0gfYngCnYZA== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR04MB8404.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(366004)(346002)(376002)(136003)(396003)(39860400002)(451199015)(478600001)(66556008)(45080400002)(76116006)(66946007)(54906003)(6916009)(71200400001)(33656002)(66446008)(64756008)(8676002)(4326008)(41300700001)(7696005)(6506007)(86362001)(53546011)(52536014)(38070700005)(66476007)(8936002)(26005)(55016003)(122000001)(38100700002)(83380400001)(5660300002)(9686003)(316002)(186003)(66574015)(44832011)(2906002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?B?SExON0tzY0R3UUx4aWs5SFBueE43bWIrZkk0dXhjUWVCRlB3TU5yQmRDcUxS?= =?utf-8?B?cXZXa1lsM0hBNndjWVViTkNqb2FVdjlId1h4SzBDU2JJTnV1Yk1HdTVUbzdM?= =?utf-8?B?YXJJUUpmd2pPc1pjR0FlWT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UtRTSs2WTJv?= =?utf-8?B?T2luNWRXSDJ6anl1cXRTMGNsZzZOakNmcEhXZmRWK1RsVkN1amdlYTdKNzJZ?= =?utf-8?B?bUZ5VCs0NzUwLzkxVnU0dDY0bHMyQWZCQjk0SXM2QXh3dG9xTUZvcXYwMXgw?= =?utf-8?B?dkRuUjlKUEFXTDZsM3hCM3M1QTRra2VpM3ptV2lVeXhkdGxjamNOMXJJdUky?= =?utf-8?Q?pXX2eH+KE35WcDX+twVlsnLcN?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8404.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c78dbc5d-f654-4c0f-9fa0-08da9b10fa6b X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Sep 2022 14:04:04.9173 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Rc83C9fjUZKi0vbeZypQJTMXknw64H50+q18sLsC2ET+/3cK9U2ZhWxMH+/t1dBnSt7Bx+LcrJeZag6FgTtRWg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB8187 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > -----Original Message----- > From: Ilpo J=C3=A4rvinen > Sent: 2022=E5=B9=B49=E6=9C=8820=E6=97=A5 20:26 > To: Sherry Sun > Cc: gregkh@linuxfoundation.org; jirislaby@kernel.org; > bhuvanchandra.dv@toradex.com; linux-serial@vger.kernel.org; linux- > kernel@vger.kernel.org; dl-linux-imx > Subject: Re: [PATCH] tty: serial: fsl_lpuart: disable dma rx/tx use flags= in > lpuart_dma_shutdown >=20 > On Tue, 20 Sep 2022, Sherry Sun wrote: >=20 > > lpuart_dma_shutdown tears down lpuart dma, but lpuart_flush_buffer can > > still occur which in turn tries to access dma apis if > > lpuart_dma_tx_use flag is true. At this point since dma is torn down, > > these dma apis can abort. Set lpuart_dma_tx_use and the corresponding > > rx flag lpuart_dma_rx_use to false in lpuart_dma_shutdown so that dmas > > are not accessed after they are relinquished. > > > > Otherwise, when try to kill btattach, kernel may panic. This patch may > > fix this issue. > > root@imx8ulpevk:~# btattach -B /dev/ttyLP2 -S 115200 > > ^C[ 90.182296] Internal error: synchronous external abort: 96000210 [= #1] > PREEMPT SMP > > [ 90.189806] Modules linked in: moal(O) mlan(O) > > [ 90.194258] CPU: 0 PID: 503 Comm: btattach Tainted: G O > 5.15.32-06136-g34eecdf2f9e4 #37 > > [ 90.203554] Hardware name: NXP i.MX8ULP 9X9 EVK (DT) > > [ 90.208513] pstate: 600000c5 (nZCv daIF -PAN -UAO -TCO -DIT -SSBS > BTYPE=3D--) > > [ 90.215470] pc : fsl_edma3_disable_request+0x8/0x60 > > [ 90.220358] lr : fsl_edma3_terminate_all+0x34/0x20c > > [ 90.225237] sp : ffff800013f0bac0 > > [ 90.228548] x29: ffff800013f0bac0 x28: 0000000000000001 x27: > ffff000008404800 > > [ 90.235681] x26: ffff000008404960 x25: ffff000008404a08 x24: > ffff000008404a00 > > [ 90.242813] x23: ffff000008404a60 x22: 0000000000000002 x21: > 0000000000000000 > > [ 90.249946] x20: ffff800013f0baf8 x19: ffff00000559c800 x18: > 0000000000000000 > > [ 90.257078] x17: 0000000000000000 x16: 0000000000000000 x15: > 0000000000000000 > > [ 90.264211] x14: 0000000000000003 x13: 0000000000000000 x12: > 0000000000000040 > > [ 90.271344] x11: ffff00000600c248 x10: ffff800013f0bb10 x9 : > ffff000057bcb090 > > [ 90.278477] x8 : fffffc0000241a08 x7 : ffff00000534ee00 x6 : > ffff000008404804 > > [ 90.285609] x5 : 0000000000000000 x4 : 0000000000000000 x3 : > ffff0000055b3480 > > [ 90.292742] x2 : ffff8000135c0000 x1 : ffff00000534ee00 x0 : > ffff00000559c800 > > [ 90.299876] Call trace: > > [ 90.302321] fsl_edma3_disable_request+0x8/0x60 > > [ 90.306851] lpuart_flush_buffer+0x40/0x160 > > [ 90.311037] uart_flush_buffer+0x88/0x120 > > [ 90.315050] tty_driver_flush_buffer+0x20/0x30 > > [ 90.319496] hci_uart_flush+0x44/0x90 > > [ 90.323162] +0x34/0x12c > > [ 90.327253] tty_ldisc_close+0x38/0x70 > > [ 90.331005] tty_ldisc_release+0xa8/0x190 > > [ 90.335018] tty_release_struct+0x24/0x8c > > [ 90.339022] tty_release+0x3ec/0x4c0 > > [ 90.342593] __fput+0x70/0x234 > > [ 90.345652] ____fput+0x14/0x20 > > [ 90.348790] task_work_run+0x84/0x17c > > [ 90.352455] do_exit+0x310/0x96c > > [ 90.355688] do_group_exit+0x3c/0xa0 > > [ 90.359259] __arm64_sys_exit_group+0x1c/0x20 > > [ 90.363609] invoke_syscall+0x48/0x114 > > [ 90.367362] el0_svc_common.constprop.0+0xd4/0xfc > > [ 90.372068] do_el0_svc+0x2c/0x94 > > [ 90.375379] el0_svc+0x28/0x80 > > [ 90.378438] el0t_64_sync_handler+0xa8/0x130 > > [ 90.382711] el0t_64_sync+0x1a0/0x1a4 > > [ 90.386376] Code: 17ffffda d503201f d503233f f9409802 (b9400041) > > [ 90.392467] ---[ end trace 2f60524b4a43f1f6 ]--- > > [ 90.397073] note: btattach[503] exited with preempt_count 1 > > [ 90.402636] Fixing recursive fault but reboot is needed! > > > > Fixes: 6250cc30c4c4 ("tty: serial: fsl_lpuart: Use scatter/gather DMA > > for Tx") > > Signed-off-by: Thara Gopinath > > Signed-off-by: Sherry Sun > > --- > > drivers/tty/serial/fsl_lpuart.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/drivers/tty/serial/fsl_lpuart.c > > b/drivers/tty/serial/fsl_lpuart.c index f21915015d67..064bd1f33c21 > > 100644 > > --- a/drivers/tty/serial/fsl_lpuart.c > > +++ b/drivers/tty/serial/fsl_lpuart.c > > @@ -1771,6 +1771,7 @@ static void lpuart_dma_shutdown(struct > lpuart_port *sport) > > if (sport->lpuart_dma_rx_use) { > > del_timer_sync(&sport->lpuart_timer); > > lpuart_dma_rx_free(&sport->port); > > + sport->lpuart_dma_rx_use =3D false; > > } > > > > if (sport->lpuart_dma_tx_use) { > > @@ -1779,6 +1780,7 @@ static void lpuart_dma_shutdown(struct > lpuart_port *sport) > > sport->dma_tx_in_progress =3D false; > > dmaengine_terminate_all(sport->dma_tx_chan); > > } > > + sport->lpuart_dma_tx_use =3D false; > > } > > > > if (sport->dma_tx_chan) >=20 > Isn't it still racy because lpuart_dma_shutdown() is called outside of po= rt's > lock? Hi Ilpo, do you think add the following changes should work for this? diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuar= t.c index 064bd1f33c21..b3c53935fbc8 100644 --- a/drivers/tty/serial/fsl_lpuart.c +++ b/drivers/tty/serial/fsl_lpuart.c @@ -1768,10 +1768,14 @@ static int lpuart32_startup(struct uart_port *port) static void lpuart_dma_shutdown(struct lpuart_port *sport) { + unsigned long flags; + if (sport->lpuart_dma_rx_use) { del_timer_sync(&sport->lpuart_timer); lpuart_dma_rx_free(&sport->port); + spin_lock_irqsave(&sport->port.lock, flags); sport->lpuart_dma_rx_use =3D false; + spin_unlock_irqrestore(&sport->port.lock, flags); } if (sport->lpuart_dma_tx_use) { @@ -1780,7 +1784,9 @@ static void lpuart_dma_shutdown(struct lpuart_port *s= port) sport->dma_tx_in_progress =3D false; dmaengine_terminate_all(sport->dma_tx_chan); } + spin_lock_irqsave(&sport->port.lock, flags); sport->lpuart_dma_tx_use =3D false; + spin_unlock_irqrestore(&sport->port.lock, flags); } Best Regards Sherry