[Intel-xe] [RFC 19/25] xe/drm: Include debug_metadata in usercoredump

Mika Kuoppala mika.kuoppala at linux.intel.com
Mon Nov 6 11:18:39 UTC 2023


From: Dominik Grzegorzek <dominik.grzegorzek at intel.com>

Include all created debug metadatas in usercoredump,
so the user can include i.e. elf binary to make the
meaningful in offline analysis.

Signed-off-by: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
---
 drivers/gpu/drm/xe/xe_usercoredump.c       | 54 +++++++++++++++++++++-
 drivers/gpu/drm/xe/xe_usercoredump_types.h |  9 ++++
 2 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/xe/xe_usercoredump.c b/drivers/gpu/drm/xe/xe_usercoredump.c
index 2d3fc5a24c48..95a893a31302 100644
--- a/drivers/gpu/drm/xe/xe_usercoredump.c
+++ b/drivers/gpu/drm/xe/xe_usercoredump.c
@@ -5,6 +5,9 @@
 
 #include "xe_usercoredump.h"
 
+#include <drm/xe_drm.h>
+
+#include "xe_debug_metadata.h"
 #include "xe_device_types.h"
 #include "xe_exec_queue_types.h"
 #include "xe_vm.h"
@@ -123,12 +126,19 @@ static void free_vma_snapshot(struct xe_vma_snapshot *s)
 void xe_user_state_snapshot_release(struct xe_user_state_snapshot *s)
 {
 	struct xe_vma_snapshot *v, *v_tmp;
+	struct xe_debug_metadata_snapshot *ms, *ms_tmp;
 
 	mutex_lock(&s->vmas.lock);
 	list_for_each_entry_safe(v, v_tmp, &s->vmas.list, link)
 		free_vma_snapshot(v);
 	mutex_unlock(&s->vmas.lock);
 
+	list_for_each_entry_safe(ms, ms_tmp, &s->metadata_list, link) {
+		list_del(&ms->link);
+		xe_debug_metadata_put(ms->mdata);
+		kfree(ms);
+	}
+
 	mutex_destroy(&s->vmas.lock);
 
 	put_pid(s->pid);
@@ -195,6 +205,28 @@ static void capture_vmas(struct xe_user_state_snapshot *s,
 	up_read(&vm->lock);
 }
 
+static void capture_metadata(struct xe_user_state_snapshot *s,
+			     struct xe_file *xef)
+{
+	struct xe_debug_metadata_snapshot *ms;
+	struct xe_debug_metadata *mdata;
+	unsigned long i;
+
+	INIT_LIST_HEAD(&s->metadata_list);
+	mutex_lock(&xef->debug_metadata.lock);
+	xa_for_each(&xef->debug_metadata.xa, i, mdata) {
+		ms = kzalloc(sizeof(*ms), GFP_KERNEL);
+		if (!ms)
+			break;
+
+		INIT_LIST_HEAD(&ms->link);
+		list_add(&ms->link, &s->metadata_list);
+		kref_get(&mdata->refcount);
+		ms->mdata = mdata;
+	}
+	mutex_unlock(&xef->debug_metadata.lock);
+}
+
 static void hexdump(struct drm_printer *m, const void *buf, size_t len)
 {
 	const size_t rowsize = 8 * sizeof(u32);
@@ -242,10 +274,23 @@ static void vma_snapshot_print(struct drm_printer *p,
 		hexdump(p, s->data, s->captured_bytes);
 }
 
+static const char *debug_metadata_type_to_str(const u64 type)
+{
+	switch (type) {
+	case DRM_XE_DEBUG_METADATA_ELF_BINARY:
+		return "elf binary";
+	case DRM_XE_DEBUG_METADATA_PROGRAM_MODULE:
+		return "program module";
+	}
+
+	return "unknown";
+}
+
 void xe_user_state_snapshot_print(struct xe_user_state_snapshot *s,
 				  struct drm_printer *p)
 {
 	struct xe_vma_snapshot *v;
+	struct xe_debug_metadata_snapshot *ms;
 
 	drm_printf(p, "PID: %d\n", pid_vnr(s->pid));
 	drm_printf(p, "Comm: %s\n", s->comm);
@@ -254,8 +299,13 @@ void xe_user_state_snapshot_print(struct xe_user_state_snapshot *s,
 	mutex_lock(&s->vmas.lock);
 	list_for_each_entry(v, &s->vmas.list, link)
 		vma_snapshot_print(p, v);
-
 	mutex_unlock(&s->vmas.lock);
+
+	list_for_each_entry(ms, &s->metadata_list, link) {
+		drm_printf(p, "Metadata id=%llu of type %s:\n",
+			   ms->mdata->id, debug_metadata_type_to_str(ms->mdata->type));
+		hexdump(p, ms->mdata->ptr, ms->mdata->len);
+	}
 }
 
 struct xe_user_state_snapshot *
@@ -287,6 +337,8 @@ xe_user_state_snapshot_capture(struct xe_exec_queue *q)
 	}
 
 	capture_vmas(s, q);
+	capture_metadata(s, xef);
+
 
 	return s;
 }
diff --git a/drivers/gpu/drm/xe/xe_usercoredump_types.h b/drivers/gpu/drm/xe/xe_usercoredump_types.h
index 635656e830cf..c69590affde7 100644
--- a/drivers/gpu/drm/xe/xe_usercoredump_types.h
+++ b/drivers/gpu/drm/xe/xe_usercoredump_types.h
@@ -13,6 +13,7 @@
 
 struct xe_device;
 struct xe_pidroot;
+struct xe_debug_metadata;
 
 struct xe_vma_snapshot {
 	struct list_head link;
@@ -28,6 +29,12 @@ struct xe_vma_snapshot {
 	void *data;
 };
 
+struct xe_debug_metadata_snapshot {
+	struct list_head link;
+
+	struct xe_debug_metadata *mdata;
+};
+
 /**
  * struct xe_user_state_snapshot - Crash snapshot
  *
@@ -43,6 +50,8 @@ struct xe_user_state_snapshot {
 		struct list_head list;
 	} vmas;
 
+	struct list_head metadata_list;
+
 	struct pid *pid;
 	u64 client_id; /* drm client id */
 	char comm[TASK_COMM_LEN];
-- 
2.34.1



More information about the Intel-xe mailing list