Skip to contentSkip to conversation

drm/i915: fix tiling limits for i915 class hw

PATCH In review Daniel Vetter 3 participants 5 messages Apr 15, 2010 – Apr 19, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915: fix tiling limits for i915 class hw

Current code is definitely crap: Largest pitch allowed spills into the TILING_Y bit of the fence registers ... :(

I've rewritten the limits check under the assumption that 3rd gen hw has a 3d pitch limit of 8kb (like 2nd gen). This is supported by an otherwise totally misleading XXX comment.

This bug mostly resulted in tiling-corrupted pixmaps because the kernel allowed too wide buffers to be tiled. Bug brought to the light by the xf86-video-intel 2.11 release because that unconditionally enabled tiling for pixmaps, relying on the kernel to check things. Tiling for the framebuffer was not affected because the ddx does some additional checks there ensure the buffer is within hw-limits.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=27449

---
 drivers/gpu/drm/i915/i915_gem_tiling.c |   15 ++++++++++-----
 drivers/gpu/drm/i915/i915_reg.h        |    2 +-
 2 files changed, 11 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/i915_gem_tiling.c +10 -5
index 449157f..b0c9a79 100644
@@ -205,11 +205,16 @@ i915_tiling_ok(struct drm_device *dev, int stride, int size, int tiling_mode)
 	} else if (IS_I9XX(dev)) {
 		uint32_t pitch_val = ffs(stride / tile_width) - 1;
 
-		/* XXX: For Y tiling, FENCE_MAX_PITCH_VAL is actually 6 (8KB)
-		 * instead of 4 (2KB) on 945s.
-		 */
-		if (pitch_val > I915_FENCE_MAX_PITCH_VAL ||
-		    size > (I830_FENCE_MAX_SIZE_VAL << 20))
+		if (size > I830_FENCE_MAX_SIZE_VAL << 20)
+			return false;
+
+		/* 128 byte wide tiles use the old i830 limit to again
+		 * allow 8kb pitches */
+		if (tiling_mode == I915_TILING_Y
+				&& HAS_128_BYTE_Y_TILING(dev)) {
+			if (pitch_val > I830_FENCE_MAX_PITCH_VAL)
+				return false;
+		} else if (pitch_val > I915_FENCE_MAX_PITCH_VAL)
 			return false;
 	} else {
 		uint32_t pitch_val = ffs(stride / tile_width) - 1;
drivers/gpu/drm/i915/i915_reg.h +1 -1
index cbbf59f..773c1ad 100644
@@ -241,7 +241,7 @@
 #define   I830_FENCE_SIZE_BITS(size)	((ffs((size) >> 19) - 1) << 8)
 #define   I830_FENCE_PITCH_SHIFT	4
 #define   I830_FENCE_REG_VALID		(1<<0)
-#define   I915_FENCE_MAX_PITCH_VAL	0x10
+#define   I915_FENCE_MAX_PITCH_VAL	4
 #define   I830_FENCE_MAX_PITCH_VAL	6
 #define   I830_FENCE_MAX_SIZE_VAL	(1<<8)
 
Signature · 1 line
1.6.6.1
#1 lore raw
Quoted 6 lines · Daniel Vetter

Current code is definitely crap: Largest pitch allowed spills into the TILING_Y bit of the fence registers ... :(

I've rewritten the limits check under the assumption that 3rd gen hw has a 3d pitch limit of 8kb (like 2nd gen). This is supported by an otherwise totally misleading XXX comment.

Good catch Daniel! Hopefully we must be soon running out of tiling bugs.

It does - the fence pitch limit is 8KiB for both 512- and 128-wide tiles. In the 128 byte case the max pitch value is 64, and correspondingly the max pitch value is 16 for 512 byte wide tiles.
-ickle

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#2 lore raw

PATCH 1/1 drm/i915: fix tiling limits for i915 class hw v2

Current code is definitely crap: Largest pitch allowed spills into the TILING_Y bit of the fence registers ... :(

I've rewritten the limits check under the assumption that 3rd gen hw has a 3d pitch limit of 8kb (like 2nd gen). This is supported by an otherwise totally misleading XXX comment.

This bug mostly resulted in tiling-corrupted pixmaps because the kernel allowed too wide buffers to be tiled. Bug brought to the light by the xf86-video-intel 2.11 release because that unconditionally enabled tiling for pixmaps, relying on the kernel to check things. Tiling for the framebuffer was not affected because the ddx does some additional checks there ensure the buffer is within hw-limits.

v2: Instead of computing the value that would be written into the hw fence registers and then checking the limits simply check whether the stride is above the 8kb limit. To better document the hw, add some WARN_ONs in i915_write_fence_reg like I've done for the i830 case (using the right limits).

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=27449

---
 drivers/gpu/drm/i915/i915_gem.c        |    6 ++++++
 drivers/gpu/drm/i915/i915_gem_tiling.c |   21 ++++++++-------------
 drivers/gpu/drm/i915/i915_reg.h        |    2 +-
 3 files changed, 15 insertions(+), 14 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +6 -0
index 6e71b5b..f302910 100644
@@ -2362,6 +2362,12 @@ static void i915_write_fence_reg(struct drm_i915_fence_reg *reg)
 	pitch_val = obj_priv->stride / tile_width;
 	pitch_val = ffs(pitch_val) - 1;
 
+	if (obj_priv->tiling_mode == I915_TILING_Y &&
+	    HAS_128_BYTE_Y_TILING(dev))
+		WARN_ON(pitch_val > I830_FENCE_MAX_PITCH_VAL);
+	else
+		WARN_ON(pitch_val > I915_FENCE_MAX_PITCH_VAL);
+
 	val = obj_priv->gtt_offset;
 	if (obj_priv->tiling_mode == I915_TILING_Y)
 		val |= 1 << I830_FENCE_TILING_Y_SHIFT;
drivers/gpu/drm/i915/i915_gem_tiling.c +8 -13
index 449157f..6393411 100644
@@ -202,21 +202,16 @@ i915_tiling_ok(struct drm_device *dev, int stride, int size, int tiling_mode)
 		 * reg, so dont bother to check the size */
 		if (stride / 128 > I965_FENCE_MAX_PITCH_VAL)
 			return false;
-	} else if (IS_I9XX(dev)) {
-		uint32_t pitch_val = ffs(stride / tile_width) - 1;
-
-		/* XXX: For Y tiling, FENCE_MAX_PITCH_VAL is actually 6 (8KB)
-		 * instead of 4 (2KB) on 945s.
-		 */
-		if (pitch_val > I915_FENCE_MAX_PITCH_VAL ||
-		    size > (I830_FENCE_MAX_SIZE_VAL << 20))
+	} else if (IS_GEN3(dev) || IS_GEN2(dev)) {
+		if (stride > 8192)
 			return false;
-	} else {
-		uint32_t pitch_val = ffs(stride / tile_width) - 1;
 
-		if (pitch_val > I830_FENCE_MAX_PITCH_VAL ||
-		    size > (I830_FENCE_MAX_SIZE_VAL << 19))
-			return false;
+		if (IS_GEN3(dev))
+			if (size > I830_FENCE_MAX_SIZE_VAL << 20)
+				return false;
+		else
+			if (size > I830_FENCE_MAX_SIZE_VAL << 19)
+				return false;
 	}
 
 	/* 965+ just needs multiples of tile width */
drivers/gpu/drm/i915/i915_reg.h +1 -1
index cbbf59f..773c1ad 100644
@@ -241,7 +241,7 @@
 #define   I830_FENCE_SIZE_BITS(size)	((ffs((size) >> 19) - 1) << 8)
 #define   I830_FENCE_PITCH_SHIFT	4
 #define   I830_FENCE_REG_VALID		(1<<0)
-#define   I915_FENCE_MAX_PITCH_VAL	0x10
+#define   I915_FENCE_MAX_PITCH_VAL	4
 #define   I830_FENCE_MAX_PITCH_VAL	6
 #define   I830_FENCE_MAX_SIZE_VAL	(1<<8)
 
Signature · 1 line
1.6.6.1
Applied
#3 lore raw

Re: [PATCH] drm/i915: fix tiling limits for i915 class hw v2

Quoted 20 lines · Daniel Vetter

Current code is definitely crap: Largest pitch allowed spills into the TILING_Y bit of the fence registers ... :(

I've rewritten the limits check under the assumption that 3rd gen hw has a 3d pitch limit of 8kb (like 2nd gen). This is supported by an otherwise totally misleading XXX comment.

This bug mostly resulted in tiling-corrupted pixmaps because the kernel allowed too wide buffers to be tiled. Bug brought to the light by the xf86-video-intel 2.11 release because that unconditionally enabled tiling for pixmaps, relying on the kernel to check things. Tiling for the framebuffer was not affected because the ddx does some additional checks there ensure the buffer is within hw-limits.

v2: Instead of computing the value that would be written into the hw fence registers and then checking the limits simply check whether the stride is above the 8kb limit. To better document the hw, add some WARN_ONs in i915_write_fence_reg like I've done for the i830 case (using the right limits).

Quoted 4 lines

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=27449

Ignore previous response. Here's exactly the patch I wanted.

Applied to for-linus.

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

#4 lore raw
In reply to Daniel Vetter
Quoted 14 lines · Daniel Vetter

Current code is definitely crap: Largest pitch allowed spills into the TILING_Y bit of the fence registers ... :(

I've rewritten the limits check under the assumption that 3rd gen hw has a 3d pitch limit of 8kb (like 2nd gen). This is supported by an otherwise totally misleading XXX comment.

This bug mostly resulted in tiling-corrupted pixmaps because the kernel allowed too wide buffers to be tiled. Bug brought to the light by the xf86-video-intel 2.11 release because that unconditionally enabled tiling for pixmaps, relying on the kernel to check things. Tiling for the framebuffer was not affected because the ddx does some additional checks there ensure the buffer is within hw-limits.

Quoted 4 lines

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=27449

Could we please just test against 8192 bytes intead of these obfuscated values?

Nice fix, though :)

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