Skip to contentSkip to conversation

drm/i915: introduce GEM_WARN_ON

PATCH In review Matthew Auld 3 participants 10 messages Dec 13, 2016 – Dec 16, 2016

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

PATCH 1/4 drm/i915: introduce GEM_WARN_ON

In a similar spirit to GEM_BUG_ON we now also have GEM_WARN_ON, with the simple goal of expressing warnings which are truly insane, and so are only really useful for CI where we have some abusive tests.

v2:
- use BUILD_BUG_ON_INVALID for !DEBUG_GEM
- clarify commit message

---
 drivers/gpu/drm/i915/i915_gem.h | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/i915/i915_gem.h +2 -0
index 8801a14a78a2..a585d47c420a 100644
@@ -27,8 +27,10 @@
 
 #ifdef CONFIG_DRM_I915_DEBUG_GEM
 #define GEM_BUG_ON(expr) BUG_ON(expr)
+#define GEM_WARN_ON(expr) WARN_ON(expr)
 #else
 #define GEM_BUG_ON(expr) BUILD_BUG_ON_INVALID(expr)
+#define GEM_WARN_ON(expr) (BUILD_BUG_ON_INVALID(expr), 0)
 #endif
 
 #define I915_NUM_ENGINES 5
Signature · 6 lines
2.9.3

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

PATCH 2/4 drm/i915: move vma sanity checking into i915_vma_bind

If we move the sanity checking from gen8_alloc_va_range_3lvl and gen6_alloc_va_range into i915_vma_bind, we will increase our coverage to now both callbacks. We also convert each WARN_ON over to a GEM_WARN_ON.

---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 12 ------------
 drivers/gpu/drm/i915/i915_vma.c     |  6 ++++++
 2 files changed, 6 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/i915_gem_gtt.c +0 -12
