All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] drm: Add Common drm_user_fence helper and Convert XE
@ 2026-08-27 13:32 Srinivasan Shanmugam
  2026-08-27 13:32 ` [PATCH v2 1/2] drm: Add common drm_user_fence helper Srinivasan Shanmugam
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Srinivasan Shanmugam @ 2026-08-27 13:32 UTC (permalink / raw)
  To: Christian König, Alex Deucher; +Cc: amd-gfx, Srinivasan Shanmugam

When a GPU dma-fence signals, drivers often need to access userspace
memory from a kthread context — either to write a fence completion
value to a userspace VA (XE) or to signal a per-queue eventfd (AMDGPU).
Both require borrowing the process MM via kthread_use_mm(), and both
use the same kref-managed dma-fence-callback-to-workqueue pattern.

Extracting this pattern into a shared DRM helper allows both XE and
AMDGPU to use it instead of maintaining independent open-coded
implementations.

This series does exactly that:

Patch 1 introduces drm_user_fence — an embeddable base structure with
driver-supplied worker/destroy callbacks. The common code handles:
 - process MM grab at init (mmgrab)
 - dma-fence callback registration
 - workqueue dispatch on fence signal
 - mmget_not_zero/kthread_use_mm/mmput in the worker
 - kref lifetime management
 - cancellation via drm_user_fence_cancel() for safe driver teardown

Patch 2 converts XE to use the new helper. struct xe_user_fence embeds
struct drm_user_fence as its base. XE-specific fields (xe_device pointer
for ufence_wq wake-up, userspace VA, expected value, signalled flag)
remain in the wrapper. No behavioral change is intended.

A follow-on patch (not in this series) will wire AMDGPU's render-node
EOP eventfd signaling path to the same helper.

v2:
 - Move INIT_WORK() to drm_user_fence_init() so the work_struct is
   initialized once at object creation, fixing lockdep class divergence
   caused by two different INIT_WORK() call sites. (Sashiko review)
 - drm_user_fence_add_callback() now consumes the fence reference in
   all paths: transferred to the callback on success, put immediately
   on the already-signaled and error paths. Callers must not put the
   fence after this call. (Sashiko review)
 - Add drm_user_fence_cancel() to allow drivers to safely detach a
   pending callback before context teardown, preventing use-after-free
   when a foreign dma-fence signals after driver unload. (Sashiko review)
 - Fix missing newline at end of new files.

Srinivasan Shanmugam (2):
  drm: Add common drm_user_fence helper
  drm/xe: Convert xe_user_fence to drm_user_fence

 drivers/gpu/drm/Makefile           |   1 +
 drivers/gpu/drm/drm_user_fence.c   | 164 +++++++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_sync.c       | 112 ++++++++------------
 drivers/gpu/drm/xe/xe_sync_types.h |   1 -
 include/drm/drm_user_fence.h       |  71 +++++++++++++
 5 files changed, 280 insertions(+), 69 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_user_fence.c
 create mode 100644 include/drm/drm_user_fence.h

-- 
2.34.1


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

end of thread, other threads:[~2026-08-27 15:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-27 13:32 [PATCH v2 0/2] drm: Add Common drm_user_fence helper and Convert XE Srinivasan Shanmugam
2026-08-27 13:32 ` [PATCH v2 1/2] drm: Add common drm_user_fence helper Srinivasan Shanmugam
2026-08-27 13:43   ` sashiko-bot
2026-08-27 13:32 ` [PATCH v2 2/2] drm/xe: Convert xe_user_fence to drm_user_fence Srinivasan Shanmugam
2026-08-27 13:43   ` sashiko-bot
2026-08-27 13:39 ` ✗ CI.checkpatch: warning for series starting with [v2,1/2] drm: Add common drm_user_fence helper Patchwork
2026-08-27 13:40 ` ✓ CI.KUnit: success " Patchwork
2026-08-27 14:31 ` ✓ Xe.CI.BAT: " Patchwork
2026-08-27 15:53 ` ✓ Xe.CI.FULL: " Patchwork

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.