Skip to content

Commit e0ff0d7

Browse files
committed
drm/xe/svm: Refactor usage of drm_gpusvm* function in xe_svm
Define xe_svm_range_find_or_insert function wrapping drm_gpusvm_range_find_or_insert for reusing in prefetch. Define xe_svm_range_get_pages function wrapping drm_gpusvm_range_get_pages for reusing in prefetch. -v2 pass pagefault defined drm_gpu_svm context as parameter in xe_svm_range_find_or_insert(Matthew Brost) Cc: Matthew Brost <matthew.brost@intel.com> Reviewed-by: Matthew Brost <matthew.brost@intel.com> Acked-by: Thomas Hellström <thomas.hellstrom@linux.intel.com> Link: https://lore.kernel.org/r/20250513040228.470682-10-himal.prasad.ghimiray@intel.com Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
1 parent da05e5d commit e0ff0d7

File tree

2 files changed

+77
-9
lines changed

2 files changed

+77
-9
lines changed

drivers/gpu/drm/xe/xe_svm.c

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,6 @@ int xe_svm_handle_pagefault(struct xe_vm *vm, struct xe_vma *vma,
785785
vm->xe->atomic_svm_timeslice_ms : 0,
786786
};
787787
struct xe_svm_range *range;
788-
struct drm_gpusvm_range *r;
789788
struct drm_exec exec;
790789
struct dma_fence *fence;
791790
struct xe_tile *tile = gt_to_tile(gt);
@@ -804,16 +803,14 @@ int xe_svm_handle_pagefault(struct xe_vm *vm, struct xe_vma *vma,
804803
if (err)
805804
return err;
806805

807-
r = drm_gpusvm_range_find_or_insert(&vm->svm.gpusvm, fault_addr,
808-
xe_vma_start(vma), xe_vma_end(vma),
809-
&ctx);
810-
if (IS_ERR(r))
811-
return PTR_ERR(r);
806+
range = xe_svm_range_find_or_insert(vm, fault_addr, vma, &ctx);
812807

813-
if (ctx.devmem_only && !r->flags.migrate_devmem)
808+
if (IS_ERR(range))
809+
return PTR_ERR(range);
810+
811+
if (ctx.devmem_only && !range->base.flags.migrate_devmem)
814812
return -EACCES;
815813

816-
range = to_xe_range(r);
817814
if (xe_svm_range_is_valid(range, tile, ctx.devmem_only))
818815
return 0;
819816

@@ -839,7 +836,7 @@ int xe_svm_handle_pagefault(struct xe_vm *vm, struct xe_vma *vma,
839836
}
840837

841838
range_debug(range, "GET PAGES");
842-
err = drm_gpusvm_range_get_pages(&vm->svm.gpusvm, r, &ctx);
839+
err = xe_svm_range_get_pages(vm, range, &ctx);
843840
/* Corner where CPU mappings have changed */
844841
if (err == -EOPNOTSUPP || err == -EFAULT || err == -EPERM) {
845842
ctx.timeslice_ms <<= 1; /* Double timeslice if we have to retry */
@@ -930,6 +927,56 @@ int xe_svm_bo_evict(struct xe_bo *bo)
930927
return drm_gpusvm_evict_to_ram(&bo->devmem_allocation);
931928
}
932929

930+
/**
931+
* xe_svm_range_find_or_insert- Find or insert GPU SVM range
932+
* @vm: xe_vm pointer
933+
* @addr: address for which range needs to be found/inserted
934+
* @vma: Pointer to struct xe_vma which mirrors CPU
935+
* @ctx: GPU SVM context
936+
*
937+
* This function finds or inserts a newly allocated a SVM range based on the
938+
* address.
939+
*
940+
* Return: Pointer to the SVM range on success, ERR_PTR() on failure.
941+
*/
942+
struct xe_svm_range *xe_svm_range_find_or_insert(struct xe_vm *vm, u64 addr,
943+
struct xe_vma *vma, struct drm_gpusvm_ctx *ctx)
944+
{
945+
struct drm_gpusvm_range *r;
946+
947+
r = drm_gpusvm_range_find_or_insert(&vm->svm.gpusvm, max(addr, xe_vma_start(vma)),
948+
xe_vma_start(vma), xe_vma_end(vma), ctx);
949+
if (IS_ERR(r))
950+
return ERR_PTR(PTR_ERR(r));
951+
952+
return to_xe_range(r);
953+
}
954+
955+
/**
956+
* xe_svm_range_get_pages() - Get pages for a SVM range
957+
* @vm: Pointer to the struct xe_vm
958+
* @range: Pointer to the xe SVM range structure
959+
* @ctx: GPU SVM context
960+
*
961+
* This function gets pages for a SVM range and ensures they are mapped for
962+
* DMA access. In case of failure with -EOPNOTSUPP, it evicts the range.
963+
*
964+
* Return: 0 on success, negative error code on failure.
965+
*/
966+
int xe_svm_range_get_pages(struct xe_vm *vm, struct xe_svm_range *range,
967+
struct drm_gpusvm_ctx *ctx)
968+
{
969+
int err = 0;
970+
971+
err = drm_gpusvm_range_get_pages(&vm->svm.gpusvm, &range->base, ctx);
972+
if (err == -EOPNOTSUPP) {
973+
range_debug(range, "PAGE FAULT - EVICT PAGES");
974+
drm_gpusvm_range_evict(&vm->svm.gpusvm, &range->base);
975+
}
976+
977+
return err;
978+
}
979+
933980
#if IS_ENABLED(CONFIG_DRM_XE_DEVMEM_MIRROR)
934981

935982
static struct drm_pagemap_device_addr

drivers/gpu/drm/xe/xe_svm.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ void xe_svm_range_debug(struct xe_svm_range *range, const char *operation);
7373
int xe_svm_alloc_vram(struct xe_vm *vm, struct xe_tile *tile,
7474
struct xe_svm_range *range,
7575
const struct drm_gpusvm_ctx *ctx);
76+
77+
struct xe_svm_range *xe_svm_range_find_or_insert(struct xe_vm *vm, u64 addr,
78+
struct xe_vma *vma, struct drm_gpusvm_ctx *ctx);
79+
80+
int xe_svm_range_get_pages(struct xe_vm *vm, struct xe_svm_range *range,
81+
struct drm_gpusvm_ctx *ctx);
82+
7683
/**
7784
* xe_svm_range_has_dma_mapping() - SVM range has DMA mapping
7885
* @range: SVM range
@@ -227,6 +234,20 @@ int xe_svm_alloc_vram(struct xe_vm *vm, struct xe_tile *tile,
227234
return -EOPNOTSUPP;
228235
}
229236

237+
static inline
238+
struct xe_svm_range *xe_svm_range_find_or_insert(struct xe_vm *vm, u64 addr,
239+
struct xe_vma *vma, struct drm_gpusvm_ctx *ctx)
240+
{
241+
return ERR_PTR(-EINVAL);
242+
}
243+
244+
static inline
245+
int xe_svm_range_get_pages(struct xe_vm *vm, struct xe_svm_range *range,
246+
struct drm_gpusvm_ctx *ctx)
247+
{
248+
return -EINVAL;
249+
}
250+
230251
static inline struct xe_svm_range *to_xe_range(struct drm_gpusvm_range *r)
231252
{
232253
return NULL;

0 commit comments

Comments
 (0)