All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] drm/vc4: Fix async page flip completion
@ 2026-11-12 12:56 Maíra Canal
  2026-11-12 12:56 ` [PATCH 1/2] drm/vc4: Drop BO usecnt before releasing the old FB Maíra Canal
  2026-11-12 12:56 ` [PATCH 2/2] drm/vc4: Complete async page flips from an ordered workqueue Maíra Canal
  0 siblings, 2 replies; 4+ messages in thread
From: Maíra Canal @ 2026-11-12 12:56 UTC (permalink / raw)
  To: Iago Toral, Melissa Wen, Maxime Ripard, Dave Stevenson,
	Raspberry Pi Kernel Maintenance, Maarten Lankhorst,
	Thomas Zimmermann, David Airlie, Simona Vetter
  Cc: kernel-dev, dri-devel, stable, Maíra Canal

VC4 implements async page flips with a custom code path that waits for
the BO fence before completing the flip. On VC4_GEN_4 (RPi 0-3), the
completion also decrements the usecnt of the old FB's BO. This series
fixes two bugs in that path.

Since commit e8941ac97f28 ("drm/vc4: Remove BOs seqnos"), the completion
runs from a dma_fence callback. VC4 signals that fence from the render
job IRQ handler. As vc4_bo_dec_usecnt() takes a mutex, running an SDL
application with SDL_VIDEODRIVER=kmsdrm on the RPi 3 triggers:

  [ 2511.636319] BUG: sleeping function called from invalid context at kernel/locking/mutex.c:623
  [ 2511.636667] in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 0, name: swapper/0
  [ 2511.636681] preempt_count: 1000002, expected: 0
  [ 2511.636689] RCU nest depth: 0, expected: 0
  [ 2511.636698] locks held by swapper/0/0: 1, on CPU#0:
  [ 2511.636711]  #0: ffff000037183198 (&fence->inline_lock){-...}-{3:3}, at: dma_fence_signal+0x88/0xec
  <snip>
  [ 2511.636892] Hardware name: Raspberry Pi 3 Model B Plus Rev 1.3 (DT)
  [ 2511.636899] Call trace:
  <snip>
  [ 2511.636991]  mutex_lock_nested+0x24/0x30
  [ 2511.637002]  vc4_bo_dec_usecnt+0x40/0x124 [vc4]
  [ 2511.637070]  vc4_async_page_flip_complete_with_cleanup+0xa0/0xc4 [vc4]
  [ 2511.637102]  dma_fence_signal_timestamp_locked+0x118/0x290
  [ 2511.637116]  dma_fence_signal+0x9c/0xec
  [ 2511.637126]  vc4_irq_render_job_done+0x24/0x114 [vc4]
  [ 2511.637158]  vc4_irq+0x16c/0x274 [vc4]

While looking into this issue, I also noticed that, since commit
4d12c36fb73b ("drm/vc4: crtc: Move the BO handling out of common page-flip
callback"), the old FB is released before decrementing its BO usecnt. If
userspace removes the old FB and closes its handle while the flip is
pending, vc4_bo_dec_usecnt() runs on a freed or recycled BO.

Patch 1 fixes the use-after-free and patch 2 moves the completion to a
worker. The UAF fix comes first, as it affects older stable kernels that
don't have the dma_fence-based completion.

Best regards,
- Maíra

---
Maíra Canal (2):
      drm/vc4: Drop BO usecnt before releasing the old FB
      drm/vc4: Complete async page flips from an ordered workqueue

 drivers/gpu/drm/vc4/vc4_crtc.c | 108 ++++++++++++++++++++---------------------
 drivers/gpu/drm/vc4/vc4_drv.h  |   6 +++
 2 files changed, 58 insertions(+), 56 deletions(-)
---
base-commit: 8bf8cda54c08ee3693f4dd1e2b7607fe5e466c79
change-id: 20261111-vc4-async-flip-fixes-1b1ab17dc795


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-12 13:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 12:56 [PATCH 0/2] drm/vc4: Fix async page flip completion Maíra Canal
2026-11-12 12:56 ` [PATCH 1/2] drm/vc4: Drop BO usecnt before releasing the old FB Maíra Canal
2026-11-12 12:56 ` [PATCH 2/2] drm/vc4: Complete async page flips from an ordered workqueue Maíra Canal
2026-11-12 13:17   ` sashiko-bot

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.