Skip to contentSkip to conversation

drm/i915/migrate: Account for the reserved_space

PATCH Superseded Matthew Auld 2 participants 5 messages Nov 24, 2022

Subsystems (3)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/3 drm/i915/migrate: Account for the reserved_space

From: Chris Wilson <[email protected]>

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.

Testcase: igt@i915_selftests@live_emit_pte_full_ring

---
 drivers/gpu/drm/i915/gt/intel_migrate.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/gt/intel_migrate.c +12 -4
index b405a04135ca..48c3b5168558 100644
@@ -342,6 +342,16 @@ static int emit_no_arbitration(struct i915_request *rq)
 	return 0;
 }
 
+static int max_pte_pkt_size(struct i915_request *rq, int pkt)
+{
+       struct intel_ring *ring = rq->ring;
+
+       pkt = min_t(int, pkt, (ring->space - rq->reserved_space) / sizeof(u32) + 5);
+       pkt = min_t(int, pkt, (ring->size - ring->emit) / sizeof(u32) + 5);
+
+       return pkt;
+}
+
 static int emit_pte(struct i915_request *rq,
 		    struct sgt_dma *it,
 		    enum i915_cache_level cache_level,
@@ -388,8 +398,7 @@ static int emit_pte(struct i915_request *rq,
 		return PTR_ERR(cs);
 
 	/* Pack as many PTE updates as possible into a single MI command */
-	pkt = min_t(int, dword_length, ring->space / sizeof(u32) + 5);
-	pkt = min_t(int, pkt, (ring->size - ring->emit) / sizeof(u32) + 5);
+	pkt = max_pte_pkt_size(rq, dword_length);
 
 	hdr = cs;
 	*cs++ = MI_STORE_DATA_IMM | REG_BIT(21); /* as qword elements */
@@ -422,8 +431,7 @@ static int emit_pte(struct i915_request *rq,
 				}
 			}
 
-			pkt = min_t(int, dword_rem, ring->space / sizeof(u32) + 5);
-			pkt = min_t(int, pkt, (ring->size - ring->emit) / sizeof(u32) + 5);
+			pkt = max_pte_pkt_size(rq, dword_rem);
 
 			hdr = cs;
 			*cs++ = MI_STORE_DATA_IMM | REG_BIT(21);
Signature · 1 line
2.38.1
#1 lore raw

PATCH v4 2/3 drm/i915/selftests: use live_subtests for live_migrate

Probably a good idea to do an igt_flush_test() at the end of each subtest, just to be sure the previous work has been flushed and doesn't somehow interfere with the current subtest.

Cc Chris Wilson <[email protected]>
Cc Andi Shyti <[email protected]>
Cc Andrzej Hajda <[email protected]>
Cc Nirmoy Das <[email protected]>
---
 drivers/gpu/drm/i915/gt/selftest_migrate.c | 28 ++++++++++++++++------
 1 file changed, 21 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/gt/selftest_migrate.c +21 -7
index 0dc5309c90a4..1eab025ac002 100644
@@ -486,7 +486,8 @@ global_clear(struct intel_migrate *migrate, u32 sz, struct rnd_state *prng)
 
 static int live_migrate_copy(void *arg)
 {
-	struct intel_migrate *migrate = arg;
+	struct intel_gt *gt = arg;
+	struct intel_migrate *migrate = &gt->migrate;
 	struct drm_i915_private *i915 = migrate->context->engine->i915;
 	I915_RND_STATE(prng);
 	int i;
@@ -507,7 +508,8 @@ static int live_migrate_copy(void *arg)
 
 static int live_migrate_clear(void *arg)
 {
-	struct intel_migrate *migrate = arg;
+	struct intel_gt *gt = arg;
+	struct intel_migrate *migrate = &gt->migrate;
 	struct drm_i915_private *i915 = migrate->context->engine->i915;
 	I915_RND_STATE(prng);
 	int i;
@@ -593,7 +595,10 @@ static int __thread_migrate_copy(void *arg)
 
 static int thread_migrate_copy(void *arg)
 {
-	return threaded_migrate(arg, __thread_migrate_copy, 0);
+	struct intel_gt *gt = arg;
+	struct intel_migrate *migrate = &gt->migrate;
+
+	return threaded_migrate(migrate, __thread_migrate_copy, 0);
 }
 
 static int __thread_global_copy(void *arg)
@@ -605,7 +610,10 @@ static int __thread_global_copy(void *arg)
 
 static int thread_global_copy(void *arg)
 {
-	return threaded_migrate(arg, __thread_global_copy, 0);
+	struct intel_gt *gt = arg;
+	struct intel_migrate *migrate = &gt->migrate;
+
+	return threaded_migrate(migrate, __thread_global_copy, 0);
 }
 
 static int __thread_migrate_clear(void *arg)
@@ -624,12 +632,18 @@ static int __thread_global_clear(void *arg)
 
 static int thread_migrate_clear(void *arg)
 {
-	return threaded_migrate(arg, __thread_migrate_clear, 0);
+	struct intel_gt *gt = arg;
+	struct intel_migrate *migrate = &gt->migrate;
+
+	return threaded_migrate(migrate, __thread_migrate_clear, 0);
 }
 
 static int thread_global_clear(void *arg)
 {
-	return threaded_migrate(arg, __thread_global_clear, 0);
+	struct intel_gt *gt = arg;
+	struct intel_migrate *migrate = &gt->migrate;
+
+	return threaded_migrate(migrate, __thread_global_clear, 0);
 }
 
 int intel_migrate_live_selftests(struct drm_i915_private *i915)
@@ -647,7 +661,7 @@ int intel_migrate_live_selftests(struct drm_i915_private *i915)
 	if (!gt->migrate.context)
 		return 0;
 
-	return i915_subtests(tests, &gt->migrate);
+	return intel_gt_live_subtests(tests, gt);
 }
 
 static struct drm_i915_gem_object *
Signature · 1 line
2.38.1
#2 lore raw

PATCH v4 3/3 drm/i915/selftests: exercise emit_pte() with nearly full ring

In reply to Matthew Auld

Simple regression test to check that we don't trample the rq->reserved_space when returning from emit_pte(), if the ring is nearly full.

v2: Make spinner_kill() static
v3: Reduce the ring size further, which should mean we need to execute less
noops; hopefully this appeases bsw. Also add some debug logging.
v4: Fix the min request construction to account for reserved_space +

    I915_EMIT_PTE_NUM_DWORDS

References: https://gitlab.freedesktop.org/drm/intel/-/issues/7535
References: https://gitlab.freedesktop.org/drm/intel/-/issues/6889

Cc Chris Wilson <[email protected]>
Cc Andi Shyti <[email protected]>
Cc Andrzej Hajda <[email protected]>
Cc Nirmoy Das <[email protected]>
---
 drivers/gpu/drm/i915/gt/intel_migrate.c    |   6 +-
 drivers/gpu/drm/i915/gt/selftest_migrate.c | 158 +++++++++++++++++++++
 2 files changed, 162 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/intel_migrate.c +4 -2
index 48c3b5168558..6df728b82a73 100644
@@ -352,6 +352,8 @@ static int max_pte_pkt_size(struct i915_request *rq, int pkt)
        return pkt;
 }
 
+#define I915_EMIT_PTE_NUM_DWORDS 6
+
 static int emit_pte(struct i915_request *rq,
 		    struct sgt_dma *it,
 		    enum i915_cache_level cache_level,
@@ -393,7 +395,7 @@ static int emit_pte(struct i915_request *rq,
 
 	offset += (u64)rq->engine->instance << 32;
 
-	cs = intel_ring_begin(rq, 6);
+	cs = intel_ring_begin(rq, I915_EMIT_PTE_NUM_DWORDS);
 	if (IS_ERR(cs))
 		return PTR_ERR(cs);
 
@@ -416,7 +418,7 @@ static int emit_pte(struct i915_request *rq,
 			intel_ring_advance(rq, cs);
 			intel_ring_update_space(ring);
 
-			cs = intel_ring_begin(rq, 6);
+			cs = intel_ring_begin(rq, I915_EMIT_PTE_NUM_DWORDS);
 			if (IS_ERR(cs))
 				return PTR_ERR(cs);
 
drivers/gpu/drm/i915/gt/selftest_migrate.c +158 -0

176 lines not on this page · raw message

Signature · 1 line
2.38.1
#3 lore raw

[Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for series starting with [v4,1/3] drm/i915/migrate: Account for the reserved_space

In reply to Matthew Auld
== Series Details ==

== Series Details ==

Series: series starting with [v4,1/3] drm/i915/migrate: Account for the reserved_space
URL : https://patchwork.freedesktop.org/series/111314/
State : warning

== Summary ==

Error: dim checkpatch failed
a161f13b1e36 drm/i915/migrate: Account for the reserved_space -:36: WARNING:LEADING_SPACE: please, no spaces at the start of a line #36: FILE: drivers/gpu/drm/i915/gt/intel_migrate.c:347:
+ struct intel_ring *ring = rq->ring;$

-:38: WARNING:LEADING_SPACE: please, no spaces at the start of a line #38: FILE: drivers/gpu/drm/i915/gt/intel_migrate.c:349:
+ pkt = min_t(int, pkt, (ring->space - rq->reserved_space) / sizeof(u32) + 5);$

-:39: WARNING:LEADING_SPACE: please, no spaces at the start of a line #39: FILE: drivers/gpu/drm/i915/gt/intel_migrate.c:350:
+ pkt = min_t(int, pkt, (ring->size - ring->emit) / sizeof(u32) + 5);$

-:41: WARNING:LEADING_SPACE: please, no spaces at the start of a line #41: FILE: drivers/gpu/drm/i915/gt/intel_migrate.c:352:
+ return pkt;$

total: 0 errors, 4 warnings, 0 checks, 34 lines checked
e82b1ca63779 drm/i915/selftests: use live_subtests for live_migrate f9c9bf06c390 drm/i915/selftests: exercise emit_pte() with nearly full ring -:77: WARNING:TRACING_LOGGING: Unnecessary ftrace-like logging - prefer using ftrace #77: FILE: drivers/gpu/drm/i915/gt/selftest_migrate.c:539:
+ pr_info("%s\n", __func__);

-:189: WARNING:MSLEEP: msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.rst #189: FILE: drivers/gpu/drm/i915/gt/selftest_migrate.c:651:
+ msleep(10); /* start all threads before we kthread_stop() */

total: 0 errors, 2 warnings, 0 checks, 200 lines checked

#4 lore raw

[Intel-gfx] ✓ Fi.CI.BAT: success for series starting with [v4,1/3] drm/i915/migrate: Account for the reserved_space

In reply to Matthew Auld
== Series Details ==

== Series Details ==

Series: series starting with [v4,1/3] drm/i915/migrate: Account for the reserved_space
URL : https://patchwork.freedesktop.org/series/111314/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_12432 -> Patchwork_111314v1
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111314v1/index.html

Participating hosts (36 -> 35)
------------------------------

Additional (1): bat-dg1-6
Missing (2): fi-ctg-p8600 fi-rkl-11600

Known issues
------------

Here are the changes found in Patchwork_111314v1 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@gem_mmap@basic:
- bat-dg1-6: NOTRUN -> [SKIP][1] ([i915#4083])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111314v1/bat-dg1-6/igt@[email protected]

* igt@gem_render_tiled_blits@basic:
- bat-dg1-6: NOTRUN -> [SKIP][2] ([i915#4079]) +1 similar issue
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111314v1/bat-dg1-6/igt@[email protected]

* igt@gem_tiled_fence_blits@basic:
- bat-dg1-6: NOTRUN -> [SKIP][3] ([i915#4077]) +2 similar issues
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111314v1/bat-dg1-6/igt@[email protected]

* igt@i915_pm_backlight@basic-brightness:
- bat-dg1-6: NOTRUN -> [SKIP][4] ([i915#7561])
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111314v1/bat-dg1-6/igt@[email protected]

* igt@i915_pm_rps@basic-api:
- bat-dg1-6: NOTRUN -> [SKIP][5] ([i915#6621])
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111314v1/bat-dg1-6/igt@[email protected]

* igt@i915_selftest@live@gt_timelines:
- fi-apl-guc: [PASS][6] -> [INCOMPLETE][7] ([i915#7511])
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12432/fi-apl-guc/igt@i915_selftest@live@gt_timelines.html
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111314v1/fi-apl-guc/igt@i915_selftest@live@gt_timelines.html

* igt@kms_addfb_basic@basic-y-tiled-legacy:
- bat-dg1-6: NOTRUN -> [SKIP][8] ([i915#4215])
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111314v1/bat-dg1-6/igt@[email protected]

* igt@kms_addfb_basic@tile-pitch-mismatch:
- bat-dg1-6: NOTRUN -> [SKIP][9] ([i915#4212]) +7 similar issues
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111314v1/bat-dg1-6/igt@[email protected]

* igt@kms_chamelium@hdmi-crc-fast:
- bat-dg1-6: NOTRUN -> [SKIP][10] ([fdo#111827]) +8 similar issues
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111314v1/bat-dg1-6/igt@[email protected]

* igt@kms_cursor_legacy@basic-busy-flip-before-cursor:
- bat-dg1-6: NOTRUN -> [SKIP][11] ([i915#4103] / [i915#4213])
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111314v1/bat-dg1-6/igt@[email protected]

* igt@kms_cursor_legacy@basic-busy-flip-before-cursor@atomic-transitions:
- fi-bsw-kefka: [PASS][12] -> [FAIL][13] ([i915#6298])
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12432/fi-bsw-kefka/igt@kms_cursor_legacy@[email protected]
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111314v1/fi-bsw-kefka/igt@kms_cursor_legacy@[email protected]

* igt@kms_force_connector_basic@force-load-detect:
- bat-dg1-6: NOTRUN -> [SKIP][14] ([fdo#109285])
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111314v1/bat-dg1-6/igt@[email protected]

* igt@kms_psr@sprite_plane_onoff:
- bat-dg1-6: NOTRUN -> [SKIP][15] ([i915#1072] / [i915#4078]) +3 similar issues
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111314v1/bat-dg1-6/igt@kms_psr@sprite_plane_onoff.html

* igt@kms_setmode@basic-clone-single-crtc:
- bat-dg1-6: NOTRUN -> [SKIP][16] ([i915#3555])
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111314v1/bat-dg1-6/igt@[email protected]

* igt@prime_vgem@basic-gtt:
- bat-dg1-6: NOTRUN -> [SKIP][17] ([i915#3708] / [i915#4077]) +1 similar issue
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111314v1/bat-dg1-6/igt@[email protected]

* igt@prime_vgem@basic-read:
- bat-dg1-6: NOTRUN -> [SKIP][18] ([i915#3708]) +3 similar issues
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111314v1/bat-dg1-6/igt@[email protected]

* igt@prime_vgem@basic-userptr:
- bat-dg1-6: NOTRUN -> [SKIP][19] ([i915#3708] / [i915#4873])
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111314v1/bat-dg1-6/igt@[email protected]

#### Possible fixes ####

* igt@i915_selftest@live@gt_lrc:
- {bat-adln-1}: [INCOMPLETE][20] ([i915#4983]) -> [PASS][21]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12432/bat-adln-1/igt@i915_selftest@live@gt_lrc.html
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111314v1/bat-adln-1/igt@i915_selftest@live@gt_lrc.html

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[fdo#109285]: https://bugs.freedesktop.org/show_bug.cgi?id=109285
[fdo#111827]: https://bugs.freedesktop.org/show_bug.cgi?id=111827
[i915#1072]: https://gitlab.freedesktop.org/drm/intel/issues/1072
[i915#3555]: https://gitlab.freedesktop.org/drm/intel/issues/3555
[i915#3708]: https://gitlab.freedesktop.org/drm/intel/issues/3708
[i915#4077]: https://gitlab.freedesktop.org/drm/intel/issues/4077
[i915#4078]: https://gitlab.freedesktop.org/drm/intel/issues/4078
[i915#4079]: https://gitlab.freedesktop.org/drm/intel/issues/4079
[i915#4083]: https://gitlab.freedesktop.org/drm/intel/issues/4083
[i915#4103]: https://gitlab.freedesktop.org/drm/intel/issues/4103
[i915#4212]: https://gitlab.freedesktop.org/drm/intel/issues/4212
[i915#4213]: https://gitlab.freedesktop.org/drm/intel/issues/4213
[i915#4215]: https://gitlab.freedesktop.org/drm/intel/issues/4215
[i915#4258]: https://gitlab.freedesktop.org/drm/intel/issues/4258
[i915#4312]: https://gitlab.freedesktop.org/drm/intel/issues/4312
[i915#4873]: https://gitlab.freedesktop.org/drm/intel/issues/4873
[i915#4983]: https://gitlab.freedesktop.org/drm/intel/issues/4983
[i915#6298]: https://gitlab.freedesktop.org/drm/intel/issues/6298
[i915#6621]: https://gitlab.freedesktop.org/drm/intel/issues/6621
[i915#6997]: https://gitlab.freedesktop.org/drm/intel/issues/6997
[i915#7511]: https://gitlab.freedesktop.org/drm/intel/issues/7511
[i915#7561]: https://gitlab.freedesktop.org/drm/intel/issues/7561

Build changes
-------------

* Linux: CI_DRM_12432 -> Patchwork_111314v1

CI-20190529: 20190529
CI_DRM_12432: 751dd27d6cc6adea727c784d7b50bf517e91c026 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_7072: 69ba7163475925cdc69aebbdfa0e87453ae165c7 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_111314v1: 751dd27d6cc6adea727c784d7b50bf517e91c026 @ git://anongit.freedesktop.org/gfx-ci/linux

### Linux commits

ad933581fc6d drm/i915/selftests: exercise emit_pte() with nearly full ring dc3dbc04435a drm/i915/selftests: use live_subtests for live_migrate 799aec7b952d drm/i915/migrate: Account for the reserved_space

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111314v1/index.html