UMD direct submission in Xe
Subsystems (5)
Matthew Brost
maintainercover UMD direct submission in Xe
This is an RFC, or possibly even a proof of concept, for UMD (User Mode Driver) direct submission in Xe. It is similar to AMD's design [1] [2] or ARM's design [3], utilizing a uAPI to convert user-space syncs (memory writes) to kernel-space syncs (DMA fences). It is built around the existing Xe preemption fences for dynamic memory management, such as userptr invalidation and buffer object (BO) eviction.
The series also enables mapping a PPGTT-bound submission ring in non-privileged mode, as well as exposing indirect ring state (such as ring head, tail, etc.) and the doorbell to user space, enabling UMD direct submission.
The target for this series is Mesa, with the goal of enabling UMD direct submission and removing the submission thread that currently handles future fences. I've discussed this with Sima and the Intel Mesa team, and it seems like a reachable target. Most synchronization will be handled in user space via memory writes and semaphore wait ring instructions, with only legacy cross-process synchronization (e.g., compositors) requiring kernel synchronization (DMA fences).
The series includes some common patches at the beginning to implement preemption fences and user fences. The idea of preemption DMA-reservation slots [4] has been dropped in favor of attaching the last exported DMA fence to the preemption fence as suggested by AMD.
This is a public checkpoint on the KMD (Kernel Mode Driver) work, which will be tabled until Intel's Mesa team has the bandwidth to begin the UMD work. That said, the uAPI is very preliminary and likely to change. One idea that was discussed is a common user fence interface based around DRM syncobjs, which will likely be explored further as UMD engagement begins. Some work for syncing VM binds (kernel operation) with UMD direct submission is also likely required.
Testing has been done with [5], and the main features—such as basic submission, dynamic memory management, user-to-kernel sync conversion, and protection against endless user fences—are working on BMG and LNL.
The GitLab branch [6] has also been pushed for reference.
Any early community feedback is always appreciated.
Matt
[1] https://patchwork.freedesktop.org/series/113675/
[2] https://patchwork.freedesktop.org/series/114385/
[3] https://patchwork.freedesktop.org/series/137924/
[4] https://patchwork.freedesktop.org/series/141129/
[5] https://patchwork.freedesktop.org/series/141518/
[6] https://gitlab.freedesktop.org/mbrost/xe-kernel-driver-umd-submission-post/-/tree/post-11-18-24?ref_type=heads
Matthew Brost (28):
dma-fence: Add dma_fence_preempt base class
dma-fence: Add dma_fence_user_fence
drm/xe: Use dma_fence_preempt base class
drm/xe: Allocate doorbells for UMD exec queues
drm/xe: Add doorbell ID to snapshot capture
drm/xe: Break submission ring out into its own BO
drm/xe: Break indirect ring state out into its own BO drm/xe: Clear GGTT in xe_bo_restore_kernel
FIXME: drm/xe: Add pad to ring and indirect state
drm/xe: Enable indirect ring on media GT
drm/xe: Don't add pinned mappings to VM bulk move
drm/xe: Add exec queue post init extension processing drm/xe: Add support for mmapping doorbells to user space drm/xe: Add support for mmapping submission ring and indirect ring
state to user space
drm/xe/uapi: Define UMD exec queue mapping uAPI
drm/xe: Add usermap exec queue extension
drm/xe: Drop EXEC_QUEUE_FLAG_UMD_SUBMISSION flag
drm/xe: Do not allow usermap exec queues in exec IOCTL drm/xe: Teach GuC backend to kill usermap queues
drm/xe: Enable preempt fences on usermap queues drm/xe/uapi: Add uAPI to convert user semaphore to / from drm syncobj drm/xe: Add user fence IRQ handler
drm/xe: Add xe_hw_fence_user_init
drm/xe: Add a message lock to the Xe GPU scheduler
drm/xe: Always wait on preempt fences in vma_check_userptr drm/xe: Teach xe_sync layer about drm_xe_semaphore
drm/xe: Add VM convert fence IOCTL
drm/xe: Add user fence TDR
Tejas Upadhyay (1):
drm/xe/mmap: Add mmap support for PCI memory barrier
drivers/dma-buf/Makefile | 2 +- drivers/dma-buf/dma-fence-preempt.c | 134 ++++++ drivers/dma-buf/dma-fence-user-fence.c | 73 ++++ drivers/gpu/drm/xe/xe_bo.c | 29 +- drivers/gpu/drm/xe/xe_bo.h | 5 + drivers/gpu/drm/xe/xe_bo_evict.c | 8 +- drivers/gpu/drm/xe/xe_device.c | 181 +++++++- drivers/gpu/drm/xe/xe_device_types.h | 3 + drivers/gpu/drm/xe/xe_exec.c | 3 +- drivers/gpu/drm/xe/xe_exec_queue.c | 175 +++++++- drivers/gpu/drm/xe/xe_exec_queue.h | 5 + drivers/gpu/drm/xe/xe_exec_queue_types.h | 13 + drivers/gpu/drm/xe/xe_execlist.c | 2 +- drivers/gpu/drm/xe/xe_ggtt.c | 19 +- drivers/gpu/drm/xe/xe_ggtt.h | 2 + drivers/gpu/drm/xe/xe_gpu_scheduler.c | 19 +- drivers/gpu/drm/xe/xe_gpu_scheduler.h | 12 +- drivers/gpu/drm/xe/xe_gpu_scheduler_types.h | 2 + drivers/gpu/drm/xe/xe_guc_exec_queue_types.h | 9 +- drivers/gpu/drm/xe/xe_guc_submit.c | 177 +++++++- drivers/gpu/drm/xe/xe_guc_submit_types.h | 2 + drivers/gpu/drm/xe/xe_hw_engine.c | 4 +- drivers/gpu/drm/xe/xe_hw_engine_group.c | 4 +- drivers/gpu/drm/xe/xe_hw_fence.c | 17 + drivers/gpu/drm/xe/xe_hw_fence.h | 3 + drivers/gpu/drm/xe/xe_lrc.c | 176 ++++++-- drivers/gpu/drm/xe/xe_lrc.h | 4 +- drivers/gpu/drm/xe/xe_lrc_types.h | 16 +- drivers/gpu/drm/xe/xe_pci.c | 1 + drivers/gpu/drm/xe/xe_preempt_fence.c | 89 ++-- drivers/gpu/drm/xe/xe_preempt_fence.h | 2 +- drivers/gpu/drm/xe/xe_preempt_fence_types.h | 11 +- drivers/gpu/drm/xe/xe_pt.c | 5 +- drivers/gpu/drm/xe/xe_sync.c | 90 ++++ drivers/gpu/drm/xe/xe_sync.h | 8 + drivers/gpu/drm/xe/xe_sync_types.h | 5 +- drivers/gpu/drm/xe/xe_vm.c | 423 ++++++++++++++++++- drivers/gpu/drm/xe/xe_vm.h | 4 +- drivers/gpu/drm/xe/xe_vm_types.h | 26 ++ include/linux/dma-fence-preempt.h | 56 +++ include/linux/dma-fence-user-fence.h | 31 ++ include/uapi/drm/xe_drm.h | 147 ++++++- 42 files changed, 1798 insertions(+), 199 deletions(-) create mode 100644 drivers/dma-buf/dma-fence-preempt.c create mode 100644 drivers/dma-buf/dma-fence-user-fence.c create mode 100644 include/linux/dma-fence-preempt.h create mode 100644 include/linux/dma-fence-user-fence.h
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 1/29 dma-fence: Add dma_fence_preempt base class
Add a dma_fence_preempt base class with driver ops to implement preemption, based on the existing Xe preemptive fence implementation.
Annotated to ensure correct driver usage.
--- drivers/dma-buf/Makefile | 2 +- drivers/dma-buf/dma-fence-preempt.c | 133 ++++++++++++++++++++++++++++ include/linux/dma-fence-preempt.h | 56 ++++++++++++ 3 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 drivers/dma-buf/dma-fence-preempt.c create mode 100644 include/linux/dma-fence-preempt.h
drivers/dma-buf/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only obj-y := dma-buf.o dma-fence.o dma-fence-array.o dma-fence-chain.o \ - dma-fence-unwrap.o dma-resv.o + dma-fence-preempt.o dma-fence-unwrap.o dma-resv.o obj-$(CONFIG_DMABUF_HEAPS) += dma-heap.o obj-$(CONFIG_DMABUF_HEAPS) += heaps/ obj-$(CONFIG_SYNC_FILE) += sync_file.o
drivers/dma-buf/dma-fence-preempt.c new file +133 -0
133 lines not on this page · raw message
include/linux/dma-fence-preempt.h new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 2/29 dma-fence: Add dma_fence_user_fence
In reply to Matthew BrostNormalize user fence attachment to a DMA fence. A user fence is a simple seqno write to memory, implemented by attaching a DMA fence callback that writes out the seqno. Intended use case is importing a dma-fence into kernel and exporting a user fence.
Helpers added to allocate, attach, and free a dma_fence_user_fence.
--- drivers/dma-buf/Makefile | 2 +- drivers/dma-buf/dma-fence-user-fence.c | 73 ++++++++++++++++++++++++++ include/linux/dma-fence-user-fence.h | 31 +++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 drivers/dma-buf/dma-fence-user-fence.c create mode 100644 include/linux/dma-fence-user-fence.h
drivers/dma-buf/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only obj-y := dma-buf.o dma-fence.o dma-fence-array.o dma-fence-chain.o \ - dma-fence-preempt.o dma-fence-unwrap.o dma-resv.o + dma-fence-preempt.o dma-fence-unwrap.o dma-fence-user-fence.o dma-resv.o obj-$(CONFIG_DMABUF_HEAPS) += dma-heap.o obj-$(CONFIG_DMABUF_HEAPS) += heaps/ obj-$(CONFIG_SYNC_FILE) += sync_file.o
drivers/dma-buf/dma-fence-user-fence.c new file +73 -0
73 lines not on this page · raw message
include/linux/dma-fence-user-fence.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2024 Intel Corporation +*/ + +#ifndef __LINUX_DMA_FENCE_USER_FENCE_H +#define __LINUX_DMA_FENCE_USER_FENCE_H + +#include <linux/dma-fence.h> +#include <linux/iosys-map.h> + +/** struct dma_fence_user_fence - User fence */ +struct dma_fence_user_fence { +/** @cb: dma-fence callback used to attach user fence to dma-fence */ +struct dma_fence_cb cb; +/** @map: IOSYS map to write seqno to */ +struct iosys_map map; +/** @seqno: seqno to write to IOSYS map */ +u64 seqno; +}; + +struct dma_fence_user_fence *dma_fence_user_fence_alloc (void ); + +void dma_fence_user_fence_free (struct dma_fence_user_fence *user_fence); + +void dma_fence_user_fence_attach (struct dma_fence *fence, +struct dma_fence_user_fence *user_fence, +struct iosys_map *map, +u64 seqno); + +#endif
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 3/29 drm/xe: Use dma_fence_preempt base class
In reply to Matthew BrostUse the dma_fence_preempt base class in Xe instead of open-coding the preemption implementation.
--- drivers/dma-buf/dma-fence-preempt.c | 5 +- drivers/gpu/drm/xe/xe_guc_submit.c | 3 + drivers/gpu/drm/xe/xe_hw_engine_group.c | 4 +- drivers/gpu/drm/xe/xe_preempt_fence.c | 80 ++++++--------------- drivers/gpu/drm/xe/xe_preempt_fence.h | 2 +- drivers/gpu/drm/xe/xe_preempt_fence_types.h | 11 +-- 6 files changed, 34 insertions(+), 71 deletions(-)
drivers/dma-buf/dma-fence-preempt.c +3 -2
@@ -8,11 +8,11 @@static void dma_fence_preempt_work_func (struct work_struct *w) { -bool cookie =dma_fence_begin_signalling ();struct dma_fence_preempt *pfence =container_of (w,typeof (*pfence), work);const struct dma_fence_preempt_ops *ops = pfence->ops;int err = pfence->base.error; +bool cookie =dma_fence_begin_signalling ();if (!err) { err = ops->preempt_wait (pfence);
@@ -23,6 +23,7 @@ static void dma_fence_preempt_work_func(struct work_struct *w)dma_fence_signal (&pfence->base); ops->preempt_finished (pfence); +/* The entire worker is signaling path, thus annotate the entirety */ dma_fence_end_signalling (cookie); }
@@ -109,7 +110,7 @@ EXPORT_SYMBOL(dma_fence_is_preempt);* * @fence: Preempt fence * @ops: Preempt fence operations -* @wq: Work queue for preempt wait, should have WQ_MEM_RECLAIM set +* @wq: Work queue for preempt wait, must have WQ_MEM_RECLAIM set * @context: Fence context * @seqno: Fence seqence number */
drivers/gpu/drm/xe/xe_guc_submit.c +3 -0
@@ -1603,6 +1603,9 @@ static int guc_exec_queue_suspend_wait(struct xe_exec_queue *q)struct xe_guc *guc =exec_queue_to_guc (q);int ret; +if (exec_queue_reset (q) ||exec_queue_killed_or_banned_or_wedged (q)) +return -ECANCELED ; +/* * Likely don't need to check exec_queue_killed() as we clear * suspend_pending upon kill but to be paranoid but races in which
drivers/gpu/drm/xe/xe_hw_engine_group.c +2 -2
@@ -163,7 +163,7 @@ int xe_hw_engine_group_add_exec_queue(struct xe_hw_engine_group *group, struct xif (xe_vm_in_fault_mode (q->vm) && group->cur_mode ==EXEC_MODE_DMA_FENCE ) { q->ops->suspend (q); err = q->ops->suspend_wait (q); -if (err) +if (err == -ETIME ) goto err_suspend;xe_hw_engine_group_resume_faulting_lr_jobs (group);
@@ -236,7 +236,7 @@ static int xe_hw_engine_group_suspend_faulting_lr_jobs(struct xe_hw_engine_groupcontinue ; err = q->ops->suspend_wait (q); -if (err) +if (err == -ETIME ) goto err_suspend; }
drivers/gpu/drm/xe/xe_preempt_fence.c +23 -57
119 lines not on this page · raw message
drivers/gpu/drm/xe/xe_preempt_fence.h +1 -1
@@ -25,7 +25,7 @@ xe_preempt_fence_arm(struct xe_preempt_fence *pfence, struct xe_exec_queue *q,static inline struct xe_preempt_fence *to_preempt_fence (struct dma_fence *fence) { - return container_of(fence, struct xe_preempt_fence, base); + return container_of(fence, struct xe_preempt_fence, base.base); }/**
drivers/gpu/drm/xe/xe_preempt_fence_types.h +2 -9
@@ -6,8 +6,7 @@#ifndef _XE_PREEMPT_FENCE_TYPES_H_#define _XE_PREEMPT_FENCE_TYPES_H_ -#include <linux/dma-fence.h> -#include <linux/workqueue.h> +#include <linux/dma-fence-preempt.h> struct xe_exec_queue ;
@@ -18,17 +17,11 @@ struct xe_exec_queue;*/ struct xe_preempt_fence {/** @base: dma fence base */ -struct dma_fence base; +struct dma_fence_preempt base;/** @link: link into list of pending preempt fences */ struct list_head link;/** @q: exec queue for this preempt fence */ struct xe_exec_queue *q; -/** @preempt_work: work struct which issues preemption */ -struct work_struct preempt_work; -/** @lock: dma-fence fence lock */ -spinlock_t lock; -/** @error: preempt fence is in error state */ -int error; };#endif
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 4/29 drm/xe: Allocate doorbells for UMD exec queues
In reply to Matthew BrostThese will be mapped to user space for UMD submission. Add infrastructure to GuC submission backend to manage these.
--- drivers/gpu/drm/xe/xe_exec_queue_types.h | 2 + drivers/gpu/drm/xe/xe_guc_exec_queue_types.h | 7 ++ drivers/gpu/drm/xe/xe_guc_submit.c | 107 +++++++++++++++++-- 3 files changed, 106 insertions(+), 10 deletions(-)
drivers/gpu/drm/xe/xe_exec_queue_types.h +2 -0
@@ -83,6 +83,8 @@ struct xe_exec_queue {#define EXEC_QUEUE_FLAG_BIND_ENGINE_CHILD BIT(3)/* kernel exec_queue only, set priority to highest level */ #define EXEC_QUEUE_FLAG_HIGH_PRIORITY BIT(4) +/* queue used for UMD submission */ +#define EXEC_QUEUE_FLAG_UMD_SUBMISSION BIT(5)/** * @flags: flags for this exec queue, should statically setup aside from ban
drivers/gpu/drm/xe/xe_guc_exec_queue_types.h +7 -0
@@ -47,6 +47,13 @@ struct xe_guc_exec_queue {u16 id;/** @suspend_wait: wait queue used to wait on pending suspends */ wait_queue_head_t suspend_wait; +/** @db: doorbell state */ +struct { +/** @db.id: doorbell ID */ +int id; +/** @db.dpa: doorbell device physical address */ +u64 dpa; + } db;/** @suspend_pending: a suspend of the exec_queue is pending */ bool suspend_pending; };
drivers/gpu/drm/xe/xe_guc_submit.c +97 -10
181 lines not on this page · raw message
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 5/29 drm/xe: Add doorbell ID to snapshot capture
In reply to Matthew BrostUseful for debugging hangs with doorbells.
--- drivers/gpu/drm/xe/xe_guc_submit.c | 2 ++ drivers/gpu/drm/xe/xe_guc_submit_types.h | 2 ++ 2 files changed, 4 insertions(+)
drivers/gpu/drm/xe/xe_guc_submit.c +2 -0
@@ -2227,6 +2227,7 @@ xe_guc_exec_queue_snapshot_capture(struct xe_exec_queue *q)return NULL ; snapshot->guc.id = q->guc->id; + snapshot->guc.db_id = q->guc->db.id;memcpy (&snapshot->name, &q->name,sizeof (snapshot->name)); snapshot->class = q->class; snapshot->logical_mask = q->logical_mask;
@@ -2321,6 +2322,7 @@ xe_guc_exec_queue_snapshot_print(struct xe_guc_submit_exec_queue_snapshot *snapsdrm_printf (p,"\tClass: %d\n" , snapshot->class);drm_printf (p,"\tLogical mask: 0x%x\n" , snapshot->logical_mask);drm_printf (p,"\tWidth: %d\n" , snapshot->width); +drm_printf (p,"\tDoorbell ID: %d\n" , snapshot->guc.db_id);drm_printf (p,"\tRef: %d\n" , snapshot->refcount);drm_printf (p,"\tTimeout: %ld (ms)\n" , snapshot->sched_timeout); drm_printf(p, "\tTimeslice: %u (us)\n",
drivers/gpu/drm/xe/xe_guc_submit_types.h +2 -0
@@ -113,6 +113,8 @@ struct xe_guc_submit_exec_queue_snapshot {u32 wqi_tail;/** @guc.id: GuC id for this exec_queue */ u16 id; +/** @guc.db_id: Doorbell id */ +u16 db_id; } guc;/**
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 6/29 drm/xe: Break submission ring out into its own BO
In reply to Matthew BrostStart laying the ground work for UMD submission. This will allow mmaping the submission ring to user space.
--- drivers/gpu/drm/xe/xe_lrc.c | 38 +++++++++++++++++++++++++------ drivers/gpu/drm/xe/xe_lrc_types.h | 9 ++++++-- 2 files changed, 38 insertions(+), 9 deletions(-)
drivers/gpu/drm/xe/xe_lrc.c +31 -7
@@ -632,7 +632,7 @@ static inline u32 __xe_lrc_ring_offset(struct xe_lrc *lrc)u32 xe_lrc_pphwsp_offset (struct xe_lrc *lrc) { -return lrc->ring.size; +return 0 ; }/* Make the magic macros work */
@@ -712,7 +712,21 @@ static inline u32 __maybe_unused __xe_lrc_##elem##_ggtt_addr(struct xe_lrc *lrc) return xe_bo_ggtt_addr(lrc->bo) + __xe_lrc_##elem##_offset(lrc); \ } \ -DECL_MAP_ADDR_HELPERS(ring) +#define DECL_MAP_RING_ADDR_HELPERS (elem) \ +static inline struct iosys_map __xe_lrc_##elem##_map(struct xe_lrc *lrc) \ +{ \ + struct iosys_map map = lrc->submission_ring->vmap; \ +\ + xe_assert(lrc_to_xe(lrc), !iosys_map_is_null(&map)); \ + iosys_map_incr(&map, __xe_lrc_##elem##_offset(lrc)); \ + return map; \ +} \ +static inline u32 __maybe_unused __xe_lrc_##elem##_ggtt_addr(struct xe_lrc *lrc) \ +{ \ + return xe_bo_ggtt_addr(lrc->submission_ring) + __xe_lrc_##elem##_offset(lrc); \ +} \ + +DECL_MAP_RING_ADDR_HELPERS(ring) DECL_MAP_ADDR_HELPERS(pphwsp) DECL_MAP_ADDR_HELPERS(seqno) DECL_MAP_ADDR_HELPERS(regs)
@@ -722,6 +736,7 @@ DECL_MAP_ADDR_HELPERS(ctx_timestamp) DECL_MAP_ADDR_HELPERS(parallel) DECL_MAP_ADDR_HELPERS(indirect_ring) +#undef DECL_RING_MAP_ADDR_HELPERS#undef DECL_MAP_ADDR_HELPERS/**
@@ -866,10 +881,8 @@ static void xe_lrc_set_ppgtt(struct xe_lrc *lrc, struct xe_vm *vm)static void xe_lrc_finish (struct xe_lrc *lrc) {xe_hw_fence_ctx_finish (&lrc->fence_ctx); -xe_bo_lock (lrc->bo, false); -xe_bo_unpin (lrc->bo); -xe_bo_unlock (lrc->bo); -xe_bo_put (lrc->bo); +xe_bo_unpin_map_no_vm (lrc->bo); +xe_bo_unpin_map_no_vm (lrc->submission_ring); }#define PVC_CTX_ASID (0x2e + 1)
@@ -889,7 +902,7 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,kref_init (&lrc->refcount); lrc->flags =0 ; - lrc_size = ring_size +xe_gt_lrc_size (gt, hwe->class); + lrc_size =xe_gt_lrc_size (gt, hwe->class);if (xe_gt_has_indirect_ring_state (gt)) lrc->flags |=XE_LRC_FLAG_INDIRECT_RING_STATE ;
@@ -905,6 +918,17 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,if (IS_ERR (lrc->bo))return PTR_ERR (lrc->bo); + lrc->submission_ring =xe_bo_create_pin_map (xe, tile, vm, ring_size, + ttm_bo_type_kernel, +XE_BO_FLAG_VRAM_IF_DGFX (tile) | +XE_BO_FLAG_GGTT | +XE_BO_FLAG_GGTT_INVALIDATE ); +if (IS_ERR (lrc->submission_ring)) { + err =PTR_ERR (lrc->submission_ring); + lrc->submission_ring =NULL ; + goto err_lrc_finish; + } + lrc->size = lrc_size; lrc->tile =gt_to_tile (hwe->gt); lrc->ring.size = ring_size;
drivers/gpu/drm/xe/xe_lrc_types.h +7 -2
@@ -17,11 +17,16 @@ struct xe_bo;*/ struct xe_lrc {/** -* @bo: buffer object (memory) for logical ring context, per process HW -* status page, and submission ring. +* @bo: buffer object (memory) for logical ring context and per process +* HW status page. */ struct xe_bo *bo; +/** +* @submission_ring: buffer object (memory) for submission_ring +*/ +struct xe_bo *submission_ring; +/** @size: size of lrc including any indirect ring state page */ u32 size;
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 7/29 drm/xe: Break indirect ring state out into its own BO
In reply to Matthew BrostStart laying the ground work for UMD submission. This will allow mmaping the indirect ring state to user space.
--- drivers/gpu/drm/xe/xe_lrc.c | 79 ++++++++++++++++++++++--------- drivers/gpu/drm/xe/xe_lrc_types.h | 7 ++- 2 files changed, 63 insertions(+), 23 deletions(-)
drivers/gpu/drm/xe/xe_lrc.c +57 -22
@@ -74,10 +74,6 @@ size_t xe_gt_lrc_size(struct xe_gt *gt, enum xe_engine_class class) size =2 *SZ_4K ; } -/* Add indirect ring state page */ -if (xe_gt_has_indirect_ring_state (gt)) - size +=LRC_INDIRECT_RING_STATE_SIZE ; -return size; }
@@ -694,8 +690,7 @@ static u32 __xe_lrc_ctx_timestamp_offset(struct xe_lrc *lrc)static inline u32 __xe_lrc_indirect_ring_offset (struct xe_lrc *lrc) { -/* Indirect ring state page is at the very end of LRC */ -return lrc->size -LRC_INDIRECT_RING_STATE_SIZE ; +return 0 ; }#define DECL_MAP_ADDR_HELPERS (elem) \
@@ -726,6 +721,20 @@ static inline u32 __maybe_unused __xe_lrc_##elem##_ggtt_addr(struct xe_lrc *lrc) return xe_bo_ggtt_addr(lrc->submission_ring) + __xe_lrc_##elem##_offset(lrc); \ } \ +#define DECL_MAP_INDIRECT_ADDR_HELPERS (elem) \ +static inline struct iosys_map __xe_lrc_##elem##_map(struct xe_lrc *lrc) \ +{ \ + struct iosys_map map = lrc->indirect_state->vmap; \ +\ + xe_assert(lrc_to_xe(lrc), !iosys_map_is_null(&map)); \ + iosys_map_incr(&map, __xe_lrc_##elem##_offset(lrc)); \ + return map; \ +} \ +static inline u32 __maybe_unused __xe_lrc_##elem##_ggtt_addr(struct xe_lrc *lrc) \ +{ \ + return xe_bo_ggtt_addr(lrc->indirect_state) + __xe_lrc_##elem##_offset(lrc); \ +} \ + DECL_MAP_RING_ADDR_HELPERS(ring) DECL_MAP_ADDR_HELPERS(pphwsp) DECL_MAP_ADDR_HELPERS(seqno)
@@ -734,8 +743,9 @@ DECL_MAP_ADDR_HELPERS(start_seqno) DECL_MAP_ADDR_HELPERS(ctx_job_timestamp) DECL_MAP_ADDR_HELPERS(ctx_timestamp) DECL_MAP_ADDR_HELPERS(parallel) -DECL_MAP_ADDR_HELPERS(indirect_ring) +DECL_MAP_INDIRECT_ADDR_HELPERS(indirect_ring) +#undef DECL_INDIRECT_MAP_ADDR_HELPERS#undef DECL_RING_MAP_ADDR_HELPERS#undef DECL_MAP_ADDR_HELPERS
@@ -845,25 +855,27 @@ void xe_lrc_write_ctx_reg(struct xe_lrc *lrc, int reg_nr, u32 val)xe_map_write32 (xe, &map, val); } -static void *empty_lrc_data (struct xe_hw_engine *hwe) +static void *empty_lrc_data (struct xe_hw_engine *hwe,bool has_default) {struct xe_gt *gt = hwe->gt;void *data;u32 *regs; - data =kzalloc (xe_gt_lrc_size (gt, hwe->class),GFP_KERNEL ); + data =kzalloc (xe_gt_lrc_size (gt, hwe->class) + +LRC_INDIRECT_RING_STATE_SIZE ,GFP_KERNEL );if (!data)return NULL ;/* 1st page: Per-Process of HW status Page */ - regs = data +LRC_PPHWSP_SIZE ; -set_offsets (regs,reg_offsets (gt_to_xe (gt), hwe->class), hwe); -set_context_control (regs, hwe); -set_memory_based_intr (regs, hwe); -reset_stop_ring (regs, hwe); +if (!has_default) { + regs = data +LRC_PPHWSP_SIZE ; +set_offsets (regs,reg_offsets (gt_to_xe (gt), hwe->class), hwe); +set_context_control (regs, hwe); +set_memory_based_intr (regs, hwe); +reset_stop_ring (regs, hwe); + }if (xe_gt_has_indirect_ring_state (gt)) { - regs = data +xe_gt_lrc_size (gt, hwe->class) - -LRC_INDIRECT_RING_STATE_SIZE ; + regs = data +xe_gt_lrc_size (gt, hwe->class);set_offsets (regs, xe2_indirect_ring_state_offsets, hwe); }
@@ -883,6 +895,7 @@ static void xe_lrc_finish(struct xe_lrc *lrc)xe_hw_fence_ctx_finish (&lrc->fence_ctx);xe_bo_unpin_map_no_vm (lrc->bo);xe_bo_unpin_map_no_vm (lrc->submission_ring); +xe_bo_unpin_map_no_vm (lrc->indirect_state); }#define PVC_CTX_ASID (0x2e + 1)
@@ -903,8 +916,6 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,kref_init (&lrc->refcount); lrc->flags =0 ; lrc_size =xe_gt_lrc_size (gt, hwe->class); -if (xe_gt_has_indirect_ring_state (gt)) - lrc->flags |=XE_LRC_FLAG_INDIRECT_RING_STATE ;/* * FIXME: Perma-pinning LRC as we don't yet support moving GGTT address
@@ -929,6 +940,22 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe, goto err_lrc_finish; } +if (xe_gt_has_indirect_ring_state (gt)) { + lrc->flags |=XE_LRC_FLAG_INDIRECT_RING_STATE ; + + lrc->indirect_state =xe_bo_create_pin_map (xe, tile, vm, +LRC_INDIRECT_RING_STATE_SIZE , + ttm_bo_type_kernel, +XE_BO_FLAG_VRAM_IF_DGFX (tile) | +XE_BO_FLAG_GGTT | +XE_BO_FLAG_GGTT_INVALIDATE ); +if (IS_ERR (lrc->indirect_state)) { + err =PTR_ERR (lrc->indirect_state); + lrc->indirect_state =NULL ; + goto err_lrc_finish; + } + } + lrc->size = lrc_size; lrc->tile =gt_to_tile (hwe->gt); lrc->ring.size = ring_size;
@@ -938,8 +965,8 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,xe_hw_fence_ctx_init (&lrc->fence_ctx, hwe->gt, hwe->fence_irq, hwe->name); -if (!gt->default_lrc[hwe->class]) { - init_data =empty_lrc_data (hwe); +if (!gt->default_lrc[hwe->class] ||xe_gt_has_indirect_ring_state (gt)) { + init_data =empty_lrc_data (hwe, !!gt->default_lrc[hwe->class]);if (!init_data) { err = -ENOMEM ; goto err_lrc_finish;
@@ -951,7 +978,7 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,* values */ map =__xe_lrc_pphwsp_map (lrc); -if (!init_data) { +if (gt->default_lrc[hwe->class]) {xe_map_memset (xe, &map,0 ,0 ,LRC_PPHWSP_SIZE );/* PPHWSP */ xe_map_memcpy_to(xe, &map, LRC_PPHWSP_SIZE, gt->default_lrc[hwe->class] + LRC_PPHWSP_SIZE,
@@ -959,9 +986,17 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe, }else {xe_map_memcpy_to (xe, &map,0 , init_data,xe_gt_lrc_size (gt, hwe->class)); -kfree (init_data); } +if (xe_gt_has_indirect_ring_state (gt)) { + map =__xe_lrc_indirect_ring_map (lrc); +xe_map_memcpy_to (xe, &map,0 , init_data + +xe_gt_lrc_size (gt, hwe->class), +LRC_INDIRECT_RING_STATE_SIZE ); + } + +kfree (init_data); +if (vm) {xe_lrc_set_ppgtt (lrc, vm);
drivers/gpu/drm/xe/xe_lrc_types.h +6 -1
@@ -27,7 +27,12 @@ struct xe_lrc {*/ struct xe_bo *submission_ring; -/** @size: size of lrc including any indirect ring state page */ +/** +* @indirect_state: buffer object (memory) for indirect state +*/ +struct xe_bo *indirect_state; + +/** @size: size of lrc */ u32 size;/** @tile: tile which this LRC belongs to */
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 8/29 drm/xe: Clear GGTT in xe_bo_restore_kernel
In reply to Matthew BrostPart of what xe_bo_restore_kernel does, is restore BO's GGTT mappings which may have been lost during a power state change. Missing is restoring the GGTT entries without BO mappings to a known state (e.g., scratch pages). Update xe_bo_restore_kernel to clear the entire GGTT before restoring BO's GGTT mappings.
v2:
- Include missing local change of tile and id variable (CI)
v3:
- Fixed kernel doc (CI)
v4:
- Only clear holes (CI)
--- drivers/gpu/drm/xe/xe_bo_evict.c | 8 +++++++- drivers/gpu/drm/xe/xe_ggtt.c | 19 ++++++++++++++++--- drivers/gpu/drm/xe/xe_ggtt.h | 2 ++ 3 files changed, 25 insertions(+), 4 deletions(-)
drivers/gpu/drm/xe/xe_bo_evict.c +7 -1
@@ -123,7 +123,8 @@ int xe_bo_evict_all(struct xe_device *xe)* @xe: xe device * * Move kernel BOs from temporary (typically system) memory to VRAM via CPU. All -* moves done via TTM calls. +* moves done via TTM calls. All GGTT are restored too, first by clearing GGTT +* to known state and then restoring individual BO's GGTT mappings. * * This function should be called early, before trying to init the GT, on device * resume.
@@ -131,8 +132,13 @@ int xe_bo_evict_all(struct xe_device *xe)int xe_bo_restore_kernel (struct xe_device *xe) {struct xe_bo *bo; +struct xe_tile *tile; +u8 id;int ret; +for_each_tile (tile, xe, id) +xe_ggtt_clear (tile->mem.ggtt); +spin_lock (&xe->pinned.lock);for (;;) { bo = list_first_entry_or_null(&xe->pinned.evicted,
drivers/gpu/drm/xe/xe_ggtt.c +16 -3
@@ -140,7 +140,7 @@ static void xe_ggtt_set_pte_and_flush(struct xe_ggtt *ggtt, u64 addr, u64 pte)ggtt_update_access_counter (ggtt); } -static void xe_ggtt_clear (struct xe_ggtt *ggtt,u64 start,u64 size) +static void __xe_ggtt_clear (struct xe_ggtt *ggtt,u64 start,u64 size) {u16 pat_index =tile_to_xe (ggtt->tile)->pat.idx[XE_CACHE_WB ];u64 end = start + size -1 ;
@@ -160,6 +160,19 @@ static void xe_ggtt_clear(struct xe_ggtt *ggtt, u64 start, u64 size) } } +static void xe_ggtt_initial_clear (struct xe_ggtt *ggtt); + +/** +* xe_ggtt_clear() - GGTT clear +* @ggtt: the &xe_ggtt to be cleared +* +* Clear all GGTT to a known state +*/ +void xe_ggtt_clear (struct xe_ggtt *ggtt) +{ +xe_ggtt_initial_clear (ggtt); +} +static void ggtt_fini_early (struct drm_device *drm,void *arg) {struct xe_ggtt *ggtt = arg;
@@ -277,7 +290,7 @@ static void xe_ggtt_initial_clear(struct xe_ggtt *ggtt)/* Display may have allocated inside ggtt, so be careful with clearing here */ mutex_lock (&ggtt->lock);drm_mm_for_each_hole (hole, &ggtt->mm, start, end) -xe_ggtt_clear (ggtt, start, end - start); +__xe_ggtt_clear (ggtt, start, end - start);xe_ggtt_invalidate (ggtt);mutex_unlock (&ggtt->lock);
@@ -294,7 +307,7 @@ static void ggtt_node_remove(struct xe_ggtt_node *node)mutex_lock (&ggtt->lock);if (bound) -xe_ggtt_clear (ggtt, node->base.start, node->base.size); +__xe_ggtt_clear (ggtt, node->base.start, node->base.size);drm_mm_remove_node (&node->base); node->base.size =0 ;mutex_unlock (&ggtt->lock);
drivers/gpu/drm/xe/xe_ggtt.h +2 -0
@@ -13,6 +13,8 @@ struct drm_printer;int xe_ggtt_init_early (struct xe_ggtt *ggtt);int xe_ggtt_init (struct xe_ggtt *ggtt); +void xe_ggtt_clear (struct xe_ggtt *ggtt); +struct xe_ggtt_node *xe_ggtt_node_init (struct xe_ggtt *ggtt);void xe_ggtt_node_fini (struct xe_ggtt_node *node); int xe_ggtt_node_insert_balloon(struct xe_ggtt_node *node,
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 9/29 FIXME: drm/xe: Add pad to ring and indirect state
In reply to Matthew BrostUnsure why, but without this intermittent hangs occur on GuC context switching.
--- drivers/gpu/drm/xe/xe_lrc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/xe/xe_lrc.c +2 -3
@@ -929,7 +929,7 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,if (IS_ERR (lrc->bo))return PTR_ERR (lrc->bo); - lrc->submission_ring = xe_bo_create_pin_map(xe, tile, vm, ring_size, + lrc->submission_ring = xe_bo_create_pin_map(xe, tile, vm, SZ_32K, ttm_bo_type_kernel, XE_BO_FLAG_VRAM_IF_DGFX(tile) | XE_BO_FLAG_GGTT |
@@ -943,8 +943,7 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,if (xe_gt_has_indirect_ring_state (gt)) { lrc->flags |=XE_LRC_FLAG_INDIRECT_RING_STATE ; - lrc->indirect_state = xe_bo_create_pin_map(xe, tile, vm, - LRC_INDIRECT_RING_STATE_SIZE, + lrc->indirect_state = xe_bo_create_pin_map(xe, tile, vm, SZ_8K, ttm_bo_type_kernel, XE_BO_FLAG_VRAM_IF_DGFX(tile) | XE_BO_FLAG_GGTT |
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 10/29 drm/xe: Enable indirect ring on media GT
In reply to Matthew BrostThe media GT supports this, required for UMD submission, so enable by default.
--- drivers/gpu/drm/xe/xe_pci.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/xe/xe_pci.c +1 -0
@@ -209,6 +209,7 @@ static const struct xe_media_desc media_xelpmp = {static const struct xe_media_desc media_xe2 = { .name ="Xe2_LPM / Xe2_HPM / Xe3_LPM" , + .has_indirect_ring_state =1 , .hw_engine_mask =GENMASK (XE_HW_ENGINE_VCS7 ,XE_HW_ENGINE_VCS0 ) | GENMASK(XE_HW_ENGINE_VECS3, XE_HW_ENGINE_VECS0) |
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 11/29 drm/xe: Don't add pinned mappings to VM bulk move
In reply to Matthew BrostWe don't want kernel pinned resources (ring, indirect state) in the VM's bulk move as these are unevictable.
--- drivers/gpu/drm/xe/xe_bo.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpu/drm/xe/xe_bo.c +4 -6
@@ -1470,6 +1470,9 @@ __xe_bo_create_locked(struct xe_device *xe, {struct xe_bo *bo =NULL ;int err; +bool want_bulk = vm && !xe_vm_in_fault_mode (vm) && + flags &XE_BO_FLAG_USER && + !(flags & (XE_BO_FLAG_PINNED |XE_BO_FLAG_GGTT ));if (vm)xe_vm_assert_held (vm);
@@ -1488,9 +1491,7 @@ __xe_bo_create_locked(struct xe_device *xe, } bo =___xe_bo_create_locked (xe, bo, tile, vm ?xe_vm_resv (vm) :NULL , - vm && !xe_vm_in_fault_mode (vm) && - flags &XE_BO_FLAG_USER ? - &vm->lru_bulk_move :NULL , size, + want_bulk ? &vm->lru_bulk_move :NULL , size, cpu_caching, type, flags);if (IS_ERR (bo))return bo;
@@ -1781,9 +1782,6 @@ int xe_bo_pin(struct xe_bo *bo)struct xe_device *xe =xe_bo_device (bo);int err; -/* We currently don't expect user BO to be pinned */ -xe_assert (xe, !xe_bo_is_user (bo)); -/* Pinned object must be in GGTT or have pinned flag */ xe_assert (xe, bo->flags & (XE_BO_FLAG_PINNED |XE_BO_FLAG_GGTT ));
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 12/29 drm/xe: Add exec queue post init extension processing
In reply to Matthew BrostAdd exec queue post init extension processing which is needed for more complex extensions in which data is returned to the user.
--- drivers/gpu/drm/xe/xe_exec_queue.c | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
drivers/gpu/drm/xe/xe_exec_queue.c +48 -0
@@ -33,6 +33,8 @@ enum xe_exec_queue_sched_prop {static int exec_queue_user_extensions (struct xe_device *xe,struct xe_exec_queue *q,u64 extensions,int ext_number); +static int exec_queue_user_extensions_post_init (struct xe_device *xe,struct xe_exec_queue *q, +u64 extensions,int ext_number);static void __xe_exec_queue_free (struct xe_exec_queue *q) {
@@ -446,6 +448,10 @@ static const xe_exec_queue_user_extension_fn exec_queue_user_extension_funcs[] = [DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY] = exec_queue_user_ext_set_property, }; +static const xe_exec_queue_user_extension_fn exec_queue_user_extension_post_init_funcs[] = { + [DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY ] =NULL , +}; +#define MAX_USER_EXTENSIONS 16static int exec_queue_user_extensions (struct xe_device *xe,struct xe_exec_queue *q,u64 extensions,int ext_number)
@@ -480,6 +486,42 @@ static int exec_queue_user_extensions(struct xe_device *xe, struct xe_exec_queuereturn 0 ; } +static int exec_queue_user_extensions_post_init (struct xe_device *xe,struct xe_exec_queue *q, +u64 extensions,int ext_number) +{ +u64 __user *address =u64_to_user_ptr (extensions); +struct drm_xe_user_extension ext; +int err; +u32 idx; + +if (XE_IOCTL_DBG (xe, ext_number >=MAX_USER_EXTENSIONS )) +return -E2BIG ; + + err =__copy_from_user (&ext, address,sizeof (ext)); +if (XE_IOCTL_DBG (xe, err)) +return -EFAULT ; + +if (XE_IOCTL_DBG (xe, ext.pad) || +XE_IOCTL_DBG (xe, ext.name >= +ARRAY_SIZE (exec_queue_user_extension_post_init_funcs))) +return -EINVAL ; + + idx =array_index_nospec (ext.name, +ARRAY_SIZE (exec_queue_user_extension_post_init_funcs)); +if (exec_queue_user_extension_post_init_funcs[idx]) { + err = exec_queue_user_extension_post_init_funcs[idx](xe, q, extensions); +if (XE_IOCTL_DBG (xe, err)) +return err; + } + +if (ext.next_extension) +return exec_queue_user_extensions_post_init (xe, q, + ext.next_extension, + ++ext_number); + +return 0 ; +} +static u32 calc_validate_logical_mask (struct xe_device *xe,struct xe_gt *gt,struct drm_xe_engine_class_instance *eci,u16 width,u16 num_placements)
@@ -647,6 +689,12 @@ int xe_exec_queue_create_ioctl(struct drm_device *dev, void *data, q->xef =xe_file_get (xef); +if (args->extensions) { + err =exec_queue_user_extensions_post_init (xe, q, args->extensions,0 ); +if (err) + goto kill_exec_queue; + } +/* user id alloc must always be last in ioctl to prevent UAF */ err =xa_alloc (&xef->exec_queue.xa, &id, q, xa_limit_32b,GFP_KERNEL );if (err)
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 13/29 drm/xe/mmap: Add mmap support for PCI memory barrier
In reply to Matthew BrostFrom: Tejas Upadhyay <[email protected]>
In order to avoid having userspace to use MI_MEM_FENCE, we are adding a mechanism for userspace to generate a PCI memory barrier with low overhead (avoiding IOCTL call as well as writing to VRAM will adds some overhead).
This is implemented by memory-mapping a page as uncached that is backed by MMIO on the dGPU and thus allowing userspace to do memory write to the page without invoking an IOCTL. We are selecting the MMIO so that it is not accessible from the PCI bus so that the MMIO writes themselves are ignored, but the PCI memory barrier will still take action as the MMIO filtering will happen after the memory barrier effect.
When we detect special defined offset in mmap(), We are mapping 4K page which contains the last of page of doorbell MMIO range to userspace for same purpose.
For user to query special offset we are adding special flag in mmap_offset ioctl which needs to be passed as follows, struct drm_xe_gem_mmap_offset mmo = {
.handle = 0, /* this must be 0 */
.flags = DRM_XE_MMAP_OFFSET_FLAG_PCI_BARRIER,
};igt_ioctl(fd, DRM_IOCTL_XE_GEM_MMAP_OFFSET, &mmo); map = mmap(NULL, size, PROT_WRITE, MAP_SHARED, fd, mmo);
Note: Test coverage for this is added by IGT
https://patchwork.freedesktop.org/series/140368/ here. UMD implementing test, once PR is ready will attach with this patch.
V6(MAuld)
- Move physical mmap to fault handler
- Modify kernel-doc and attach UMD PR when ready
V5(MAuld)
- Return invalid early in case of non 4K PAGE_SIZE
- Format kernel-doc and add note for 4K PAGE_SIZE HW limit
V4(MAuld)
- Add kernel-doc for uapi change
- Restrict page size to 4K
V3(MAuld)
- Remove offset defination from UAPI to be able to change later
- Edit commit message for special flag addition
V2(MAuld)
- Add fault handler with dummy page to handle unplug device
- Add Build check for special offset to be below normal start page
- Test d3hot, mapping seems to be valid in d3hot as well
- Add more info to commit message
--- drivers/gpu/drm/xe/xe_bo.c | 16 ++++- drivers/gpu/drm/xe/xe_bo.h | 2 + drivers/gpu/drm/xe/xe_device.c | 103 ++++++++++++++++++++++++++++++++- include/uapi/drm/xe_drm.h | 29 +++++++++- 4 files changed, 147 insertions(+), 3 deletions(-)
drivers/gpu/drm/xe/xe_bo.c +15 -1
@@ -2138,9 +2138,23 @@ int xe_gem_mmap_offset_ioctl(struct drm_device *dev, void *data, XE_IOCTL_DBG(xe, args->reserved[0] || args->reserved[1]))return -EINVAL ; -if (XE_IOCTL_DBG (xe, args->flags)) +if (XE_IOCTL_DBG (xe, args->flags & + ~DRM_XE_MMAP_OFFSET_FLAG_PCI_BARRIER ))return -EINVAL ; +if (args->flags &DRM_XE_MMAP_OFFSET_FLAG_PCI_BARRIER ) { +if (XE_IOCTL_DBG (xe, args->handle)) +return -EINVAL ; + +if (XE_IOCTL_DBG (xe,PAGE_SIZE >SZ_4K )) +return -EINVAL ; + +BUILD_BUG_ON (((XE_PCI_BARRIER_MMAP_OFFSET >>XE_PTE_SHIFT ) + +SZ_4K ) >=DRM_FILE_PAGE_OFFSET_START ); + args->offset =XE_PCI_BARRIER_MMAP_OFFSET ; +return 0 ; + } + gem_obj =drm_gem_object_lookup (file, args->handle);if (XE_IOCTL_DBG (xe, !gem_obj))return -ENOENT ;
drivers/gpu/drm/xe/xe_bo.h +2 -0
@@ -63,6 +63,8 @@#define XE_BO_PROPS_INVALID (-1) +#define XE_PCI_BARRIER_MMAP_OFFSET (0x50 << XE_PTE_SHIFT) +struct sg_table ;struct xe_bo *xe_bo_alloc (void );
drivers/gpu/drm/xe/xe_device.c +102 -1
114 lines not on this page · raw message
include/uapi/drm/xe_drm.h +28 -1
@@ -811,6 +811,32 @@ struct drm_xe_gem_create {/** * struct drm_xe_gem_mmap_offset - Input of &DRM_IOCTL_XE_GEM_MMAP_OFFSET +* +* The @flags can be: +* - %DRM_XE_MMAP_OFFSET_FLAG_PCI_BARRIER - For user to query special offset +* for use in mmap ioctl. Writing to the returned mmap address will generate a +* PCI memory barrier with low overhead (avoiding IOCTL call as well as writing +* to VRAM which would also add overhead), acting like an MI_MEM_FENCE +* instruction. +* +* Note: The mmap size can be at most 4K, due to HW limitations. As a result +* this interface is only supported on CPU architectures that support 4K page +* size. The mmap_offset ioctl will detect this and gracefully return an +* error, where userspace is expected to have a different fallback method for +* triggering a barrier. +* +* Roughly the usage would be as follows: +* +* .. code-block:: C +* +* struct drm_xe_gem_mmap_offset mmo = { +* .handle = 0, // must be set to 0 +* .flags = DRM_XE_MMAP_OFFSET_FLAG_PCI_BARRIER, +* }; +* +* err = ioctl(fd, DRM_IOCTL_XE_GEM_MMAP_OFFSET, &mmo); +* map = mmap(NULL, size, PROT_WRITE, MAP_SHARED, fd, mmo.offset); +* map[i] = 0xdeadbeaf; // issue barrier */ struct drm_xe_gem_mmap_offset {/** @extensions: Pointer to the first extension struct, if any */
@@ -819,7 +845,8 @@ struct drm_xe_gem_mmap_offset {/** @handle: Handle for the object being mapped. */ __u32 handle; -/** @flags: Must be zero */ +#define DRM_XE_MMAP_OFFSET_FLAG_PCI_BARRIER (1 << 0) +/** @flags: Flags */ __u32 flags;/** @offset: The fake offset to use for subsequent mmap call */
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 14/29 drm/xe: Add support for mmapping doorbells to user space
In reply to Matthew BrostDoorbells need to be mapped to user space for UMD direct submisssion, add support for this.
FIXME: Wildly insecure as anyone can pick MMIO doorbell offset, will need to randomize and tie unique offset to FD. Can be done in later revs before upstreaming.
--- drivers/gpu/drm/xe/xe_bo.h | 3 ++ drivers/gpu/drm/xe/xe_device.c | 73 ++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+)
drivers/gpu/drm/xe/xe_bo.h +3 -0
@@ -64,6 +64,9 @@#define XE_BO_PROPS_INVALID (-1)#define XE_PCI_BARRIER_MMAP_OFFSET (0x50 << XE_PTE_SHIFT) +#define XE_MMIO_DOORBELL_MMAP_OFFSET (0x100 << XE_PTE_SHIFT) +#define XE_MMIO_DOORBELL_PFN_START (SZ_4M >> XE_PTE_SHIFT) +#define XE_MMIO_DOORBELL_PFN_COUNT (256)struct sg_table ;
drivers/gpu/drm/xe/xe_device.c +73 -0
85 lines not on this page · raw message
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 15/29 drm/xe: Add support for mmapping submission ring and indirect ring state to user space
In reply to Matthew BrostThe ring and indirect ring state need to mapped to user space for UMD direction submission, add support for this.
--- drivers/gpu/drm/xe/xe_bo.c | 3 --- drivers/gpu/drm/xe/xe_exec_queue.c | 2 +- drivers/gpu/drm/xe/xe_execlist.c | 2 +- drivers/gpu/drm/xe/xe_lrc.c | 29 ++++++++++++++++++++++------- drivers/gpu/drm/xe/xe_lrc.h | 4 ++-- 5 files changed, 26 insertions(+), 14 deletions(-)
drivers/gpu/drm/xe/xe_bo.c +0 -3
@@ -1311,9 +1311,6 @@ struct xe_bo *___xe_bo_create_locked(struct xe_device *xe, struct xe_bo *bo,size_t aligned_size;int err; -/* Only kernel objects should set GT */ -xe_assert (xe, !tile || type == ttm_bo_type_kernel); -if (XE_WARN_ON (!size)) {xe_bo_free (bo);return ERR_PTR (-EINVAL );
drivers/gpu/drm/xe/xe_exec_queue.c +1 -1
@@ -119,7 +119,7 @@ static int __xe_exec_queue_init(struct xe_exec_queue *q) }for (i =0 ; i < q->width; ++i) { - q->lrc[i] =xe_lrc_create (q->hwe, q->vm,SZ_16K ); + q->lrc[i] =xe_lrc_create (q, q->hwe, q->vm,SZ_16K );if (IS_ERR (q->lrc[i])) { err =PTR_ERR (q->lrc[i]); goto err_unlock;
drivers/gpu/drm/xe/xe_execlist.c +1 -1
@@ -265,7 +265,7 @@ struct xe_execlist_port *xe_execlist_port_create(struct xe_device *xe, port->hwe = hwe; - port->lrc =xe_lrc_create (hwe,NULL ,SZ_16K ); + port->lrc =xe_lrc_create (NULL , hwe,NULL ,SZ_16K );if (IS_ERR (port->lrc)) { err =PTR_ERR (port->lrc); goto err;
drivers/gpu/drm/xe/xe_lrc.c +22 -7
@@ -901,8 +901,9 @@ static void xe_lrc_finish(struct xe_lrc *lrc)#define PVC_CTX_ASID (0x2e + 1)#define PVC_CTX_ACC_CTR_THOLD (0x2a + 1) -static int xe_lrc_init (struct xe_lrc *lrc,struct xe_hw_engine *hwe, -struct xe_vm *vm,u32 ring_size) +static int xe_lrc_init (struct xe_lrc *lrc,struct xe_exec_queue *q, +struct xe_hw_engine *hwe,struct xe_vm *vm, +u32 ring_size) {struct xe_gt *gt = hwe->gt;struct xe_tile *tile =gt_to_tile (gt);
@@ -911,6 +912,11 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,void *init_data =NULL ;u32 arb_enable;u32 lrc_size; +bool user_queue = q && q->flags &EXEC_QUEUE_FLAG_UMD_SUBMISSION ; +enum ttm_bo_type submit_type = user_queue ? ttm_bo_type_device : + ttm_bo_type_kernel; +unsigned int submit_flags = user_queue ? +XE_BO_FLAG_USER :0 ;int err;kref_init (&lrc->refcount);
@@ -930,7 +936,8 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,return PTR_ERR (lrc->bo); lrc->submission_ring =xe_bo_create_pin_map (xe, tile, vm,SZ_32K , - ttm_bo_type_kernel, + submit_type, + submit_flags |XE_BO_FLAG_VRAM_IF_DGFX (tile) |XE_BO_FLAG_GGTT |XE_BO_FLAG_GGTT_INVALIDATE );
@@ -944,7 +951,8 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe, lrc->flags |=XE_LRC_FLAG_INDIRECT_RING_STATE ; lrc->indirect_state =xe_bo_create_pin_map (xe, tile, vm,SZ_8K , - ttm_bo_type_kernel, + submit_type, + submit_flags |XE_BO_FLAG_VRAM_IF_DGFX (tile) |XE_BO_FLAG_GGTT |XE_BO_FLAG_GGTT_INVALIDATE );
@@ -955,6 +963,12 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe, } } +/* Wait for clear */ +if (user_queue) +dma_resv_wait_timeout (xe_vm_resv (vm), +DMA_RESV_USAGE_KERNEL , + false,MAX_SCHEDULE_TIMEOUT ); + lrc->size = lrc_size; lrc->tile =gt_to_tile (hwe->gt); lrc->ring.size = ring_size;
@@ -1060,6 +1074,7 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,/** * xe_lrc_create - Create a LRC +* @q: Execution queue * @hwe: Hardware Engine * @vm: The VM (address space) * @ring_size: LRC ring size
@@ -1069,8 +1084,8 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,* Return pointer to created LRC upon success and an error pointer * upon failure. */ -struct xe_lrc *xe_lrc_create (struct xe_hw_engine *hwe,struct xe_vm *vm, -u32 ring_size) +struct xe_lrc *xe_lrc_create (struct xe_exec_queue *q,struct xe_hw_engine *hwe, +struct xe_vm *vm,u32 ring_size) {struct xe_lrc *lrc;int err;
@@ -1079,7 +1094,7 @@ struct xe_lrc *xe_lrc_create(struct xe_hw_engine *hwe, struct xe_vm *vm,if (!lrc)return ERR_PTR (-ENOMEM ); - err =xe_lrc_init (lrc, hwe, vm, ring_size); + err =xe_lrc_init (lrc, q, hwe, vm, ring_size);if (err) {kfree (lrc);return ERR_PTR (err);
drivers/gpu/drm/xe/xe_lrc.h +2 -2
@@ -41,8 +41,8 @@ struct xe_lrc_snapshot {#define LRC_PPHWSP_SCRATCH_ADDR (0x34 * 4) -struct xe_lrc *xe_lrc_create (struct xe_hw_engine *hwe,struct xe_vm *vm, -u32 ring_size); +struct xe_lrc *xe_lrc_create (struct xe_exec_queue *q,struct xe_hw_engine *hwe, +struct xe_vm *vm,u32 ring_size);void xe_lrc_destroy (struct kref *ref);/**
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 16/29 drm/xe/uapi: Define UMD exec queue mapping uAPI
In reply to Matthew BrostDefine UMD exec queue mapping uAPI. The submit ring, indirect LRC state (ring head, tail, etc...), and doorbell are securly mapped to user space. The ring is a VM PPGTT addres, while indirect LRC state and doorbell mapping is provided via a fake offset like BOs.
--- include/uapi/drm/xe_drm.h | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
include/uapi/drm/xe_drm.h +56 -0
@@ -1111,6 +1111,61 @@ struct drm_xe_vm_bind {__u64 reserved[2 ]; }; +/** +* struct drm_xe_exec_queue_ext_usermap +*/ +struct drm_xe_exec_queue_ext_usermap { +/** @base: base user extension */ +struct drm_xe_user_extension base; + +/** @flags: MBZ */ +__u32 flags; + +/** @version: Version of usermap */ +#define DRM_XE_EXEC_QUEUE_USERMAP_VERSION_XE2_REV0 0 +__u32 version; + +/** +* @ring_size: The ring size. 4k-2M valid, must be 4k aligned. User +* space has to pad allocation / mapping to avoid prefetch faults. +* Prefetch size is platform dependent. +*/ +__u32 ring_size; + +/** @pad: MBZ */ +__u32 pad; + +/** +* @ring_addr: Ring address mapped within the VM, should be mapped as +* UC. +*/ +__u64 ring_addr; + +/** +* @indirect_ring_state_offset: The fake indirect ring state offset to +* use for subsequent mmap call. Always 4k in size. +*/ +__u64 indirect_ring_state_offset; + +/** +* @doorbell_offset: The fake doorbell offset to use for subsequent mmap +* call. Always 4k in size. +*/ +__u64 doorbell_offset; + +/** @doorbell_page_offset: The doorbell offset within the mmapped page */ +__u32 doorbell_page_offset; + +/** +* @indirect_ring_state_handle: Indirect ring state buffer object +* handle. Allocated by KMD and must be closed by user. +*/ +__u32 indirect_ring_state_handle; + +/** @reserved: Reserved */ +__u64 reserved[2 ]; +}; +/** * struct drm_xe_exec_queue_create - Input of &DRM_IOCTL_XE_EXEC_QUEUE_CREATE *
@@ -1138,6 +1193,7 @@ struct drm_xe_exec_queue_create {#define DRM_XE_EXEC_QUEUE_SET_PROPERTY_PRIORITY 0#define DRM_XE_EXEC_QUEUE_SET_PROPERTY_TIMESLICE 1 +#define DRM_XE_EXEC_QUEUE_EXTENSION_USERMAP 1/** @extensions: Pointer to the first extension struct, if any */ __u64 extensions;
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 17/29 drm/xe: Add usermap exec queue extension
In reply to Matthew BrostImplement uAPI which maps submit rings, indirect LRC state, and doorbells to user space. This is required for UMD direction submission.
--- drivers/gpu/drm/xe/xe_exec_queue.c | 125 ++++++++++++++++++++++- drivers/gpu/drm/xe/xe_exec_queue_types.h | 13 +++ drivers/gpu/drm/xe/xe_execlist.c | 2 +- drivers/gpu/drm/xe/xe_lrc.c | 59 +++++++---- drivers/gpu/drm/xe/xe_lrc.h | 2 +- 5 files changed, 176 insertions(+), 25 deletions(-)
drivers/gpu/drm/xe/xe_exec_queue.c +124 -1
@@ -11,6 +11,7 @@#include <drm/drm_file.h> #include <uapi/drm/xe_drm.h> +#include "xe_bo.h" #include "xe_device.h" #include "xe_gt.h" #include "xe_hw_engine_class_sysfs.h"
@@ -38,12 +39,18 @@ static int exec_queue_user_extensions_post_init(struct xe_device *xe, struct xe_static void __xe_exec_queue_free (struct xe_exec_queue *q) { +struct xe_device *xe = q->vm ? q->vm->xe :NULL ; +if (q->vm)xe_vm_put (q->vm);if (q->xef)xe_file_put (q->xef); +if (q->usermap) +xe_pm_runtime_put (xe); + +kfree (q->usermap);kfree (q); }
@@ -110,6 +117,8 @@ static struct xe_exec_queue *__xe_exec_queue_alloc(struct xe_device *xe,static int __xe_exec_queue_init (struct xe_exec_queue *q) {struct xe_vm *vm = q->vm; +u64 ring_addr = q->usermap ? q->usermap->ring_addr :0 ; +u32 ring_size = q->usermap ? q->usermap->ring_size :SZ_16K ;int i, err;if (vm) {
@@ -119,7 +128,8 @@ static int __xe_exec_queue_init(struct xe_exec_queue *q) }for (i =0 ; i < q->width; ++i) { - q->lrc[i] =xe_lrc_create (q, q->hwe, q->vm,SZ_16K ); + q->lrc[i] =xe_lrc_create (q, q->hwe, q->vm, ring_size, + ring_addr);if (IS_ERR (q->lrc[i])) { err =PTR_ERR (q->lrc[i]); goto err_unlock;
@@ -444,12 +454,125 @@ typedef int (*xe_exec_queue_user_extension_fn)(struct xe_device *xe,struct xe_exec_queue *q, u64 extension); +static int exec_queue_user_ext_usermap (struct xe_device *xe, +struct xe_exec_queue *q, +u64 extension) +{ +u64 __user *address =u64_to_user_ptr (extension); +struct drm_xe_exec_queue_ext_usermap ext; +int err; + +/* Just parse args and make sure they are sane */ + +if (XE_IOCTL_DBG (xe, !xe_gt_has_indirect_ring_state (q->gt))) +return -EOPNOTSUPP ; + +if (XE_IOCTL_DBG (xe, q->width !=1 )) +return -EOPNOTSUPP ; + +if (XE_IOCTL_DBG (xe, q->flags & (EXEC_QUEUE_FLAG_KERNEL | +EXEC_QUEUE_FLAG_PERMANENT | +EXEC_QUEUE_FLAG_VM | +EXEC_QUEUE_FLAG_BIND_ENGINE_CHILD ))) +return -EOPNOTSUPP ; + +if (XE_IOCTL_DBG (xe, q->width !=1 )) +return -EOPNOTSUPP ; + +/* +* XXX: More or less free to support this but targeting Mesa for now as +* LR mode has ULLS. +*/ +if (XE_IOCTL_DBG (xe,xe_vm_in_lr_mode (q->vm))) +return -EOPNOTSUPP ; + +if (XE_IOCTL_DBG (xe, q->flags &EXEC_QUEUE_FLAG_UMD_SUBMISSION )) +return -EINVAL ; + + err =__copy_from_user (&ext, address,sizeof (ext)); +if (XE_IOCTL_DBG (xe, err)) +return -EFAULT ; + +if (XE_IOCTL_DBG (xe, ext.reserved[0 ] || ext.reserved[1 ])) +return -EINVAL ; + +if (XE_IOCTL_DBG (xe, ext.pad)) +return -EINVAL ; + +if (XE_IOCTL_DBG (xe, ext.flags)) +return -EINVAL ; + +if (XE_IOCTL_DBG (xe, ext.ring_size <SZ_4K || + ext.ring_size >SZ_2M || + ext.ring_size & ~PAGE_MASK )) +return -EINVAL ; + +if (XE_IOCTL_DBG (xe, ext.version != +DRM_XE_EXEC_QUEUE_USERMAP_VERSION_XE2_REV0 )) +return -EINVAL ; + + q->usermap =kzalloc (sizeof (struct xe_exec_queue_usermap ),GFP_KERNEL ); +if (!q->usermap) +return -ENOMEM ; + + q->usermap->ring_size = ext.ring_size; + q->usermap->ring_addr = ext.ring_addr; + +xe_pm_runtime_get_noresume (xe); + q->flags |=EXEC_QUEUE_FLAG_UMD_SUBMISSION ; + +return 0 ; +} + +static int exec_queue_user_ext_post_init_usermap (struct xe_device *xe, +struct xe_exec_queue *q, +u64 extension) +{ +struct drm_xe_exec_queue_ext_usermap ext; +struct xe_lrc *lrc = q->lrc[0 ]; +u64 __user *address =u64_to_user_ptr (extension); +u32 indirect_ring_state_handle; +int err; + + err =__copy_from_user (&ext, address,sizeof (ext)); +if (XE_IOCTL_DBG (xe, err)) +return -EFAULT ; + + err =drm_gem_handle_create (q->xef->drm, + &lrc->indirect_state->ttm.base, + &indirect_ring_state_handle); +if (err) +return err; + + ext.indirect_ring_state_offset = +drm_vma_node_offset_addr (&lrc->indirect_state->ttm.base.vma_node); + ext.indirect_ring_state_handle = indirect_ring_state_handle; + ext.doorbell_offset =XE_MMIO_DOORBELL_MMAP_OFFSET + +SZ_4K * q->guc->db.id; + ext.doorbell_page_offset =0 ; + + err =copy_to_user (address, &ext,sizeof (ext)); +if (XE_IOCTL_DBG (xe, err)) { + err = -EFAULT ; + goto close_handles; + } + +return 0 ; + +close_handles: +drm_gem_handle_delete (q->xef->drm, indirect_ring_state_handle); + +return err; +} +static const xe_exec_queue_user_extension_fn exec_queue_user_extension_funcs[] = { [DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY ] = exec_queue_user_ext_set_property, + [DRM_XE_EXEC_QUEUE_EXTENSION_USERMAP ] = exec_queue_user_ext_usermap, };static const xe_exec_queue_user_extension_fn exec_queue_user_extension_post_init_funcs[] = { [DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY ] =NULL , + [DRM_XE_EXEC_QUEUE_EXTENSION_USERMAP ] = exec_queue_user_ext_post_init_usermap, };#define MAX_USER_EXTENSIONS 16
drivers/gpu/drm/xe/xe_exec_queue_types.h +13 -0
@@ -31,6 +31,16 @@ enum xe_exec_queue_priority { XE_EXEC_QUEUE_PRIORITY_COUNT }; +/** +* struct xe_exec_queue_usermap - Execution queue usermap (UMD submission) +*/ +struct xe_exec_queue_usermap { +/** @ring_addr: ring address (PPGTT) */ +u64 ring_addr; +/** @ring_size: ring size */ +u32 ring_size; +}; +/** * struct xe_exec_queue - Execution queue *
@@ -130,6 +140,9 @@ struct xe_exec_queue {struct list_head link; } lr; +/** @usermap: user map interface */ +struct xe_exec_queue_usermap *usermap; +/** @ops: submission backend exec queue operations */ const struct xe_exec_queue_ops *ops;
drivers/gpu/drm/xe/xe_execlist.c +1 -1
@@ -265,7 +265,7 @@ struct xe_execlist_port *xe_execlist_port_create(struct xe_device *xe, port->hwe = hwe; - port->lrc =xe_lrc_create (NULL , hwe,NULL ,SZ_16K ); + port->lrc =xe_lrc_create (NULL , hwe,NULL ,SZ_16K ,0 );if (IS_ERR (port->lrc)) { err =PTR_ERR (port->lrc); goto err;
drivers/gpu/drm/xe/xe_lrc.c +37 -22
113 lines not on this page · raw message
drivers/gpu/drm/xe/xe_lrc.h +1 -1
@@ -42,7 +42,7 @@ struct xe_lrc_snapshot {#define LRC_PPHWSP_SCRATCH_ADDR (0x34 * 4)struct xe_lrc *xe_lrc_create (struct xe_exec_queue *q,struct xe_hw_engine *hwe, -struct xe_vm *vm,u32 ring_size); +struct xe_vm *vm,u32 ring_size,u64 ring_addr);void xe_lrc_destroy (struct kref *ref);/**
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 18/29 drm/xe: Drop EXEC_QUEUE_FLAG_UMD_SUBMISSION flag
In reply to Matthew BrostUse xe_exec_queue_is_usermap helper instead.
--- drivers/gpu/drm/xe/xe_exec_queue.c | 3 +-- drivers/gpu/drm/xe/xe_exec_queue.h | 5 +++++ drivers/gpu/drm/xe/xe_exec_queue_types.h | 2 -- drivers/gpu/drm/xe/xe_guc_submit.c | 4 ++-- drivers/gpu/drm/xe/xe_lrc.c | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-)
drivers/gpu/drm/xe/xe_exec_queue.c +1 -2
@@ -486,7 +486,7 @@ static int exec_queue_user_ext_usermap(struct xe_device *xe,if (XE_IOCTL_DBG (xe,xe_vm_in_lr_mode (q->vm)))return -EOPNOTSUPP ; -if (XE_IOCTL_DBG (xe, q->flags &EXEC_QUEUE_FLAG_UMD_SUBMISSION )) +if (XE_IOCTL_DBG (xe,xe_exec_queue_is_usermap (q)))return -EINVAL ; err =__copy_from_user (&ext, address,sizeof (ext));
@@ -519,7 +519,6 @@ static int exec_queue_user_ext_usermap(struct xe_device *xe, q->usermap->ring_addr = ext.ring_addr;xe_pm_runtime_get_noresume (xe); - q->flags |=EXEC_QUEUE_FLAG_UMD_SUBMISSION ;return 0 ; }
drivers/gpu/drm/xe/xe_exec_queue.h +5 -0
@@ -57,6 +57,11 @@ static inline bool xe_exec_queue_is_parallel(struct xe_exec_queue *q)return q->width >1 ; } +static inline bool xe_exec_queue_is_usermap (struct xe_exec_queue *q) +{ +return !!q->usermap; +} +bool xe_exec_queue_is_lr (struct xe_exec_queue *q);bool xe_exec_queue_ring_full (struct xe_exec_queue *q);
drivers/gpu/drm/xe/xe_exec_queue_types.h +0 -2
@@ -93,8 +93,6 @@ struct xe_exec_queue {#define EXEC_QUEUE_FLAG_BIND_ENGINE_CHILD BIT(3)/* kernel exec_queue only, set priority to highest level */ #define EXEC_QUEUE_FLAG_HIGH_PRIORITY BIT(4) -/* queue used for UMD submission */ -#define EXEC_QUEUE_FLAG_UMD_SUBMISSION BIT(5)/** * @flags: flags for this exec queue, should statically setup aside from ban
drivers/gpu/drm/xe/xe_guc_submit.c +2 -2
@@ -1522,7 +1522,7 @@ static int guc_exec_queue_init(struct xe_exec_queue *q)xe_sched_stop (sched); q->guc->db.id =-1 ; -if (q->flags &EXEC_QUEUE_FLAG_UMD_SUBMISSION ) { +if (xe_exec_queue_is_usermap (q)) { db_id =xe_guc_db_mgr_reserve_id_locked (&guc->dbm);if (db_id <0 ) { err = db_id;
@@ -1532,7 +1532,7 @@ static int guc_exec_queue_init(struct xe_exec_queue *q)mutex_unlock (&guc->submission_state.lock); -if (q->flags &EXEC_QUEUE_FLAG_UMD_SUBMISSION ) { +if (xe_exec_queue_is_usermap (q)) { q->guc->db.id = db_id; err =create_doorbell (guc, q);if (err)
drivers/gpu/drm/xe/xe_lrc.c +2 -2
@@ -18,7 +18,7 @@#include "xe_bo.h" #include "xe_device.h" #include "xe_drm_client.h" -#include "xe_exec_queue_types.h" +#include "xe_exec_queue.h" #include "xe_gt.h" #include "xe_gt_printk.h" #include "xe_hw_fence.h"
@@ -912,7 +912,7 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_exec_queue *q,void *init_data =NULL ;u32 arb_enable;u32 lrc_size; -bool user_queue = q && q->flags &EXEC_QUEUE_FLAG_UMD_SUBMISSION ; +bool user_queue = q &&xe_exec_queue_is_usermap (q);;enum ttm_bo_type submit_type = user_queue ? ttm_bo_type_device : ttm_bo_type_kernel; unsigned int submit_flags = user_queue ?
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 19/29 drm/xe: Do not allow usermap exec queues in exec IOCTL
In reply to Matthew BrostNot supported at the moment, may need something in the no doorbells available.
--- drivers/gpu/drm/xe/xe_exec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_exec.c +2 -1
@@ -132,7 +132,8 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)if (XE_IOCTL_DBG (xe, !q))return -ENOENT ; -if (XE_IOCTL_DBG (xe, q->flags &EXEC_QUEUE_FLAG_VM )) { +if (XE_IOCTL_DBG (xe, q->flags &EXEC_QUEUE_FLAG_VM || +xe_exec_queue_is_usermap (q))) { err = -EINVAL ; goto err_exec_queue; }
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 20/29 drm/xe: Teach GuC backend to kill usermap queues
In reply to Matthew BrostUsermap exec queue's teardown (kill) differs from other exec queues as no job is available, a doorbell is mapped, and the kill should be immediate.
A follow up could unify LR queue cleanup with usermap but keeping this a seperate flow for now.
--- drivers/gpu/drm/xe/xe_guc_exec_queue_types.h | 2 +- drivers/gpu/drm/xe/xe_guc_submit.c | 56 +++++++++++++++++++- 2 files changed, 55 insertions(+), 3 deletions(-)
drivers/gpu/drm/xe/xe_guc_exec_queue_types.h +1 -1
@@ -29,7 +29,7 @@ struct xe_guc_exec_queue {* a message needs to sent through the GPU scheduler but memory * allocations are not allowed. */ -#define MAX_STATIC_MSG_TYPE 3 +#define MAX_STATIC_MSG_TYPE 4struct xe_sched_msg static_msgs[MAX_STATIC_MSG_TYPE ];/** @lr_tdr: long running TDR worker */ struct work_struct lr_tdr;
drivers/gpu/drm/xe/xe_guc_submit.c +54 -2
109 lines not on this page · raw message
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 21/29 drm/xe: Enable preempt fences on usermap queues
In reply to Matthew BrostPreempt fences are used by usermap queues to implement dynamic memory (BO eviction, userptr invalidation), enable preempt fences on usermap queues.
--- drivers/gpu/drm/xe/xe_exec_queue.c | 3 ++- drivers/gpu/drm/xe/xe_pt.c | 3 +-- drivers/gpu/drm/xe/xe_vm.c | 18 ++++++++---------- drivers/gpu/drm/xe/xe_vm.h | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-)
drivers/gpu/drm/xe/xe_exec_queue.c +2 -1
@@ -794,7 +794,8 @@ int xe_exec_queue_create_ioctl(struct drm_device *dev, void *data,if (IS_ERR (q))return PTR_ERR (q); -if (xe_vm_in_preempt_fence_mode (vm)) { +if (xe_vm_in_preempt_fence_mode (vm) || +xe_exec_queue_is_usermap (q)) { q->lr.context =dma_fence_context_alloc (1 ); err =xe_vm_add_compute_exec_queue (vm, q);
drivers/gpu/drm/xe/xe_pt.c +1 -2
@@ -1882,8 +1882,7 @@ static void bind_op_commit(struct xe_vm *vm, struct xe_tile *tile,* the rebind worker */ if (pt_update_ops->wait_vm_bookkeep && -xe_vm_in_preempt_fence_mode (vm) && - !current->mm) + vm->preempt.num_exec_queues && !current->mm)xe_vm_queue_rebind_worker (vm); }
drivers/gpu/drm/xe/xe_vm.c +8 -10
@@ -229,7 +229,8 @@ int xe_vm_add_compute_exec_queue(struct xe_vm *vm, struct xe_exec_queue *q)int err;bool wait; -xe_assert (vm->xe,xe_vm_in_preempt_fence_mode (vm)); +xe_assert (vm->xe,xe_vm_in_preempt_fence_mode (vm) || +xe_exec_queue_is_usermap (q));down_write (&vm->lock); err =drm_gpuvm_exec_lock (&vm_exec);
@@ -280,7 +281,7 @@ int xe_vm_add_compute_exec_queue(struct xe_vm *vm, struct xe_exec_queue *q)*/ void xe_vm_remove_compute_exec_queue (struct xe_vm *vm,struct xe_exec_queue *q) { -if (!xe_vm_in_preempt_fence_mode (vm)) +if (!xe_vm_in_preempt_fence_mode (vm) && !xe_exec_queue_is_usermap (q))return ;down_write (&vm->lock);
@@ -487,7 +488,7 @@ static void preempt_rebind_work_func(struct work_struct *w)long wait;int __maybe_unused tries =0 ; -xe_assert (vm->xe,xe_vm_in_preempt_fence_mode (vm)); +xe_assert (vm->xe, !xe_vm_in_fault_mode (vm));trace_xe_vm_rebind_worker_enter (vm);down_write (&vm->lock);
@@ -1467,10 +1468,9 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags) vm->batch_invalidate_tlb = true; } -if (vm->flags &XE_VM_FLAG_LR_MODE ) { -INIT_WORK (&vm->preempt.rebind_work, preempt_rebind_work_func); +INIT_WORK (&vm->preempt.rebind_work, preempt_rebind_work_func); +if (vm->flags &XE_VM_FLAG_LR_MODE ) vm->batch_invalidate_tlb = false; - }/* Fill pt_root after allocating scratch tables */ for_each_tile (tile, xe, id) {
@@ -1543,8 +1543,7 @@ void xe_vm_close_and_put(struct xe_vm *vm)xe_assert (xe, !vm->preempt.num_exec_queues);xe_vm_close (vm); -if (xe_vm_in_preempt_fence_mode (vm)) -flush_work (&vm->preempt.rebind_work); +flush_work (&vm->preempt.rebind_work);down_write (&vm->lock);for_each_tile (tile, xe, id) {
@@ -1644,8 +1643,7 @@ static void vm_destroy_work_func(struct work_struct *w)/* xe_vm_close_and_put was not called? */ xe_assert (xe, !vm->size); -if (xe_vm_in_preempt_fence_mode (vm)) -flush_work (&vm->preempt.rebind_work); +flush_work (&vm->preempt.rebind_work);mutex_destroy (&vm->snap_mutex);
drivers/gpu/drm/xe/xe_vm.h +1 -1
@@ -216,7 +216,7 @@ int xe_vm_invalidate_vma(struct xe_vma *vma);static inline void xe_vm_queue_rebind_worker (struct xe_vm *vm) { -xe_assert (vm->xe,xe_vm_in_preempt_fence_mode (vm)); +xe_assert (vm->xe, !xe_vm_in_fault_mode (vm));queue_work (vm->xe->ordered_wq, &vm->preempt.rebind_work); }
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 22/29 drm/xe/uapi: Add uAPI to convert user semaphore to / from drm syncobj
In reply to Matthew BrostSimple interface to allow user space to share user syncs with kernel syncs (dma-fences). The idea also is when user syncs are converted to kernel syncs, preemption is guarded against until the kernel sync signals. This is required to adhere to dma-fencing rules (no memory allocates done in path of dma-fence, resume after preemption requires memory allocations).
FIXME: uAPI likely to change, perhaps in drm generic way. Currently enough for a PoC and enable initial Mesa development.
--- include/uapi/drm/xe_drm.h | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+)
include/uapi/drm/xe_drm.h +62 -0
@@ -102,6 +102,7 @@ extern "C" {#define DRM_XE_EXEC 0x09#define DRM_XE_WAIT_USER_FENCE 0x0a#define DRM_XE_OBSERVATION 0x0b +#define DRM_XE_VM_CONVERT_FENCE 0x0c/* Must be kept compact -- no holes */
@@ -117,6 +118,7 @@ extern "C" {#define DRM_IOCTL_XE_EXEC DRM_IOW(DRM_COMMAND_BASE + DRM_XE_EXEC, struct drm_xe_exec)#define DRM_IOCTL_XE_WAIT_USER_FENCE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_WAIT_USER_FENCE, struct drm_xe_wait_user_fence)#define DRM_IOCTL_XE_OBSERVATION DRM_IOW(DRM_COMMAND_BASE + DRM_XE_OBSERVATION, struct drm_xe_observation_param) +#define DRM_IOCTL_XE_VM_CONVERT_FENCE DRM_IOW(DRM_COMMAND_BASE + DRM_XE_VM_CONVERT_FENCE, struct drm_xe_vm_convert_fence)/** * DOC: Xe IOCTL Extensions
@@ -1796,6 +1798,66 @@ struct drm_xe_oa_stream_info {__u64 reserved[3 ]; }; +/** +* struct drm_xe_semaphore - Semaphore +*/ +struct drm_xe_semaphore { +/** +* @handle: Handle for the semaphore. Must be bound to the VM when +* passed into drm_xe_vm_convert_fence. +*/ +__u32 handle; + +/** @offset: Offset in BO for semaphore, must QW aligned */ +__u32 offset; + +/** @seqno: Sequence number of semaphore */ +__u64 seqno; + +/** @token: Semaphore token - MBZ as not supported yet */ +__u64 token; + +/** @reserved: reserved for future use */ +__u64 reserved[2 ]; +}; + +/** +* struct drm_xe_vm_convert_fence - Convert semaphore to / from syncobj +* +* DRM_XE_SYNC_FLAG_SIGNAL set indicates semaphore -> syncobj +* DRM_XE_SYNC_FLAG_SIGNAL clear indicates syncobj -> semaphore +*/ +struct drm_xe_vm_convert_fence { +/** +* @extensions: Pointer to the first extension struct, if any +*/ +__u64 extensions; + +/** @vm_id: VM ID */ +__u32 vm_id; + +/** @flags: Flags - MBZ */ +__u32 flags; + +/** @pad: MBZ */ +__u32 pad; + +/** +* @num_syncs: Number of struct drm_xe_sync and struct drm_xe_semaphore +* in arrays. +*/ +__u32 num_syncs; + +/** @syncs: Pointer to struct drm_xe_sync array. */ +__u64 syncs; + +/** @semaphores: Pointer to struct drm_xe_semaphore array. */ +__u64 semaphores; + +/** @reserved: reserved for future use */ +__u64 reserved[2 ]; +}; +#if defined(__cplusplus) }#endif
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 23/29 drm/xe: Add user fence IRQ handler
In reply to Matthew BrostImported user fences will not be tied to a specific queue or hardware engine class. Therefore, a device IRQ handler is needed to signal the associated exported DMA fences.
--- drivers/gpu/drm/xe/xe_device.c | 4 ++++ drivers/gpu/drm/xe/xe_device_types.h | 3 +++ drivers/gpu/drm/xe/xe_hw_engine.c | 4 +++- 3 files changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_device.c +4 -0
@@ -39,6 +39,7 @@#include "xe_gt_sriov_vf.h" #include "xe_guc.h" #include "xe_hw_engine_group.h" +#include "xe_hw_fence.h" #include "xe_hwmon.h" #include "xe_irq.h" #include "xe_memirq.h"
@@ -902,6 +903,7 @@ int xe_device_probe(struct xe_device *xe)if (err) goto err; +xe_hw_fence_irq_init (&xe->user_fence_irq);for_each_gt (gt, xe, id) { last_gt = id;
@@ -944,6 +946,7 @@ int xe_device_probe(struct xe_device *xe)xe_oa_fini (xe); err_fini_gt: +xe_hw_fence_irq_finish (&xe->user_fence_irq);for_each_gt (gt, xe, id) {if (id < last_gt)xe_gt_remove (gt);
@@ -979,6 +982,7 @@ void xe_device_remove(struct xe_device *xe)xe_heci_gsc_fini (xe); +xe_hw_fence_irq_finish (&xe->user_fence_irq);for_each_gt (gt, xe, id)xe_gt_remove (gt); }
drivers/gpu/drm/xe/xe_device_types.h +3 -0
@@ -507,6 +507,9 @@ struct xe_device {int mode; } wedged; +/** @user_fence_irq: User fence IRQ handler */ +struct xe_hw_fence_irq user_fence_irq; +#ifdef TEST_VM_OPS_ERROR /** * @vm_inject_error_position: inject errors at different places in VM
drivers/gpu/drm/xe/xe_hw_engine.c +3 -1
@@ -822,8 +822,10 @@ void xe_hw_engine_handle_irq(struct xe_hw_engine *hwe, u16 intr_vec)if (hwe->irq_handler) hwe->irq_handler (hwe, intr_vec); -if (intr_vec >_RENDER_USER_INTERRUPT ) +if (intr_vec >_RENDER_USER_INTERRUPT ) { +xe_hw_fence_irq_run (>_to_xe (hwe->gt)->user_fence_irq);xe_hw_fence_irq_run (hwe->fence_irq); + } }/**
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 24/29 drm/xe: Add xe_hw_fence_user_init
In reply to Matthew BrostAdd xe_hw_fence_user_init which can create a struct xe_hw_fence from a user input rather than internal LRC state. Used to import user fence and export them as dma fences.
--- drivers/gpu/drm/xe/xe_hw_fence.c | 17 +++++++++++++++++ drivers/gpu/drm/xe/xe_hw_fence.h | 3 +++ 2 files changed, 20 insertions(+)
drivers/gpu/drm/xe/xe_hw_fence.c +17 -0
@@ -263,3 +263,20 @@ void xe_hw_fence_init(struct dma_fence *fence, struct xe_hw_fence_ctx *ctx,trace_xe_hw_fence_create (hw_fence); } + +void xe_hw_fence_user_init (struct dma_fence *fence,struct xe_device *xe, +struct iosys_map seqno_map,u64 seqno) +{ +struct xe_hw_fence *hw_fence = +container_of (fence,typeof (*hw_fence), dma); + + hw_fence->xe = xe; +snprintf (hw_fence->name,sizeof (hw_fence->name),"user" ); + hw_fence->seqno_map = seqno_map; + +INIT_LIST_HEAD (&hw_fence->irq_link); +dma_fence_init (fence, &xe_hw_fence_ops, &xe->user_fence_irq.lock, +dma_fence_context_alloc (1 ), seqno); + +trace_xe_hw_fence_create (hw_fence); +}
drivers/gpu/drm/xe/xe_hw_fence.h +3 -0
@@ -30,4 +30,7 @@ void xe_hw_fence_free(struct dma_fence *fence);void xe_hw_fence_init (struct dma_fence *fence,struct xe_hw_fence_ctx *ctx,struct iosys_map seqno_map); +void xe_hw_fence_user_init (struct dma_fence *fence,struct xe_device *xe, +struct iosys_map seqno_map,u64 seqno); +#endif
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 25/29 drm/xe: Add a message lock to the Xe GPU scheduler
In reply to Matthew BrostStop abusing job list lock for message, use a dedicated lock. This lock will soon be able to be taken in IRQ contexts, using irqsave for simplicity. Can to tweaked in a follow up as needed.
--- drivers/gpu/drm/xe/xe_gpu_scheduler.c | 19 ++++++++++++------- drivers/gpu/drm/xe/xe_gpu_scheduler.h | 12 ++++-------- drivers/gpu/drm/xe/xe_gpu_scheduler_types.h | 2 ++ drivers/gpu/drm/xe/xe_guc_submit.c | 15 +++++++++------ 4 files changed, 27 insertions(+), 21 deletions(-)
drivers/gpu/drm/xe/xe_gpu_scheduler.c +12 -7
@@ -14,25 +14,27 @@ static void xe_sched_process_msg_queue(struct xe_gpu_scheduler *sched)static void xe_sched_process_msg_queue_if_ready (struct xe_gpu_scheduler *sched) {struct xe_sched_msg *msg; +unsigned long flags; -xe_sched_msg_lock (sched); +xe_sched_msg_lock (sched, flags); msg = list_first_entry_or_null(&sched->msgs, struct xe_sched_msg, link);if (msg)xe_sched_process_msg_queue (sched); -xe_sched_msg_unlock (sched); +xe_sched_msg_unlock (sched, flags); }static struct xe_sched_msg *xe_sched_get_msg (struct xe_gpu_scheduler *sched) {struct xe_sched_msg *msg; +unsigned long flags; -xe_sched_msg_lock (sched); +xe_sched_msg_lock (sched, flags); msg =list_first_entry_or_null (&sched->msgs, struct xe_sched_msg, link);if (msg)list_del_init (&msg->link); -xe_sched_msg_unlock (sched); +xe_sched_msg_unlock (sched, flags);return msg; }
@@ -64,6 +66,7 @@ int xe_sched_init(struct xe_gpu_scheduler *sched, struct device *dev) { sched->ops = xe_ops; +spin_lock_init (&sched->msg_lock);INIT_LIST_HEAD (&sched->msgs);INIT_WORK (&sched->work_process_msg, xe_sched_process_msg_work);
@@ -98,15 +101,17 @@ void xe_sched_submission_resume_tdr(struct xe_gpu_scheduler *sched)void xe_sched_add_msg (struct xe_gpu_scheduler *sched,struct xe_sched_msg *msg) { -xe_sched_msg_lock (sched); +unsigned long flags; + +xe_sched_msg_lock (sched, flags);xe_sched_add_msg_locked (sched, msg); -xe_sched_msg_unlock (sched); +xe_sched_msg_unlock (sched, flags); }void xe_sched_add_msg_locked (struct xe_gpu_scheduler *sched,struct xe_sched_msg *msg) { -lockdep_assert_held (&sched->base.job_list_lock); +lockdep_assert_held (&sched->msg_lock);list_add_tail (&msg->link, &sched->msgs);xe_sched_process_msg_queue (sched);
drivers/gpu/drm/xe/xe_gpu_scheduler.h +4 -8
@@ -29,15 +29,11 @@ void xe_sched_add_msg(struct xe_gpu_scheduler *sched,void xe_sched_add_msg_locked (struct xe_gpu_scheduler *sched,struct xe_sched_msg *msg); -static inline void xe_sched_msg_lock (struct xe_gpu_scheduler *sched) -{ -spin_lock (&sched->base.job_list_lock); -} +#define xe_sched_msg_lock (sched, flags) \ + spin_lock_irqsave(&sched->msg_lock, flags) -static inline void xe_sched_msg_unlock (struct xe_gpu_scheduler *sched) -{ -spin_unlock (&sched->base.job_list_lock); -} +#define xe_sched_msg_unlock (sched, flags) \ + spin_unlock_irqrestore(&sched->msg_lock, flags)static inline void xe_sched_stop (struct xe_gpu_scheduler *sched) {
drivers/gpu/drm/xe/xe_gpu_scheduler_types.h +2 -0
@@ -47,6 +47,8 @@ struct xe_gpu_scheduler {const struct xe_sched_backend_ops *ops;/** @msgs: list of messages to be processed in @work_process_msg */ struct list_head msgs; +/** @msg_lock: Lock for messages */ +spinlock_t msg_lock;/** @work_process_msg: processes messages */ struct work_struct work_process_msg; };
drivers/gpu/drm/xe/xe_guc_submit.c +9 -6
@@ -1704,14 +1704,15 @@ static int guc_exec_queue_suspend(struct xe_exec_queue *q) {struct xe_gpu_scheduler *sched = &q->guc->sched;struct xe_sched_msg *msg = q->guc->static_msgs +STATIC_MSG_SUSPEND ; +unsigned long flags;if (exec_queue_killed_or_banned_or_wedged (q))return -EINVAL ; -xe_sched_msg_lock (sched); +xe_sched_msg_lock (sched, flags);if (guc_exec_queue_try_add_msg (q, msg,SUSPEND )) q->guc->suspend_pending = true; -xe_sched_msg_unlock (sched); +xe_sched_msg_unlock (sched, flags);return 0 ; }
@@ -1751,30 +1752,32 @@ static void guc_exec_queue_resume(struct xe_exec_queue *q)struct xe_gpu_scheduler *sched = &q->guc->sched;struct xe_sched_msg *msg = q->guc->static_msgs +STATIC_MSG_RESUME ;struct xe_guc *guc =exec_queue_to_guc (q); +unsigned long flags;xe_gt_assert (guc_to_gt (guc), !q->guc->suspend_pending); -xe_sched_msg_lock (sched); +xe_sched_msg_lock (sched, flags);guc_exec_queue_try_add_msg (q, msg,RESUME ); -xe_sched_msg_unlock (sched); +xe_sched_msg_unlock (sched, flags); }static void guc_exec_queue_kill_user (struct xe_exec_queue *q) {struct xe_gpu_scheduler *sched = &q->guc->sched;struct xe_sched_msg *msg = q->guc->static_msgs +STATIC_MSG_KILL_USER ; +unsigned long flags;if (exec_queue_extra_ref (q))return ;set_exec_queue_banned (q); -xe_sched_msg_lock (sched); +xe_sched_msg_lock (sched, flags);if (guc_exec_queue_try_add_msg (q, msg,KILL_USER )) {set_exec_queue_extra_ref (q);xe_exec_queue_get (q); } -xe_sched_msg_unlock (sched); +xe_sched_msg_unlock (sched, flags); }static bool guc_exec_queue_reset_status (struct xe_exec_queue *q)
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 26/29 drm/xe: Always wait on preempt fences in vma_check_userptr
In reply to Matthew BrostThe assumption only a VM in preempt fence mode has preempt fences attached is not true, preempt fences can be attached to a dma-resv VM if user queues are open.
--- drivers/gpu/drm/xe/xe_pt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_pt.c +1 -1
@@ -1231,7 +1231,7 @@ static int vma_check_userptr(struct xe_vm *vm, struct xe_vma *vma, &vm->userptr.invalidated);spin_unlock (&vm->userptr.invalidated_lock); -if (xe_vm_in_preempt_fence_mode (vm)) { +if (vm->preempt.num_exec_queues) {struct dma_resv_iter cursor;struct dma_fence *fence;long err;
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 27/29 drm/xe: Teach xe_sync layer about drm_xe_semaphore
In reply to Matthew BrostTeach xe_sync layer about drm_xe_semaphore which is used import / export user fences.
--- drivers/gpu/drm/xe/xe_sync.c | 90 ++++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_sync.h | 8 +++ drivers/gpu/drm/xe/xe_sync_types.h | 5 +- 3 files changed, 102 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_sync.c +90 -0
@@ -6,6 +6,7 @@#include "xe_sync.h" #include <linux/dma-fence-array.h> +#include <linux/dma-fence-user-fence.h> #include <linux/kthread.h> #include <linux/sched/mm.h> #include <linux/uaccess.h>
@@ -14,11 +15,15 @@#include <drm/drm_syncobj.h> #include <uapi/drm/xe_drm.h> +#include "xe_bo.h" #include "xe_device_types.h" #include "xe_exec_queue.h" +#include "xe_hw_fence.h" #include "xe_macros.h" #include "xe_sched_job_types.h" +#define IS_UNINSTALLED_HW_FENCE BIT(31) +struct xe_user_fence {struct xe_device *xe;struct kref refcount;
@@ -211,6 +216,74 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,return 0 ; } +int xe_sync_semaphore_parse (struct xe_device *xe,struct xe_file *xef, +struct xe_sync_entry *sync, +struct drm_xe_semaphore __user *semaphore_user, +unsigned int flags) +{ +struct drm_xe_semaphore semaphore_in; +struct drm_gem_object *gem_obj; +struct xe_bo *bo; + +if (copy_from_user (&semaphore_in, semaphore_user, +sizeof (*semaphore_user))) +return -EFAULT ; + +if (XE_IOCTL_DBG (xe, semaphore_in.offset &0x7 || + !semaphore_in.handle || semaphore_in.token || + semaphore_in.reserved[0 ] || semaphore_in.reserved[1 ])) +return -EINVAL ; + + gem_obj =drm_gem_object_lookup (xef->drm, semaphore_in.handle); +if (XE_IOCTL_DBG (xe, !gem_obj)) +return -ENOENT ; + + bo =gem_to_xe_bo (gem_obj); + +if (XE_IOCTL_DBG (xe, bo->size < semaphore_in.offset)) { +xe_bo_put (bo); +return -EINVAL ; + } + +if (flags &DRM_XE_SYNC_FLAG_SIGNAL ) { +struct iosys_map vmap = sync->bo->vmap; +struct dma_fence *fence; + + sync->chain_fence =dma_fence_chain_alloc (); +if (!sync->chain_fence) { +xe_bo_put (bo); +dma_fence_chain_free (sync->chain_fence); +return -ENOMEM ; + } + + fence =xe_hw_fence_alloc (); +if (IS_ERR (fence)) { +xe_bo_put (bo); +return PTR_ERR (fence); + } + + vmap = bo->vmap; +iosys_map_incr (&vmap, semaphore_in.offset); + +xe_hw_fence_user_init (fence, xe, vmap, semaphore_in.seqno); + sync->fence = fence; + sync->flags =IS_UNINSTALLED_HW_FENCE ; + }else { + sync->user_fence =dma_fence_user_fence_alloc (); +if (XE_IOCTL_DBG (xe, !sync->user_fence)) { +xe_bo_put (bo); +return PTR_ERR (sync->ufence); + } + + sync->addr = semaphore_in.offset; + sync->timeline_value = semaphore_in.seqno; + sync->flags =DRM_XE_SYNC_FLAG_SIGNAL ; + } + sync->bo = bo; + +return 0 ; +} +int xe_sync_entry_add_deps (struct xe_sync_entry *sync,struct xe_sched_job *job) {if (sync->fence)
@@ -249,17 +322,34 @@ void xe_sync_entry_signal(struct xe_sync_entry *sync, struct dma_fence *fence)user_fence_put (sync->ufence);dma_fence_put (fence); } + }else if (sync->user_fence) { +struct iosys_map vmap = sync->bo->vmap; + +iosys_map_incr (&vmap, sync->addr); +dma_fence_user_fence_attach (fence, sync->user_fence, + &vmap, sync->timeline_value); + sync->user_fence =NULL ; } } +void xe_sync_entry_hw_fence_installed (struct xe_sync_entry *sync) +{ + sync->flags &= ~IS_UNINSTALLED_HW_FENCE ; +} +void xe_sync_entry_cleanup (struct xe_sync_entry *sync) {if (sync->syncobj)drm_syncobj_put (sync->syncobj); +xe_bo_put (sync->bo); +if (sync->flags &IS_UNINSTALLED_HW_FENCE ) +dma_fence_set_error (sync->fence, -ECANCELED );dma_fence_put (sync->fence);dma_fence_chain_free (sync->chain_fence);if (sync->ufence)user_fence_put (sync->ufence); +if (sync->user_fence) +dma_fence_user_fence_free (sync->user_fence); }/**
drivers/gpu/drm/xe/xe_sync.h +8 -0
@@ -8,6 +8,9 @@#include "xe_sync_types.h" +struct drm_xe_semaphore ; +struct drm_xe_sync ; +struct xe_device ;struct xe_exec_queue ;struct xe_file ;
@@ -22,10 +25,15 @@ int xe_sync_entry_parse(struct xe_device *xe, struct xe_file *xef,struct xe_sync_entry *sync, struct drm_xe_sync __user *sync_user, unsigned int flags); +int xe_sync_semaphore_parse (struct xe_device *xe,struct xe_file *xef, +struct xe_sync_entry *sync, +struct drm_xe_semaphore __user *semaphore_user, +unsigned int flags);int xe_sync_entry_add_deps (struct xe_sync_entry *sync,struct xe_sched_job *job);void xe_sync_entry_signal (struct xe_sync_entry *sync,struct dma_fence *fence); +void xe_sync_entry_hw_fence_installed (struct xe_sync_entry *sync);void xe_sync_entry_cleanup (struct xe_sync_entry *sync);struct dma_fence * xe_sync_in_fence_get(struct xe_sync_entry *sync, int num_sync,
drivers/gpu/drm/xe/xe_sync_types.h +4 -1
@@ -11,14 +11,17 @@struct drm_syncobj ;struct dma_fence ;struct dma_fence_chain ; -struct drm_xe_sync ; +struct dma_fence_user_fence ;struct user_fence ; +struct xe_bo ;struct xe_sync_entry {struct drm_syncobj *syncobj;struct dma_fence *fence;struct dma_fence_chain *chain_fence;struct xe_user_fence *ufence; +struct dma_fence_user_fence *user_fence; +struct xe_bo *bo;u64 addr;u64 timeline_value;u32 type;
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 28/29 drm/xe: Add VM convert fence IOCTL
In reply to Matthew BrostBasically a version of the resume worker which also converts user syncs to kerenl syncs (dma-fences) and vise versa. The expoxrted dma-fences in the conversion guard against preemption which is required to avoid breaking dma fence rules (no memory allocations in path of dma-fence, resume requires memory allocations).
--- drivers/gpu/drm/xe/xe_device.c | 1 + drivers/gpu/drm/xe/xe_preempt_fence.c | 9 + drivers/gpu/drm/xe/xe_vm.c | 247 +++++++++++++++++++++++++- drivers/gpu/drm/xe/xe_vm.h | 2 + drivers/gpu/drm/xe/xe_vm_types.h | 4 + 5 files changed, 254 insertions(+), 9 deletions(-)
drivers/gpu/drm/xe/xe_device.c +1 -0
@@ -191,6 +191,7 @@ static const struct drm_ioctl_desc xe_ioctls[] = {DRM_IOCTL_DEF_DRV (XE_WAIT_USER_FENCE , xe_wait_user_fence_ioctl,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (XE_OBSERVATION , xe_observation_ioctl,DRM_RENDER_ALLOW ), + DRM_IOCTL_DEF_DRV(XE_VM_CONVERT_FENCE, xe_vm_convert_fence_ioctl, DRM_RENDER_ALLOW), };static long xe_drm_ioctl (struct file *file,unsigned int cmd,unsigned long arg)
drivers/gpu/drm/xe/xe_preempt_fence.c +9 -0
@@ -12,6 +12,14 @@ static struct xe_exec_queue *to_exec_queue(struct dma_fence_preempt *fence) return container_of(fence, struct xe_preempt_fence, base)->q; } +static struct dma_fence * +xe_preempt_fence_preempt_delay (struct dma_fence_preempt *fence) +{ +struct xe_exec_queue *q =to_exec_queue (fence); + +return q->vm->preempt.exported_fence ?:dma_fence_get_stub (); +} +static int xe_preempt_fence_preempt (struct dma_fence_preempt *fence) {struct xe_exec_queue *q =to_exec_queue (fence);
@@ -35,6 +43,7 @@ static void xe_preempt_fence_preempt_finished(struct dma_fence_preempt *fence) }static const struct dma_fence_preempt_ops xe_preempt_fence_ops = { + .preempt_delay = xe_preempt_fence_preempt_delay, .preempt = xe_preempt_fence_preempt, .preempt_wait = xe_preempt_fence_preempt_wait, .preempt_finished = xe_preempt_fence_preempt_finished,
drivers/gpu/drm/xe/xe_vm.c +238 -9
304 lines not on this page · raw message
drivers/gpu/drm/xe/xe_vm.h +2 -0
@@ -181,6 +181,8 @@ int xe_vm_destroy_ioctl(struct drm_device *dev, void *data, struct drm_file *file);int xe_vm_bind_ioctl (struct drm_device *dev,void *data,struct drm_file *file); +int xe_vm_convert_fence_ioctl (struct drm_device *dev,void *data, +struct drm_file *file);void xe_vm_close_and_put (struct xe_vm *vm);
drivers/gpu/drm/xe/xe_vm_types.h +4 -0
@@ -254,6 +254,10 @@ struct xe_vm {* BOs */ struct work_struct rebind_work; +/** @seqno: Seqno of exported dma-fences */ +u64 seqno; +/** @exported_fence: Chain of exported dma-fences */ +struct dma_fence *exported_fence; } preempt;/** @um: unified memory state */
Signature · 1 line
2.34.1
Matthew Brost
maintainerRFC PATCH 29/29 drm/xe: Add user fence TDR
In reply to Matthew BrostWe cannot let user fences exported as dma-fence run forever. Add a TDR to protect against this. If the TDR fires the entire VM is killed as dma-fences are not tied to an individual queue.
--- drivers/gpu/drm/xe/xe_vm.c | 164 +++++++++++++++++++++++++++++-- drivers/gpu/drm/xe/xe_vm_types.h | 22 +++++ 2 files changed, 179 insertions(+), 7 deletions(-)
drivers/gpu/drm/xe/xe_vm.c +157 -7
@@ -30,6 +30,7 @@#include "xe_exec_queue.h" #include "xe_gt_pagefault.h" #include "xe_gt_tlb_invalidation.h" +#include "xe_hw_fence.h" #include "xe_migrate.h" #include "xe_pat.h" #include "xe_pm.h"
@@ -336,11 +337,15 @@ void xe_vm_kill(struct xe_vm *vm, bool unlocked)if (unlocked)xe_vm_lock (vm, false); - vm->flags |=XE_VM_FLAG_BANNED ; -trace_xe_vm_kill (vm); +if (!(vm->flags |=XE_VM_FLAG_BANNED )) { + vm->flags |=XE_VM_FLAG_BANNED ; +trace_xe_vm_kill (vm); -list_for_each_entry (q, &vm->preempt.exec_queues, lr.link) - q->ops->kill (q); +list_for_each_entry (q, &vm->preempt.exec_queues, lr.link) + q->ops->kill (q); + +/* TODO: Unmap usermap doorbells */ + }if (unlocked)xe_vm_unlock (vm);
@@ -1393,6 +1398,9 @@ static void xe_vm_free_scratch(struct xe_vm *vm) } } +static void userfence_tdr (struct work_struct *w); +static void userfence_kill (struct work_struct *w); +struct xe_vm *xe_vm_create (struct xe_device *xe,u32 flags) {struct drm_gem_object *vm_resv_obj;
@@ -1517,6 +1525,12 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags) } } +spin_lock_init (&vm->userfence.lock); +INIT_LIST_HEAD (&vm->userfence.pending_list); + vm->userfence.timeout =HZ *5 ; +INIT_DELAYED_WORK (&vm->userfence.tdr, userfence_tdr); +INIT_WORK (&vm->userfence.kill_work, userfence_kill); +if (number_tiles >1 ) vm->composite_fence_ctx =dma_fence_context_alloc (1 );
@@ -1562,6 +1576,9 @@ void xe_vm_close_and_put(struct xe_vm *vm)xe_vm_close (vm);flush_work (&vm->preempt.rebind_work); +flush_delayed_work (&vm->userfence.tdr); +flush_work (&vm->userfence.kill_work); +down_write (&vm->lock);for_each_tile (tile, xe, id) {if (vm->q[id])
@@ -3449,6 +3466,114 @@ static int check_semaphores(struct xe_vm *vm, struct xe_sync_entry *syncs,return 0 ; } +struct tdr_item { +struct dma_fence *fence; +struct xe_vm *vm; +struct list_head link; +struct dma_fence_cb cb; +u64 deadline; +}; + +static void userfence_kill (struct work_struct *w) +{ +struct xe_vm *vm = + container_of(w, struct xe_vm, userfence.kill_work); + +down_write (&vm->lock); +xe_vm_kill (vm, true); +up_write (&vm->lock); +} + +static void userfence_tdr (struct work_struct *w) +{ +struct xe_vm *vm = + container_of(w, struct xe_vm, userfence.tdr.work); +struct tdr_item *tdr_item; +bool timeout = false, cookie =dma_fence_begin_signalling (); + +xe_hw_fence_irq_stop (&vm->xe->user_fence_irq); + +spin_lock_irq (&vm->userfence.lock); +list_for_each_entry (tdr_item, &vm->userfence.pending_list, link) { +if (!dma_fence_is_signaled (tdr_item->fence)) { +drm_notice (&vm->xe->drm, +"Timedout usermap fence: seqno=%llu, deadline=%llu, jiffies=%llu" , + tdr_item->fence->seqno, tdr_item->deadline, +get_jiffies_64 ()); +dma_fence_set_error (tdr_item->fence, -ETIME ); + timeout = true; + vm->userfence.timeout =0 ; + } + } +spin_unlock_irq (&vm->userfence.lock); + +xe_hw_fence_irq_start (&vm->xe->user_fence_irq); + +/* +* This is dma-fence signaling path so we cannot take the locks requires +* to kill a VM. Defer killing to a worker. +*/ +if (timeout) +schedule_work (&vm->userfence.kill_work); + +dma_fence_end_signalling (cookie); +} + +static void userfence_fence_cb (struct dma_fence *fence, +struct dma_fence_cb *cb) +{ + struct tdr_item *next, *tdr_item = container_of(cb, struct tdr_item, cb); +struct xe_vm *vm = tdr_item->vm; +struct xe_gt *gt =xe_device_get_gt (vm->xe,0 ); + +if (fence) +spin_lock (&vm->userfence.lock); +else +spin_lock_irq (&vm->userfence.lock); + +list_del (&tdr_item->link); + next =list_first_entry_or_null (&vm->userfence.pending_list, +typeof (*next), link); +if (next) +mod_delayed_work (gt->ordered_wq, &vm->userfence.tdr, + next->deadline -get_jiffies_64 ()); +else +cancel_delayed_work (&vm->userfence.tdr); + +if (fence) +spin_unlock (&vm->userfence.lock); +else +spin_unlock_irq (&vm->userfence.lock); + +dma_fence_put (tdr_item->fence); +xe_vm_put (tdr_item->vm); +kfree (tdr_item); +} + +static void userfence_tdr_add (struct xe_vm *vm,struct tdr_item *tdr_item, +struct dma_fence *fence) +{ +struct xe_gt *gt =xe_device_get_gt (vm->xe,0 ); +int ret; + + tdr_item->fence =dma_fence_get (fence); + tdr_item->vm =xe_vm_get (vm); +INIT_LIST_HEAD (&tdr_item->link); + tdr_item->deadline = vm->userfence.timeout +get_jiffies_64 (); + +spin_lock_irq (&vm->userfence.lock); +list_add_tail (&tdr_item->link, &vm->userfence.pending_list); +if (list_is_singular (&vm->userfence.pending_list)) +mod_delayed_work (gt->ordered_wq, + &vm->userfence.tdr, + vm->userfence.timeout); +spin_unlock_irq (&vm->userfence.lock); + + ret =dma_fence_add_callback (fence, &tdr_item->cb, userfence_fence_cb); +if (ret == -ENOENT ) +userfence_fence_cb (NULL , &tdr_item->cb); +} +int xe_vm_convert_fence_ioctl (struct drm_device *dev,void *data,struct drm_file *file) {
@@ -3459,6 +3584,7 @@ int xe_vm_convert_fence_ioctl(struct drm_device *dev, void *data,struct drm_xe_semaphore __user *semaphores_user;struct xe_sync_entry *syncs =NULL ;struct xe_vm *vm; +struct tdr_item **tdr_items =NULL ;int err =0 , i, num_syncs =0 ;bool done = false;struct drm_exec exec;
@@ -3493,6 +3619,12 @@ int xe_vm_convert_fence_ioctl(struct drm_device *dev, void *data, goto release_vm_lock; } + tdr_items =kcalloc (args->num_syncs,sizeof (*tdr_items),GFP_KERNEL ); +if (!tdr_items) { + err = -ENOMEM ; + goto release_vm_lock; + } + syncs_user =u64_to_user_ptr (args->syncs); semaphores_user =u64_to_user_ptr (args->semaphores);for (i =0 ; i < args->num_syncs; i++, num_syncs++) {
@@ -3505,6 +3637,15 @@ int xe_vm_convert_fence_ioctl(struct drm_device *dev, void *data,if (err) goto release_syncs; +if (sync->flags &DRM_XE_SYNC_FLAG_SIGNAL ) { + tdr_items[i] =kmalloc (sizeof (struct tdr_item ), +GFP_KERNEL ); +if (!tdr_items[i]) { +xe_sync_entry_cleanup (&syncs[i]); + goto release_syncs; + } + } + err =xe_sync_semaphore_parse (xe, xef, semaphore_sync, &semaphores_user[i], sync->flags);
@@ -3591,6 +3732,10 @@ int xe_vm_convert_fence_ioctl(struct drm_device *dev, void *data, &semaphore_sync->chain_fence->base; semaphore_sync->chain_fence =NULL ; +userfence_tdr_add (vm, tdr_items[i], + semaphore_sync->fence); + tdr_items[i] =0 ; + semaphore_sync->fence =NULL ;/* Ref owned by chain */ }else {xe_sync_entry_signal (semaphore_sync, sync->fence);
@@ -3617,9 +3762,13 @@ int xe_vm_convert_fence_ioctl(struct drm_device *dev, void *data, out_unlock:drm_exec_fini (&exec); release_syncs: -while (err != -EAGAIN && num_syncs--) { -xe_sync_entry_cleanup (&syncs[num_syncs]); -xe_sync_entry_cleanup (&syncs[args->num_syncs + num_syncs]); +if (err != -EAGAIN ) { +for (i =0 ; i < num_syncs; ++i) +kfree (tdr_items[i]); +while (num_syncs--) { +xe_sync_entry_cleanup (&syncs[num_syncs]); +xe_sync_entry_cleanup (&syncs[args->num_syncs + num_syncs]); + } } release_vm_lock:if (err == -EAGAIN )
@@ -3629,6 +3778,7 @@ int xe_vm_convert_fence_ioctl(struct drm_device *dev, void *data,xe_vm_put (vm);free_preempt_fences (&preempt_fences);kfree (syncs); +kfree (tdr_items);return err; }
drivers/gpu/drm/xe/xe_vm_types.h +22 -0
@@ -260,6 +260,28 @@ struct xe_vm {struct dma_fence *exported_fence; } preempt; +/** @userfence: User fence state */ +struct { +/** +* @userfence.lock: fence lock +*/ +spinlock_t lock; +/** +* @userfence.pending_list: pending fence list, protected by +* userfence.lock +*/ +struct list_head pending_list; +/** @userfence.tdr: fence TDR */ +struct delayed_work tdr; +/** @userfence.kill_work */ +struct work_struct kill_work; +/** +* @userfence.timeout: Fence timeout period, protected by +* userfence.lock +*/ +u32 timeout; + } userfence; +/** @um: unified memory state */ struct {/** @asid: address space ID, unique to each VM */
Signature · 1 line
2.34.1
Patchwork
CI✗ Fi.CI.BUILD: failure for UMD direct submission in Xe
In reply to Matthew Brost== Series Details ==
== Series Details ==
Series: UMD direct submission in Xe
URL : https://patchwork.freedesktop.org/series/141523/
State : failure
== Summary ==
Applying: dma-fence: Add dma_fence_preempt base class
Patch failed at 0001 dma-fence: Add dma_fence_preempt base class When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".