Skip to contentSkip to conversation

drm/i915/migrate: Account for the reserved_space

PATCH Superseded Matthew Auld 3 participants 5 messages Nov 18, 2022 – Dec 6, 2022

Subsystems (3)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 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 v2 2/2 drm/i915/selftests: exercise emit_pte() with nearly full ring

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

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

Cc Chris Wilson <[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 | 152 +++++++++++++++++++++
 2 files changed, 156 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 +152 -0

170 lines not on this page · raw message

Signature · 1 line
2.38.1
#2 lore raw

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

In reply to Matthew Auld
== Series Details ==

== Series Details ==

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

== Summary ==

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

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

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

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

total: 0 errors, 4 warnings, 0 checks, 34 lines checked
28ff1746d334 drm/i915/selftests: exercise emit_pte() with nearly full ring
-:179: WARNING:MSLEEP: msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.rst #179: FILE: drivers/gpu/drm/i915/gt/selftest_migrate.c:644:
+ msleep(10); /* start all threads before we kthread_stop() */

total: 0 errors, 1 warnings, 0 checks, 194 lines checked

#3 lore raw

[Intel-gfx] ✗ Fi.CI.BAT: failure for series starting with [v2,1/2] drm/i915/migrate: Account for the reserved_space

In reply to Matthew Auld
== Series Details ==

== Series Details ==

Series: series starting with [v2,1/2] drm/i915/migrate: Account for the reserved_space
URL : https://patchwork.freedesktop.org/series/111076/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_12398 -> Patchwork_111076v1
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with Patchwork_111076v1 absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes introduced in Patchwork_111076v1, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.

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

Participating hosts (41 -> 27)
------------------------------

Additional (1): fi-rkl-11600
Missing (15): fi-ilk-m540 bat-dg1-7 fi-bdw-samus bat-dg1-6 bat-dg2-8 bat-adlm-1 bat-dg2-9 bat-adlp-6 bat-adlp-4 fi-ctg-p8600 bat-adln-1 bat-rplp-1 bat-rpls-2 bat-dg2-11 bat-jsl-1

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in Patchwork_111076v1:

### IGT changes ###

#### Possible regressions ####

* igt@i915_selftest@live@migrate:
- fi-bsw-nick: [PASS][1] -> [TIMEOUT][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12398/fi-bsw-nick/igt@i915_selftest@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111076v1/fi-bsw-nick/igt@i915_selftest@[email protected]
- fi-bsw-kefka: [PASS][3] -> [TIMEOUT][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12398/fi-bsw-kefka/igt@i915_selftest@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111076v1/fi-bsw-kefka/igt@i915_selftest@[email protected]

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

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

### IGT changes ###

#### Issues hit ####

* igt@debugfs_test@basic-hwmon:
- fi-rkl-11600: NOTRUN -> [SKIP][5] ([i915#7456])
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111076v1/fi-rkl-11600/igt@[email protected]

* igt@gem_huc_copy@huc-copy:
- fi-rkl-11600: NOTRUN -> [SKIP][6] ([i915#2190])
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111076v1/fi-rkl-11600/igt@[email protected]

* igt@gem_lmem_swapping@basic:
- fi-apl-guc: NOTRUN -> [SKIP][7] ([fdo#109271] / [i915#4613]) +3 similar issues
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111076v1/fi-apl-guc/igt@[email protected]

* igt@gem_lmem_swapping@parallel-random-engines:
- fi-rkl-11600: NOTRUN -> [SKIP][8] ([i915#4613]) +3 similar issues
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111076v1/fi-rkl-11600/igt@[email protected]

* igt@gem_tiled_pread_basic:
- fi-rkl-11600: NOTRUN -> [SKIP][9] ([i915#3282])
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111076v1/fi-rkl-11600/igt@gem_tiled_pread_basic.html

* igt@i915_pm_backlight@basic-brightness:
- fi-rkl-11600: NOTRUN -> [SKIP][10] ([i915#7561])
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111076v1/fi-rkl-11600/igt@[email protected]

* igt@i915_suspend@basic-s3-without-i915:
- fi-rkl-11600: NOTRUN -> [INCOMPLETE][11] ([i915#4817])
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111076v1/fi-rkl-11600/igt@[email protected]

* igt@kms_chamelium@common-hpd-after-suspend:
- fi-apl-guc: NOTRUN -> [SKIP][12] ([fdo#109271] / [fdo#111827])
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111076v1/fi-apl-guc/igt@[email protected]

* igt@kms_chamelium@hdmi-hpd-fast:
- fi-rkl-11600: NOTRUN -> [SKIP][13] ([fdo#111827]) +7 similar issues
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111076v1/fi-rkl-11600/igt@[email protected]

* igt@kms_cursor_legacy@basic-busy-flip-before-cursor:
- fi-rkl-11600: NOTRUN -> [SKIP][14] ([i915#4103])
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111076v1/fi-rkl-11600/igt@[email protected]

* igt@kms_force_connector_basic@force-load-detect:
- fi-rkl-11600: NOTRUN -> [SKIP][15] ([fdo#109285] / [i915#4098])
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111076v1/fi-rkl-11600/igt@[email protected]

* igt@kms_psr@sprite_plane_onoff:
- fi-rkl-11600: NOTRUN -> [SKIP][16] ([i915#1072]) +3 similar issues
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111076v1/fi-rkl-11600/igt@kms_psr@sprite_plane_onoff.html

* igt@kms_setmode@basic-clone-single-crtc:
- fi-rkl-11600: NOTRUN -> [SKIP][17] ([i915#3555] / [i915#4098])
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111076v1/fi-rkl-11600/igt@[email protected]

* igt@prime_vgem@basic-read:
- fi-rkl-11600: NOTRUN -> [SKIP][18] ([fdo#109295] / [i915#3291] / [i915#3708]) +2 similar issues
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111076v1/fi-rkl-11600/igt@[email protected]

* igt@prime_vgem@basic-userptr:
- fi-rkl-11600: NOTRUN -> [SKIP][19] ([fdo#109295] / [i915#3301] / [i915#3708])
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111076v1/fi-rkl-11600/igt@[email protected]

#### Possible fixes ####

* igt@core_hotunplug@unbind-rebind:
- fi-apl-guc: [INCOMPLETE][20] ([i915#7073]) -> [PASS][21]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12398/fi-apl-guc/igt@[email protected]
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111076v1/fi-apl-guc/igt@[email protected]

* igt@kms_cursor_legacy@basic-busy-flip-before-cursor@atomic-transitions-varying-size:
- fi-bsw-kefka: [FAIL][22] ([i915#6298]) -> [PASS][23]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12398/fi-bsw-kefka/igt@kms_cursor_legacy@basic-busy-flip-before-cursor@atomic-transitions-varying-size.html
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111076v1/fi-bsw-kefka/igt@kms_cursor_legacy@basic-busy-flip-before-cursor@atomic-transitions-varying-size.html

[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[fdo#109285]: https://bugs.freedesktop.org/show_bug.cgi?id=109285
[fdo#109295]: https://bugs.freedesktop.org/show_bug.cgi?id=109295
[fdo#111827]: https://bugs.freedesktop.org/show_bug.cgi?id=111827
[i915#1072]: https://gitlab.freedesktop.org/drm/intel/issues/1072
[i915#2190]: https://gitlab.freedesktop.org/drm/intel/issues/2190
[i915#3282]: https://gitlab.freedesktop.org/drm/intel/issues/3282
[i915#3291]: https://gitlab.freedesktop.org/drm/intel/issues/3291
[i915#3301]: https://gitlab.freedesktop.org/drm/intel/issues/3301
[i915#3555]: https://gitlab.freedesktop.org/drm/intel/issues/3555
[i915#3708]: https://gitlab.freedesktop.org/drm/intel/issues/3708
[i915#4098]: https://gitlab.freedesktop.org/drm/intel/issues/4098
[i915#4103]: https://gitlab.freedesktop.org/drm/intel/issues/4103
[i915#4613]: https://gitlab.freedesktop.org/drm/intel/issues/4613
[i915#4817]: https://gitlab.freedesktop.org/drm/intel/issues/4817
[i915#6298]: https://gitlab.freedesktop.org/drm/intel/issues/6298
[i915#7073]: https://gitlab.freedesktop.org/drm/intel/issues/7073
[i915#7456]: https://gitlab.freedesktop.org/drm/intel/issues/7456
[i915#7561]: https://gitlab.freedesktop.org/drm/intel/issues/7561

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

* Linux: CI_DRM_12398 -> Patchwork_111076v1

CI-20190529: 20190529
CI_DRM_12398: 6ff9396457d55a1915566b11121e8fe6f9068b1c @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_7068: 5c0ec905b6bbecfb8df8b8f3315d0470539e6ae3 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_111076v1: 6ff9396457d55a1915566b11121e8fe6f9068b1c @ git://anongit.freedesktop.org/gfx-ci/linux

### Linux commits

3fa5606931da drm/i915/selftests: exercise emit_pte() with nearly full ring 2577f09dabf1 drm/i915/migrate: Account for the reserved_space

== Logs ==

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

Reviewed-by on v2 1/2
#4 lore raw
In reply to Matthew Auld
Quoted 30 lines · Matthew Auld

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 +0 -0
index b405a04135ca..48c3b5168558 100644
@@ -342,6 +342,16 @@ static int emit_no_arbitration(struct i915_request *rq)
  	return 0;
  }
 

drivers/gpu/drm/i915/gt/intel_migrate.c static int emit_no_arbitration(struct i915_request *rq) · line 354

Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_migrate.c +10 -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;
+}
+

I guess, the assumption that subtractions of u32 values do not overflows, is valid.
Then I guess more natural would be use u32 for all vars involved, this way we can use min instead of min_t, minor nit.

Anyway:

Regards
Andrzej

Quoted 23 lines
drivers/gpu/drm/i915/gt/intel_migrate.c +2 -4
  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);