Skip to contentSkip to conversation

tests/i915: Add test for unaligned detiler fences

PATCH In review Imre Deak 2 participants 3 messages Jan 13, 2020

Subsystems (3)
lore
Share & tools
lore

Imre Deak

author
#0 lore raw

PATCH 1/1 tests/i915: Add test for unaligned detiler fences

Add a test to check the detiling on a buffer with a size that isn't aligned to the detiler fence stride we add for the buffer. While writes beyond the last full tile row may target an address beyond the buffer's size, we still expect that such writes will not lead to a corruption on memory pages that are not owned by the process performing the write.

The reason for this test: on TGL such writes lead to random memory corruption in memory not belonging to the process. This should be prevented ensuring that we keep pages that user space can access (padding the object size to be tile-row size aligned) reserved in the GTT address space until userspace can write through the fenced region.

Cc Chris Wilson <[email protected]>
Cc Ville Syrjälä <[email protected]>
---
 tests/Makefile.sources                |   3 +
 tests/i915/gem_unaligned_fence.c      | 108 ++++++++++++++++++++++++++
 tests/intel-ci/fast-feedback.testlist |   1 +
 tests/meson.build                     |   1 +
 4 files changed, 113 insertions(+)
 create mode 100644 tests/i915/gem_unaligned_fence.c
tests/Makefile.sources +3 -0
index 806eb02d..dce1d197 100644
@@ -460,6 +460,9 @@ gem_tiled_wc_SOURCES = i915/gem_tiled_wc.c
 TESTS_progs += gem_tiling_max_stride
 gem_tiling_max_stride_SOURCES = i915/gem_tiling_max_stride.c
 
+TESTS_progs += gem_unaligned_fence
+gem_unaligned_fence_SOURCES = i915/gem_unaligned_fence.c
+
 TESTS_progs += gem_unfence_active_buffers
 gem_unfence_active_buffers_SOURCES = i915/gem_unfence_active_buffers.c
 
tests/i915/gem_unaligned_fence.c new file +108 -0

108 lines not on this page · raw message

tests/intel-ci/fast-feedback.testlist +1 -0
index 8081446e..44460cd2 100644
@@ -70,6 +70,7 @@ igt@gem_sync@basic-store-each
 igt@gem_tiled_blits@basic
 igt@gem_tiled_fence_blits@basic
 igt@gem_tiled_pread_basic
+igt@gem_unaligned_fence@basic
 igt@gem_wait@basic-busy-all
 igt@gem_wait@basic-wait-all
 igt@gem_wait@basic-await-all
