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 X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 4867AC07E9C for ; Fri, 9 Jul 2021 09:55:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B58A613CC for ; Fri, 9 Jul 2021 09:55:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232059AbhGIJ6j (ORCPT ); Fri, 9 Jul 2021 05:58:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231991AbhGIJ6h (ORCPT ); Fri, 9 Jul 2021 05:58:37 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C307EC0613E8 for ; Fri, 9 Jul 2021 02:55:54 -0700 (PDT) Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=[IPv6:::1]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m1nES-0001nB-OP; Fri, 09 Jul 2021 11:55:40 +0200 Message-ID: Subject: Re: [PATCH v14 12/12] dmaengine: imx-sdma: add terminated list for freed descriptor in worker From: Lucas Stach To: Robin Gong , 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, 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 Date: Fri, 09 Jul 2021 11:55:39 +0200 In-Reply-To: <1617809456-17693-13-git-send-email-yibin.gong@nxp.com> References: <1617809456-17693-1-git-send-email-yibin.gong@nxp.com> <1617809456-17693-13-git-send-email-yibin.gong@nxp.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.1 (3.40.1-1.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.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 Am Mittwoch, dem 07.04.2021 um 23:30 +0800 schrieb Robin Gong: > 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 9519b41..4174580 100644 > --- a/drivers/dma/imx-sdma.c > +++ b/drivers/dma/imx-sdma.c > @@ -381,6 +381,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; > }; > > @@ -1041,9 +1042,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 > @@ -1052,10 +1050,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) > @@ -1069,6 +1064,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); > } > @@ -2075,6 +2077,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); > /* 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 X-Spam-Level: X-Spam-Status: No, score=-14.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 4FE12C07E99 for ; Fri, 9 Jul 2021 09:57:16 +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 191E0613C9 for ; Fri, 9 Jul 2021 09:57:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 191E0613C9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de 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: Date:Cc:To:From:Subject:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ZV7Pgp5M39EJfsqb6feX8t3q5H0P+CMt30IB7Y6FKQw=; b=lEj7pX2XMgC4Nb yJZCjO0n0KK0FZHf+kVy2mXun/z2MpKugxI6kqZ1439kYJ/R8SPKp9L0Rtd+r3qFdV3QfPg1Z9Tk8 +7IVV2Oysh0fdR5/dWZn0djpt8529d8euHcTgSmG5pgLr0akqUKJruX630jOZ4P6H2ZNiSbU0dZXh gb+M1JUeVCEd8XYKnSFHqPbTfR9bUpmNe45lbLbwhkwaJZIv4z2L5xVn9q0o+6cJz37tku16esyBO rUP+uyt4vP4CB0RCIOyq0A2L+ywxv4xJsV3tKQyXGrgeAuULRNY4XsEBcXS15rsFFRUU+DIuf9Uf5 6gPVncJPMgpjUKDFv8qg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m1nEk-001Ppr-QE; Fri, 09 Jul 2021 09:55:58 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m1nEg-001PoT-Nh for linux-arm-kernel@lists.infradead.org; Fri, 09 Jul 2021 09:55:56 +0000 Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=[IPv6:::1]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m1nES-0001nB-OP; Fri, 09 Jul 2021 11:55:40 +0200 Message-ID: Subject: Re: [PATCH v14 12/12] dmaengine: imx-sdma: add terminated list for freed descriptor in worker From: Lucas Stach To: Robin Gong , 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, 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 Date: Fri, 09 Jul 2021 11:55:39 +0200 In-Reply-To: <1617809456-17693-13-git-send-email-yibin.gong@nxp.com> References: <1617809456-17693-1-git-send-email-yibin.gong@nxp.com> <1617809456-17693-13-git-send-email-yibin.gong@nxp.com> User-Agent: Evolution 3.40.1 (3.40.1-1.fc34) MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.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-20210709_025554_830766_4AB17207 X-CRM114-Status: GOOD ( 21.81 ) 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: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Am Mittwoch, dem 07.04.2021 um 23:30 +0800 schrieb Robin Gong: > 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 9519b41..4174580 100644 > --- a/drivers/dma/imx-sdma.c > +++ b/drivers/dma/imx-sdma.c > @@ -381,6 +381,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; > }; > > @@ -1041,9 +1042,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 > @@ -1052,10 +1050,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) > @@ -1069,6 +1064,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); > } > @@ -2075,6 +2077,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); > /* _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel