Skip to contentSkip to conversation

drm: move the debugfs accel driver code to drm layer

PATCH Superseded Sunil Khatri 4 participants 16 messages Jun 24, 2025 – Jun 26, 2025

Subsystems (4)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/5 drm: move the debugfs accel driver code to drm layer

move the debugfs accel driver code to the drm layer. This is first inline change to move the debugfs related changes for drm to drm_debugfs.c

---
 drivers/accel/drm_accel.c | 16 ----------------
 drivers/gpu/drm/drm_drv.c |  6 +++++-
 include/drm/drm_accel.h   |  5 -----
 3 files changed, 5 insertions(+), 22 deletions(-)
drivers/accel/drm_accel.c +0 -16
index aa826033b0ce..ca3357acd127 100644
@@ -20,8 +20,6 @@
 
 DEFINE_XARRAY_ALLOC(accel_minors_xa);
 
-static struct dentry *accel_debugfs_root;
-
 static const struct device_type accel_sysfs_device_minor = {
 	.name = "accel_minor"
 };
@@ -73,17 +71,6 @@ static const struct drm_info_list accel_debugfs_list[] = {
 };
 #define ACCEL_DEBUGFS_ENTRIES ARRAY_SIZE(accel_debugfs_list)
 
-/**
- * accel_debugfs_init() - Initialize debugfs for device
- * @dev: Pointer to the device instance.
- *
- * This function creates a root directory for the device in debugfs.
- */
-void accel_debugfs_init(struct drm_device *dev)
-{
-	drm_debugfs_dev_init(dev, accel_debugfs_root);
-}
-
 /**
  * accel_debugfs_register() - Register debugfs for device
  * @dev: Pointer to the device instance.
@@ -194,7 +181,6 @@ static const struct file_operations accel_stub_fops = {
 void accel_core_exit(void)
 {
 	unregister_chrdev(ACCEL_MAJOR, "accel");
-	debugfs_remove(accel_debugfs_root);
 	accel_sysfs_destroy();
 	WARN_ON(!xa_empty(&accel_minors_xa));
 }
@@ -209,8 +195,6 @@ int __init accel_core_init(void)
 		goto error;
 	}
 
-	accel_debugfs_root = debugfs_create_dir("accel", NULL);
-
 	ret = register_chrdev(ACCEL_MAJOR, "accel", &accel_stub_fops);
 	if (ret < 0)
 		DRM_ERROR("Cannot register ACCEL major: %d\n", ret);
drivers/gpu/drm/drm_drv.c +5 -1
index 17fc5dc708f4..5d57b622f9aa 100644
@@ -70,6 +70,7 @@ DEFINE_XARRAY_ALLOC(drm_minors_xa);
 static bool drm_core_init_complete;
 
 static struct dentry *drm_debugfs_root;
+static struct dentry *accel_debugfs_root;
 
 DEFINE_STATIC_SRCU(drm_unplug_srcu);
 
@@ -752,7 +753,7 @@ static int drm_dev_init(struct drm_device *dev,
 	}
 
 	if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL))
-		accel_debugfs_init(dev);
+		drm_debugfs_dev_init(dev, accel_debugfs_root);
 	else
 		drm_debugfs_dev_init(dev, drm_debugfs_root);
 
@@ -1166,6 +1167,7 @@ static void drm_core_exit(void)
 {
 	drm_privacy_screen_lookup_exit();
 	drm_panic_exit();
+	debugfs_remove(accel_debugfs_root);
 	accel_core_exit();
 	unregister_chrdev(DRM_MAJOR, "drm");
 	debugfs_remove(drm_debugfs_root);
@@ -1193,6 +1195,8 @@ static int __init drm_core_init(void)
 	if (ret < 0)
 		goto error;
 
+	accel_debugfs_root = debugfs_create_dir("accel", NULL);
+
 	ret = accel_core_init();
 	if (ret < 0)
 		goto error;
include/drm/drm_accel.h +0 -5
index 038ccb02f9a3..20a665ec6f16 100644
@@ -58,7 +58,6 @@ void accel_core_exit(void);
 int accel_core_init(void);
 void accel_set_device_instance_params(struct device *kdev, int index);
 int accel_open(struct inode *inode, struct file *filp);
-void accel_debugfs_init(struct drm_device *dev);
 void accel_debugfs_register(struct drm_device *dev);
 
 #else
@@ -77,10 +76,6 @@ static inline void accel_set_device_instance_params(struct device *kdev, int ind
 {
 }
 
-static inline void accel_debugfs_init(struct drm_device *dev)
-{
-}
-
 static inline void accel_debugfs_register(struct drm_device *dev)
 {
 }
Signature · 1 line
2.34.1
#1 lore raw

PATCH v5 2/5 drm: move debugfs functionality from drm_drv.c to drm_debugfs.c

move the debugfs functions from drm_drv.c to drm_debugfs.c

move this root node to the debugfs for easily handling of future requirements to add more information in the root directory and one of which is planned to have directories for each client in the root directory which is dri.

---
 drivers/gpu/drm/drm_debugfs.c  | 37 ++++++++++++++++++++++++++++------
 drivers/gpu/drm/drm_drv.c      | 19 ++++++-----------
 drivers/gpu/drm/drm_internal.h |  6 ++----
 include/drm/drm_drv.h          | 24 ++++++++++++++++++++--
 4 files changed, 61 insertions(+), 25 deletions(-)
drivers/gpu/drm/drm_debugfs.c +31 -6
index 2d43bda82887..a227903c29c4 100644
@@ -44,6 +44,9 @@
 #include "drm_crtc_internal.h"
 #include "drm_internal.h"
 
+static struct dentry *accel_debugfs_root;
+static struct dentry *drm_debugfs_root;
+
 /***************************************************
  * Initialization, etc.
  **************************************************/
@@ -286,16 +289,39 @@ int drm_debugfs_remove_files(const struct drm_info_list *files, int count,
 }
 EXPORT_SYMBOL(drm_debugfs_remove_files);
 
+void drm_debugfs_init_root(void)
+{
+	drm_debugfs_root = debugfs_create_dir("dri", NULL);
+}
+
+void drm_debugfs_remove_root(void)
+{
+	debugfs_remove(drm_debugfs_root);
+}
+
+void drm_debugfs_init_accel_root(void)
+{
+	accel_debugfs_root = debugfs_create_dir("accel", NULL);
+}
+
+void drm_debugfs_remove_accel_root(void)
+{
+	debugfs_remove(accel_debugfs_root);
+}
+
+
 /**
  * drm_debugfs_dev_init - create debugfs directory for the device
  * @dev: the device which we want to create the directory for
- * @root: the parent directory depending on the device type
  *
  * Creates the debugfs directory for the device under the given root directory.
  */
-void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root)
+void drm_debugfs_dev_init(struct drm_device *dev)
 {
-	dev->debugfs_root = debugfs_create_dir(dev->unique, root);
+	if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL))
+		dev->debugfs_root = debugfs_create_dir(dev->unique, accel_debugfs_root);
+	else
+		dev->debugfs_root = debugfs_create_dir(dev->unique, drm_debugfs_root);
 }
 
 /**
@@ -322,14 +348,13 @@ void drm_debugfs_dev_register(struct drm_device *dev)
 		drm_atomic_debugfs_init(dev);
 }
 
-int drm_debugfs_register(struct drm_minor *minor, int minor_id,
-			 struct dentry *root)
+int drm_debugfs_register(struct drm_minor *minor, int minor_id)
 {
 	struct drm_device *dev = minor->dev;
 	char name[64];
 
 	sprintf(name, "%d", minor_id);
-	minor->debugfs_symlink = debugfs_create_symlink(name, root,
+	minor->debugfs_symlink = debugfs_create_symlink(name, drm_debugfs_root,
 							dev->unique);
 
 	/* TODO: Only for compatibility with drivers */
drivers/gpu/drm/drm_drv.c +6 -13
index 5d57b622f9aa..db19aef9cfd2 100644
@@ -69,9 +69,6 @@ DEFINE_XARRAY_ALLOC(drm_minors_xa);
  */
 static bool drm_core_init_complete;
 