tests/meson.build +1 -0
index 570de545..19cdce53 100644
@@ -219,6 +219,7 @@ i915_progs = [
 	'gem_tiled_wb',
 	'gem_tiled_wc',
 	'gem_tiling_max_stride',
+	'gem_unaligned_fence',
 	'gem_unfence_active_buffers',
 	'gem_unref_active_buffers',
 	'gem_userptr_blits',
Signature · 6 lines
2.23.1

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#1 lore raw

Quoting Imre Deak (2020-01-13 17:21:20)

Quoted 11 lines

Add a test to check the detiling on a buffer with a size that isn't aligned to the detiler fence stride we add for the buffer. While writes beyond the last full tile row may target an address beyond the buffer's size, we still expect that such writes will not lead to a corruption on memory pages that are not owned by the process performing the write.

The reason for this test: on TGL such writes lead to random memory corruption in memory not belonging to the process. This should be prevented ensuring that we keep pages that user space can access (padding the object size to be tile-row size aligned) reserved in the GTT address space until userspace can write through the fenced region.

This is going through a different IP block and driver paths than the original bug. When we are using a fence, we create a vma that is sufficient to include the last tile row. When we create a vma for the display, we don't ask for that...

drivers/gpu/drm/i915/gem/i915_gem_domain.c +15 -10
@@ -344,19 +344,24 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
 	 * put it anyway and hope that userspace can cope (but always first
 	 * try to preserve the existing ABI).
 	 */
-	vma = ERR_PTR(-ENOSPC);
-	if ((flags & PIN_MAPPABLE) == 0 &&
-	    (!view || view->type == I915_GGTT_VIEW_NORMAL))
-		vma = i915_gem_object_ggtt_pin(obj, view, 0, alignment,
-					       flags |
-					       PIN_MAPPABLE |
-					       PIN_NONBLOCK);
-	if (IS_ERR(vma))
-		vma = i915_gem_object_ggtt_pin(obj, view, 0, alignment, flags);
+	vma = i915_vma_instance(obj, &i915->ggtt.vm, view);
 	if (IS_ERR(vma))
 		return vma;
 
-	vma->display_alignment = max_t(u64, vma->display_alignment, alignment);
+	alignment = max(vma->display_alignment, alignment);
+
+	ret = -ENOSPC;
+	if ((flags & PIN_MAPPABLE) == 0 &&
+	    vma->ggtt_view.type == I915_GGTT_VIEW_NORMAL)
+		ret = i915_vma_pin(vma,
+				   alignment, vma->fence_size,
+				   flags | PIN_MAPPABLE | PIN_NONBLOCK);
+	if (ret == -ENOSPC)
+		ret = i915_vma_pin(vma, alignment, vma->fence_size, flags);
+	if (ret)
+		return ERR_PTR(ret);
+
+	vma->display_alignment = alignment;
 
 	i915_gem_object_flush_if_display(obj);
 
drivers/gpu/drm/i915/i915_vma.c +1 -1
index 17d7c525ea5c..57df22b809fa 100644
@@ -619,7 +619,7 @@ i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
 	GEM_BUG_ON(drm_mm_node_allocated(&vma->node));
 
 	size = max(size, vma->size);
-	alignment = max(alignment, vma->display_alignment);
+	alignment = max_t(typeof(alignment), alignment, vma->display_alignment);
 	if (flags & PIN_MAPPABLE) {
 		size = max_t(typeof(size), size, vma->fence_size);
 		alignment = max_t(typeof(alignment),
drivers/gpu/drm/i915/i915_vma_types.h +1 -1
index e0942efd5236..2cf642ecbd7d 100644
@@ -182,7 +182,6 @@ struct i915_vma {
 	struct i915_fence_reg *fence;
 
 	u64 size;
-	u64 display_alignment;
 	struct i915_page_sizes page_sizes;
 
 	/* mmap-offset associated with fencing for this vma */
@@ -190,6 +189,7 @@ struct i915_vma {
 
 	u32 fence_size;
 	u32 fence_alignment;
+	u32 display_alignment;
 
 	/**
 	 * Count of the number of times this vma has been opened by different

The partial fencing interaction with HW and peeking at the pages behind should be covered by selftests -- as we want to peek at physical pages. Mostly done already.
-Chris
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

author
#2 lore raw
Quoted 13 lines · Chris Wilson

Quoting Imre Deak (2020-01-13 17:21:20)

Quoted 11 lines

Add a test to check the detiling on a buffer with a size that isn't aligned to the detiler fence stride we add for the buffer. While writes beyond the last full tile row may target an address beyond the buffer's size, we still expect that such writes will not lead to a corruption on memory pages that are not owned by the process performing the write.

The reason for this test: on TGL such writes lead to random memory corruption in memory not belonging to the process. This should be prevented ensuring that we keep pages that user space can access (padding the object size to be tile-row size aligned) reserved in the GTT address space until userspace can write through the fenced region.

Quoted 4 lines

This is going through a different IP block and driver paths than the original bug. When we are using a fence, we create a vma that is sufficient to include the last tile row. When we create a vma for the display, we don't ask for that...

Yes, then there must be some other issue too, since this test still shows the corruption, even though it's only using a gem buffer not a framebuffer.

Quoted 72 lines
drivers/gpu/drm/i915/gem/i915_gem_domain.c +15 -10
@@ -344,19 +344,24 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
 	 * put it anyway and hope that userspace can cope (but always first
 	 * try to preserve the existing ABI).
 	 */
-	vma = ERR_PTR(-ENOSPC);
-	if ((flags & PIN_MAPPABLE) == 0 &&
-	    (!view || view->type == I915_GGTT_VIEW_NORMAL))
-		vma = i915_gem_object_ggtt_pin(obj, view, 0, alignment,
-					       flags |
-					       PIN_MAPPABLE |
-					       PIN_NONBLOCK);
-	if (IS_ERR(vma))
-		vma = i915_gem_object_ggtt_pin(obj, view, 0, alignment, flags);
+	vma = i915_vma_instance(obj, &i915->ggtt.vm, view);
 	if (IS_ERR(vma))
 		return vma;
 
-	vma->display_alignment = max_t(u64, vma->display_alignment, alignment);
+	alignment = max(vma->display_alignment, alignment);
+
+	ret = -ENOSPC;
+	if ((flags & PIN_MAPPABLE) == 0 &&
+	    vma->ggtt_view.type == I915_GGTT_VIEW_NORMAL)
+		ret = i915_vma_pin(vma,
+				   alignment, vma->fence_size,
+				   flags | PIN_MAPPABLE | PIN_NONBLOCK);
+	if (ret == -ENOSPC)
+		ret = i915_vma_pin(vma, alignment, vma->fence_size, flags);
+	if (ret)
+		return ERR_PTR(ret);
+
+	vma->display_alignment = alignment;
 
 	i915_gem_object_flush_if_display(obj);
 
drivers/gpu/drm/i915/i915_vma.c +1 -1
index 17d7c525ea5c..57df22b809fa 100644
@@ -619,7 +619,7 @@ i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
 	GEM_BUG_ON(drm_mm_node_allocated(&vma->node));
 
 	size = max(size, vma->size);
-	alignment = max(alignment, vma->display_alignment);
+	alignment = max_t(typeof(alignment), alignment, vma->display_alignment);
 	if (flags & PIN_MAPPABLE) {
 		size = max_t(typeof(size), size, vma->fence_size);
 		alignment = max_t(typeof(alignment),
drivers/gpu/drm/i915/i915_vma_types.h +1 -1
index e0942efd5236..2cf642ecbd7d 100644
@@ -182,7 +182,6 @@ struct i915_vma {
 	struct i915_fence_reg *fence;
 
 	u64 size;
-	u64 display_alignment;
 	struct i915_page_sizes page_sizes;
 
 	/* mmap-offset associated with fencing for this vma */
@@ -190,6 +189,7 @@ struct i915_vma {
 
 	u32 fence_size;
 	u32 fence_alignment;
+	u32 display_alignment;
 
 	/**
 	 * Count of the number of times this vma has been opened by different
Quoted 4 lines

The partial fencing interaction with HW and peeking at the pages behind should be covered by selftests -- as we want to peek at physical pages. Mostly done already.
-Chris

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev