From patchwork Thu Nov 19 18:02:21 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4175 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id 07B461C36BF for ; Thu, 19 Nov 2026 19:03:11 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-27870-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-27870-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 9528F18A040 for ; Thu, 19 Nov 2026 18:03:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795111389; b=hlRcT+tMXL88FhoXOjlpLA5wiAy/+xFDFC8j3msVchVlnpR06jhYvmCwawTxIr7mUrRH 9irqhqG4i6xb8971iZOdKZ98SJkHfDgFW8GKj8LentcPprmRKTGE0JctZyg8q8W9pZzel tlOvh8vwfaXix+IUgbqbdjQZx1y6ZwgKtdDXvOYHw7Bmarh0xmKz9HqEjf1fzCNkBGI7o Cy6uzSqkSvJdYoCD4vKxnTs3h9YUjLw3MU3SjQBtwOXOp15xbfwtKxvS9M5QRW37uML7j DcFWlJmm0K8YIjHKwnt2HE8Cj/jIxuYA3weV3pM0E3Ya2A7EvPoPkicc6bp10MAUESw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795111389; h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature: X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State: X-Gm-Gg:X-Received:Received:From:Date:Subject:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=I06+c10KQYGyPd16B/H1g1q5/WZ+PHIJV96gXM/5eoY=; b=JuZBmjKbsIXihmld+/aBV8tEgZtYR238XTbpifzx5ZHBZ7JmfUWdN74pMtpcZsLYoFvS 2IQ2tTEotHCWoxXhH/QCAJ8Q+I0KqG2LC1A5gLLQz4RPbrV2QIrXET8oASmdHVI2d5G4s jOKuwvDLYFYYXLnUVXFRe5GoaTKcUO3E2JYXg/D1825r7IzqtyWZ5cLI63ryhsModJM8f 2v4/W+stU4vxTcjz6x0tBCJN7AKTr4JpSp+N02Hk9XZdVB3YesQSHbZRJOhpZ1oZS/W4o EjhJVOehMmHgGQD5caLsKaMfigY8rjWx8THfjiBa7hWfIG1/NkTC8Qqio5BzF5fzs7Q== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="HQTsml4/"; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 43B4B606A338; Thu, 19 Nov 2026 18:03:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=HQTsml4/ X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795111389; b=Vyvt8nmhHf/bnywpKyNn9CvfqL+LBOc/DrWT+DB4MHLqkbmEqXqdVNzuW/I75BieWd6R uOLTjiPUHjbPFZqKenCFc1wFus8NmB+K7/8bdqqXziGoLj3gpLnVITyWDRXvY+RNiTn0a hatGlz/bU2r07d9GHlNyojkXUKRHwRS9uG1fTJUJCkN6D6bnsxhJEy7uEMTb9A2a3Nd9n 1YrIbvkfrDbLVN3BCyA47dSzn/Ntm1/0cszYejGTkk9M+7iRoYYfzJouUBG2MnslVRHHu 3Zrq/6jYcb/EqHzoPl2x5r4WtgL7ZDW1+hOUnK5K2saFS68iZAu3gS866ws5yZBXtpw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795111389; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=I06+c10KQYGyPd16B/H1g1q5/WZ+PHIJV96gXM/5eoY=; b=lBNYxiqpzK/eMPbGZxZM8bc9/h/39UvwQXYVbXDft9GDS17489TFUE4lkgHGQFIECXcq RFGMnPQLXkQIgSSp+zNmOz30ouf1j+3ATe+OyuiysBM4AVgLnGdtDi++gBCMMgowcYYZ2 o/0s85MzOQ3b4skQ9ERsPZMuKIBt9FcKCRG1U1L/HtIM8ZMA17RWjGQgnndhIzgCbPVXa rd9ZnnHsfkv++u50uUhOHmTk0YQX7QNjsr27HfJ0Ve66cs1ile8kti+JgQcU/FB7Eob36 LBNd/xtpV6NWwJ4tp7tTM34mGveGUA9lFMSEGqiIFLRDNLe41YtneNFo/HFk9IKTakg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="HQTsml4/"; arc=none smtp.remote-ip=209.85.161.43 Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCEF6606A334 for ; Thu, 19 Nov 2026 18:03:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CCEF6606A334 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-71aed54d4c5so14426eaf.0 for ; Thu, 19 Nov 2026 10:03:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795111388; x=1795716188; darn=lists.linux.dev; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=I06+c10KQYGyPd16B/H1g1q5/WZ+PHIJV96gXM/5eoY=; b=HQTsml4/H/RJdBGsa9M8rDPOzA3KA+mSl3laQbD2ordKQux2e4v+nLQ0InF3ZwQQaA 43TZSPSA5OndHR8/0T7e7BkgTKUEfNew9Gp7mdCUI9WnmRtIJRYyhcmlpT6Tg4lFX4Wr rhPRc+IIxd2DBe+HLstDLDLqRIw6NSVRQSO8nxCb4FiaqGrycCOzG7oA1TNxIFkEMmPG AQTyyvXhzVi/0ZQS5lj9B3iqldwMjp3FSmzOsDDnI7mkz48ULRvNY1uFzUUnNsPVQpDN uULBjW/VP0PPEaA4bT5dHUrELbB1KQygRuA0meucyk8DTkcrcpZyOP4RifSb7q9gpcIq 5ExA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795111388; x=1795716188; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=I06+c10KQYGyPd16B/H1g1q5/WZ+PHIJV96gXM/5eoY=; b=tvcQd3rXQsGAXtsyPr1i6lKaAMJs2WdvT1olO1VZvroJHwBc6qcDAJvKhbvNPVmyzF N7q0lHSzZRF2Rn8m3DcG6jmbyV8UZ4FZVvZIBuTBODej/KpGNMf22RJxWbluRui60rC1 OhjY/6y4vSNV26rV6L0EGxJjZqxOxhK+5m0x/4XI9cxounHNiDVp+hZWF+njWs7sJm52 Yl/8vR5QFyuQphEscudDlKLiyWHgmSm3oJah3xpI+iiLEEi4oTb5PC/urBQeBPVS1ciY B9zRHCEsBTNrchizJ2Dec/s0D7ryeWrGEzBySRegDQso28NMjNb/PpZQI4xV175s2DZo YHEQ== X-Forwarded-Encrypted: i=1; AL+hErHHw4ZEDSBZMb6vmU1g7edTyLJMwBNQFbFkijLseBxCPuX5GGnP5u9SUeulIpCGTF6le6StwhfZloINHg==@lists.linux.dev X-Gm-Message-State: APuU4Z8FWkioVDCz4sB9uiGoi7KDvZTnsMeQO/6lyjpaIsJCsPRw6BEe PrunSKo5QUL6U2zbVYVe4cO191WKJHAjS7mCUGiH2XWCTSw6pPqtZHvM X-Gm-Gg: AYBFou23d0p85Hfqyb9fpZ/b5q0ptKSwoxzvu/RxQRy4mBLlzZ9X+ioFIg6RYif6GzQ Dv5GFMx/ts4ILhpfDcxUEqDgMIbj2EwTf7n4OSy/b/yb/m3BD3zKLyTYtzz6CCwzYMS8nWoXV+G 2bfJ4US2uppiIOKzisuqDU4D7fXRWrwDKCSJil3rWrzm7KCPqHyEb9NBhV4k0e2DJvqSd18r4GC MS3sBkGIDAbQOkeFj/qdxLx+7m6Zx3PYP5eTdZD/rvtJrO7aI2GcWr9RxFhF5zLjTbFxuc+TH1M X7c9K7ENmxNhpoaFOJ2f7BdwR6qkKkXPzAqLRnNDk5zfYq2z9PM8lRYzkNo2QU4o6SOODUZY1IW idIe6sZGGUNSrJ3xYJmrm+24yuMQzOcMaXYRXiI6z4CUaSQdmjtGQSQwjXTXJSDPwz0bzU6V3ho oLoTMZy/titQ/MfcaEAZ+l7EoZ6okCl1KRCDLZRiiK+BajuExpmZTAx/X3AUkilt7xZ/Fou9qX3 0NiIU5ZnvEMf8sGexQxS795kPMqs8RZjxXZUebYe8u38Rt4TiAAmG0hHMr7FccY1Si4bd9s6K9R QQathUBjK80ALdDGFLl1d8qAw6SowmJaDHQKtS6Hza9JRE0nZSijmWWkI3xMMbWr4KPuijiS5U0 vtelxWVgXL9VEhff1GWEaJPz7j/rNgo4cgR84YztjqExcgerT0+EISvjTbSIXoGCklgQ355t3QJ E2XsNQ60WOl6Sbre8tBQ65zPHyLmkLaiv450wtofXdiYzpeW+PF1Cf X-Received: by 2002:a05:6820:340a:10b0:716:db9f:682c with SMTP id 006d021491bc7-71b3960e47cmr234297eaf.69.1795111387559; Thu, 19 Nov 2026 10:03:07 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-71b3806ef20sm448478eaf.7.2026.11.19.10.03.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2026 10:03:07 -0800 (PST) From: James Hilliard Date: Thu, 19 Nov 2026 11:02:21 -0700 Subject: [PATCH v3 1/3] dmaengine: virt-dma: share deferred descriptor retirement X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Message-Id: <20261119-submit-sun4i-dma-callback-lifetime-v1-v3-1-3935aef58db9@gmail.com> References: <20261119-submit-sun4i-dma-callback-lifetime-v1-v3-0-3935aef58db9@gmail.com> In-Reply-To: <20261119-submit-sun4i-dma-callback-lifetime-v1-v3-0-3935aef58db9@gmail.com> To: Vinod Koul , Frank Li , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Hans de Goede , =?utf-8?q?Emilio_L=C3=B3pez?= , Maxime Ripard Cc: dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, James Hilliard X-Mailer: b4 0.17-dev X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [4.31 / 15.00]; RBL_SENDERSCORE(2.00)[172.234.253.10:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:helo,sea.lore.kernel.org:rdns]; FROM_HAS_DN(0.00)[]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; TAGGED_RCPT(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; RCPT_COUNT_TWELVE(0.00)[13]; FREEMAIL_CC(0.00)[vger.kernel.org,lists.infradead.org,lists.linux.dev,gmail.com]; RCVD_COUNT_FIVE(0.00)[6]; TAGGED_FROM(0.00)[bounces-27870-noreply=patchwork.local]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TO_DN_SOME(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[209.85.161.43:received,100.77.114.92:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.234.253.10:from]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10]; RECEIVED_SPAMHAUS_PBL(0.00)[174.29.1.49:received]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_TO(0.00)[kernel.org,gmail.com,sholland.org,elopez.com.ar]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 07B461C36BF X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX A cyclic callback can retain its descriptor after the tasklet drops the virtual-channel lock. Collecting and freeing descriptors during atomic termination does not wait for that callback, and clearing vc->cyclic alone only cancels a callback which has not started. Provide vchan_terminate_all() to clear the pending cyclic callback and move submitted, issued and completed descriptors to desc_terminated. A cyclic descriptor moved to the completed list by an error path is still retained; completed descriptors already detached by the tasklet remain its responsibility. Leave prepared descriptors on desc_allocated: the client still owns them and may submit them after terminating earlier work. Freeing channel resources, unlike termination, still releases these descriptors. vchan_synchronize() drains callbacks before freeing or recycling retired descriptors. Repeated termination leaves them on the terminated list. Signed-off-by: James Hilliard --- drivers/dma/virt-dma.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/dma/virt-dma.h b/drivers/dma/virt-dma.h index abf2ae737c30..f753c6b62d6b 100644 --- a/drivers/dma/virt-dma.h +++ b/drivers/dma/virt-dma.h @@ -199,6 +199,25 @@ static inline void vchan_get_all_descriptors(struct virt_dma_chan *vc, list_splice_tail_init(&vc->desc_terminated, head); } +/** + * vchan_terminate_all - retire descriptors until callbacks have drained + * @vc: virtual channel to terminate + * + * The caller must hold vc.lock and prevent further callback publication. + * Submitted, issued and completed descriptors stay on desc_terminated until + * vchan_synchronize() drains callbacks. Prepared descriptors remain available + * for submission. The completion tasklet owns descriptors it already detached. + */ +static inline void vchan_terminate_all(struct virt_dma_chan *vc) +{ + lockdep_assert_held(&vc->lock); + + vc->cyclic = NULL; + list_splice_tail_init(&vc->desc_submitted, &vc->desc_terminated); + list_splice_tail_init(&vc->desc_issued, &vc->desc_terminated); + list_splice_tail_init(&vc->desc_completed, &vc->desc_terminated); +} + static inline void vchan_free_chan_resources(struct virt_dma_chan *vc) { struct virt_dma_desc *vd; @@ -232,7 +251,7 @@ static inline const char *vchan_chan_name(struct virt_dma_chan *vc) * Makes sure that all scheduled or active callbacks have finished running. For * proper operation the caller has to ensure that no new callbacks are scheduled * after the invocation of this function started. - * Free up the terminated cyclic descriptor to prevent memory leakage. + * Free or recycle terminated descriptors after their callbacks have drained. */ static inline void vchan_synchronize(struct virt_dma_chan *vc) { From patchwork Thu Nov 19 18:02:22 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4176 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id 74DA11C4EB9 for ; Thu, 19 Nov 2026 19:03:17 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-27871-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-27871-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 05C4518A83E for ; Thu, 19 Nov 2026 18:03:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795111391; b=zzdcusLHjE75cGXRN4lKdKQrh9nXDF1K2qGj6v2yf8D8Cu4u0cy0mn/0nFGvJKqGMERp 78ObEebrOTytlioCw2Ipd+544oT0YOzJM7hMJEqjtSgJMNSh64WvBJWz8K0MdDnW3LseK PjKKN6EHa6daQTGCaJCiBsdEnm/ZAJvXum8SsKB5FlRL0zTrH51pvG9yQEGhcK3dzPvB2 SpZQ5KOYG+wvVF0X2I5RR6kxLOInrAvP0SoTNQRhxQs/D57PdA9olrlPZ2oY9mR2701Az 5mW+2aEchpBuGttMWHXPi1V7sis9aOLo+qrhZt8RI2shxVjFyH0i+swEXQDU+GzAjDA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795111391; h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature: X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State: X-Gm-Gg:X-Received:Received:From:Date:Subject:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=xgSmoxBrqnKlDHDPXkpFmY/x2C8GWXkCurAJnyoUmxM=; b=ji5fLy9WcVZcBvYxnQUqCMnjUiKUWCLZjGm3ZRu6Oj0gDFFr6xUEg3o5CyIMaOd46ptU Gmuq/SsKVggrGCoVJV67esqmqZZdYwK516c0QDzGPYs7BOfTEETgL1ROrQpydtLXHb7uv rhs7OcDOpVTEw8L8BNvnr2k/4JDv8LFvrIPz0ftChghM4dJUCekouLG9yAlskcB1uSOyn CqKnEbbw/uNlbmQRsiM6CLqS501dsxQoAZwGnWzBt84fCsIhNZBtdMQkp7Cx+4lkNFNhu uDS84hRjyPi8vikWOomOzqucyP+eSW002P+OneeX3oSUhEU9fju46aMUFQiwNEFULCQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="bs/LuToK"; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4EB2C606A33D; Thu, 19 Nov 2026 18:03:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=bs/LuToK X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795111391; b=zk59nnCZ+Fzv9OF0HxP2WcpLeieNK4pomDkw9hHDQ3Dlfz4WXuX8l2+dIwNuB1WN2I5X HxlpSlr6ySqboxj7emEC7ATME8ZL2sh/Tyw+NPZYSPLjMK8ZCQLeHJTM5510mecko0nvA rRJqqOBKzB+TMSX78RsSn7Dqp5Hnkdjwh9jHdU8x8BpIcodVOmBzMDJCGB1B7P0p9K2uy mZliJKiMXSWxqXK9+SGTXridf2tZ/OvSuVqx6+FO3O/RjQNyqd70npOhJ14Ud0bXmDBvj Jq55x1fshbyCzBcpTB+/rVXnAImwfR37Rn7kS0x1Ci7zGOlvGvZPQm3pRAdcAPxeFDw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795111391; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=xgSmoxBrqnKlDHDPXkpFmY/x2C8GWXkCurAJnyoUmxM=; b=Qp2zLq+1TTpZg8FXAgPyrMXm6UKHCyEdozUpOcL4Rm3zmwDXaGSnyko1ln1KqQ/vtB5R GF6LU+DS4RsESwywQ+PpaQVb52KSrlcyysX7yUVn6pAK+uuF/VfcZiG1dud9Yz3nJBwCp DK/UIHwust6eY4ftm97f6mlnCrAjDGgxE9oqw5qapMijIyBlAwYAaODN42hDIDalEzp3j PgJE8wpF9mT62YJHhWe29YIePeYrS4pRND0ZhdVq++r7NEjcC54DZ3As1WGpMRKba9I96 bUAvQ/ZzUOIXI7VW2lOtKW48fgn3XcD+jkHZ64CmMclN9jNFzsuPbJUquic366V3VCw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="bs/LuToK"; arc=none smtp.remote-ip=209.85.161.45 Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E152606A338 for ; Thu, 19 Nov 2026 18:03:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3E152606A338 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oo1-f45.google.com with SMTP id 006d021491bc7-71acdd32a53so1000584eaf.3 for ; Thu, 19 Nov 2026 10:03:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795111389; x=1795716189; darn=lists.linux.dev; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=xgSmoxBrqnKlDHDPXkpFmY/x2C8GWXkCurAJnyoUmxM=; b=bs/LuToKNc+egLbAT2zhdeLzQlXTjo7qH53LTiOjwmAGg6O9ysoRUSVpyCSoL7oslI /OUKJN+h9Mz0pBk5NKf7wbeBJwlbsmYYUSXPCvGcw8BKFmp1DYAgU6ewqVtxrVZJ0zrc s1wuOHdQoXXqhFSDafsysQuWLFNkmTujOJosiLId66/lcE9ue5AB0Kkqb7FouRLgMxc5 DD3cM7RbW+koXE1bMrNtdeotVSgMR7hYGMN/h2pmncqhNjua6tlwinARljvaqK0Fsl/8 PSomIWHPAZo7tGTpaCturmNMQvYJarwGlS1Wi/rJ5k8ZuEjW2CeaYuRfOqLqbp8TWOW4 2KcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795111389; x=1795716189; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=xgSmoxBrqnKlDHDPXkpFmY/x2C8GWXkCurAJnyoUmxM=; b=q37wREf2zhKgQKOawUQLIN8iYsFKjCcKCKh7lGltCYVDfMFbvYXrZcrhX+DuCLmSYC TRgyHYS6I/t0jgcMnyn/dOaWK3U2YnO0RcvUG5NPBP4N/9Lef/kMOo3oANq0gp2PV3iw VE6AkOysS1Ql0WRXpCQ+b1slLVgFKXwZbuJ+9rLNNwtQQygHysW/3qgLpAsTb9j0HDld /e649GvrMK3t5fLRZcVrQ9ngHyf70qCvvyaH7Iz3G6fH6qZAL0/4lEZMKEyKUwvKF74v dfIpjMcQsPLreya8k02qJuXPBD89LPCbLG4uI+2cF23ULnxCchuje7RoVzIiGDj3ZpCP qU6Q== X-Forwarded-Encrypted: i=1; AL+hErERTlt+Hjk04anQq/XhspTKbclAUuN//Xc24EhlUJYVY/3oit/wc0FIrgeihwKSCt4htM8F0Ocl3Z4MPw==@lists.linux.dev X-Gm-Message-State: APuU4Z9bQ+3WoelD3GvznWFShfRsEWHyGlRRyvPdtM2adSNc2af6KJr8 hdBgDaVY8/PqZZqEYl8hU7VYSkZBuFpaV4bv/KYkvZGSkGhMUOV7fbz7 X-Gm-Gg: AYBFou0LtdTIcPFRfTI0RGB2wXuYbvSVq11MbMEksFc+TVi1ML//n6Ew5T4Mb7VEBY+ +X9j+CPUy+1geoCOW8OhM2S3oO4t62242QpkggXYNkiaWTm6TTf7u2+MuVTdAeyjS5mqtm090EZ l4AQafT9sqGA7VBkbjp+aeRsvQbLzGoKGpcjj1aAd6rOFSDjm7J+ZZ3Cc1k/OaG0efkQ0v+Zjmo xBV4M/MnxdEFetyKKgeTK0WByNukoJRPx0xKsTYnPSYL/5JxyxXoPAuKL9Xv3Ko7JKqZOU2srUt WXsJ3VBePfrcgxmE91tKrJA3T/Bw477AFjw3+qFytwY0hcCBXjMgNZfTe74pmdKeqZrz/f13Jqx 1dds7AO2d4dEuUDLf1A2bLhrfQrYTch6oWfHKlw8S3RMStDjceSByd4w8RVPiHR/T1SZNHHq0MH DBKOLKucuLuWk9qHk5LkIKYUuzL23yxojrDZ1/bQs+qCR6c1grwz6sTECuJUM+oA4BzSOg3nu/q 50TZL4cbCKTiHTu7VzvKl8sTQN7Gcmw4Yalb8XbJt7/BrTXP+47YbDxSZbNKgvYdlpkpEo0DFwV 2pKmx650kiLLXlxKnLES+zTPKp9w4UO7EL0HPN61Hb6PYrlMr7GneGet44VA+5tHjb7ckHQ8yh4 CTDtPZ+KnmCU/VlJMC/tMlr3uc9l4QtxVNbQHPnsnyRd6P00+ZGkExEQXdz32Q/kp8+ee6JC+EM AUfQTTVXTsNah3kxNqEZU4W7sNTdWbGv7RgNkHx0N4UP1CETYMX+rk X-Received: by 2002:a05:6820:614:b0:71a:f794:49c6 with SMTP id 006d021491bc7-71b39566d0cmr341259eaf.69.1795111388904; Thu, 19 Nov 2026 10:03:08 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-71b3806ef20sm448478eaf.7.2026.11.19.10.03.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2026 10:03:08 -0800 (PST) From: James Hilliard Date: Thu, 19 Nov 2026 11:02:22 -0700 Subject: [PATCH v3 2/3] dmaengine: sun4i: retain cyclic descriptors until callbacks drain X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Message-Id: <20261119-submit-sun4i-dma-callback-lifetime-v1-v3-2-3935aef58db9@gmail.com> References: <20261119-submit-sun4i-dma-callback-lifetime-v1-v3-0-3935aef58db9@gmail.com> In-Reply-To: <20261119-submit-sun4i-dma-callback-lifetime-v1-v3-0-3935aef58db9@gmail.com> To: Vinod Koul , Frank Li , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Hans de Goede , =?utf-8?q?Emilio_L=C3=B3pez?= , Maxime Ripard Cc: dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, James Hilliard X-Mailer: b4 0.17-dev X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [4.31 / 15.00]; RBL_SENDERSCORE(2.00)[172.234.253.10:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; BAD_REP_POLICIES(0.10)[]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; TAGGED_RCPT(0.00)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_TWELVE(0.00)[13]; FREEMAIL_CC(0.00)[vger.kernel.org,lists.infradead.org,lists.linux.dev,gmail.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:helo,sea.lore.kernel.org:rdns]; FORGED_SENDER_MAILLIST(0.00)[]; FROM_HAS_DN(0.00)[]; TAGGED_FROM(0.00)[bounces-27871-noreply=patchwork.local]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10]; TO_DN_SOME(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[209.85.161.45:received,100.77.114.92:received]; RCVD_COUNT_FIVE(0.00)[6]; FREEMAIL_TO(0.00)[kernel.org,gmail.com,sholland.org,elopez.com.ar]; MIME_TRACE(0.00)[0:+]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; RECEIVED_SPAMHAUS_PBL(0.00)[174.29.1.49:received]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.234.253.10:from] X-Rspamd-Queue-Id: 74DA11C4EB9 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX A cyclic IRQ queues a virt-dma tasklet with a pointer to the active descriptor. sun4i_dma_terminate_all() frees it without clearing the queued cyclic callback or waiting for one which has already started. The tasklet can subsequently access the freed descriptor. There is no device_synchronize callback to let clients drain these callbacks before releasing their own resources either. Serialize both half-transfer and end-transfer IRQ handling with termination under the virtual-channel lock. Recheck the physical-channel association after acquiring that lock so an IRQ which looked up the channel before termination cannot use its detached transfer state. Use vchan_terminate_all() to retire descriptors until synchronization. This clears any pending cyclic callback. Retain them until a new synchronize callback has waited for the IRQ handler and drained the tasklet. Drain callbacks before freeing channel resources as well. Termination itself remains usable from atomic context and from a completion callback. The shared helper retains all collected descriptors. An in-flight non-cyclic callback still owns its descriptor on the tasklet's private list and retires it when the callback returns. Fixes: b096c1377d1e ("dmaengine: sun4i: Add support for the DMA engine on sun[457]i SoCs") Signed-off-by: James Hilliard --- drivers/dma/sun4i-dma.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/drivers/dma/sun4i-dma.c b/drivers/dma/sun4i-dma.c index 225e4a53502b..b0c91dab62f0 100644 --- a/drivers/dma/sun4i-dma.c +++ b/drivers/dma/sun4i-dma.c @@ -293,10 +293,20 @@ static int convert_buswidth(enum dma_slave_buswidth addr_width) return (addr_width >> 1); } +static void sun4i_dma_synchronize(struct dma_chan *chan) +{ + struct sun4i_dma_dev *priv = to_sun4i_dma_dev(chan->device); + struct sun4i_dma_vchan *vchan = to_sun4i_dma_vchan(chan); + + synchronize_irq(priv->irq); + vchan_synchronize(&vchan->vc); +} + static void sun4i_dma_free_chan_resources(struct dma_chan *chan) { struct sun4i_dma_vchan *vchan = to_sun4i_dma_vchan(chan); + sun4i_dma_synchronize(chan); vchan_free_chan_resources(&vchan->vc); } @@ -322,7 +332,7 @@ static struct sun4i_dma_pchan *find_and_use_pchan(struct sun4i_dma_dev *priv, spin_lock_irqsave(&priv->lock, flags); for_each_clear_bit_from(i, priv->pchans_used, max) { pchan = &pchans[i]; - pchan->vchan = vchan; + WRITE_ONCE(pchan->vchan, vchan); set_bit(i, priv->pchans_used); break; } @@ -339,7 +349,7 @@ static void release_pchan(struct sun4i_dma_dev *priv, spin_lock_irqsave(&priv->lock, flags); - pchan->vchan = NULL; + WRITE_ONCE(pchan->vchan, NULL); clear_bit(nr, priv->pchans_used); spin_unlock_irqrestore(&priv->lock, flags); @@ -970,13 +980,11 @@ static int sun4i_dma_terminate_all(struct dma_chan *chan) { struct sun4i_dma_dev *priv = to_sun4i_dma_dev(chan->device); struct sun4i_dma_vchan *vchan = to_sun4i_dma_vchan(chan); - struct sun4i_dma_pchan *pchan = vchan->pchan; - LIST_HEAD(head); + struct sun4i_dma_pchan *pchan; unsigned long flags; spin_lock_irqsave(&vchan->vc.lock, flags); - vchan_get_all_descriptors(&vchan->vc, &head); - spin_unlock_irqrestore(&vchan->vc.lock, flags); + pchan = vchan->pchan; /* * Clearing the configuration register will halt the pchan. Interrupts @@ -991,13 +999,14 @@ static int sun4i_dma_terminate_all(struct dma_chan *chan) release_pchan(priv, pchan); } - spin_lock_irqsave(&vchan->vc.lock, flags); /* Clear these so the vchan is usable again */ vchan->processing = NULL; vchan->pchan = NULL; - spin_unlock_irqrestore(&vchan->vc.lock, flags); + vchan->contract = NULL; - vchan_dma_desc_free_list(&vchan->vc, &head); + /* A tasklet may already be using the active cyclic descriptor. */ + vchan_terminate_all(&vchan->vc); + spin_unlock_irqrestore(&vchan->vc.lock, flags); return 0; } @@ -1128,9 +1137,15 @@ static irqreturn_t sun4i_dma_interrupt(int irq, void *dev_id) for_each_set_bit(bit, &pendirq, 32) { pchan = &pchans[bit >> 1]; - vchan = pchan->vchan; + vchan = READ_ONCE(pchan->vchan); if (!vchan) /* a terminated channel may still interrupt */ continue; + + spin_lock(&vchan->vc.lock); + if (vchan->pchan != pchan || !vchan->processing) { + spin_unlock(&vchan->vc.lock); + continue; + } contract = vchan->contract; /* @@ -1138,8 +1153,6 @@ static irqreturn_t sun4i_dma_interrupt(int irq, void *dev_id) * interrupt (odd bit) */ if (bit & 1) { - spin_lock(&vchan->vc.lock); - /* * Move the promise into the completed list now that * we're done with it @@ -1173,8 +1186,6 @@ static irqreturn_t sun4i_dma_interrupt(int irq, void *dev_id) disableirqs |= BIT(bit); release_pchan(priv, pchan); } - - spin_unlock(&vchan->vc.lock); } else { /* Half done interrupt */ if (contract->is_cyclic) @@ -1182,6 +1193,7 @@ static irqreturn_t sun4i_dma_interrupt(int irq, void *dev_id) else disableirqs |= BIT(bit); } + spin_unlock(&vchan->vc.lock); } /* Disable the IRQs for events we handled */ @@ -1276,6 +1288,7 @@ static int sun4i_dma_probe(struct platform_device *pdev) priv->slave.device_prep_dma_cyclic = sun4i_dma_prep_dma_cyclic; priv->slave.device_config = sun4i_dma_config; priv->slave.device_terminate_all = sun4i_dma_terminate_all; + priv->slave.device_synchronize = sun4i_dma_synchronize; priv->slave.copy_align = 2; priv->slave.src_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | From patchwork Thu Nov 19 18:02:23 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4177 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id 8D5381C0349 for ; Thu, 19 Nov 2026 19:03:19 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-27872-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-27872-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id B400618AB1F for ; Thu, 19 Nov 2026 18:03:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795111392; b=tX2E0WQrGXr8BbfYWkAJAOh43RcQt+w2WwDsIWGHvyRg+IBD+aZI4dnu49aBSfUWY9iy EzhDZBJK6Cixzhj+Hp4kOkMPg+19LQTRMMNPkwRIuB/TQSZmmsXtkvwYbDV+NsSpirrTG DG+g+FyYLC5L+5CvCGRjdPhahz7FaD5f63B80n2d7JwUu43xbE2REak01JfOqULdLLqGm 9mqfU2U1J58QkblXWr0BU8FH5yB13cjGzoiuS5ItzZFws823Nrr8CHZ+VBLxwxxSl6VTZ fYp1cRpcPLg2iEYQxtAeUG1MK5AyLWl6ODoui1NzZa8yR/u8OQQmRUp7aUrryNBWDqQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795111392; h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature: X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State: X-Gm-Gg:X-Received:Received:From:Date:Subject:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=dfbuM0pmbxDgRGHnvK9GVp1KbnVrBOX0xw08dSvpRRw=; b=IpohoKeiTUD5OVKZ7yCeuqq9iMXUSVF25hOXH5KPxQ5qtMY1eHzn518Em4NHcetaJsmo +clQ23wVxuE0gozeb/mUSIplNyeaVWcNkDf1F97SQb4wQOK4VzAi9cFEzKovXL7Yzpj+k a2faMdE8FW7GLsT4fOgFEi8ktivbAe3YyW+lXDwS7hVH+38DjFFQBTYEvsq4Q4SAdJRKp H2lYc0Ss1PYvKr5Vh3UI0ZVTpmdxpUQp2GL8ubBYFCrvna7gm6jKRYyCNQsgadNvGH86g Ik23t5q9xFv8EdapUj7pMlVFdkcsUBcwYwUhBccpSHr4WqFt6HQmSdE08PJ6Uj3tA7g== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=M1jjQZA7; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3DC6760A2605; Thu, 19 Nov 2026 18:03:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=M1jjQZA7 X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795111392; b=rrnf8Ue8lSAOJk0YPOAjpo3yiQRSU67ExYIZMQHNjF7FX+xBUgrnxD6g4wyZZTQ3t/MA sRz4z8wL00RPYSI4phRGmHAT45JelB9Rm3Bs7m95ZVFyZ7oI8h2fYCYPqDuiyyP/k67Mt J2Q/Sfq6eqofk7FA51mZYhp4veigHKgN1FoIbFpbzNcXS4FT4la6KzF3HW5+BK01bW/14 naHNADdlZcFw6KBGWtkAdUDfJV/MhOrnPGRP9zowkWq3h/bKLKlA/QWbIY7WUn4YucBxS q/gAnPW98gD9WnR9Wmz9KRqEEIpCxAAk/dzW5TdVmNQTMrsqOJckbfjRWcea2NF/Fkw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795111392; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=dfbuM0pmbxDgRGHnvK9GVp1KbnVrBOX0xw08dSvpRRw=; b=2+XqJQMYX7PSFVRKTRk9+jB2hm0cmF3Aa9qYXcv4QqQehrAmSO+7d6AOty0X1P5gVgWs urBr9MOZBJikihx5RprTz0Ph18zH2pAjfOuTV7Ena3NsiL0OTQcZ09FWX+WIg6rUrb3DK JqD7fInL7PeJ5L70V7yohO9wknAUjMg592iKQpYvYelO4FUmKUEfh3u4kFygPiAot4SnL WQotHIBcNcNTh+Be6Z+XVjYxUduAyfYbLMlAEL70XnQ705nPl58Hcx6OBmYy7cyaT8ukd VdHZwUArhs1YIiRS8otoz7oes6y90uXUpa/Sf8wfmad3jPq0wlGCkKdh5ZUOpLkqJZg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=M1jjQZA7; arc=none smtp.remote-ip=209.85.161.47 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCB69606A33C for ; Thu, 19 Nov 2026 18:03:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CCB69606A33C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-716c0217635so1359504eaf.0 for ; Thu, 19 Nov 2026 10:03:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795111391; x=1795716191; darn=lists.linux.dev; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=dfbuM0pmbxDgRGHnvK9GVp1KbnVrBOX0xw08dSvpRRw=; b=M1jjQZA786Mjs4vf1CPYlMmdt0oecB+eHUHN4UbvkWhRo6vqBTNIq82vaJz5XwFgGg p2IQye3L998S7DEVuD8/ifaziKHrn4mR+6/XU9HK8tEa6EDpBshsomZi/fCOtSFcBX79 6Q67C34NwxgcAn0ece8pNSBZK4HIevERIKuhYdeUAxKpLoA94EpSZ4TNr5dymhCP1YD2 LYTEqXMSHp95jD1kWuttcc5KDKQksifdDGcQEm12fV3gFxopPMX37Hpcia3AjnRlBO6Z sf+ghWCGeWGthknqpHrQkKvfWN4RUn3AtwIIQRsL9Y1Em1I5nk2e6hQEY3WCX4FjDoW9 +xMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795111391; x=1795716191; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=dfbuM0pmbxDgRGHnvK9GVp1KbnVrBOX0xw08dSvpRRw=; b=qEok0W2c5haheQHJm5lihDvFosxiElQrYSa8i7fMv9oJdOQ16LktHteEOPMorN7dZj vrj9P4jCZDj9/dJcyXV0UZ3/U4DNEoqDoiNadQiBdMFyDePe/eOrlzHC79wzE2VwVxJj GDlkbHN3CYfrM4MUxg+q0QoT6yMm035ZID+HxyFnsV3LVB2JXzxxgI4WeE245LjAeV6K 10JtJQ4E+bTwPUO9Hf3sSXYGt+bmplPlY4J+/4IV4Ded11ui7ZXNcXRidmJ/QTLMoQFg lBXdiDR6SGdFXqfi+V06I2q22cjllWAZ1bPy0sVlWNkazmkF7ai/KtFVHnqg8IsUumpD /iUg== X-Forwarded-Encrypted: i=1; AL+hErEDF73veNaWF5FliTuRiJWup8yXHT9zM/IhQTwJPHDZwxoXIjaicyJrHTkixGXxOipPIaq24nJxlPPgIA==@lists.linux.dev X-Gm-Message-State: APuU4Z+DNVgwa58txagb/F7hIyhT1jkRO5lz5GDeSAqrqIPQo1ZQTMm6 0vV2/nxzx344zIadV/HFocSCt51yLQRX54p97fniOQGM7Lu8+HG32Igh475VyuJe X-Gm-Gg: AYBFou23wW6UmWyvAESlQe3rTq70a2EmDMXVNaGDqmxFgR3VKFLsWoE7YSiLn2ayh14 0cNs/ewakW5tINFC3SxvlGpcCt/nj8EMV+uFxQjVlrphrVfQCPjgFQBpKzjhYwHEi1MDUcz0S5l bRdP5nIYv8lM0i11mc6fwhMOvvWMrYm7Jvg9g+zdF4+NW5fKhNHhGyZtC2cFAlqWXaY6h2PYyFK I7qKnapinpE+JJmZIwVsdapzd9A7jFJwXuP5A8XJLcRb+9NiyM+Wzh7Qy9CBwuH2li+iK9HamJw Sf9aMhMyZWRW7IdADxHVCO1rOfQ7dmoTGRtzQ6Oi3lYqIj5Cv/tM8zLwvu/i6fvs1lWGYjjKYKK lIyl7xRMptnOCljC7wMKo/Vhqd0lzGBr9ey2pvrfHspdIXXccHXOwemVYI3qSsLv/3vGonzdOn9 uaH+Lf1L23wEFpwk/TwDSzqhQg/y5Vk8cjztLWAm5fy6wTE4pJUemoOgmsbFwqY0vNkyXsuaBBd rKYFTzp5HL/lUVwo6jQTPsGEj0JxK/QYG5xi5ahhawb/y1cmp3gaHoqAhUyLMbofAw19wPd6gZa hJmgME8l1betlDQAq7hd1bdWeFRc7y9J/tnR8HU2GUUgzMl8YORL/mIcl+1GNUBx9BZqeklvLCI Nye8LcgFxn9L1SnBdR/wwm3C4EM2J6ObjuvFvdd+gIaXyJN8fd93fMLzemMl1V7lR7VBcqV5dCe US31HCIYh+Am6tmUCVfxAKrGMFGUNkJiHzvtG1XfeCxEG1Qq+VAABuyw== X-Received: by 2002:a05:6820:248a:b0:71a:f035:823e with SMTP id 006d021491bc7-71b3945d5demr218426eaf.7.1795111390594; Thu, 19 Nov 2026 10:03:10 -0800 (PST) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-71b3806ef20sm448478eaf.7.2026.11.19.10.03.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2026 10:03:09 -0800 (PST) From: James Hilliard Date: Thu, 19 Nov 2026 11:02:23 -0700 Subject: [PATCH v3 3/3] dmaengine: sun4i: retire interrupt state before channel reuse X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Message-Id: <20261119-submit-sun4i-dma-callback-lifetime-v1-v3-3-3935aef58db9@gmail.com> References: <20261119-submit-sun4i-dma-callback-lifetime-v1-v3-0-3935aef58db9@gmail.com> In-Reply-To: <20261119-submit-sun4i-dma-callback-lifetime-v1-v3-0-3935aef58db9@gmail.com> To: Vinod Koul , Frank Li , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Hans de Goede , =?utf-8?q?Emilio_L=C3=B3pez?= , Maxime Ripard Cc: dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, James Hilliard X-Mailer: b4 0.17-dev X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [4.31 / 15.00]; RBL_SENDERSCORE(2.00)[172.234.253.10:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.18)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:helo,sea.lore.kernel.org:rdns]; FROM_HAS_DN(0.00)[]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; TAGGED_RCPT(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; RCPT_COUNT_TWELVE(0.00)[13]; FREEMAIL_CC(0.00)[vger.kernel.org,lists.infradead.org,lists.linux.dev,gmail.com]; RCVD_COUNT_FIVE(0.00)[6]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27872-noreply=patchwork.local]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10:c]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[209.85.161.47:received,100.77.114.92:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.234.253.10:from]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; RECEIVED_SPAMHAUS_PBL(0.00)[174.29.1.49:received]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_TO(0.00)[kernel.org,gmail.com,sholland.org,elopez.com.ar]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 8D5381C0349 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: INBOX The IRQ handler samples pending status before looking up the physical channel's virtual owner. Another CPU can terminate that owner and start a transfer on a different virtual channel using the same physical channel. The old pending bit then passes the new owner's association check and can complete its transfer before the DMA has finished. The handler also releases a completed transfer's physical channel before masking and acknowledging its interrupts. A replacement transfer can start in between, only to have its interrupts disabled or cleared by the old handler's deferred cleanup. Clear both pending interrupt sources when disabling a physical channel, and read the status back before allowing the channel to be reused. Disable the sources before releasing a completed transfer's channel. Re-read and acknowledge each pending event under the owning virtual channel's lock, before completing or rearming the transfer. This rejects stale status and keeps the old handler from clearing a replacement transfer's events. Fixes: b096c1377d1e ("dmaengine: sun4i: Add support for the DMA engine on sun[457]i SoCs") Signed-off-by: James Hilliard --- drivers/dma/sun4i-dma.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/drivers/dma/sun4i-dma.c b/drivers/dma/sun4i-dma.c index b0c91dab62f0..6ecc45cadd91 100644 --- a/drivers/dma/sun4i-dma.c +++ b/drivers/dma/sun4i-dma.c @@ -400,6 +400,13 @@ static void set_pchan_interrupt(struct sun4i_dma_dev *priv, writel_relaxed(reg, priv->base + SUN4I_DMA_IRQ_ENABLE_REG); + /* Do not leave pending events for the channel's next owner. */ + if (!half && !end) { + writel_relaxed(BIT(pchan_number * 2) | BIT(pchan_number * 2 + 1), + priv->base + SUN4I_DMA_IRQ_PENDING_STATUS_REG); + readl(priv->base + SUN4I_DMA_IRQ_PENDING_STATUS_REG); + } + spin_unlock_irqrestore(&priv->lock, flags); } @@ -1125,14 +1132,13 @@ static irqreturn_t sun4i_dma_interrupt(int irq, void *dev_id) struct sun4i_dma_vchan *vchan; struct sun4i_dma_contract *contract; struct sun4i_dma_promise *promise; - unsigned long pendirq, irqs, disableirqs; + unsigned long pendirq, irqs; int bit, i, free_room, allow_mitigation = 1; pendirq = readl_relaxed(priv->base + SUN4I_DMA_IRQ_PENDING_STATUS_REG); handle_pending: - disableirqs = 0; free_room = 0; for_each_set_bit(bit, &pendirq, 32) { @@ -1142,10 +1148,13 @@ static irqreturn_t sun4i_dma_interrupt(int irq, void *dev_id) continue; spin_lock(&vchan->vc.lock); - if (vchan->pchan != pchan || !vchan->processing) { + /* The channel may have been reused since pendirq was sampled. */ + irqs = readl_relaxed(priv->base + SUN4I_DMA_IRQ_PENDING_STATUS_REG); + if (vchan->pchan != pchan || !vchan->processing || !(irqs & BIT(bit))) { spin_unlock(&vchan->vc.lock); continue; } + writel_relaxed(BIT(bit), priv->base + SUN4I_DMA_IRQ_PENDING_STATUS_REG); contract = vchan->contract; /* @@ -1183,7 +1192,7 @@ static irqreturn_t sun4i_dma_interrupt(int irq, void *dev_id) vchan->pchan = NULL; free_room = 1; - disableirqs |= BIT(bit); + set_pchan_interrupt(priv, pchan, 0, 0); release_pchan(priv, pchan); } } else { @@ -1191,21 +1200,11 @@ static irqreturn_t sun4i_dma_interrupt(int irq, void *dev_id) if (contract->is_cyclic) vchan_cyclic_callback(&contract->vd); else - disableirqs |= BIT(bit); + set_pchan_interrupt(priv, pchan, 0, 1); } spin_unlock(&vchan->vc.lock); } - /* Disable the IRQs for events we handled */ - spin_lock(&priv->lock); - irqs = readl_relaxed(priv->base + SUN4I_DMA_IRQ_ENABLE_REG); - writel_relaxed(irqs & ~disableirqs, - priv->base + SUN4I_DMA_IRQ_ENABLE_REG); - spin_unlock(&priv->lock); - - /* Writing 1 to the pending field will clear the pending interrupt */ - writel_relaxed(pendirq, priv->base + SUN4I_DMA_IRQ_PENDING_STATUS_REG); - /* * If a pchan was freed, we may be able to schedule something else, * so have a look around