Skip to content

Commit cb3d7b3

Browse files
author
Thomas Hellström
committed
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
1 parent c4dfa0b commit cb3d7b3

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
@@ -85,15 +85,7 @@ static void check_residency(struct kunit *test, struct xe_bo *exported,
8585
return;
8686
}
8787

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

9890
if (params->force_different_devices)
9991
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
@@ -188,6 +188,8 @@ static void try_add_system(struct xe_device *xe, struct xe_bo *bo,
188188

189189
bo->placements[*c] = (struct ttm_place) {
190190
.mem_type = XE_PL_TT,
191+
.flags = (bo_flags & XE_BO_FLAG_VRAM_MASK) ?
192+
TTM_PL_FLAG_FALLBACK : 0,
191193
};
192194
*c += 1;
193195
}
@@ -2311,14 +2313,15 @@ uint64_t vram_region_gpu_offset(struct ttm_resource *res)
23112313
/**
23122314
* xe_bo_pin_external - pin an external BO
23132315
* @bo: buffer object to be pinned
2316+
* @in_place: Pin in current placement, don't attempt to migrate.
23142317
*
23152318
* Pin an external (not tied to a VM, can be exported via dma-buf / prime FD)
23162319
* BO. Unique call compared to xe_bo_pin as this function has it own set of
23172320
* asserts and code to ensure evict / restore on suspend / resume.
23182321
*
23192322
* Returns 0 for success, negative error code otherwise.
23202323
*/
2321-
int xe_bo_pin_external(struct xe_bo *bo)
2324+
int xe_bo_pin_external(struct xe_bo *bo, bool in_place)
23222325
{
23232326
struct xe_device *xe = xe_bo_device(bo);
23242327
int err;
@@ -2327,9 +2330,11 @@ int xe_bo_pin_external(struct xe_bo *bo)
23272330
xe_assert(xe, xe_bo_is_user(bo));
23282331

23292332
if (!xe_bo_is_pinned(bo)) {
2330-
err = xe_bo_validate(bo, NULL, false);
2331-
if (err)
2332-
return err;
2333+
if (!in_place) {
2334+
err = xe_bo_validate(bo, NULL, false);
2335+
if (err)
2336+
return err;
2337+
}
23332338

23342339
spin_lock(&xe->pinned.lock);
23352340
list_add_tail(&bo->pinned_link, &xe->pinned.late.external);
@@ -2482,6 +2487,9 @@ int xe_bo_validate(struct xe_bo *bo, struct xe_vm *vm, bool allow_res_evict)
24822487
};
24832488
int ret;
24842489

2490+
if (xe_bo_is_pinned(bo))
2491+
return 0;
2492+
24852493
if (vm) {
24862494
lockdep_assert_held(&vm->lock);
24872495
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
@@ -200,7 +200,7 @@ static inline void xe_bo_unlock_vm_held(struct xe_bo *bo)
200200
}
201201
}
202202

203-
int xe_bo_pin_external(struct xe_bo *bo);
203+
int xe_bo_pin_external(struct xe_bo *bo, bool in_place);
204204
int xe_bo_pin(struct xe_bo *bo);
205205
void xe_bo_unpin_external(struct xe_bo *bo);
206206
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)