Skip to contentSkip to conversation

igt: Test tiled bo for proper fence.

PATCH In review Bob Paauwe 2 participants 4 messages Dec 18, 2014 – Dec 19, 2014

lore
Share & tools
lore

Bob Paauwe

author
#0 lore raw

PATCH 1/1 igt: Test tiled bo for proper fence.

When a tiled bo is allocated such that the actual size of the bo is larger than the region covered by the tiles. For example allocating a Y-tiled bo that is 1920 x 1088 (15 x 34 tiles) results in a bo that is 0x200000 bytes instead of the 0x1FE000 bytes covered by the tiles. The fence needs to cover only the actual tiled region, otherwise writes beyond the tiled region may get converted to an address beyond the actual bo boundry.

This will test for that case by creating a tiled bo and a linear bo.
The linear bo is mapped directly after the tiled bo. The linear bo is filed with a specific value (0x00)
The tiled bo is filled with a different value (0xff)

If any bytes in the linear bo get written with 0xff, then the fence allowed writing beyond the tiled bo boundry.

---
 tests/Makefile.sources           |   1 +
 tests/gem_tiled_fence_overflow.c | 134 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 135 insertions(+)
 create mode 100644 tests/gem_tiled_fence_overflow.c
tests/Makefile.sources +1 -0
index d15a68b..c644fd3 100644
@@ -136,6 +136,7 @@ TESTS_progs = \
 	gem_tiled_pread_pwrite \
 	gem_tiled_swapping \
 	gem_tiled_wb \
+	gem_tiled_fence_overflow \
 	gem_tiling_max_stride \
 	gem_unfence_active_buffers \
 	gem_unref_active_buffers \
tests/gem_tiled_fence_overflow.c new file +134 -0

134 lines not on this page · raw message

Signature · 1 line
2.1.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#1 lore raw
Quoted 13 lines · Bob Paauwe

When a tiled bo is allocated such that the actual size of the bo is larger than the region covered by the tiles. For example allocating a Y-tiled bo that is 1920 x 1088 (15 x 34 tiles) results in a bo that is 0x200000 bytes instead of the 0x1FE000 bytes covered by the tiles. The fence needs to cover only the actual tiled region, otherwise writes beyond the tiled region may get converted to an address beyond the actual bo boundry.

This will test for that case by creating a tiled bo and a linear bo.
The linear bo is mapped directly after the tiled bo. The linear bo is filed with a specific value (0x00)
The tiled bo is filled with a different value (0xff)

Quoted 4 lines

If any bytes in the linear bo get written with 0xff, then the fence allowed writing beyond the tiled bo boundry.

Oh dear this is scary. Bunch of comments below.
-Daniel

Quoted 56 lines
---
 tests/Makefile.sources           |   1 +
 tests/gem_tiled_fence_overflow.c | 134 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 135 insertions(+)
 create mode 100644 tests/gem_tiled_fence_overflow.c
tests/Makefile.sources +1 -0
index d15a68b..c644fd3 100644
@@ -136,6 +136,7 @@ TESTS_progs = \
 	gem_tiled_pread_pwrite \
 	gem_tiled_swapping \
 	gem_tiled_wb \
+	gem_tiled_fence_overflow \
 	gem_tiling_max_stride \
 	gem_unfence_active_buffers \
 	gem_unref_active_buffers \
tests/gem_tiled_fence_overflow.c new file +32 -0
new file mode 100644
index 0000000..36482f7
@@ -0,0 +1,134 @@
+/*
+ * Copyright © 2014 Green Hills Software
+ * Copyright © 2009,2011,2014 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Bob Paauwe <[email protected]>
+ *    Dan Hettena <[email protected]>
+ *
+ */
+
+/** @file gem_tiled_fence_overflow.c
+ *
+ * This test tiled fenced regions to verify that they don't overflow

tests/gem_tiled_fence_overflow.c line 42

Quoted 10 lines
tests/gem_tiled_fence_overflow.c new file +10 -0
+ * into a flollowing allocation.  This can happen if the tiled region
+ * is less than the size of the object and the fence includes the
+ * "extra" bytes available beyond the tiled region.
+ *
+ * We check this by creating a tiled object followed by a linear object.
+ * The linear object if filled with 0x00 and then the tiled object is
+ * filled with 0xff.  If any of the bytes in the linear object are
+ * changed to 0xff, the fenced region is greater than than the tiled
+ * region, thus allowing us to write beyond the tiled buffer's allocation.
+ */

The newfangled way to describe tests is with IGT_TEST_DESCRIPTION. This gets magically pulled into the documentation we generate since recently for tests, see e.g.

http://people.freedesktop.org/~danvet/igt/igt-gem-tests.html

