public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Panthor BO tagging and GEMS debug display
@ 2025-03-16 21:51 Adrián Larumbe
  2025-03-16 21:51 ` [PATCH 1/4] drm/panthor: Introduce BO labeling Adrián Larumbe
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Adrián Larumbe @ 2025-03-16 21:51 UTC (permalink / raw)
  To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter
  Cc: kernel, Adrián Larumbe, dri-devel, linux-kernel

This patch series is aimed at providing UM with detailed memory profiling
information in debug builds. It is achieved through a device-wide list of
DRM GEM objects, and also implementing the ability to label BO's from UM
through a new IOCTL.

The new debugfs file shows a list of driver DRM GEM objects in tabular mode.
To visualise it, cat sudo cat /sys/kernel/debug/dri/*.gpu/gems.
To test this functionality from UM, please refer to this Mesa patch series:

https://gitlab.collabora.com/alarumbe/mesa/-/commits/bo-tagging-panthor-gl

Adrián Larumbe (4):
  drm/panthor: Introduce BO labeling
  drm/panthor: Add driver IOCTL for setting BO labels
  drm/panthor: show device-wide list of DRM GEM objects over DebugFS
  drm/panthor: Display heap chunk entries in DebugFS GEMS file

 drivers/gpu/drm/panthor/panthor_device.c |   5 +
 drivers/gpu/drm/panthor/panthor_device.h |   8 ++
 drivers/gpu/drm/panthor/panthor_drv.c    |  57 +++++++++++
 drivers/gpu/drm/panthor/panthor_gem.c    | 119 +++++++++++++++++++++++
 drivers/gpu/drm/panthor/panthor_gem.h    |  34 +++++++
 drivers/gpu/drm/panthor/panthor_heap.c   |  15 +++
 include/uapi/drm/panthor_drm.h           |  14 +++
 7 files changed, 252 insertions(+)

--
2.48.1

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 1/4] drm/panthor: Introduce BO labeling
  2025-03-16 21:51 [PATCH 0/4] Panthor BO tagging and GEMS debug display Adrián Larumbe
@ 2025-03-16 21:51 ` Adrián Larumbe
  2025-03-17  7:45   ` Boris Brezillon
  2025-03-16 21:51 ` [PATCH 2/4] drm/panthor: Add driver IOCTL for setting BO labels Adrián Larumbe
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 14+ messages in thread
From: Adrián Larumbe @ 2025-03-16 21:51 UTC (permalink / raw)
  To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter
  Cc: kernel, Adrián Larumbe, dri-devel, linux-kernel

Add a new character string Panthor BO field, and a function that allows
setting it from within the driver.

Driver takes care of freeing the string when it's replaced or no longer
needed at object destruction time, but allocating it is the responsibility
of callers.

Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
---
 drivers/gpu/drm/panthor/panthor_gem.c | 18 ++++++++++++++++++
 drivers/gpu/drm/panthor/panthor_gem.h | 12 ++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
index 8244a4e6c2a2..3c58bb2965ea 100644
--- a/drivers/gpu/drm/panthor/panthor_gem.c
+++ b/drivers/gpu/drm/panthor/panthor_gem.c
@@ -18,6 +18,9 @@ static void panthor_gem_free_object(struct drm_gem_object *obj)
 	struct panthor_gem_object *bo = to_panthor_bo(obj);
 	struct drm_gem_object *vm_root_gem = bo->exclusive_vm_root_gem;
 
+	kfree(bo->label);
+	mutex_destroy(&bo->label_lock);
+
 	drm_gem_free_mmap_offset(&bo->base.base);
 	mutex_destroy(&bo->gpuva_list_lock);
 	drm_gem_shmem_free(&bo->base);
@@ -196,6 +199,7 @@ struct drm_gem_object *panthor_gem_create_object(struct drm_device *ddev, size_t
 	obj->base.map_wc = !ptdev->coherent;
 	mutex_init(&obj->gpuva_list_lock);
 	drm_gem_gpuva_set_lock(&obj->base.base, &obj->gpuva_list_lock);
+	mutex_init(&obj->label_lock);
 
 	return &obj->base.base;
 }
@@ -247,3 +251,17 @@ panthor_gem_create_with_handle(struct drm_file *file,
 
 	return ret;
 }
+
+void
+panthor_gem_label_bo(struct drm_gem_object *obj, const char *label)
+{
+	struct panthor_gem_object *bo = to_panthor_bo(obj);
+	const char *old_label;
+
+	mutex_lock(&bo->label_lock);
+	old_label = bo->label;
+	bo->label = label;
+	mutex_unlock(&bo->label_lock);
+
+	kfree(old_label);
+}
diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/panthor/panthor_gem.h
index 5749ef2ebe03..da9268d24566 100644
--- a/drivers/gpu/drm/panthor/panthor_gem.h
+++ b/drivers/gpu/drm/panthor/panthor_gem.h
@@ -46,6 +46,15 @@ struct panthor_gem_object {
 
 	/** @flags: Combination of drm_panthor_bo_flags flags. */
 	u32 flags;
+
+	/**
+	 * @label: Pointer to NULL-terminated string, can be assigned within the
+	 * driver itself or through a specific IOCTL.
+	 */
+	const char *label;
+
+	/** @label_lock: Lock that protects access to the @label field. */
+	struct mutex label_lock;
 };
 
 /**
@@ -91,6 +100,9 @@ panthor_gem_create_with_handle(struct drm_file *file,
 			       struct panthor_vm *exclusive_vm,
 			       u64 *size, u32 flags, uint32_t *handle);
 
+void
+panthor_gem_label_bo(struct drm_gem_object *obj, const char *label);
+
 static inline u64
 panthor_kernel_bo_gpuva(struct panthor_kernel_bo *bo)
 {
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 2/4] drm/panthor: Add driver IOCTL for setting BO labels
  2025-03-16 21:51 [PATCH 0/4] Panthor BO tagging and GEMS debug display Adrián Larumbe
  2025-03-16 21:51 ` [PATCH 1/4] drm/panthor: Introduce BO labeling Adrián Larumbe
@ 2025-03-16 21:51 ` Adrián Larumbe
  2025-03-17  7:50   ` Boris Brezillon
  2025-03-17  7:54   ` Boris Brezillon
  2025-03-16 21:51 ` [PATCH 3/4] drm/panthor: show device-wide list of DRM GEM objects over DebugFS Adrián Larumbe
  2025-03-16 21:51 ` [PATCH 4/4] drm/panthor: Display heap chunk entries in DebugFS GEMS file Adrián Larumbe
  3 siblings, 2 replies; 14+ messages in thread
From: Adrián Larumbe @ 2025-03-16 21:51 UTC (permalink / raw)
  To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter
  Cc: kernel, Adrián Larumbe, dri-devel, linux-kernel

Allow UM to label a BO for which it possesses a DRM handle.

Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
---
 drivers/gpu/drm/panthor/panthor_drv.c | 31 +++++++++++++++++++++++++++
 include/uapi/drm/panthor_drm.h        | 14 ++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
index 310bb44abe1a..f41b8946258f 100644
--- a/drivers/gpu/drm/panthor/panthor_drv.c
+++ b/drivers/gpu/drm/panthor/panthor_drv.c
@@ -1330,6 +1330,35 @@ static int panthor_ioctl_vm_get_state(struct drm_device *ddev, void *data,
 	return 0;
 }
 
+static int panthor_ioctl_label_bo(struct drm_device *ddev, void *data,
+				  struct drm_file *file)
+{
+	struct drm_panthor_label_bo *args = data;
+	struct drm_gem_object *obj;
+	const char *label;
+	int ret = 0;
+
+	obj = drm_gem_object_lookup(file, args->handle);
+	if (!obj)
+		return -ENOENT;
+
+	if (args->len && args->label) {
+		label = strndup_user(u64_to_user_ptr(args->label), args->len + 1);
+		if (IS_ERR(label)) {
+			ret = PTR_ERR(label);
+			goto err_label;
+		}
+	} else
+		label = NULL;
+
+	panthor_gem_label_bo(obj, label);
+
+err_label:
+	drm_gem_object_put(obj);
+
+	return ret;
+}
+
 static int
 panthor_open(struct drm_device *ddev, struct drm_file *file)
 {
@@ -1399,6 +1428,7 @@ static const struct drm_ioctl_desc panthor_drm_driver_ioctls[] = {
 	PANTHOR_IOCTL(TILER_HEAP_CREATE, tiler_heap_create, DRM_RENDER_ALLOW),
 	PANTHOR_IOCTL(TILER_HEAP_DESTROY, tiler_heap_destroy, DRM_RENDER_ALLOW),
 	PANTHOR_IOCTL(GROUP_SUBMIT, group_submit, DRM_RENDER_ALLOW),
+	PANTHOR_IOCTL(LABEL_BO, label_bo, DRM_RENDER_ALLOW),
 };
 
 static int panthor_mmap(struct file *filp, struct vm_area_struct *vma)
@@ -1508,6 +1538,7 @@ static void panthor_debugfs_init(struct drm_minor *minor)
  * - 1.2 - adds DEV_QUERY_GROUP_PRIORITIES_INFO query
  *       - adds PANTHOR_GROUP_PRIORITY_REALTIME priority
  * - 1.3 - adds DRM_PANTHOR_GROUP_STATE_INNOCENT flag
+ * - 1.4 - adds DRM_IOCTL_PANTHOR_LABEL_BO ioctl
  */
 static const struct drm_driver panthor_drm_driver = {
 	.driver_features = DRIVER_RENDER | DRIVER_GEM | DRIVER_SYNCOBJ |
diff --git a/include/uapi/drm/panthor_drm.h b/include/uapi/drm/panthor_drm.h
index 97e2c4510e69..1a7ed567d36a 100644
--- a/include/uapi/drm/panthor_drm.h
+++ b/include/uapi/drm/panthor_drm.h
@@ -127,6 +127,9 @@ enum drm_panthor_ioctl_id {
 
 	/** @DRM_PANTHOR_TILER_HEAP_DESTROY: Destroy a tiler heap. */
 	DRM_PANTHOR_TILER_HEAP_DESTROY,
+
+	/** @DRM_PANTHOR_LABEL_BO: Label a BO. */
+	DRM_PANTHOR_LABEL_BO,
 };
 
 /**
@@ -977,6 +980,15 @@ struct drm_panthor_tiler_heap_destroy {
 	__u32 pad;
 };
 
+/**
+ * struct drm_panthor_label_bo - Arguments passed to DRM_IOCTL_PANTHOR_LABEL_BO
+ */
+struct drm_panthor_label_bo {
+	__u32 handle;
+	__u32 len;
+	__u64 label;
+};
+
 /**
  * DRM_IOCTL_PANTHOR() - Build a Panthor IOCTL number
  * @__access: Access type. Must be R, W or RW.
@@ -1019,6 +1031,8 @@ enum {
 		DRM_IOCTL_PANTHOR(WR, TILER_HEAP_CREATE, tiler_heap_create),
 	DRM_IOCTL_PANTHOR_TILER_HEAP_DESTROY =
 		DRM_IOCTL_PANTHOR(WR, TILER_HEAP_DESTROY, tiler_heap_destroy),
+	DRM_IOCTL_PANTHOR_LABEL_BO =
+		DRM_IOCTL_PANTHOR(WR, LABEL_BO, label_bo),
 };
 
 #if defined(__cplusplus)
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 3/4] drm/panthor: show device-wide list of DRM GEM objects over DebugFS
  2025-03-16 21:51 [PATCH 0/4] Panthor BO tagging and GEMS debug display Adrián Larumbe
  2025-03-16 21:51 ` [PATCH 1/4] drm/panthor: Introduce BO labeling Adrián Larumbe
  2025-03-16 21:51 ` [PATCH 2/4] drm/panthor: Add driver IOCTL for setting BO labels Adrián Larumbe
@ 2025-03-16 21:51 ` Adrián Larumbe
  2025-03-17  8:26   ` Boris Brezillon
  2025-03-16 21:51 ` [PATCH 4/4] drm/panthor: Display heap chunk entries in DebugFS GEMS file Adrián Larumbe
  3 siblings, 1 reply; 14+ messages in thread
From: Adrián Larumbe @ 2025-03-16 21:51 UTC (permalink / raw)
  To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
	Sumit Semwal, Christian König
  Cc: kernel, Adrián Larumbe, dri-devel, linux-kernel, linux-media,
	linaro-mm-sig

Add a device DebugFS file that displays a complete list of all the DRM GEM
objects that are exposed to UM through a DRM handle.

Since leaking object identifiers that might belong to a different NS is
inadmissible, this functionality is only made available in debug builds
with DEBUGFS support enabled.

File format is that of a table, with each entry displaying a variety of
fields with information about each GEM object.

Each GEM object entry in the file displays the following information
fields: Client PID, BO's global name, reference count, BO virtual size, BO
resize size, VM address in its DRM-managed range, BO label and a flag
bitmask.

Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
---
 drivers/gpu/drm/panthor/panthor_device.c |   5 ++
 drivers/gpu/drm/panthor/panthor_device.h |   8 ++
 drivers/gpu/drm/panthor/panthor_drv.c    |  26 ++++++
 drivers/gpu/drm/panthor/panthor_gem.c    | 101 +++++++++++++++++++++++
 drivers/gpu/drm/panthor/panthor_gem.h    |  22 +++++
 5 files changed, 162 insertions(+)

diff --git a/drivers/gpu/drm/panthor/panthor_device.c b/drivers/gpu/drm/panthor/panthor_device.c
index a9da1d1eeb70..7df12eefc39f 100644
--- a/drivers/gpu/drm/panthor/panthor_device.c
+++ b/drivers/gpu/drm/panthor/panthor_device.c
@@ -263,6 +263,11 @@ int panthor_device_init(struct panthor_device *ptdev)
 	pm_runtime_set_autosuspend_delay(ptdev->base.dev, 50);
 	pm_runtime_use_autosuspend(ptdev->base.dev);
 
+#ifdef CONFIG_DEBUG_FS
+	drmm_mutex_init(&ptdev->base, &ptdev->gems_lock);
+	INIT_LIST_HEAD(&ptdev->gems);
+#endif
+
 	ret = drm_dev_register(&ptdev->base, 0);
 	if (ret)
 		goto err_disable_autosuspend;
diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/panthor/panthor_device.h
index da6574021664..6c030978cdc3 100644
--- a/drivers/gpu/drm/panthor/panthor_device.h
+++ b/drivers/gpu/drm/panthor/panthor_device.h
@@ -205,6 +205,14 @@ struct panthor_device {
 
 	/** @fast_rate: Maximum device clock frequency. Set by DVFS */
 	unsigned long fast_rate;
+
+#ifdef CONFIG_DEBUG_FS
+	/** @gems_lock: Protects the device-wide list of GEM objects. */
+	struct mutex gems_lock;
+
+	/** @gems: Device-wide list of GEM objects owned by at least one file. */
+	struct list_head gems;
+#endif
 };
 
 struct panthor_gpu_usage {
diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
index f41b8946258f..6663eff44bdc 100644
--- a/drivers/gpu/drm/panthor/panthor_drv.c
+++ b/drivers/gpu/drm/panthor/panthor_drv.c
@@ -1525,9 +1525,35 @@ static const struct file_operations panthor_drm_driver_fops = {
 };
 
 #ifdef CONFIG_DEBUG_FS
+static int panthor_gems_show(struct seq_file *m, void *data)
+{
+	struct drm_info_node *node = m->private;
+	struct drm_device *dev = node->minor->dev;
+	struct panthor_device *ptdev = container_of(dev, struct panthor_device, base);
+
+	panthor_gem_print_objects(ptdev, m);
+
+	return 0;
+}
+
+
+static struct drm_info_list panthor_debugfs_list[] = {
+	{"gems", panthor_gems_show, 0, NULL},
+};
+
+static int panthor_gems_debugfs_init(struct drm_minor *minor)
+{
+	drm_debugfs_create_files(panthor_debugfs_list,
+				 ARRAY_SIZE(panthor_debugfs_list),
+				 minor->debugfs_root, minor);
+
+	return 0;
+}
+
 static void panthor_debugfs_init(struct drm_minor *minor)
 {
 	panthor_mmu_debugfs_init(minor);
+	panthor_gems_debugfs_init(minor);
 }
 #endif
 
diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
index 3c58bb2965ea..8cea6caf3143 100644
--- a/drivers/gpu/drm/panthor/panthor_gem.c
+++ b/drivers/gpu/drm/panthor/panthor_gem.c
@@ -17,6 +17,16 @@ static void panthor_gem_free_object(struct drm_gem_object *obj)
 {
 	struct panthor_gem_object *bo = to_panthor_bo(obj);
 	struct drm_gem_object *vm_root_gem = bo->exclusive_vm_root_gem;
+#ifdef CONFIG_DEBUG_FS
+	struct drm_device *dev = bo->base.base.dev;
+	struct panthor_device *ptdev = container_of(dev, struct panthor_device, base);
+
+	if (!list_empty(&bo->gems_node)) {
+		mutex_lock(&ptdev->gems_lock);
+		list_del_init(&bo->gems_node);
+		mutex_unlock(&ptdev->gems_lock);
+	}
+#endif
 
 	kfree(bo->label);
 	mutex_destroy(&bo->label_lock);
@@ -201,6 +211,12 @@ struct drm_gem_object *panthor_gem_create_object(struct drm_device *ddev, size_t
 	drm_gem_gpuva_set_lock(&obj->base.base, &obj->gpuva_list_lock);
 	mutex_init(&obj->label_lock);
 
+#ifdef CONFIG_DEBUG_FS
+	INIT_LIST_HEAD(&obj->gems_node);
+	obj->creator.tgid = current->group_leader->pid;
+	get_task_comm(obj->creator.process_name, current->group_leader);
+#endif
+
 	return &obj->base.base;
 }
 
@@ -224,6 +240,10 @@ panthor_gem_create_with_handle(struct drm_file *file,
 	int ret;
 	struct drm_gem_shmem_object *shmem;
 	struct panthor_gem_object *bo;
+#ifdef CONFIG_DEBUG_FS
+	struct panthor_device *ptdev =
+		container_of(ddev, struct panthor_device, base);
+#endif
 
 	shmem = drm_gem_shmem_create(ddev, *size);
 	if (IS_ERR(shmem))
@@ -249,6 +269,12 @@ panthor_gem_create_with_handle(struct drm_file *file,
 	/* drop reference from allocate - handle holds it now. */
 	drm_gem_object_put(&shmem->base);
 
+#ifdef CONFIG_DEBUG_FS
+	mutex_lock(&ptdev->gems_lock);
+	list_add_tail(&bo->gems_node, &ptdev->gems);
+	mutex_unlock(&ptdev->gems_lock);
+#endif
+
 	return ret;
 }
 
@@ -265,3 +291,78 @@ panthor_gem_label_bo(struct drm_gem_object *obj, const char *label)
 
 	kfree(old_label);
 }
+
+#ifdef CONFIG_DEBUG_FS
+static bool panfrost_gem_print_flag(const char *name,
+				    bool is_set,
+				    bool other_flags_printed,
+				    struct seq_file *m)
+{
+	if (is_set)
+		seq_printf(m, "%s%s", other_flags_printed ? "," : "", name);
+
+	return is_set | other_flags_printed;
+}
+
+void panthor_gem_print_objects(struct panthor_device *ptdev,
+				struct seq_file *m)
+{
+	size_t total = 0, total_resident = 0, total_reclaimable = 0;
+	struct panthor_gem_object *bo;
+
+	seq_puts(m, "created-by                      global-name     refcount        size            resident-size   file-offset     flags           label\n");
+	seq_puts(m, "------------------------------------------------------------------------------------------------------------------------------------------------\n");
+
+	mutex_lock(&ptdev->gems_lock);
+	list_for_each_entry(bo, &ptdev->gems, gems_node) {
+		unsigned int refcount = kref_read(&bo->base.base.refcount);
+		char creator_info[32] = {};
+		bool has_flags = false;
+		size_t resident_size;
+
+		/* Skip BOs being destroyed. */
+		if (!refcount)
+			continue;
+
+		resident_size = bo->base.pages != NULL ? bo->base.base.size : 0;
+
+		snprintf(creator_info, sizeof(creator_info),
+			 "%s/%d", bo->creator.process_name, bo->creator.tgid);
+		seq_printf(m, "%-32s%-16d%-16d%-16zd%-16zd%-16lx",
+			   creator_info,
+			   bo->base.base.name,
+			   refcount,
+			   bo->base.base.size,
+			   resident_size,
+			   drm_vma_node_start(&bo->base.base.vma_node));
+
+		seq_puts(m, "(");
+		has_flags = panfrost_gem_print_flag("imported", bo->base.base.import_attach != NULL,
+						    has_flags, m);
+		has_flags = panfrost_gem_print_flag("exported", bo->base.base.dma_buf != NULL,
+						    has_flags, m);
+		if (bo->base.madv < 0)
+			has_flags = panfrost_gem_print_flag("purged", true, has_flags, m);
+		else if (bo->base.madv > 0)
+			has_flags = panfrost_gem_print_flag("purgeable", true, has_flags, m);
+		if (!has_flags)
+			seq_puts(m, "none");
+		seq_puts(m, ")");
+
+		mutex_lock(&bo->label_lock);
+		seq_printf(m, "%-16s%-60s", "", bo->label ? : NULL);
+		mutex_unlock(&bo->label_lock);
+		seq_puts(m, "\n");
+
+		total += bo->base.base.size;
+		total_resident += resident_size;
+		if (bo->base.madv > 0)
+			total_reclaimable += resident_size;
+	}
+	mutex_unlock(&ptdev->gems_lock);
+
+	seq_puts(m, "================================================================================================================================================\n");
+	seq_printf(m, "Total size: %zd, Total resident: %zd, Total reclaimable: %zd\n",
+		   total, total_resident, total_reclaimable);
+}
+#endif
diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/panthor/panthor_gem.h
index da9268d24566..c0be30434b34 100644
--- a/drivers/gpu/drm/panthor/panthor_gem.h
+++ b/drivers/gpu/drm/panthor/panthor_gem.h
@@ -55,6 +55,23 @@ struct panthor_gem_object {
 
 	/** @label_lock: Lock that protects access to the @label field. */
 	struct mutex label_lock;
+
+#ifdef CONFIG_DEBUG_FS
+	/**
+	 * @gems_node: Node used to insert the object in the device-wide list of
+	 * GEM objects, to display information about it through a DebugFS file.
+	 */
+	struct list_head gems_node;
+
+	/** @creator: Information about the UM process which created the GEM. */
+	struct {
+		/** @process_name: Group leader name in owning thread's process */
+		char process_name[TASK_COMM_LEN];
+
+		/** @tgid: PID of the thread's group leader within its process */
+		pid_t tgid;
+	} creator;
+#endif
 };
 
 /**
@@ -150,4 +167,9 @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
 
 void panthor_kernel_bo_destroy(struct panthor_kernel_bo *bo);
 
+#ifdef CONFIG_DEBUG_FS
+void panthor_gem_print_objects(struct panthor_device *pfdev,
+			       struct seq_file *m);
+#endif
+
 #endif /* __PANTHOR_GEM_H__ */
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 4/4] drm/panthor: Display heap chunk entries in DebugFS GEMS file
  2025-03-16 21:51 [PATCH 0/4] Panthor BO tagging and GEMS debug display Adrián Larumbe
                   ` (2 preceding siblings ...)
  2025-03-16 21:51 ` [PATCH 3/4] drm/panthor: show device-wide list of DRM GEM objects over DebugFS Adrián Larumbe
@ 2025-03-16 21:51 ` Adrián Larumbe
  2025-03-17  8:31   ` Boris Brezillon
  3 siblings, 1 reply; 14+ messages in thread
From: Adrián Larumbe @ 2025-03-16 21:51 UTC (permalink / raw)
  To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter
  Cc: kernel, Adrián Larumbe, dri-devel, linux-kernel

Expand the driver's DebugFS GEMS file to display entries for the heap
chunks' GEM objects, both those allocated at heap creation time through an
ioctl(), or in response to a tiler OOM event.

Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
---
 drivers/gpu/drm/panthor/panthor_heap.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/gpu/drm/panthor/panthor_heap.c b/drivers/gpu/drm/panthor/panthor_heap.c
index db0285ce5812..520d1fcf5c36 100644
--- a/drivers/gpu/drm/panthor/panthor_heap.c
+++ b/drivers/gpu/drm/panthor/panthor_heap.c
@@ -139,6 +139,10 @@ static int panthor_alloc_heap_chunk(struct panthor_device *ptdev,
 	struct panthor_heap_chunk *chunk;
 	struct panthor_heap_chunk_header *hdr;
 	int ret;
+#ifdef CONFIG_DEBUG_FS
+	struct panthor_gem_object *obj;
+	const char *label;
+#endif
 
 	chunk = kmalloc(sizeof(*chunk), GFP_KERNEL);
 	if (!chunk)
@@ -180,6 +184,17 @@ static int panthor_alloc_heap_chunk(struct panthor_device *ptdev,
 	heap->chunk_count++;
 	mutex_unlock(&heap->lock);
 
+#ifdef CONFIG_DEBUG_FS
+	obj = to_panthor_bo(chunk->bo->obj);
+
+	mutex_lock(&ptdev->gems_lock);
+	list_add_tail(&obj->gems_node, &ptdev->gems);
+	mutex_unlock(&ptdev->gems_lock);
+
+	label = kstrdup_const("\"Tiler heap chunk\"", GFP_KERNEL);
+	panthor_gem_label_bo(chunk->bo->obj, label);
+#endif
+
 	return 0;
 
 err_destroy_bo:
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/4] drm/panthor: Introduce BO labeling
  2025-03-16 21:51 ` [PATCH 1/4] drm/panthor: Introduce BO labeling Adrián Larumbe
@ 2025-03-17  7:45   ` Boris Brezillon
  0 siblings, 0 replies; 14+ messages in thread
From: Boris Brezillon @ 2025-03-17  7:45 UTC (permalink / raw)
  To: Adrián Larumbe
  Cc: Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, kernel,
	linux-kernel

On Sun, 16 Mar 2025 21:51:32 +0000
Adrián Larumbe <adrian.larumbe@collabora.com> wrote:

> Add a new character string Panthor BO field, and a function that allows
> setting it from within the driver.
> 
> Driver takes care of freeing the string when it's replaced or no longer
> needed at object destruction time, but allocating it is the responsibility
> of callers.
> 
> Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
> ---
>  drivers/gpu/drm/panthor/panthor_gem.c | 18 ++++++++++++++++++
>  drivers/gpu/drm/panthor/panthor_gem.h | 12 ++++++++++++
>  2 files changed, 30 insertions(+)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
> index 8244a4e6c2a2..3c58bb2965ea 100644
> --- a/drivers/gpu/drm/panthor/panthor_gem.c
> +++ b/drivers/gpu/drm/panthor/panthor_gem.c
> @@ -18,6 +18,9 @@ static void panthor_gem_free_object(struct drm_gem_object *obj)
>  	struct panthor_gem_object *bo = to_panthor_bo(obj);
>  	struct drm_gem_object *vm_root_gem = bo->exclusive_vm_root_gem;
>  
> +	kfree(bo->label);
> +	mutex_destroy(&bo->label_lock);
> +
>  	drm_gem_free_mmap_offset(&bo->base.base);
>  	mutex_destroy(&bo->gpuva_list_lock);
>  	drm_gem_shmem_free(&bo->base);
> @@ -196,6 +199,7 @@ struct drm_gem_object *panthor_gem_create_object(struct drm_device *ddev, size_t
>  	obj->base.map_wc = !ptdev->coherent;
>  	mutex_init(&obj->gpuva_list_lock);
>  	drm_gem_gpuva_set_lock(&obj->base.base, &obj->gpuva_list_lock);
> +	mutex_init(&obj->label_lock);
>  
>  	return &obj->base.base;
>  }
> @@ -247,3 +251,17 @@ panthor_gem_create_with_handle(struct drm_file *file,
>  
>  	return ret;
>  }
> +
> +void
> +panthor_gem_label_bo(struct drm_gem_object *obj, const char *label)
> +{
> +	struct panthor_gem_object *bo = to_panthor_bo(obj);
> +	const char *old_label;
> +
> +	mutex_lock(&bo->label_lock);
> +	old_label = bo->label;
> +	bo->label = label;
> +	mutex_unlock(&bo->label_lock);
> +
> +	kfree(old_label);
> +}
> diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/panthor/panthor_gem.h
> index 5749ef2ebe03..da9268d24566 100644
> --- a/drivers/gpu/drm/panthor/panthor_gem.h
> +++ b/drivers/gpu/drm/panthor/panthor_gem.h
> @@ -46,6 +46,15 @@ struct panthor_gem_object {
>  
>  	/** @flags: Combination of drm_panthor_bo_flags flags. */
>  	u32 flags;
> +
> +	/**
> +	 * @label: Pointer to NULL-terminated string, can be assigned within the
> +	 * driver itself or through a specific IOCTL.
> +	 */
> +	const char *label;
> +
> +	/** @label_lock: Lock that protects access to the @label field. */
> +	struct mutex label_lock;

Nit: can we have a label struct with the lock and string under it
instead?

	/** @label: Fields related to GEM labeling. */
	struct {
		/**
		 * @label.str: Pointer to NULL-terminated string, can be assigned within the
		 * driver itself or through a specific IOCTL.
		 */
		const char *str;

		/** @label.lock: Lock that protects access to the @label field. */
		struct mutex lock;
	} label;

>  };
>  
>  /**
> @@ -91,6 +100,9 @@ panthor_gem_create_with_handle(struct drm_file *file,
>  			       struct panthor_vm *exclusive_vm,
>  			       u64 *size, u32 flags, uint32_t *handle);
>  
> +void
> +panthor_gem_label_bo(struct drm_gem_object *obj, const char *label);
> +
>  static inline u64
>  panthor_kernel_bo_gpuva(struct panthor_kernel_bo *bo)
>  {


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/4] drm/panthor: Add driver IOCTL for setting BO labels
  2025-03-16 21:51 ` [PATCH 2/4] drm/panthor: Add driver IOCTL for setting BO labels Adrián Larumbe
@ 2025-03-17  7:50   ` Boris Brezillon
  2025-03-19 13:49     ` Adrián Larumbe
  2025-03-17  7:54   ` Boris Brezillon
  1 sibling, 1 reply; 14+ messages in thread
From: Boris Brezillon @ 2025-03-17  7:50 UTC (permalink / raw)
  To: Adrián Larumbe
  Cc: Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, kernel, dri-devel,
	linux-kernel

On Sun, 16 Mar 2025 21:51:33 +0000
Adrián Larumbe <adrian.larumbe@collabora.com> wrote:

> Allow UM to label a BO for which it possesses a DRM handle.
> 
> Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
> ---
>  drivers/gpu/drm/panthor/panthor_drv.c | 31 +++++++++++++++++++++++++++
>  include/uapi/drm/panthor_drm.h        | 14 ++++++++++++
>  2 files changed, 45 insertions(+)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
> index 310bb44abe1a..f41b8946258f 100644
> --- a/drivers/gpu/drm/panthor/panthor_drv.c
> +++ b/drivers/gpu/drm/panthor/panthor_drv.c
> @@ -1330,6 +1330,35 @@ static int panthor_ioctl_vm_get_state(struct drm_device *ddev, void *data,
>  	return 0;
>  }
>  
> +static int panthor_ioctl_label_bo(struct drm_device *ddev, void *data,
> +				  struct drm_file *file)
> +{
> +	struct drm_panthor_label_bo *args = data;
> +	struct drm_gem_object *obj;
> +	const char *label;
> +	int ret = 0;
> +
> +	obj = drm_gem_object_lookup(file, args->handle);
> +	if (!obj)
> +		return -ENOENT;
> +
> +	if (args->len && args->label) {
> +		label = strndup_user(u64_to_user_ptr(args->label), args->len + 1);
> +		if (IS_ERR(label)) {
> +			ret = PTR_ERR(label);
> +			goto err_label;
> +		}
> +	} else
> +		label = NULL;
> +
> +	panthor_gem_label_bo(obj, label);
> +
> +err_label:
> +	drm_gem_object_put(obj);
> +
> +	return ret;
> +}
> +
>  static int
>  panthor_open(struct drm_device *ddev, struct drm_file *file)
>  {
> @@ -1399,6 +1428,7 @@ static const struct drm_ioctl_desc panthor_drm_driver_ioctls[] = {
>  	PANTHOR_IOCTL(TILER_HEAP_CREATE, tiler_heap_create, DRM_RENDER_ALLOW),
>  	PANTHOR_IOCTL(TILER_HEAP_DESTROY, tiler_heap_destroy, DRM_RENDER_ALLOW),
>  	PANTHOR_IOCTL(GROUP_SUBMIT, group_submit, DRM_RENDER_ALLOW),
> +	PANTHOR_IOCTL(LABEL_BO, label_bo, DRM_RENDER_ALLOW),
>  };
>  
>  static int panthor_mmap(struct file *filp, struct vm_area_struct *vma)
> @@ -1508,6 +1538,7 @@ static void panthor_debugfs_init(struct drm_minor *minor)
>   * - 1.2 - adds DEV_QUERY_GROUP_PRIORITIES_INFO query
>   *       - adds PANTHOR_GROUP_PRIORITY_REALTIME priority
>   * - 1.3 - adds DRM_PANTHOR_GROUP_STATE_INNOCENT flag
> + * - 1.4 - adds DRM_IOCTL_PANTHOR_LABEL_BO ioctl
>   */
>  static const struct drm_driver panthor_drm_driver = {
>  	.driver_features = DRIVER_RENDER | DRIVER_GEM | DRIVER_SYNCOBJ |
> diff --git a/include/uapi/drm/panthor_drm.h b/include/uapi/drm/panthor_drm.h
> index 97e2c4510e69..1a7ed567d36a 100644
> --- a/include/uapi/drm/panthor_drm.h
> +++ b/include/uapi/drm/panthor_drm.h
> @@ -127,6 +127,9 @@ enum drm_panthor_ioctl_id {
>  
>  	/** @DRM_PANTHOR_TILER_HEAP_DESTROY: Destroy a tiler heap. */
>  	DRM_PANTHOR_TILER_HEAP_DESTROY,
> +
> +	/** @DRM_PANTHOR_LABEL_BO: Label a BO. */
> +	DRM_PANTHOR_LABEL_BO,

DRM_PANTHOR_BO_SET_LABEL to follow the DRM_PANTHOR_<object>_<action>
naming scheme used in this file.

I'd also be tempted to introduce a DRM_PANTHOR_BO_GET_LABEL ioctl while
we're at it.

>  };
>  
>  /**
> @@ -977,6 +980,15 @@ struct drm_panthor_tiler_heap_destroy {
>  	__u32 pad;
>  };
>  
> +/**
> + * struct drm_panthor_label_bo - Arguments passed to DRM_IOCTL_PANTHOR_LABEL_BO
> + */
> +struct drm_panthor_label_bo {
> +	__u32 handle;
> +	__u32 len;
> +	__u64 label;

Can you document these fields?

> +};
> +
>  /**
>   * DRM_IOCTL_PANTHOR() - Build a Panthor IOCTL number
>   * @__access: Access type. Must be R, W or RW.
> @@ -1019,6 +1031,8 @@ enum {
>  		DRM_IOCTL_PANTHOR(WR, TILER_HEAP_CREATE, tiler_heap_create),
>  	DRM_IOCTL_PANTHOR_TILER_HEAP_DESTROY =
>  		DRM_IOCTL_PANTHOR(WR, TILER_HEAP_DESTROY, tiler_heap_destroy),
> +	DRM_IOCTL_PANTHOR_LABEL_BO =
> +		DRM_IOCTL_PANTHOR(WR, LABEL_BO, label_bo),
>  };
>  
>  #if defined(__cplusplus)


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/4] drm/panthor: Add driver IOCTL for setting BO labels
  2025-03-16 21:51 ` [PATCH 2/4] drm/panthor: Add driver IOCTL for setting BO labels Adrián Larumbe
  2025-03-17  7:50   ` Boris Brezillon
@ 2025-03-17  7:54   ` Boris Brezillon
  1 sibling, 0 replies; 14+ messages in thread
From: Boris Brezillon @ 2025-03-17  7:54 UTC (permalink / raw)
  To: Adrián Larumbe
  Cc: Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, kernel, dri-devel,
	linux-kernel

On Sun, 16 Mar 2025 21:51:33 +0000
Adrián Larumbe <adrian.larumbe@collabora.com> wrote:

> Allow UM to label a BO for which it possesses a DRM handle.
> 
> Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
> ---
>  drivers/gpu/drm/panthor/panthor_drv.c | 31 +++++++++++++++++++++++++++
>  include/uapi/drm/panthor_drm.h        | 14 ++++++++++++
>  2 files changed, 45 insertions(+)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
> index 310bb44abe1a..f41b8946258f 100644
> --- a/drivers/gpu/drm/panthor/panthor_drv.c
> +++ b/drivers/gpu/drm/panthor/panthor_drv.c
> @@ -1330,6 +1330,35 @@ static int panthor_ioctl_vm_get_state(struct drm_device *ddev, void *data,
>  	return 0;
>  }
>  
> +static int panthor_ioctl_label_bo(struct drm_device *ddev, void *data,
> +				  struct drm_file *file)
> +{
> +	struct drm_panthor_label_bo *args = data;
> +	struct drm_gem_object *obj;
> +	const char *label;
> +	int ret = 0;
> +
> +	obj = drm_gem_object_lookup(file, args->handle);
> +	if (!obj)
> +		return -ENOENT;
> +
> +	if (args->len && args->label) {

We probably want to have a limit on the label length (PAGE_SIZE or
less?). I would also return -EINVAL if the length is not zero and the
label is NULL instead of silently setting the label to NULL.

> +		label = strndup_user(u64_to_user_ptr(args->label), args->len + 1);
> +		if (IS_ERR(label)) {
> +			ret = PTR_ERR(label);
> +			goto err_label;
> +		}
> +	} else
> +		label = NULL;

	} else {
		label = NULL;
	}
> +
> +	panthor_gem_label_bo(obj, label);
> +
> +err_label:
> +	drm_gem_object_put(obj);
> +
> +	return ret;
> +}
> +

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 3/4] drm/panthor: show device-wide list of DRM GEM objects over DebugFS
  2025-03-16 21:51 ` [PATCH 3/4] drm/panthor: show device-wide list of DRM GEM objects over DebugFS Adrián Larumbe
@ 2025-03-17  8:26   ` Boris Brezillon
  0 siblings, 0 replies; 14+ messages in thread
From: Boris Brezillon @ 2025-03-17  8:26 UTC (permalink / raw)
  To: Adrián Larumbe
  Cc: Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Sumit Semwal,
	Christian König, kernel, dri-devel, linux-kernel,
	linux-media, linaro-mm-sig

On Sun, 16 Mar 2025 21:51:34 +0000
Adrián Larumbe <adrian.larumbe@collabora.com> wrote:

> Add a device DebugFS file that displays a complete list of all the DRM GEM
> objects that are exposed to UM through a DRM handle.
> 
> Since leaking object identifiers that might belong to a different NS is
> inadmissible, this functionality is only made available in debug builds
> with DEBUGFS support enabled.
> 
> File format is that of a table, with each entry displaying a variety of
> fields with information about each GEM object.
> 
> Each GEM object entry in the file displays the following information
> fields: Client PID, BO's global name, reference count, BO virtual size, BO
> resize size, VM address in its DRM-managed range, BO label and a flag
> bitmask.
> 
> Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
> ---
>  drivers/gpu/drm/panthor/panthor_device.c |   5 ++
>  drivers/gpu/drm/panthor/panthor_device.h |   8 ++
>  drivers/gpu/drm/panthor/panthor_drv.c    |  26 ++++++
>  drivers/gpu/drm/panthor/panthor_gem.c    | 101 +++++++++++++++++++++++
>  drivers/gpu/drm/panthor/panthor_gem.h    |  22 +++++
>  5 files changed, 162 insertions(+)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_device.c b/drivers/gpu/drm/panthor/panthor_device.c
> index a9da1d1eeb70..7df12eefc39f 100644
> --- a/drivers/gpu/drm/panthor/panthor_device.c
> +++ b/drivers/gpu/drm/panthor/panthor_device.c
> @@ -263,6 +263,11 @@ int panthor_device_init(struct panthor_device *ptdev)
>  	pm_runtime_set_autosuspend_delay(ptdev->base.dev, 50);
>  	pm_runtime_use_autosuspend(ptdev->base.dev);
>  
> +#ifdef CONFIG_DEBUG_FS
> +	drmm_mutex_init(&ptdev->base, &ptdev->gems_lock);
> +	INIT_LIST_HEAD(&ptdev->gems);
> +#endif
> +
>  	ret = drm_dev_register(&ptdev->base, 0);
>  	if (ret)
>  		goto err_disable_autosuspend;
> diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/panthor/panthor_device.h
> index da6574021664..6c030978cdc3 100644
> --- a/drivers/gpu/drm/panthor/panthor_device.h
> +++ b/drivers/gpu/drm/panthor/panthor_device.h
> @@ -205,6 +205,14 @@ struct panthor_device {
>  
>  	/** @fast_rate: Maximum device clock frequency. Set by DVFS */
>  	unsigned long fast_rate;
> +
> +#ifdef CONFIG_DEBUG_FS
> +	/** @gems_lock: Protects the device-wide list of GEM objects. */
> +	struct mutex gems_lock;
> +
> +	/** @gems: Device-wide list of GEM objects owned by at least one file. */
> +	struct list_head gems;

	struct {
		struct mutex lock;
		struct list_head list;
	} gems;

> +#endif
>  };
>  
>  struct panthor_gpu_usage {
> diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
> index f41b8946258f..6663eff44bdc 100644
> --- a/drivers/gpu/drm/panthor/panthor_drv.c
> +++ b/drivers/gpu/drm/panthor/panthor_drv.c
> @@ -1525,9 +1525,35 @@ static const struct file_operations panthor_drm_driver_fops = {
>  };
>  
>  #ifdef CONFIG_DEBUG_FS
> +static int panthor_gems_show(struct seq_file *m, void *data)
> +{
> +	struct drm_info_node *node = m->private;
> +	struct drm_device *dev = node->minor->dev;
> +	struct panthor_device *ptdev = container_of(dev, struct panthor_device, base);
> +
> +	panthor_gem_print_objects(ptdev, m);
> +
> +	return 0;
> +}
> +
> +
> +static struct drm_info_list panthor_debugfs_list[] = {
> +	{"gems", panthor_gems_show, 0, NULL},
> +};
> +
> +static int panthor_gems_debugfs_init(struct drm_minor *minor)
> +{
> +	drm_debugfs_create_files(panthor_debugfs_list,
> +				 ARRAY_SIZE(panthor_debugfs_list),
> +				 minor->debugfs_root, minor);
> +
> +	return 0;
> +}
> +
>  static void panthor_debugfs_init(struct drm_minor *minor)
>  {
>  	panthor_mmu_debugfs_init(minor);
> +	panthor_gems_debugfs_init(minor);
>  }
>  #endif
>  
> diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
> index 3c58bb2965ea..8cea6caf3143 100644
> --- a/drivers/gpu/drm/panthor/panthor_gem.c
> +++ b/drivers/gpu/drm/panthor/panthor_gem.c
> @@ -17,6 +17,16 @@ static void panthor_gem_free_object(struct drm_gem_object *obj)
>  {
>  	struct panthor_gem_object *bo = to_panthor_bo(obj);
>  	struct drm_gem_object *vm_root_gem = bo->exclusive_vm_root_gem;
> +#ifdef CONFIG_DEBUG_FS
> +	struct drm_device *dev = bo->base.base.dev;
> +	struct panthor_device *ptdev = container_of(dev, struct panthor_device, base);
> +
> +	if (!list_empty(&bo->gems_node)) {
> +		mutex_lock(&ptdev->gems_lock);
> +		list_del_init(&bo->gems_node);
> +		mutex_unlock(&ptdev->gems_lock);
> +	}
> +#endif

Can we add helpers to add/remove a GEM to the list and define dummy
implementations for the !CONFIG_DEBUG_FS case?

#ifdef CONFIG_DEBUG_FS
static void panthor_gem_debugfs_bo_init(struct panthor_gem_object *bo)
{
	INIT_LIST_HEAD(&obj->gems_node);
	obj->creator.tgid = current->group_leader->pid;
	get_task_comm(obj->creator.process_name, current->group_leader);
}

static void panthor_gem_debugfs_bo_add(struct panthor_gem_object *bo)
{
	struct panthor_device *ptdev = container_of(bo->base.base.dev,
						    struct panthor_device, base);

	mutex_lock(&ptdev->gems_lock);
	list_add_tail(&bo->gems_node, &ptdev->gems);
	mutex_unlock(&ptdev->gems_lock);
}

static void panthor_gem_debugfs_bo_rm(struct panthor_gem_object *bo)
{
	struct panthor_device *ptdev = container_of(bo->base.base.dev,
						    struct panthor_device, base);
	
	if (list_empty(&bo->gems_node))
		return;

	mutex_lock(&ptdev->gems_lock);
	list_del_init(&bo->gems_node);
	mutex_unlock(&ptdev->gems_lock);
}
#else
static void panthor_gem_debugfs_bo_init(struct panthor_gem_object *bo) {}
static void panthor_gem_debugfs_bo_add(struct panthor_gem_object *bo) {}
static void panthor_gem_debugfs_bo_rm(struct panthor_gem_object *bo) {}
#endif

>  
>  	kfree(bo->label);
>  	mutex_destroy(&bo->label_lock);
> @@ -201,6 +211,12 @@ struct drm_gem_object *panthor_gem_create_object(struct drm_device *ddev, size_t
>  	drm_gem_gpuva_set_lock(&obj->base.base, &obj->gpuva_list_lock);
>  	mutex_init(&obj->label_lock);
>  
> +#ifdef CONFIG_DEBUG_FS
> +	INIT_LIST_HEAD(&obj->gems_node);
> +	obj->creator.tgid = current->group_leader->pid;
> +	get_task_comm(obj->creator.process_name, current->group_leader);
> +#endif

	panthor_gem_debugfs_bo_init(obj);
	
> +
>  	return &obj->base.base;
>  }
>  
> @@ -224,6 +240,10 @@ panthor_gem_create_with_handle(struct drm_file *file,
>  	int ret;
>  	struct drm_gem_shmem_object *shmem;
>  	struct panthor_gem_object *bo;
> +#ifdef CONFIG_DEBUG_FS
> +	struct panthor_device *ptdev =
> +		container_of(ddev, struct panthor_device, base);
> +#endif
>  
>  	shmem = drm_gem_shmem_create(ddev, *size);
>  	if (IS_ERR(shmem))
> @@ -249,6 +269,12 @@ panthor_gem_create_with_handle(struct drm_file *file,
>  	/* drop reference from allocate - handle holds it now. */
>  	drm_gem_object_put(&shmem->base);
>  
> +#ifdef CONFIG_DEBUG_FS
> +	mutex_lock(&ptdev->gems_lock);
> +	list_add_tail(&bo->gems_node, &ptdev->gems);
> +	mutex_unlock(&ptdev->gems_lock);
> +#endif

	panthor_gem_debugfs_bo_rm(bo);

> +
>  	return ret;
>  }
>  
> @@ -265,3 +291,78 @@ panthor_gem_label_bo(struct drm_gem_object *obj, const char *label)
>  
>  	kfree(old_label);
>  }
> +
> +#ifdef CONFIG_DEBUG_FS
> +static bool panfrost_gem_print_flag(const char *name,
> +				    bool is_set,
> +				    bool other_flags_printed,
> +				    struct seq_file *m)
> +{
> +	if (is_set)
> +		seq_printf(m, "%s%s", other_flags_printed ? "," : "", name);
> +
> +	return is_set | other_flags_printed;
> +}
> +
> +void panthor_gem_print_objects(struct panthor_device *ptdev,
> +				struct seq_file *m)
> +{
> +	size_t total = 0, total_resident = 0, total_reclaimable = 0;
> +	struct panthor_gem_object *bo;
> +
> +	seq_puts(m, "created-by                      global-name     refcount        size            resident-size   file-offset     flags           label\n");
> +	seq_puts(m, "------------------------------------------------------------------------------------------------------------------------------------------------\n");
> +
> +	mutex_lock(&ptdev->gems_lock);
> +	list_for_each_entry(bo, &ptdev->gems, gems_node) {
> +		unsigned int refcount = kref_read(&bo->base.base.refcount);
> +		char creator_info[32] = {};
> +		bool has_flags = false;
> +		size_t resident_size;
> +
> +		/* Skip BOs being destroyed. */
> +		if (!refcount)
> +			continue;
> +
> +		resident_size = bo->base.pages != NULL ? bo->base.base.size : 0;
> +
> +		snprintf(creator_info, sizeof(creator_info),
> +			 "%s/%d", bo->creator.process_name, bo->creator.tgid);
> +		seq_printf(m, "%-32s%-16d%-16d%-16zd%-16zd%-16lx",
> +			   creator_info,
> +			   bo->base.base.name,
> +			   refcount,
> +			   bo->base.base.size,
> +			   resident_size,
> +			   drm_vma_node_start(&bo->base.base.vma_node));
> +
> +		seq_puts(m, "(");
> +		has_flags = panfrost_gem_print_flag("imported", bo->base.base.import_attach != NULL,
> +						    has_flags, m);
> +		has_flags = panfrost_gem_print_flag("exported", bo->base.base.dma_buf != NULL,
> +						    has_flags, m);
> +		if (bo->base.madv < 0)
> +			has_flags = panfrost_gem_print_flag("purged", true, has_flags, m);
> +		else if (bo->base.madv > 0)
> +			has_flags = panfrost_gem_print_flag("purgeable", true, has_flags, m);
> +		if (!has_flags)
> +			seq_puts(m, "none");
> +		seq_puts(m, ")");
> +
> +		mutex_lock(&bo->label_lock);
> +		seq_printf(m, "%-16s%-60s", "", bo->label ? : NULL);
> +		mutex_unlock(&bo->label_lock);
> +		seq_puts(m, "\n");

Let's have a panthor_gem_debugfs_bo_print() helper to print a single BO.

> +
> +		total += bo->base.base.size;
> +		total_resident += resident_size;
> +		if (bo->base.madv > 0)
> +			total_reclaimable += resident_size;
> +	}
> +	mutex_unlock(&ptdev->gems_lock);
> +
> +	seq_puts(m, "================================================================================================================================================\n");
> +	seq_printf(m, "Total size: %zd, Total resident: %zd, Total reclaimable: %zd\n",
> +		   total, total_resident, total_reclaimable);
> +}
> +#endif
> diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/panthor/panthor_gem.h
> index da9268d24566..c0be30434b34 100644
> --- a/drivers/gpu/drm/panthor/panthor_gem.h
> +++ b/drivers/gpu/drm/panthor/panthor_gem.h
> @@ -55,6 +55,23 @@ struct panthor_gem_object {
>  
>  	/** @label_lock: Lock that protects access to the @label field. */
>  	struct mutex label_lock;
> +
> +#ifdef CONFIG_DEBUG_FS
> +	/**
> +	 * @gems_node: Node used to insert the object in the device-wide list of
> +	 * GEM objects, to display information about it through a DebugFS file.
> +	 */
> +	struct list_head gems_node;
> +
> +	/** @creator: Information about the UM process which created the GEM. */
> +	struct {
> +		/** @process_name: Group leader name in owning thread's process */
> +		char process_name[TASK_COMM_LEN];
> +
> +		/** @tgid: PID of the thread's group leader within its process */
> +		pid_t tgid;
> +	} creator;

Can we put all these fields under a debugfs struct?

struct panthor_gem_debugfs {
	/**
	 * @gems_node: Node used to insert the object in the device-wide list of
	 * GEM objects, to display information about it through a DebugFS file.
	 */
	struct list_head gems_node;

	/** @creator: Information about the UM process which created the GEM. */
	struct {
		/** @process_name: Group leader name in owning thread's process */
		char process_name[TASK_COMM_LEN];
	
		/** @tgid: PID of the thread's group leader within its process */
		pid_t tgid;
	} creator;
};

...

struct panthor_gem_object {
	...

#ifdef CONFIG_DEBUG_FS
	struct panthor_gem_debugfs debugfs;
#endif

	...
};

> +#endif
>  };
>  
>  /**
> @@ -150,4 +167,9 @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
>  
>  void panthor_kernel_bo_destroy(struct panthor_kernel_bo *bo);
>  
> +#ifdef CONFIG_DEBUG_FS
> +void panthor_gem_print_objects(struct panthor_device *pfdev,
> +			       struct seq_file *m);

s/panthor_gem_print_objects/panthor_gem_debugfs_print_bos/

> +#endif
> +
>  #endif /* __PANTHOR_GEM_H__ */


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 4/4] drm/panthor: Display heap chunk entries in DebugFS GEMS file
  2025-03-16 21:51 ` [PATCH 4/4] drm/panthor: Display heap chunk entries in DebugFS GEMS file Adrián Larumbe
@ 2025-03-17  8:31   ` Boris Brezillon
  2025-03-19 13:18     ` Adrián Larumbe
  0 siblings, 1 reply; 14+ messages in thread
From: Boris Brezillon @ 2025-03-17  8:31 UTC (permalink / raw)
  To: Adrián Larumbe
  Cc: Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, kernel, dri-devel,
	linux-kernel

On Sun, 16 Mar 2025 21:51:35 +0000
Adrián Larumbe <adrian.larumbe@collabora.com> wrote:

> Expand the driver's DebugFS GEMS file to display entries for the heap
> chunks' GEM objects, both those allocated at heap creation time through an
> ioctl(), or in response to a tiler OOM event.
> 
> Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
> ---
>  drivers/gpu/drm/panthor/panthor_heap.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_heap.c b/drivers/gpu/drm/panthor/panthor_heap.c
> index db0285ce5812..520d1fcf5c36 100644
> --- a/drivers/gpu/drm/panthor/panthor_heap.c
> +++ b/drivers/gpu/drm/panthor/panthor_heap.c
> @@ -139,6 +139,10 @@ static int panthor_alloc_heap_chunk(struct panthor_device *ptdev,
>  	struct panthor_heap_chunk *chunk;
>  	struct panthor_heap_chunk_header *hdr;
>  	int ret;
> +#ifdef CONFIG_DEBUG_FS
> +	struct panthor_gem_object *obj;
> +	const char *label;
> +#endif
>  
>  	chunk = kmalloc(sizeof(*chunk), GFP_KERNEL);
>  	if (!chunk)
> @@ -180,6 +184,17 @@ static int panthor_alloc_heap_chunk(struct panthor_device *ptdev,
>  	heap->chunk_count++;
>  	mutex_unlock(&heap->lock);
>  
> +#ifdef CONFIG_DEBUG_FS
> +	obj = to_panthor_bo(chunk->bo->obj);
> +
> +	mutex_lock(&ptdev->gems_lock);
> +	list_add_tail(&obj->gems_node, &ptdev->gems);
> +	mutex_unlock(&ptdev->gems_lock);
> +
> +	label = kstrdup_const("\"Tiler heap chunk\"", GFP_KERNEL);

Do we really need the extra quotes around 'Tiler heap chunk'?

> +	panthor_gem_label_bo(chunk->bo->obj, label);
> +#endif

Let's define a helper to assign a label to a kernel BO instead of
open-coding it here. BTW, I suspect we'll want to assign labels to
other kernel BOs too (FW buffers).

> +
>  	return 0;
>  
>  err_destroy_bo:


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 4/4] drm/panthor: Display heap chunk entries in DebugFS GEMS file
  2025-03-17  8:31   ` Boris Brezillon
@ 2025-03-19 13:18     ` Adrián Larumbe
  2025-03-19 16:39       ` Boris Brezillon
  0 siblings, 1 reply; 14+ messages in thread
From: Adrián Larumbe @ 2025-03-19 13:18 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, kernel, dri-devel,
	linux-kernel

On 17.03.2025 09:31, Boris Brezillon wrote:
> On Sun, 16 Mar 2025 21:51:35 +0000
> Adrián Larumbe <adrian.larumbe@collabora.com> wrote:
>
> > Expand the driver's DebugFS GEMS file to display entries for the heap
> > chunks' GEM objects, both those allocated at heap creation time through an
> > ioctl(), or in response to a tiler OOM event.
> >
> > Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
> > ---
> >  drivers/gpu/drm/panthor/panthor_heap.c | 15 +++++++++++++++
> >  1 file changed, 15 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/panthor/panthor_heap.c b/drivers/gpu/drm/panthor/panthor_heap.c
> > index db0285ce5812..520d1fcf5c36 100644
> > --- a/drivers/gpu/drm/panthor/panthor_heap.c
> > +++ b/drivers/gpu/drm/panthor/panthor_heap.c
> > @@ -139,6 +139,10 @@ static int panthor_alloc_heap_chunk(struct panthor_device *ptdev,
> >  	struct panthor_heap_chunk *chunk;
> >  	struct panthor_heap_chunk_header *hdr;
> >  	int ret;
> > +#ifdef CONFIG_DEBUG_FS
> > +	struct panthor_gem_object *obj;
> > +	const char *label;
> > +#endif
> >
> >  	chunk = kmalloc(sizeof(*chunk), GFP_KERNEL);
> >  	if (!chunk)
> > @@ -180,6 +184,17 @@ static int panthor_alloc_heap_chunk(struct panthor_device *ptdev,
> >  	heap->chunk_count++;
> >  	mutex_unlock(&heap->lock);
> >
> > +#ifdef CONFIG_DEBUG_FS
> > +	obj = to_panthor_bo(chunk->bo->obj);
> > +
> > +	mutex_lock(&ptdev->gems_lock);
> > +	list_add_tail(&obj->gems_node, &ptdev->gems);
> > +	mutex_unlock(&ptdev->gems_lock);
> > +
> > +	label = kstrdup_const("\"Tiler heap chunk\"", GFP_KERNEL);
>
> Do we really need the extra quotes around 'Tiler heap chunk'?

We want them quoted like this so that the BO name can be told apart from the
the extra tagging information (like modifiers) and any suffix sent down from gl

> > +	panthor_gem_label_bo(chunk->bo->obj, label);
> > +#endif
>
> Let's define a helper to assign a label to a kernel BO instead of
> open-coding it here. BTW, I suspect we'll want to assign labels to
> other kernel BOs too (FW buffers).
>
> > +
> >  	return 0;
> >
> >  err_destroy_bo:


Adrian Larumbe

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/4] drm/panthor: Add driver IOCTL for setting BO labels
  2025-03-17  7:50   ` Boris Brezillon
@ 2025-03-19 13:49     ` Adrián Larumbe
  2025-03-19 16:28       ` Boris Brezillon
  0 siblings, 1 reply; 14+ messages in thread
From: Adrián Larumbe @ 2025-03-19 13:49 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, kernel, dri-devel,
	linux-kernel

Hi Boris,

On 17.03.2025 08:50, Boris Brezillon wrote:
> On Sun, 16 Mar 2025 21:51:33 +0000
> Adrián Larumbe <adrian.larumbe@collabora.com> wrote:
>
> > Allow UM to label a BO for which it possesses a DRM handle.
> >
> > Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
> > ---
> >  drivers/gpu/drm/panthor/panthor_drv.c | 31 +++++++++++++++++++++++++++
> >  include/uapi/drm/panthor_drm.h        | 14 ++++++++++++
> >  2 files changed, 45 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
> > index 310bb44abe1a..f41b8946258f 100644
> > --- a/drivers/gpu/drm/panthor/panthor_drv.c
> > +++ b/drivers/gpu/drm/panthor/panthor_drv.c
> > @@ -1330,6 +1330,35 @@ static int panthor_ioctl_vm_get_state(struct drm_device *ddev, void *data,
> >  	return 0;
> >  }
> >
> > +static int panthor_ioctl_label_bo(struct drm_device *ddev, void *data,
> > +				  struct drm_file *file)
> > +{
> > +	struct drm_panthor_label_bo *args = data;
> > +	struct drm_gem_object *obj;
> > +	const char *label;
> > +	int ret = 0;
> > +
> > +	obj = drm_gem_object_lookup(file, args->handle);
> > +	if (!obj)
> > +		return -ENOENT;
> > +
> > +	if (args->len && args->label) {
> > +		label = strndup_user(u64_to_user_ptr(args->label), args->len + 1);
> > +		if (IS_ERR(label)) {
> > +			ret = PTR_ERR(label);
> > +			goto err_label;
> > +		}
> > +	} else
> > +		label = NULL;
> > +
> > +	panthor_gem_label_bo(obj, label);
> > +
> > +err_label:
> > +	drm_gem_object_put(obj);
> > +
> > +	return ret;
> > +}
> > +
> >  static int
> >  panthor_open(struct drm_device *ddev, struct drm_file *file)
> >  {
> > @@ -1399,6 +1428,7 @@ static const struct drm_ioctl_desc panthor_drm_driver_ioctls[] = {
> >  	PANTHOR_IOCTL(TILER_HEAP_CREATE, tiler_heap_create, DRM_RENDER_ALLOW),
> >  	PANTHOR_IOCTL(TILER_HEAP_DESTROY, tiler_heap_destroy, DRM_RENDER_ALLOW),
> >  	PANTHOR_IOCTL(GROUP_SUBMIT, group_submit, DRM_RENDER_ALLOW),
> > +	PANTHOR_IOCTL(LABEL_BO, label_bo, DRM_RENDER_ALLOW),
> >  };
> >
> >  static int panthor_mmap(struct file *filp, struct vm_area_struct *vma)
> > @@ -1508,6 +1538,7 @@ static void panthor_debugfs_init(struct drm_minor *minor)
> >   * - 1.2 - adds DEV_QUERY_GROUP_PRIORITIES_INFO query
> >   *       - adds PANTHOR_GROUP_PRIORITY_REALTIME priority
> >   * - 1.3 - adds DRM_PANTHOR_GROUP_STATE_INNOCENT flag
> > + * - 1.4 - adds DRM_IOCTL_PANTHOR_LABEL_BO ioctl
> >   */
> >  static const struct drm_driver panthor_drm_driver = {
> >  	.driver_features = DRIVER_RENDER | DRIVER_GEM | DRIVER_SYNCOBJ |
> > diff --git a/include/uapi/drm/panthor_drm.h b/include/uapi/drm/panthor_drm.h
> > index 97e2c4510e69..1a7ed567d36a 100644
> > --- a/include/uapi/drm/panthor_drm.h
> > +++ b/include/uapi/drm/panthor_drm.h
> > @@ -127,6 +127,9 @@ enum drm_panthor_ioctl_id {
> >
> >  	/** @DRM_PANTHOR_TILER_HEAP_DESTROY: Destroy a tiler heap. */
> >  	DRM_PANTHOR_TILER_HEAP_DESTROY,
> > +
> > +	/** @DRM_PANTHOR_LABEL_BO: Label a BO. */
> > +	DRM_PANTHOR_LABEL_BO,
>
> DRM_PANTHOR_BO_SET_LABEL to follow the DRM_PANTHOR_<object>_<action>
> naming scheme used in this file.
>
> I'd also be tempted to introduce a DRM_PANTHOR_BO_GET_LABEL ioctl while
> we're at it.

I thought of this too, but I was a bit reluctant because at present there are no UM
driver users who need this functionality.

> >  };
> >
> >  /**
> > @@ -977,6 +980,15 @@ struct drm_panthor_tiler_heap_destroy {
> >  	__u32 pad;
> >  };
> >
> > +/**
> > + * struct drm_panthor_label_bo - Arguments passed to DRM_IOCTL_PANTHOR_LABEL_BO
> > + */
> > +struct drm_panthor_label_bo {
> > +	__u32 handle;
> > +	__u32 len;
> > +	__u64 label;
>
> Can you document these fields?
>
> > +};
> > +
> >  /**
> >   * DRM_IOCTL_PANTHOR() - Build a Panthor IOCTL number
> >   * @__access: Access type. Must be R, W or RW.
> > @@ -1019,6 +1031,8 @@ enum {
> >  		DRM_IOCTL_PANTHOR(WR, TILER_HEAP_CREATE, tiler_heap_create),
> >  	DRM_IOCTL_PANTHOR_TILER_HEAP_DESTROY =
> >  		DRM_IOCTL_PANTHOR(WR, TILER_HEAP_DESTROY, tiler_heap_destroy),
> > +	DRM_IOCTL_PANTHOR_LABEL_BO =
> > +		DRM_IOCTL_PANTHOR(WR, LABEL_BO, label_bo),
> >  };
> >
> >  #if defined(__cplusplus)


Adrian Larumbe

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/4] drm/panthor: Add driver IOCTL for setting BO labels
  2025-03-19 13:49     ` Adrián Larumbe
@ 2025-03-19 16:28       ` Boris Brezillon
  0 siblings, 0 replies; 14+ messages in thread
From: Boris Brezillon @ 2025-03-19 16:28 UTC (permalink / raw)
  To: Adrián Larumbe
  Cc: Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, kernel, dri-devel,
	linux-kernel

On Wed, 19 Mar 2025 13:49:02 +0000
Adrián Larumbe <adrian.larumbe@collabora.com> wrote:

> Hi Boris,
> 
> On 17.03.2025 08:50, Boris Brezillon wrote:
> > On Sun, 16 Mar 2025 21:51:33 +0000
> > Adrián Larumbe <adrian.larumbe@collabora.com> wrote:
> >  
> > > Allow UM to label a BO for which it possesses a DRM handle.
> > >
> > > Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
> > > ---
> > >  drivers/gpu/drm/panthor/panthor_drv.c | 31 +++++++++++++++++++++++++++
> > >  include/uapi/drm/panthor_drm.h        | 14 ++++++++++++
> > >  2 files changed, 45 insertions(+)
> > >
> > > diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
> > > index 310bb44abe1a..f41b8946258f 100644
> > > --- a/drivers/gpu/drm/panthor/panthor_drv.c
> > > +++ b/drivers/gpu/drm/panthor/panthor_drv.c
> > > @@ -1330,6 +1330,35 @@ static int panthor_ioctl_vm_get_state(struct drm_device *ddev, void *data,
> > >  	return 0;
> > >  }
> > >
> > > +static int panthor_ioctl_label_bo(struct drm_device *ddev, void *data,
> > > +				  struct drm_file *file)
> > > +{
> > > +	struct drm_panthor_label_bo *args = data;
> > > +	struct drm_gem_object *obj;
> > > +	const char *label;
> > > +	int ret = 0;
> > > +
> > > +	obj = drm_gem_object_lookup(file, args->handle);
> > > +	if (!obj)
> > > +		return -ENOENT;
> > > +
> > > +	if (args->len && args->label) {
> > > +		label = strndup_user(u64_to_user_ptr(args->label), args->len + 1);
> > > +		if (IS_ERR(label)) {
> > > +			ret = PTR_ERR(label);
> > > +			goto err_label;
> > > +		}
> > > +	} else
> > > +		label = NULL;
> > > +
> > > +	panthor_gem_label_bo(obj, label);
> > > +
> > > +err_label:
> > > +	drm_gem_object_put(obj);
> > > +
> > > +	return ret;
> > > +}
> > > +
> > >  static int
> > >  panthor_open(struct drm_device *ddev, struct drm_file *file)
> > >  {
> > > @@ -1399,6 +1428,7 @@ static const struct drm_ioctl_desc panthor_drm_driver_ioctls[] = {
> > >  	PANTHOR_IOCTL(TILER_HEAP_CREATE, tiler_heap_create, DRM_RENDER_ALLOW),
> > >  	PANTHOR_IOCTL(TILER_HEAP_DESTROY, tiler_heap_destroy, DRM_RENDER_ALLOW),
> > >  	PANTHOR_IOCTL(GROUP_SUBMIT, group_submit, DRM_RENDER_ALLOW),
> > > +	PANTHOR_IOCTL(LABEL_BO, label_bo, DRM_RENDER_ALLOW),
> > >  };
> > >
> > >  static int panthor_mmap(struct file *filp, struct vm_area_struct *vma)
> > > @@ -1508,6 +1538,7 @@ static void panthor_debugfs_init(struct drm_minor *minor)
> > >   * - 1.2 - adds DEV_QUERY_GROUP_PRIORITIES_INFO query
> > >   *       - adds PANTHOR_GROUP_PRIORITY_REALTIME priority
> > >   * - 1.3 - adds DRM_PANTHOR_GROUP_STATE_INNOCENT flag
> > > + * - 1.4 - adds DRM_IOCTL_PANTHOR_LABEL_BO ioctl
> > >   */
> > >  static const struct drm_driver panthor_drm_driver = {
> > >  	.driver_features = DRIVER_RENDER | DRIVER_GEM | DRIVER_SYNCOBJ |
> > > diff --git a/include/uapi/drm/panthor_drm.h b/include/uapi/drm/panthor_drm.h
> > > index 97e2c4510e69..1a7ed567d36a 100644
> > > --- a/include/uapi/drm/panthor_drm.h
> > > +++ b/include/uapi/drm/panthor_drm.h
> > > @@ -127,6 +127,9 @@ enum drm_panthor_ioctl_id {
> > >
> > >  	/** @DRM_PANTHOR_TILER_HEAP_DESTROY: Destroy a tiler heap. */
> > >  	DRM_PANTHOR_TILER_HEAP_DESTROY,
> > > +
> > > +	/** @DRM_PANTHOR_LABEL_BO: Label a BO. */
> > > +	DRM_PANTHOR_LABEL_BO,  
> >
> > DRM_PANTHOR_BO_SET_LABEL to follow the DRM_PANTHOR_<object>_<action>
> > naming scheme used in this file.
> >
> > I'd also be tempted to introduce a DRM_PANTHOR_BO_GET_LABEL ioctl while
> > we're at it.  
> 
> I thought of this too, but I was a bit reluctant because at present there are no UM
> driver users who need this functionality.

I guess the labeling done in mesa could be made to use GEM labels if
the feature is supported. And honestly, I hate the idea of having an
half-baked implementation allowing the user to set a label with no way
to retrieve this label back. Can we at least change the name such that
we can later add a GET_LABEL ioctl?

> 
> > >  };
> > >
> > >  /**
> > > @@ -977,6 +980,15 @@ struct drm_panthor_tiler_heap_destroy {
> > >  	__u32 pad;
> > >  };
> > >
> > > +/**
> > > + * struct drm_panthor_label_bo - Arguments passed to DRM_IOCTL_PANTHOR_LABEL_BO
> > > + */
> > > +struct drm_panthor_label_bo {
> > > +	__u32 handle;
> > > +	__u32 len;
> > > +	__u64 label;  
> >
> > Can you document these fields?
> >  
> > > +};
> > > +
> > >  /**
> > >   * DRM_IOCTL_PANTHOR() - Build a Panthor IOCTL number
> > >   * @__access: Access type. Must be R, W or RW.
> > > @@ -1019,6 +1031,8 @@ enum {
> > >  		DRM_IOCTL_PANTHOR(WR, TILER_HEAP_CREATE, tiler_heap_create),
> > >  	DRM_IOCTL_PANTHOR_TILER_HEAP_DESTROY =
> > >  		DRM_IOCTL_PANTHOR(WR, TILER_HEAP_DESTROY, tiler_heap_destroy),
> > > +	DRM_IOCTL_PANTHOR_LABEL_BO =
> > > +		DRM_IOCTL_PANTHOR(WR, LABEL_BO, label_bo),
> > >  };
> > >
> > >  #if defined(__cplusplus)  
> 
> 
> Adrian Larumbe


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 4/4] drm/panthor: Display heap chunk entries in DebugFS GEMS file
  2025-03-19 13:18     ` Adrián Larumbe
@ 2025-03-19 16:39       ` Boris Brezillon
  0 siblings, 0 replies; 14+ messages in thread
From: Boris Brezillon @ 2025-03-19 16:39 UTC (permalink / raw)
  To: Adrián Larumbe
  Cc: Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, kernel, dri-devel,
	linux-kernel

On Wed, 19 Mar 2025 13:18:53 +0000
Adrián Larumbe <adrian.larumbe@collabora.com> wrote:

> On 17.03.2025 09:31, Boris Brezillon wrote:
> > On Sun, 16 Mar 2025 21:51:35 +0000
> > Adrián Larumbe <adrian.larumbe@collabora.com> wrote:
> >  
> > > Expand the driver's DebugFS GEMS file to display entries for the heap
> > > chunks' GEM objects, both those allocated at heap creation time through an
> > > ioctl(), or in response to a tiler OOM event.
> > >
> > > Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
> > > ---
> > >  drivers/gpu/drm/panthor/panthor_heap.c | 15 +++++++++++++++
> > >  1 file changed, 15 insertions(+)
> > >
> > > diff --git a/drivers/gpu/drm/panthor/panthor_heap.c b/drivers/gpu/drm/panthor/panthor_heap.c
> > > index db0285ce5812..520d1fcf5c36 100644
> > > --- a/drivers/gpu/drm/panthor/panthor_heap.c
> > > +++ b/drivers/gpu/drm/panthor/panthor_heap.c
> > > @@ -139,6 +139,10 @@ static int panthor_alloc_heap_chunk(struct panthor_device *ptdev,
> > >  	struct panthor_heap_chunk *chunk;
> > >  	struct panthor_heap_chunk_header *hdr;
> > >  	int ret;
> > > +#ifdef CONFIG_DEBUG_FS
> > > +	struct panthor_gem_object *obj;
> > > +	const char *label;
> > > +#endif
> > >
> > >  	chunk = kmalloc(sizeof(*chunk), GFP_KERNEL);
> > >  	if (!chunk)
> > > @@ -180,6 +184,17 @@ static int panthor_alloc_heap_chunk(struct panthor_device *ptdev,
> > >  	heap->chunk_count++;
> > >  	mutex_unlock(&heap->lock);
> > >
> > > +#ifdef CONFIG_DEBUG_FS
> > > +	obj = to_panthor_bo(chunk->bo->obj);
> > > +
> > > +	mutex_lock(&ptdev->gems_lock);
> > > +	list_add_tail(&obj->gems_node, &ptdev->gems);
> > > +	mutex_unlock(&ptdev->gems_lock);
> > > +
> > > +	label = kstrdup_const("\"Tiler heap chunk\"", GFP_KERNEL);  
> >
> > Do we really need the extra quotes around 'Tiler heap chunk'?  
> 
> We want them quoted like this so that the BO name can be told apart from the
> the extra tagging information (like modifiers) and any suffix sent down from gl

Feels like you want the kernel to use a format that's used by mesa but
not really standardized. What happens if we decide to change the
formatting there? Suddenly, kernel BOs become the outliers again, and
you're back to the inconsistency you were trying to avoid. My
recommendation would be to keep kernel BO labels simple (just a regular
string, no quoting, no extra props) and let the debugfs printer
segregate kernel BOs from user BOs to make the distinction clear.

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2025-03-19 16:39 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-16 21:51 [PATCH 0/4] Panthor BO tagging and GEMS debug display Adrián Larumbe
2025-03-16 21:51 ` [PATCH 1/4] drm/panthor: Introduce BO labeling Adrián Larumbe
2025-03-17  7:45   ` Boris Brezillon
2025-03-16 21:51 ` [PATCH 2/4] drm/panthor: Add driver IOCTL for setting BO labels Adrián Larumbe
2025-03-17  7:50   ` Boris Brezillon
2025-03-19 13:49     ` Adrián Larumbe
2025-03-19 16:28       ` Boris Brezillon
2025-03-17  7:54   ` Boris Brezillon
2025-03-16 21:51 ` [PATCH 3/4] drm/panthor: show device-wide list of DRM GEM objects over DebugFS Adrián Larumbe
2025-03-17  8:26   ` Boris Brezillon
2025-03-16 21:51 ` [PATCH 4/4] drm/panthor: Display heap chunk entries in DebugFS GEMS file Adrián Larumbe
2025-03-17  8:31   ` Boris Brezillon
2025-03-19 13:18     ` Adrián Larumbe
2025-03-19 16:39       ` Boris Brezillon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox