Skip to content

Commit 3ca608d

Browse files
committed
drm/xe: Basic SVM BO eviction
Wire xe_bo_move to GPU SVM migration via new helper xe_svm_bo_evict. v2: - Use xe_svm_bo_evict - Drop bo->range v3: - Kernel doc (Thomas) v4: - Add missing xe_bo.c code v5: - Add XE_BO_FLAG_CPU_ADDR_MIRROR flag in this patch (Thomas) - Add message on eviction failure v6: - Only compile if CONFIG_DRM_GPUSVM selected (CI, Lucas) Signed-off-by: Matthew Brost <matthew.brost@intel.com> Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20250306012657.3505757-29-matthew.brost@intel.com
1 parent 2f118c9 commit 3ca608d

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

drivers/gpu/drm/xe/xe_bo.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ int xe_bo_placement_for_flags(struct xe_device *xe, struct xe_bo *bo,
279279
static void xe_evict_flags(struct ttm_buffer_object *tbo,
280280
struct ttm_placement *placement)
281281
{
282+
struct xe_bo *bo;
283+
282284
if (!xe_bo_is_xe_bo(tbo)) {
283285
/* Don't handle scatter gather BOs */
284286
if (tbo->type == ttm_bo_type_sg) {
@@ -290,6 +292,12 @@ static void xe_evict_flags(struct ttm_buffer_object *tbo,
290292
return;
291293
}
292294

295+
bo = ttm_to_xe_bo(tbo);
296+
if (bo->flags & XE_BO_FLAG_CPU_ADDR_MIRROR) {
297+
*placement = sys_placement;
298+
return;
299+
}
300+
293301
/*
294302
* For xe, sg bos that are evicted to system just triggers a
295303
* rebind of the sg list upon subsequent validation to XE_PL_TT.
@@ -734,6 +742,20 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
734742
goto out;
735743
}
736744

745+
if (!move_lacks_source && (bo->flags & XE_BO_FLAG_CPU_ADDR_MIRROR) &&
746+
new_mem->mem_type == XE_PL_SYSTEM) {
747+
ret = xe_svm_bo_evict(bo);
748+
if (!ret) {
749+
drm_dbg(&xe->drm, "Evict system allocator BO success\n");
750+
ttm_bo_move_null(ttm_bo, new_mem);
751+
} else {
752+
drm_dbg(&xe->drm, "Evict system allocator BO failed=%pe\n",
753+
ERR_PTR(ret));
754+
}
755+
756+
goto out;
757+
}
758+
737759
if (old_mem_type == XE_PL_SYSTEM && new_mem->mem_type == XE_PL_TT && !handle_system_ccs) {
738760
ttm_bo_move_null(ttm_bo, new_mem);
739761
goto out;

drivers/gpu/drm/xe/xe_bo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
XE_BO_FLAG_GGTT1 | \
4848
XE_BO_FLAG_GGTT2 | \
4949
XE_BO_FLAG_GGTT3)
50+
#define XE_BO_FLAG_CPU_ADDR_MIRROR BIT(22)
5051

5152
/* this one is trigger internally only */
5253
#define XE_BO_FLAG_INTERNAL_TEST BIT(30)

drivers/gpu/drm/xe/xe_svm.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,8 @@ static int xe_svm_alloc_vram(struct xe_vm *vm, struct xe_tile *tile,
617617
bo = xe_bo_create_locked(tile_to_xe(tile), NULL, NULL,
618618
xe_svm_range_size(range),
619619
ttm_bo_type_device,
620-
XE_BO_FLAG_VRAM_IF_DGFX(tile));
620+
XE_BO_FLAG_VRAM_IF_DGFX(tile) |
621+
XE_BO_FLAG_CPU_ADDR_MIRROR);
621622
if (IS_ERR(bo)) {
622623
err = PTR_ERR(bo);
623624
if (xe_vm_validate_should_retry(NULL, err, &end))
@@ -772,6 +773,20 @@ bool xe_svm_has_mapping(struct xe_vm *vm, u64 start, u64 end)
772773
return drm_gpusvm_has_mapping(&vm->svm.gpusvm, start, end);
773774
}
774775

776+
/**
777+
* xe_svm_bo_evict() - SVM evict BO to system memory
778+
* @bo: BO to evict
779+
*
780+
* SVM evict BO to system memory. GPU SVM layer ensures all device pages
781+
* are evicted before returning.
782+
*
783+
* Return: 0 on success standard error code otherwise
784+
*/
785+
int xe_svm_bo_evict(struct xe_bo *bo)
786+
{
787+
return drm_gpusvm_evict_to_ram(&bo->devmem_allocation);
788+
}
789+
775790
#if IS_ENABLED(CONFIG_DRM_XE_DEVMEM_MIRROR)
776791
static struct drm_pagemap_device_addr
777792
xe_drm_pagemap_device_map(struct drm_pagemap *dpagemap,

drivers/gpu/drm/xe/xe_svm.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#define XE_INTERCONNECT_VRAM DRM_INTERCONNECT_DRIVER
1313

14+
struct xe_bo;
1415
struct xe_vram_region;
1516
struct xe_tile;
1617
struct xe_vm;
@@ -67,6 +68,8 @@ int xe_svm_handle_pagefault(struct xe_vm *vm, struct xe_vma *vma,
6768
bool atomic);
6869

6970
bool xe_svm_has_mapping(struct xe_vm *vm, u64 start, u64 end);
71+
72+
int xe_svm_bo_evict(struct xe_bo *bo);
7073
#else
7174
static inline bool xe_svm_range_pages_valid(struct xe_svm_range *range)
7275
{
@@ -108,6 +111,12 @@ bool xe_svm_has_mapping(struct xe_vm *vm, u64 start, u64 end)
108111
{
109112
return false;
110113
}
114+
115+
static inline
116+
int xe_svm_bo_evict(struct xe_bo *bo)
117+
{
118+
return 0;
119+
}
111120
#endif
112121

113122
/**

0 commit comments

Comments
 (0)