-static struct dentry *drm_debugfs_root;
-static struct dentry *accel_debugfs_root;
-
 DEFINE_STATIC_SRCU(drm_unplug_srcu);
 
 /*
@@ -184,8 +181,7 @@ static int drm_minor_register(struct drm_device *dev, enum drm_minor_type type)
 		return 0;
 
 	if (minor->type != DRM_MINOR_ACCEL) {
-		ret = drm_debugfs_register(minor, minor->index,
-					   drm_debugfs_root);
+		ret = drm_debugfs_register(minor, minor->index);
 		if (ret) {
 			DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n");
 			goto err_debugfs;
@@ -752,10 +748,7 @@ static int drm_dev_init(struct drm_device *dev,
 		goto err;
 	}
 
-	if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL))
-		drm_debugfs_dev_init(dev, accel_debugfs_root);
-	else
-		drm_debugfs_dev_init(dev, drm_debugfs_root);
+	drm_debugfs_dev_init(dev);
 
 	return 0;
 
@@ -1167,10 +1160,10 @@ static void drm_core_exit(void)
 {
 	drm_privacy_screen_lookup_exit();
 	drm_panic_exit();
-	debugfs_remove(accel_debugfs_root);
+	drm_debugfs_remove_accel_root();
 	accel_core_exit();
 	unregister_chrdev(DRM_MAJOR, "drm");
-	debugfs_remove(drm_debugfs_root);
+	drm_debugfs_remove_root();
 	drm_sysfs_destroy();
 	WARN_ON(!xa_empty(&drm_minors_xa));
 	drm_connector_ida_destroy();
@@ -1189,13 +1182,13 @@ static int __init drm_core_init(void)
 		goto error;
 	}
 
-	drm_debugfs_root = debugfs_create_dir("dri", NULL);
+	drm_debugfs_init_root();
 
 	ret = register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops);
 	if (ret < 0)
 		goto error;
 
-	accel_debugfs_root = debugfs_create_dir("accel", NULL);
+	drm_debugfs_init_accel_root();
 
 	ret = accel_core_init();
 	if (ret < 0)
drivers/gpu/drm/drm_internal.h +2 -4
index b2b6a8e49dda..d2d8e72f32d9 100644
@@ -186,8 +186,7 @@ void drm_gem_vunmap(struct drm_gem_object *obj, struct iosys_map *map);
 #if defined(CONFIG_DEBUG_FS)
 void drm_debugfs_dev_fini(struct drm_device *dev);
 void drm_debugfs_dev_register(struct drm_device *dev);
-int drm_debugfs_register(struct drm_minor *minor, int minor_id,
-			 struct dentry *root);
+int drm_debugfs_register(struct drm_minor *minor, int minor_id);
 void drm_debugfs_unregister(struct drm_minor *minor);
 void drm_debugfs_connector_add(struct drm_connector *connector);
 void drm_debugfs_connector_remove(struct drm_connector *connector);
@@ -205,8 +204,7 @@ static inline void drm_debugfs_dev_register(struct drm_device *dev)
 {
 }
 
-static inline int drm_debugfs_register(struct drm_minor *minor, int minor_id,
-				       struct dentry *root)
+static inline int drm_debugfs_register(struct drm_minor *minor, int minor_id)
 {
 	return 0;
 }
include/drm/drm_drv.h +22 -2
index a43d707b5f36..7964dd878144 100644
@@ -566,9 +566,29 @@ static inline bool drm_firmware_drivers_only(void)
 }
 
 #if defined(CONFIG_DEBUG_FS)
-void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root);
+void drm_debugfs_dev_init(struct drm_device *dev);
+void drm_debugfs_init_root(void);
+void drm_debugfs_remove_root(void);
+void drm_debugfs_init_accel_root(void);
+void drm_debugfs_remove_accel_root(void);
 #else
-static inline void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root)
+static inline void drm_debugfs_dev_init(struct drm_device *dev)
+{
+}
+
+static inline void drm_debugfs_init_root(void)
+{
+}
+
+static inline void drm_debugfs_remove_root(void)
+{
+}
+
+static inline void drm_debugfs_init_accel_root(void)
+{
+}
+
+static inline void drm_debugfs_remove_accel_root(void)
 {
 }
 #endif
Signature · 1 line
2.34.1
maintainer
#2 lore raw

Re: [PATCH v5 2/5] drm: move debugfs functionality from drm_drv.c to drm_debugfs.c

Quoted 39 lines · Sunil Khatri

move the debugfs functions from drm_drv.c to drm_debugfs.c

move this root node to the debugfs for easily handling of future requirements to add more information in the root directory and one of which is planned to have directories for each client in the root directory which is dri.

---
 drivers/gpu/drm/drm_debugfs.c  | 37 ++++++++++++++++++++++++++++------
 drivers/gpu/drm/drm_drv.c      | 19 ++++++-----------
 drivers/gpu/drm/drm_internal.h |  6 ++----
 include/drm/drm_drv.h          | 24 ++++++++++++++++++++--
 4 files changed, 61 insertions(+), 25 deletions(-)
drivers/gpu/drm/drm_debugfs.c +7 -0
index 2d43bda82887..a227903c29c4 100644
@@ -44,6 +44,9 @@
 #include "drm_crtc_internal.h"
 #include "drm_internal.h"
 
+static struct dentry *accel_debugfs_root;
+static struct dentry *drm_debugfs_root;
+
 /***************************************************
  * Initialization, etc.
  **************************************************/
@@ -286,16 +289,39 @@ int drm_debugfs_remove_files(const struct drm_info_list *files, int count,
 }
 EXPORT_SYMBOL(drm_debugfs_remove_files);
 
+void drm_debugfs_init_root(void)
+{
+	drm_debugfs_root = debugfs_create_dir("dri", NULL);
+}

drivers/gpu/drm/drm_debugfs.c int drm_debugfs_remove_files(const struct drm_info_list *files, int count, · line 305

Quoted 10 lines
drivers/gpu/drm/drm_debugfs.c +10 -0
+
+void drm_debugfs_remove_root(void)
+{
+	debugfs_remove(drm_debugfs_root);
+}
+
+void drm_debugfs_init_accel_root(void)
+{
+	accel_debugfs_root = debugfs_create_dir("accel", NULL);
+}

I think that this can be done in just the drm_debugfs_init_root() function. No need to split it into two functions.

Apart from that looks good to me as well.

Regards,
Christian.

Quoted 167 lines
drivers/gpu/drm/drm_debugfs.c +14 -6
+
+void drm_debugfs_remove_accel_root(void)
+{
+	debugfs_remove(accel_debugfs_root);
+}
+
+
 /**
  * drm_debugfs_dev_init - create debugfs directory for the device
  * @dev: the device which we want to create the directory for
- * @root: the parent directory depending on the device type
  *
  * Creates the debugfs directory for the device under the given root directory.
  */
-void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root)
+void drm_debugfs_dev_init(struct drm_device *dev)
 {
-	dev->debugfs_root = debugfs_create_dir(dev->unique, root);
+	if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL))
+		dev->debugfs_root = debugfs_create_dir(dev->unique, accel_debugfs_root);
+	else
+		dev->debugfs_root = debugfs_create_dir(dev->unique, drm_debugfs_root);
 }
 
 /**
@@ -322,14 +348,13 @@ void drm_debugfs_dev_register(struct drm_device *dev)
 		drm_atomic_debugfs_init(dev);
 }
 
-int drm_debugfs_register(struct drm_minor *minor, int minor_id,
-			 struct dentry *root)
+int drm_debugfs_register(struct drm_minor *minor, int minor_id)
 {
 	struct drm_device *dev = minor->dev;
 	char name[64];
 
 	sprintf(name, "%d", minor_id);
-	minor->debugfs_symlink = debugfs_create_symlink(name, root,
+	minor->debugfs_symlink = debugfs_create_symlink(name, drm_debugfs_root,
 							dev->unique);
 
 	/* TODO: Only for compatibility with drivers */
drivers/gpu/drm/drm_drv.c +6 -13
index 5d57b622f9aa..db19aef9cfd2 100644
@@ -69,9 +69,6 @@ DEFINE_XARRAY_ALLOC(drm_minors_xa);
  */
 static bool drm_core_init_complete;
 
-static struct dentry *drm_debugfs_root;
-static struct dentry *accel_debugfs_root;
-
 DEFINE_STATIC_SRCU(drm_unplug_srcu);
 
 /*
@@ -184,8 +181,7 @@ static int drm_minor_register(struct drm_device *dev, enum drm_minor_type type)
 		return 0;
 
 	if (minor->type != DRM_MINOR_ACCEL) {
-		ret = drm_debugfs_register(minor, minor->index,
-					   drm_debugfs_root);
+		ret = drm_debugfs_register(minor, minor->index);
 		if (ret) {
 			DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n");
 			goto err_debugfs;
@@ -752,10 +748,7 @@ static int drm_dev_init(struct drm_device *dev,
 		goto err;
 	}
 
-	if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL))
-		drm_debugfs_dev_init(dev, accel_debugfs_root);
-	else
-		drm_debugfs_dev_init(dev, drm_debugfs_root);
+	drm_debugfs_dev_init(dev);
 
 	return 0;
 
@@ -1167,10 +1160,10 @@ static void drm_core_exit(void)
 {
 	drm_privacy_screen_lookup_exit();
 	drm_panic_exit();
-	debugfs_remove(accel_debugfs_root);
+	drm_debugfs_remove_accel_root();
 	accel_core_exit();
 	unregister_chrdev(DRM_MAJOR, "drm");
-	debugfs_remove(drm_debugfs_root);
+	drm_debugfs_remove_root();
 	drm_sysfs_destroy();
 	WARN_ON(!xa_empty(&drm_minors_xa));
 	drm_connector_ida_destroy();
@@ -1189,13 +1182,13 @@ static int __init drm_core_init(void)
 		goto error;
 	}
 
-	drm_debugfs_root = debugfs_create_dir("dri", NULL);
+	drm_debugfs_init_root();
 
 	ret = register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops);
 	if (ret < 0)
 		goto error;
 
-	accel_debugfs_root = debugfs_create_dir("accel", NULL);
+	drm_debugfs_init_accel_root();
 
 	ret = accel_core_init();
 	if (ret < 0)
drivers/gpu/drm/drm_internal.h +2 -4
index b2b6a8e49dda..d2d8e72f32d9 100644
@@ -186,8 +186,7 @@ void drm_gem_vunmap(struct drm_gem_object *obj, struct iosys_map *map);
 #if defined(CONFIG_DEBUG_FS)
 void drm_debugfs_dev_fini(struct drm_device *dev);
 void drm_debugfs_dev_register(struct drm_device *dev);
-int drm_debugfs_register(struct drm_minor *minor, int minor_id,
-			 struct dentry *root);
+int drm_debugfs_register(struct drm_minor *minor, int minor_id);
 void drm_debugfs_unregister(struct drm_minor *minor);
 void drm_debugfs_connector_add(struct drm_connector *connector);
 void drm_debugfs_connector_remove(struct drm_connector *connector);
@@ -205,8 +204,7 @@ static inline void drm_debugfs_dev_register(struct drm_device *dev)
 {
 }
 
-static inline int drm_debugfs_register(struct drm_minor *minor, int minor_id,
-				       struct dentry *root)
+static inline int drm_debugfs_register(struct drm_minor *minor, int minor_id)
 {
 	return 0;
 }
include/drm/drm_drv.h +22 -2
index a43d707b5f36..7964dd878144 100644
@@ -566,9 +566,29 @@ static inline bool drm_firmware_drivers_only(void)
 }
 
 #if defined(CONFIG_DEBUG_FS)
-void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root);
+void drm_debugfs_dev_init(struct drm_device *dev);
+void drm_debugfs_init_root(void);
+void drm_debugfs_remove_root(void);
+void drm_debugfs_init_accel_root(void);
+void drm_debugfs_remove_accel_root(void);
 #else
-static inline void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root)
+static inline void drm_debugfs_dev_init(struct drm_device *dev)
+{
+}
+
+static inline void drm_debugfs_init_root(void)
+{
+}
+
+static inline void drm_debugfs_remove_root(void)
+{
+}
+
+static inline void drm_debugfs_init_accel_root(void)
+{
+}
+
+static inline void drm_debugfs_remove_accel_root(void)
 {
 }
 #endif
#3 lore raw

Re: [PATCH v5 2/5] drm: move debugfs functionality from drm_drv.c to drm_debugfs.c

Quoted 37 lines · Christian König
Quoted 35 lines · Sunil Khatri

move the debugfs functions from drm_drv.c to drm_debugfs.c

move this root node to the debugfs for easily handling of future requirements to add more information in the root directory and one of which is planned to have directories for each client in the root directory which is dri.

---
  drivers/gpu/drm/drm_debugfs.c  | 37 ++++++++++++++++++++++++++++------
  drivers/gpu/drm/drm_drv.c      | 19 ++++++-----------
  drivers/gpu/drm/drm_internal.h |  6 ++----
  include/drm/drm_drv.h          | 24 ++++++++++++++++++++--
  4 files changed, 61 insertions(+), 25 deletions(-)
drivers/gpu/drm/drm_debugfs.c +3 -0
index 2d43bda82887..a227903c29c4 100644
@@ -44,6 +44,9 @@
  #include "drm_crtc_internal.h"
  #include "drm_internal.h"
 
+static struct dentry *accel_debugfs_root;
+static struct dentry *drm_debugfs_root;
+
  /***************************************************
   * Initialization, etc.
   **************************************************/
