From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.251.105.195 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796200636; b=W+X55ZjbhiNPN2L/8lrYd3Yzx0+j9mNHuDeB4a5M/sZZoS52ksIP/Wge4SUKawj+N3x0 api9sEGkhwZJkmbbY9HvJX3y6pwg2Wrc9yDV8R03eKtM0FbBu6/MQXuE43a4sV9jvWBkX kGbGrUMr/R5DqqBXV0FZ7AWxnOdVI9LkUJP4MhexbUYtszGNGWWjHRBq1K/MPBou+7q+a ZF3mxE3bs/6uTbG4Eil+R8gdczVlowFV7WT19UqAeuEFce9Hx0nLkRBpTluEuuwCSkci7 hso1IKmm5Ao/Bj0KktAbR9q3fnwJlY2bwWgOPOa9pMFoz1GyQZ17kTSU9lgJkjSVmdw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796200636; h=DMARC-Filter:DKIM-Signature:Received:Date:From:To:Cc:Subject: Message-ID:In-Reply-To:References:Organization:X-Mailer:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=y6ewwwk4cb/JUZbHxLNwMyOgmjBC+ZSMYM1KqVu7b5M=; b=VTAo8GTFH4RU/8qxGsHoWsWq5CRbKrGqQa5mtKlHEjzwg/BbGfyxm9Txw25MIHP1kQab UMLhQxDz5AG1S57pgIjhMrH8Ro4hSPLeMT4y7LTL1k/hNqqcs+ttpsG0qTtZIBNr0C7vX NyDHazhrgKD9Yx2PFqYm7r6TUsosV0qm+y3sj7+ZogalCSS5lhi8lz6eLd1ow7TGw8vZ5 rfKS3LKev1y7vBIzeuWJdjHOLFinzXeIiL0Bo13Yu0T3LzrdfD3NMCfEIowTzlOy+0mkT lotO12ddvpIxCzkEKlgjQk17kmprGCUg83Gxolm0AfBsE7BkCteYQgl4qBfvc9p+ajg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=CbMrLDCi; arc=none smtp.remote-ip=148.251.105.195 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71140606A323 for ; Wed, 2 Dec 2026 08:37:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 71140606A323 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=CbMrLDCi DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1796200633; bh=bvB3iStdbhdGBw+fnPU3Qq5Gxx3Dl3N5pwsSJnHjCgc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=CbMrLDCi3QM6YFbOJr/zmgPC3CWHNrCz6xdnbmdIBM4py/bELLMX9KYCfgh+0MYAs 5HcYiNC7+s508gEWoq8EiwaomQhKu3mTmiaEYhPWSrjQYiWFhnyvShgK6dBHye3s2O Ga2M8fK2JGzPn0My+wMHRE8Wi0xVYlHc95qtC7rXADkdCCZqDu1xJlN2HR8urlHH5G kMuRI8vyKKh0KkpOuGBbjA82xl/xL1BPf4jEI/YsxMoXYndcrjTcvSxwOm2NqHgK/W m9qb6b0fMy1AGXSm+tZPkMnWxSpsq7ImwWNka/5K6Ks18xW54ol9BF0vd47DINLlhv XC7MSaJvW9jcw== Received: from fedora1.home (unknown [100.64.0.11]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange secp256r1 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bbrezillon) by bali.collaboradmins.com (Postfix) with ESMTPSA id BC18B17E03F1; Wed, 02 Dec 2026 09:37:12 +0100 (CET) Date: Wed, 2 Dec 2026 09:37:07 +0100 From: Boris Brezillon To: "Christian =?UTF-8?B?S8O2bmln?=" Cc: christian.koenig@amd.com, tursulin@ursulin.net, phasta@mailbox.org, dakr@kernel.org, erhan.bilgili@gmail.com, sumit.semwal@linaro.org, alessio.belle@imgtec.com, luigi.santivetti@imgtec.com, thierry.reding@kernel.org, mperttunen@nvidia.com, kraxel@redhat.com, gurchetansingh@chromium.org, dri-devel@lists.freedesktop.org, imagination@lists.freedesktop.org, linux-tegra@vger.kernel.org, virtualization@lists.linux.dev Subject: Re: [PATCH] dma-buf: improve robustness of dma_fence_unwrap_for_each Message-ID: <20261202093707.6967cdc3@fedora1.home> In-Reply-To: <20261201165600.9415-1-christian.koenig@amd.com> References: <20261201165600.9415-1-christian.koenig@amd.com> Organization: Collabora X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-redhat-linux-gnu) X-Mailing-List: linux-tegra@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 On Tue, 1 Dec 2026 17:55:59 +0100 "Christian K=C3=B6nig" wrote: > The macro dma_fence_unwrap_for_each() is used to deep dive into fences in > chain and array containers. >=20 > To guarantee correct functionality it does this by keeping a reference to > chain elements in the iterator structure. But so far there was no well > defined cleanup procedure for the iterator when breaking out of the loop > early. >=20 > Some code implemented dropping the reference manually, but Erhan now found > another issue in an error path in amdgpu. >=20 > Fix this for good, provide a proper cleanup function which is > automatically used with a guard and remove the workarounds spread around > in the calling code. >=20 > Signed-off-by: Christian K=C3=B6nig Thanks for pushing that through, I've rebased my panthor changes on top and will post a new version shortly. > Reported-by: Erhan Bilgili > --- > drivers/dma-buf/dma-buf.c | 5 +- > drivers/dma-buf/dma-fence-unwrap.c | 58 ++++++++++++------- > drivers/dma-buf/st-dma-fence-unwrap.c | 27 +++------ > drivers/dma-buf/sync_file.c | 5 +- > .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 6 +- > drivers/gpu/drm/imagination/pvr_sync.c | 14 ++--- > drivers/gpu/drm/tegra/submit.c | 6 +- > drivers/gpu/drm/virtio/virtgpu_submit.c | 7 +-- > include/linux/dma-fence-unwrap.h | 35 ++++++----- The core changes are Reviewed-by: Boris Brezillon just one comment below. > +/** > + * dma_fence_unwrap_cleanup - cleanup the cursor should we exit early > + * @cursor: current position inside the containers > + * > + * Drop the fence reference inside the cursor should we exit the unwrap = loop > + * early. > + */ > +void dma_fence_unwrap_cleanup(struct dma_fence_unwrap *cursor) > +{ > + dma_fence_put(cursor->chain); > +} > +EXPORT_SYMBOL_GPL(dma_fence_unwrap_cleanup); This feels like a good candidate for a static inline declaration in dma-fence-unwrap.h. This way, the compiler can see through it and inline things. I guess LTO could to that too, but I tend to think it's slightly better when this sort of inlining is done at compile time.