From patchwork Tue Jul 13 18:41:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Gong X-Patchwork-Id: 12373641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=3.0 tests=BAYES_00, DATE_IN_FUTURE_06_12,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E32DC07E95 for ; Tue, 13 Jul 2021 11:11:03 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 32F2260725 for ; Tue, 13 Jul 2021 11:11:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 32F2260725 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=V2GTCsTtXQDjvcR8FPwGKYP8iIlBEnQtbkWabRbJSH8=; b=VjXHc2gK5d4wHH RI0yaxe72Al3r0uWiWlXiraJPm/iFklAHH0L7Ez/RMKgHYQcf5JF+PDzezrddzinDWJ2nqTyqnbof 3aLjJEKqMleV1bGVbLYIHCOHxhijfwpWmriLvfJLsV4AddJpPjXpAzAx1tof+BORnhsOrsMt40UL3 QDH36GY5iQiSyBD9nOp9097fxykFhsQIUyfsfWHqiBuO8Uz2AhLDiS4OcoCTBV5JzLSerTqMCShWk NXwUANBBKHlKK1K98vXvZInFy3gVuGYaneyKKwNh6XCsN3mGeKlaBerF/ngZOcSsIFQ8lnZo+QYtL +7URCrClJXOMI/sBB2Mw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m3GGR-00A5cb-Go; Tue, 13 Jul 2021 11:07:49 +0000 Received: from mail-vi1eur05on2064.outbound.protection.outlook.com ([40.107.21.64] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m3Fcl-009umG-Rf for linux-arm-kernel@lists.infradead.org; Tue, 13 Jul 2021 10:26:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Lw9JzuuB9vT4M0OTgliRus5AOFxWU6P3hmI2mRox34uIY23yxHxyXRFg2rzdmEtqqwxDPUJv19BZprfxfgYl7p/BhteOqMMohT4iZyNGLqhSeLmiP0j4dLM5vbJ/tPNuOJad5AZi9b+4fl6g6n1OI60z1VD0DcpMlrEOkj0ADwUt0IFEFGjjQaXvWcTKpzKdb9655RLc9nbvtvrLNEcyDjIOaSAkcGJLqs3wTRxcR2S4AUmdyISQQ5vg8tNQHBeiPkivO+nAHDKvuz0SJUkg5MG3b24t+5Np8nkP+F0ay62hjlBP8PuAmSJguyN/BfqDwSGfmmlJ/MqWho3yQaoM8g== 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-SenderADCheck; bh=tW5lZMEUKTmo+F4zrVNicpKnImo9kdoACV6FdhIqYE8=; b=bPSvVzu1u0J1OLwgAamw9BfM/NsfPCeCaIlr1VdYf9t/YqbcalQBJV0DV2WHCt9tzMNko6SyBhpxSvUNnYmifdg3k4x/9WKb3ZHe4akgSLJ2qlQKBw2wxZF+jcRavYyi5xHaGtVQR1IzgRMBLfWKdDYcwrsHBaFpvrGLkzvXaY7YxiL9j829GOFTtvuo1KOaaAMia6As2RnpJ2CE7uQYQJl9tYcuPjEMS0tptg8agpBLqOuHSVM0mmrrme28CWt4GNCt3K9dhhd3CImi2qyyEIJkIjHn0clHznwwHsUlV9ICUlovG1vJR0I5r6Lm0lfQNs5c45mwtC8PsO6ZBa7NSQ== 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=tW5lZMEUKTmo+F4zrVNicpKnImo9kdoACV6FdhIqYE8=; b=RM/5rz7EWZZmjThDXt9vPsoO/nvs3GpCM3hzCYsN3QIihOcAzLnAWf1jTUkTRdBqrF+UWYx2vDT/V6vMT89WTVP3xjLSSmk+ZST1yag7xFqILxgWPbbEOV7aukE13YNlL24tiNHa9wYecmNKBzwZQxCW8vpl0FQjHV2HNCOfscA= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VE1PR04MB6688.eurprd04.prod.outlook.com (2603:10a6:803:127::25) by VI1PR0402MB3344.eurprd04.prod.outlook.com (2603:10a6:803:10::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.23; Tue, 13 Jul 2021 10:26:45 +0000 Received: from VE1PR04MB6688.eurprd04.prod.outlook.com ([fe80::a978:6f38:2bce:9076]) by VE1PR04MB6688.eurprd04.prod.outlook.com ([fe80::a978:6f38:2bce:9076%5]) with mapi id 15.20.4308.027; Tue, 13 Jul 2021 10:26:45 +0000 From: Robin Gong To: vkoul@kernel.org, mark.rutland@arm.com, broonie@kernel.org, robh+dt@kernel.org, catalin.marinas@arm.com, will.deacon@arm.com, shawnguo@kernel.org, festevam@gmail.com, s.hauer@pengutronix.de, martin.fuzzey@flowbird.group, u.kleine-koenig@pengutronix.de, dan.j.williams@intel.com, matthias.schiffer@ew.tq-group.com, frieder.schrempf@kontron.de, m.felsch@pengutronix.de, l.stach@pengutronix.de, xiaoning.wang@nxp.com Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, linux-imx@nxp.com, kernel@pengutronix.de, dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v15 12/12] dmaengine: imx-sdma: add terminated list for freed descriptor in worker Date: Wed, 14 Jul 2021 02:41:49 +0800 Message-Id: <1626201709-19643-13-git-send-email-yibin.gong@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1626201709-19643-1-git-send-email-yibin.gong@nxp.com> References: <1626201709-19643-1-git-send-email-yibin.gong@nxp.com> X-ClientProxiedBy: SG2PR06CA0198.apcprd06.prod.outlook.com (2603:1096:4:1::30) To VE1PR04MB6688.eurprd04.prod.outlook.com (2603:10a6:803:127::25) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from robin-OptiPlex-790.ap.freescale.net (119.31.174.66) by SG2PR06CA0198.apcprd06.prod.outlook.com (2603:1096:4:1::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.4308.20 via Frontend Transport; Tue, 13 Jul 2021 10:26:38 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 15601e84-2593-4bb7-c239-08d945e8b695 X-MS-TrafficTypeDiagnostic: VI1PR0402MB3344: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: n/lmkUxoYbV/s+9mcZN9UN6Hzmk8yzE+sYF6ifJzcQO5aNKZSXEqToho+dvEWP0gNLHeOiNe0dMsiishgMVPAdWRX10eM6PX0bWNk8aXhCGmNH+RNaowHGg9SbjzuqXHlqrYfmn9qpmebf2qkcPiPfTbWXbMYS39tMsMRrA6Aj2gJyi+YJgtgkaTsle1XNxWdvy3pgmzEr1Ka7sYjYGWX/JgJ6eq+2A7aoJL6V8E/lcIkQrz8m8Jlh3q5D4SuoivrqPCuvYCDIteHo0wrXSaiTXBmvhjDrpb7hDTyGi65UOtGmxbuu+ifxCUccjVcRIC2VM3B68rGAse7f4ixInssuegImLD9jy4f1COuyOLRcr8MyUuNNchbbaRS+x9AFsGQMOD6Krn06iw1/K7RocGsrlHKnF00/4Yh7S1smw43y+xYor07ECS5vR6iGM780kr3jjfL+5l8GIEOD2nE7dfKiqI2HLtjxZmcZqPR3/zUG6WpNh7K/LqVG7WUDSyvLu7sUIUPSEX+JSA2n9fwLTofIboKgSer3QulM8e5noa0DqepWLS4/mTVa0vPz1RYV+mMdReofdrKe85oTvY0oT/x7O/QHRekYFRfs5MqhuB66hJWmmder/thdhTYxd/qBvNAP0VWSozmrYzQfiecUjQdqgZ8P93h2MsVZj1euqmNsuAOXpdjrFxCk0AEzks9c6HFDBpNeJaJ5bkg8bV72Uy3KHxaVQa+nnA7liBUw0HWJywqpS/BxJZ50oGYHyUGUhjwapeC7xSpABrc6OEfiySqPORU/vIlC2RlRzH3tDoTbwOjmEivr+RtnRteVotUwVX X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR04MB6688.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(396003)(366004)(346002)(376002)(39850400004)(4326008)(26005)(66476007)(956004)(36756003)(8936002)(6486002)(478600001)(5660300002)(6512007)(86362001)(83380400001)(7416002)(2616005)(6666004)(966005)(66946007)(8676002)(66556008)(316002)(38100700002)(38350700002)(6636002)(2906002)(921005)(6506007)(186003)(52116002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: oDX9Kw3I+oQ9ya6O+g2zgsMah7CU9WmeNcsPKsN9IVNS3JAXe5zUaodonXXbMlku0IY2LOVsQaUeE43gLJe2e2KqJ+vCylbAtUkEzRaeSHwoYaK2aDGJTQc6dQ9VArP1P3gnIVxWKATbxpK/Tt5/Nc8LGAxcd7wxbwyLmcOMTDjeK6lVT5+NElRbXgia8LAvX7qYaZ+2740m3Wp6CQlU2/poGnS+sUdQ5JWQRCJpEEoWBnBqLHfqzvn8aFMHWZ7IoNUuCzmeNvmu9VZvngVwFZHf3PkRO5ZyRrHTuRG7vGe0+bb4Hv1L4D/KxTr8WhV8lFZ4NMpZ3pwiIJyCQtpFRna2jgyPPqQLQcVg2CcR2rnZW+Zqut/N1RXItOYq6vprRl4nlMQbnr+rPj55wh4G7Yb0r0ccXtZhqhALHdiOgbn2ZNYjUogNTZQJ3oNjlFO2C7MwxlL9nNm2XFStCE2RqQyKFNlwklD9Ct2ioIgJxbXXLA7x1m//tontxmM+iIvPfXPhAvqHyQ5HB0jfKYSABaln5fWLdzS8t/15AiXuRIMjD221w2mOQaHNYHpLVyac3WGZkUAgL5Bz9NCyFTX7m5mgusRtPEbZP+huYjP8iuzU2JiK1slGYuqVPivHa1MhyQHr1V95AeVYKOPY/ebZ/hDcIKDbdz+hKveYQSAi62keO/tUYKr4R6OrMaBBZ7wt2p3MvPBOeQe6MbTUjpeYfquhE0AiK/JtQc8qYB66Wr/RSyicDsroGwUyRsnPza5gecWnBwgof+qpF//+YUzKB99jALg59VhuJ2miC7+2MySW7L4SsQJCATwE4WDdPClUQ869iGO7Mj/QO/T8nMRfSn5BhihV6vikUDLomvlHpoIT7kzkfoJM/fBG/6xlAj2YSDhZaYB0UQZ7AHhSgxrLkg4osqv5G583ONA4F+V5EyfV0Uk1Bz5e4NIRhgPXO6kBRJlSRNJkV8kYKJC0igQYg8vkApxhgV2/QsJ2EOji5uViOqD7HKS+HLTlpunJbhgnJ3jaeV5d56vReWIf+xtyWdfTvRGMMCMu/auec+cSErqnFz2NdUkh5efOQPNxrnHZ0LTzPoHSD4Red7EWnypQxRoUeXSvCxQxBCT9dl8s/FLHCuJ7YTjCZZMA1beU17/2X7JuPuzDUVKwSan6mOsnWhXuEk26lwmqq+xfHKnvV3Gm1zOTgK5AnTUhr56uwK/sQEYkDBdaUA77spiVzLvnWa2x+lnuaOh0cLt8PslOFt8m+1Z1PBPnwM8W9XfjpdWl3sR8nUCxGS5teWKikJHW/2P31RHjKejQHtskiE47I0KPFv4eAqerp+F+VPnaV7Y+ X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 15601e84-2593-4bb7-c239-08d945e8b695 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6688.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jul 2021 10:26:44.9232 (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: CKfROocsmD6Ng9WVnQTop8begq4dmyfZXtZCXuP5szBcVysqKAc1v6y2pVj/o4lKiYPqQYddhVAN81Avufc6EA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3344 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210713_032647_960633_DF18BCD3 X-CRM114-Status: GOOD ( 14.83 ) 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 Add terminated list for keeping descriptor so that it could be freed in worker without any potential involving next descriptor raised up before this descriptor freed, because vchan_get_all_descriptors get all descriptors including the last terminated descriptor and the next descriptor, hence, the next descriptor maybe freed unexpectly when it's done in worker without this patch. https://www.spinics.net/lists/dmaengine/msg23367.html Signed-off-by: Robin Gong Reported-by: Richard Leitner Reviewed-by: Lucas Stach --- drivers/dma/imx-sdma.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index c449755..6e0490d 100644 --- a/drivers/dma/imx-sdma.c +++ b/drivers/dma/imx-sdma.c @@ -439,6 +439,7 @@ struct sdma_channel { enum dma_status status; struct imx_dma_data data; struct work_struct terminate_worker; + struct list_head terminated; bool is_ram_script; }; @@ -1107,9 +1108,6 @@ static void sdma_channel_terminate_work(struct work_struct *work) { struct sdma_channel *sdmac = container_of(work, struct sdma_channel, terminate_worker); - unsigned long flags; - LIST_HEAD(head); - /* * According to NXP R&D team a delay of one BD SDMA cost time * (maximum is 1ms) should be added after disable of the channel @@ -1118,10 +1116,7 @@ static void sdma_channel_terminate_work(struct work_struct *work) */ usleep_range(1000, 2000); - spin_lock_irqsave(&sdmac->vc.lock, flags); - vchan_get_all_descriptors(&sdmac->vc, &head); - spin_unlock_irqrestore(&sdmac->vc.lock, flags); - vchan_dma_desc_free_list(&sdmac->vc, &head); + vchan_dma_desc_free_list(&sdmac->vc, &sdmac->terminated); } static int sdma_terminate_all(struct dma_chan *chan) @@ -1135,6 +1130,13 @@ static int sdma_terminate_all(struct dma_chan *chan) if (sdmac->desc) { vchan_terminate_vdesc(&sdmac->desc->vd); + /* + * move out current descriptor into terminated list so that + * it could be free in sdma_channel_terminate_work alone + * later without potential involving next descriptor raised + * up before the last descriptor terminated. + */ + vchan_get_all_descriptors(&sdmac->vc, &sdmac->terminated); sdmac->desc = NULL; schedule_work(&sdmac->terminate_worker); } @@ -2132,6 +2134,7 @@ static int sdma_probe(struct platform_device *pdev) sdmac->channel = i; sdmac->vc.desc_free = sdma_desc_free; + INIT_LIST_HEAD(&sdmac->terminated); INIT_WORK(&sdmac->terminate_worker, sdma_channel_terminate_work); /*