@@ -286,16 +289,39 @@ int drm_debugfs_remove_files(const struct drm_info_list *files, int count,
  }
  EXPORT_SYMBOL(drm_debugfs_remove_files);
 
Quoted 15 lines
Quoted 4 lines
drivers/gpu/drm/drm_debugfs.c +4 -0
+void drm_debugfs_init_root(void)
+{
+	drm_debugfs_root = debugfs_create_dir("dri", NULL);
+}

drivers/gpu/drm/drm_debugfs.c int drm_debugfs_remove_files(const struct drm_info_list *files, int count, · line 305

Quoted 10 lines
drivers/gpu/drm/drm_debugfs.c +10 -0
+
+void drm_debugfs_remove_root(void)
+{
+	debugfs_remove(drm_debugfs_root);
+}
+
+void drm_debugfs_init_accel_root(void)
+{
+	accel_debugfs_root = debugfs_create_dir("accel", NULL);
+}

I think that this can be done in just the drm_debugfs_init_root() function. No need to split it into two functions.

Sure, Noted

Regards
Sunil

Quoted 173 lines

Apart from that looks good to me as well.

Regards,
Christian.

Quoted 167 lines
drivers/gpu/drm/drm_debugfs.c +14 -6
+
+void drm_debugfs_remove_accel_root(void)
+{
+	debugfs_remove(accel_debugfs_root);
+}
+
+
  /**
   * drm_debugfs_dev_init - create debugfs directory for the device
   * @dev: the device which we want to create the directory for
- * @root: the parent directory depending on the device type
   *
   * Creates the debugfs directory for the device under the given root directory.
   */
-void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root)
+void drm_debugfs_dev_init(struct drm_device *dev)
  {
-	dev->debugfs_root = debugfs_create_dir(dev->unique, root);
+	if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL))
+		dev->debugfs_root = debugfs_create_dir(dev->unique, accel_debugfs_root);
+	else
+		dev->debugfs_root = debugfs_create_dir(dev->unique, drm_debugfs_root);
  }
 
  /**
@@ -322,14 +348,13 @@ void drm_debugfs_dev_register(struct drm_device *dev)
  		drm_atomic_debugfs_init(dev);
  }
 
-int drm_debugfs_register(struct drm_minor *minor, int minor_id,
-			 struct dentry *root)
+int drm_debugfs_register(struct drm_minor *minor, int minor_id)
  {
  	struct drm_device *dev = minor->dev;
  	char name[64];
 
  	sprintf(name, "%d", minor_id);
-	minor->debugfs_symlink = debugfs_create_symlink(name, root,
+	minor->debugfs_symlink = debugfs_create_symlink(name, drm_debugfs_root,
  							dev->unique);
 
  	/* TODO: Only for compatibility with drivers */
drivers/gpu/drm/drm_drv.c +6 -13
index 5d57b622f9aa..db19aef9cfd2 100644
@@ -69,9 +69,6 @@ DEFINE_XARRAY_ALLOC(drm_minors_xa);
   */
  static bool drm_core_init_complete;
 
-static struct dentry *drm_debugfs_root;
-static struct dentry *accel_debugfs_root;
-
  DEFINE_STATIC_SRCU(drm_unplug_srcu);
 
  /*
@@ -184,8 +181,7 @@ static int drm_minor_register(struct drm_device *dev, enum drm_minor_type type)
  		return 0;
 
  	if (minor->type != DRM_MINOR_ACCEL) {
-		ret = drm_debugfs_register(minor, minor->index,
-					   drm_debugfs_root);
+		ret = drm_debugfs_register(minor, minor->index);
  		if (ret) {
  			DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n");
  			goto err_debugfs;
@@ -752,10 +748,7 @@ static int drm_dev_init(struct drm_device *dev,
  		goto err;
  	}
 
-	if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL))
-		drm_debugfs_dev_init(dev, accel_debugfs_root);
-	else
-		drm_debugfs_dev_init(dev, drm_debugfs_root);
+	drm_debugfs_dev_init(dev);
 
  	return 0;
 
@@ -1167,10 +1160,10 @@ static void drm_core_exit(void)
  {
  	drm_privacy_screen_lookup_exit();
  	drm_panic_exit();
-	debugfs_remove(accel_debugfs_root);
+	drm_debugfs_remove_accel_root();
  	accel_core_exit();
  	unregister_chrdev(DRM_MAJOR, "drm");
-	debugfs_remove(drm_debugfs_root);
+	drm_debugfs_remove_root();
  	drm_sysfs_destroy();
  	WARN_ON(!xa_empty(&drm_minors_xa));
  	drm_connector_ida_destroy();
@@ -1189,13 +1182,13 @@ static int __init drm_core_init(void)
  		goto error;
  	}
 
-	drm_debugfs_root = debugfs_create_dir("dri", NULL);
+	drm_debugfs_init_root();
 
  	ret = register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops);
  	if (ret < 0)
  		goto error;
 
-	accel_debugfs_root = debugfs_create_dir("accel", NULL);
+	drm_debugfs_init_accel_root();
 
  	ret = accel_core_init();
  	if (ret < 0)
drivers/gpu/drm/drm_internal.h +2 -4
index b2b6a8e49dda..d2d8e72f32d9 100644
@@ -186,8 +186,7 @@ void drm_gem_vunmap(struct drm_gem_object *obj, struct iosys_map *map);
  #if defined(CONFIG_DEBUG_FS)
  void drm_debugfs_dev_fini(struct drm_device *dev);
  void drm_debugfs_dev_register(struct drm_device *dev);
-int drm_debugfs_register(struct drm_minor *minor, int minor_id,
-			 struct dentry *root);
+int drm_debugfs_register(struct drm_minor *minor, int minor_id);
  void drm_debugfs_unregister(struct drm_minor *minor);
  void drm_debugfs_connector_add(struct drm_connector *connector);
  void drm_debugfs_connector_remove(struct drm_connector *connector);
@@ -205,8 +204,7 @@ static inline void drm_debugfs_dev_register(struct drm_device *dev)
  {
  }
 
-static inline int drm_debugfs_register(struct drm_minor *minor, int minor_id,
-				       struct dentry *root)
+static inline int drm_debugfs_register(struct drm_minor *minor, int minor_id)
  {
  	return 0;
  }
include/drm/drm_drv.h +22 -2
index a43d707b5f36..7964dd878144 100644
@@ -566,9 +566,29 @@ static inline bool drm_firmware_drivers_only(void)
  }
 
  #if defined(CONFIG_DEBUG_FS)
-void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root);
+void drm_debugfs_dev_init(struct drm_device *dev);
+void drm_debugfs_init_root(void);
+void drm_debugfs_remove_root(void);
+void drm_debugfs_init_accel_root(void);
+void drm_debugfs_remove_accel_root(void);
  #else
-static inline void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root)
+static inline void drm_debugfs_dev_init(struct drm_device *dev)
+{
+}
+
+static inline void drm_debugfs_init_root(void)
+{
+}
+
+static inline void drm_debugfs_remove_root(void)
+{
+}
+
+static inline void drm_debugfs_init_accel_root(void)
+{
+}
+
+static inline void drm_debugfs_remove_accel_root(void)
  {
  }
  #endif
#4 lore raw

PATCH v5 3/5 drm: add debugfs support on per client-id basis

In reply to Sunil Khatri

add support to add a directory for each client-id with root at the dri level. Since the clients are unique and not just related to one single drm device, so it makes more sense to add all the client based nodes with root as dri.

Also create a symlink back to the parent drm device from each client.

---
 drivers/gpu/drm/drm_debugfs.c | 26 ++++++++++++++++++++++++++
 drivers/gpu/drm/drm_file.c    |  6 ++++++
 include/drm/drm_debugfs.h     | 11 +++++++++++
 include/drm/drm_file.h        |  7 +++++++
 4 files changed, 50 insertions(+)
drivers/gpu/drm/drm_debugfs.c +26 -0
index a227903c29c4..ebdf60665b86 100644
@@ -309,6 +309,32 @@ void drm_debugfs_remove_accel_root(void)
 	debugfs_remove(accel_debugfs_root);
 }
 
+void drm_debugfs_clients_add(struct drm_file *file)
+{
+	char *client;
+
+	client = kasprintf(GFP_KERNEL, "client-%llu", file->client_id);
+	if (!client)
+		return;
+
+	/* Create a debugfs directory for the client in root on drm debugfs */
+	file->debugfs_client = debugfs_create_dir(client, drm_debugfs_root);
+	kfree(client);
+
+	client = kasprintf(GFP_KERNEL, "../%s", file->minor->dev->unique);
+	if (!client)
+		return;
+
+	/* Create a link from client_id to the drm device this client id belongs to */
+	debugfs_create_symlink("device", file->debugfs_client, client);
+	kfree(client);
+}
+
+void drm_debugfs_clients_remove(struct drm_file *file)
+{
+	debugfs_remove_recursive(file->debugfs_client);
+	file->debugfs_client = NULL;
+}
 
 /**
  * drm_debugfs_dev_init - create debugfs directory for the device
drivers/gpu/drm/drm_file.c +6 -0
index 06ba6dcbf5ae..17b803ab119e 100644
@@ -45,6 +45,7 @@
 #include <drm/drm_file.h>
 #include <drm/drm_gem.h>
 #include <drm/drm_print.h>
+#include <drm/drm_debugfs.h>
 
 #include "drm_crtc_internal.h"
 #include "drm_internal.h"
@@ -167,6 +168,8 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor)
 
 	drm_prime_init_file_private(&file->prime);
 
+	drm_debugfs_clients_add(file);
+
 	if (dev->driver->open) {
 		ret = dev->driver->open(dev, file);
 		if (ret < 0)
@@ -181,6 +184,8 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor)
 		drm_syncobj_release(file);
 	if (drm_core_check_feature(dev, DRIVER_GEM))
 		drm_gem_release(dev, file);
+
+	drm_debugfs_clients_remove(file);
 	put_pid(rcu_access_pointer(file->pid));
 	kfree(file);
 
@@ -236,6 +241,7 @@ void drm_file_free(struct drm_file *file)
 		     atomic_read(&dev->open_count));
 
 	drm_events_release(file);
+	drm_debugfs_clients_remove(file);
 
 	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
 		drm_fb_release(file);
include/drm/drm_debugfs.h +11 -0
index cf06cee4343f..2b3767ad8f5d 100644
@@ -153,6 +153,9 @@ void drm_debugfs_add_files(struct drm_device *dev,
 
 int drm_debugfs_gpuva_info(struct seq_file *m,
 			   struct drm_gpuvm *gpuvm);
+
+void drm_debugfs_clients_add(struct drm_file *file);
+void drm_debugfs_clients_remove(struct drm_file *file);
 #else
 static inline void drm_debugfs_create_files(const struct drm_info_list *files,
 					    int count, struct dentry *root,
@@ -181,6 +184,14 @@ static inline int drm_debugfs_gpuva_info(struct seq_file *m,
 {
 	return 0;
 }
+
+static void drm_debugfs_clients_add(struct drm_file *file)
+{
+}
+
+static void drm_debugfs_clients_remove(struct drm_file *file)
+{
+}
 #endif
 
 #endif /* _DRM_DEBUGFS_H_ */
