From: Simona Vetter <simona.vetter@ffwll.ch>
To: "Christian König" <ckoenig.leichtzumerken@gmail.com>
Cc: jani.saarinen@intel.com, jani.nikula@linux.intel.com,
tursulin@ursulin.net, simona.vetter@ffwll.ch,
tzimmermann@suse.de, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/prime: fix drm_prime_add_buf_handle
Date: Fri, 13 Jun 2025 16:10:22 +0200 [thread overview]
Message-ID: <aEwxTkK3w19L1_T2@phenom.ffwll.local> (raw)
In-Reply-To: <aEwv_sV3V6p8dmkP@phenom.ffwll.local>
On Fri, Jun 13, 2025 at 04:04:46PM +0200, Simona Vetter wrote:
> On Fri, Jun 13, 2025 at 03:12:01PM +0200, Christian König wrote:
> > It is possible through flink or IOCTLs like MODE_GETFB2 to create
> > multiple handles for the same underlying GEM object.
> >
> > But in prime we explicitely don't want to have multiple handles for the
> > same DMA-buf. So just ignore it if a DMA-buf is exported with another
> > handle.
> >
> > This was made obvious by removing the extra check in
> > drm_gem_prime_handle_to_dmabuf() to not add the handle if we could already
> > find it in the housekeeping structures.
> >
> > Signed-off-by: Christian König <christian.koenig@amd.com>
> > ---
> > drivers/gpu/drm/drm_prime.c | 11 +++++++++++
> > 1 file changed, 11 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
> > index 1d93b44c00c4..f5f30d947b61 100644
> > --- a/drivers/gpu/drm/drm_prime.c
> > +++ b/drivers/gpu/drm/drm_prime.c
> > @@ -113,6 +113,17 @@ static int drm_prime_add_buf_handle(struct drm_prime_file_private *prime_fpriv,
> >
> > rb = *p;
> > pos = rb_entry(rb, struct drm_prime_member, dmabuf_rb);
> > +
> > + /*
> > + * Just ignore the new handle if we already have an handle for
> > + * this DMA-buf.
> > + */
> > + if (dma_buf == pos->dma_buf) {
> > + dma_buf_put(dma_buf);
> > + kfree(member);
> > + return 0;
>
> This feels a bit brittle, because this case should only be possible when
> called from drm_gem_prime_handle_to_dmabuf and not from
> drm_gem_prime_fd_to_handle() (where it would indicate a real race and
> hence bug in our code).
>
> I think drm_gem_prime_fd_to_handle() should WARN_ON if it hits this case.
Simplest would be to return -EEXISTS here and then either silence that
errno or warn about it in the two call sites. Not pretty, but everything
else looks worse.
-Sima
>
> Otherwise yes this is the functional change that I've missed :-/ Note that
> there's no race in the original code, because it's all protected by the
> file_priv->prime.lock. Which means I think you're claim that you've only
> widened the race with your patch is wrong.
>
> Cheers, Sima
>
> > +
> > + }
> > if (dma_buf > pos->dma_buf)
> > p = &rb->rb_right;
> > else
> > --
> > 2.34.1
> >
>
> --
> Simona Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch
--
Simona Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
next prev parent reply other threads:[~2025-06-13 14:10 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-13 13:12 Trying to fix drm/prime: remove drm_prime_lookup_buf_by_handle Christian König
2025-06-13 13:12 ` [PATCH] drm/prime: fix drm_prime_add_buf_handle Christian König
2025-06-13 14:04 ` Simona Vetter
2025-06-13 14:10 ` Simona Vetter [this message]
2025-06-17 14:11 ` Simona Vetter
2025-06-17 14:29 ` Simona Vetter
2025-06-13 14:12 ` Christian König
2025-06-13 14:35 ` Simona Vetter
2025-06-13 15:03 ` Christian König
2025-06-16 10:38 ` Simona Vetter
2025-06-16 11:38 ` Christian König
2025-06-17 13:55 ` Simona Vetter
2025-06-13 14:32 ` Trying to fix drm/prime: remove drm_prime_lookup_buf_by_handle Saarinen, Jani
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=aEwxTkK3w19L1_T2@phenom.ffwll.local \
--to=simona.vetter@ffwll.ch \
--cc=ckoenig.leichtzumerken@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=jani.saarinen@intel.com \
--cc=tursulin@ursulin.net \
--cc=tzimmermann@suse.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.