Commit 8ec21a7c authored by Chris Wilson's avatar Chris Wilson

drm/i915/selftests: Use a sacrificial context for hang testing

Avoid injecting hangs in to the i915->kernel_context in case the GPU
reset leaves corruption in the context image in its wake (leading to
continual failures and system hangs after the selftests are ostensibly
complete). Use a sacrificial kernel_context instead.

v2: Closing a context is tricky; export a function (for selftests) from
i915_gem_context.c to get it right.
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Cc: Michel Thierry <michel.thierry@intel.com>
Reviewed-by: default avatarMika Kuoppala <mika.kuoppala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180205152431.12163-2-chris@chris-wilson.co.uk
parent a8b66f2c
...@@ -33,6 +33,7 @@ struct hang { ...@@ -33,6 +33,7 @@ struct hang {
struct drm_i915_private *i915; struct drm_i915_private *i915;
struct drm_i915_gem_object *hws; struct drm_i915_gem_object *hws;
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
struct i915_gem_context *ctx;
u32 *seqno; u32 *seqno;
u32 *batch; u32 *batch;
}; };
...@@ -45,9 +46,15 @@ static int hang_init(struct hang *h, struct drm_i915_private *i915) ...@@ -45,9 +46,15 @@ static int hang_init(struct hang *h, struct drm_i915_private *i915)
memset(h, 0, sizeof(*h)); memset(h, 0, sizeof(*h));
h->i915 = i915; h->i915 = i915;
h->ctx = kernel_context(i915);
if (IS_ERR(h->ctx))
return PTR_ERR(h->ctx);
h->hws = i915_gem_object_create_internal(i915, PAGE_SIZE); h->hws = i915_gem_object_create_internal(i915, PAGE_SIZE);
if (IS_ERR(h->hws)) if (IS_ERR(h->hws)) {
return PTR_ERR(h->hws); err = PTR_ERR(h->hws);
goto err_ctx;
}
h->obj = i915_gem_object_create_internal(i915, PAGE_SIZE); h->obj = i915_gem_object_create_internal(i915, PAGE_SIZE);
if (IS_ERR(h->obj)) { if (IS_ERR(h->obj)) {
...@@ -79,6 +86,8 @@ static int hang_init(struct hang *h, struct drm_i915_private *i915) ...@@ -79,6 +86,8 @@ static int hang_init(struct hang *h, struct drm_i915_private *i915)
i915_gem_object_put(h->obj); i915_gem_object_put(h->obj);
err_hws: err_hws:
i915_gem_object_put(h->hws); i915_gem_object_put(h->hws);
err_ctx:
kernel_context_close(h->ctx);
return err; return err;
} }
...@@ -196,9 +205,7 @@ static int emit_recurse_batch(struct hang *h, ...@@ -196,9 +205,7 @@ static int emit_recurse_batch(struct hang *h,
} }
static struct drm_i915_gem_request * static struct drm_i915_gem_request *
hang_create_request(struct hang *h, hang_create_request(struct hang *h, struct intel_engine_cs *engine)
struct intel_engine_cs *engine,
struct i915_gem_context *ctx)
{ {
struct drm_i915_gem_request *rq; struct drm_i915_gem_request *rq;
int err; int err;
...@@ -225,7 +232,7 @@ hang_create_request(struct hang *h, ...@@ -225,7 +232,7 @@ hang_create_request(struct hang *h,
h->batch = vaddr; h->batch = vaddr;
} }
rq = i915_gem_request_alloc(engine, ctx); rq = i915_gem_request_alloc(engine, h->ctx);
if (IS_ERR(rq)) if (IS_ERR(rq))
return rq; return rq;
...@@ -307,6 +314,8 @@ static void hang_fini(struct hang *h) ...@@ -307,6 +314,8 @@ static void hang_fini(struct hang *h)
i915_gem_object_unpin_map(h->hws); i915_gem_object_unpin_map(h->hws);
i915_gem_object_put(h->hws); i915_gem_object_put(h->hws);
kernel_context_close(h->ctx);
flush_test(h->i915, I915_WAIT_LOCKED); flush_test(h->i915, I915_WAIT_LOCKED);
} }
...@@ -342,7 +351,7 @@ static int igt_hang_sanitycheck(void *arg) ...@@ -342,7 +351,7 @@ static int igt_hang_sanitycheck(void *arg)
if (!intel_engine_can_store_dword(engine)) if (!intel_engine_can_store_dword(engine))
continue; continue;
rq = hang_create_request(&h, engine, i915->kernel_context); rq = hang_create_request(&h, engine);
if (IS_ERR(rq)) { if (IS_ERR(rq)) {
err = PTR_ERR(rq); err = PTR_ERR(rq);
pr_err("Failed to create request for %s, err=%d\n", pr_err("Failed to create request for %s, err=%d\n",
...@@ -479,8 +488,7 @@ static int __igt_reset_engine(struct drm_i915_private *i915, bool active) ...@@ -479,8 +488,7 @@ static int __igt_reset_engine(struct drm_i915_private *i915, bool active)
struct drm_i915_gem_request *rq; struct drm_i915_gem_request *rq;
mutex_lock(&i915->drm.struct_mutex); mutex_lock(&i915->drm.struct_mutex);
rq = hang_create_request(&h, engine, rq = hang_create_request(&h, engine);
i915->kernel_context);
if (IS_ERR(rq)) { if (IS_ERR(rq)) {
err = PTR_ERR(rq); err = PTR_ERR(rq);
mutex_unlock(&i915->drm.struct_mutex); mutex_unlock(&i915->drm.struct_mutex);
...@@ -687,8 +695,7 @@ static int __igt_reset_engine_others(struct drm_i915_private *i915, ...@@ -687,8 +695,7 @@ static int __igt_reset_engine_others(struct drm_i915_private *i915,
struct drm_i915_gem_request *rq; struct drm_i915_gem_request *rq;
mutex_lock(&i915->drm.struct_mutex); mutex_lock(&i915->drm.struct_mutex);
rq = hang_create_request(&h, engine, rq = hang_create_request(&h, engine);
i915->kernel_context);
if (IS_ERR(rq)) { if (IS_ERR(rq)) {
err = PTR_ERR(rq); err = PTR_ERR(rq);
mutex_unlock(&i915->drm.struct_mutex); mutex_unlock(&i915->drm.struct_mutex);
...@@ -843,7 +850,7 @@ static int igt_wait_reset(void *arg) ...@@ -843,7 +850,7 @@ static int igt_wait_reset(void *arg)
if (err) if (err)
goto unlock; goto unlock;
rq = hang_create_request(&h, i915->engine[RCS], i915->kernel_context); rq = hang_create_request(&h, i915->engine[RCS]);
if (IS_ERR(rq)) { if (IS_ERR(rq)) {
err = PTR_ERR(rq); err = PTR_ERR(rq);
goto fini; goto fini;
...@@ -922,7 +929,7 @@ static int igt_reset_queue(void *arg) ...@@ -922,7 +929,7 @@ static int igt_reset_queue(void *arg)
if (!intel_engine_can_store_dword(engine)) if (!intel_engine_can_store_dword(engine))
continue; continue;
prev = hang_create_request(&h, engine, i915->kernel_context); prev = hang_create_request(&h, engine);
if (IS_ERR(prev)) { if (IS_ERR(prev)) {
err = PTR_ERR(prev); err = PTR_ERR(prev);
goto fini; goto fini;
...@@ -936,9 +943,7 @@ static int igt_reset_queue(void *arg) ...@@ -936,9 +943,7 @@ static int igt_reset_queue(void *arg)
struct drm_i915_gem_request *rq; struct drm_i915_gem_request *rq;
unsigned int reset_count; unsigned int reset_count;
rq = hang_create_request(&h, rq = hang_create_request(&h, engine);
engine,
i915->kernel_context);
if (IS_ERR(rq)) { if (IS_ERR(rq)) {
err = PTR_ERR(rq); err = PTR_ERR(rq);
goto fini; goto fini;
...@@ -1049,7 +1054,7 @@ static int igt_handle_error(void *arg) ...@@ -1049,7 +1054,7 @@ static int igt_handle_error(void *arg)
if (err) if (err)
goto err_unlock; goto err_unlock;
rq = hang_create_request(&h, engine, i915->kernel_context); rq = hang_create_request(&h, engine);
if (IS_ERR(rq)) { if (IS_ERR(rq)) {
err = PTR_ERR(rq); err = PTR_ERR(rq);
goto err_fini; goto err_fini;
......
...@@ -92,3 +92,14 @@ live_context(struct drm_i915_private *i915, struct drm_file *file) ...@@ -92,3 +92,14 @@ live_context(struct drm_i915_private *i915, struct drm_file *file)
return i915_gem_create_context(i915, file->driver_priv); return i915_gem_create_context(i915, file->driver_priv);
} }
struct i915_gem_context *
kernel_context(struct drm_i915_private *i915)
{
return i915_gem_context_create_kernel(i915, I915_PRIORITY_NORMAL);
}
void kernel_context_close(struct i915_gem_context *ctx)
{
context_close(ctx);
}
...@@ -36,4 +36,7 @@ void mock_context_close(struct i915_gem_context *ctx); ...@@ -36,4 +36,7 @@ void mock_context_close(struct i915_gem_context *ctx);
struct i915_gem_context * struct i915_gem_context *
live_context(struct drm_i915_private *i915, struct drm_file *file); live_context(struct drm_i915_private *i915, struct drm_file *file);
struct i915_gem_context *kernel_context(struct drm_i915_private *i915);
void kernel_context_close(struct i915_gem_context *ctx);
#endif /* !__MOCK_CONTEXT_H */ #endif /* !__MOCK_CONTEXT_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment