Linux virtualization list
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@collabora.com>
To: "Christian König" <ckoenig.leichtzumerken@gmail.com>
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
Date: Wed, 2 Dec 2026 09:37:07 +0100	[thread overview]
Message-ID: <20261202093707.6967cdc3@fedora1.home> (raw)
In-Reply-To: <20261201165600.9415-1-christian.koenig@amd.com>

On Tue,  1 Dec 2026 17:55:59 +0100
"Christian König" <ckoenig.leichtzumerken@gmail.com> wrote:

> The macro dma_fence_unwrap_for_each() is used to deep dive into fences in
> chain and array containers.
> 
> 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.
> 
> Some code implemented dropping the reference manually, but Erhan now found
> another issue in an error path in amdgpu.
> 
> 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.
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>

Thanks for pushing that through, I've rebased my panthor changes on top
and will post a new version shortly.

> Reported-by: Erhan Bilgili <erhan.bilgili@gmail.com>
> ---
>  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 <boris.brezillon@collabora.com>

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.

  parent reply	other threads:[~2026-12-02  8:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 16:55 [PATCH] dma-buf: improve robustness of dma_fence_unwrap_for_each Christian König
2026-12-01 17:03 ` sashiko-bot
2026-12-02  8:37 ` Boris Brezillon [this message]
2026-12-02  9:01 ` Tvrtko Ursulin
2026-12-02 12:43   ` Christian König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202093707.6967cdc3@fedora1.home \
    --to=boris.brezillon@collabora.com \
    --cc=alessio.belle@imgtec.com \
    --cc=christian.koenig@amd.com \
    --cc=ckoenig.leichtzumerken@gmail.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=erhan.bilgili@gmail.com \
    --cc=gurchetansingh@chromium.org \
    --cc=imagination@lists.freedesktop.org \
    --cc=kraxel@redhat.com \
    --cc=linux-tegra@vger.kernel.org \
    --cc=luigi.santivetti@imgtec.com \
    --cc=mperttunen@nvidia.com \
    --cc=phasta@mailbox.org \
    --cc=sumit.semwal@linaro.org \
    --cc=thierry.reding@kernel.org \
    --cc=tursulin@ursulin.net \
    --cc=virtualization@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox