Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2349039rdb; Fri, 8 Dec 2023 05:50:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IEhyYs5pN6MDPgW5aI33nQEauVpiwKulLO62oqP9IvZTbeRVnT45QKKzOgYE4cq6o0cOvj1 X-Received: by 2002:a05:6a00:218f:b0:6cd:f3f4:56b5 with SMTP id h15-20020a056a00218f00b006cdf3f456b5mr39864pfi.23.1702043436989; Fri, 08 Dec 2023 05:50:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702043436; cv=none; d=google.com; s=arc-20160816; b=hKw/LwdtKOjZD1fEgkDadMtXNXcv6XNciRIOQiy6at3270eVJiIuJgNwe2IkhTPeuz JDcV2z6tFzqrSoIeQD8UO9RR3U13FSGJ63/ViMhhX2TnNaxLdsjqUCoMxIzS46zHXaNg U18C62sbwvC1yJa8Umtbi6bVD73Yw2cfFB9xm4oeIijm1juiDx/JA4J4z6Ry/Ypk9xpy dDRXnL3yxyw221/u4Fb6G548o9A2+wgbbk2cVEyFwd7P0q2esGxwgczSYgatSNKU2VZz 5XJqcFNwmaJwRDColH9eTXhHLI+UxsaLijSgXFP5r+Hli+tyxyUUYHwBEupKbgaxLYEj PVPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=TFnmjLQd7yXXz0FUvRgSBTsyp1BXgYpSk1S5kee4UxI=; fh=1pmAyp3xZ8sWUV98t98q7URUgX68KjDmTZriOyZWZ/U=; b=mcUAsQ2jXYD97WCqKgKz/HLwiaVPWuzeK8en5VoR30zmBxCZSBfzS573NMSKn/jG5i HgoKI0rD2fKUl+VWTLz/24eWmNlzztYVpcofbgkPrPvGUE0AZuFQg4ezczn79kb3JecX 9KXpZI26TZRQOYZayvcnThalY/n/6QB6sRzTcaot/Cc2Y1KGiwRjdVsf0mdNXMbb6VRa nyOMr9kCLOBzeqImH3lgV1AeZhaqjVhQGjGBHRSdA0NqToOTQZXXeJAVnbpZJzp02KmL BLSJH4GIAnhszl3xfPuUgSSkWWkr22V6cezfmXIdIBAQJi51Zqsa16n/enKBD5eNiE4e 8n4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@alatek.krakow.pl header.s=99EE5E86-D06A-11EC-BE24-DBCCD0A148D3 header.b=atzC66+l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alatek.krakow.pl Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id z4-20020a656644000000b005c1faa82c06si1522217pgv.470.2023.12.08.05.50.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 05:50:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=fail header.i=@alatek.krakow.pl header.s=99EE5E86-D06A-11EC-BE24-DBCCD0A148D3 header.b=atzC66+l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alatek.krakow.pl Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 3F375887B760; Fri, 8 Dec 2023 05:50:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573856AbjLHNuT (ORCPT + 99 others); Fri, 8 Dec 2023 08:50:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573849AbjLHNuS (ORCPT ); Fri, 8 Dec 2023 08:50:18 -0500 Received: from helios.alatek.com.pl (helios.alatek.com.pl [85.14.123.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E86C0198D; Fri, 8 Dec 2023 05:50:24 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by helios.alatek.com.pl (Postfix) with ESMTP id 062FF2D00F54; Fri, 8 Dec 2023 14:50:23 +0100 (CET) Received: from helios.alatek.com.pl ([127.0.0.1]) by localhost (helios.alatek.com.pl [127.0.0.1]) (amavis, port 10032) with ESMTP id k_HF2D6S06dv; Fri, 8 Dec 2023 14:50:22 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by helios.alatek.com.pl (Postfix) with ESMTP id A8B3E2D00F53; Fri, 8 Dec 2023 14:50:22 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.10.3 helios.alatek.com.pl A8B3E2D00F53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alatek.krakow.pl; s=99EE5E86-D06A-11EC-BE24-DBCCD0A148D3; t=1702043422; bh=TFnmjLQd7yXXz0FUvRgSBTsyp1BXgYpSk1S5kee4UxI=; h=From:To:Date:Message-Id:MIME-Version; b=atzC66+l8DJ2VM7fkAEiMMz09K3Rvni+JoCCnsWiZAan2akwW7A8dFiI6uqR0iGP5 gJ3mwl5weEHyTTTRNCt6F42dAsZrpvdGdlGRejwk/JO99ywhxZ33hgx847A7327YI9 7PTd7BfbtognPxwuKIVhc29MW4wiFD+Ee+AVt04HHkafbtfcuB+coMV8npHRzIi3sY SHdJoWV2m4o7i+J7MjpFNtP6nQusRsdwISaHcVTt40m2vnHmVb43VRbyHsDiUNXT9R 9uO9jT1QvCvrSTbrmZj7pw7xyaYKA4kh5uxiyS9LFSbZEYT78Ch0cB5lMMta7F90dl Rk2heYUiY8E8g== X-Virus-Scanned: amavis at alatek.com.pl Received: from helios.alatek.com.pl ([127.0.0.1]) by localhost (helios.alatek.com.pl [127.0.0.1]) (amavis, port 10026) with ESMTP id gTBO7jEdy2Ip; Fri, 8 Dec 2023 14:50:22 +0100 (CET) Received: from localhost.localdomain (unknown [10.125.125.6]) by helios.alatek.com.pl (Postfix) with ESMTPSA id 27C512D00F4D; Fri, 8 Dec 2023 14:50:22 +0100 (CET) From: Jan Kuliga To: lizhi.hou@amd.com, brian.xu@amd.com, raj.kumar.rampelli@amd.com, vkoul@kernel.org, michal.simek@amd.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, miquel.raynal@bootlin.com Cc: jankul@alatek.krakow.pl Subject: [PATCH v4 4/8] dmaengine: xilinx: xdma: Rework xdma_terminate_all() Date: Fri, 8 Dec 2023 14:49:25 +0100 Message-Id: <20231208134929.49523-5-jankul@alatek.krakow.pl> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231208134838.49500-1-jankul@alatek.krakow.pl> References: <20231208134838.49500-1-jankul@alatek.krakow.pl> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,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 howler.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 (howler.vger.email [0.0.0.0]); Fri, 08 Dec 2023 05:50:34 -0800 (PST) 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 =3D vchan_next_desc(&xchan->vchan); - struct xdma_device *xdev =3D xchan->xdev_hdl; int ret; - - if (!vd || !xchan->busy) - return -EINVAL; + u32 val; + struct xdma_device *xdev =3D xchan->xdev_hdl; /* clear run stop bit to prevent any further auto-triggering */ ret =3D regmap_write(xdev->rmap, xchan->base + XDMA_CHAN_CONTROL_W1C, - CHAN_CTRL_RUN_STOP); + CHAN_CTRL_RUN_STOP); if (ret) return ret; - xchan->busy =3D false; + /* Clear the channel status register */ + ret =3D 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 *cha= n) static int xdma_terminate_all(struct dma_chan *chan) { struct xdma_chan *xdma_chan =3D to_xdma_chan(chan); - struct xdma_desc *desc =3D 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 =3D false; vd =3D vchan_next_desc(&xdma_chan->vchan); - if (vd) - desc =3D 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