Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2148422pxb; Mon, 12 Apr 2021 16:05:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5WJ3gu8m4COjASt0Kmf3q7s+TzRolSL87pmX4evOKkffngIWKgKrUYyxvpR+1HMs6htiX X-Received: by 2002:a65:6643:: with SMTP id z3mr28360579pgv.387.1618268700046; Mon, 12 Apr 2021 16:05:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618268700; cv=none; d=google.com; s=arc-20160816; b=aQP0x+TycNwAiT8xgqPCWAyIB7771OVRPfBvh+SsVthsYiPEYP3OLhyQ0Ha/9Tk/y7 ubyWxEENpMhz9IiYcxsILgB1nbS7U5NzJ/fwjslDRosi6oXb68CKonktsLtY988ov2u1 X7uGSgaLhfrrP/mPq1Lp9/9H467U9Qu9NyKRrxY5WaioP4CvVz8AnT1WOunlUom+mA/O DB8yxDvE0h90fMcjvrFk1BLjStNILFUL+5e971BbSHhROn5rRSLl2sDxeYQZiuQHXitB YOcezIhNuyCRQNsnCPmsrIAXuwRIr7qZiALvT9uEkNLV+DFblAFNG2gtHtxmx+lBiXsw cR7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=FIa8vzlJ95KgTvemP99zsGvjuO3hsl64E5Vg1pmoZ4w=; b=vHtJlvVqaq7/N8ArlBKaZIXf3DCYVF7K+cOb0yH+wg8QX6YTtNxV31oXI7pG7gfdn9 HwfID9JPcGJjluWY8uzXOO2yOxXPq7L69Sl91N9smlrVvDSc6kLPwp9aThYZWImjWKV+ fuv7rQotQtbTau2oRCPz5sC7hs/UetrdGDxg3sSJawYESQ0X/jq7qvKH/rjg7czYEoos D3Ldv/WT1yye+WGuLi4o3sXcxBfBi0ovvsqUtN6zzU4N4LAKNWYCe6Hz9nyWrnOjQ0h2 8es8gvi8qvjuAUBMXcpaYmQDTynh6K4JmtSTzZTqEGW+m4zvI3b0z7ddlq/N0vkOBXP1 zAcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=INfHcv6K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c3si14549908pfo.192.2021.04.12.16.04.47; Mon, 12 Apr 2021 16:05:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=INfHcv6K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244485AbhDLJwo (ORCPT + 99 others); Mon, 12 Apr 2021 05:52:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:56020 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241785AbhDLJjc (ORCPT ); Mon, 12 Apr 2021 05:39:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BDEB26120B; Mon, 12 Apr 2021 09:39:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618220354; bh=aPImZCrgJujvvKf1wVXHwFUAAvYaRgDhpRe+X56AdfI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=INfHcv6K4T5EPreapejD3JkX/41eszO4nsjC/osCjhYV8BjhUV3lHEcemYgEXx7OF n7xE7VI+TcsLQDkoN6qJzluyveUoI0/xxQ38xXcBRWQhY4sstGGwVzJLlnkHUg4v6J AQqqGaVC4ZB0H9Mvr1uTHgGERU2aQK9Idm/mqgiP0OpBNc58LQ34vXTsbbLeexjU+O OiVVKVY/0sjcQ4qQabSh/YYB57GFJRn+sT6++bYN0Z8ZxPY4+zyabRpt0tF+ouPnjf eMg+St1PeMyZy4+YagkdsTPL5ss6PjPdX1EpV91wOi/pEuWpNQfbKP9oy4S6BDr6+6 sEnQ5QHwoLdJQ== Date: Mon, 12 Apr 2021 15:09:10 +0530 From: Vinod Koul To: Robin Gong Cc: 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, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de, dmaengine@vger.kernel.org, linux-imx@nxp.com Subject: Re: [PATCH v14 12/12] dmaengine: imx-sdma: add terminated list for freed descriptor in worker Message-ID: References: <1617809456-17693-1-git-send-email-yibin.gong@nxp.com> <1617809456-17693-13-git-send-email-yibin.gong@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1617809456-17693-13-git-send-email-yibin.gong@nxp.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07-04-21, 23:30, Robin Gong wrote: > 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 Sound like you should implement .device_synchronize() and do the actual work there..? > > Signed-off-by: Robin Gong > Reported-by: Richard Leitner > --- > 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); > /* > -- > 2.7.4 -- ~Vinod