All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Bin Luo (University of Electronic Science and Technology of China)" <luob87709@gmail.com>
To: jani.nikula@linux.intel.com
Cc: rodrigo.vivi@intel.com, intel-gfx@lists.freedesktop.org,
	intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] drm/i915/display: hold frontbuffer ref across dirtyfb fence callback
Date: Sat, 28 Nov 2026 18:04:29 +0800	[thread overview]
Message-ID: <20261128100429.689-1-luob87709@gmail.com> (raw)
In-Reply-To: <8247d106ca535db291d2f85a3b8bea7956c6ccd8@intel.com>

Hi Jani,

On Fri, Nov 27, 2026 at 04:17:21PM +0200, Jani Nikula wrote:
> On Fri, 27 Nov 2026, "Bin Luo (University of Electronic Science and Technology of China)" <luob87709@gmail.com> wrote:
> > intel_user_framebuffer_dirty() stores the raw intel_frontbuffer pointer
> > in frontbuffer_fence_cb without taking a frontbuffer reference. If the
> > framebuffer is destroyed and its owner frontbuffer reference is dropped
> > before the reservation dma_fence signals,
> > intel_user_framebuffer_fence_wake() passes a freed intel_frontbuffer
> > pointer to intel_frontbuffer_queue_flush(), causing a use-after-free.
> 
> Please describe a real world scenario where this "if" can happen.

1. Framebuffer fb1 is currently scanned out on a plane (so
   atomic_read(&front->bits) != 0), and its BO has an unsignaled write
   dma_fence in obj->resv:
   - On xe, any normal in-flight GPU render job to fb1's BO suffices,
     because xe_frontbuffer has no i915_active front->write tracker
     holding a reference to front.
   - On i915 (as well as xe), an imported DMA-BUF / PRIME fence from
     another GPU or a sync_file imported via DMA_BUF_IOCTL_IMPORT_SYNC_FILE
     likewise does not take a frontbuffer reference via front->write.

2. Userspace issues DRM_IOCTL_MODE_DIRTYFB on fb1:
   - intel_user_framebuffer_dirty() fetches the unsignaled singleton
     fence from obj->resv, attaches intel_user_framebuffer_fence_wake()
     with the raw cb->front pointer, and returns 0.
   - drm_mode_dirtyfb_ioctl() immediately drops its temporary fb1
     reference via drm_framebuffer_put(fb1).

3. Before that fence signals (e.g., a render job taking >1 vblank or a
   slow/stalled external DMA-BUF fence), userspace flips the plane to
   another framebuffer fb2 (or disables the CRTC / closes the DRM fd)
   and removes fb1 via DRM_IOCTL_MODE_RMFB (or drm_fb_release()).
   - The atomic commit only waits on fb2's fence (if any) and the
     vblank, not on the old fb1's obj->resv fences.

4. Once vblank completes, intel_cleanup_plane_fb() drops the plane's
   reference to fb1, fb1's refcount hits zero, and
   intel_user_framebuffer_destroy() calls
   intel_parent_frontbuffer_put(display, intel_fb->frontbuffer).
   - Because nothing else holds a reference to front (on xe,
     intel_fb->frontbuffer is the sole reference until
     intel_frontbuffer_queue_flush() runs; on i915, foreign DMA-BUF
     fences do not hold front->write), frontbuffer_release() frees
     front (kfree() on xe, kfree_rcu() on i915) while cb->base is still
     attached to the unsignaled fence.

5. When the fence later signals (normal completion or GPU reset),
   intel_user_framebuffer_fence_wake() passes the freed cb->front to
   intel_frontbuffer_queue_flush().

If you agree this scenario is worth fixing, I can also send a v3 that
includes this scenario in the commit message and removes the now-unused
intel_frontbuffer_queue_flush() / intel_frontbuffer_flush_work() /
flush_work dead code noted by Sashiko.

Best regards,
Bin Luo

      reply	other threads:[~2026-11-28 10:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 13:39 [PATCH v2] drm/i915/display: hold frontbuffer ref across dirtyfb fence callback Bin Luo (University of Electronic Science and Technology of China)
2026-11-27 13:55 ` sashiko-bot
2026-11-27 14:17 ` Jani Nikula
2026-11-28 10:04   ` Bin Luo (University of Electronic Science and Technology of China) [this message]

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=20261128100429.689-1-luob87709@gmail.com \
    --to=luob87709@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rodrigo.vivi@intel.com \
    /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.