include/drm/drm_file.h +7 -0
index 5c3b2aa3e69d..eab7546aad79 100644
@@ -400,6 +400,13 @@ struct drm_file {
 	 * @client_name_lock: Protects @client_name.
 	 */
 	struct mutex client_name_lock;
+
+	/**
+	 * @debugfs_client:
+	 *
+	 * debugfs directory for each client under a drm node.
+	 */
+	struct dentry *debugfs_client;
 };
 
 /**
Signature · 1 line
2.34.1
maintainer
#5 lore raw

Re: [PATCH v5 3/5] drm: add debugfs support on per client-id basis

Quoted 33 lines · Sunil Khatri

add support to add a directory for each client-id with root at the dri level. Since the clients are unique and not just related to one single drm device, so it makes more sense to add all the client based nodes with root as dri.

Also create a symlink back to the parent drm device from each client.

---
 drivers/gpu/drm/drm_debugfs.c | 26 ++++++++++++++++++++++++++
 drivers/gpu/drm/drm_file.c    |  6 ++++++
 include/drm/drm_debugfs.h     | 11 +++++++++++
 include/drm/drm_file.h        |  7 +++++++
 4 files changed, 50 insertions(+)
drivers/gpu/drm/drm_debugfs.c +8 -0
index a227903c29c4..ebdf60665b86 100644
@@ -309,6 +309,32 @@ void drm_debugfs_remove_accel_root(void)
 	debugfs_remove(accel_debugfs_root);
 }
 
+void drm_debugfs_clients_add(struct drm_file *file)
+{
+	char *client;
+
+	client = kasprintf(GFP_KERNEL, "client-%llu", file->client_id);
+	if (!client)
+		return;
+

drivers/gpu/drm/drm_debugfs.c void drm_debugfs_remove_accel_root(void) · line 329

Quoted 10 lines
drivers/gpu/drm/drm_debugfs.c +10 -0
+	/* Create a debugfs directory for the client in root on drm debugfs */
+	file->debugfs_client = debugfs_create_dir(client, drm_debugfs_root);
+	kfree(client);
+
+	client = kasprintf(GFP_KERNEL, "../%s", file->minor->dev->unique);
+	if (!client)
+		return;
+
+	/* Create a link from client_id to the drm device this client id belongs to */
+	debugfs_create_symlink("device", file->debugfs_client, client);

Mhm, that won't work for accel devices. How should we fix that?

Quoted 42 lines
drivers/gpu/drm/drm_debugfs.c +8 -0
+	kfree(client);
+}
+
+void drm_debugfs_clients_remove(struct drm_file *file)
+{
+	debugfs_remove_recursive(file->debugfs_client);
+	file->debugfs_client = NULL;
+}
 
 /**
  * drm_debugfs_dev_init - create debugfs directory for the device
drivers/gpu/drm/drm_file.c +5 -0
index 06ba6dcbf5ae..17b803ab119e 100644
@@ -45,6 +45,7 @@
 #include <drm/drm_file.h>
 #include <drm/drm_gem.h>
 #include <drm/drm_print.h>
+#include <drm/drm_debugfs.h>
 
 #include "drm_crtc_internal.h"
 #include "drm_internal.h"
@@ -167,6 +168,8 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor)
 
 	drm_prime_init_file_private(&file->prime);
 
+	drm_debugfs_clients_add(file);
+
 	if (dev->driver->open) {
 		ret = dev->driver->open(dev, file);
 		if (ret < 0)
@@ -181,6 +184,8 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor)
 		drm_syncobj_release(file);
 	if (drm_core_check_feature(dev, DRIVER_GEM))
 		drm_gem_release(dev, file);
+
+	drm_debugfs_clients_remove(file);
 	put_pid(rcu_access_pointer(file->pid));
 	kfree(file);
 

drivers/gpu/drm/drm_file.c void drm_file_free(struct drm_file *file) · line 244

Quoted 4 lines
drivers/gpu/drm/drm_file.c +1 -0
@@ -236,6 +241,7 @@ void drm_file_free(struct drm_file *file)
 		     atomic_read(&dev->open_count));
 
 	drm_events_release(file);
+	drm_debugfs_clients_remove(file);

That most likely needs to come even before releasing the events.

Regards,
Christian.

Quoted 50 lines
drivers/gpu/drm/drm_file.c +0 -0
 	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
 		drm_fb_release(file);
include/drm/drm_debugfs.h +11 -0
index cf06cee4343f..2b3767ad8f5d 100644
@@ -153,6 +153,9 @@ void drm_debugfs_add_files(struct drm_device *dev,
 
 int drm_debugfs_gpuva_info(struct seq_file *m,
 			   struct drm_gpuvm *gpuvm);
+
+void drm_debugfs_clients_add(struct drm_file *file);
+void drm_debugfs_clients_remove(struct drm_file *file);
 #else
 static inline void drm_debugfs_create_files(const struct drm_info_list *files,
 					    int count, struct dentry *root,
@@ -181,6 +184,14 @@ static inline int drm_debugfs_gpuva_info(struct seq_file *m,
 {
 	return 0;
 }
+
+static void drm_debugfs_clients_add(struct drm_file *file)
+{
+}
+
+static void drm_debugfs_clients_remove(struct drm_file *file)
+{
+}
 #endif
 
 #endif /* _DRM_DEBUGFS_H_ */
include/drm/drm_file.h +7 -0
index 5c3b2aa3e69d..eab7546aad79 100644
@@ -400,6 +400,13 @@ struct drm_file {
 	 * @client_name_lock: Protects @client_name.
 	 */
 	struct mutex client_name_lock;
+
+	/**
+	 * @debugfs_client:
+	 *
+	 * debugfs directory for each client under a drm node.
+	 */
+	struct dentry *debugfs_client;
 };
 
 /**
#6 lore raw

Re: [PATCH v5 3/5] drm: add debugfs support on per client-id basis

Quoted 37 lines · Christian König
Quoted 36 lines · Sunil Khatri

add support to add a directory for each client-id with root at the dri level. Since the clients are unique and not just related to one single drm device, so it makes more sense to add all the client based nodes with root as dri.

Also create a symlink back to the parent drm device from each client.

---
  drivers/gpu/drm/drm_debugfs.c | 26 ++++++++++++++++++++++++++
  drivers/gpu/drm/drm_file.c    |  6 ++++++
  include/drm/drm_debugfs.h     | 11 +++++++++++
  include/drm/drm_file.h        |  7 +++++++
  4 files changed, 50 insertions(+)
drivers/gpu/drm/drm_debugfs.c +11 -0
index a227903c29c4..ebdf60665b86 100644
@@ -309,6 +309,32 @@ void drm_debugfs_remove_accel_root(void)
  	debugfs_remove(accel_debugfs_root);
  }
 
+void drm_debugfs_clients_add(struct drm_file *file)
+{
+	char *client;
+
+	client = kasprintf(GFP_KERNEL, "client-%llu", file->client_id);
+	if (!client)
+		return;
+
+	/* Create a debugfs directory for the client in root on drm debugfs */
+	file->debugfs_client = debugfs_create_dir(client, drm_debugfs_root);
+	kfree(client);
Quoted 8 lines

drivers/gpu/drm/drm_debugfs.c void drm_debugfs_remove_accel_root(void) · line 329

Quoted 7 lines
drivers/gpu/drm/drm_debugfs.c +7 -0
+
+	client = kasprintf(GFP_KERNEL, "../%s", file->minor->dev->unique);
+	if (!client)
+		return;
+
+	/* Create a link from client_id to the drm device this client id belongs to */
+	debugfs_create_symlink("device", file->debugfs_client, client);

Mhm, that won't work for accel devices. How should we fix that?

All the clients we are creating is doing for the dri clients only and not for accel driver, Since the root itself is different for accel it cant be in dri and we could leave that for accel driver to take care if they need client directory for something or this we could pick later if there is a need.

In the mean while what we can do in the drm_alloc/drm_free is to add an extra condition to check if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL)) or not. and create and remove client onyl for !accel if(!drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL))
drm_debugfs_clients_add(file); and
if(!drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL))
drm_debugfs_clients_remove(file);

Quoted 42 lines
Quoted 42 lines
drivers/gpu/drm/drm_debugfs.c +8 -0
+	kfree(client);
+}
+
+void drm_debugfs_clients_remove(struct drm_file *file)
+{
+	debugfs_remove_recursive(file->debugfs_client);
+	file->debugfs_client = NULL;
+}
 
  /**
   * drm_debugfs_dev_init - create debugfs directory for the device
drivers/gpu/drm/drm_file.c +5 -0
index 06ba6dcbf5ae..17b803ab119e 100644
@@ -45,6 +45,7 @@
  #include <drm/drm_file.h>
  #include <drm/drm_gem.h>
  #include <drm/drm_print.h>
+#include <drm/drm_debugfs.h>
 
  #include "drm_crtc_internal.h"
  #include "drm_internal.h"
@@ -167,6 +168,8 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor)
 
  	drm_prime_init_file_private(&file->prime);
 
+	drm_debugfs_clients_add(file);
+
  	if (dev->driver->open) {
  		ret = dev->driver->open(dev, file);
  		if (ret < 0)
@@ -181,6 +184,8 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor)
  		drm_syncobj_release(file);
  	if (drm_core_check_feature(dev, DRIVER_GEM))
  		drm_gem_release(dev, file);
+
+	drm_debugfs_clients_remove(file);
  	put_pid(rcu_access_pointer(file->pid));
  	kfree(file);
 
Quoted 6 lines

drivers/gpu/drm/drm_file.c void drm_file_free(struct drm_file *file) · line 244

Quoted 5 lines
drivers/gpu/drm/drm_file.c +1 -0
@@ -236,6 +241,7 @@ void drm_file_free(struct drm_file *file)
  		     atomic_read(&dev->open_count));
 
  	drm_events_release(file);
+	drm_debugfs_clients_remove(file);

That most likely needs to come even before releasing the events.

Sure will move it before events_release.

Regards
Sunil Khatri

Quoted 54 lines

Regards,
Christian.

Quoted 50 lines
drivers/gpu/drm/drm_file.c +0 -0
  	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  		drm_fb_release(file);
include/drm/drm_debugfs.h +11 -0
index cf06cee4343f..2b3767ad8f5d 100644
@@ -153,6 +153,9 @@ void drm_debugfs_add_files(struct drm_device *dev,
 
  int drm_debugfs_gpuva_info(struct seq_file *m,
  			   struct drm_gpuvm *gpuvm);
+
+void drm_debugfs_clients_add(struct drm_file *file);
+void drm_debugfs_clients_remove(struct drm_file *file);
  #else
  static inline void drm_debugfs_create_files(const struct drm_info_list *files,
  					    int count, struct dentry *root,
@@ -181,6 +184,14 @@ static inline int drm_debugfs_gpuva_info(struct seq_file *m,
  {
  	return 0;
  }
+
+static void drm_debugfs_clients_add(struct drm_file *file)
+{
+}
+
+static void drm_debugfs_clients_remove(struct drm_file *file)
+{
+}
  #endif
 
  #endif /* _DRM_DEBUGFS_H_ */
