[PATCH 16/16] [DEBUG] dump_stack stolen resource freeing during test

Robert Beckett bob.beckett at collabora.com
Mon Jun 27 13:17:13 UTC 2022


---
 drivers/gpu/drm/i915/gt/selftest_reset.c   | 40 ++++++++++++++++++++--
 drivers/gpu/drm/i915/intel_memory_region.h |  1 +
 drivers/gpu/drm/i915/intel_region_ttm.c    |  2 ++
 3 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/gt/selftest_reset.c b/drivers/gpu/drm/i915/gt/selftest_reset.c
index ca130ccf63c7..273f34aa4a59 100644
--- a/drivers/gpu/drm/i915/gt/selftest_reset.c
+++ b/drivers/gpu/drm/i915/gt/selftest_reset.c
@@ -3,6 +3,7 @@
  * Copyright © 2018 Intel Corporation
  */
 
+#include "drm/ttm/ttm_resource.h"
 #include <linux/crc32.h>
 #include <linux/highmem.h>
 #include <linux/sched/mm.h>
@@ -58,6 +59,27 @@ static struct page ** alloc_orig(unsigned long num_pages)
 	return pages;
 }
 
+struct dbg_man_func {
+	const struct ttm_resource_manager_func *orig;
+	struct ttm_resource_manager_func dbg;
+};
+
+static void dbg_free(struct ttm_resource_manager *man, struct ttm_resource *res)
+{
+	struct dbg_man_func *dbg = container_of(man->func, struct dbg_man_func, dbg);
+
+	if (res->placement & (1 << 31)) {
+		dbg->orig->free(man, res);
+		return;
+	}
+	pr_info("BOB_DEBUG: %s(): man=%pS res={ start=0x%lx num_pages=0x%lx mem_type=0x%x placement=0x%x }\n",
+			__func__, man, res->start, res->num_pages, res->mem_type, res->placement);
+	pr_info("BOB_DEBUG: %s(): STACK:\n", __func__);
+	dump_stack();
+
+	dbg->orig->free(man, res);
+}
+
 static int
 __igt_reset_stolen(struct intel_gt *gt,
 		   intel_engine_mask_t mask,
@@ -76,6 +98,8 @@ __igt_reset_stolen(struct intel_gt *gt,
 	int err;
 	struct page **orig;
 	struct ttm_resource_dbg *orig_busy;
+	struct ttm_resource_manager *man;
+	struct dbg_man_func mf;
 
 	if (!drm_mm_node_allocated(&ggtt->error_capture))
 		return 0;
@@ -141,6 +165,13 @@ __igt_reset_stolen(struct intel_gt *gt,
 		i915_request_add(rq);
 	}
 
+	man = gt->i915->mm.stolen_region->region_private;
+	mf.orig = man->func;
+	mf.dbg.alloc = man->func->alloc;
+	mf.dbg.debug = man->func->debug;
+	mf.dbg.free = dbg_free;
+	man->func = &mf.dbg;
+
 	for (page = 0; page < num_pages; page++) {
 		dma_addr_t dma = (dma_addr_t)dsm->start + (page << PAGE_SHIFT);
 		void __iomem *s;
@@ -179,13 +210,14 @@ __igt_reset_stolen(struct intel_gt *gt,
 		intel_gt_reset(gt, mask, NULL);
 	} else {
 		for_each_engine(engine, gt, id) {
+			int ret;
 			if (!(mask & engine->mask))
 				continue;
-			err = intel_engine_reset(engine, NULL);
-			if (err)
+			ret = intel_engine_reset(engine, NULL);
+			if (ret)
 				pr_err("BOB_DEBUG: %s(): intel_engine_reset(%px(name=%.8s id=%d), NULL) returned %d. intel_engine_uses_guc(%px)=%d\n",
 						__func__, engine, engine->name,
-						engine->id, err, engine,
+						engine->id, ret, engine,
 						intel_engine_uses_guc(engine));
 		}
 	}
@@ -257,6 +289,8 @@ __igt_reset_stolen(struct intel_gt *gt,
 	mb();
 	ggtt->vm.clear_range(&ggtt->vm, ggtt->error_capture.start, PAGE_SIZE);
 
+	man->func = mf.orig;
+
 	if (count > 0) {
 		pr_info("%s reset clobbered %ld pages of stolen, last clobber at page %ld\n",
 			msg, count, max);
diff --git a/drivers/gpu/drm/i915/intel_memory_region.h b/drivers/gpu/drm/i915/intel_memory_region.h
index 048955b5429f..d278a0eb0f7c 100644
--- a/drivers/gpu/drm/i915/intel_memory_region.h
+++ b/drivers/gpu/drm/i915/intel_memory_region.h
@@ -93,6 +93,7 @@ struct intel_memory_region {
 	bool is_range_manager;
 
 	void *region_private;
+	void (*debug_free)(struct intel_memory_region *mem, struct ttm_resource *res);
 };
 
 struct intel_memory_region *
diff --git a/drivers/gpu/drm/i915/intel_region_ttm.c b/drivers/gpu/drm/i915/intel_region_ttm.c
index 0122eeaf0071..3dae5368f534 100644
--- a/drivers/gpu/drm/i915/intel_region_ttm.c
+++ b/drivers/gpu/drm/i915/intel_region_ttm.c
@@ -319,6 +319,8 @@ bool intel_region_ttm_range_busy_debug(struct intel_memory_region *mem,
 	dbg->busy = false;
 	dbg->err = 0;
 
+	dummy->placement |= 1 << 31; // dont debug this one
+
 	intel_region_ttm_resource_free(mem, dummy);
 	return false;
 }
-- 
2.25.1



More information about the Intel-gfx-trybot mailing list