Skip to content

Commit 31a2e6c

Browse files
ickle-intelrodrigovivi
authored andcommitted
drm/i915/migrate: Account for the reserved_space
If the ring is nearly full when calling into emit_pte(), we might incorrectly trample the reserved_space when constructing the packet to emit the PTEs. This then triggers the GEM_BUG_ON(rq->reserved_space > ring->space) when later submitting the request, since the request itself doesn't have enough space left in the ring to emit things like workarounds, breadcrumbs etc. v2: Fix the whitespace errors Testcase: igt@i915_selftests@live_emit_pte_full_ring Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/7535 Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/6889 Fixes: cf58602 ("drm/i915/gt: Pipelined page migration") Signed-off-by: Chris Wilson <[email protected]> Signed-off-by: Matthew Auld <[email protected]> Cc: Andrzej Hajda <[email protected]> Cc: Andi Shyti <[email protected]> Cc: Nirmoy Das <[email protected]> Cc: <[email protected]> # v5.15+ Tested-by: Nirmoy Das <[email protected]> Reviewed-by: Nirmoy Das <[email protected]> Reviewed-by: Andrzej Hajda <[email protected]> Reviewed-by: Andi Shyti <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit 35168a6) Signed-off-by: Rodrigo Vivi <[email protected]>
1 parent 3153eeb commit 31a2e6c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

drivers/gpu/drm/i915/gt/intel_migrate.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,16 @@ static int emit_no_arbitration(struct i915_request *rq)
342342
return 0;
343343
}
344344

345+
static int max_pte_pkt_size(struct i915_request *rq, int pkt)
346+
{
347+
struct intel_ring *ring = rq->ring;
348+
349+
pkt = min_t(int, pkt, (ring->space - rq->reserved_space) / sizeof(u32) + 5);
350+
pkt = min_t(int, pkt, (ring->size - ring->emit) / sizeof(u32) + 5);
351+
352+
return pkt;
353+
}
354+
345355
static int emit_pte(struct i915_request *rq,
346356
struct sgt_dma *it,
347357
enum i915_cache_level cache_level,
@@ -388,8 +398,7 @@ static int emit_pte(struct i915_request *rq,
388398
return PTR_ERR(cs);
389399

390400
/* Pack as many PTE updates as possible into a single MI command */
391-
pkt = min_t(int, dword_length, ring->space / sizeof(u32) + 5);
392-
pkt = min_t(int, pkt, (ring->size - ring->emit) / sizeof(u32) + 5);
401+
pkt = max_pte_pkt_size(rq, dword_length);
393402

394403
hdr = cs;
395404
*cs++ = MI_STORE_DATA_IMM | REG_BIT(21); /* as qword elements */
@@ -422,8 +431,7 @@ static int emit_pte(struct i915_request *rq,
422431
}
423432
}
424433

425-
pkt = min_t(int, dword_rem, ring->space / sizeof(u32) + 5);
426-
pkt = min_t(int, pkt, (ring->size - ring->emit) / sizeof(u32) + 5);
434+
pkt = max_pte_pkt_size(rq, dword_rem);
427435

428436
hdr = cs;
429437
*cs++ = MI_STORE_DATA_IMM | REG_BIT(21);

0 commit comments

Comments
 (0)