drm/i915/gt: Poison GTT scratch pages
diff mbox series

Message ID 20200122201822.889250-1-chris@chris-wilson.co.uk
State New
Headers show
Series
  • drm/i915/gt: Poison GTT scratch pages
Related show

Commit Message

Chris Wilson Jan. 22, 2020, 8:18 p.m. UTC
Using a clear page for scratch means that we have relatively benign
errors in case it is accidentally used, but that can be rather too
benign for debugging. If we poison the scratch, ideally it quickly
results in an obvious error.

Suggested-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
---
 drivers/gpu/drm/i915/gt/intel_gtt.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Patch
diff mbox series

diff --git a/drivers/gpu/drm/i915/gt/intel_gtt.c b/drivers/gpu/drm/i915/gt/intel_gtt.c
index 45d8e0019a8e..aaba06a774ab 100644
--- a/drivers/gpu/drm/i915/gt/intel_gtt.c
+++ b/drivers/gpu/drm/i915/gt/intel_gtt.c
@@ -331,6 +331,21 @@  int setup_scratch_page(struct i915_address_space *vm, gfp_t gfp)
 		if (unlikely(!page))
 			goto skip;
 
+		/*
+		 * Use a non-zero scratch page for debugging.
+		 *
+		 * We want a value that should be reasonably obvious
+		 * to spot in the error state, while also causing a GPU hang
+		 * if executed. We prefer using a clear page in production, so
+		 * should it ever be accidentally used, the effect should be
+		 * fairly benign.
+		 */
+		if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)) {
+			kunmap_atomic(memset64(kmap_atomic(page),
+					       POISON_FREE,
+					       size / sizeof(64)));
+		}
+
 		addr = dma_map_page_attrs(vm->dma,
 					  page, 0, size,
 					  PCI_DMA_BIDIRECTIONAL,