index ef00d36680c9..4f405b445b6c 100644
@@ -1303,15 +1303,6 @@ static int gen8_alloc_va_range_3lvl(struct i915_address_space *vm,
 	uint32_t pdpes = I915_PDPES_PER_PDP(dev_priv);
 	int ret;
 
-	/* Wrap is never okay since we can only represent 48b, and we don't
-	 * actually use the other side of the canonical address space.
-	 */
-	if (WARN_ON(start + length < start))
-		return -ENODEV;
-
-	if (WARN_ON(start + length > vm->total))
-		return -ENODEV;
-
 	ret = alloc_gen8_temp_bitmaps(&new_page_dirs, &new_page_tables, pdpes);
 	if (ret)
 		return ret;
@@ -1929,9 +1920,6 @@ static int gen6_alloc_va_range(struct i915_address_space *vm,
 	uint32_t pde;
 	int ret;
 
-	if (WARN_ON(start_in + length_in > ppgtt->base.total))
-		return -ENODEV;
-
 	start = start_save = start_in;
 	length = length_save = length_in;
 
drivers/gpu/drm/i915/i915_vma.c +6 -0
index 37c3eebe8316..9e121222c5eb 100644
@@ -176,6 +176,12 @@ int i915_vma_bind(struct i915_vma *vma, enum i915_cache_level cache_level,
 	if (bind_flags == 0)
 		return 0;
 
+	if (GEM_WARN_ON(vma->node.start + vma->node.size < vma->node.start))
+		return -ENODEV;
+
+	if (GEM_WARN_ON(vma->node.start + vma->node.size > vma->vm->total))
+		return -ENODEV;
+
 	if (vma_flags == 0 && vma->vm->allocate_va_range) {
 		trace_i915_va_alloc(vma);
 		ret = vma->vm->allocate_va_range(vma->vm,
Signature · 6 lines
2.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

PATCH 3/4 drm/i915: introduce range_overflows utility macros

In reply to Matthew Auld

In a number places we hand-roll the overflow sanity check for ranges, so roll that into single macro, conceived by Chris, along with its typed variant.

---
 drivers/gpu/drm/i915/i915_drv.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +12 -0
index 20bc04d5e617..47b5a9f1c9ed 100644
@@ -218,6 +218,18 @@ static inline const char *enableddisabled(bool v)
 	return v ? "enabled" : "disabled";
 }
 
+#define range_overflows(start, size, max) ({ \
+	typeof(start) start__ = (start); \
+	typeof(size) size__ = (size); \
+	typeof(max) max__ = (max); \
+	(void)(&start__ == &size__); \
+	(void)(&start__ == &max__); \
+	start > max || size > max - start; \
+})
+
+#define range_overflows_t(type, start, size, max) \
+	range_overflows(((type)start), ((type)size), ((type)max))
+
 enum pipe {
 	INVALID_PIPE = -1,
 	PIPE_A = 0,
Signature · 6 lines
2.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#5 lore raw

PATCH 4/4 drm/i915: convert to using range_overflows

In reply to Matthew Auld

Convert some of the obvious hand-rolled ranged overflow sanity checks to our shiny new range_overflows macro.

---
 drivers/gpu/drm/i915/i915_gem.c | 6 ++----
 drivers/gpu/drm/i915/i915_vma.c | 6 ++----
 2 files changed, 4 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +2 -4
index f86a71d9fe37..782be625d37d 100644
@@ -1140,8 +1140,7 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data,
 		return -ENOENT;
 
 	/* Bounds check source.  */
-	if (args->offset > obj->base.size ||
-	    args->size > obj->base.size - args->offset) {
+	if (range_overflows_t(u64, args->offset, args->size, obj->base.size)) {
 		ret = -EINVAL;
 		goto out;
 	}
@@ -1454,8 +1453,7 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
 		return -ENOENT;
 
 	/* Bounds check destination. */
-	if (args->offset > obj->base.size ||
-	    args->size > obj->base.size - args->offset) {
+	if (range_overflows_t(u64, args->offset, args->size, obj->base.size)) {
 		ret = -EINVAL;
 		goto err;
 	}
drivers/gpu/drm/i915/i915_vma.c +2 -4
index 9e121222c5eb..47599390dca7 100644
@@ -176,10 +176,8 @@ int i915_vma_bind(struct i915_vma *vma, enum i915_cache_level cache_level,
 	if (bind_flags == 0)
 		return 0;
 
-	if (GEM_WARN_ON(vma->node.start + vma->node.size < vma->node.start))
-		return -ENODEV;
-
-	if (GEM_WARN_ON(vma->node.start + vma->node.size > vma->vm->total))
+	if (GEM_WARN_ON(range_overflows(vma->node.start, vma->node.size,
+					vma->vm->total)))
 		return -ENODEV;
 
 	if (vma_flags == 0 && vma->vm->allocate_va_range) {
Signature · 6 lines
2.9.3

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw

✓ Fi.CI.BAT: success for series starting with [1/4] drm/i915: introduce GEM_WARN_ON

In reply to Matthew Auld
== Series Details ==

== Series Details ==

Series: series starting with [1/4] drm/i915: introduce GEM_WARN_ON
URL : https://patchwork.freedesktop.org/series/16758/
State : success

== Summary ==

Series 16758v1 Series without cover letter
https://patchwork.freedesktop.org/api/1.0/series/16758/revisions/1/mbox/

fi-bdw-5557u     total:247  pass:233  dwarn:0   dfail:0   fail:0   skip:14 
fi-bsw-n3050     total:247  pass:208  dwarn:0   dfail:0   fail:0   skip:39 
fi-bxt-t5700     total:247  pass:220  dwarn:0   dfail:0   fail:0   skip:27 
fi-byt-j1900     total:247  pass:220  dwarn:0   dfail:0   fail:0   skip:27 
fi-byt-n2820     total:247  pass:216  dwarn:0   dfail:0   fail:0   skip:31 
fi-hsw-4770      total:247  pass:228  dwarn:0   dfail:0   fail:0   skip:19 
fi-hsw-4770r     total:247  pass:228  dwarn:0   dfail:0   fail:0   skip:19 
fi-ilk-650       total:247  pass:195  dwarn:0   dfail:0   fail:0   skip:52 
fi-ivb-3520m     total:247  pass:226  dwarn:0   dfail:0   fail:0   skip:21 
fi-ivb-3770      total:247  pass:226  dwarn:0   dfail:0   fail:0   skip:21 
fi-kbl-7500u     total:247  pass:226  dwarn:0   dfail:0   fail:0   skip:21 
fi-skl-6260u     total:247  pass:234  dwarn:0   dfail:0   fail:0   skip:13 
fi-skl-6700hq    total:247  pass:227  dwarn:0   dfail:0   fail:0   skip:20 
fi-skl-6700k     total:247  pass:224  dwarn:3   dfail:0   fail:0   skip:20 
fi-skl-6770hq    total:247  pass:234  dwarn:0   dfail:0   fail:0   skip:13 
fi-snb-2520m     total:247  pass:216  dwarn:0   dfail:0   fail:0   skip:31 
fi-snb-2600      total:247  pass:215  dwarn:0   dfail:0   fail:0   skip:32 

57b72b4a6d7b787aedeb7b776ab35c3b2d7f58e9 drm-tip: 2016y-12m-13d-17h-59m-26s UTC integration manifest ec9dba0 drm/i915: convert to using range_overflows
2e82cdf drm/i915: introduce range_overflows utility macros
b2b8e00 drm/i915: move vma sanity checking into i915_vma_bind
16aef35 drm/i915: introduce GEM_WARN_ON

== Logs ==

For more details see: https://intel-gfx-ci.01.org/CI/Patchwork_3282/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#4 lore raw

Re: [PATCH 3/4] drm/i915: introduce range_overflows utility macros

In reply to Matthew Auld
Quoted 21 lines · Matthew Auld

In a number places we hand-roll the overflow sanity check for ranges, so roll that into single macro, conceived by Chris, along with its typed variant.

---
 drivers/gpu/drm/i915/i915_drv.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +1 -0
index 20bc04d5e617..47b5a9f1c9ed 100644
@@ -218,6 +218,18 @@ static inline const char *enableddisabled(bool v)
 	return v ? "enabled" : "disabled";
 }
 
+#define range_overflows(start, size, max) ({ \

drivers/gpu/drm/i915/i915_drv.h static inline const char *enableddisabled(bool v) · line 231

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +10 -0
+	typeof(start) start__ = (start); \
+	typeof(size) size__ = (size); \
+	typeof(max) max__ = (max); \
+	(void)(&start__ == &size__); \
+	(void)(&start__ == &max__); \
+	start > max || size > max - start; \
+})
+
+#define range_overflows_t(type, start, size, max) \
+	range_overflows(((type)start), ((type)size), ((type)max))

Hmm, should be (type)(start) etc. Yeah, this is slightly more obvious than min_t's method.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v1 4/4
#6 lore raw

Re: [PATCH 4/4] drm/i915: convert to using range_overflows

In reply to Matthew Auld
Quoted 7 lines · Matthew Auld

Convert some of the obvious hand-rolled ranged overflow sanity checks to our shiny new range_overflows macro.

-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v1 2/4
#2 lore raw

Re: [PATCH 2/4] drm/i915: move vma sanity checking into i915_vma_bind

In reply to Matthew Auld
Quoted 8 lines · Matthew Auld

If we move the sanity checking from gen8_alloc_va_range_3lvl and gen6_alloc_va_range into i915_vma_bind, we will increase our coverage to now both callbacks. We also convert each WARN_ON over to a GEM_WARN_ON.

-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v1 1/4
#9 lore raw
In reply to Matthew Auld
Quoted 4 lines · Matthew Auld

In a similar spirit to GEM_BUG_ON we now also have GEM_WARN_ON, with the simple goal of expressing warnings which are truly insane, and so are only really useful for CI where we have some abusive tests.

Quoted 8 lines

v2:
- use BUILD_BUG_ON_INVALID for !DEBUG_GEM
- clarify commit message

-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#8 lore raw

Re: ✓ Fi.CI.BAT: success for series starting with [1/4] drm/i915: introduce GEM_WARN_ON

In reply to Patchwork
Quoted 30 lines · Patchwork

== Series Details ==

Series: series starting with [1/4] drm/i915: introduce GEM_WARN_ON
URL : https://patchwork.freedesktop.org/series/16758/
State : success

== Summary ==

Series 16758v1 Series without cover letter
https://patchwork.freedesktop.org/api/1.0/series/16758/revisions/1/mbox/

fi-bdw-5557u     total:247  pass:233  dwarn:0   dfail:0   fail:0   skip:14 
fi-bsw-n3050     total:247  pass:208  dwarn:0   dfail:0   fail:0   skip:39 
fi-bxt-t5700     total:247  pass:220  dwarn:0   dfail:0   fail:0   skip:27 
fi-byt-j1900     total:247  pass:220  dwarn:0   dfail:0   fail:0   skip:27 
fi-byt-n2820     total:247  pass:216  dwarn:0   dfail:0   fail:0   skip:31 
fi-hsw-4770      total:247  pass:228  dwarn:0   dfail:0   fail:0   skip:19 
fi-hsw-4770r     total:247  pass:228  dwarn:0   dfail:0   fail:0   skip:19 
fi-ilk-650       total:247  pass:195  dwarn:0   dfail:0   fail:0   skip:52 
fi-ivb-3520m     total:247  pass:226  dwarn:0   dfail:0   fail:0   skip:21 
fi-ivb-3770      total:247  pass:226  dwarn:0   dfail:0   fail:0   skip:21 
fi-kbl-7500u     total:247  pass:226  dwarn:0   dfail:0   fail:0   skip:21 
fi-skl-6260u     total:247  pass:234  dwarn:0   dfail:0   fail:0   skip:13 
fi-skl-6700hq    total:247  pass:227  dwarn:0   dfail:0   fail:0   skip:20 
fi-skl-6700k     total:247  pass:224  dwarn:3   dfail:0   fail:0   skip:20 
fi-skl-6770hq    total:247  pass:234  dwarn:0   dfail:0   fail:0   skip:13 
fi-snb-2520m     total:247  pass:216  dwarn:0   dfail:0   fail:0   skip:31 
fi-snb-2600      total:247  pass:215  dwarn:0   dfail:0   fail:0   skip:32 
Quoted 5 lines

57b72b4a6d7b787aedeb7b776ab35c3b2d7f58e9 drm-tip: 2016y-12m-13d-17h-59m-26s UTC integration manifest ec9dba0 drm/i915: convert to using range_overflows
2e82cdf drm/i915: introduce range_overflows utility macros
b2b8e00 drm/i915: move vma sanity checking into i915_vma_bind
16aef35 drm/i915: introduce GEM_WARN_ON

And pushed. Thanks,
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx