Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3882262rdb; Mon, 11 Dec 2023 02:54:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IHrn86nyAvtvqUTfrwPkQLEeBhI4Pw+vl2Mgun9wCd4dK639H43C3519/do7gIYdZs/cAKo X-Received: by 2002:a05:6a00:852:b0:6ce:2757:7865 with SMTP id q18-20020a056a00085200b006ce27577865mr6389593pfk.32.1702292057863; Mon, 11 Dec 2023 02:54:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702292057; cv=none; d=google.com; s=arc-20160816; b=OfUIhC9JyOrSPvCpiHPEzhJYcvb/wir6lUrQmHULqzr+VXfcqT3UFX2YrqzxAbbwkG o0Req9OhVCwhn87KBqrVMSg5uEoE+vK++5KT/WWm00gydehfimERM/LNBtKCw2jjK5kS NUQxOqMgXm+NsKf212LiqlUtbvXS3K8/0CRcIVF4VEkUztgdsmh4/0WlR5H3I6X246cK shre+Qmpd+7jItJKnQZJ+4d8G1VRNmRNkllnN815iyaBhyRSlojjK7YE7qA5CfFVixjy QCneojSmKYswiLoS2JhIYWZcqtSJeIdL0Ukoczcd/MSGPPCbsHGZBAqB6PC46HJN3oNv jc0Q== 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=iuuMJaWlZL4m9v+F083lqHCom0RJFSPbTZkvdpVIwrc=; fh=84E365O0F6DY3jzbAFsm4+M0lFOijqSOYj6lJkPEhV0=; b=a3LckXYIWKZg2g/321si+aydm+HHMN5iC7agpewtPLlVhVaPxNMw2yn3S6Sp7NwDd8 koGz/vqJuyhBjqsHLdPpa0qgZwYpXVDgzviah2sFEBDg5BLDO+XKjkenkYbE1yMir2V3 Ao0972wh7LljR/39xSIBpDa9QSJrwhOVm0c5DjnCsrf+JOVFVoDDJO1XWjqeeLBlwwoJ 7W5rlwxbPonz8x6XAAL4C/MZ+ye3nm7x2B+yLpict0vXCzm0/GfEQlX+My02oaZYqp2B syy4AazOanz/NgU0WS5gRbSpbbBIraj2BEDMhiWS19rel7SFcTST4undPHWHL/xSLKls o9Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iJ2xmnKN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id l184-20020a6388c1000000b005c6b543b425si5616214pgd.617.2023.12.11.02.54.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 02:54:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iJ2xmnKN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 68AD58097E4B; Mon, 11 Dec 2023 02:54:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234220AbjLKKyC (ORCPT + 99 others); Mon, 11 Dec 2023 05:54:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231734AbjLKKx7 (ORCPT ); Mon, 11 Dec 2023 05:53:59 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2711EA1 for ; Mon, 11 Dec 2023 02:54:06 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 304A1C433C7; Mon, 11 Dec 2023 10:54:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702292045; bh=Mew19YXARFjy0JbYv18LDqEwa392ENZRfLl+eSvOMKA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=iJ2xmnKNSkDBALZLpUjhCE29HPVqxORPSTSbZ46jS2m+jtpo7r2n4BUX0Xm4zvOTH YO6lfYSyBivPT45enhCace80oThVdPEhEZEJYn0MZp9oKA1FTQh47NItT2oQV2KZjQ wyfZAZXpCQ2DGEdq0HEf/ax/d61eVh6BFo3fpdKdQgM6pR4w1Uekomk54AxzcGz7w0 0YJ0t67KITwfy6FW8SkEs3PSMEqCO0o1ipj9vPM0TigyFZgRHxuj7QrDHXh+6bvxUi ywroaL9KQdcVubnmIOpoV4uW+UsVhxjOi3v4x99zDQ1lkA/Ehr5TGlRptO25obv3RO ju07LyRJ7ZK3Q== Date: Mon, 11 Dec 2023 16:24:01 +0530 From: Vinod Koul To: Jan Kuliga Cc: lizhi.hou@amd.com, brian.xu@amd.com, raj.kumar.rampelli@amd.com, michal.simek@amd.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, miquel.raynal@bootlin.com Subject: Re: [PATCH v4 4/8] dmaengine: xilinx: xdma: Rework xdma_terminate_all() Message-ID: References: <20231208134838.49500-1-jankul@alatek.krakow.pl> <20231208134929.49523-5-jankul@alatek.krakow.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231208134929.49523-5-jankul@alatek.krakow.pl> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 11 Dec 2023 02:54:15 -0800 (PST) On 08-12-23, 14:49, Jan Kuliga wrote: > Simplify xdma_xfer_stop(). Stop the dma engine and clear its status > register unconditionally - just do what its name states. This change > also allows to call it without grabbing a lock, which minimizes > the total time spent with a spinlock held. > > Delete the currently processed vd.node from the vc.desc_issued list > prior to passing it to vchan_terminate_vdesc(). In case there's more > than one descriptor pending on vc.desc_issued list, calling > vchan_terminate_desc() results in losing the link between > vc.desc_issued list head and the second descriptor on the list. Doing so > results in resources leakege, as vchan_dma_desc_free_list() won't be > able to properly free memory resources attached to descriptors, > resulting in dma_pool_destroy() failure. > > Don't call vchan_dma_desc_free_list() from within xdma_terminate_all(). > Move all terminated descriptors to the vc.desc_terminated list instead. > This allows to postpone freeing memory resources associated with > descriptors until the call to vchan_synchronize(), which is called from > xdma_synchronize() callback. This is the right way to do it - > xdma_terminate_all() should return as soon as possible, while freeing > resources (that may be time consuming in case of large number of > descriptors) can be done safely later. > > Fixes: 290bb5d2d1e2 > ("dmaengine: xilinx: xdma: Add terminate_all/synchronize callbacks") > > Signed-off-by: Jan Kuliga > --- > drivers/dma/xilinx/xdma.c | 32 ++++++++++++++++---------------- > 1 file changed, 16 insertions(+), 16 deletions(-) > > diff --git a/drivers/dma/xilinx/xdma.c b/drivers/dma/xilinx/xdma.c > index 1bce48e5d86c..521ba2a653b6 100644 > --- a/drivers/dma/xilinx/xdma.c > +++ b/drivers/dma/xilinx/xdma.c > @@ -379,20 +379,20 @@ static int xdma_xfer_start(struct xdma_chan *xchan) > */ > static int xdma_xfer_stop(struct xdma_chan *xchan) > { > - struct virt_dma_desc *vd = vchan_next_desc(&xchan->vchan); > - struct xdma_device *xdev = xchan->xdev_hdl; > int ret; > - > - if (!vd || !xchan->busy) > - return -EINVAL; > + u32 val; > + struct xdma_device *xdev = xchan->xdev_hdl; > > /* clear run stop bit to prevent any further auto-triggering */ > ret = regmap_write(xdev->rmap, xchan->base + XDMA_CHAN_CONTROL_W1C, > - CHAN_CTRL_RUN_STOP); > + CHAN_CTRL_RUN_STOP); Why this change, checkpatch would tell you this is not expected alignment (run with strict) > if (ret) > return ret; > > - xchan->busy = false; > + /* Clear the channel status register */ > + ret = regmap_read(xdev->rmap, xchan->base + XDMA_CHAN_STATUS_RC, &val); > + if (ret) > + return ret; > > return 0; > } > @@ -505,25 +505,25 @@ static void xdma_issue_pending(struct dma_chan *chan) > static int xdma_terminate_all(struct dma_chan *chan) > { > struct xdma_chan *xdma_chan = to_xdma_chan(chan); > - struct xdma_desc *desc = NULL; > struct virt_dma_desc *vd; > unsigned long flags; > LIST_HEAD(head); > > - spin_lock_irqsave(&xdma_chan->vchan.lock, flags); > xdma_xfer_stop(xdma_chan); > > + spin_lock_irqsave(&xdma_chan->vchan.lock, flags); > + > + xdma_chan->busy = false; > vd = vchan_next_desc(&xdma_chan->vchan); > - if (vd) > - desc = to_xdma_desc(vd); > - if (desc) { > - dma_cookie_complete(&desc->vdesc.tx); > - vchan_terminate_vdesc(&desc->vdesc); > + if (vd) { > + list_del(&vd->node); > + dma_cookie_complete(&vd->tx); > + vchan_terminate_vdesc(vd); > } > - > vchan_get_all_descriptors(&xdma_chan->vchan, &head); > + list_splice_tail(&head, &xdma_chan->vchan.desc_terminated); > + > spin_unlock_irqrestore(&xdma_chan->vchan.lock, flags); > - vchan_dma_desc_free_list(&xdma_chan->vchan, &head); > > return 0; > } > -- > 2.34.1 -- ~Vinod