Skip to content

Commit bd3d1f8

Browse files
committed
drm/i915/selftests: Mark GPR checking more hostile
Currently, we check that a new context has a clear set of general purpose registers. Add a little bit of hostility by preempting our new context and re-poisoning the GPR to ensure that there is no context leakage from preemption. Signed-off-by: Chris Wilson <[email protected]> Reviewed-by: Ramalingam C <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent e7aa531 commit bd3d1f8

File tree

1 file changed

+96
-31
lines changed

1 file changed

+96
-31
lines changed

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

Lines changed: 96 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4344,13 +4344,13 @@ static int live_lrc_state(void *arg)
43444344
return err;
43454345
}
43464346

4347-
static int gpr_make_dirty(struct intel_engine_cs *engine)
4347+
static int gpr_make_dirty(struct intel_context *ce)
43484348
{
43494349
struct i915_request *rq;
43504350
u32 *cs;
43514351
int n;
43524352

4353-
rq = intel_engine_create_kernel_request(engine);
4353+
rq = intel_context_create_request(ce);
43544354
if (IS_ERR(rq))
43554355
return PTR_ERR(rq);
43564356

@@ -4362,53 +4362,54 @@ static int gpr_make_dirty(struct intel_engine_cs *engine)
43624362

43634363
*cs++ = MI_LOAD_REGISTER_IMM(NUM_GPR_DW);
43644364
for (n = 0; n < NUM_GPR_DW; n++) {
4365-
*cs++ = CS_GPR(engine, n);
4365+
*cs++ = CS_GPR(ce->engine, n);
43664366
*cs++ = STACK_MAGIC;
43674367
}
43684368
*cs++ = MI_NOOP;
43694369

43704370
intel_ring_advance(rq, cs);
4371+
4372+
rq->sched.attr.priority = I915_PRIORITY_BARRIER;
43714373
i915_request_add(rq);
43724374

43734375
return 0;
43744376
}
43754377

