Skip to content

Commit 1dd47b5

Browse files
mikuintickle
authored andcommitted
drm/i915: Add live selftests for indirect ctx batchbuffers
Indirect ctx batchbuffers are a hw feature of which batch can be run, by hardware, during context restoration stage. Driver can setup a batchbuffer and also an offset into the context image. When context image is marshalled from memory to registers, and when the offset from the start of context register state is equal of what driver pre-determined, batch will run. So one can manipulate context restoration process at cacheline granularity, given some limitations, as you need to have rudimentaries in place before you can run a batch. Add selftest which will write the ring start register to a canary spot. This will test that hardware will run a batchbuffer for the context in question. v2: request wait fix, naming (Chris) v3: test order (Chris) v4: rebase Signed-off-by: Mika Kuoppala <[email protected]> Acked-by: Chris Wilson <[email protected]> Signed-off-by: Chris Wilson <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 685d210 commit 1dd47b5

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed

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

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5710,6 +5710,155 @@ static int live_lrc_isolation(void *arg)
57105710
return err;
57115711
}
57125712

5713+
static int indirect_ctx_submit_req(struct intel_context *ce)
5714+
{
5715+
struct i915_request *rq;
5716+
int err = 0;
5717+
5718+
rq = intel_context_create_request(ce);
5719+
if (IS_ERR(rq))
5720+
return PTR_ERR(rq);
5721+
5722+
i915_request_get(rq);
5723+
i915_request_add(rq);
5724+
5725+
if (i915_request_wait(rq, 0, HZ / 5) < 0)
5726+
err = -ETIME;
5727+
5728+
i915_request_put(rq);
5729+
5730+
return err;
5731+
}
5732+
5733+
#define CTX_BB_CANARY_OFFSET (3 * 1024)
5734+
#define CTX_BB_CANARY_INDEX (CTX_BB_CANARY_OFFSET / sizeof(u32))
5735+
5736+
static u32 *
5737+
emit_indirect_ctx_bb_canary(const struct intel_context *ce, u32 *cs)
5738+
{
5739+
*cs++ = MI_STORE_REGISTER_MEM_GEN8 |
5740+
MI_SRM_LRM_GLOBAL_GTT |
5741+
MI_LRI_LRM_CS_MMIO;
5742+
*cs++ = i915_mmio_reg_offset(RING_START(0));
5743+
*cs++ = i915_ggtt_offset(ce->state) +
5744+
context_wa_bb_offset(ce) +
5745+
CTX_BB_CANARY_OFFSET;
5746+
*cs++ = 0;
5747+
5748+
return cs;
5749+
}
5750+
5751+
static void
5752+
indirect_ctx_bb_setup(struct intel_context *ce)
5753+
{
5754+
u32 *cs = context_indirect_bb(ce);
5755+
5756+
cs[CTX_BB_CANARY_INDEX] = 0xdeadf00d;
5757+
5758+
setup_indirect_ctx_bb(ce, ce->engine, emit_indirect_ctx_bb_canary);
5759+
}
5760+
5761+
static bool check_ring_start(struct intel_context *ce)
5762+
{
5763+
const u32 * const ctx_bb = (void *)(ce->lrc_reg_state) -
5764+
LRC_STATE_OFFSET + context_wa_bb_offset(ce);
5765+
5766+
if (ctx_bb[CTX_BB_CANARY_INDEX] == ce->lrc_reg_state[CTX_RING_START])
5767+
return true;
5768+
5769+
pr_err("ring start mismatch: canary 0x%08x vs state 0x%08x\n",
5770+
ctx_bb[CTX_BB_CANARY_INDEX],
5771+
ce->lrc_reg_state[CTX_RING_START]);
5772+
5773+
return false;
5774+
}
5775+
5776+
static int indirect_ctx_bb_check(struct intel_context *ce)
5777+
{
5778+
int err;
5779+
5780+
err = indirect_ctx_submit_req(ce);
5781+
if (err)
5782+
return err;
5783+
5784+
if (!check_ring_start(ce))
5785+
return -EINVAL;
5786+
5787+
return 0;
5788+
}
5789+
5790+
static int __live_lrc_indirect_ctx_bb(struct intel_engine_cs *engine)
5791+
{
5792+
struct intel_context *a, *b;
5793+
int err = 0;
5794+
5795+
a = intel_context_create(engine);
5796+
b = intel_context_create(engine);
5797+
5798+
err = intel_context_pin(a);
5799+
if (err)
5800+
return err;
5801+
5802+
err = intel_context_pin(b);
5803+
if (err) {
5804+
intel_context_put(a);
5805+
return err;
5806+
}
5807+
5808+
/* We use the already reserved extra page in context state */
5809+
if (!a->wa_bb_page) {
5810+
GEM_BUG_ON(b->wa_bb_page);
5811+
GEM_BUG_ON(INTEL_GEN(engine->i915) == 12);
5812+
goto out;
5813+
}
5814+
5815+
/*
5816+
* In order to test that our per context bb is truly per context,
5817+
* and executes at the intended spot on context restoring process,
5818+
* make the batch store the ring start value to memory.
5819+
* As ring start is restored apriori of starting the indirect ctx bb and
5820+
* as it will be different for each context, it fits to this purpose.
5821+
*/
5822+
indirect_ctx_bb_setup(a);
5823+
indirect_ctx_bb_setup(b);
5824+
5825+
err = indirect_ctx_bb_check(a);
5826+
if (err)
5827+
goto out;
5828+
5829+
err = indirect_ctx_bb_check(b);
5830+
out:
5831+
intel_context_unpin(b);
5832+
intel_context_put(b);
5833+
5834+
intel_context_unpin(a);
5835+
intel_context_put(a);
5836+
5837+
return err;
5838+
}
5839+
5840+
static int live_lrc_indirect_ctx_bb(void *arg)
5841+
{
5842+
struct intel_gt *gt = arg;
5843+
struct intel_engine_cs *engine;
5844+
enum intel_engine_id id;
5845+
int err = 0;
5846+
5847+
for_each_engine(engine, gt, id) {
5848+
intel_engine_pm_get(engine);
5849+
err = __live_lrc_indirect_ctx_bb(engine);
5850+
intel_engine_pm_put(engine);
5851+
5852+
if (igt_flush_test(gt->i915))
5853+
err = -EIO;
5854+
5855+
if (err)
5856+
break;
5857+
}
5858+
5859+
return err;
5860+
}
5861+
57135862
static void garbage_reset(struct intel_engine_cs *engine,
57145863
struct i915_request *rq)
57155864
{
@@ -5945,6 +6094,7 @@ int intel_lrc_live_selftests(struct drm_i915_private *i915)
59456094
SUBTEST(live_lrc_timestamp),
59466095
SUBTEST(live_lrc_garbage),
59476096
SUBTEST(live_pphwsp_runtime),
6097+
SUBTEST(live_lrc_indirect_ctx_bb),
59486098
};
59496099

59506100
if (!HAS_LOGICAL_RING_CONTEXTS(i915))

0 commit comments

Comments
 (0)