Skip to content

Commit 3a1edef

Browse files
committed
drm/xe: Make WA BB part of LRC BO
No idea why, but without this GuC context switches randomly fail when running IGTs in a loop. Need to follow up why this fixes the aforementioned issue but can live with a stable driver for now. Fixes: 617d824 ("drm/xe: Add WA BB to capture active context utilization") Cc: stable@vger.kernel.org Signed-off-by: Matthew Brost <matthew.brost@intel.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Tested-by: Shuicheng Lin <shuicheng.lin@intel.com> Link: https://lore.kernel.org/r/20250612031925.4009701-1-matthew.brost@intel.com
1 parent 0fccfb6 commit 3a1edef

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

drivers/gpu/drm/xe/xe_lrc.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
#define LRC_PPHWSP_SIZE SZ_4K
4242
#define LRC_INDIRECT_RING_STATE_SIZE SZ_4K
43+
#define LRC_WA_BB_SIZE SZ_4K
4344

4445
static struct xe_device *
4546
lrc_to_xe(struct xe_lrc *lrc)
@@ -910,7 +911,6 @@ static void xe_lrc_finish(struct xe_lrc *lrc)
910911
{
911912
xe_hw_fence_ctx_finish(&lrc->fence_ctx);
912913
xe_bo_unpin_map_no_vm(lrc->bo);
913-
xe_bo_unpin_map_no_vm(lrc->bb_per_ctx_bo);
914914
}
915915

916916
/*
@@ -973,22 +973,27 @@ struct wa_bb_setup {
973973
u32 *batch, size_t max_size);
974974
};
975975

976+
static size_t wa_bb_offset(struct xe_lrc *lrc)
977+
{
978+
return lrc->bo->size - LRC_WA_BB_SIZE;
979+
}
980+
976981
static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
977982
{
978-
const size_t max_size = lrc->bb_per_ctx_bo->size;
983+
const size_t max_size = LRC_WA_BB_SIZE;
979984
static const struct wa_bb_setup funcs[] = {
980985
{ .setup = wa_bb_setup_utilization },
981986
};
982987
ssize_t remain;
983988
u32 *cmd, *buf = NULL;
984989

985-
if (lrc->bb_per_ctx_bo->vmap.is_iomem) {
990+
if (lrc->bo->vmap.is_iomem) {
986991
buf = kmalloc(max_size, GFP_KERNEL);
987992
if (!buf)
988993
return -ENOMEM;
989994
cmd = buf;
990995
} else {
991-
cmd = lrc->bb_per_ctx_bo->vmap.vaddr;
996+
cmd = lrc->bo->vmap.vaddr + wa_bb_offset(lrc);
992997
}
993998

994999
remain = max_size / sizeof(*cmd);
@@ -1011,13 +1016,14 @@ static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
10111016
*cmd++ = MI_BATCH_BUFFER_END;
10121017

10131018
if (buf) {
1014-
xe_map_memcpy_to(gt_to_xe(lrc->gt), &lrc->bb_per_ctx_bo->vmap, 0,
1015-
buf, (cmd - buf) * sizeof(*cmd));
1019+
xe_map_memcpy_to(gt_to_xe(lrc->gt), &lrc->bo->vmap,
1020+
wa_bb_offset(lrc), buf,
1021+
(cmd - buf) * sizeof(*cmd));
10161022
kfree(buf);
10171023
}
10181024

1019-
xe_lrc_write_ctx_reg(lrc, CTX_BB_PER_CTX_PTR,
1020-
xe_bo_ggtt_addr(lrc->bb_per_ctx_bo) | 1);
1025+
xe_lrc_write_ctx_reg(lrc, CTX_BB_PER_CTX_PTR, xe_bo_ggtt_addr(lrc->bo) +
1026+
wa_bb_offset(lrc) + 1);
10211027

10221028
return 0;
10231029

@@ -1059,20 +1065,13 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
10591065
* FIXME: Perma-pinning LRC as we don't yet support moving GGTT address
10601066
* via VM bind calls.
10611067
*/
1062-
lrc->bo = xe_bo_create_pin_map(xe, tile, NULL, lrc_size,
1068+
lrc->bo = xe_bo_create_pin_map(xe, tile, NULL,
1069+
lrc_size + LRC_WA_BB_SIZE,
10631070
ttm_bo_type_kernel,
10641071
bo_flags);
10651072
if (IS_ERR(lrc->bo))
10661073
return PTR_ERR(lrc->bo);
10671074

1068-
lrc->bb_per_ctx_bo = xe_bo_create_pin_map(xe, tile, NULL, SZ_4K,
1069-
ttm_bo_type_kernel,
1070-
bo_flags);
1071-
if (IS_ERR(lrc->bb_per_ctx_bo)) {
1072-
err = PTR_ERR(lrc->bb_per_ctx_bo);
1073-
goto err_lrc_finish;
1074-
}
1075-
10761075
lrc->size = lrc_size;
10771076
lrc->ring.size = ring_size;
10781077
lrc->ring.tail = 0;
@@ -1860,7 +1859,8 @@ struct xe_lrc_snapshot *xe_lrc_snapshot_capture(struct xe_lrc *lrc)
18601859
snapshot->seqno = xe_lrc_seqno(lrc);
18611860
snapshot->lrc_bo = xe_bo_get(lrc->bo);
18621861
snapshot->lrc_offset = xe_lrc_pphwsp_offset(lrc);
1863-
snapshot->lrc_size = lrc->bo->size - snapshot->lrc_offset;
1862+
snapshot->lrc_size = lrc->bo->size - snapshot->lrc_offset -
1863+
LRC_WA_BB_SIZE;
18641864
snapshot->lrc_snapshot = NULL;
18651865
snapshot->ctx_timestamp = lower_32_bits(xe_lrc_ctx_timestamp(lrc));
18661866
snapshot->ctx_job_timestamp = xe_lrc_ctx_job_timestamp(lrc);

drivers/gpu/drm/xe/xe_lrc_types.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ struct xe_lrc {
5353

5454
/** @ctx_timestamp: readout value of CTX_TIMESTAMP on last update */
5555
u64 ctx_timestamp;
56-
57-
/** @bb_per_ctx_bo: buffer object for per context batch wa buffer */
58-
struct xe_bo *bb_per_ctx_bo;
5956
};
6057

6158
struct xe_lrc_snapshot;

0 commit comments

Comments
 (0)