include/drm/drm_file.h +7 -0
index 5c3b2aa3e69d..eab7546aad79 100644
@@ -400,6 +400,13 @@ struct drm_file {
  	 * @client_name_lock: Protects @client_name.
  	 */
  	struct mutex client_name_lock;
+
+	/**
+	 * @debugfs_client:
+	 *
+	 * debugfs directory for each client under a drm node.
+	 */
+	struct dentry *debugfs_client;
  };
 
  /**
maintainer
#7 lore raw

Re: [PATCH v5 3/5] drm: add debugfs support on per client-id basis

Quoted 48 lines · Sunil
Quoted 37 lines · Christian König
Quoted 36 lines · Sunil Khatri

add support to add a directory for each client-id with root at the dri level. Since the clients are unique and not just related to one single drm device, so it makes more sense to add all the client based nodes with root as dri.

Also create a symlink back to the parent drm device from each client.

---
 drivers/gpu/drm/drm_debugfs.c | 26 ++++++++++++++++++++++++++
 drivers/gpu/drm/drm_file.c    |  6 ++++++
 include/drm/drm_debugfs.h     | 11 +++++++++++
 include/drm/drm_file.h        |  7 +++++++
 4 files changed, 50 insertions(+)
drivers/gpu/drm/drm_debugfs.c +11 -0
index a227903c29c4..ebdf60665b86 100644
@@ -309,6 +309,32 @@ void drm_debugfs_remove_accel_root(void)
 	debugfs_remove(accel_debugfs_root);
 }
 
+void drm_debugfs_clients_add(struct drm_file *file)
+{
+	char *client;
+
+	client = kasprintf(GFP_KERNEL, "client-%llu", file->client_id);
+	if (!client)
+		return;
+
+	/* Create a debugfs directory for the client in root on drm debugfs */
+	file->debugfs_client = debugfs_create_dir(client, drm_debugfs_root);
+	kfree(client);
Quoted 8 lines

drivers/gpu/drm/drm_debugfs.c void drm_debugfs_remove_accel_root(void) · line 329

Quoted 7 lines
drivers/gpu/drm/drm_debugfs.c +7 -0
+
+	client = kasprintf(GFP_KERNEL, "../%s", file->minor->dev->unique);
+	if (!client)
+		return;
+
+	/* Create a link from client_id to the drm device this client id belongs to */
+	debugfs_create_symlink("device", file->debugfs_client, client);

Mhm, that won't work for accel devices. How should we fix that?

Quoted 8 lines

All the clients we are creating is doing for the dri clients only and not for accel driver, Since the root itself is different for accel it cant be in dri and we could leave that for accel driver to take care if they need client directory for something or this we could pick later if there is a need.

In the mean while what we can do in the drm_alloc/drm_free is to add an extra condition to check if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL)) or not. and create and remove client onyl for !accel if(!drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL))
                drm_debugfs_clients_add(file); and
if(!drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL))
                drm_debugfs_clients_remove(file);

Works for me.

Regards,
Christian.

Quoted 108 lines
Quoted 43 lines
Quoted 43 lines
drivers/gpu/drm/drm_debugfs.c +8 -0
+	kfree(client);
+}
+
+void drm_debugfs_clients_remove(struct drm_file *file)
+{
+	debugfs_remove_recursive(file->debugfs_client);
+	file->debugfs_client = NULL;
+}
 
 /**
  * drm_debugfs_dev_init - create debugfs directory for the device
drivers/gpu/drm/drm_file.c +5 -0
index 06ba6dcbf5ae..17b803ab119e 100644
@@ -45,6 +45,7 @@
 #include <drm/drm_file.h>
 #include <drm/drm_gem.h>
 #include <drm/drm_print.h>
+#include <drm/drm_debugfs.h>
 
 #include "drm_crtc_internal.h"
 #include "drm_internal.h"
@@ -167,6 +168,8 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor)
 
 	drm_prime_init_file_private(&file->prime);
 
+	drm_debugfs_clients_add(file);
+
 	if (dev->driver->open) {
 		ret = dev->driver->open(dev, file);
 		if (ret < 0)
@@ -181,6 +184,8 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor)
 		drm_syncobj_release(file);
 	if (drm_core_check_feature(dev, DRIVER_GEM))
 		drm_gem_release(dev, file);
+
+	drm_debugfs_clients_remove(file);
 	put_pid(rcu_access_pointer(file->pid));
 	kfree(file);
 
Quoted 6 lines

drivers/gpu/drm/drm_file.c void drm_file_free(struct drm_file *file) · line 244

Quoted 5 lines
drivers/gpu/drm/drm_file.c +1 -0
@@ -236,6 +241,7 @@ void drm_file_free(struct drm_file *file)
 		     atomic_read(&dev->open_count));
 
 	drm_events_release(file);
+	drm_debugfs_clients_remove(file);

That most likely needs to come even before releasing the events.

Sure will move it before events_release.

Regards
Sunil Khatri

Quoted 53 lines

Regards,
Christian.

Quoted 50 lines
drivers/gpu/drm/drm_file.c +0 -0
 	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
 		drm_fb_release(file);
include/drm/drm_debugfs.h +11 -0
index cf06cee4343f..2b3767ad8f5d 100644
@@ -153,6 +153,9 @@ void drm_debugfs_add_files(struct drm_device *dev,
 
 int drm_debugfs_gpuva_info(struct seq_file *m,
 			   struct drm_gpuvm *gpuvm);
+
+void drm_debugfs_clients_add(struct drm_file *file);
+void drm_debugfs_clients_remove(struct drm_file *file);
 #else
 static inline void drm_debugfs_create_files(const struct drm_info_list *files,
 					    int count, struct dentry *root,
@@ -181,6 +184,14 @@ static inline int drm_debugfs_gpuva_info(struct seq_file *m,
 {
 	return 0;
 }
+
+static void drm_debugfs_clients_add(struct drm_file *file)
+{
+}
+
+static void drm_debugfs_clients_remove(struct drm_file *file)
+{
+}
 #endif
 
 #endif /* _DRM_DEBUGFS_H_ */
include/drm/drm_file.h +7 -0
index 5c3b2aa3e69d..eab7546aad79 100644
@@ -400,6 +400,13 @@ struct drm_file {
 	 * @client_name_lock: Protects @client_name.
 	 */
 	struct mutex client_name_lock;
+
+	/**
+	 * @debugfs_client:
+	 *
+	 * debugfs directory for each client under a drm node.
+	 */
+	struct dentry *debugfs_client;
 };
 
 /**
#8 lore raw

Re: [PATCH v5 3/5] drm: add debugfs support on per client-id basis

In reply to Sunil Khatri
Quoted 108 lines · Sunil Khatri

add support to add a directory for each client-id with root at the dri level. Since the clients are unique and not just related to one single drm device, so it makes more sense to add all the client based nodes with root as dri.

Also create a symlink back to the parent drm device from each client.

---
  drivers/gpu/drm/drm_debugfs.c | 26 ++++++++++++++++++++++++++
  drivers/gpu/drm/drm_file.c    |  6 ++++++
  include/drm/drm_debugfs.h     | 11 +++++++++++
  include/drm/drm_file.h        |  7 +++++++
  4 files changed, 50 insertions(+)
drivers/gpu/drm/drm_debugfs.c +26 -0
index a227903c29c4..ebdf60665b86 100644
@@ -309,6 +309,32 @@ void drm_debugfs_remove_accel_root(void)
  	debugfs_remove(accel_debugfs_root);
  }
 
+void drm_debugfs_clients_add(struct drm_file *file)
+{
+	char *client;
+
+	client = kasprintf(GFP_KERNEL, "client-%llu", file->client_id);
+	if (!client)
+		return;
+
+	/* Create a debugfs directory for the client in root on drm debugfs */
+	file->debugfs_client = debugfs_create_dir(client, drm_debugfs_root);
+	kfree(client);
+
+	client = kasprintf(GFP_KERNEL, "../%s", file->minor->dev->unique);
+	if (!client)
+		return;
+
+	/* Create a link from client_id to the drm device this client id belongs to */
+	debugfs_create_symlink("device", file->debugfs_client, client);
+	kfree(client);
+}
+
+void drm_debugfs_clients_remove(struct drm_file *file)
+{
+	debugfs_remove_recursive(file->debugfs_client);
+	file->debugfs_client = NULL;
+}
 
  /**
   * drm_debugfs_dev_init - create debugfs directory for the device
drivers/gpu/drm/drm_file.c +6 -0
index 06ba6dcbf5ae..17b803ab119e 100644
@@ -45,6 +45,7 @@
  #include <drm/drm_file.h>
  #include <drm/drm_gem.h>
  #include <drm/drm_print.h>
+#include <drm/drm_debugfs.h>
 
  #include "drm_crtc_internal.h"
  #include "drm_internal.h"
@@ -167,6 +168,8 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor)
 
  	drm_prime_init_file_private(&file->prime);
 
+	drm_debugfs_clients_add(file);
+
  	if (dev->driver->open) {
  		ret = dev->driver->open(dev, file);
  		if (ret < 0)
@@ -181,6 +184,8 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor)
  		drm_syncobj_release(file);
  	if (drm_core_check_feature(dev, DRIVER_GEM))
  		drm_gem_release(dev, file);
+
+	drm_debugfs_clients_remove(file);
  	put_pid(rcu_access_pointer(file->pid));
  	kfree(file);
 
@@ -236,6 +241,7 @@ void drm_file_free(struct drm_file *file)
  		     atomic_read(&dev->open_count));
 
  	drm_events_release(file);
+	drm_debugfs_clients_remove(file);
 
  	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  		drm_fb_release(file);
include/drm/drm_debugfs.h +3 -0
index cf06cee4343f..2b3767ad8f5d 100644
@@ -153,6 +153,9 @@ void drm_debugfs_add_files(struct drm_device *dev,
 
  int drm_debugfs_gpuva_info(struct seq_file *m,
  			   struct drm_gpuvm *gpuvm);
+
+void drm_debugfs_clients_add(struct drm_file *file);
+void drm_debugfs_clients_remove(struct drm_file *file);
  #else
  static inline void drm_debugfs_create_files(const struct drm_info_list *files,
  					    int count, struct dentry *root,
@@ -181,6 +184,14 @@ static inline int drm_debugfs_gpuva_info(struct seq_file *m,
  {

include/drm/drm_debugfs.h static inline int drm_debugfs_gpuva_info(struct seq_file *m, · line 194

Quoted 10 lines
include/drm/drm_debugfs.h +8 -0
  	return 0;
  }
+
+static void drm_debugfs_clients_add(struct drm_file *file)
+{
+}
+
+static void drm_debugfs_clients_remove(struct drm_file *file)
+{
+}

You forgot static inline for these two.

Regards,

Tvrtko

Quoted 21 lines
include/drm/drm_debugfs.h +0 -0
  #endif
 
  #endif /* _DRM_DEBUGFS_H_ */