Quoted 33 lines
tests/gem_tiled_fence_overflow.c new file +33 -0
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+
+#include <drm.h>
+
+#include "ioctl_wrappers.h"
+#include "drmtest.h"
+#include "intel_bufmgr.h"
+#include "intel_batchbuffer.h"
+#include "intel_io.h"
+#include "intel_chipset.h"
+#include "igt_aux.h"
+
+static drm_intel_bufmgr *bufmgr;
+static int width = 480, height = 1088;
+
+igt_simple_main
+{
+	drm_intel_bo *bo_tiled;
+	drm_intel_bo *bo_linear;
+	int fd, cpp = 4;
+	int failed = 0;
+	uint32_t tiled_mode = I915_TILING_Y;
+	unsigned long pitch;
+
+	igt_skip_on_simulation();

tests/gem_tiled_fence_overflow.c line 85

Quoted 10 lines
tests/gem_tiled_fence_overflow.c new file +10 -0
+
+	fd = drm_open_any();
+
+
+	bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
+
+	bo_tiled = drm_intel_bo_alloc_tiled(bufmgr, "bo_tiled",
+										width, height, cpp, &tiled_mode,
+										&pitch, BO_ALLOC_FOR_RENDER);
+

Alignment gone wrong?

tests/gem_tiled_fence_overflow.c line 89

Quoted 4 lines
tests/gem_tiled_fence_overflow.c new file +4 -0
+	igt_assert(tiled_mode == I915_TILING_Y);
+
+	if (drm_intel_gem_bo_map_gtt(bo_tiled) != 0)
+		igt_assert(false);

Just push the condition into the igt_assert, if it fails the output will be much more information than "Condition failed: false". Same for the ones below.

tests/gem_tiled_fence_overflow.c line 91

Quoted 2 lines
tests/gem_tiled_fence_overflow.c new file +2 -0
+	igt_info("Y-tiled buffer %d x %d cpp %d stride %ld size 0x%lx\n",
+			 width, height, cpp, pitch, bo_tiled->size);

Codingstyle from i915 is to aling continuations with the opening ( Yeah, I'm nitpicking a bit ;-)

Quoted 7 lines
tests/gem_tiled_fence_overflow.c new file +7 -0
+
+	bo_linear = drm_intel_bo_alloc(bufmgr, "bo_linear", 0x1000, 4096);
+
+	if (drm_intel_gem_bo_map_gtt(bo_linear) != 0)
+		igt_assert(false);
+	igt_info("linear buffer size 0x%lx\n", bo_linear->size);
+

tests/gem_tiled_fence_overflow.c line 108

Quoted 10 lines
tests/gem_tiled_fence_overflow.c new file +10 -0
+
+	/*
+	 * Force the two buffers into the GTT such that the tiled
+	 * buffer is first, followed by the linear buffer.
+	 */
+	*(volatile char *)bo_tiled->virtual;
+	*(volatile char *)bo_linear->virtual;
+
+	/* Clear the linear buffer to all 0's */
+	memset(bo_linear->virtual, 0, bo_linear->size);

All buffers are cleared to 0 at alloc time (well if they're not cached, which isn't possible here).

tests/gem_tiled_fence_overflow.c line 116

Quoted 8 lines
tests/gem_tiled_fence_overflow.c new file +8 -0
+
+	/* Set the tiled buffer to all 0xff's */
+	memset(bo_tiled->virtual, 0xff, bo_tiled->size);
+	memset(bo_tiled->virtual, 0xdd, pitch * height);
+
+	/* Verify linear buffer is still all 0's by looking for a 0xff */
+	if (memchr(bo_linear->virtual, 0xff, bo_linear->size) != NULL)
+		failed = 1;

Imo just igt_assert here and reduce all the control flow.

Quoted 7 lines
tests/gem_tiled_fence_overflow.c new file +7 -0
+
+
+	/* Clean up */
+	drm_intel_bo_unreference(bo_linear);
+	drm_intel_gem_bo_unmap_gtt(bo_linear);
+	drm_intel_bo_unreference(bo_tiled);
+	drm_intel_gem_bo_unmap_gtt(bo_tiled);

tests/gem_tiled_fence_overflow.c line 133

Quoted 10 lines
tests/gem_tiled_fence_overflow.c new file +10 -0
+	drm_intel_bufmgr_destroy(bufmgr);
+
+	close(fd);
+
+	if (failed) {
+		igt_info("Test failed\n");
+		igt_fail(1);
+	}
+
+	igt_info("Test passed\n");

If you want neat output imo better done in the library. We already do it for subtests, for simple tests thus far the testrunner results where good enough. But certainly can be patched up.

Quoted 9 lines
tests/gem_tiled_fence_overflow.c new file +1 -0
+}
Signature · 7 lines
2.1.0


_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#2 lore raw
Quoted 93 lines · On Thu, 18 Dec 2014 21:31:43 +0100 Daniel Vetter <[email protected]> wrote:
Quoted 13 lines · Bob Paauwe

When a tiled bo is allocated such that the actual size of the bo is larger than the region covered by the tiles. For example allocating a Y-tiled bo that is 1920 x 1088 (15 x 34 tiles) results in a bo that is 0x200000 bytes instead of the 0x1FE000 bytes covered by the tiles. The fence needs to cover only the actual tiled region, otherwise writes beyond the tiled region may get converted to an address beyond the actual bo boundry.

This will test for that case by creating a tiled bo and a linear bo.
The linear bo is mapped directly after the tiled bo. The linear bo is filed with a specific value (0x00)
The tiled bo is filled with a different value (0xff)

Quoted 4 lines

If any bytes in the linear bo get written with 0xff, then the fence allowed writing beyond the tiled bo boundry.

Oh dear this is scary. Bunch of comments below.
-Daniel

Quoted 56 lines
---
 tests/Makefile.sources           |   1 +
 tests/gem_tiled_fence_overflow.c | 134 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 135 insertions(+)
 create mode 100644 tests/gem_tiled_fence_overflow.c
tests/Makefile.sources +1 -0
index d15a68b..c644fd3 100644
@@ -136,6 +136,7 @@ TESTS_progs = \
 	gem_tiled_pread_pwrite \
 	gem_tiled_swapping \
 	gem_tiled_wb \
+	gem_tiled_fence_overflow \
 	gem_tiling_max_stride \
 	gem_unfence_active_buffers \
 	gem_unref_active_buffers \
tests/gem_tiled_fence_overflow.c new file +32 -0
new file mode 100644
index 0000000..36482f7
@@ -0,0 +1,134 @@
+/*
+ * Copyright © 2014 Green Hills Software
+ * Copyright © 2009,2011,2014 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Bob Paauwe <[email protected]>
+ *    Dan Hettena <[email protected]>
+ *
+ */
+
+/** @file gem_tiled_fence_overflow.c
+ *
+ * This test tiled fenced regions to verify that they don't overflow

tests/gem_tiled_fence_overflow.c line 42

Quoted 10 lines
tests/gem_tiled_fence_overflow.c new file +10 -0
+ * into a flollowing allocation.  This can happen if the tiled region
+ * is less than the size of the object and the fence includes the
+ * "extra" bytes available beyond the tiled region.
+ *
+ * We check this by creating a tiled object followed by a linear object.
+ * The linear object if filled with 0x00 and then the tiled object is
+ * filled with 0xff.  If any of the bytes in the linear object are
+ * changed to 0xff, the fenced region is greater than than the tiled
+ * region, thus allowing us to write beyond the tiled buffer's allocation.
+ */

The newfangled way to describe tests is with IGT_TEST_DESCRIPTION. This gets magically pulled into the documentation we generate since recently for tests, see e.g.

Quoted 1 line

http://people.freedesktop.org/~danvet/igt/igt-gem-tests.html

Ok, the one test I uses as reference didn't have this. Added in v2.

Quoted 74 lines
Quoted 34 lines
tests/gem_tiled_fence_overflow.c new file +33 -0
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+
+#include <drm.h>
+
+#include "ioctl_wrappers.h"
+#include "drmtest.h"
+#include "intel_bufmgr.h"
+#include "intel_batchbuffer.h"
+#include "intel_io.h"
+#include "intel_chipset.h"
+#include "igt_aux.h"
+
+static drm_intel_bufmgr *bufmgr;
+static int width = 480, height = 1088;
+
+igt_simple_main
+{
+	drm_intel_bo *bo_tiled;
+	drm_intel_bo *bo_linear;
+	int fd, cpp = 4;
+	int failed = 0;
+	uint32_t tiled_mode = I915_TILING_Y;
+	unsigned long pitch;
+
+	igt_skip_on_simulation();

tests/gem_tiled_fence_overflow.c line 85

Quoted 10 lines
tests/gem_tiled_fence_overflow.c new file +10 -0
+
+	fd = drm_open_any();
+
+
+	bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
+
+	bo_tiled = drm_intel_bo_alloc_tiled(bufmgr, "bo_tiled",
+										width, height, cpp, &tiled_mode,
+										&pitch, BO_ALLOC_FOR_RENDER);
+

Alignment gone wrong?

tests/gem_tiled_fence_overflow.c line 89

Quoted 4 lines
tests/gem_tiled_fence_overflow.c new file +4 -0
+	igt_assert(tiled_mode == I915_TILING_Y);
+
+	if (drm_intel_gem_bo_map_gtt(bo_tiled) != 0)
+		igt_assert(false);

Just push the condition into the igt_assert, if it fails the output will be much more information than "Condition failed: false". Same for the ones below.

tests/gem_tiled_fence_overflow.c line 91

Quoted 2 lines
tests/gem_tiled_fence_overflow.c new file +2 -0
+	igt_info("Y-tiled buffer %d x %d cpp %d stride %ld size 0x%lx\n",
+			 width, height, cpp, pitch, bo_tiled->size);

Codingstyle from i915 is to aling continuations with the opening ( Yeah, I'm nitpicking a bit ;-)

Quoted 12 lines
tests/gem_tiled_fence_overflow.c new file +12 -0
+
+	bo_linear = drm_intel_bo_alloc(bufmgr, "bo_linear", 0x1000, 4096);
+
+	if (drm_intel_gem_bo_map_gtt(bo_linear) != 0)
+		igt_assert(false);
+	igt_info("linear buffer size 0x%lx\n", bo_linear->size);
+
+
+	/*
+	 * Force the two buffers into the GTT such that the tiled
+	 * buffer is first, followed by the linear buffer.
+	 */
Quoted 8 lines

tests/gem_tiled_fence_overflow.c line 108

Quoted 5 lines
tests/gem_tiled_fence_overflow.c new file +5 -0
+	*(volatile char *)bo_tiled->virtual;
+	*(volatile char *)bo_linear->virtual;
+
+	/* Clear the linear buffer to all 0's */
+	memset(bo_linear->virtual, 0, bo_linear->size);

All buffers are cleared to 0 at alloc time (well if they're not cached, which isn't possible here).

Yeah, I guess it's not necessary and may using the word "Clear" in the comment isn't quite right. The value set could be anything but having it cleared is convenient. I'll drop this and improve the comment below to reflect that the linear buffer is cleared by default.

Quoted 11 lines

tests/gem_tiled_fence_overflow.c line 116

Quoted 9 lines
tests/gem_tiled_fence_overflow.c new file +8 -0
+
+	/* Set the tiled buffer to all 0xff's */
+	memset(bo_tiled->virtual, 0xff, bo_tiled->size);
+	memset(bo_tiled->virtual, 0xdd, pitch * height);
+
+	/* Verify linear buffer is still all 0's by looking for a 0xff */
+	if (memchr(bo_linear->virtual, 0xff, bo_linear->size) != NULL)
+		failed = 1;

Imo just igt_assert here and reduce all the control flow.

So it's ok to skip all the unref / unmap when the test fails?

Quoted 13 lines
Quoted 13 lines
tests/gem_tiled_fence_overflow.c new file +13 -0
+
+
+	/* Clean up */
+	drm_intel_bo_unreference(bo_linear);
+	drm_intel_gem_bo_unmap_gtt(bo_linear);
+	drm_intel_bo_unreference(bo_tiled);
+	drm_intel_gem_bo_unmap_gtt(bo_tiled);
+	drm_intel_bufmgr_destroy(bufmgr);
+
+	close(fd);
+
+	if (failed) {
+		igt_info("Test failed\n");
Quoted 20 lines

tests/gem_tiled_fence_overflow.c line 133

Quoted 4 lines
tests/gem_tiled_fence_overflow.c new file +4 -0
+		igt_fail(1);
+	}
+
+	igt_info("Test passed\n");

If you want neat output imo better done in the library. We already do it for subtests, for simple tests thus far the testrunner results where good enough. But certainly can be patched up.

Quoted 9 lines
tests/gem_tiled_fence_overflow.c new file +1 -0
+}
Signature · 7 lines
2.1.0


_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw
Quoted 15 lines · Bob Paauwe
Quoted 11 lines · On Thu, 18 Dec 2014 21:31:43 +0100 Daniel Vetter <[email protected]> wrote:

tests/gem_tiled_fence_overflow.c line 116

Quoted 8 lines · Bob Paauwe
tests/gem_tiled_fence_overflow.c new file +8 -0
+
+	/* Set the tiled buffer to all 0xff's */
+	memset(bo_tiled->virtual, 0xff, bo_tiled->size);
+	memset(bo_tiled->virtual, 0xdd, pitch * height);
+
+	/* Verify linear buffer is still all 0's by looking for a 0xff */
+	if (memchr(bo_linear->virtual, 0xff, bo_linear->size) != NULL)
+		failed = 1;

Imo just igt_assert here and reduce all the control flow.

Quoted 1 line

So it's ok to skip all the unref / unmap when the test fails?

Totally. The kernel will clean up the mess for you, and being able to do that is why we run each test as its own binary. It also helps a lot in streamlining the testlogic by removing and control-flow which isn't part of the test itself.
-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx