Skip to content

Commit 5c87fee

Browse files
Thomas Hellströmrodrigovivi
authored andcommitted
drm/xe: Attempt to bring bos back to VRAM after eviction
VRAM+TT bos that are evicted from VRAM to TT may remain in TT also after a revalidation following eviction or suspend. This manifests itself as applications becoming sluggish after buffer objects get evicted or after a resume from suspend or hibernation. If the bo supports placement in both VRAM and TT, and we are on DGFX, mark the TT placement as fallback. This means that it is tried only after VRAM + eviction. This flaw has probably been present since the xe module was upstreamed but use a Fixes: commit below where backporting is likely to be simple. For earlier versions we need to open- code the fallback algorithm in the driver. v2: - Remove check for dgfx. (Matthew Auld) - Update the xe_dma_buf kunit test for the new strategy (CI) - Allow dma-buf to pin in current placement (CI) - Make xe_bo_validate() for pinned bos a NOP. Closes: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/5995 Fixes: a78a8da ("drm/ttm: replace busy placement with flags v6") Cc: Matthew Brost <matthew.brost@intel.com> Cc: Matthew Auld <matthew.auld@intel.com> Cc: <stable@vger.kernel.org> # v6.9+ Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com> Reviewed-by: Matthew Auld <matthew.auld@intel.com> Link: https://lore.kernel.org/r/20250904160715.2613-2-thomas.hellstrom@linux.intel.com (cherry picked from commit cb3d7b3) Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
1 parent 7934fdc commit 5c87fee

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

drivers/gpu/drm/xe/tests/xe_bo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ static int evict_test_run_tile(struct xe_device *xe, struct xe_tile *tile, struc
236236
}
237237

238238
xe_bo_lock(external, false);
239-
err = xe_bo_pin_external(external);
239+
err = xe_bo_pin_external(external, false);
240240
xe_bo_unlock(external);
241241
if (err) {
242242
KUNIT_FAIL(test, "external bo pin err=%pe\n",

drivers/gpu/drm/xe/tests/xe_dma_buf.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,7 @@ static void check_residency(struct kunit *test, struct xe_bo *exported,
8989
return;
9090
}
9191

92-
/*
93-
* If on different devices, the exporter is kept in system if
94-
* possible, saving a migration step as the transfer is just
95-
* likely as fast from system memory.
96-
*/
97-
if (params->mem_mask & XE_BO_FLAG_SYSTEM)
98-
KUNIT_EXPECT_TRUE(test, xe_bo_is_mem_type(exported, XE_PL_TT));
99-
else
100-
KUNIT_EXPECT_TRUE(test, xe_bo_is_mem_type(exported, mem_type));
92+
KUNIT_EXPECT_TRUE(test, xe_bo_is_mem_type(exported, mem_type));
10193

10294
if (params->force_different_devices)
10395
KUNIT_EXPECT_TRUE(test, xe_bo_is_mem_type(imported, XE_PL_TT));

drivers/gpu/drm/xe/xe_bo.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ static void try_add_system(struct xe_device *xe, struct xe_bo *bo,
186186

187187
bo->placements[*c] = (struct ttm_place) {
188188
.mem_type = XE_PL_TT,
189+
.flags = (bo_flags & XE_BO_FLAG_VRAM_MASK) ?
190+
TTM_PL_FLAG_FALLBACK : 0,
189191
};
190192
*c += 1;
191193
}
@@ -2269,14 +2271,15 @@ uint64_t vram_region_gpu_offset(struct ttm_resource *res)
22692271
/**
22702272
* xe_bo_pin_external - pin an external BO
22712273
* @bo: buffer object to be pinned
2274+
* @in_place: Pin in current placement, don't attempt to migrate.
22722275
*
22732276
* Pin an external (not tied to a VM, can be exported via dma-buf / prime FD)
22742277
* BO. Unique call compared to xe_bo_pin as this function has it own set of
22752278
* asserts and code to ensure evict / restore on suspend / resume.
22762279
*
22772280
* Returns 0 for success, negative error code otherwise.
22782281
*/
2279-
int xe_bo_pin_external(struct xe_bo *bo)
2282+
int xe_bo_pin_external(struct xe_bo *bo, bool in_place)
22802283
{
22812284
struct xe_device *xe = xe_bo_device(bo);
22822285
int err;
@@ -2285,9 +2288,11 @@ int xe_bo_pin_external(struct xe_bo *bo)
22852288
xe_assert(xe, xe_bo_is_user(bo));
22862289

22872290
if (!xe_bo_is_pinned(bo)) {
2288-
err = xe_bo_validate(bo, NULL, false);
2289-
if (err)
2290-
return err;
2291+
if (!in_place) {
2292+
err = xe_bo_validate(bo, NULL, false);
2293+
if (err)
2294+
return err;
2295+
}
22912296

22922297
spin_lock(&xe->pinned.lock);
22932298
list_add_tail(&bo->pinned_link, &xe->pinned.late.external);
@@ -2440,6 +2445,9 @@ int xe_bo_validate(struct xe_bo *bo, struct xe_vm *vm, bool allow_res_evict)
24402445
};
24412446
int ret;
24422447

2448+
if (xe_bo_is_pinned(bo))
2449+
return 0;
2450+
24432451
if (vm) {
24442452
lockdep_assert_held(&vm->lock);
24452453
xe_vm_assert_held(vm);

drivers/gpu/drm/xe/xe_bo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static inline void xe_bo_unlock_vm_held(struct xe_bo *bo)
198198
}
199199
}
200200

201-
int xe_bo_pin_external(struct xe_bo *bo);
201+
int xe_bo_pin_external(struct xe_bo *bo, bool in_place);
202202
int xe_bo_pin(struct xe_bo *bo);
203203
void xe_bo_unpin_external(struct xe_bo *bo);
204204
void xe_bo_unpin(struct xe_bo *bo);

drivers/gpu/drm/xe/xe_dma_buf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static int xe_dma_buf_pin(struct dma_buf_attachment *attach)
7272
return ret;
7373
}
7474

75-
ret = xe_bo_pin_external(bo);
75+
ret = xe_bo_pin_external(bo, true);
7676
xe_assert(xe, !ret);
7777

7878
return 0;

0 commit comments

Comments
 (0)