summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/i915/selftests
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2023-08-30 16:06:38 -0700
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2023-08-30 16:06:38 -0700
commit1ac731c529cd4d6adbce134754b51ff7d822b145 (patch)
tree143ab3f35ca5f3b69f583c84e6964b17139c2ec1 /drivers/gpu/drm/i915/selftests
parent07b4c950f27bef0362dc6ad7ee713aab61d58149 (diff)
parent54116d442e001e1b6bd482122043b1870998a1f3 (diff)
Merge branch 'next' into for-linus
Prepare input updates for 6.6 merge window.
Diffstat (limited to 'drivers/gpu/drm/i915/selftests')
-rw-r--r--drivers/gpu/drm/i915/selftests/i915_gem_gtt.c360
-rw-r--r--drivers/gpu/drm/i915/selftests/i915_live_selftests.h1
-rw-r--r--drivers/gpu/drm/i915/selftests/i915_request.c134
3 files changed, 81 insertions, 414 deletions
diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
index 01e75160a84a..154801f1c468 100644
--- a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
@@ -69,8 +69,10 @@ static int fake_get_pages(struct drm_i915_gem_object *obj)
rem = round_up(obj->base.size, BIT(31)) >> 31;
/* restricted by sg_alloc_table */
- if (overflows_type(rem, unsigned int))
+ if (overflows_type(rem, unsigned int)) {
+ kfree(pages);
return -E2BIG;
+ }
if (sg_alloc_table(pages, rem, GFP)) {
kfree(pages);
@@ -1940,361 +1942,6 @@ out_put:
return err;
}
-static int context_sync(struct intel_context *ce)
-{
- struct i915_request *rq;
- long timeout;
-
- rq = intel_context_create_request(ce);
- if (IS_ERR(rq))
- return PTR_ERR(rq);
-
- i915_request_get(rq);
- i915_request_add(rq);
-
- timeout = i915_request_wait(rq, 0, HZ / 5);
- i915_request_put(rq);
-
- return timeout < 0 ? -EIO : 0;
-}
-
-static struct i915_request *
-submit_batch(struct intel_context *ce, u64 addr)
-{
- struct i915_request *rq;
- int err;
-
- rq = intel_context_create_request(ce);
- if (IS_ERR(rq))
- return rq;
-
- err = 0;
- if (rq->engine->emit_init_breadcrumb) /* detect a hang */
- err = rq->engine->emit_init_breadcrumb(rq);
- if (err == 0)
- err = rq->engine->emit_bb_start(rq, addr, 0, 0);
-
- if (err == 0)
- i915_request_get(rq);
- i915_request_add(rq);
-
- return err ? ERR_PTR(err) : rq;
-}
-
-static u32 *spinner(u32 *batch, int i)
-{
- return batch + i * 64 / sizeof(*batch) + 4;
-}
-
-static void end_spin(u32 *batch, int i)
-{
- *spinner(batch, i) = MI_BATCH_BUFFER_END;
- wmb();
-}
-
-static int igt_cs_tlb(void *arg)
-{
- const unsigned int count = PAGE_SIZE / 64;
- const unsigned int chunk_size = count * PAGE_SIZE;
- struct drm_i915_private *i915 = arg;
- struct drm_i915_gem_object *bbe, *act, *out;
- struct i915_gem_engines_iter it;
- struct i915_address_space *vm;
- struct i915_gem_context *ctx;
- struct intel_context *ce;
- struct i915_vma *vma;
- I915_RND_STATE(prng);
- struct file *file;
- unsigned int i;
- u32 *result;
- u32 *batch;
- int err = 0;
-
- /*
- * Our mission here is to fool the hardware to execute something
- * from scratch as it has not seen the batch move (due to missing
- * the TLB invalidate).
- */
-
- file = mock_file(i915);
- if (IS_ERR(file))
- return PTR_ERR(file);
-
- ctx = live_context(i915, file);
- if (IS_ERR(ctx)) {
- err = PTR_ERR(ctx);
- goto out_unlock;
- }
-
- vm = i915_gem_context_get_eb_vm(ctx);
- if (i915_is_ggtt(vm))
- goto out_vm;
-
- /* Create two pages; dummy we prefill the TLB, and intended */
- bbe = i915_gem_object_create_internal(i915, PAGE_SIZE);
- if (IS_ERR(bbe)) {
- err = PTR_ERR(bbe);
- goto out_vm;
- }
-
- batch = i915_gem_object_pin_map_unlocked(bbe, I915_MAP_WC);
- if (IS_ERR(batch)) {
- err = PTR_ERR(batch);
- goto out_put_bbe;
- }
- memset32(batch, MI_BATCH_BUFFER_END, PAGE_SIZE / sizeof(u32));
- i915_gem_object_flush_map(bbe);
- i915_gem_object_unpin_map(bbe);
-
- act = i915_gem_object_create_internal(i915, PAGE_SIZE);
- if (IS_ERR(act)) {
- err = PTR_ERR(act);
- goto out_put_bbe;
- }
-
- /* Track the execution of each request by writing into different slot */
- batch = i915_gem_object_pin_map_unlocked(act, I915_MAP_WC);
- if (IS_ERR(batch)) {
- err = PTR_ERR(batch);
- goto out_put_act;
- }
- for (i = 0; i < count; i++) {
- u32 *cs = batch + i * 64 / sizeof(*cs);
- u64 addr = (vm->total - PAGE_SIZE) + i * sizeof(u32);
-
- GEM_BUG_ON(GRAPHICS_VER(i915) < 6);
- cs[0] = MI_STORE_DWORD_IMM_GEN4;
- if (GRAPHICS_VER(i915) >= 8) {
- cs[1] = lower_32_bits(addr);
- cs[2] = upper_32_bits(addr);
- cs[3] = i;
- cs[4] = MI_NOOP;
- cs[5] = MI_BATCH_BUFFER_START_GEN8;
- } else {
- cs[1] = 0;
- cs[2] = lower_32_bits(addr);
- cs[3] = i;
- cs[4] = MI_NOOP;
- cs[5] = MI_BATCH_BUFFER_START;
- }
- }
-
- out = i915_gem_object_create_internal(i915, PAGE_SIZE);
- if (IS_ERR(out)) {
- err = PTR_ERR(out);
- goto out_put_batch;
- }
- i915_gem_object_set_cache_coherency(out, I915_CACHING_CACHED);
-
- vma = i915_vma_instance(out, vm, NULL);
- if (IS_ERR(vma)) {
- err = PTR_ERR(vma);
- goto out_put_out;
- }
-
- err = i915_vma_pin(vma, 0, 0,
- PIN_USER |
- PIN_OFFSET_FIXED |
- (vm->total - PAGE_SIZE));
- if (err)
- goto out_put_out;
- GEM_BUG_ON(vma->node.start != vm->total - PAGE_SIZE);
-
- result = i915_gem_object_pin_map_unlocked(out, I915_MAP_WB);
- if (IS_ERR(result)) {
- err = PTR_ERR(result);
- goto out_put_out;
- }
-
- for_each_gem_engine(ce, i915_gem_context_lock_engines(ctx), it) {
- IGT_TIMEOUT(end_time);
- unsigned long pass = 0;
-
- if (!intel_engine_can_store_dword(ce->engine))
- continue;
-
- while (!__igt_timeout(end_time, NULL)) {
- struct i915_vm_pt_stash stash = {};
- struct i915_request *rq;
- struct i915_gem_ww_ctx ww;
- struct i915_vma_resource *vma_res;
- u64 offset;
-
- offset = igt_random_offset(&prng,
- 0, vm->total - PAGE_SIZE,
- chunk_size, PAGE_SIZE);
-
- memset32(result, STACK_MAGIC, PAGE_SIZE / sizeof(u32));
-
- vma = i915_vma_instance(bbe, vm, NULL);
- if (IS_ERR(vma)) {
- err = PTR_ERR(vma);
- goto end;
- }
-
- i915_gem_object_lock(bbe, NULL);
- err = i915_vma_get_pages(vma);
- i915_gem_object_unlock(bbe);
- if (err)
- goto end;
-
- vma_res = i915_vma_resource_alloc();
- if (IS_ERR(vma_res)) {
- i915_vma_put_pages(vma);
- err = PTR_ERR(vma_res);
- goto end;
- }
-
- i915_gem_ww_ctx_init(&ww, false);
-retry:
- err = i915_vm_lock_objects(vm, &ww);
- if (err)
- goto end_ww;
-
- err = i915_vm_alloc_pt_stash(vm, &stash, chunk_size);
- if (err)
- goto end_ww;
-
- err = i915_vm_map_pt_stash(vm, &stash);
- if (!err)
- vm->allocate_va_range(vm, &stash, offset, chunk_size);
- i915_vm_free_pt_stash(vm, &stash);
-end_ww:
- if (err == -EDEADLK) {
- err = i915_gem_ww_ctx_backoff(&ww);
- if (!err)
- goto retry;
- }
- i915_gem_ww_ctx_fini(&ww);
- if (err) {
- kfree(vma_res);
- goto end;
- }
-
- i915_vma_resource_init_from_vma(vma_res, vma);
- /* Prime the TLB with the dummy pages */
- for (i = 0; i < count; i++) {
- vma_res->start = offset + i * PAGE_SIZE;
- vm->insert_entries(vm, vma_res, I915_CACHE_NONE,
- 0);
-
- rq = submit_batch(ce, vma_res->start);
- if (IS_ERR(rq)) {
- err = PTR_ERR(rq);
- i915_vma_resource_fini(vma_res);
- kfree(vma_res);
- goto end;
- }
- i915_request_put(rq);
- }
- i915_vma_resource_fini(vma_res);
- i915_vma_put_pages(vma);
-
- err = context_sync(ce);
- if (err) {
- pr_err("%s: dummy setup timed out\n",
- ce->engine->name);
- kfree(vma_res);
- goto end;
- }
-
- vma = i915_vma_instance(act, vm, NULL);
- if (IS_ERR(vma)) {
- kfree(vma_res);
- err = PTR_ERR(vma);
- goto end;
- }
-
- i915_gem_object_lock(act, NULL);
- err = i915_vma_get_pages(vma);
- i915_gem_object_unlock(act);
- if (err) {
- kfree(vma_res);
- goto end;
- }
-
- i915_vma_resource_init_from_vma(vma_res, vma);
- /* Replace the TLB with target batches */
- for (i = 0; i < count; i++) {
- struct i915_request *rq;
- u32 *cs = batch + i * 64 / sizeof(*cs);
- u64 addr;
-
- vma_res->start = offset + i * PAGE_SIZE;
- vm->insert_entries(vm, vma_res, I915_CACHE_NONE, 0);
-
- addr = vma_res->start + i * 64;
- cs[4] = MI_NOOP;
- cs[6] = lower_32_bits(addr);
- cs[7] = upper_32_bits(addr);
- wmb();
-
- rq = submit_batch(ce, addr);
- if (IS_ERR(rq)) {
- err = PTR_ERR(rq);
- i915_vma_resource_fini(vma_res);
- kfree(vma_res);
- goto end;
- }
-
- /* Wait until the context chain has started */
- if (i == 0) {
- while (READ_ONCE(result[i]) &&
- !i915_request_completed(rq))
- cond_resched();
- } else {
- end_spin(batch, i - 1);
- }
-
- i915_request_put(rq);
- }
- end_spin(batch, count - 1);
-
- i915_vma_resource_fini(vma_res);
- kfree(vma_res);
- i915_vma_put_pages(vma);
-
- err = context_sync(ce);
- if (err) {
- pr_err("%s: writes timed out\n",
- ce->engine->name);
- goto end;
- }
-
- for (i = 0; i < count; i++) {
- if (result[i] != i) {
- pr_err("%s: Write lost on pass %lu, at offset %llx, index %d, found %x, expected %x\n",
- ce->engine->name, pass,
- offset, i, result[i], i);
- err = -EINVAL;
- goto end;
- }
- }
-
- vm->clear_range(vm, offset, chunk_size);
- pass++;
- }
- }
-end:
- if (igt_flush_test(i915))
- err = -EIO;
- i915_gem_context_unlock_engines(ctx);
- i915_gem_object_unpin_map(out);
-out_put_out:
- i915_gem_object_put(out);
-out_put_batch:
- i915_gem_object_unpin_map(act);
-out_put_act:
- i915_gem_object_put(act);
-out_put_bbe:
- i915_gem_object_put(bbe);
-out_vm:
- i915_vm_put(vm);
-out_unlock:
- fput(file);
- return err;
-}
-
int i915_gem_gtt_live_selftests(struct drm_i915_private *i915)
{
static const struct i915_subtest tests[] = {
@@ -2314,7 +1961,6 @@ int i915_gem_gtt_live_selftests(struct drm_i915_private *i915)
SUBTEST(igt_ggtt_fill),
SUBTEST(igt_ggtt_page),
SUBTEST(igt_ggtt_misaligned_pin),
- SUBTEST(igt_cs_tlb),
};
GEM_BUG_ON(offset_in_page(to_gt(i915)->ggtt->vm.total));
diff --git a/drivers/gpu/drm/i915/selftests/i915_live_selftests.h b/drivers/gpu/drm/i915/selftests/i915_live_selftests.h
index aaf8a380e5c7..5aee6c9a8295 100644
--- a/drivers/gpu/drm/i915/selftests/i915_live_selftests.h
+++ b/drivers/gpu/drm/i915/selftests/i915_live_selftests.h
@@ -25,6 +25,7 @@ selftest(gt_lrc, intel_lrc_live_selftests)
selftest(gt_mocs, intel_mocs_live_selftests)
selftest(gt_pm, intel_gt_pm_live_selftests)
selftest(gt_heartbeat, intel_heartbeat_live_selftests)
+selftest(gt_tlb, intel_tlb_live_selftests)
selftest(requests, i915_request_live_selftests)
selftest(migrate, intel_migrate_live_selftests)
selftest(active, i915_active_live_selftests)
diff --git a/drivers/gpu/drm/i915/selftests/i915_request.c b/drivers/gpu/drm/i915/selftests/i915_request.c
index 6fe22b096bdd..a9b79888c193 100644
--- a/drivers/gpu/drm/i915/selftests/i915_request.c
+++ b/drivers/gpu/drm/i915/selftests/i915_request.c
@@ -957,18 +957,18 @@ static int live_cancel_request(void *arg)
return 0;
}
-static struct i915_vma *empty_batch(struct drm_i915_private *i915)
+static struct i915_vma *empty_batch(struct intel_gt *gt)
{
struct drm_i915_gem_object *obj;
struct i915_vma *vma;
u32 *cmd;
int err;
- obj = i915_gem_object_create_internal(i915, PAGE_SIZE);
+ obj = i915_gem_object_create_internal(gt->i915, PAGE_SIZE);
if (IS_ERR(obj))
return ERR_CAST(obj);
- cmd = i915_gem_object_pin_map_unlocked(obj, I915_MAP_WB);
+ cmd = i915_gem_object_pin_map_unlocked(obj, I915_MAP_WC);
if (IS_ERR(cmd)) {
err = PTR_ERR(cmd);
goto err;
@@ -979,15 +979,15 @@ static struct i915_vma *empty_batch(struct drm_i915_private *i915)
__i915_gem_object_flush_map(obj, 0, 64);
i915_gem_object_unpin_map(obj);
- intel_gt_chipset_flush(to_gt(i915));
+ intel_gt_chipset_flush(gt);
- vma = i915_vma_instance(obj, &to_gt(i915)->ggtt->vm, NULL);
+ vma = i915_vma_instance(obj, gt->vm, NULL);
if (IS_ERR(vma)) {
err = PTR_ERR(vma);
goto err;
}
- err = i915_vma_pin(vma, 0, 0, PIN_USER | PIN_GLOBAL);
+ err = i915_vma_pin(vma, 0, 0, PIN_USER);
if (err)
goto err;
@@ -1005,6 +1005,14 @@ err:
return ERR_PTR(err);
}
+static int emit_bb_start(struct i915_request *rq, struct i915_vma *batch)
+{
+ return rq->engine->emit_bb_start(rq,
+ i915_vma_offset(batch),
+ i915_vma_size(batch),
+ 0);
+}
+
static struct i915_request *
empty_request(struct intel_engine_cs *engine,
struct i915_vma *batch)
@@ -1016,10 +1024,7 @@ empty_request(struct intel_engine_cs *engine,
if (IS_ERR(request))
return request;
- err = engine->emit_bb_start(request,
- i915_vma_offset(batch),
- i915_vma_size(batch),
- I915_DISPATCH_SECURE);
+ err = emit_bb_start(request, batch);
if (err)
goto out_request;
@@ -1034,8 +1039,7 @@ static int live_empty_request(void *arg)
struct drm_i915_private *i915 = arg;
struct intel_engine_cs *engine;
struct igt_live_test t;
- struct i915_vma *batch;
- int err = 0;
+ int err;
/*
* Submit various sized batches of empty requests, to each engine
@@ -1043,16 +1047,17 @@ static int live_empty_request(void *arg)
* the overhead of submitting requests to the hardware.
*/
- batch = empty_batch(i915);
- if (IS_ERR(batch))
- return PTR_ERR(batch);
-
for_each_uabi_engine(engine, i915) {
IGT_TIMEOUT(end_time);
struct i915_request *request;
+ struct i915_vma *batch;
unsigned long n, prime;
ktime_t times[2] = {};
+ batch = empty_batch(engine->gt);
+ if (IS_ERR(batch))
+ return PTR_ERR(batch);
+
err = igt_live_test_begin(&t, i915, __func__, engine->name);
if (err)
goto out_batch;
@@ -1100,27 +1105,29 @@ static int live_empty_request(void *arg)
engine->name,
ktime_to_ns(times[0]),
prime, div64_u64(ktime_to_ns(times[1]), prime));
+out_batch:
+ i915_vma_unpin(batch);
+ i915_vma_put(batch);
+ if (err)
+ break;
}
-out_batch:
- i915_vma_unpin(batch);
- i915_vma_put(batch);
return err;
}
-static struct i915_vma *recursive_batch(struct drm_i915_private *i915)
+static struct i915_vma *recursive_batch(struct intel_gt *gt)
{
struct drm_i915_gem_object *obj;
- const int ver = GRAPHICS_VER(i915);
+ const int ver = GRAPHICS_VER(gt->i915);
struct i915_vma *vma;
u32 *cmd;
int err;
- obj = i915_gem_object_create_internal(i915, PAGE_SIZE);
+ obj = i915_gem_object_create_internal(gt->i915, PAGE_SIZE);
if (IS_ERR(obj))
return ERR_CAST(obj);
- vma = i915_vma_instance(obj, to_gt(i915)->vm, NULL);
+ vma = i915_vma_instance(obj, gt->vm, NULL);
if (IS_ERR(vma)) {
err = PTR_ERR(vma);
goto err;
@@ -1152,7 +1159,7 @@ static struct i915_vma *recursive_batch(struct drm_i915_private *i915)
__i915_gem_object_flush_map(obj, 0, 64);
i915_gem_object_unpin_map(obj);
- intel_gt_chipset_flush(to_gt(i915));
+ intel_gt_chipset_flush(gt);
return vma;
@@ -1186,7 +1193,6 @@ static int live_all_engines(void *arg)
struct intel_engine_cs *engine;
struct i915_request **request;
struct igt_live_test t;
- struct i915_vma *batch;
unsigned int idx;
int err;
@@ -1204,42 +1210,44 @@ static int live_all_engines(void *arg)
if (err)
goto out_free;
- batch = recursive_batch(i915);
- if (IS_ERR(batch)) {
- err = PTR_ERR(batch);
- pr_err("%s: Unable to create batch, err=%d\n", __func__, err);
- goto out_free;
- }
-
- i915_vma_lock(batch);
-
idx = 0;
for_each_uabi_engine(engine, i915) {
+ struct i915_vma *batch;
+
+ batch = recursive_batch(engine->gt);
+ if (IS_ERR(batch)) {
+ err = PTR_ERR(batch);
+ pr_err("%s: Unable to create batch, err=%d\n",
+ __func__, err);
+ goto out_free;
+ }
+
+ i915_vma_lock(batch);
request[idx] = intel_engine_create_kernel_request(engine);
if (IS_ERR(request[idx])) {
err = PTR_ERR(request[idx]);
pr_err("%s: Request allocation failed with err=%d\n",
__func__, err);
- goto out_request;
+ goto out_unlock;
}
+ GEM_BUG_ON(request[idx]->context->vm != batch->vm);
err = i915_vma_move_to_active(batch, request[idx], 0);
GEM_BUG_ON(err);
- err = engine->emit_bb_start(request[idx],
- i915_vma_offset(batch),
- i915_vma_size(batch),
- 0);
+ err = emit_bb_start(request[idx], batch);
GEM_BUG_ON(err);
request[idx]->batch = batch;
i915_request_get(request[idx]);
i915_request_add(request[idx]);
idx++;
+out_unlock:
+ i915_vma_unlock(batch);
+ if (err)
+ goto out_request;
}
- i915_vma_unlock(batch);
-
idx = 0;
for_each_uabi_engine(engine, i915) {
if (i915_request_completed(request[idx])) {
@@ -1251,17 +1259,23 @@ static int live_all_engines(void *arg)
idx++;
}
- err = recursive_batch_resolve(batch);
- if (err) {
- pr_err("%s: failed to resolve batch, err=%d\n", __func__, err);
- goto out_request;
+ idx = 0;
+ for_each_uabi_engine(engine, i915) {
+ err = recursive_batch_resolve(request[idx]->batch);
+ if (err) {
+ pr_err("%s: failed to resolve batch, err=%d\n",
+ __func__, err);
+ goto out_request;
+ }
+ idx++;
}
idx = 0;
for_each_uabi_engine(engine, i915) {
+ struct i915_request *rq = request[idx];
long timeout;
- timeout = i915_request_wait(request[idx], 0,
+ timeout = i915_request_wait(rq, 0,
MAX_SCHEDULE_TIMEOUT);
if (timeout < 0) {
err = timeout;
@@ -1270,8 +1284,10 @@ static int live_all_engines(void *arg)
goto out_request;
}
- GEM_BUG_ON(!i915_request_completed(request[idx]));
- i915_request_put(request[idx]);
+ GEM_BUG_ON(!i915_request_completed(rq));
+ i915_vma_unpin(rq->batch);
+ i915_vma_put(rq->batch);
+ i915_request_put(rq);
request[idx] = NULL;
idx++;
}
@@ -1281,12 +1297,18 @@ static int live_all_engines(void *arg)
out_request:
idx = 0;
for_each_uabi_engine(engine, i915) {
- if (request[idx])
- i915_request_put(request[idx]);
+ struct i915_request *rq = request[idx];
+
+ if (!rq)
+ continue;
+
+ if (rq->batch) {
+ i915_vma_unpin(rq->batch);
+ i915_vma_put(rq->batch);
+ }
+ i915_request_put(rq);
idx++;
}
- i915_vma_unpin(batch);
- i915_vma_put(batch);
out_free:
kfree(request);
return err;
@@ -1322,7 +1344,7 @@ static int live_sequential_engines(void *arg)
for_each_uabi_engine(engine, i915) {
struct i915_vma *batch;
- batch = recursive_batch(i915);
+ batch = recursive_batch(engine->gt);
if (IS_ERR(batch)) {
err = PTR_ERR(batch);
pr_err("%s: Unable to create batch for %s, err=%d\n",
@@ -1338,6 +1360,7 @@ static int live_sequential_engines(void *arg)
__func__, engine->name, err);
goto out_unlock;
}
+ GEM_BUG_ON(request[idx]->context->vm != batch->vm);
if (prev) {
err = i915_request_await_dma_fence(request[idx],
@@ -1353,10 +1376,7 @@ static int live_sequential_engines(void *arg)
err = i915_vma_move_to_active(batch, request[idx], 0);
GEM_BUG_ON(err);
- err = engine->emit_bb_start(request[idx],
- i915_vma_offset(batch),
- i915_vma_size(batch),
- 0);
+ err = emit_bb_start(request[idx], batch);
GEM_BUG_ON(err);
request[idx]->batch = batch;