From patchwork Sun Nov 15 09:06:34 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4107 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id 444911C44E5 for ; Sun, 15 Nov 2026 10:06:57 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-27654-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-27654-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id D774A3D47E for ; Sun, 15 Nov 2026 09:06:55 +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=1794733613; b=xOKoFzslXOYmD+3HjGKZdcnR4vRSL/rMRannnrsvF+P291ukaRf9iI7seuiouw1OkYMk uUSAN1voIcGLmW9Sj0D1tdTkb4kBaXy0Rbqx0xF3Jxlit+gxtY9JCktND2cYoeU/rrZyU VDX5G59SnAUjx1r9fvolVmNDcTOcukb3nqeyHxCIZbViDOMEeg/qAOBOPvYXiFZg/1ZGo K31NXjPCQCiWUPQVXJ8dcSKroWrFcFepTBE1vVPn4ypyO0zeCXQLlIJuse1HQwPiPc8CA 54nXtm7NPdJAjq4+qUTPPEC2NE6QfV4GH0Z1jANri6JEwtxM84Q/woQsUiES85s/PKw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794733613; 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=WVskqBN7adAe0blUmUVhbRXdugopDwsXLNQtgww94JA=; b=VjH0GTRlnunJQlYLrvyL7w5lTIiG6t5MWjQTsG/FsZF8IsuwDeTSnA1uvEpPkTdCPRW7 6L47lNhE8y+hbp5e1YSPtwl/pUBubLdjMZFcfTDFenMGrrgXapdVXshVURsanA9XMy6an 1mClgiafvbTwKsvv8D5VtIOj84i/zeNIJ+8ir400nRDaKdaJCoy4bfiuNyEGdILpQfsiU 7WFdCGceWqoot2ONCjhfjk/U7rRQ+tj5nw5YSKUTpYZ8cedpiFoBgcI3bCbLu03JWmVCn paJO5tAG1KMPuladNJYzO7nyuf1/FCwSOw7x9mjiNgq/ZSauTZXC9oM5ICk6B3jPH7Q== 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="uqjiT/sV"; 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 0E7D1606A336; Sun, 15 Nov 2026 09:06:53 +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=uqjiT/sV 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=1794733613; b=Y8/h4vW4U5kjzSBmPtB+qmiHY/6REZx0l+CIdYeLEVy8IaZnxbPMOL8AnToGrtpLPMDN gBK9HxDfcq8DdHKoFv+2ugSa24u0BqIFK2SJzXzIRqJX+IHsP9DsTCNKNnmrFseEOlN6d ec43Bqn6j1pIgj311rMRJO2lx87utfNFBVApo5kDbhJO+7KY7BX0oDU9R1IlgTP+3Q7OW QLifJc1pJWrRFp+SlGDkZ857PQLRJHbgAmcoY+c8kqlrXQx8OgAn0nvsGeG6QzrHuMdLV Np7L+GWGF4nj6IVE8levneoTT/4c7foEkm0O4x5nX8I6SUpTYw4BpszKDM6h1uQLIdQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794733613; 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=WVskqBN7adAe0blUmUVhbRXdugopDwsXLNQtgww94JA=; b=ATPjVoG7cvKMy4pFVMY2y1JMeOCvoJMJgtgKGY2WK3P0g5FKKyg2l9eojrWlHr90BY88 s7l9cCLmTUOe0iJaJ/zQi3wOmdti/FEYuP7Vg9fbKbp33RQpV8KBRXnBJjaZgf9dUCONN EaWMHbxdpY51nYELspmjkKvWFzraGKszeQqjNnvgdfByKKa1FZFpxErSiDVNxNwqL+CZc 5gDgN53xWpenk4Jd86nnZCHE6DU7Z/u96BbyCBXnjWUrwx3lEaB/iYHwNtmMqXXM+8pBK jy+M1e+ILHB2oVwa6hUUqAgaxx12pPIPFqFohUZVSXFDXl08mkhykfUqCC6lsHaTRbA== 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="uqjiT/sV"; 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 96FE6606A32D for ; Sun, 15 Nov 2026 09:06:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 96FE6606A32D 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-70b875f6f1fso2970617eaf.2 for ; Sun, 15 Nov 2026 01:06:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794733611; x=1795338411; 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=WVskqBN7adAe0blUmUVhbRXdugopDwsXLNQtgww94JA=; b=uqjiT/sV/AfVnrLy2gRBMHu2DK1jfgf9sls8k9UgASIhr88Ug7DVLVnEJxcZKWFLyk Ssqqw7B5503hg1N1v1w6JmXfbO0N6Z4MB2K5Y5dWNBlYTRSDu4fq5wqTsQL2bS+I4pQv Vz+TmcLKUg7zlEFQogNZreFy/MJSOK3pX/cyMiTVBCF9Z94BNc6KEQoGyTe3Nd//YQxd D7R3CI/4dSev8AcIemFtJKKuwhcGPod66qegPqJWmpyF7jfrNz3pmo299Xu7QYQYKwiB c0ALMz+5it0P191y7NgNuilMN7WK4YFxyFjeoMHbh/3UUxwnsUqoVpMgZ3N2v4hHSIKL ZQbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794733611; x=1795338411; 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=WVskqBN7adAe0blUmUVhbRXdugopDwsXLNQtgww94JA=; b=OcSJ1ghe+uuSU3cHy+wPEPte59I7PulPDP0HesArkC8wuPqFaZSGLVjcKL9tH+Tdnq /qTQBBsug3+PibVH/nsaYx4DSXXXcvlW2lviqBNsqYNtozWVohMZpO99OozLoowUHdGt whjnEVS06nMamOBclO+tWED4fIfHoKWZfNQxSsIocRWRK6+yXbGpeAFT/cATW+f7E8lf 6dmNgBh4iLhJs/cLkEb/dbECpz2Z/IJGNgSXD6gTSbD2I1/uU4Mob7F+Cn7vsyIbujls bXNdQn1drGeJzzYu8Iim3/NVAurGJCNpgYUZD4vgkScYYrlMon76uJ2ylaoFqSkjE37m CTaw== X-Forwarded-Encrypted: i=1; AL+hErFqbSGnNrtAhEu7qdKFiDovTGKKoPmp2vdzw9qk9Nyk8I2MP1MWWTw7fai+PPPdFfO0fC5rqLj7cfkkjQ==@lists.linux.dev X-Gm-Message-State: APuU4Z9E/imZXBdaHuuKkHBQZ3yG1OKXpprwDiKajAfeL78sUXJhpLGR thZdtg8S+HpcslWHgZ46Kpar248AjUveKxjJnVORlx9MjjTnUclbRQpw X-Gm-Gg: AYBFou1EHleWohNcA3ho8jmT4w7+GMyU/sFqhiu7IKZvrv58X2rONC4oZHgEa8WGs46 T6OjKP6cgneWgXnWZ1X8euMZ9BZULY5Qhpx4G8azaY+RmqxRDbiZdtMHkr3fgaTHM7eGcfOtdCg qCOKwsJeDg+j+WJ+Vl4+eDcirV9C7zPKXmGtt43YrCXbDCFGC7hMZA603llg7Wpnr+AgYnb+L8r oc7bACjItHRwAeEUVktuqnHWFV4P3+3OqQC1WTK4eh8dTcL81X29NJxD3TmMck6rhSzDvCXM3ew KzzDCdNUfFdWJ5h6zDulGgoCIBHKnlrO48uRNPDtzV+OzVc0VuTqQa67u3JWtmG7kw6dC897+sb +GIUNmgxR8Drs6fXNXJKNMLrYnFpq++4uWjlzM89t2dJIZ34GsOTAUxE9qMXA6bFm63V/vPa3Lm iWaq2D9kKfatHKx17qLjkntd3VDTV6HEvldZ2l848aUHyzj+xB+IdLZacGrd7UvdUdHfystXSEI 7+z9d1g9W/pWSySyDePWh2SFsTqi8rM94IkG+Zsrqgl7K1h2JMyBLX2YtDm+MSBCrl79uonq6Re zkh7xnMDErUDNKA9lysNR4CEGD9/gkKkwpmmAvw/ZkJcSXGuXk/jh5IDL4aaOgetGTvP24Zje88 pekSfhvnS2l/7O0dzt9DijZLYbgHakOly3cKcSJLNMoJsr7pzOfh+jz6Vdgl/A1V2iT1nWYPBSh wPygcUrCzscmofDVIf34wfcsMCQNTL6mQVuJ13IGx9GtTVXYMBv3tx X-Received: by 2002:a05:6820:418b:b0:716:c34d:c2aa with SMTP id 006d021491bc7-71ab509ed1amr5396398eaf.37.1794733611590; Sun, 15 Nov 2026 01:06:51 -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-71ab4338765sm6198902eaf.14.2026.11.15.01.06.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Nov 2026 01:06:51 -0800 (PST) From: James Hilliard Date: Sun, 15 Nov 2026 02:06:34 -0700 Subject: [PATCH v2 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: <20261115-submit-sun4i-dma-callback-lifetime-v1-v2-1-fb7d258702f8@gmail.com> References: <20261115-submit-sun4i-dma-callback-lifetime-v1-v2-0-fb7d258702f8@gmail.com> In-Reply-To: <20261115-submit-sun4i-dma-callback-lifetime-v1-v2-0-fb7d258702f8@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.15.2 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.19 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[172.105.105.114: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)[]; FREEMAIL_CC(0.00)[vger.kernel.org,lists.infradead.org,lists.linux.dev,gmail.com]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWELVE(0.00)[13]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; TAGGED_RCPT(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; ASN(0.00)[asn:63949, ipnet:172.105.96.0/20, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; R_SPF_ALLOW(0.00)[+ip4:172.105.105.114]; TO_DN_SOME(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[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:+]; TAGGED_FROM(0.00)[bounces-27654-noreply=patchwork.local]; 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.105.105.114:from] X-Rspamd-Queue-Id: 444911C44E5 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 all channel-owned descriptors to desc_terminated. This also retains a cyclic descriptor moved to the completed list by an error path, without requiring provider-specific descriptor-type checks. Already detached completed descriptors remain owned by the tasklet. vchan_synchronize() drains callbacks before freeing or recycling the retired descriptors. Repeated termination leaves them on the terminated list until that synchronization occurs. Signed-off-by: James Hilliard --- drivers/dma/virt-dma.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/dma/virt-dma.h b/drivers/dma/virt-dma.h index abf2ae737c30..d3057fc85a9b 100644 --- a/drivers/dma/virt-dma.h +++ b/drivers/dma/virt-dma.h @@ -199,6 +199,24 @@ 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. + * Descriptors detached by the completion tasklet remain owned by that tasklet. + * All other descriptors are retained until vchan_synchronize(), including any + * descriptor still referenced by an executing cyclic callback. + */ +static inline void vchan_terminate_all(struct virt_dma_chan *vc) +{ + LIST_HEAD(head); + + vchan_get_all_descriptors(vc, &head); + vc->cyclic = NULL; + list_splice_tail_init(&head, &vc->desc_terminated); +} + static inline void vchan_free_chan_resources(struct virt_dma_chan *vc) { struct virt_dma_desc *vd; @@ -232,7 +250,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 Sun Nov 15 09:06:35 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4108 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id 52AD81C44E5 for ; Sun, 15 Nov 2026 10:07:02 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-27655-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-27655-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id AC0933E189 for ; Sun, 15 Nov 2026 09:07:00 +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=1794733614; b=KlOUWW09yT5YQvAlMBdoyoHDZ7JYEaiJjhEjqBudZmujT12l/PLVIEqzGGoBQevlTni1 llatLyCBwotatCId2X5CaeM2mhkV6SoeZ7F7Fr8zuBCQdGTqfg+bxZalpuYD6b5ttHrOt TO6Xbih6m4tdX/FGuw5bbBs2cZ5rbJdHXcn/Rb1eTzUrhJqV0ZYwG+cQj17skhbPipenM l4P2kdCGnlS5Q4LOI4m6n4KDJrqM+j/MO1MEndTnYismz+3AHA47WG9+3QWJD1JXGtlzT uR9l6nveYP6sT3bpeWxnfSTuw4zZQ6jyrOJW3dOlWSAzw28MYlwWPjlWsWN/Rtd3TbQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794733614; 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=LJfY+FZMpdHpX5PsK9lpaEcmxlu7DHLOE36m7FoMtF7fiDC5ZIyk25JvXEcnDypmY4SS NHR4SXIBhuC2lrfLFWIltuxq21xbAwNn7RFpRpNnm3nAyjnPGZB5N1zA760SN1upp3Yfy b4NZq6syGhEAq9bcBjPaoUKJlT0y++4SliosfnH3tST4H6KY1v8rukVC67lnbjFj231Hp R37MckzMZ1V69nrT9o+fYehBN+/dgSWoruSZtKQNU8MAv6fpLO46AIzTHi7XX2wGMJNWq 0dI0KPdKqqXnTLv+ryxHFDXBpledSsMMjW/t/7f9NmaJhNQ3tYLvXnYnmvWTPB0ECqg== 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=BBxyn6y7; 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 8D3CC606A893; Sun, 15 Nov 2026 09:06:54 +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=BBxyn6y7 X-Original-To: linux-sunxi@lists.linux.dev 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=1794733614; b=pWlMSwUVX5tUpqAQIxfBk+anRFml49qtLWy4Ox62GjkA5OVJr2rUYhEtpWfiorqH/9E0 OIx5xb3mI3UiOqC5vhmHGt8YzBTt7KAk15AqUF4q/nE8qrA33I2SMo586YExdK0G4CAqI caPSu9KgsB1jlYx2uiTHBGJPTBrnVkLNmsClaq3j3NZVqQ+znfw6o+2NqJXFKVhEglEOr xqyWLFvQyK1EK3N+xTCnAZotXjzLYGMmjdVyNob3U5CYbYW/Ajhwhz+F+bdHkStVXeM5e g9sOuGmE3ID6U+1nHtN41G3h8qdAuROSDwNenFqNaRpXBiZf0O9bgtg2XiwTg8baqPQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794733614; 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=wtTIQQmBOFQGh29+iO2/S5+uWe0mXyYfMBYB9Pak0f4yJrSlEqVETHqbl1T/FO2z2KwH nGySeG7zTGT7G4IrlBqUFOvDI4Yxi6hLYtrDbv6Uav0aGz5LiYg/3Rc58cKql3d/ubWUO qUGyccE0x0T7PWUPUSteE3rx2ASN0RsfMi1N/GD9NnQXen+ftQF/4Fy8Vq8HTpMTuQrHV AE2DkQPFt4GYyygBB75RzpR9xucCgPvT4OaLe7h5zyNYrX4utfW1cJiZQky/mvqIgpJsH hd0pTr/9rfply2YNXwIVMaQB2YHpwD39b+BDB+1nL3mSYbbhIcPh3ARiZl0nFnkpsBQ== 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=BBxyn6y7; 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 2509B606A88C for ; Sun, 15 Nov 2026 09:06:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2509B606A88C 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-f41.google.com with SMTP id 006d021491bc7-6b1afdf5196so869357eaf.2 for ; Sun, 15 Nov 2026 01:06:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794733613; x=1795338413; 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=BBxyn6y7ZkX0H+LtsmtdiIqhF+qUouOJk/mKnU+HjUYZBiuSiCc7ewPTsIdYUzQ5W7 wkI4+aL6F8cdd3KCowxmS3gUSceWd6fhpOlWE7ThOrpRhkuRdgszsHLpKN3tZ/yzKJW9 1VAbghknBFKB8+hOchAxfm4+5hmvHerYYBAYLGf3F+pkSTChiHainYJiOJM/G1HNLI03 hf0yb729Dk5Qtu6GnCZWE4Cd4auRLK3qKF5RLEe6Zi6weFicSwbuqOW6abx3Mn3abeEd bw9nWWLskcnnm0p0cWWCbKW6OkWnX7eZakGry5aGyx55ypL/9/QZDM6hBLcp/spN8kU/ a7VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794733613; x=1795338413; 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=2KA3heHe2Zn6dkBHBlkiQ9Rdo2CpoU6nd1cfXOUfe76jssLK8YYVFocZFEkdnZ1Bu9 a2qqqmKE5E6aDyJ+RY0En7s/G0JN9LvRpktyKXInER0BpyHSlx70mVPW/0YEGQpYX7Ht a2Ux4O37Cct6kO3lenbvb+j3yaieIKQOlwvEiIp3p7YkDvlR3uZKylYskG9t3XjWvOr/ EjmCriGTTOVRsd0DS/vDx2bSGt1aSyCiNgvZsrmk2uNNlfxEyOAPAU1J5y4bnBNdwUr8 FHAwWgrlnz7mJjMKyBZljVk8Gor9yVVEmsh+4dETnEnP3dFdvRSD4b1OBZ18viVhQ0xD xYmQ== X-Forwarded-Encrypted: i=1; AL+hErGjweIWM3SUbeLVv3Mw+GadDai3DmBNrR23ZMXLNeE6H63FMrXJg0pBAZAjH89uxPmKOItxphXCAhl/3g==@lists.linux.dev X-Gm-Message-State: APuU4Z/LNGgK/tC5xw3F68OYfiL4QAvOUFHeH3iJTdVc8nKPVzkGzT/1 xDWDkMX4mm2XXkLcmut2WtXngrCenYFI1awzhxYL+09BKO0/5TSwfjAI X-Gm-Gg: AYBFou12mjA+ALX5xWDcFrGxeYnSYfCT/qm3+gGX4SFFXHR7ybNxsibHFtg8Kongd+Z 5TEqJMaQ0NMZhkqgRCc4rfkkaM/gQV+WP+mYb430UtGDJgaDFWqxQSgrI+T9ZX2P3kwLoZg+nUL 6Td3yncw2U8ZPc8t2iGum6jgSz34UzojecHlXaXJ2AUMp5/SYH3d0tcZfGWVm3Yzzkxl0iR9Waf O1MNKpdGGHWS3mj946BLoeI4lXjCTsUabzBlZrRknWwdDqXV8brppWrv1oyB97fOGdoc7eshXgk kw0Y4CPA5M40wGkMvXTpCRORcHaRzU2TGiYtVjadmlnp+5nt2fmNQQEYuvk8MGzMksQZyR2P4By sraIUG9yr+Q88MhaEhS42s35uLnLj4FvGSNPovDs5UhhnF93ZQ3SeL8wx/RbzwoPfVZAUiU3hLi Ghc0NU7Es509ZVcZfQ/eXDc1lizLbMyLw5aszsKNLuSrV083DWsye93Z/Z6Vb7PRxgJS3C9jAGi 1pVUqiM6WVyR4e/vPu+wGCS8g23ycrQEC6/BfTYwLeudYfd3Ji7JpoMcZsnL7a8oFsGYXTWdDNP pDyo8iWwPiQ3DU2imoOm232c5+n2O9baNhRrYmU1nO3GL5cIFVpdkf7eERyyi/HZirRUYWflvBB ceQJhxVENE7kHfTjfZbSh1w1NiyFI6K6iX5ywvaIShXeubjfZ6E7gYKL8or771jDDfEJEjJAjmN ApASaWlhP8j14m5BJX17MDPxxSfTuSjGX5D4/SwLk2m0nMzwfFmkJO X-Received: by 2002:a05:6820:1c98:b0:716:d143:4692 with SMTP id 006d021491bc7-71ab50b23e5mr4407570eaf.33.1794733613075; Sun, 15 Nov 2026 01:06:53 -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-71ab4338765sm6198902eaf.14.2026.11.15.01.06.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Nov 2026 01:06:52 -0800 (PST) From: James Hilliard Date: Sun, 15 Nov 2026 02:06:35 -0700 Subject: [PATCH v2 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: <20261115-submit-sun4i-dma-callback-lifetime-v1-v2-2-fb7d258702f8@gmail.com> References: <20261115-submit-sun4i-dma-callback-lifetime-v1-v2-0-fb7d258702f8@gmail.com> In-Reply-To: <20261115-submit-sun4i-dma-callback-lifetime-v1-v2-0-fb7d258702f8@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.15.2 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.19 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[172.105.105.114: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)[]; FREEMAIL_CC(0.00)[vger.kernel.org,lists.infradead.org,lists.linux.dev,gmail.com]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWELVE(0.00)[13]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; TAGGED_RCPT(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; ASN(0.00)[asn:63949, ipnet:172.105.96.0/20, country:SG]; FREEMAIL_FROM(0.00)[gmail.com]; R_SPF_ALLOW(0.00)[+ip4:172.105.105.114]; TO_DN_SOME(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[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:+]; TAGGED_FROM(0.00)[bounces-27655-noreply=patchwork.local]; 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.105.105.114:from] X-Rspamd-Queue-Id: 52AD81C44E5 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 Sun Nov 15 09:06:36 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 4109 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id F40641C50BC for ; Sun, 15 Nov 2026 10:07:05 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-27656-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-27656-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id ADF993F1C7 for ; Sun, 15 Nov 2026 09:07:03 +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=1794733616; b=KL+g/p7aoYKBGT5YzSJByKC7+wHPHg7uIGTSx+3PyiFweFFZD1sjYsCTvgod4jlf3yaj q5dkvBiJaThkAebMtkr0+8vPbl0e7qoMSZrNn8aUkra+x5Epgvqz7tRIDwLR2wo8z9KpG ZsyfkJBcXaICx+erXGYxRME7B7Cu/fHrLnW5uSg0bEll5EPB+YBROyPEg/EvJGU+2X9Uq G47Ot5U4ODDdg6brNHKUZ7ECAydrD9gLzY3UvZE6t30pMyGBF3iuEPXDbR6ivfhPMuZI1 t0kZzNeRvoTP/z38JeTLRil01bNf2SOmW6Mvx1h5CXDUx4sUQ0GoUxn+f0HQOiCn3zQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794733616; 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=QjeGO/xrP2P5tPm6o+agGakCFqZAu7v7HnjmdbzGyp1TuqOj7tJ91riTn83gEFKRk1Gp mrBtxFYrU6BnTrjqBzMlsYShmOHOrYhIUU5ITwEtT+YAUctNG3RYlC/SVylo5rR4E7dbX GfdOJhJWikFzE9EB6ixK/+JGlUxowyzCtyrwTtu3C4Unka4deKWicvK/O1NmbYywWO7EQ Rrsgo3w59/VeC93pk3S7/jojZr7sXbWNHfKlWhpIetJh7kn2t4p0E/uN9zNJq2OMLOOxu XFuA5SZdy3W+wzyjWDLjEoyqDy2Rcy83qMWPjXxVZp4mNsrrqrd0bXpBlWCB25+J69g== 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=ZfJRIxCJ; 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 DE6F1606A89C; Sun, 15 Nov 2026 09:06:55 +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=ZfJRIxCJ 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=1794733615; b=uGpPIN8KI7KoLNBXRsM+uYq7qR6S3Ehls7iQR3zJAQFZ++2m7MJWxwqK+qio1xWGXQeC gahMv9FFLiGXiKIfLSvKLFlG7jlVYaXE2rkplxmjnGPv0Och53xmRyWKzFg2QJUd3OI6k LOiCDyuYoOUp9hopE4QwTBFhOmpIGIImqoV8Rbo17SLlCoOc4oqB3Gs2cCdIAOhEeZ3UQ /epTltRsi/EBiJBb3UE0lqbLXw0XTa4bfoVcbYX4RfpOjaHxr2v/8Uz+36XaljWai2IRg YUPgHAfhINYtBrLZ8kQqngQVBc2GT8tgU32ALdwIRkLpE+wTA8u/J7hnS36rZygx0pQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794733615; 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=sJ9c2oYiCHlE1sOxWaQzQYmTZW1K4aZMATzEovS9Na3lits0SDOhy5cPYL7X9NhmO+HX 77Q2yhTlH6jDibGmzrJmrxxz/ZRnIw8Ot8hz4cKut+jQzW1DuMDFPyNFyB1MXDBIrVr8k 4re8DJlQxvmurmFJqDPbBev3/FJrZrJk7h1s9ulgJlVf/nbdQ1bxi/jfP39WGZfrVKkS3 fFLxwf2jH1CrK+Dfp8UU/5YuQGTVOcHdfttpS0AHqFzY5mUTmuHAGFJx4dLL4MSvGY9tR tEPh4A3Cbb4adTOHhRfYsn7PTurQuJtZyysQ7s2zbadQX6kl3QyuoB/OQTHlmCWdM3w== 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=ZfJRIxCJ; 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 77EFC606A89A for ; Sun, 15 Nov 2026 09:06:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 77EFC606A89A 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-71acdd32a53so425530eaf.3 for ; Sun, 15 Nov 2026 01:06:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794733614; x=1795338414; 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=ZfJRIxCJYH1a3DmTrGUDEaBHSRapN8gXKfZcRCft24g07OxNdcxnNF6YJFVcdc8ZAf p3fmKZ/b2kppytWD458Km/777WTFP4ANkUEDvCtmBbtulvAbGqXyPPiJkF0f38sOzi3Q JFu+5tLHRl8lRN97sf3EuTJIm33r/jgy8DDVXijYsjPaGkmz07uwlwldFyGm/ZvqXqeV TCuOZ9dfO8y5m1ctSBT6WFa6UJDe/FeeedAZs0XcgQX06Dm5m0Z5jKw11BP4bxknF2oj kW7kR1exsXMj4zEdl+m8KSxyIIe8DEgXxb6p3US0gwFRVgYnKktQ/xe3YjT5FL/NwmzE noJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794733614; x=1795338414; 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=ayRN0BRDPHpHnXHkdw6rBaOahuTOBHB5L2uwCc5JXjWzbOvsyQvu+lxKRLn/Q+m0v4 1/OQlX2gBJp32xqDe6D9+gXr1HwPQXOHR1MrzQ+EPqGnFHG5ISGEzAwgaD1Vm8LZoTH6 mJxWyBm844RFfT5QPpcZO0wS3akNJYf1xYuwn8tz/zVZas49NicOWgj1DrQaMi9Bp5xf g0Wi1ZaxFsGLWP8FaJ8rDHBD//42A2bnWtmZ94gjMRVHWL0UY/TUBA/saQFro4fGBEEf B154wlzwyRCr4s41Ar1j4ag6fE2ZNbj+ZJoa/tIkvCqyNuNBwAnqueOQrsuhsINGBvf2 4dxg== X-Forwarded-Encrypted: i=1; AL+hErGXcdJTKavjqC9VRAq6OzYvS9ROdLaOrcmR1KeGLgEyChbB+6jh+ulF2b6p2zHloBRmt61Lma4n6O+63w==@lists.linux.dev X-Gm-Message-State: APuU4Z/OLy6YGp10A4uuaB2IU9sSOTNDbzS0Brk3LRoJTuKu07Tr4Mzk QBOU9aG+ucvwJN4tc1+zTFHwLQ4PV7SC9o90mGjZArvdbxRSupowQzbi X-Gm-Gg: AYBFou092Og1bsZhlOeY/qfW2dixwanMRIZCgGlWmiiXflRFRzCbe4KZSlLDWy314Xj wTGccDMfTsYsZmaPXwlopi1XninX+xGNCId/WURR5z6ACnPuCiE6PWhiX5h46D3MBKXa/HPwUcN XTkQSikA3nNbxrLVR4TRS461U5ihkSEjNLb/oukiaFnJw/sLL/zn0J3mO2TKNpbwxdiZXEjThN+ ikp85W1YDDo/keXMqKwbVh2G/Lz8c/3NbZCkt3f/Q50JGOGBBnEezj3HCEmw3URDbpQh0+uooUs 3BKGyN1Vbiw/6NpSZQWgM/DGoiaWQuzQu/JtFZhelpKIbtesa8kbuchLc7hoetaf5iqIvzI54KU LUhZKaDjBSffuzQVlI1xT8jN/boguVxdx0Htl1Pl5jCloK04pNNlAFe5xnElQ9ZJeeZBtTRvt8i F5rQhI0KBz47hM3wtrJ0cLjaNTysA0bMwM9vyCtszAYor50AQmkhIGiPNJTjcI+AVd+/xDfvPcQ WCoBrDw1FScdZb02iLFXnUMf0s2nEgch4GssL+lWmAD8paWNPjm2+ELowgu6QlQbXUP29Oa5n3F xmEL+Cf9mEEMThP7HRiI5tWoTOG0JsVxnyGJLv/hFfaleY6v7SJXnMVdbb+M8YnDpQKKaIxVRTH ESSxwFDQc3T2+FcjwZESH166ycPqyC+yTrZ7QaWcFiPpy3wwoxHmmNVbkyOQZEAEX5XZ4urO7de WKxL6xVOLpxcyvZNoFO6fyDikacGAuO7IPyuzUhvwqU4Cjuf3RfX7v X-Received: by 2002:a05:6820:1caa:b0:71a:e9eb:6b9b with SMTP id 006d021491bc7-71ae9eb6f5amr480181eaf.21.1794733614395; Sun, 15 Nov 2026 01:06:54 -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-71ab4338765sm6198902eaf.14.2026.11.15.01.06.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Nov 2026 01:06:53 -0800 (PST) From: James Hilliard Date: Sun, 15 Nov 2026 02:06:36 -0700 Subject: [PATCH v2 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: <20261115-submit-sun4i-dma-callback-lifetime-v1-v2-3-fb7d258702f8@gmail.com> References: <20261115-submit-sun4i-dma-callback-lifetime-v1-v2-0-fb7d258702f8@gmail.com> In-Reply-To: <20261115-submit-sun4i-dma-callback-lifetime-v1-v2-0-fb7d258702f8@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.15.2 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.19 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[172.105.105.114: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)[]; FREEMAIL_CC(0.00)[vger.kernel.org,lists.infradead.org,lists.linux.dev,gmail.com]; FROM_HAS_DN(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[]; RCPT_COUNT_TWELVE(0.00)[13]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc20261015:i=2]; TAGGED_RCPT(0.00)[]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; RCVD_COUNT_FIVE(0.00)[6]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-27656-noreply=patchwork.local]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:172.105.105.114:c]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.105.105.114:from]; ASN(0.00)[asn:63949, ipnet:172.105.96.0/20, 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: F40641C50BC 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