Skip to content

Commit 503a6f4

Browse files
matt-auldrodrigovivi
authored andcommitted
drm/xe/bo: sync kernel fences for KMD buffers
With things like pipelined evictions, VRAM pages can be marked as free and yet still have some active kernel fences, with the idea that the next caller to allocate the memory will respect them. However it looks like we are missing synchronisation for KMD internal buffers, like page-tables, lrc etc. For userspace objects we should already have the required synchronisation for CPU access via the fault handler, and likewise for GPU access when vm_binding them. To fix this synchronise against any kernel fences for all KMD objects at creation. This should resolve some severe corruption seen during evictions. v2 (Matt B): - Revamp the comment explaining this. Also mention why USAGE_KERNEL is correct here. v3 (Thomas): - Make sure to use ctx.interruptible for the wait. Testcase: igt@xe-evict-ccs Closes: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/853 Closes: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/855 Reported-by: Zbigniew Kempczyński <[email protected]> Signed-off-by: Matthew Auld <[email protected]> Cc: Thomas Hellström <[email protected]> Cc: Matthew Brost <[email protected]> Reviewed-by: Thomas Hellström <[email protected]> Tested-by: Zbigniew Kempczyński <[email protected]> Signed-off-by: Rodrigo Vivi <[email protected]>
1 parent a667cf5 commit 503a6f4

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

drivers/gpu/drm/xe/xe_bo.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,37 @@ struct xe_bo *__xe_bo_create_locked(struct xe_device *xe, struct xe_bo *bo,
12691269
if (err)
12701270
return ERR_PTR(err);
12711271

1272+
/*
1273+
* The VRAM pages underneath are potentially still being accessed by the
1274+
* GPU, as per async GPU clearing and async evictions. However TTM makes
1275+
* sure to add any corresponding move/clear fences into the objects
1276+
* dma-resv using the DMA_RESV_USAGE_KERNEL slot.
1277+
*
1278+
* For KMD internal buffers we don't care about GPU clearing, however we
1279+
* still need to handle async evictions, where the VRAM is still being
1280+
* accessed by the GPU. Most internal callers are not expecting this,
1281+
* since they are missing the required synchronisation before accessing
1282+
* the memory. To keep things simple just sync wait any kernel fences
1283+
* here, if the buffer is designated KMD internal.
1284+
*
1285+
* For normal userspace objects we should already have the required
1286+
* pipelining or sync waiting elsewhere, since we already have to deal
1287+
* with things like async GPU clearing.
1288+
*/
1289+
if (type == ttm_bo_type_kernel) {
1290+
long timeout = dma_resv_wait_timeout(bo->ttm.base.resv,
1291+
DMA_RESV_USAGE_KERNEL,
1292+
ctx.interruptible,
1293+
MAX_SCHEDULE_TIMEOUT);
1294+
1295+
if (timeout < 0) {
1296+
if (!resv)
1297+
dma_resv_unlock(bo->ttm.base.resv);
1298+
xe_bo_put(bo);
1299+
return ERR_PTR(timeout);
1300+
}
1301+
}
1302+
12721303
bo->created = true;
12731304
if (bulk)
12741305
ttm_bo_set_bulk_move(&bo->ttm, bulk);

0 commit comments

Comments
 (0)