include/drm/drm_file.h +7 -0
index 5c3b2aa3e69d..eab7546aad79 100644
@@ -400,6 +400,13 @@ struct drm_file {
  	 * @client_name_lock: Protects @client_name.
  	 */
  	struct mutex client_name_lock;
+
+	/**
+	 * @debugfs_client:
+	 *
+	 * debugfs directory for each client under a drm node.
+	 */
+	struct dentry *debugfs_client;
  };
 
  /**
#9 lore raw

Re: [PATCH v5 3/5] drm: add debugfs support on per client-id basis

Quoted 111 lines · Tvrtko Ursulin
Quoted 109 lines · Sunil Khatri

add support to add a directory for each client-id with root at the dri level. Since the clients are unique and not just related to one single drm device, so it makes more sense to add all the client based nodes with root as dri.

Also create a symlink back to the parent drm device from each client.

---
  drivers/gpu/drm/drm_debugfs.c | 26 ++++++++++++++++++++++++++ drivers/gpu/drm/drm_file.c    |  6 ++++++ include/drm/drm_debugfs.h     | 11 +++++++++++ include/drm/drm_file.h        |  7 +++++++

  4 files changed, 50 insertions(+)
drivers/gpu/drm/drm_debugfs.c +8 -0
index a227903c29c4..ebdf60665b86 100644
@@ -309,6 +309,32 @@ void drm_debugfs_remove_accel_root(void)
       debugfs_remove(accel_debugfs_root);
   }
   +void drm_debugfs_clients_add(struct drm_file *file)
+{
+    char *client;
+
+    client = kasprintf(GFP_KERNEL, "client-%llu", file->client_id);
+    if (!client)
+        return;
+
+    /* Create a debugfs directory for the client in root on drm 

debugfs */
+    file->debugfs_client = debugfs_create_dir(client, drm_debugfs_root);
+    kfree(client);

drivers/gpu/drm/drm_debugfs.c +6 -0
+
+    client = kasprintf(GFP_KERNEL, "../%s", file->minor->dev->unique);
+    if (!client)
+        return;
+
+    /* Create a link from client_id to the drm device this client id 

belongs to */
+    debugfs_create_symlink("device", file->debugfs_client, client); +    kfree(client);

drivers/gpu/drm/drm_debugfs.c +7 -0
+}
+
+void drm_debugfs_clients_remove(struct drm_file *file)
+{
+    debugfs_remove_recursive(file->debugfs_client);
+    file->debugfs_client = NULL;
+}

    /**
   * drm_debugfs_dev_init - create debugfs directory for the device

drivers/gpu/drm/drm_file.c +4 -0
index 06ba6dcbf5ae..17b803ab119e 100644
@@ -45,6 +45,7 @@
   #include <drm/drm_file.h>
   #include <drm/drm_gem.h>
   #include <drm/drm_print.h>
+#include <drm/drm_debugfs.h>
     #include "drm_crtc_internal.h"
   #include "drm_internal.h"
@@ -167,6 +168,8 @@ struct drm_file *drm_file_alloc(struct drm_minor 
 *minor)
         drm_prime_init_file_private(&file->prime);
   +    drm_debugfs_clients_add(file);
+
       if (dev->driver->open) {
           ret = dev->driver->open(dev, file);
           if (ret < 0)
@@ -181,6 +184,8 @@ struct drm_file *drm_file_alloc(struct drm_minor 
 *minor)
           drm_syncobj_release(file);
       if (drm_core_check_feature(dev, DRIVER_GEM))
           drm_gem_release(dev, file);
+
+    drm_debugfs_clients_remove(file);
       put_pid(rcu_access_pointer(file->pid));
       kfree(file);

  @@ -236,6 +241,7 @@ void drm_file_free(struct drm_file *file) atomic_read(&dev->open_count)); drm_events_release(file);
+    drm_debugfs_clients_remove(file);
        if (drm_core_check_feature(dev, DRIVER_MODESET)) { drm_fb_release(file);

include/drm/drm_debugfs.h +5 -0
index cf06cee4343f..2b3767ad8f5d 100644
@@ -153,6 +153,9 @@ void drm_debugfs_add_files(struct drm_device *dev,
     int drm_debugfs_gpuva_info(struct seq_file *m,
                  struct drm_gpuvm *gpuvm);
+
+void drm_debugfs_clients_add(struct drm_file *file);
+void drm_debugfs_clients_remove(struct drm_file *file);
   #else
   static inline void drm_debugfs_create_files(const struct drm_info_list *files,
                           int count, struct dentry *root,
@@ -181,6 +184,14 @@ static inline int drm_debugfs_gpuva_info(struct 
 seq_file *m,
   {
       return 0;
   }
+
+static void drm_debugfs_clients_add(struct drm_file *file)
Quoted 8 lines

include/drm/drm_debugfs.h static inline int drm_debugfs_gpuva_info(struct seq_file *m, · line 194

Quoted 6 lines
include/drm/drm_debugfs.h +6 -0
+{
+}
+
+static void drm_debugfs_clients_remove(struct drm_file *file)
+{
+}

You forgot static inline for these two.

Thanks for catching that up. Will update.

Regards
Sunil

Quoted 25 lines

Regards,

Tvrtko

Quoted 19 lines
include/drm/drm_debugfs.h +0 -0
   #endif
     #endif /* _DRM_DEBUGFS_H_ */
include/drm/drm_file.h +7 -0
index 5c3b2aa3e69d..eab7546aad79 100644
@@ -400,6 +400,13 @@ struct drm_file {
        * @client_name_lock: Protects @client_name.
        */
       struct mutex client_name_lock;
+
+    /**
+     * @debugfs_client:
+     *
+     * debugfs directory for each client under a drm node.
+     */
+    struct dentry *debugfs_client;
   };
     /**
#10 lore raw

PATCH v5 4/5 drm/amdgpu: add debugfs support for VM pagetable per client

In reply to Sunil Khatri

Each drm node is associated with a unique client-id. Create a directory for each drm-file in the dri root directory. This directory is unique to hold information related to a client id which is unique in the system irrespective of how many drm devices are on the system.

Adding root page table base address of the VM under the client-id node along with the process information in debugfs.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c  | 58 ++++++++++++++++++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h  |  4 +-
 3 files changed, 61 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1 -1
index d2ce7d86dbc8..aa912168fd68 100644
@@ -1395,7 +1395,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 	if (r)
 		goto error_pasid;
 
-	r = amdgpu_vm_init(adev, &fpriv->vm, fpriv->xcp_id);
+	r = amdgpu_vm_init(adev, &fpriv->vm, fpriv->xcp_id, file_priv);
 	if (r)
 		goto error_pasid;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +57 -1

82 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +3 -1
index f3ad687125ad..555afaf867c4 100644
@@ -487,7 +487,9 @@ int amdgpu_vm_set_pasid(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 			u32 pasid);
 
 long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout);
-int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcp_id);
+int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcp_id,
+		   struct drm_file *file);
+
 int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm);
 void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
 int amdgpu_vm_lock_pd(struct amdgpu_vm *vm, struct drm_exec *exec,
Signature · 1 line
2.34.1
maintainer
#11 lore raw

Re: [PATCH v5 4/5] drm/amdgpu: add debugfs support for VM pagetable per client

Quoted 42 lines · Sunil Khatri

Each drm node is associated with a unique client-id. Create a directory for each drm-file in the dri root directory. This directory is unique to hold information related to a client id which is unique in the system irrespective of how many drm devices are on the system.

Adding root page table base address of the VM under the client-id node along with the process information in debugfs.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c  | 58 ++++++++++++++++++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h  |  4 +-
 3 files changed, 61 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1 -1
index d2ce7d86dbc8..aa912168fd68 100644
@@ -1395,7 +1395,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 	if (r)
 		goto error_pasid;
 
-	r = amdgpu_vm_init(adev, &fpriv->vm, fpriv->xcp_id);
+	r = amdgpu_vm_init(adev, &fpriv->vm, fpriv->xcp_id, file_priv);
 	if (r)
 		goto error_pasid;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -0
index 3911c78f8282..9e3dd187b597 100644
@@ -2520,12 +2520,67 @@ void amdgpu_vm_set_task_info(struct amdgpu_vm *vm)
 	get_task_comm(vm->task_info->process_name, current->group_leader);
 }
 
+#if defined(CONFIG_DEBUG_FS)
+static int amdgpu_pt_info_read(struct seq_file *m, void *unused)
+{
+	struct drm_file *file;

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_set_task_info(struct amdgpu_vm *vm) · line 2536

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +9 -0
+	struct amdgpu_fpriv *fpriv;
+	struct pid *pid;
+	struct task_struct *task;
+	struct amdgpu_bo *root_bo;
+	int r;
+
 
+	file = (struct drm_file *)m->private;
+	if (!file || !file->driver_priv)
+		return -EINVAL;

This here is racy. It can be that the debugfs file is opened and read in just the exact moment the client it belongs to is closed.

You need to do something like this here:

if (!file_ref_get(&file->file->f_ref))

	return -EINVAL;

And then an fput(file->file) at the end of the function.

It would probably best to have a helper for that in drm_debugfs.c since that needs to be done for all per client debugfs files.

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +8 -0
+
+	fpriv = file->driver_priv;
+	if (!fpriv || !fpriv->vm.root.bo)
+		return -ENODEV;
+
+	root_bo = amdgpu_bo_ref(fpriv->vm.root.bo);
+	r = amdgpu_bo_reserve(root_bo, true);
+	if (r) {

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_set_task_info(struct amdgpu_vm *vm) · line 2553

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10 -0
+		amdgpu_bo_unref(&root_bo);
+		return 0;
+	}
+
+	rcu_read_lock();
+	pid = rcu_dereference(file->pid);
+	task = pid_task(pid, PIDTYPE_TGID);
+
+	seq_printf(m, "pid: %d\n", task ? task->pid : 0);
+	seq_printf(m, "comm: %s\n", task ? task->comm : "Unset");

Thinking more about it, the pid and task name should probably be a different driver independent file, e.g. implemented in drm_debugfs.c

Because that is something all drivers should be able to provide.

We could potentially print the same line of information we print in the clints debugfs file.

Regards,
Christian.

Quoted 65 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +24 -0
+	seq_printf(m, "pt_base: 0x%llx\n", amdgpu_bo_gpu_offset(fpriv->vm.root.bo));
+
+	rcu_read_unlock();
+	amdgpu_bo_unreserve(root_bo);
+	amdgpu_bo_unref(&root_bo);
+
+	return 0;
+}
+
+static int amdgpu_pt_info_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, amdgpu_pt_info_read, inode->i_private);
+}
+
+static const struct file_operations amdgpu_pt_info_fops = {
+	.owner = THIS_MODULE,
+	.open = amdgpu_pt_info_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = single_release,
+};
+#endif
+
 /**
  * amdgpu_vm_init - initialize a vm instance
  *
  * @adev: amdgpu_device pointer
  * @vm: requested vm
  * @xcp_id: GPU partition selection id
+ * @file: drm_file
  *
  * Init @vm fields.

*

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -1
@@ -2533,7 +2588,7 @@ void amdgpu_vm_set_task_info(struct amdgpu_vm *vm)
  * 0 for success, error for failure.
  */
 int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
