GPUVA with no uAPI changes
Subsystems (6)
Matthew Brost
maintainercover GPUVA with no uAPI changes
The patches from [1] rebased + address review feedback which do not include uAPI changes.
[1] https://patchwork.freedesktop.org/series/117156/
Danilo Krummrich (3):
maple_tree: split up MA_STATE() macro
drm: manager to keep track of GPUs VA mappings
drm: debugfs: provide infrastructure to dump a DRM GPU VA space
Matthew Brost (6):
drm/xe: Ban a VM if rebind worker hits an error drm/xe: Add helpers to hide struct xe_vma internals
maple_tree: Export mas_preallocate
drm/xe: Remove __xe_vm_bind forward declaration drm/xe: Port Xe to GPUVA
drm/xe: Avoid doing rebinds
Documentation/gpu/drm-mm.rst | 42 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_debugfs.c | 41 + drivers/gpu/drm/drm_gem.c | 3 + drivers/gpu/drm/drm_gpuva_mgr.c | 1971 ++++++++++++++++++ drivers/gpu/drm/xe/tests/xe_migrate.c | 2 +- drivers/gpu/drm/xe/xe_bo.c | 11 +- drivers/gpu/drm/xe/xe_device.c | 2 +- drivers/gpu/drm/xe/xe_engine.c | 13 + drivers/gpu/drm/xe/xe_exec.c | 8 +- drivers/gpu/drm/xe/xe_gt_pagefault.c | 23 +- drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c | 14 +- drivers/gpu/drm/xe/xe_migrate.c | 10 +- drivers/gpu/drm/xe/xe_pt.c | 129 +- drivers/gpu/drm/xe/xe_pt.h | 2 +- drivers/gpu/drm/xe/xe_trace.h | 15 +- drivers/gpu/drm/xe/xe_vm.c | 1973 ++++++++++--------- drivers/gpu/drm/xe/xe_vm.h | 104 +- drivers/gpu/drm/xe/xe_vm_madvise.c | 91 +- drivers/gpu/drm/xe/xe_vm_types.h | 175 +- include/drm/drm_debugfs.h | 25 + include/drm/drm_drv.h | 6 + include/drm/drm_gem.h | 52 + include/drm/drm_gpuva_mgr.h | 682 +++++++ include/linux/maple_tree.h | 7 +- lib/maple_tree.c | 1 + 26 files changed, 4167 insertions(+), 1236 deletions(-) create mode 100644 drivers/gpu/drm/drm_gpuva_mgr.c create mode 100644 include/drm/drm_gpuva_mgr.h
Signature · 1 line
2.34.1
Matthew Brost
maintainerPATCH 1/9 drm/xe: Ban a VM if rebind worker hits an error
We cannot recover a VM if a rebind worker hits an error, ban the VM if happens to ensure we do not attempt to place this VM on the hardware again.
A follow up will inform the user if this happens.
v2: Return -ECANCELED in exec VM closed or banned, check for closed or banned within VM lock.
--- drivers/gpu/drm/xe/xe_engine.c | 13 +++++++ drivers/gpu/drm/xe/xe_exec.c | 6 ++-- drivers/gpu/drm/xe/xe_trace.h | 5 +++ drivers/gpu/drm/xe/xe_vm.c | 55 ++++++++++++++++++++---------- drivers/gpu/drm/xe/xe_vm.h | 11 ++++++ drivers/gpu/drm/xe/xe_vm_madvise.c | 2 +- drivers/gpu/drm/xe/xe_vm_types.h | 5 +-- 7 files changed, 73 insertions(+), 24 deletions(-)
drivers/gpu/drm/xe/xe_engine.c +13 -0
@@ -597,10 +597,23 @@ int xe_engine_create_ioctl(struct drm_device *dev, void *data,if (XE_IOCTL_ERR (xe, !vm))return -ENOENT ; + err =down_read_interruptible (&vm->lock); +if (err) { +xe_vm_put (vm); +return err; + } + +if (XE_IOCTL_ERR (xe,xe_vm_is_closed_or_banned (vm))) { +up_read (&vm->lock); +xe_vm_put (vm); +return -ENOENT ; + } + e =xe_engine_create (xe, vm, logical_mask, args->width, hwe,xe_vm_no_dma_fences (vm) ?0 :ENGINE_FLAG_PERSISTENT ); +up_read (&vm->lock);xe_vm_put (vm);if (IS_ERR (e))return PTR_ERR (e);
drivers/gpu/drm/xe/xe_exec.c +3 -3
@@ -297,9 +297,9 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file)if (err) goto err_unlock_list; -if (xe_vm_is_closed (engine->vm)) { -drm_warn (&xe->drm,"Trying to schedule after vm is closed\n" ); - err = -EIO ; +if (xe_vm_is_closed_or_banned (engine->vm)) { +drm_warn (&xe->drm,"Trying to schedule after vm is closed or banned\n" ); + err = -ECANCELED ; goto err_engine_end; }
drivers/gpu/drm/xe/xe_trace.h +5 -0
@@ -477,6 +477,11 @@ DECLARE_EVENT_CLASS(xe_vm, __entry->asid) ); +DEFINE_EVENT (xe_vm, xe_vm_kill, + TP_PROTO(struct xe_vm *vm), +TP_ARGS (vm) +); +DEFINE_EVENT (xe_vm, xe_vm_create, TP_PROTO(struct xe_vm *vm), TP_ARGS(vm)
drivers/gpu/drm/xe/xe_vm.c +37 -18
136 lines not on this page · raw message
drivers/gpu/drm/xe/xe_vm.h +11 -0
@@ -49,6 +49,17 @@ static inline bool xe_vm_is_closed(struct xe_vm *vm)return !vm->size; } +static inline bool xe_vm_is_banned (struct xe_vm *vm) +{ +return vm->flags &XE_VM_FLAG_BANNED ; +} + +static inline bool xe_vm_is_closed_or_banned (struct xe_vm *vm) +{ +lockdep_assert_held (&vm->lock); +return xe_vm_is_closed (vm) ||xe_vm_is_banned (vm); +} +struct xe_vma *xe_vm_find_overlapping_vma (struct xe_vm *vm,const struct xe_vma *vma);
drivers/gpu/drm/xe/xe_vm_madvise.c +1 -1
@@ -313,7 +313,7 @@ int xe_vm_madvise_ioctl(struct drm_device *dev, void *data,if (XE_IOCTL_ERR (xe, !vm))return -EINVAL ; -if (XE_IOCTL_ERR (xe,xe_vm_is_closed (vm))) { +if (XE_IOCTL_ERR (xe,xe_vm_is_closed_or_banned (vm))) { err = -ENOENT ; goto put_vm; }
drivers/gpu/drm/xe/xe_vm_types.h +3 -2
@@ -183,8 +183,9 @@ struct xe_vm {#define XE_VM_FLAG_MIGRATION BIT(3)#define XE_VM_FLAG_SCRATCH_PAGE BIT(4)#define XE_VM_FLAG_FAULT_MODE BIT(5) -#define XE_VM_FLAG_GT_ID (flags) (((flags) >> 6) & 0x3) -#define XE_VM_FLAG_SET_TILE_ID (tile) ((tile)->id << 6) +#define XE_VM_FLAG_BANNED BIT(6) +#define XE_VM_FLAG_GT_ID (flags) (((flags) >> 7) & 0x3) +#define XE_VM_FLAG_SET_TILE_ID (tile) ((tile)->id << 7)unsigned long flags;/** @composite_fence_ctx: context composite fence */
Signature · 1 line
2.34.1
Matthew Brost
maintainerPATCH 2/9 drm/xe: Add helpers to hide struct xe_vma internals
In reply to Matthew BrostThis will help with the GPUVA port as the internals of struct xe_vma will change.
--- drivers/gpu/drm/xe/xe_bo.c | 4 +- drivers/gpu/drm/xe/xe_exec.c | 2 +- drivers/gpu/drm/xe/xe_gt_pagefault.c | 7 +- drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c | 14 +- drivers/gpu/drm/xe/xe_pt.c | 88 +++++------ drivers/gpu/drm/xe/xe_trace.h | 10 +- drivers/gpu/drm/xe/xe_vm.c | 163 ++++++++++---------- drivers/gpu/drm/xe/xe_vm.h | 76 +++++++-- drivers/gpu/drm/xe/xe_vm_madvise.c | 12 +- 9 files changed, 211 insertions(+), 165 deletions(-)
drivers/gpu/drm/xe/xe_bo.c +2 -2
@@ -411,7 +411,7 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo, }list_for_each_entry (vma, &bo->vmas, bo_link) { -struct xe_vm *vm = vma->vm; +struct xe_vm *vm =xe_vma_vm (vma);trace_xe_vma_evict (vma);
@@ -439,7 +439,7 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo, }else {bool vm_resv_locked = false; -struct xe_vm *vm = vma->vm; +struct xe_vm *vm =xe_vma_vm (vma);/* * We need to put the vma on the vm's rebind_list,
drivers/gpu/drm/xe/xe_exec.c +1 -1
@@ -126,7 +126,7 @@ static int xe_exec_begin(struct xe_engine *e, struct ww_acquire_ctx *ww,if (xe_vma_is_userptr (vma))continue ; - err =xe_bo_validate (vma->bo, vm, false); + err =xe_bo_validate (xe_vma_bo (vma), vm, false);if (err) {xe_vm_unlock_dma_resv (vm, tv_onstack, *tv, ww, objs); *tv =NULL ;
drivers/gpu/drm/xe/xe_gt_pagefault.c +4 -3
@@ -77,7 +77,8 @@ static bool vma_is_valid(struct xe_gt *gt, struct xe_vma *vma)static bool vma_matches (struct xe_vma *vma,struct xe_vma *lookup) { -if (lookup->start > vma->end || lookup->end < vma->start) +if (xe_vma_start (lookup) >xe_vma_end (vma) -1 || +xe_vma_end (lookup) -1 <xe_vma_start (vma))return false;return true;
@@ -171,7 +172,7 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf) }/* Lock VM and BOs dma-resv */ - bo = vma->bo; + bo =xe_vma_bo (vma);if (only_needs_bo_lock (bo)) {/* This path ensures the BO's LRU is updated */ ret =xe_bo_lock (bo, &ww, xe->info.tile_count, false);
@@ -538,7 +539,7 @@ static int handle_acc(struct xe_gt *gt, struct acc *acc) goto unlock_vm;/* Lock VM and BOs dma-resv */ - bo = vma->bo; + bo =xe_vma_bo (vma);if (only_needs_bo_lock (bo)) {/* This path ensures the BO's LRU is updated */ ret =xe_bo_lock (bo, &ww, xe->info.tile_count, false);
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c +7 -7
@@ -203,8 +203,8 @@ int xe_gt_tlb_invalidation_vma(struct xe_gt *gt,if (!xe->info.has_range_tlb_invalidation) { action[len++] =MAKE_INVAL_OP (XE_GUC_TLB_INVAL_FULL ); }else { -u64 start = vma->start; -u64 length = vma->end - vma->start +1 ; +u64 start =xe_vma_start (vma); +u64 length =xe_vma_size (vma);u64 align, end;if (length <SZ_4K )
@@ -217,12 +217,12 @@ int xe_gt_tlb_invalidation_vma(struct xe_gt *gt,* address mask covering the required range. */ align =roundup_pow_of_two (length); - start =ALIGN_DOWN (vma->start, align); - end =ALIGN (vma->start + length, align); + start =ALIGN_DOWN (xe_vma_start (vma), align); + end =ALIGN (xe_vma_end (vma), align); length = align;while (start + length < end) { length <<=1 ; - start =ALIGN_DOWN (vma->start, length); + start =ALIGN_DOWN (xe_vma_start (vma), length); }/*
@@ -231,7 +231,7 @@ int xe_gt_tlb_invalidation_vma(struct xe_gt *gt,*/ if (length >=SZ_2M ) { length =max_t (u64,SZ_16M , length); - start =ALIGN_DOWN (vma->start, length); + start =ALIGN_DOWN (xe_vma_start (vma), length); }XE_BUG_ON (length <SZ_4K );
@@ -240,7 +240,7 @@ int xe_gt_tlb_invalidation_vma(struct xe_gt *gt,XE_BUG_ON (!IS_ALIGNED (start, length)); action[len++] =MAKE_INVAL_OP (XE_GUC_TLB_INVAL_PAGE_SELECTIVE ); - action[len++] = vma->vm->usm.asid; + action[len++] =xe_vma_vm (vma)->usm.asid; action[len++] =lower_32_bits (start); action[len++] =upper_32_bits (start); action[len++] =ilog2 (length) -ilog2 (SZ_4K );
drivers/gpu/drm/xe/xe_pt.c +44 -44
236 lines not on this page · raw message
drivers/gpu/drm/xe/xe_trace.h +5 -5
@@ -18,7 +18,7 @@#include "xe_gt_types.h" #include "xe_guc_engine_types.h" #include "xe_sched_job.h" -#include "xe_vm_types.h" +#include "xe_vm.h" DECLARE_EVENT_CLASS(xe_gt_tlb_invalidation_fence, TP_PROTO(struct xe_gt_tlb_invalidation_fence *fence),
@@ -373,10 +373,10 @@ DECLARE_EVENT_CLASS(xe_vma,TP_fast_assign ( __entry->vma = (unsigned long)vma; - __entry->asid = vma->vm->usm.asid; - __entry->start = vma->start; - __entry->end = vma->end; - __entry->ptr = (u64 )vma->userptr.ptr; + __entry->asid =xe_vma_vm (vma)->usm.asid; + __entry->start =xe_vma_start (vma); + __entry->end =xe_vma_end (vma) -1 ; + __entry->ptr =xe_vma_userptr (vma); ), TP_printk("vma=0x%016llx, asid=0x%05x, start=0x%012llx, end=0x%012llx, ptr=0x%012llx,",
drivers/gpu/drm/xe/xe_vm.c +82 -81
463 lines not on this page · raw message
drivers/gpu/drm/xe/xe_vm.h +60 -16
88 lines not on this page · raw message
drivers/gpu/drm/xe/xe_vm_madvise.c +6 -6
@@ -30,7 +30,7 @@ static int madvise_preferred_mem_class(struct xe_device *xe, struct xe_vm *vm,struct xe_bo *bo;struct ww_acquire_ctx ww; - bo = vmas[i]->bo; + bo =xe_vma_bo (vmas[i]); err =xe_bo_lock (bo, &ww,0 , true);if (err)
@@ -55,7 +55,7 @@ static int madvise_preferred_gt(struct xe_device *xe, struct xe_vm *vm,struct xe_bo *bo;struct ww_acquire_ctx ww; - bo = vmas[i]->bo; + bo =xe_vma_bo (vmas[i]); err =xe_bo_lock (bo, &ww,0 , true);if (err)
@@ -91,7 +91,7 @@ static int madvise_preferred_mem_class_gt(struct xe_device *xe,struct xe_bo *bo;struct ww_acquire_ctx ww; - bo = vmas[i]->bo; + bo =xe_vma_bo (vmas[i]); err =xe_bo_lock (bo, &ww,0 , true);if (err)
@@ -114,7 +114,7 @@ static int madvise_cpu_atomic(struct xe_device *xe, struct xe_vm *vm,struct xe_bo *bo;struct ww_acquire_ctx ww; - bo = vmas[i]->bo; + bo =xe_vma_bo (vmas[i]);if (XE_IOCTL_ERR (xe, !(bo->flags &XE_BO_CREATE_SYSTEM_BIT )))return -EINVAL ;
@@ -145,7 +145,7 @@ static int madvise_device_atomic(struct xe_device *xe, struct xe_vm *vm,struct xe_bo *bo;struct ww_acquire_ctx ww; - bo = vmas[i]->bo; + bo =xe_vma_bo (vmas[i]);if (XE_IOCTL_ERR (xe, !(bo->flags &XE_BO_CREATE_VRAM0_BIT ) && !(bo->flags &XE_BO_CREATE_VRAM1_BIT )))return -EINVAL ;
@@ -176,7 +176,7 @@ static int madvise_priority(struct xe_device *xe, struct xe_vm *vm,struct xe_bo *bo;struct ww_acquire_ctx ww; - bo = vmas[i]->bo; + bo =xe_vma_bo (vmas[i]); err =xe_bo_lock (bo, &ww,0 , true);if (err)
Signature · 1 line
2.34.1
Matthew Brost
maintainerPATCH 3/9 maple_tree: Export mas_preallocate
In reply to Matthew BrostThe DRM GPUVA implementation needs this function.
--- lib/maple_tree.c | 1 + 1 file changed, 1 insertion(+)
lib/maple_tree.c +1 -0
@@ -5815,6 +5815,7 @@ int mas_preallocate(struct ma_state *mas, gfp_t gfp)mas_reset (mas);return ret; } +EXPORT_SYMBOL_GPL (mas_preallocate);/* * mas_destroy() - destroy a maple state.
Signature · 1 line
2.34.1
Matthew Brost
maintainerPATCH 4/9 maple_tree: split up MA_STATE() macro
In reply to Matthew BrostFrom: Danilo Krummrich <[email protected]>
Split up the MA_STATE() macro such that components using the maple tree can easily inherit from struct ma_state and build custom tree walk macros to hide their internals from users.
Example:
struct sample_iterator {
struct ma_state mas;
struct sample_mgr *mgr;
};\#define SAMPLE_ITERATOR(name, __mgr, start) \
struct sample_iterator name = { \
.mas = MA_STATE_INIT(&(__mgr)->mt, start, 0), \
.mgr = __mgr, \
}\#define sample_iter_for_each_range(it__, entry__, end__) \
mas_for_each(&(it__).mas, entry__, end__)--
struct sample *sample;SAMPLE_ITERATOR(si, min);
sample_iter_for_each_range(&si, sample, max) {
frob(mgr, sample);
}--- include/linux/maple_tree.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
include/linux/maple_tree.h +5 -2
@@ -423,8 +423,8 @@ struct ma_wr_state {#define MA_ERROR (err) \ ((struct maple_enode *)(((unsigned long)err << 2) | 2UL)) -#define MA_STATE (name, mt, first, end) \ - struct ma_state name = { \ +#define MA_STATE_INIT (mt, first, end) \ + { \ .tree = mt, \ .index = first, \ .last = end, \
@@ -435,6 +435,9 @@ struct ma_wr_state { .mas_flags = 0, \ } +#define MA_STATE (name, mt, first, end) \ + struct ma_state name = MA_STATE_INIT(mt, first, end) +#define MA_WR_STATE (name, ma_state, wr_entry) \ struct ma_wr_state name = { \ .mas = ma_state, \
Signature · 1 line
2.34.1
Matthew Brost
maintainerPATCH 5/9 drm: manager to keep track of GPUs VA mappings
In reply to Matthew BrostFrom: Danilo Krummrich <[email protected]>
Add infrastructure to keep track of GPU virtual address (VA) mappings with a decicated VA space manager implementation.
New UAPIs, motivated by Vulkan sparse memory bindings graphics drivers start implementing, allow userspace applications to request multiple and arbitrary GPU VA mappings of buffer objects. The DRM GPU VA manager is intended to serve the following purposes in this context.
1) Provide infrastructure to track GPU VA allocations and mappings, making use of the maple_tree.
2) Generically connect GPU VA mappings to their backing buffers, in particular DRM GEM objects.
3) Provide a common implementation to perform more complex mapping operations on the GPU VA space. In particular splitting and merging of GPU VA mappings, e.g. for intersecting mapping requests or partial unmap requests.
--- Documentation/gpu/drm-mm.rst | 42 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_gem.c | 3 + drivers/gpu/drm/drm_gpuva_mgr.c | 1971 +++++++++++++++++++++++++++++++ include/drm/drm_drv.h | 6 + include/drm/drm_gem.h | 52 + include/drm/drm_gpuva_mgr.h | 682 +++++++++++ 7 files changed, 2757 insertions(+) create mode 100644 drivers/gpu/drm/drm_gpuva_mgr.c create mode 100644 include/drm/drm_gpuva_mgr.h
Documentation/gpu/drm-mm.rst +42 -0
@@ -466,6 +466,48 @@ DRM MM Range Allocator Function References .. kernel-doc:: drivers/gpu/drm/drm_mm.c :export: +DRM GPU VA Manager +================== + +Overview +-------- + +.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c + :doc: Overview + +Split and Merge +--------------- + +.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c + :doc: Split and Merge + +Locking +------- + +.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c + :doc: Locking + +Examples +-------- + +.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c + :doc: Examples + +Quirks +------ + +.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c + :doc: Quirks + +DRM GPU VA Manager Function References +-------------------------------------- + +.. kernel-doc:: include/drm/drm_gpuva_mgr.h + :internal: + +.. kernel-doc:: drivers/gpu/drm/drm_gpuva_mgr.c + :export: + DRM Buddy Allocator ===================
drivers/gpu/drm/Makefile +1 -0
@@ -45,6 +45,7 @@ drm-y := \ drm_vblank.o \ drm_vblank_work.o \ drm_vma_manager.o \ + drm_gpuva_mgr.o \ drm_writeback.o drm-$(CONFIG_DRM_LEGACY) += \ drm_agpsupport.o \
drivers/gpu/drm/drm_gem.c +3 -0
@@ -164,6 +164,9 @@ void drm_gem_private_object_init(struct drm_device *dev,if (!obj->resv) obj->resv = &obj->_resv; +if (drm_core_check_feature (dev,DRIVER_GEM_GPUVA )) +drm_gem_gpuva_init (obj); +drm_vma_node_reset (&obj->vma_node);INIT_LIST_HEAD (&obj->lru_node); }
drivers/gpu/drm/drm_gpuva_mgr.c new file +1971 -0
1,971 lines not on this page · raw message
include/drm/drm_drv.h +6 -0
@@ -104,6 +104,12 @@ enum drm_driver_feature {* acceleration should be handled by two drivers that are connected using auxiliary bus. */ DRIVER_COMPUTE_ACCEL =BIT (7 ), +/** +* @DRIVER_GEM_GPUVA: +* +* Driver supports user defined GPU VA bindings for GEM objects. +*/ + DRIVER_GEM_GPUVA = BIT(8),/* IMPORTANT: Below are all the legacy flags, add new ones above. */
include/drm/drm_gem.h +52 -0
68 lines not on this page · raw message
include/drm/drm_gpuva_mgr.h new file +682 -0
682 lines not on this page · raw message
Signature · 1 line
2.34.1
Matthew Brost
maintainerPATCH 6/9 drm: debugfs: provide infrastructure to dump a DRM GPU VA space
In reply to Matthew BrostFrom: Danilo Krummrich <[email protected]>
This commit adds a function to dump a DRM GPU VA space and a macro for drivers to register the struct drm_info_list 'gpuvas' entry.
Most likely, most drivers might maintain one DRM GPU VA space per struct drm_file, but there might also be drivers not having a fixed relation between DRM GPU VA spaces and a DRM core infrastructure, hence we need the indirection via the driver iterating it's maintained DRM GPU VA spaces.
--- drivers/gpu/drm/drm_debugfs.c | 41 +++++++++++++++++++++++++++++++++++ include/drm/drm_debugfs.h | 25 +++++++++++++++++++++ 2 files changed, 66 insertions(+)
drivers/gpu/drm/drm_debugfs.c +41 -0
@@ -39,6 +39,7 @@#include <drm/drm_file.h> #include <drm/drm_gem.h> #include <drm/drm_managed.h> +#include <drm/drm_gpuva_mgr.h> #include "drm_crtc_internal.h" #include "drm_internal.h"
@@ -175,6 +176,46 @@ static const struct file_operations drm_debugfs_fops = { .release = single_release, }; +/** +* drm_debugfs_gpuva_info - dump the given DRM GPU VA space +* @m: pointer to the &seq_file to write +* @mgr: the &drm_gpuva_manager representing the GPU VA space +* +* Dumps the GPU VA mappings of a given DRM GPU VA manager. +* +* For each DRM GPU VA space drivers should call this function from their +* &drm_info_list's show callback. +* +* Returns: 0 on success, -ENODEV if the &mgr is not initialized +*/ +int drm_debugfs_gpuva_info (struct seq_file *m, +struct drm_gpuva_manager *mgr) +{ +DRM_GPUVA_ITER (it, mgr,0 ); +struct drm_gpuva *va, *kva = &mgr->kernel_alloc_node; + +if (!mgr->name) +return -ENODEV ; + +seq_printf (m,"DRM GPU VA space (%s) [0x%016llx;0x%016llx]\n" , + mgr->name, mgr->mm_start, mgr->mm_start + mgr->mm_range); +seq_printf (m,"Kernel reserved node [0x%016llx;0x%016llx]\n" , + kva->va.addr, kva->va.addr + kva->va.range); +seq_puts (m,"\n" ); +seq_puts (m," VAs | start | range | end | object | object offset\n" ); +seq_puts (m,"-------------------------------------------------------------------------------------------------------------\n" ); +drm_gpuva_iter_for_each (va, it) { +if (unlikely (va == &mgr->kernel_alloc_node)) +continue ; + +seq_printf (m," | 0x%016llx | 0x%016llx | 0x%016llx | 0x%016llx | 0x%016llx\n" , + va->va.addr, va->va.range, va->va.addr + va->va.range, + (u64 )va->gem.obj, va->gem.offset); + } + +return 0 ; +} +EXPORT_SYMBOL (drm_debugfs_gpuva_info);/** * drm_debugfs_create_files - Initialize a given set of debugfs files for DRM
include/drm/drm_debugfs.h +25 -0
@@ -34,6 +34,22 @@#include <linux/types.h> #include <linux/seq_file.h> + +#include <drm/drm_gpuva_mgr.h> + +/** +* DRM_DEBUGFS_GPUVA_INFO - &drm_info_list entry to dump a GPU VA space +* @show: the &drm_info_list's show callback +* @data: driver private data +* +* Drivers should use this macro to define a &drm_info_list entry to provide a +* debugfs file for dumping the GPU VA space regions and mappings. +* +* For each DRM GPU VA space drivers should call drm_debugfs_gpuva_info() from +* their @show callback. +*/ +#define DRM_DEBUGFS_GPUVA_INFO (show, data) {"gpuvas", show, DRIVER_GEM_GPUVA, data} +/** * struct drm_info_list - debugfs info list entry *
@@ -134,6 +150,9 @@ void drm_debugfs_add_file(struct drm_device *dev, const char *name,void drm_debugfs_add_files (struct drm_device *dev,const struct drm_debugfs_info *files,int count); + +int drm_debugfs_gpuva_info (struct seq_file *m, +struct drm_gpuva_manager *mgr);#else static inline void drm_debugfs_create_files(const struct drm_info_list *files, int count, struct dentry *root,
@@ -155,6 +174,12 @@ static inline void drm_debugfs_add_files(struct drm_device *dev, const struct drm_debugfs_info *files, int count) {} + +static inline int drm_debugfs_gpuva_info (struct seq_file *m, +struct drm_gpuva_manager *mgr) +{ +return 0 ; +}#endif #endif /* _DRM_DEBUGFS_H_ */
Signature · 1 line
2.34.1
Matthew Brost
maintainerPATCH 7/9 drm/xe: Remove __xe_vm_bind forward declaration
In reply to Matthew BrostNot needed so remove it.
--- drivers/gpu/drm/xe/xe_vm.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/gpu/drm/xe/xe_vm.c +0 -5
@@ -694,11 +694,6 @@ static void preempt_rebind_work_func(struct work_struct *w)trace_xe_vm_rebind_worker_exit (vm); } -struct async_op_fence ; -static int __xe_vm_bind (struct xe_vm *vm,struct xe_vma *vma, -struct xe_engine *e,struct xe_sync_entry *syncs, -u32 num_syncs,struct async_op_fence *afence); -static bool vma_userptr_invalidate (struct mmu_interval_notifier *mni,const struct mmu_notifier_range *range,unsigned long cur_seq)
Signature · 1 line
2.34.1
Matthew Brost
maintainerPATCH 8/9 drm/xe: Port Xe to GPUVA
In reply to Matthew BrostRather than open coding VM binds and VMA tracking, use the GPUVA library. GPUVA provides a common infrastructure for VM binds to use mmap / munmap semantics and support for VK sparse bindings.
The concepts are:
1) xe_vm inherits from drm_gpuva_manager
2) xe_vma inherits from drm_gpuva
3) xe_vma_op inherits from drm_gpuva_op
4) VM bind operations (MAP, UNMAP, PREFETCH, UNMAP_ALL) call into the GPUVA code to generate an VMA operations list which is parsed, commited, and executed.
v2 (CI): Add break after default in case statement.
v3: Rebase
v4: Fix some error handling
v5: Use unlocked verison VMA in error paths
v6: Rebase, address some review feedback mainly Thomas H
--- drivers/gpu/drm/xe/tests/xe_migrate.c | 2 +- drivers/gpu/drm/xe/xe_bo.c | 9 +- drivers/gpu/drm/xe/xe_device.c | 2 +- drivers/gpu/drm/xe/xe_gt_pagefault.c | 20 +- drivers/gpu/drm/xe/xe_migrate.c | 10 +- drivers/gpu/drm/xe/xe_pt.c | 40 +- drivers/gpu/drm/xe/xe_pt.h | 2 +- drivers/gpu/drm/xe/xe_vm.c | 1795 ++++++++++++------------- drivers/gpu/drm/xe/xe_vm.h | 35 +- drivers/gpu/drm/xe/xe_vm_madvise.c | 77 +- drivers/gpu/drm/xe/xe_vm_types.h | 173 ++- 11 files changed, 1070 insertions(+), 1095 deletions(-)
drivers/gpu/drm/xe/tests/xe_migrate.c +1 -1
@@ -300,7 +300,7 @@ static void xe_migrate_sanity_test(struct xe_migrate *m, struct kunit *test)/* First part of the test, are we updating our pagetable bo with a new entry? */ xe_map_wr (xe, &bo->vmap,XE_PAGE_SIZE * (NUM_KERNEL_PDE -1 ), u64,0xdeaddeadbeefbeef ); - expected =xe_pte_encode (NULL , pt,0 ,XE_CACHE_WB ,0 ,0 ); + expected =xe_pte_encode (NULL , pt,0 ,XE_CACHE_WB ,0 );if (m->eng->vm->flags &XE_VM_FLAGS_64K ) expected |=XE_PTE_PS64 ;if (xe_bo_is_vram (pt))
drivers/gpu/drm/xe/xe_bo.c +5 -4
@@ -397,7 +397,8 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo, {struct dma_resv_iter cursor;struct dma_fence *fence; -struct xe_vma *vma; +struct drm_gpuva *gpuva; +struct drm_gem_object *obj = &bo->ttm.base;int ret =0 ;dma_resv_assert_held (bo->ttm.base.resv);
@@ -410,9 +411,10 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo,dma_resv_iter_end (&cursor); } -list_for_each_entry (vma, &bo->vmas, bo_link) { +drm_gem_for_each_gpuva (gpuva, obj) { +struct xe_vma *vma =gpuva_to_vma (gpuva);struct xe_vm *vm =xe_vma_vm (vma); - +trace_xe_vma_evict (vma);if (xe_vm_in_fault_mode (vm)) {
@@ -439,7 +441,6 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo, }else {bool vm_resv_locked = false; -struct xe_vm *vm =xe_vma_vm (vma);/* * We need to put the vma on the vm's rebind_list,
drivers/gpu/drm/xe/xe_device.c +1 -1
@@ -135,7 +135,7 @@ static struct drm_driver driver = { .driver_features =DRIVER_GEM |DRIVER_RENDER |DRIVER_SYNCOBJ | - DRIVER_SYNCOBJ_TIMELINE, + DRIVER_SYNCOBJ_TIMELINE | DRIVER_GEM_GPUVA, .open = xe_file_open, .postclose = xe_file_close,
drivers/gpu/drm/xe/xe_gt_pagefault.c +7 -13
@@ -75,10 +75,10 @@ static bool vma_is_valid(struct xe_gt *gt, struct xe_vma *vma) !(BIT (gt->info.id) & vma->usm.tile_invalidated); } -static bool vma_matches (struct xe_vma *vma,struct xe_vma *lookup) +static bool vma_matches (struct xe_vma *vma,u64 page_addr) { -if (xe_vma_start (lookup) >xe_vma_end (vma) -1 || -xe_vma_end (lookup) -1 <xe_vma_start (vma)) +if (page_addr >xe_vma_end (vma) -1 || + page_addr +SZ_4K -1 <xe_vma_start (vma))return false;return true;
@@ -91,16 +91,14 @@ static bool only_needs_bo_lock(struct xe_bo *bo)static struct xe_vma *lookup_vma (struct xe_vm *vm,u64 page_addr) { -struct xe_vma *vma =NULL , lookup; +struct xe_vma *vma =NULL ; - lookup.start = page_addr; - lookup.end = lookup.start +SZ_4K -1 ;if (vm->usm.last_fault_vma) {/* Fast lookup */ -if (vma_matches (vm->usm.last_fault_vma, &lookup)) +if (vma_matches (vm->usm.last_fault_vma, page_addr)) vma = vm->usm.last_fault_vma; }if (!vma) - vma =xe_vm_find_overlapping_vma (vm, &lookup); + vma =xe_vm_find_overlapping_vma (vm, page_addr,SZ_4K );return vma; }
@@ -489,12 +487,8 @@ static struct xe_vma *get_acc_vma(struct xe_vm *vm, struct acc *acc) {u64 page_va = acc->va_range_base + (ffs (acc->sub_granularity) -1 ) *sub_granularity_in_byte (acc->granularity); -struct xe_vma lookup; - - lookup.start = page_va; - lookup.end = lookup.start +SZ_4K -1 ; -return xe_vm_find_overlapping_vma (vm, &lookup); +return xe_vm_find_overlapping_vma (vm, page_va,SZ_4K ); }static int handle_acc (struct xe_gt *gt,struct acc *acc)
drivers/gpu/drm/xe/xe_migrate.c +5 -5
@@ -197,7 +197,7 @@ static int xe_migrate_prepare_vm(struct xe_tile *tile, struct xe_migrate *m,/* Map the entire BO in our level 0 pt */ for (i =0 , level =0 ; i < num_entries; level++) { entry =xe_pte_encode (NULL , bo, i *XE_PAGE_SIZE , -XE_CACHE_WB ,0 ,0 ); +XE_CACHE_WB ,0 );xe_map_wr (xe, &bo->vmap, map_ofs + level *8 , u64, entry);
@@ -216,7 +216,7 @@ static int xe_migrate_prepare_vm(struct xe_tile *tile, struct xe_migrate *m, i += vm->flags & XE_VM_FLAGS_64K ? XE_64K_PAGE_SIZE : XE_PAGE_SIZE) { entry =xe_pte_encode (NULL , batch, i, -XE_CACHE_WB ,0 ,0 ); +XE_CACHE_WB ,0 );xe_map_wr (xe, &bo->vmap, map_ofs + level *8 , u64, entry);
@@ -1159,7 +1159,8 @@ xe_migrate_update_pgtables(struct xe_migrate *m,u64 addr;int err =0 ;bool usm = !eng && xe->info.supports_usm; -bool first_munmap_rebind = vma && vma->first_munmap_rebind; +bool first_munmap_rebind = vma && + vma->gpuva.flags &XE_VMA_FIRST_REBIND ;/* Use the CPU if no in syncs and engine is idle */ if (no_in_syncs (syncs, num_syncs) && (!eng ||xe_engine_is_idle (eng))) {
@@ -1231,8 +1232,7 @@ xe_migrate_update_pgtables(struct xe_migrate *m,BUG_ON (pt_bo->size !=SZ_4K ); - addr =xe_pte_encode (NULL , pt_bo,0 ,XE_CACHE_WB , -0 ,0 ); + addr =xe_pte_encode (NULL , pt_bo,0 ,XE_CACHE_WB ,0 ); bb->cs[bb->len++] =lower_32_bits (addr); bb->cs[bb->len++] =upper_32_bits (addr); }
drivers/gpu/drm/xe/xe_pt.c +19 -21
@@ -100,15 +100,15 @@ static dma_addr_t vma_addr(struct xe_vma *vma, u64 offset, } } -static u64 __pte_encode (u64 pte,enum xe_cache_level cache,u32 flags, -u32 pt_level) +static u64 __pte_encode (u64 pte,enum xe_cache_level cache, +struct xe_vma *vma,u32 pt_level) { pte |=XE_PAGE_PRESENT |XE_PAGE_RW ; -if (unlikely (flags &XE_PTE_FLAG_READ_ONLY )) +if (unlikely (vma &&xe_vma_read_only (vma))) pte &= ~XE_PAGE_RW ; -if (unlikely (flags &XE_PTE_FLAG_NULL )) +if (unlikely (vma &&xe_vma_is_null (vma))) pte |=XE_PTE_NULL ;/* FIXME: I don't think the PPAT handling is correct for MTL */
@@ -142,7 +142,6 @@ static u64 __pte_encode(u64 pte, enum xe_cache_level cache, u32 flags,* @bo: If @vma is NULL, representing the memory to point to. * @offset: The offset into @vma or @bo. * @cache: The cache level indicating -* @flags: Currently only supports PTE_READ_ONLY for read-only access. * @pt_level: The page-table level of the page-table into which the entry * is to be inserted. *
@@ -150,7 +149,7 @@ static u64 __pte_encode(u64 pte, enum xe_cache_level cache, u32 flags,*/ u64 xe_pte_encode (struct xe_vma *vma,struct xe_bo *bo,u64 offset,enum xe_cache_level cache, -u32 flags,u32 pt_level) +u32 pt_level) {u64 pte;bool is_vram;
@@ -162,11 +161,11 @@ u64 xe_pte_encode(struct xe_vma *vma, struct xe_bo *bo,if (is_vram) { pte |=XE_PPGTT_PTE_LM ; -if (vma && vma->use_atomic_access_pte_bit) +if (vma && vma->gpuva.flags &XE_VMA_ATOMIC_PTE_BIT ) pte |=XE_USM_PPGTT_PTE_AE ; } -return __pte_encode (pte, cache, flags, pt_level); +return __pte_encode (pte, cache, vma, pt_level); } static u64 __xe_pt_empty_pte(struct xe_tile *tile, struct xe_vm *vm,
@@ -179,7 +178,7 @@ static u64 __xe_pt_empty_pte(struct xe_tile *tile, struct xe_vm *vm,if (level ==0 ) {u64 empty =xe_pte_encode (NULL , vm->scratch_bo[id],0 , -XE_CACHE_WB ,0 ,0 ); +XE_CACHE_WB ,0 );return empty; }else {
@@ -424,10 +423,9 @@ struct xe_pt_stage_bind_walk {*/ bool needs_64K;/** -* @pte_flags: Flags determining PTE setup. These are not flags -* encoded directly in the PTE. See @default_pte for those. +* @vma: VMA being mapped */ -u32 pte_flags; +struct xe_vma *vma;/* Also input, but is updated during the walk*/ /** @curs: The DMA address cursor. */
@@ -564,7 +562,7 @@ static bool xe_pt_hugepte_possible(u64 addr, u64 next, unsigned int level,return false;/* null VMA's do not have dma addresses */ -if (xe_walk->pte_flags &XE_PTE_FLAG_NULL ) +if (xe_vma_is_null (xe_walk->vma))return true;/* Is the DMA address huge PTE size aligned? */
@@ -590,7 +588,7 @@ xe_pt_scan_64K(u64 addr, u64 next, struct xe_pt_stage_bind_walk *xe_walk)return false;/* null VMA's do not have dma addresses */ -if (xe_walk->pte_flags &XE_PTE_FLAG_NULL ) +if (xe_vma_is_null (xe_walk->vma))return true;xe_res_next (&curs, addr - xe_walk->va_curs_start);
@@ -643,14 +641,13 @@ xe_pt_stage_bind_entry(struct xe_ptw *parent, pgoff_t offset,/* Is this a leaf entry ?*/ if (level ==0 ||xe_pt_hugepte_possible (addr, next, level, xe_walk)) {struct xe_res_cursor *curs = xe_walk->curs; -bool is_null = xe_walk->pte_flags &XE_PTE_FLAG_NULL ; +bool is_null =xe_vma_is_null (xe_walk->vma);XE_WARN_ON (xe_walk->va_curs_start != addr); pte =__pte_encode (is_null ?0 :xe_res_dma (curs) + xe_walk->dma_offset, - xe_walk->cache, xe_walk->pte_flags, - level); + xe_walk->cache, xe_walk->vma, level); pte |= xe_walk->default_pte;/*
@@ -762,7 +759,7 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma, .tile = tile, .curs = &curs, .va_curs_start = xe_vma_start(vma), - .pte_flags = vma->pte_flags, + .vma = vma, .wupd.entries = entries, .needs_64K = (xe_vma_vm(vma)->flags & XE_VM_FLAGS_64K) && is_vram, };
@@ -771,7 +768,7 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma,if (is_vram) { xe_walk.default_pte =XE_PPGTT_PTE_LM ; -if (vma && vma->use_atomic_access_pte_bit) +if (vma && vma->gpuva.flags &XE_VMA_ATOMIC_PTE_BIT ) xe_walk.default_pte |=XE_USM_PPGTT_PTE_AE ; xe_walk.dma_offset =vram_region_gpu_offset (bo->ttm.resource); xe_walk.cache =XE_CACHE_WB ;
@@ -1343,6 +1340,7 @@ __xe_pt_bind_vma(struct xe_tile *tile, struct xe_vma *vma, struct xe_engine *e, syncs, num_syncs, &bind_pt_update.base);if (!IS_ERR (fence)) { +bool last_munmap_rebind = vma->gpuva.flags &XE_VMA_LAST_REBIND ;LLIST_HEAD (deferred);/* TLB invalidation must be done before signaling rebind */
@@ -1359,7 +1357,7 @@ __xe_pt_bind_vma(struct xe_tile *tile, struct xe_vma *vma, struct xe_engine *e,/* add shared fence now for pagetable delayed destroy */ dma_resv_add_fence (&vm->resv, fence, !rebind && - vma->last_munmap_rebind ? + last_munmap_rebind ?DMA_RESV_USAGE_KERNEL :DMA_RESV_USAGE_BOOKKEEP );
@@ -1377,7 +1375,7 @@ __xe_pt_bind_vma(struct xe_tile *tile, struct xe_vma *vma, struct xe_engine *e,up_read (&vm->userptr.notifier_lock);xe_bo_put_commit (&deferred); } -if (!rebind && vma->last_munmap_rebind && +if (!rebind && last_munmap_rebind &&xe_vm_in_compute_mode (vm))queue_work (vm->xe->ordered_wq, &vm->preempt.rebind_work);
drivers/gpu/drm/xe/xe_pt.h +1 -1
@@ -50,5 +50,5 @@ u64 xe_pde_encode(struct xe_bo *bo, u64 bo_offset,u64 xe_pte_encode (struct xe_vma *vma,struct xe_bo *bo,u64 offset,enum xe_cache_level cache, -u32 flags,u32 pt_level); +u32 pt_level);#endif
drivers/gpu/drm/xe/xe_vm.c +873 -922
2,323 lines not on this page · raw message
drivers/gpu/drm/xe/xe_vm.h +26 -9
@@ -6,6 +6,7 @@#ifndef _XE_VM_H_#define _XE_VM_H_ +#include "xe_bo_types.h" #include "xe_macros.h" #include "xe_map.h" #include "xe_vm_types.h"
@@ -61,7 +62,22 @@ static inline bool xe_vm_is_closed_or_banned(struct xe_vm *vm) }struct xe_vma * -xe_vm_find_overlapping_vma (struct xe_vm *vm,struct xe_vma *vma); +xe_vm_find_overlapping_vma (struct xe_vm *vm,u64 start,u64 range); + +static inline struct xe_vm *gpuva_to_vm (struct drm_gpuva *gpuva) +{ + return container_of(gpuva->mgr, struct xe_vm, mgr); +} + +static inline struct xe_vma *gpuva_to_vma (struct drm_gpuva *gpuva) +{ + return container_of(gpuva, struct xe_vma, gpuva); +} + +static inline struct xe_vma_op *gpuva_op_to_vma_op (struct drm_gpuva_op *op) +{ + return container_of(op, struct xe_vma_op, base); +}/* * Let's abstract start, size, end, bo_offset, vm, and bo as the underlying
@@ -69,12 +85,12 @@ xe_vm_find_overlapping_vma(struct xe_vm *vm, struct xe_vma *vma);*/ static inline u64 xe_vma_start (struct xe_vma *vma) { -return vma->start; +return vma->gpuva.va.addr; }static inline u64 xe_vma_size (struct xe_vma *vma) { -return vma->end - vma->start +1 ; +return vma->gpuva.va.range; }static inline u64 xe_vma_end (struct xe_vma *vma)
@@ -84,32 +100,33 @@ static inline u64 xe_vma_end(struct xe_vma *vma)static inline u64 xe_vma_bo_offset (struct xe_vma *vma) { -return vma->bo_offset; +return vma->gpuva.gem.offset; }static inline struct xe_bo *xe_vma_bo (struct xe_vma *vma) { -return vma->bo; +return !vma->gpuva.gem.obj ?NULL : + container_of(vma->gpuva.gem.obj, struct xe_bo, ttm.base); }static inline struct xe_vm *xe_vma_vm (struct xe_vma *vma) { -return vma->vm; + return container_of(vma->gpuva.mgr, struct xe_vm, mgr); }static inline bool xe_vma_read_only (struct xe_vma *vma) { -return vma->pte_flags &XE_PTE_FLAG_READ_ONLY ; +return vma->gpuva.flags &XE_VMA_READ_ONLY ; }static inline u64 xe_vma_userptr (struct xe_vma *vma) { -return vma->userptr.ptr; +return vma->gpuva.gem.offset; }static inline bool xe_vma_is_null (struct xe_vma *vma) { -return vma->pte_flags &XE_PTE_FLAG_NULL ; +return vma->gpuva.flags &DRM_GPUVA_SPARSE ; }static inline bool xe_vma_has_no_bo (struct xe_vma *vma)
drivers/gpu/drm/xe/xe_vm_madvise.c +16 -61
97 lines not on this page · raw message
drivers/gpu/drm/xe/xe_vm_types.h +116 -57
217 lines not on this page · raw message
Signature · 1 line
2.34.1
Matthew Brost
maintainerPATCH 9/9 drm/xe: Avoid doing rebinds
In reply to Matthew BrostIf we dont change page sizes we can avoid doing rebinds rather just do a partial unbind. The algorithm to determine its page size is greedy as we assume all pages in the removed VMA are the largest page used in the VMA.
--- drivers/gpu/drm/xe/xe_pt.c | 1 + drivers/gpu/drm/xe/xe_vm.c | 71 +++++++++++++++++++++++++------- drivers/gpu/drm/xe/xe_vm_types.h | 17 ++++---- 3 files changed, 64 insertions(+), 25 deletions(-)
drivers/gpu/drm/xe/xe_pt.c +1 -0
@@ -668,6 +668,7 @@ xe_pt_stage_bind_entry(struct xe_ptw *parent, pgoff_t offset,if (!is_null)xe_res_next (curs, next - addr); xe_walk->va_curs_start = next; + xe_walk->vma->gpuva.flags |= (XE_VMA_PTE_4K << level); *action =ACTION_CONTINUE ;return ret;
drivers/gpu/drm/xe/xe_vm.c +56 -15
113 lines not on this page · raw message
drivers/gpu/drm/xe/xe_vm_types.h +7 -10
@@ -29,6 +29,9 @@ struct xe_vm;#define XE_VMA_ATOMIC_PTE_BIT (DRM_GPUVA_USERBITS << 2)#define XE_VMA_FIRST_REBIND (DRM_GPUVA_USERBITS << 3)#define XE_VMA_LAST_REBIND (DRM_GPUVA_USERBITS << 4) +#define XE_VMA_PTE_4K (DRM_GPUVA_USERBITS << 5) +#define XE_VMA_PTE_2M (DRM_GPUVA_USERBITS << 6) +#define XE_VMA_PTE_1G (DRM_GPUVA_USERBITS << 7)struct xe_vma {/** @gpuva: Base GPUVA object */
@@ -323,14 +326,6 @@ struct xe_vma_op_map {bool is_null; }; -/** struct xe_vma_op_unmap - VMA unmap operation */ -struct xe_vma_op_unmap { -/** @start: start of the VMA unmap */ -u64 start; -/** @range: range of the VMA unmap */ -u64 range; -}; -/** struct xe_vma_op_remap - VMA remap operation */ struct xe_vma_op_remap {/** @prev: VMA preceding part of a split mapping */
@@ -341,6 +336,10 @@ struct xe_vma_op_remap {u64 start;/** @range: range of the VMA unmap */ u64 range; +/** @skip_prev: skip prev rebind */ +bool skip_prev; +/** @skip_next: skip next rebind */ +bool skip_next;/** @unmap_done: unmap operation in done */ bool unmap_done; };
@@ -398,8 +397,6 @@ struct xe_vma_op {union {/** @map: VMA map operation specific data */ struct xe_vma_op_map map; -/** @unmap: VMA unmap operation specific data */ -struct xe_vma_op_unmap unmap;/** @remap: VMA remap operation specific data */ struct xe_vma_op_remap remap;/** @prefetch: VMA prefetch operation specific data */
Signature · 1 line
2.34.1
Patchwork
CI[Intel-xe] ✓ CI.Patch_applied: success for GPUVA with no uAPI changes
In reply to Matthew Brost== Series Details ==
== Series Details ==
Series: GPUVA with no uAPI changes
URL : https://patchwork.freedesktop.org/series/120000/
State : success
== Summary ==
=== Applying kernel patches on branch 'drm-xe-next' with base: === Base commit: abdb420db amend! drm/xe : Fix GT looping for standalone media === git am output follows ===
.git/rebase-apply/patch:51: trailing whitespace.
warning: 1 line adds whitespace errors.
Applying: drm/xe: Ban a VM if rebind worker hits an error
Applying: drm/xe: Add helpers to hide struct xe_vma internals
Applying: maple_tree: Export mas_preallocate
Applying: maple_tree: split up MA_STATE() macro
Applying: drm: manager to keep track of GPUs VA mappings
Applying: drm: debugfs: provide infrastructure to dump a DRM GPU VA space
Applying: drm/xe: Remove __xe_vm_bind forward declaration
Applying: drm/xe: Port Xe to GPUVA
Applying: drm/xe: Avoid doing rebinds
Patchwork
CI[Intel-xe] ✗ CI.checkpatch: warning for GPUVA with no uAPI changes
In reply to Matthew Brost== Series Details ==
== Series Details ==
Series: GPUVA with no uAPI changes
URL : https://patchwork.freedesktop.org/series/120000/
State : warning
== Summary ==
+ KERNEL=/kernel
+ git clone https://gitlab.freedesktop.org/drm/maintainer-tools mt Cloning into 'mt'...
warning: redirecting to https://gitlab.freedesktop.org/drm/maintainer-tools.git/
+ git -C mt rev-list -n1 origin/master c7d32770e3cd31d9fc134ce41f329b10aa33ee15
+ cd /kernel
+ git config --global --add safe.directory /kernel
+ git log -n1
commit 7421e9506c016eea67c7033ef9522eba0a08c84a
Author: Matthew Brost <[email protected]> Date: Wed Jun 28 14:41:27 2023 -0700
drm/xe: Avoid doing rebinds
If we dont change page sizes we can avoid doing rebinds rather just do a partial unbind. The algorithm to determine its page size is greedy as we assume all pages in the removed VMA are the largest page used in the VMA.
+ /mt/dim checkpatch abdb420db479bae28a2abd7ba2c66229b7e8cb77 drm-intel2ee4a4ade drm/xe: Ban a VM if rebind worker hits an error0a2ca40cc drm/xe: Add helpers to hide struct xe_vma internals
-:637: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #637: FILE: drivers/gpu/drm/xe/xe_vm.c:1168:
+ XE_BUG_ON(xe_vma_end(vma) > vm->size);
-:646: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #646: FILE: drivers/gpu/drm/xe/xe_vm.c:1177:
+ XE_BUG_ON(xe_vma_vm(vma) != vm);
-:655: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #655: FILE: drivers/gpu/drm/xe/xe_vm.c:1185:
+ XE_BUG_ON(xe_vma_vm(vma) != vm);
-:745: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis #745: FILE: drivers/gpu/drm/xe/xe_vm.c:2592:
+ XE_IOCTL_ERR(xe, (xe_vma_start(vma) != addr ||
+ xe_vma_end(vma) != addr + range) && !async))
-:852: WARNING:LONG_LINE: line length of 101 exceeds 100 columns #852: FILE: drivers/gpu/drm/xe/xe_vm.c:2794:
+ if (!xe_bo_can_migrate(xe_vma_bo(__vma), region_to_mem_type[region]))
-:861: WARNING:LONG_LINE: line length of 101 exceeds 100 columns #861: FILE: drivers/gpu/drm/xe/xe_vm.c:2808:
+ if (!xe_bo_can_migrate(xe_vma_bo(__vma), region_to_mem_type[region]))
-:887: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #887: FILE: drivers/gpu/drm/xe/xe_vm.c:3437:
+ XE_BUG_ON(!xe_vm_in_fault_mode(xe_vma_vm(vma)));
total: 0 errors, 6 warnings, 1 checks, 947 lines checked 17fce89e0 maple_tree: Export mas_preallocate 1ecdd8d6a maple_tree: split up MA_STATE() macro -:50: ERROR:MISSING_SIGN_OFF: Missing Signed-off-by: line(s)
total: 1 errors, 0 warnings, 0 checks, 19 lines checked3d2e9151d drm: manager to keep track of GPUs VA mappings
Traceback (most recent call last):
File "scripts/spdxcheck.py", line 6, in <module>
from ply import lex, yacc
ModuleNotFoundError: No module named 'ply'
Traceback (most recent call last):
File "scripts/spdxcheck.py", line 6, in <module>
from ply import lex, yacc
ModuleNotFoundError: No module named 'ply'
-:109: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #109:
new file mode 100644
-:615: WARNING:SPACE_BEFORE_TAB: please, no space before tabs #615: FILE: drivers/gpu/drm/drm_gpuva_mgr.c:502:
+ *^I^I ^I struct drm_gpuva_op_map *op);$
-:817: CHECK:BRACES: Blank lines aren't necessary after an open brace '{' #817: FILE: drivers/gpu/drm/drm_gpuva_mgr.c:704:
+{
+
-:865: CHECK:BRACES: Blank lines aren't necessary before a close brace '}' #865: FILE: drivers/gpu/drm/drm_gpuva_mgr.c:752:
+
+}
-:2055: CHECK:LINE_SPACING: Please don't use multiple blank lines #2055: FILE: drivers/gpu/drm/drm_gpuva_mgr.c:1942:
+
+
-:2407: ERROR:POINTER_LOCATION: "foo * bar" should be "foo *bar"
#2407: FILE: include/drm/drm_gpuva_mgr.h:225:
+struct drm_gpuva_prealloc * drm_gpuva_prealloc_create(struct drm_gpuva_manager *mgr);
-:2424: CHECK:LINE_SPACING: Please use a blank line after function/struct/union/enum declarations #2424: FILE: include/drm/drm_gpuva_mgr.h:242:
+};
+typedef struct drm_gpuva_iterator * drm_gpuva_state_t;
-:2424: WARNING:NEW_TYPEDEFS: do not add new typedefs #2424: FILE: include/drm/drm_gpuva_mgr.h:242:
+typedef struct drm_gpuva_iterator * drm_gpuva_state_t;
-:2424: ERROR:POINTER_LOCATION: "foo * bar" should be "foo *bar" #2424: FILE: include/drm/drm_gpuva_mgr.h:242:
+typedef struct drm_gpuva_iterator * drm_gpuva_state_t;
-:2448: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'mgr__' - possible side-effects? #2448: FILE: include/drm/drm_gpuva_mgr.h:266:
+#define DRM_GPUVA_ITER(name, mgr__, start) \
+ struct drm_gpuva_iterator name = { \
+ .mas = MA_STATE_INIT(&(mgr__)->mtree, start, 0), \
+ .mgr = mgr__, \
+ }
-:2466: ERROR:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses #2466: FILE: include/drm/drm_gpuva_mgr.h:284:
+#define drm_gpuva_iter_for_each_range(va__, it__, end__) \
+ while (((va__) = drm_gpuva_iter_find(&(it__), (end__) - 1)))
-:2484: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'it__' - possible side-effects? #2484: FILE: include/drm/drm_gpuva_mgr.h:302:
+#define drm_gpuva_iter_for_each(va__, it__) \
+ drm_gpuva_iter_for_each_range(va__, it__, (it__).mgr->mm_start + (it__).mgr->mm_range)
-:2753: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis #2753: FILE: include/drm/drm_gpuva_mgr.h:571:
+drm_gpuva_prefetch_ops_create(struct drm_gpuva_manager *mgr,
+ u64 addr, u64 range);
total: 3 errors, 3 warnings, 7 checks, 2797 lines checked208e94aea drm: debugfs: provide infrastructure to dump a DRM GPU VA space 8d9e32dd6 drm/xe: Remove __xe_vm_bind forward declaration70451d80a drm/xe: Port Xe to GPUVA
-:16: WARNING:TYPO_SPELLING: 'commited' may be misspelled - perhaps 'committed'? #16:
GPUVA code to generate an VMA operations list which is parsed, commited,
^^^^^^^^
-:22: WARNING:TYPO_SPELLING: 'verison' may be misspelled - perhaps 'version'? #22:
v5: Use unlocked verison VMA in error paths
^^^^^^^
-:25: ERROR:BAD_SIGN_OFF: Unrecognized email address: 'Matthew Brost <[email protected]' #25:
-:63: ERROR:TRAILING_WHITESPACE: trailing whitespace #63: FILE: drivers/gpu/drm/xe/xe_bo.c:432:
+ $
-:63: WARNING:LEADING_SPACE: please, no spaces at the start of a line #63: FILE: drivers/gpu/drm/xe/xe_bo.c:432:
+ $
-:561: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #561: FILE: drivers/gpu/drm/xe/xe_vm.c:1141:
+ XE_BUG_ON(start + range > vm->size);
-:664: WARNING:LINE_SPACING: Missing a blank line after declarations #664: FILE: drivers/gpu/drm/xe/xe_vm.c:1406:
+ struct drm_gpuva *gpuva;
+ DRM_GPUVA_ITER(it, &vm->mgr, 0);
-:833: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #833: FILE: drivers/gpu/drm/xe/xe_vm.c:1818:
+ XE_BUG_ON(!xe_vm_in_fault_mode(vm));
-:1040: WARNING:BLOCK_COMMENT_STYLE: Block comments use * on subsequent lines #1040: FILE: drivers/gpu/drm/xe/xe_vm.c:2167:
+ return -ENODATA; /* Not an actual error, IOCTL
+ cleans up returns and 0 */
-:1040: WARNING:BLOCK_COMMENT_STYLE: Block comments use a trailing */ on a separate line #1040: FILE: drivers/gpu/drm/xe/xe_vm.c:2167:
+ cleans up returns and 0 */
-:1042: CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis #1042: FILE: drivers/gpu/drm/xe/xe_vm.c:2169:
+ if (XE_IOCTL_ERR(xe, (xe_vma_start(vma) != addr ||
+ xe_vma_end(vma) != addr + range) && !async))
-:1048: WARNING:BLOCK_COMMENT_STYLE: Block comments use * on subsequent lines #1048: FILE: drivers/gpu/drm/xe/xe_vm.c:2175:
+ return -ENODATA; /* Not an actual error, IOCTL
+ cleans up returns and 0 */
-:1048: WARNING:BLOCK_COMMENT_STYLE: Block comments use a trailing */ on a separate line #1048: FILE: drivers/gpu/drm/xe/xe_vm.c:2175:
+ cleans up returns and 0 */
-:1051: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #1051: FILE: drivers/gpu/drm/xe/xe_vm.c:2178:
+ XE_BUG_ON("NOT POSSIBLE");
-:1133: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #1133: FILE: drivers/gpu/drm/xe/xe_vm.c:2231:
+ XE_BUG_ON("NOT POSSIBLE");
-:1295: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #1295: FILE: drivers/gpu/drm/xe/xe_vm.c:2306:
+ XE_BUG_ON(!bo);
-:1326: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #1326: FILE: drivers/gpu/drm/xe/xe_vm.c:2323:
+ XE_BUG_ON("NOT POSSIBLE");
-:1393: ERROR:SPACING: space required before the open parenthesis '(' #1393: FILE: drivers/gpu/drm/xe/xe_vm.c:2372:
+ } else if(!xe_vma_has_no_bo(vma) && !bo->vm) {
-:1408: WARNING:TYPO_SPELLING: 'commiting' may be misspelled - perhaps 'committing'? #1408: FILE: drivers/gpu/drm/xe/xe_vm.c:2387:
+ * prior to fully commiting to the operations. This setup can fail.
^^^^^^^^^
-:1421: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #1421: FILE: drivers/gpu/drm/xe/xe_vm.c:2400:
+ XE_BUG_ON(num_ops_list > 1 && !async);
-:1471: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #1471: FILE: drivers/gpu/drm/xe/xe_vm.c:2429:
+ XE_BUG_ON(!first && !async);
-:1602: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #1602: FILE: drivers/gpu/drm/xe/xe_vm.c:2518:
+ XE_BUG_ON("NOT POSSIBLE");
-:2011: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #2011: FILE: drivers/gpu/drm/xe/xe_vm.c:2684:
+ XE_BUG_ON("NOT POSSIBLE");
-:2102: ERROR:SPACING: space required before the open parenthesis '(' #2102: FILE: drivers/gpu/drm/xe/xe_vm.c:2725:
+ else if(op->remap.prev)
-:2120: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #2120: FILE: drivers/gpu/drm/xe/xe_vm.c:2743:
+ XE_BUG_ON("NOT POSSIBLE");
-:2213: WARNING:AVOID_BUG: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants #2213: FILE: drivers/gpu/drm/xe/xe_vm.c:2817:
+ XE_BUG_ON("NOT POSSIBLE");
-:2319: WARNING:MEMORY_BARRIER: memory barrier without comment #2319: FILE: drivers/gpu/drm/xe/xe_vm.c:2889:
+ smp_wmb();
-:2494: WARNING:ENOTSUPP: ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP #2494: FILE: drivers/gpu/drm/xe/xe_vm.c:3154:
+ err = -ENOTSUPP;
-:2503: WARNING:ENOTSUPP: ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP #2503: FILE: drivers/gpu/drm/xe/xe_vm.c:3176:
+ err = -ENOTSUPP;
-:2717: ERROR:POINTER_LOCATION: "foo* bar" should be "foo *bar" #2717: FILE: drivers/gpu/drm/xe/xe_vm.c:3445:
+ struct xe_vma* vma = gpuva_to_vma(gpuva);
-:3142: ERROR:NO_AUTHOR_SIGN_OFF: Missing Signed-off-by: line by nominal patch author 'Matthew Brost <[email protected]>'
total: 6 errors, 24 warnings, 1 checks, 2987 lines checked 7421e9506 drm/xe: Avoid doing rebinds
-:71: WARNING:LONG_LINE: line length of 102 exceeds 100 columns #71: FILE: drivers/gpu/drm/xe/xe_vm.c:2503:
+ IS_ALIGNED(xe_vma_end(vma), xe_vma_max_pte_size(old));
-:86: WARNING:LONG_LINE: line length of 104 exceeds 100 columns #86: FILE: drivers/gpu/drm/xe/xe_vm.c:2532:
+ IS_ALIGNED(xe_vma_start(vma), xe_vma_max_pte_size(old));
total: 0 errors, 2 warnings, 0 checks, 161 lines checked
Patchwork
CI[Intel-xe] ✗ CI.KUnit: failure for GPUVA with no uAPI changes
In reply to Matthew Brost== Series Details ==
== Series Details ==
Series: GPUVA with no uAPI changes
URL : https://patchwork.freedesktop.org/series/120000/
State : failure
== Summary ==
+ trap cleanup EXIT
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/xe/.kunitconfig ERROR:root:../drivers/gpu/drm/xe/xe_vm.c: In function ‘xe_vma_op_unwind’:../drivers/gpu/drm/xe/xe_vm.c:2838:3: error: a label can only be part of a statement and a declaration is not a statement
2838 | struct xe_vma *vma = gpuva_to_vma(op->base.remap.unmap->va);
| ^~~~~~make[6]: *** [../scripts/Makefile.build:252: drivers/gpu/drm/xe/xe_vm.o] Error 1 make[6]: *** Waiting for unfinished jobs....
make[5]: *** [../scripts/Makefile.build:494: drivers/gpu/drm/xe] Error 2 make[4]: *** [../scripts/Makefile.build:494: drivers/gpu/drm] Error 2 make[3]: *** [../scripts/Makefile.build:494: drivers/gpu] Error 2 make[2]: *** [../scripts/Makefile.build:494: drivers] Error 2 make[1]: *** [/kernel/Makefile:2025: .] Error 2
make: *** [Makefile:226: __sub-make] Error 2
[21:45:07] Configuring KUnit Kernel ...
Generating .config ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig [21:45:11] Building KUnit Kernel ... Populating config with: $ make ARCH=um O=.kunit olddefconfig Building with: $ make ARCH=um O=.kunit --jobs=48 + cleanup ++ stat -c %u:%g /kernel + chown -R 1003:1003 /kernel