From nobody Tue Nov 24 12:36:06 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795111389; b=eNt7ux+B7kmH8j7WdF84rixqhC5BiAjrLrNuXzPo6HoGIgudMDJ2R7Q3X9rdRPvifWO5 wT5mC52SSO7XVW+IpbGbQLdvQX9kJqruVmwwwE8wMr/edwfhG67HhVdyr9pTtK2UYRrpA odMF02UBIMk9m3giuBQBr8VAh94XQmSS/RIEm6KyH4PnszifjnEmbNJiTWiNQanjJmDYw G+T7Qfoo0pMLcafehCFOtvu+E+qaFU5NpUGRkAAZWgGzPFtpgbIAr0LQz/qBeYB3BrfXt 883k1NQ26fZEziikBmyFnk3zOowqk4Z0bTHbFN3e0BQopfVnVDtFQSBU3Ccc78+0U4A== 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=EPVyFaATt/kISeINhQCkl7w+B4/hGnkMtTbn1uTBhQNV73k6tjCh/TnY7iLmpxXYtKZa w52jO24sn2nwWGx+WsaeP7vhbXKUY5n4hnVhRD5axvXiVPxfWCCjftNYyS8ztDJ/ILSbX tgAVAFGhr5fDlcr0V/DLNvTs9/QupYY9VvUXPe4Gnao4TOIsFUmwZDl6/Ygi68en6Mh/X jHEEGidWxssKhC8cLHqkoHbhaaRj1AUjm88e3GIRGTYeP3rIv17RYb1fDzUZxcmYGeuHo hT2pzijvX8KSxYcoXC20UkFNs6C/8XXi5ao92kX5Vpi9ps3C3qCetaNDp7DG5jTiNog== 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=DYEpxgBw; arc=none smtp.remote-ip=209.85.161.49 Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) (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 DCD9E606A335 for ; Thu, 19 Nov 2026 18:03:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DCD9E606A335 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 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=DYEpxgBw Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-702fd86d674so1771948eaf.2 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=vger.kernel.org; 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=DYEpxgBwNBU9ZlLRYeAhl+VOhhcyolS1iutkHkIZMJ9kiaeJ1r0CA0jkLIc/iyBk1W 112kcn3WGBsArIWl1rG5mZAwDixuG7iqQveilbXR8/vz4bJ+B1eeHsWkKr5ScXkh7QTL QyFg+zYIkKsI1R64Ka/g0fJWUIT+aTMSFqV8wuN4Fy36KJQat+7olupQ0VhHJOLqSLnz XuAFDTGNWF9mNFVpVvaBs9zvN8OTNUR+IbWbqJd6AkL+w4XdtcljwinV/48smMNvt3eR ZGuUWr8hirI3DNYTdRPKL/YXQLWDtcw+ISXLJ5yl2NZQy5Y/llVWw9dheKI+4/ylB5Ay Gc3A== 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=S+nnj4I4t4uXZiQIW2SIED4EA4Dcz26ryenU7O1GgDFAWDdi1Guas/6fJLSbqxN1il wSPWxpgUKOlwxgGrUE8WAHEf2sd1GJbgDXnSDyW/duChiih3myAaBiUl5XqNHtvN1JRx RBOwsMZ7nkD2MBgPLqAxi9GgR0Af+jBIw58fctyIv+uUWoZT3st9B+40yUv5k8KbJkvo bVDQoWoRH+xEzcCjYD2NzjOvNC1VE78q4I4wX2+V3Bs/6LnpxlZiVB6VtLgw4XK5cYb/ yuA+Sn1JR/IDtYx3FKeJ8UtqqliL4j82XgI/UwE1CvolwzCBotIbLQApeBKd5RBdsNT2 RKzA== X-Forwarded-Encrypted: i=1; AL+hErHgycpwayhobFSGKvn30K2+LAyyk0MxYRHymkf/3Qwu57oXrQz0L63mvFg5h0h9QkVENXofTdJdUft+Ceg=@vger.kernel.org X-Gm-Message-State: APuU4Z8c63pZaq/en1aqDOjnRNvUwG8CAHuuWm6IxTXdxRu77FxZY10P RqNhLkXm/iCmcuSZymGfcnuFpFG8TPMqSoeni2GZZ+lKBMpcQnit9OFb X-Gm-Gg: AYBFou2ADx+GwbBdtv+49m6JOKbQIJxoT0WZqIw04lDozVtA6Lu3eUwlJew/djoZTsj zm7anKREgbBqbCY9Ij6wkX9dWT80cuPa3ie4pHdDImGxJU+n5CoBbeBthDZJ6g16gDxrYdUoeuO SJiDUbIXSuu4MeksV2uHnJVs9W6koezbpd25FoJ/Jy3DemUqPjLI0P4mBha68xwVsDYA4LAtoCN ZJ7GOwwgLw/eig0s2hlQI3e1JlgyJi0jBFjsVGwaKcdXkbpttTjZA+fNvHXHyHTg2Rmb9SyZ/Nl Hh6u35omQAMq9k4fCJcZdJueB1QQ/e5oRQFdB7FGOQGtO45G5GPiWwpmscxalNIsh7DG/1UFYFD bA1HUev1G++2vrE7X5Ivxtq+lqfg0vht6kVIHMaUjJWUhMaQrpbYaZfn2qDBUqy4p/Mil0pKz/z kWV3nVzlUAFJLZw5A7MmUZEp1sLGbGg6/T96nU57y4qv/H8IqbvpIpref3Lzp/THltPnkEIj09Q nqCfXPY2+fLt/lO8NI8tgWS3LmnMZrFX0cUrmxCUPQnJzTnrB//An8lNL6ABduIhmqTbzZaUO9i VznXFLKpX5ClIF8Z+dvCP77FL94SlZbGXgNVqhM6Of3efxD9XQEYh16xxTW1w6mgkOf8FzUy/kw TEM/gxj/PSxHeY/H9duOkazh0BAPP2ZL10dJIZjFUa6KpphYS6/D2qlt2KE2wfzFtw0tx4KfihE ISmN6FMJvd+mxGZKxt07SRn4a1WYBvW1iVvMBsgA7bKiKWuvtcBPF6 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-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 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 vi= rt_dma_chan *vc, list_splice_tail_init(&vc->desc_terminated, head); } =20 +/** + * 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 unt= il + * vchan_synchronize() drains callbacks. Prepared descriptors remain avail= able + * for submission. The completion tasklet owns descriptors it already deta= ched. + */ +static inline void vchan_terminate_all(struct virt_dma_chan *vc) +{ + lockdep_assert_held(&vc->lock); + + vc->cyclic =3D 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_d= ma_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 sch= eduled * 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 drain= ed. */ static inline void vchan_synchronize(struct virt_dma_chan *vc) { --=20 2.53.0 From nobody Tue Nov 24 12:36:06 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795111390; b=4Hr6fWLIoSTFTu2Xt1zUaFc6cFL5Lp3dHEITR4coPHBYFQDZprERp5MfpXHqcP3VyXZ0 S7vtfU/HxQyS7mcqtTHJqencj6bqW2GBNeRCm9gfSvPOHPT96TNZdbArqgDTdI+38ODbt PnWdNmUlTK1r0bOKIQfgyCoLnuDuU7nMO7lRtw/LfnX8Me1iUiWFIpcNijtY0eGXDdSIZ KlAEFyCGsI3NSqSElX4mONEGPQlNZqx6Ef9DSyhM7RlsraNtq1DEY5tTSY3u3tI1yGjYK k4I5wkKGnNF2P9pEZ4yVO5bzduHgCzupAY4BGIJkEy/jTCUTRlbROjZ7o+Dp9FkBUhA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795111390; 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=x4xuE+irBlD9+o31SKtDjvo+r+GFhTru84SRGLwkB9nqiji4R3DVpV3z3J+HhKsFQsNK IdxVQt3rTFrGmYirDxLgmfpZlF4sCuMaqj8KN5Pen2GHWwLQgwqmOWzv7EXI4d967+TD5 sA6OLv/inTcji0YC4MsCorqF+Ep6fhvInC0G3ANl+H2rYqKmP+TPyvvgIc/jHMpzLCqFX 9n6pdMkun0Z9VAqv5gztAIgOdJy0k/juTpxSHBPL7iKeCm6/Ofu3UEiLwooxTqLmNm4vV oV4hvon1xZfQe7O0cCsNE8F9v9eOU16T0ZJYjpnwXfiZx4pLWK9VzTJuz45LMrdgFOA== 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=fzRNPf51; arc=none smtp.remote-ip=209.85.161.41 Received: from mail-oo1-f41.google.com (mail-oo1-f41.google.com [209.85.161.41]) (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 3C7D7606A333 for ; Thu, 19 Nov 2026 18:03:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3C7D7606A333 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 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=fzRNPf51 Received: by mail-oo1-f41.google.com with SMTP id 006d021491bc7-703be215729so4518eaf.1 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=vger.kernel.org; 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=fzRNPf515yOTUM7GQIR5y2GWzmgvJd98uCwhAzFHCQTfZTRxWKOVI4uFLxPDCUhzEO csealtC7PMGowcKCUW93tRfedWxQgYp0whXXWN07WjKOkCsNBKBoC9SUxr7Uqauc0fBc vs+W3JwusJ9foX4WIaSISR9/VxtfnkH0SCtWAdJRA6O4n1zmpOgZr9GyPejh4wu2afe9 A/Rt5IVQhu01UB029MLMxs7MYDOoX+0WrrCDRCiBa3AUeYDeKcUwLYZ96Izby7V4VEQp Nx1lCAs8XSmvA72RHn6FGZnQ4hJ8gD3XHta0u64LX6dM7w9SNh7I0iP7JbNTbaOMUHiY Gwyg== 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=H5B0Nal+kojWulYei0NJ09ZIbcBJ5wsVNn9GR/BLkh/STK5S1M6foum6H5YPQUO9Ga CxIY/qiUCMHOQj5dxN4oRwHM0/BdwJiyArp90byIlygNtVEdRUetaOn8oLpuMUIZl+Ut vpZRoDuhW4LRnlg/oGsTkriyKqlnXAin+5La0lzkJJydREcvHLNDYfWOtZctddFkWc5W maDXbjCGJz9UlitzL54bpGG8xsHUjWUCxYJuQc+oBKpmWeJMBrgqQeDnXgNBTQQPGXUM cRRXRCMolZXdKNCswfMPuXgYZa2Yb6nfFNlugiuUFEwl/vK92n3/4XVFC2O9SKH7a2uC jung== X-Forwarded-Encrypted: i=1; AL+hErFidMYbyCECWSb5JMEybK7Bz7CGkEXqMrdSBhtLnH9vIaftKtI6lv0BhQArXtjpzmaGd6BSNgj3gRr2U7Q=@vger.kernel.org X-Gm-Message-State: APuU4Z8MHWj794qbhGsxMBiAj1GvKHqQxnAWXC8gdrXa6jzNz6zNc+IT IdoIEfI9h0venHH4Uus8umhjHlBOQqoDh6VFfJAWqd3nNI5RgFpWKomd X-Gm-Gg: AYBFou2F4TfB5PXzv9PBMcWxNi+ioHxc62jpmFhv1IaP5EF0EgkKQO7YhBvnVNbbi5X 9pnEy8IjwzOl4ziOYlm1QR+OR4CxIn5oQPMHhZW15u7YTNZM1irZuJYNjE1ma6KbcGz7sIIPSqa odAiLqC6yCQFgyTcV37jhwDSwb94XJtTCb7p3KbuhsLgUQWhkKBeFoTdTiuh2kO7gpYoERMt4GT dW/1F1VL/wCqaIaD5tvMRgomfW/iHvAp+boc7pHGeI2weB1wJIGC5UD4lE0wi8XmIrWmdRf8VNx s82kCVRy9+Ln8p9bktAhRrviBLCkEv3I+PAWzXphEypP80vt7q9ZGFH4SpNp/iATO513e3D9Tot jpo2aRroNt+kMcGnL2MCOhMcnXhCkLNFgeiiS1vjJrWHZyiumAdJExux2XDROJ7tGlv0Gke+gJT SU2+rSKT5U0hO0hLVBUepx0WeM9xKRMWDjgWljdf29UD9XfI6UVCXG9DaO1oYiI2y1//lrve+uw 86WIksbaLt7vwenBogX1HOAB1X46wBVWWR/QfRaxtk0V/PkWumGur6p+4EBEZrIAUgjok/B17As x+mV9TNF3KiHF/7rIl+dUUxnTlWpT64ho+o/vIiHRAjekRXLhwJjlScCGpmwX3G0Bopbzwglr2o awoF0XFJEtgN2K9r9Twiweg0qJfRBM3K+bUHDJWi96fNg5burp90JAmzQaUokg/ijmRhGDS1uzT 6Z7oyWgfbvN/UyY9sy1j3NRBWaxXjvRntViJ2vKQySi3Db3n8OjMkv 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-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 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 s= un[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 a= ddr_width) return (addr_width >> 1); } =20 +static void sun4i_dma_synchronize(struct dma_chan *chan) +{ + struct sun4i_dma_dev *priv =3D to_sun4i_dma_dev(chan->device); + struct sun4i_dma_vchan *vchan =3D 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 =3D to_sun4i_dma_vchan(chan); =20 + sun4i_dma_synchronize(chan); vchan_free_chan_resources(&vchan->vc); } =20 @@ -322,7 +332,7 @@ static struct sun4i_dma_pchan *find_and_use_pchan(struc= t sun4i_dma_dev *priv, spin_lock_irqsave(&priv->lock, flags); for_each_clear_bit_from(i, priv->pchans_used, max) { pchan =3D &pchans[i]; - pchan->vchan =3D 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, =20 spin_lock_irqsave(&priv->lock, flags); =20 - pchan->vchan =3D NULL; + WRITE_ONCE(pchan->vchan, NULL); clear_bit(nr, priv->pchans_used); =20 spin_unlock_irqrestore(&priv->lock, flags); @@ -970,13 +980,11 @@ static int sun4i_dma_terminate_all(struct dma_chan *c= han) { struct sun4i_dma_dev *priv =3D to_sun4i_dma_dev(chan->device); struct sun4i_dma_vchan *vchan =3D to_sun4i_dma_vchan(chan); - struct sun4i_dma_pchan *pchan =3D vchan->pchan; - LIST_HEAD(head); + struct sun4i_dma_pchan *pchan; unsigned long flags; =20 spin_lock_irqsave(&vchan->vc.lock, flags); - vchan_get_all_descriptors(&vchan->vc, &head); - spin_unlock_irqrestore(&vchan->vc.lock, flags); + pchan =3D vchan->pchan; =20 /* * Clearing the configuration register will halt the pchan. Interrupts @@ -991,13 +999,14 @@ static int sun4i_dma_terminate_all(struct dma_chan *c= han) release_pchan(priv, pchan); } =20 - spin_lock_irqsave(&vchan->vc.lock, flags); /* Clear these so the vchan is usable again */ vchan->processing =3D NULL; vchan->pchan =3D NULL; - spin_unlock_irqrestore(&vchan->vc.lock, flags); + vchan->contract =3D NULL; =20 - 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); =20 return 0; } @@ -1128,9 +1137,15 @@ static irqreturn_t sun4i_dma_interrupt(int irq, void= *dev_id) =20 for_each_set_bit(bit, &pendirq, 32) { pchan =3D &pchans[bit >> 1]; - vchan =3D pchan->vchan; + vchan =3D READ_ONCE(pchan->vchan); if (!vchan) /* a terminated channel may still interrupt */ continue; + + spin_lock(&vchan->vc.lock); + if (vchan->pchan !=3D pchan || !vchan->processing) { + spin_unlock(&vchan->vc.lock); + continue; + } contract =3D vchan->contract; =20 /* @@ -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 |=3D 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 |=3D BIT(bit); } + spin_unlock(&vchan->vc.lock); } =20 /* Disable the IRQs for events we handled */ @@ -1276,6 +1288,7 @@ static int sun4i_dma_probe(struct platform_device *pd= ev) priv->slave.device_prep_dma_cyclic =3D sun4i_dma_prep_dma_cyclic; priv->slave.device_config =3D sun4i_dma_config; priv->slave.device_terminate_all =3D sun4i_dma_terminate_all; + priv->slave.device_synchronize =3D sun4i_dma_synchronize; priv->slave.copy_align =3D 2; priv->slave.src_addr_widths =3D BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | --=20 2.53.0 From nobody Tue Nov 24 12:36:06 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795111392; b=OAGsfLn+Hpb5Av8WuXUJHrE74qMrxJIjdW+IXQMG51WGJTmZM6zi11HQ5XzjGIwsEtO6 n8rqtTtlouHYgCdjm5Dzy8oRJ2UHPHWfZER/vhX32ja7f2acmd2lClu7ZOgcZMc+rrgr/ kB0Z5GTu++tAVM+WfnTblnutsQ04oRlS7PwXTJCUJ/YxOWLkFKvMApfvXD/0thX+/ZunC 4EMjgEbmjVhpBe+BaBRMfBXwtlcZ0HL4Srsrqgp+yoqerY+6+LbcCQc8eZ4AjhHEOltzp +fU1xd9WkqPz8utNJA3Mp/e3qnSUY6UTcohbPelRDmTWK7PIS/lF1is8IKh3w1Y1bdg== 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=K6TFpbL7DWKeoOB7LLsCRiOi/z8RajJRQf1YvlnmBEG1GwRqmGVg43svfzuEmYJPP5P9 YfZIQxQ8lo+PdOCsFc96FUErnG4N9c5IE6mj7ACDwMo7ZEwPpAzhQ26oIu1aj4NPYh66X T/ntJ+StWu6aYhTBuVw3Z642W3xiVybS2ZoRK0hWgGdPbntpMfQ7L/WS0HO7RKrLzmNCd mj7E1NgjdsKGGkH3Up1JpoB4DeTETcSguqaHeWCpdvd8GnihMx9JlLV0ET5j8FReosWWp J91SwirZsMIpTwPxmKPM6RwwZ/xPbswLiTWi3psGod4AJjjn1oZOOY3Okrl51VlmEoA== 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=kMMJaIw1; arc=none smtp.remote-ip=209.85.161.48 Received: from mail-oo1-f48.google.com (mail-oo1-f48.google.com [209.85.161.48]) (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 C05F6606A33B for ; Thu, 19 Nov 2026 18:03:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C05F6606A33B 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 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=kMMJaIw1 Received: by mail-oo1-f48.google.com with SMTP id 006d021491bc7-716c0217635so1359505eaf.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=vger.kernel.org; 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=kMMJaIw1atQfQOHDkKbNI3z2L+GOPgCJHW4PfsqAw0f0i3wrVcTaOrg/D2b8I9prRV vUoeDxsjHea9FMdIjMANCtGt3N9NwINAx9mi5E9LEjBxiH2dk+sqGLGClXY8etHQTH7K j5lCvDcAabqkV0JSivgusAJmn5LXpzkr4AqbgF9CSFWo6I6/GTsCVL1//eYzfg8h/aND kmZb6WOZvScp7wNtM560ctYRiwrvPshk+UmxDTYJStO3ZdB0LfkY0raMY+rY99njfWtF PIkibAwYMNFmTmNNVf5sQCDE/MJvbXabEngC7VfHgkt67ifo94+zejMmegsFJ+v3qa8k H/Zw== 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=ihFWz7inKZDD3Ueno3WoGClfSAMrVLW+TMSBpuNDwUpJzPPo4OnNTH8HE3wB5rMLtW 452T+tT5bG/RAKjz6VrsTT32nx6lffNMMo9pE7VlVGLloj18nO7bD3lpI2LfwyaXYOtr +uaUuwziycwFFaLAhyZuoK+Lui0aXFQbZOsovFtR4UHud9y2EmIUvDTdol+3DQLGvW/O saOuuUAAv0J/Z1Aj2xBTBy0qQ1X2YdAJjErZk89rttcLOZuOVkrPw2daHJxw1PW0i68/ jxyvXw8h7HkgA1Cw3zX3hW0yXTyyYU9aeLDW5D/pp39nvnetWt27li/SudP5nSDMkVlP fNcw== X-Forwarded-Encrypted: i=1; AL+hErFAm31O5m2E+Rnd8XVG+L/SGuY+D13p9AKIwYgHngziFaed8Sedi5u9IChf6O2Nuu3IgmTmBighnb7AbgQ=@vger.kernel.org X-Gm-Message-State: APuU4Z/hpDpLi3bA9aKFd9JrVoiCnFQrn51pyQsaL5HFvZunztMureJ8 RtRV+5UAmTNMcVZUIdL5rivnAH+8wrx+Ji87KxvxUHwt3xRQqhUvlHoY X-Gm-Gg: AYBFou1cc1aqiSuMY0bJkdLkmYHpK8i2eKia1Z1U3N+RQw/B4XFL5GGKtezQL91IGEB QrISKK6FE138gus+dGkZNFQ32lhYzStRI2GJrCLCxzCO3krpnWlbI0HEg6n737HcVDWkUlQjGnW mF4uCO2Z5OT9gDk9GuU1PhLf3mcPY6gfZNSxpoQZUSUuRyxW42j++sXDbk1ZZQtAJZcShifTbWN SSNOp3rpJxCZ+8+wIuO/lR+VFUgIgP+pD/x6yTs1O+dObN+Guf+8hggBU3yz1dedqUwTt+t0PVp IcrgnZcPF+sRqfL4kD57qK5HNxc0s/k0niqegiAoNWp8v9AsgLA232yFrjmGrDV/JIhJaty+gHG t7yEJguuRJX0Z+dj9FmNp2G7dm6k06wjnEw0/9UJ4mTL58JO9D7+d4awfoJdEvwy2erRpwefJoY 0EA34+opAS5BiPLFcio1dHI0A0TY+Vn+6pheKEoF1lFOKdam4cjYOmH+yx0Ocw/Jl5X7QeIB89V aLTlEAYIu2dU+PalXToA7+V3nokH5pEjGr8JL/HW/IjkLJBxL1UxU/PXZVddt5r5joN/QWzPFb9 ojyYGB7fAnXFVgUAns+KBwStwS/BHAX+LFoBsKpWEJQtwNDkExEvuBS4Z+JMH8DPV/XdoFmCJEW +rufloQS+rgBdtcC7dX/b3EGq11soYFhlb81cz/E1SEiZrAoEswP/pn5b+tC6bi6JVTvgudHU7v aBDgYV1zueaPmY/np9O4rxBOOy/ciBJC9EHqb6MlU4T9LHjJ73StQ6Gg== 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-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 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 s= un[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, =20 writel_relaxed(reg, priv->base + SUN4I_DMA_IRQ_ENABLE_REG); =20 + /* 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); } =20 @@ -1125,14 +1132,13 @@ static irqreturn_t sun4i_dma_interrupt(int irq, voi= d *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 =3D 1; =20 pendirq =3D readl_relaxed(priv->base + SUN4I_DMA_IRQ_PENDING_STATUS_REG); =20 handle_pending: =20 - disableirqs =3D 0; free_room =3D 0; =20 for_each_set_bit(bit, &pendirq, 32) { @@ -1142,10 +1148,13 @@ static irqreturn_t sun4i_dma_interrupt(int irq, voi= d *dev_id) continue; =20 spin_lock(&vchan->vc.lock); - if (vchan->pchan !=3D pchan || !vchan->processing) { + /* The channel may have been reused since pendirq was sampled. */ + irqs =3D readl_relaxed(priv->base + SUN4I_DMA_IRQ_PENDING_STATUS_REG); + if (vchan->pchan !=3D 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 =3D vchan->contract; =20 /* @@ -1183,7 +1192,7 @@ static irqreturn_t sun4i_dma_interrupt(int irq, void = *dev_id) vchan->pchan =3D NULL; =20 free_room =3D 1; - disableirqs |=3D 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, voi= d *dev_id) if (contract->is_cyclic) vchan_cyclic_callback(&contract->vd); else - disableirqs |=3D BIT(bit); + set_pchan_interrupt(priv, pchan, 0, 1); } spin_unlock(&vchan->vc.lock); } =20 - /* Disable the IRQs for events we handled */ - spin_lock(&priv->lock); - irqs =3D 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 --=20 2.53.0