[PATCH 30/79] drm/i915: Detect impossible GTT insertion

Chris Wilson chris at chris-wilson.co.uk
Sun Jan 1 18:50:50 UTC 2017


Check the size against the start, end, alignment restrictions before
searching for a suitable location for the VMA inside the GTT.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 2912969ac079..6b9f05bf64ea 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -23,10 +23,13 @@
  *
  */
 
+#include <linux/log2.h>
 #include <linux/seq_file.h>
 #include <linux/stop_machine.h>
+
 #include <drm/drmP.h>
 #include <drm/i915_drm.h>
+
 #include "i915_drv.h"
 #include "i915_vgpu.h"
 #include "i915_trace.h"
@@ -3564,6 +3567,15 @@ int i915_gem_gtt_insert(struct i915_address_space *vm,
 	int err;
 
 	lockdep_assert_held(&vm->i915->drm.struct_mutex);
+	GEM_BUG_ON(!size);
+	GEM_BUG_ON(alignment && !is_power_of_2(alignment));
+	GEM_BUG_ON(start >= end);
+
+	if (unlikely(range_overflows(start, size, end)))
+		return -ENOSPC;
+
+	if (unlikely(round_up(start, alignment) > round_down(end - size, alignment)))
+		return -ENOSPC;
 
 	mode = DRM_MM_INSERT_BEST;
 	if (flags & PIN_HIGH)
-- 
2.11.0



More information about the Intel-gfx-trybot mailing list