-		   int32_t xcp_id)
+		   int32_t xcp_id, struct drm_file *file)
 {
 	struct amdgpu_bo *root_bo;
 	struct amdgpu_bo_vm *root;
@@ -2609,6 +2664,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	if (r)
 		DRM_DEBUG("Failed to create task info for VM\n");
 
+	debugfs_create_file("pt_info", 0444, file->debugfs_client, file, &amdgpu_pt_info_fops);
 	amdgpu_bo_unreserve(vm->root.bo);
 	amdgpu_bo_unref(&root_bo);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +3 -1
index f3ad687125ad..555afaf867c4 100644
@@ -487,7 +487,9 @@ int amdgpu_vm_set_pasid(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 			u32 pasid);
 
 long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout);
-int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcp_id);
+int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcp_id,
+		   struct drm_file *file);
+
 int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm);
 void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
 int amdgpu_vm_lock_pd(struct amdgpu_vm *vm, struct drm_exec *exec,
#12 lore raw

Re: [PATCH v5 4/5] drm/amdgpu: add debugfs support for VM pagetable per client

Quoted 39 lines · Christian König
Quoted 38 lines · Sunil Khatri

Each drm node is associated with a unique client-id. Create a directory for each drm-file in the dri root directory. This directory is unique to hold information related to a client id which is unique in the system irrespective of how many drm devices are on the system.

Adding root page table base address of the VM under the client-id node along with the process information in debugfs.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c  | 58 ++++++++++++++++++++++++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h  |  4 +-
  3 files changed, 61 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1 -1
index d2ce7d86dbc8..aa912168fd68 100644
@@ -1395,7 +1395,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
  	if (r)
  		goto error_pasid;
 
-	r = amdgpu_vm_init(adev, &fpriv->vm, fpriv->xcp_id);
+	r = amdgpu_vm_init(adev, &fpriv->vm, fpriv->xcp_id, file_priv);
  	if (r)
  		goto error_pasid;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
index 3911c78f8282..9e3dd187b597 100644
@@ -2520,12 +2520,67 @@ void amdgpu_vm_set_task_info(struct amdgpu_vm *vm)
  	get_task_comm(vm->task_info->process_name, current->group_leader);
  }
 
Quoted 14 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_set_task_info(struct amdgpu_vm *vm) · line 2535

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +13 -0
+#if defined(CONFIG_DEBUG_FS)
+static int amdgpu_pt_info_read(struct seq_file *m, void *unused)
+{
+	struct drm_file *file;
+	struct amdgpu_fpriv *fpriv;
+	struct pid *pid;
+	struct task_struct *task;
+	struct amdgpu_bo *root_bo;
+	int r;
+
+	file = (struct drm_file *)m->private;
+	if (!file || !file->driver_priv)
+		return -EINVAL;

This here is racy. It can be that the debugfs file is opened and read in just the exact moment the client it belongs to is closed.'

I dont see drm_file ref_get being taken anywhere in our driver. It's directly being used.

Quoted 9 lines

You need to do something like this here:

if (!file_ref_get(&file->file->f_ref))

	return -EINVAL;

And then an fput(file->file) at the end of the function.

It would probably best to have a helper for that in drm_debugfs.c since that needs to be done for all per client debugfs files.

In case you think we still need it then why not directly user file_ref_get and fput itself. why need a new function all together for one line.

Quoted 21 lines
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +8 -0
+
+	fpriv = file->driver_priv;
+	if (!fpriv || !fpriv->vm.root.bo)
+		return -ENODEV;
+
+	root_bo = amdgpu_bo_ref(fpriv->vm.root.bo);
+	r = amdgpu_bo_reserve(root_bo, true);
+	if (r) {

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_set_task_info(struct amdgpu_vm *vm) · line 2553

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10 -0
+		amdgpu_bo_unref(&root_bo);
+		return 0;
+	}
+
+	rcu_read_lock();
+	pid = rcu_dereference(file->pid);
+	task = pid_task(pid, PIDTYPE_TGID);
+
+	seq_printf(m, "pid: %d\n", task ? task->pid : 0);
+	seq_printf(m, "comm: %s\n", task ? task->comm : "Unset");

Thinking more about it, the pid and task name should probably be a different driver independent file, e.g. implemented in drm_debugfs.c

Quoted 3 lines

Because that is something all drivers should be able to provide.

We could potentially print the same line of information we print in the clints debugfs file.

We do exactly same thing in drm_debugfs in drm_file_err, and i am doing exactly same thing here. If not, there in drm_debugfs i will have to create one for debugfs file there for each client but doing it here for both information in one point here. But i am open any if you think that would be a better approach.

Regards
Sunil Khatri

Quoted 69 lines

Regards,
Christian.

Quoted 65 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +26 -1
+	seq_printf(m, "pt_base: 0x%llx\n", amdgpu_bo_gpu_offset(fpriv->vm.root.bo));
+
+	rcu_read_unlock();
+	amdgpu_bo_unreserve(root_bo);
+	amdgpu_bo_unref(&root_bo);
+
+	return 0;
+}
+
+static int amdgpu_pt_info_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, amdgpu_pt_info_read, inode->i_private);
+}
+
+static const struct file_operations amdgpu_pt_info_fops = {
+	.owner = THIS_MODULE,
+	.open = amdgpu_pt_info_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = single_release,
+};
+#endif
+
  /**
   * amdgpu_vm_init - initialize a vm instance
   *
   * @adev: amdgpu_device pointer
   * @vm: requested vm
   * @xcp_id: GPU partition selection id
+ * @file: drm_file
   *
   * Init @vm fields.
   *
@@ -2533,7 +2588,7 @@ void amdgpu_vm_set_task_info(struct amdgpu_vm *vm)
   * 0 for success, error for failure.
   */
  int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
-		   int32_t xcp_id)
+		   int32_t xcp_id, struct drm_file *file)
  {
  	struct amdgpu_bo *root_bo;
  	struct amdgpu_bo_vm *root;
@@ -2609,6 +2664,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  	if (r)
  		DRM_DEBUG("Failed to create task info for VM\n");
 
+	debugfs_create_file("pt_info", 0444, file->debugfs_client, file, &amdgpu_pt_info_fops);
  	amdgpu_bo_unreserve(vm->root.bo);
  	amdgpu_bo_unref(&root_bo);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +3 -1
index f3ad687125ad..555afaf867c4 100644
@@ -487,7 +487,9 @@ int amdgpu_vm_set_pasid(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  			u32 pasid);
 
  long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout);
-int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcp_id);
+int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcp_id,
+		   struct drm_file *file);
+
  int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm);
  void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
  int amdgpu_vm_lock_pd(struct amdgpu_vm *vm, struct drm_exec *exec,
#13 lore raw

PATCH v5 5/5 drm/amdgpu: add support of debugfs for mqd information

In reply to Sunil Khatri

add mqd support based on queue of for each client-id so the gpu address could be used to dump the mqd.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 52 +++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h |  1 +
 2 files changed, 53 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +52 -0
index 295e7186e156..dbac940b2517 100644
@@ -318,6 +318,9 @@ amdgpu_userq_destroy(struct drm_file *filp, int queue_id)
 		amdgpu_bo_unreserve(queue->db_obj.obj);
 	}
 	amdgpu_bo_unref(&queue->db_obj.obj);
+
+	debugfs_remove_recursive(queue->debugfs_queue);
+
 	r = amdgpu_userq_unmap_helper(uq_mgr, queue);
 	amdgpu_userq_cleanup(uq_mgr, queue, queue_id);
 	mutex_unlock(&uq_mgr->userq_mutex);
@@ -343,6 +346,46 @@ static int amdgpu_userq_priority_permit(struct drm_file *filp,
 	return -EACCES;
 }
 
+#if defined(CONFIG_DEBUG_FS)
+static int amdgpu_mqd_info_read(struct seq_file *m, void *unused)
+{
+	struct amdgpu_usermode_queue *queue = (struct amdgpu_usermode_queue *)m->private;
+	struct amdgpu_bo *bo;
+	int r;
+
+	if (!queue || !queue->mqd.obj)
+		return -EINVAL;
+
+	bo = amdgpu_bo_ref(queue->mqd.obj);
+	r = amdgpu_bo_reserve(bo, true);
+	if (r) {
+		amdgpu_bo_unref(&bo);
+		return 0;
+	}
+
+	seq_printf(m, "queue_type %d\n", queue->queue_type);
+	seq_printf(m, "mqd_gpu_address: 0x%llx\n", amdgpu_bo_gpu_offset(queue->mqd.obj));
+
+	amdgpu_bo_unreserve(bo);
+	amdgpu_bo_unref(&bo);
+
+	return 0;
+}
+
+static int amdgpu_mqd_info_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, amdgpu_mqd_info_read, inode->i_private);
+}
+
+static const struct file_operations amdgpu_mqd_info_fops = {
+	.owner = THIS_MODULE,
+	.open = amdgpu_mqd_info_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = single_release,
+};
+#endif
+
 static int
 amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 {
@@ -352,6 +395,7 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	const struct amdgpu_userq_funcs *uq_funcs;
 	struct amdgpu_usermode_queue *queue;
 	struct amdgpu_db_info db_info;
+	char *queue_name;
 	bool skip_map_queue;
 	uint64_t index;
 	int qid, r = 0;
@@ -475,6 +519,14 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 		}
 	}
 