4376-
static int __live_gpr_clear(struct intel_engine_cs *engine,
4377-
struct i915_vma *scratch)
4378+
static struct i915_request *
4379+
__gpr_read(struct intel_context *ce, struct i915_vma *scratch, u32 *slot)
43784380
{
4379-
struct intel_context *ce;
4381+
const u32 offset =
4382+
i915_ggtt_offset(ce->engine->status_page.vma) +
4383+
offset_in_page(slot);
43804384
struct i915_request *rq;
43814385
u32 *cs;
43824386
int err;
43834387
int n;
43844388

4385-
if (INTEL_GEN(engine->i915) < 9 && engine->class != RENDER_CLASS)
4386-
return 0; /* GPR only on rcs0 for gen8 */
4387-
4388-
err = gpr_make_dirty(engine);
4389-
if (err)
4390-
return err;
4391-
4392-
ce = intel_context_create(engine);
4393-
if (IS_ERR(ce))
4394-
return PTR_ERR(ce);
4395-
43964389
rq = intel_context_create_request(ce);
4397-
if (IS_ERR(rq)) {
4398-
err = PTR_ERR(rq);
4399-
goto err_put;
4400-
}
4390+
if (IS_ERR(rq))
4391+
return rq;
44014392

4402-
cs = intel_ring_begin(rq, 4 * NUM_GPR_DW);
4393+
cs = intel_ring_begin(rq, 6 + 4 * NUM_GPR_DW);
44034394
if (IS_ERR(cs)) {
4404-
err = PTR_ERR(cs);
44054395
i915_request_add(rq);
4406-
goto err_put;
4396+
return ERR_CAST(cs);
44074397
}
44084398

4399+
*cs++ = MI_ARB_ON_OFF | MI_ARB_ENABLE;
4400+
*cs++ = MI_NOOP;
4401+
4402+
*cs++ = MI_SEMAPHORE_WAIT |
4403+
MI_SEMAPHORE_GLOBAL_GTT |
4404+
MI_SEMAPHORE_POLL |
4405+
MI_SEMAPHORE_SAD_NEQ_SDD;
4406+
*cs++ = 0;
4407+
*cs++ = offset;
4408+
*cs++ = 0;
4409+
44094410
for (n = 0; n < NUM_GPR_DW; n++) {
44104411
*cs++ = MI_STORE_REGISTER_MEM_GEN8 | MI_USE_GGTT;
4411-
*cs++ = CS_GPR(engine, n);
4412+
*cs++ = CS_GPR(ce->engine, n);
44124413
*cs++ = i915_ggtt_offset(scratch) + n * sizeof(u32);
44134414
*cs++ = 0;
44144415
}
@@ -4421,9 +4422,59 @@ static int __live_gpr_clear(struct intel_engine_cs *engine,
44214422

44224423
i915_request_get(rq);
44234424
i915_request_add(rq);
4425+
if (err) {
4426+
i915_request_put(rq);
4427+
rq = ERR_PTR(err);
4428+
}
4429+
4430+
return rq;
4431+
}
4432+
4433+
static int __live_lrc_gpr(struct intel_engine_cs *engine,
4434+
struct i915_vma *scratch,
4435+
bool preempt)
4436+
{
4437+
u32 *slot = memset32(engine->status_page.addr + 1000, 0, 4);
4438+
struct intel_context *ce;
4439+
struct i915_request *rq;
4440+
u32 *cs;
4441+
int err;
4442+
int n;
4443+
4444+
if (INTEL_GEN(engine->i915) < 9 && engine->class != RENDER_CLASS)
4445+
return 0; /* GPR only on rcs0 for gen8 */
4446+
4447+
err = gpr_make_dirty(engine->kernel_context);
4448+
if (err)
4449+
return err;
4450+
4451+
ce = intel_context_create(engine);
4452+
if (IS_ERR(ce))
4453+
return PTR_ERR(ce);
4454+
4455+
rq = __gpr_read(ce, scratch, slot);
4456+
if (IS_ERR(rq)) {
4457+
err = PTR_ERR(rq);
4458+
goto err_put;
4459+
}
4460+
4461+
err = wait_for_submit(engine, rq, HZ / 2);
44244462
if (err)
44254463
goto err_rq;
44264464

4465+
if (preempt) {
4466+
err = gpr_make_dirty(engine->kernel_context);
4467+
if (err)
4468+
goto err_rq;
4469+
4470+
err = emit_semaphore_signal(engine->kernel_context, slot);
4471+
if (err)
4472+
goto err_rq;
4473+
} else {
4474+
slot[0] = 1;
4475+
wmb();
4476+
}
4477+
44274478
if (i915_request_wait(rq, 0, HZ / 5) < 0) {
44284479
err = -ETIME;
44294480
goto err_rq;
@@ -4449,13 +4500,15 @@ static int __live_gpr_clear(struct intel_engine_cs *engine,
44494500
i915_gem_object_unpin_map(scratch->obj);
44504501

44514502
err_rq:
4503+
memset32(&slot[0], -1, 4);
4504+
wmb();
44524505
i915_request_put(rq);
44534506
err_put:
44544507
intel_context_put(ce);
44554508
return err;
44564509
}
44574510

4458-
static int live_gpr_clear(void *arg)
4511+
static int live_lrc_gpr(void *arg)
44594512
{
44604513
struct intel_gt *gt = arg;
44614514
struct intel_engine_cs *engine;
@@ -4473,14 +4526,26 @@ static int live_gpr_clear(void *arg)
44734526
return PTR_ERR(scratch);
44744527

44754528
for_each_engine(engine, gt, id) {
4476-
err = __live_gpr_clear(engine, scratch);
4529+
unsigned long heartbeat;
4530+
4531+
engine_heartbeat_disable(engine, &heartbeat);
4532+
4533+
err = __live_lrc_gpr(engine, scratch, false);
4534+
if (err)
4535+
goto err;
4536+
4537+
err = __live_lrc_gpr(engine, scratch, true);
4538+
if (err)
4539+
goto err;
4540+
4541+
err:
4542+
engine_heartbeat_enable(engine, heartbeat);
4543+
if (igt_flush_test(gt->i915))
4544+
err = -EIO;
44774545
if (err)
44784546
break;
44794547
}
44804548

4481-
if (igt_flush_test(gt->i915))
4482-
err = -EIO;
4483-
44844549
i915_vma_unpin_and_release(&scratch, 0);
44854550
return err;
44864551
}
@@ -4779,7 +4844,7 @@ int intel_lrc_live_selftests(struct drm_i915_private *i915)
47794844
SUBTEST(live_lrc_layout),
47804845
SUBTEST(live_lrc_fixed),
47814846
SUBTEST(live_lrc_state),
4782-
SUBTEST(live_gpr_clear),
4847+
SUBTEST(live_lrc_gpr),
47834848
SUBTEST(live_lrc_timestamp),
47844849
SUBTEST(live_pphwsp_runtime),
47854850
};

0 commit comments

Comments
 (0)