+	queue_name = kasprintf(GFP_KERNEL, "queue-%d", qid);
+	if (!queue_name)
+		return -ENOMEM;
+
+	/* Queue dentry per client to hold MQD information   */
+	queue->debugfs_queue = debugfs_create_dir(queue_name, filp->debugfs_client);
+	debugfs_create_file("mqd_info", 0444, queue->debugfs_queue, queue, &amdgpu_mqd_info_fops);
+	kfree(queue_name);
 
 	args->out.queue_id = qid;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +1 -0
index ec040c2fd6c9..b1ca91b7cda4 100644
@@ -65,6 +65,7 @@ struct amdgpu_usermode_queue {
 	struct dma_fence	*last_fence;
 	u32			xcp_id;
 	int			priority;
+	struct dentry		*debugfs_queue;
 };
 
 struct amdgpu_userq_funcs {
Signature · 1 line
2.34.1
maintainer
#14 lore raw
In reply to Sunil Khatri
Quoted 3 lines · Sunil Khatri

move the debugfs accel driver code to the drm layer. This is first inline change to move the debugfs related changes for drm to drm_debugfs.c

Maybe write something like this:

"And intermediate step to move all debugfs related handling into drm_debugfs.c".

Apart from that looks good to me.

Regards,
Christian.

Quoted 117 lines
---
 drivers/accel/drm_accel.c | 16 ----------------
 drivers/gpu/drm/drm_drv.c |  6 +++++-
 include/drm/drm_accel.h   |  5 -----
 3 files changed, 5 insertions(+), 22 deletions(-)
drivers/accel/drm_accel.c +0 -16
index aa826033b0ce..ca3357acd127 100644
@@ -20,8 +20,6 @@
 
 DEFINE_XARRAY_ALLOC(accel_minors_xa);
 
-static struct dentry *accel_debugfs_root;
-
 static const struct device_type accel_sysfs_device_minor = {
 	.name = "accel_minor"
 };
@@ -73,17 +71,6 @@ static const struct drm_info_list accel_debugfs_list[] = {
 };
 #define ACCEL_DEBUGFS_ENTRIES ARRAY_SIZE(accel_debugfs_list)
 
-/**
- * accel_debugfs_init() - Initialize debugfs for device
- * @dev: Pointer to the device instance.
- *
- * This function creates a root directory for the device in debugfs.
- */
-void accel_debugfs_init(struct drm_device *dev)
-{
-	drm_debugfs_dev_init(dev, accel_debugfs_root);
-}
-
 /**
  * accel_debugfs_register() - Register debugfs for device
  * @dev: Pointer to the device instance.
@@ -194,7 +181,6 @@ static const struct file_operations accel_stub_fops = {
 void accel_core_exit(void)
 {
 	unregister_chrdev(ACCEL_MAJOR, "accel");
-	debugfs_remove(accel_debugfs_root);
 	accel_sysfs_destroy();
 	WARN_ON(!xa_empty(&accel_minors_xa));
 }
@@ -209,8 +195,6 @@ int __init accel_core_init(void)
 		goto error;
 	}
 
-	accel_debugfs_root = debugfs_create_dir("accel", NULL);
-
 	ret = register_chrdev(ACCEL_MAJOR, "accel", &accel_stub_fops);
 	if (ret < 0)
 		DRM_ERROR("Cannot register ACCEL major: %d\n", ret);
drivers/gpu/drm/drm_drv.c +5 -1
index 17fc5dc708f4..5d57b622f9aa 100644
@@ -70,6 +70,7 @@ DEFINE_XARRAY_ALLOC(drm_minors_xa);
 static bool drm_core_init_complete;
 
 static struct dentry *drm_debugfs_root;
+static struct dentry *accel_debugfs_root;
 
 DEFINE_STATIC_SRCU(drm_unplug_srcu);
 
@@ -752,7 +753,7 @@ static int drm_dev_init(struct drm_device *dev,
 	}
 
 	if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL))
-		accel_debugfs_init(dev);
+		drm_debugfs_dev_init(dev, accel_debugfs_root);
 	else
 		drm_debugfs_dev_init(dev, drm_debugfs_root);
 
@@ -1166,6 +1167,7 @@ static void drm_core_exit(void)
 {
 	drm_privacy_screen_lookup_exit();
 	drm_panic_exit();
+	debugfs_remove(accel_debugfs_root);
 	accel_core_exit();
 	unregister_chrdev(DRM_MAJOR, "drm");
 	debugfs_remove(drm_debugfs_root);
@@ -1193,6 +1195,8 @@ static int __init drm_core_init(void)
 	if (ret < 0)
 		goto error;
 
+	accel_debugfs_root = debugfs_create_dir("accel", NULL);
+
 	ret = accel_core_init();
 	if (ret < 0)
 		goto error;
include/drm/drm_accel.h +0 -5
index 038ccb02f9a3..20a665ec6f16 100644
@@ -58,7 +58,6 @@ void accel_core_exit(void);
 int accel_core_init(void);
 void accel_set_device_instance_params(struct device *kdev, int index);
 int accel_open(struct inode *inode, struct file *filp);
-void accel_debugfs_init(struct drm_device *dev);
 void accel_debugfs_register(struct drm_device *dev);
 
 #else
@@ -77,10 +76,6 @@ static inline void accel_set_device_instance_params(struct device *kdev, int ind
 {
 }
 
-static inline void accel_debugfs_init(struct drm_device *dev)
-{
-}
-
 static inline void accel_debugfs_register(struct drm_device *dev)
 {
 }
#15 lore raw
Quoted 5 lines · Christian König
Quoted 3 lines · Sunil Khatri

move the debugfs accel driver code to the drm layer. This is first inline change to move the debugfs related changes for drm to drm_debugfs.c

Maybe write something like this:

Noted

Regards
Sunil

Quoted 124 lines

"And intermediate step to move all debugfs related handling into drm_debugfs.c".

Apart from that looks good to me.

Regards,
Christian.

Quoted 116 lines
---
  drivers/accel/drm_accel.c | 16 ----------------
  drivers/gpu/drm/drm_drv.c |  6 +++++-
  include/drm/drm_accel.h   |  5 -----
  3 files changed, 5 insertions(+), 22 deletions(-)
drivers/accel/drm_accel.c +0 -16
index aa826033b0ce..ca3357acd127 100644
@@ -20,8 +20,6 @@
 
  DEFINE_XARRAY_ALLOC(accel_minors_xa);
 
-static struct dentry *accel_debugfs_root;
-
  static const struct device_type accel_sysfs_device_minor = {
  	.name = "accel_minor"
  };
@@ -73,17 +71,6 @@ static const struct drm_info_list accel_debugfs_list[] = {
  };
  #define ACCEL_DEBUGFS_ENTRIES ARRAY_SIZE(accel_debugfs_list)
 
-/**
- * accel_debugfs_init() - Initialize debugfs for device
- * @dev: Pointer to the device instance.
- *
- * This function creates a root directory for the device in debugfs.
- */
-void accel_debugfs_init(struct drm_device *dev)
-{
-	drm_debugfs_dev_init(dev, accel_debugfs_root);
-}
-
  /**
   * accel_debugfs_register() - Register debugfs for device
   * @dev: Pointer to the device instance.
@@ -194,7 +181,6 @@ static const struct file_operations accel_stub_fops = {
  void accel_core_exit(void)
  {
  	unregister_chrdev(ACCEL_MAJOR, "accel");
-	debugfs_remove(accel_debugfs_root);
  	accel_sysfs_destroy();
  	WARN_ON(!xa_empty(&accel_minors_xa));
  }
@@ -209,8 +195,6 @@ int __init accel_core_init(void)
  		goto error;
  	}
 
-	accel_debugfs_root = debugfs_create_dir("accel", NULL);
-
  	ret = register_chrdev(ACCEL_MAJOR, "accel", &accel_stub_fops);
  	if (ret < 0)
  		DRM_ERROR("Cannot register ACCEL major: %d\n", ret);
drivers/gpu/drm/drm_drv.c +5 -1
index 17fc5dc708f4..5d57b622f9aa 100644
@@ -70,6 +70,7 @@ DEFINE_XARRAY_ALLOC(drm_minors_xa);
  static bool drm_core_init_complete;
 
  static struct dentry *drm_debugfs_root;
+static struct dentry *accel_debugfs_root;
 
  DEFINE_STATIC_SRCU(drm_unplug_srcu);
 
@@ -752,7 +753,7 @@ static int drm_dev_init(struct drm_device *dev,
  	}
 
  	if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL))
-		accel_debugfs_init(dev);
+		drm_debugfs_dev_init(dev, accel_debugfs_root);
  	else
  		drm_debugfs_dev_init(dev, drm_debugfs_root);
 
@@ -1166,6 +1167,7 @@ static void drm_core_exit(void)
  {
  	drm_privacy_screen_lookup_exit();
  	drm_panic_exit();
+	debugfs_remove(accel_debugfs_root);
  	accel_core_exit();
  	unregister_chrdev(DRM_MAJOR, "drm");
  	debugfs_remove(drm_debugfs_root);
@@ -1193,6 +1195,8 @@ static int __init drm_core_init(void)
  	if (ret < 0)
  		goto error;
 
+	accel_debugfs_root = debugfs_create_dir("accel", NULL);
+
  	ret = accel_core_init();
  	if (ret < 0)
  		goto error;
include/drm/drm_accel.h +0 -5
index 038ccb02f9a3..20a665ec6f16 100644
@@ -58,7 +58,6 @@ void accel_core_exit(void);
  int accel_core_init(void);
  void accel_set_device_instance_params(struct device *kdev, int index);
  int accel_open(struct inode *inode, struct file *filp);
-void accel_debugfs_init(struct drm_device *dev);
  void accel_debugfs_register(struct drm_device *dev);
 
  #else
@@ -77,10 +76,6 @@ static inline void accel_set_device_instance_params(struct device *kdev, int ind
  {
  }
 
-static inline void accel_debugfs_init(struct drm_device *dev)
-{
-}
-
  static inline void accel_debugfs_register(struct drm_device *dev)
  {
  }