All of lore.kernel.org
 help / color / mirror / Atom feed
* DRM debugfs cleanup take 6
@ 2023-08-29 11:01 Christian König
  2023-08-29 11:01 ` [PATCH 1/5] drm/debugfs: drop debugfs_init() for the render and accel node v2 Christian König
                   ` (4 more replies)
  0 siblings, 5 replies; 18+ messages in thread
From: Christian König @ 2023-08-29 11:01 UTC (permalink / raw)
  To: ogabbay, ttayar, dri-devel

Hi guys,

Tomer found a few more issues (mostly kerneldoc) which are fixed in this
spin. I think we can land that now.

Please review and/or comment,
Christian.



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

* [PATCH 1/5] drm/debugfs: drop debugfs_init() for the render and accel node v2
  2023-08-29 11:01 DRM debugfs cleanup take 6 Christian König
@ 2023-08-29 11:01 ` Christian König
  2023-08-30  8:19   ` Andi Shyti
  2023-09-01  8:00   ` Tomer Tayar
  2023-08-29 11:01 ` [PATCH 2/5] drm/debugfs: disallow debugfs access when device isn't registered Christian König
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 18+ messages in thread
From: Christian König @ 2023-08-29 11:01 UTC (permalink / raw)
  To: ogabbay, ttayar, dri-devel

We want to remove per minor debugfs directories. Start by stopping
drivers from adding anything inside of those in the mid layer callback.

v2: drop it for the accel node as well

Signed-off-by: Christian König <christian.koenig@amd.com>
Tested-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
---
 drivers/accel/drm_accel.c     | 3 ---
 drivers/gpu/drm/drm_debugfs.c | 2 +-
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/accel/drm_accel.c b/drivers/accel/drm_accel.c
index 4a9baf02439e..01edf2c00b5a 100644
--- a/drivers/accel/drm_accel.c
+++ b/drivers/accel/drm_accel.c
@@ -99,9 +99,6 @@ void accel_debugfs_init(struct drm_minor *minor, int minor_id)
 
 	drm_debugfs_create_files(accel_debugfs_list, ACCEL_DEBUGFS_ENTRIES,
 				 minor->debugfs_root, minor);
-
-	if (dev->driver->debugfs_init)
-		dev->driver->debugfs_init(minor);
 }
 
 /**
diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index 2de43ff3ce0a..d90d0827bfad 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -284,7 +284,7 @@ int drm_debugfs_init(struct drm_minor *minor, int minor_id,
 		drm_client_debugfs_init(minor);
 	}
 
-	if (dev->driver->debugfs_init)
+	if (dev->driver->debugfs_init && dev->render != minor)
 		dev->driver->debugfs_init(minor);
 
 	list_for_each_entry_safe(entry, tmp, &dev->debugfs_list, list) {
-- 
2.34.1


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

* [PATCH 2/5] drm/debugfs: disallow debugfs access when device isn't registered
  2023-08-29 11:01 DRM debugfs cleanup take 6 Christian König
  2023-08-29 11:01 ` [PATCH 1/5] drm/debugfs: drop debugfs_init() for the render and accel node v2 Christian König
@ 2023-08-29 11:01 ` Christian König
  2023-08-29 11:31   ` Andi Shyti
  2023-08-29 11:01 ` [PATCH 3/5] drm/debugfs: rework debugfs directory creation v5 Christian König
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 18+ messages in thread
From: Christian König @ 2023-08-29 11:01 UTC (permalink / raw)
  To: ogabbay, ttayar, dri-devel

During device bringup it might be that we can't access the debugfs files.
Return -ENODEV until the registration is completed on access.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/drm_debugfs.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index d90d0827bfad..8a4c90fd9f02 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -150,6 +150,9 @@ static int drm_debugfs_open(struct inode *inode, struct file *file)
 {
 	struct drm_info_node *node = inode->i_private;
 
+	if (!device_is_registered(node->minor->kdev))
+		return -ENODEV;
+
 	return single_open(file, node->info_ent->show, node);
 }
 
@@ -157,6 +160,10 @@ static int drm_debugfs_entry_open(struct inode *inode, struct file *file)
 {
 	struct drm_debugfs_entry *entry = inode->i_private;
 	struct drm_debugfs_info *node = &entry->file;
+	struct drm_minor *minor = entry->dev->primary ?: entry->dev->accel;
+
+	if (!device_is_registered(minor->kdev))
+		return -ENODEV;
 
 	return single_open(file, node->show, entry);
 }
-- 
2.34.1


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

* [PATCH 3/5] drm/debugfs: rework debugfs directory creation v5
  2023-08-29 11:01 DRM debugfs cleanup take 6 Christian König
  2023-08-29 11:01 ` [PATCH 1/5] drm/debugfs: drop debugfs_init() for the render and accel node v2 Christian König
  2023-08-29 11:01 ` [PATCH 2/5] drm/debugfs: disallow debugfs access when device isn't registered Christian König
@ 2023-08-29 11:01 ` Christian König
  2023-08-31 21:49   ` Andi Shyti
  2023-08-29 11:01 ` [PATCH 4/5] drm/debugfs: remove dev->debugfs_list and debugfs_mutex v2 Christian König
  2023-08-29 11:01 ` [PATCH 5/5] drm/debugfs: rework drm_debugfs_create_files implementation v2 Christian König
  4 siblings, 1 reply; 18+ messages in thread
From: Christian König @ 2023-08-29 11:01 UTC (permalink / raw)
  To: ogabbay, ttayar, dri-devel

Instead of the per minor directories only create a single debugfs
directory for the whole device directly when the device is initialized.

For DRM devices each minor gets a symlink to the per device directory
for now until we can be sure that this isn't useful any more in any way.

Accel devices create only the per device directory and also drops the mid
layer callback to create driver specific files.

v2: cleanup accel component as well
v3: fix typo when debugfs is disabled
v4: call drm_debugfs_dev_fini() during release as well,
    some kerneldoc typos fixed
v5: rebased and one more kerneldoc fix

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/accel/drm_accel.c           | 30 +++++++-----
 drivers/gpu/drm/drm_atomic.c        |  4 +-
 drivers/gpu/drm/drm_bridge.c        |  4 +-
 drivers/gpu/drm/drm_client.c        |  4 +-
 drivers/gpu/drm/drm_crtc_internal.h |  2 +-
 drivers/gpu/drm/drm_debugfs.c       | 76 ++++++++++++++++++++---------
 drivers/gpu/drm/drm_drv.c           | 21 ++++++--
 drivers/gpu/drm/drm_framebuffer.c   |  4 +-
 drivers/gpu/drm/drm_internal.h      | 20 ++++++--
 include/drm/drm_accel.h             |  9 +++-
 include/drm/drm_bridge.h            |  2 +-
 include/drm/drm_client.h            |  2 +-
 include/drm/drm_device.h            |  7 +++
 include/drm/drm_drv.h               |  8 +++
 include/drm/drm_file.h              |  1 +
 15 files changed, 136 insertions(+), 58 deletions(-)

diff --git a/drivers/accel/drm_accel.c b/drivers/accel/drm_accel.c
index 01edf2c00b5a..8ba3db2ec5bb 100644
--- a/drivers/accel/drm_accel.c
+++ b/drivers/accel/drm_accel.c
@@ -79,26 +79,32 @@ static const struct drm_info_list accel_debugfs_list[] = {
 #define ACCEL_DEBUGFS_ENTRIES ARRAY_SIZE(accel_debugfs_list)
 
 /**
- * accel_debugfs_init() - Initialize debugfs for accel minor
- * @minor: Pointer to the drm_minor instance.
- * @minor_id: The minor's id
+ * accel_debugfs_init() - Initialize debugfs for device
+ * @dev: Pointer to the device instance.
  *
- * This function initializes the drm minor's debugfs members and creates
- * a root directory for the minor in debugfs. It also creates common files
- * for accelerators and calls the driver's debugfs init callback.
+ * This function creates a root directory for the device in debugfs.
  */
-void accel_debugfs_init(struct drm_minor *minor, int minor_id)
+void accel_debugfs_init(struct drm_device *dev)
 {
-	struct drm_device *dev = minor->dev;
-	char name[64];
+	drm_debugfs_dev_init(dev, accel_debugfs_root);
+}
+
+/**
+ * accel_debugfs_register() - Register debugfs for device
+ * @dev: Pointer to the device instance.
+ *
+ * Creates common files for accelerators.
+ */
+void accel_debugfs_register(struct drm_device *dev)
+{
+	struct drm_minor *minor = dev->accel;
 
 	INIT_LIST_HEAD(&minor->debugfs_list);
 	mutex_init(&minor->debugfs_lock);
-	sprintf(name, "%d", minor_id);
-	minor->debugfs_root = debugfs_create_dir(name, accel_debugfs_root);
+	minor->debugfs_root = dev->debugfs_root;
 
 	drm_debugfs_create_files(accel_debugfs_list, ACCEL_DEBUGFS_ENTRIES,
-				 minor->debugfs_root, minor);
+				 dev->debugfs_root, minor);
 }
 
 /**
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 2c454568a607..affce6a8851f 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -1832,9 +1832,9 @@ static const struct drm_debugfs_info drm_atomic_debugfs_list[] = {
 	{"state", drm_state_info, 0},
 };
 
-void drm_atomic_debugfs_init(struct drm_minor *minor)
+void drm_atomic_debugfs_init(struct drm_device *dev)
 {
-	drm_debugfs_add_files(minor->dev, drm_atomic_debugfs_list,
+	drm_debugfs_add_files(dev, drm_atomic_debugfs_list,
 			      ARRAY_SIZE(drm_atomic_debugfs_list));
 }
 #endif
diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
index 39e68e45bb12..30d66bee0ec6 100644
--- a/drivers/gpu/drm/drm_bridge.c
+++ b/drivers/gpu/drm/drm_bridge.c
@@ -1384,9 +1384,9 @@ static const struct drm_debugfs_info drm_bridge_debugfs_list[] = {
 	{ "bridge_chains", drm_bridge_chains_info, 0 },
 };
 
-void drm_bridge_debugfs_init(struct drm_minor *minor)
+void drm_bridge_debugfs_init(struct drm_device *dev)
 {
-	drm_debugfs_add_files(minor->dev, drm_bridge_debugfs_list,
+	drm_debugfs_add_files(dev, drm_bridge_debugfs_list,
 			      ARRAY_SIZE(drm_bridge_debugfs_list));
 }
 #endif
diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c
index 037e36f2049c..2762572f286e 100644
--- a/drivers/gpu/drm/drm_client.c
+++ b/drivers/gpu/drm/drm_client.c
@@ -535,9 +535,9 @@ static const struct drm_debugfs_info drm_client_debugfs_list[] = {
 	{ "internal_clients", drm_client_debugfs_internal_clients, 0 },
 };
 
-void drm_client_debugfs_init(struct drm_minor *minor)
+void drm_client_debugfs_init(struct drm_device *dev)
 {
-	drm_debugfs_add_files(minor->dev, drm_client_debugfs_list,
+	drm_debugfs_add_files(dev, drm_client_debugfs_list,
 			      ARRAY_SIZE(drm_client_debugfs_list));
 }
 #endif
diff --git a/drivers/gpu/drm/drm_crtc_internal.h b/drivers/gpu/drm/drm_crtc_internal.h
index 501a10edd0e1..8556c3b3ff88 100644
--- a/drivers/gpu/drm/drm_crtc_internal.h
+++ b/drivers/gpu/drm/drm_crtc_internal.h
@@ -232,7 +232,7 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
 /* drm_atomic.c */
 #ifdef CONFIG_DEBUG_FS
 struct drm_minor;
-void drm_atomic_debugfs_init(struct drm_minor *minor);
+void drm_atomic_debugfs_init(struct drm_device *dev);
 #endif
 
 int __drm_atomic_helper_disable_plane(struct drm_plane *plane,
diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index 8a4c90fd9f02..5ec28c0e12d9 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -266,8 +266,46 @@ void drm_debugfs_create_files(const struct drm_info_list *files, int count,
 }
 EXPORT_SYMBOL(drm_debugfs_create_files);
 
-int drm_debugfs_init(struct drm_minor *minor, int minor_id,
-		     struct dentry *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)
+{
+	dev->debugfs_root = debugfs_create_dir(dev->unique, root);
+}
+
+/**
+ * drm_debugfs_dev_fini - cleanup debugfs directory
+ * @dev: the device to cleanup the debugfs stuff
+ *
+ * Remove the debugfs directory, might be called multiple times.
+ */
+void drm_debugfs_dev_fini(struct drm_device *dev)
+{
+	debugfs_remove_recursive(dev->debugfs_root);
+	dev->debugfs_root = NULL;
+}
+
+void drm_debugfs_dev_register(struct drm_device *dev)
+{
+	drm_debugfs_add_files(dev, drm_debugfs_list, DRM_DEBUGFS_ENTRIES);
+
+	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
+		drm_framebuffer_debugfs_init(dev);
+		drm_client_debugfs_init(dev);
+	}
+	if (drm_drv_uses_atomic_modeset(dev)) {
+		drm_atomic_debugfs_init(dev);
+		drm_bridge_debugfs_init(dev);
+	}
+}
+
+int drm_debugfs_register(struct drm_minor *minor, int minor_id,
+			 struct dentry *root)
 {
 	struct drm_device *dev = minor->dev;
 	struct drm_debugfs_entry *entry, *tmp;
@@ -276,20 +314,11 @@ int drm_debugfs_init(struct drm_minor *minor, int minor_id,
 	INIT_LIST_HEAD(&minor->debugfs_list);
 	mutex_init(&minor->debugfs_lock);
 	sprintf(name, "%d", minor_id);
-	minor->debugfs_root = debugfs_create_dir(name, root);
-
-	drm_debugfs_add_files(minor->dev, drm_debugfs_list, DRM_DEBUGFS_ENTRIES);
+	minor->debugfs_symlink = debugfs_create_symlink(name, root,
+							dev->unique);
 
-	if (drm_drv_uses_atomic_modeset(dev)) {
-		drm_atomic_debugfs_init(minor);
-		drm_bridge_debugfs_init(minor);
-	}
-
-	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
-		drm_framebuffer_debugfs_init(minor);
-
-		drm_client_debugfs_init(minor);
-	}
+	/* TODO: Only for compatibility with drivers */
+	minor->debugfs_root = dev->debugfs_root;
 
 	if (dev->driver->debugfs_init && dev->render != minor)
 		dev->driver->debugfs_init(minor);
@@ -356,13 +385,12 @@ static void drm_debugfs_remove_all_files(struct drm_minor *minor)
 
 void drm_debugfs_cleanup(struct drm_minor *minor)
 {
-	if (!minor->debugfs_root)
+	if (!minor->debugfs_symlink)
 		return;
 
 	drm_debugfs_remove_all_files(minor);
-
-	debugfs_remove_recursive(minor->debugfs_root);
-	minor->debugfs_root = NULL;
+	debugfs_remove(minor->debugfs_symlink);
+	minor->debugfs_symlink = NULL;
 }
 
 /**
@@ -547,13 +575,13 @@ static const struct file_operations drm_connector_fops = {
 
 void drm_debugfs_connector_add(struct drm_connector *connector)
 {
-	struct drm_minor *minor = connector->dev->primary;
+	struct drm_device *dev = connector->dev;
 	struct dentry *root;
 
-	if (!minor->debugfs_root)
+	if (!dev->debugfs_root)
 		return;
 
-	root = debugfs_create_dir(connector->name, minor->debugfs_root);
+	root = debugfs_create_dir(connector->name, dev->debugfs_root);
 	connector->debugfs_entry = root;
 
 	/* force */
@@ -588,7 +616,7 @@ void drm_debugfs_connector_remove(struct drm_connector *connector)
 
 void drm_debugfs_crtc_add(struct drm_crtc *crtc)
 {
-	struct drm_minor *minor = crtc->dev->primary;
+	struct drm_device *dev = crtc->dev;
 	struct dentry *root;
 	char *name;
 
@@ -596,7 +624,7 @@ void drm_debugfs_crtc_add(struct drm_crtc *crtc)
 	if (!name)
 		return;
 
-	root = debugfs_create_dir(name, minor->debugfs_root);
+	root = debugfs_create_dir(name, dev->debugfs_root);
 	kfree(name);
 
 	crtc->debugfs_entry = root;
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 3eda026ffac6..d28f415cd733 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -172,10 +172,9 @@ static int drm_minor_register(struct drm_device *dev, enum drm_minor_type type)
 	if (!minor)
 		return 0;
 
-	if (minor->type == DRM_MINOR_ACCEL) {
-		accel_debugfs_init(minor, minor->index);
-	} else {
-		ret = drm_debugfs_init(minor, minor->index, drm_debugfs_root);
+	if (minor->type != DRM_MINOR_ACCEL) {
+		ret = drm_debugfs_register(minor, minor->index,
+					   drm_debugfs_root);
 		if (ret) {
 			DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n");
 			goto err_debugfs;
@@ -697,6 +696,11 @@ static int drm_dev_init(struct drm_device *dev,
 		goto err;
 	}
 
+	if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL))
+		accel_debugfs_init(dev);
+	else
+		drm_debugfs_dev_init(dev, drm_debugfs_root);
+
 	return 0;
 
 err:
@@ -786,6 +790,9 @@ static void drm_dev_release(struct kref *ref)
 {
 	struct drm_device *dev = container_of(ref, struct drm_device, ref);
 
+	/* Just in case register/unregister was never called */
+	drm_debugfs_dev_fini(dev);
+
 	if (dev->driver->release)
 		dev->driver->release(dev);
 
@@ -916,6 +923,11 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
 	if (drm_dev_needs_global_mutex(dev))
 		mutex_lock(&drm_global_mutex);
 
+	if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL))
+		accel_debugfs_register(dev);
+	else
+		drm_debugfs_dev_register(dev);
+
 	ret = drm_minor_register(dev, DRM_MINOR_RENDER);
 	if (ret)
 		goto err_minors;
@@ -1001,6 +1013,7 @@ void drm_dev_unregister(struct drm_device *dev)
 	drm_minor_unregister(dev, DRM_MINOR_ACCEL);
 	drm_minor_unregister(dev, DRM_MINOR_PRIMARY);
 	drm_minor_unregister(dev, DRM_MINOR_RENDER);
+	drm_debugfs_dev_fini(dev);
 }
 EXPORT_SYMBOL(drm_dev_unregister);
 
diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
index aff3746dedfb..ba51deb6d042 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -1222,9 +1222,9 @@ static const struct drm_debugfs_info drm_framebuffer_debugfs_list[] = {
 	{ "framebuffer", drm_framebuffer_info, 0 },
 };
 
-void drm_framebuffer_debugfs_init(struct drm_minor *minor)
+void drm_framebuffer_debugfs_init(struct drm_device *dev)
 {
-	drm_debugfs_add_files(minor->dev, drm_framebuffer_debugfs_list,
+	drm_debugfs_add_files(dev, drm_framebuffer_debugfs_list,
 			      ARRAY_SIZE(drm_framebuffer_debugfs_list));
 }
 #endif
diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h
index ba12acd55139..dee75a9cc59e 100644
--- a/drivers/gpu/drm/drm_internal.h
+++ b/drivers/gpu/drm/drm_internal.h
@@ -180,8 +180,10 @@ void drm_gem_vunmap(struct drm_gem_object *obj, struct iosys_map *map);
 
 /* drm_debugfs.c drm_debugfs_crc.c */
 #if defined(CONFIG_DEBUG_FS)
-int drm_debugfs_init(struct drm_minor *minor, int minor_id,
-		     struct dentry *root);
+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);
 void drm_debugfs_cleanup(struct drm_minor *minor);
 void drm_debugfs_late_register(struct drm_device *dev);
 void drm_debugfs_connector_add(struct drm_connector *connector);
@@ -190,8 +192,16 @@ void drm_debugfs_crtc_add(struct drm_crtc *crtc);
 void drm_debugfs_crtc_remove(struct drm_crtc *crtc);
 void drm_debugfs_crtc_crc_add(struct drm_crtc *crtc);
 #else
-static inline int drm_debugfs_init(struct drm_minor *minor, int minor_id,
-				   struct dentry *root)
+static inline void drm_debugfs_dev_fini(struct drm_device *dev)
+{
+}
+
+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)
 {
 	return 0;
 }
@@ -259,4 +269,4 @@ int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
 /* drm_framebuffer.c */
 void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent,
 				const struct drm_framebuffer *fb);
-void drm_framebuffer_debugfs_init(struct drm_minor *minor);
+void drm_framebuffer_debugfs_init(struct drm_device *dev);
diff --git a/include/drm/drm_accel.h b/include/drm/drm_accel.h
index d4955062c77e..f4d3784b1dce 100644
--- a/include/drm/drm_accel.h
+++ b/include/drm/drm_accel.h
@@ -58,7 +58,8 @@ int accel_minor_alloc(void);
 void accel_minor_replace(struct drm_minor *minor, int index);
 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_minor *minor, int minor_id);
+void accel_debugfs_init(struct drm_device *dev);
+void accel_debugfs_register(struct drm_device *dev);
 
 #else
 
@@ -89,7 +90,11 @@ static inline void accel_set_device_instance_params(struct device *kdev, int ind
 {
 }
 
-static inline void accel_debugfs_init(struct drm_minor *minor, int minor_id)
+static inline void accel_debugfs_init(struct drm_device *dev)
+{
+}
+
+static inline void accel_debugfs_register(struct drm_device *dev)
 {
 }
 
diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h
index c339fc85fd07..2dd94224f17e 100644
--- a/include/drm/drm_bridge.h
+++ b/include/drm/drm_bridge.h
@@ -950,6 +950,6 @@ static inline struct drm_bridge *drmm_of_get_bridge(struct drm_device *drm,
 }
 #endif
 
-void drm_bridge_debugfs_init(struct drm_minor *minor);
+void drm_bridge_debugfs_init(struct drm_device *dev);
 
 #endif
diff --git a/include/drm/drm_client.h b/include/drm/drm_client.h
index c0a14b40c039..d47458ecdac4 100644
--- a/include/drm/drm_client.h
+++ b/include/drm/drm_client.h
@@ -195,6 +195,6 @@ int drm_client_modeset_dpms(struct drm_client_dev *client, int mode);
 	drm_for_each_connector_iter(connector, iter) \
 		if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
 
-void drm_client_debugfs_init(struct drm_minor *minor);
+void drm_client_debugfs_init(struct drm_device *dev);
 
 #endif
diff --git a/include/drm/drm_device.h b/include/drm/drm_device.h
index 7cf4afae2e79..3cf12b14232d 100644
--- a/include/drm/drm_device.h
+++ b/include/drm/drm_device.h
@@ -311,6 +311,13 @@ struct drm_device {
 	 */
 	struct drm_fb_helper *fb_helper;
 
+	/**
+	 * @debugfs_root:
+	 *
+	 * Root directory for debugfs files.
+	 */
+	struct dentry *debugfs_root;
+
 	/**
 	 * @debugfs_mutex:
 	 *
diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
index 9813fa759b75..9850fe73b739 100644
--- a/include/drm/drm_drv.h
+++ b/include/drm/drm_drv.h
@@ -581,4 +581,12 @@ static inline bool drm_firmware_drivers_only(void)
 	return video_firmware_drivers_only();
 }
 
+#if defined(CONFIG_DEBUG_FS)
+void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root);
+#else
+static void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root)
+{
+}
+#endif
+
 #endif
diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h
index 010239392adf..12930a08368c 100644
--- a/include/drm/drm_file.h
+++ b/include/drm/drm_file.h
@@ -79,6 +79,7 @@ struct drm_minor {
 	struct device *kdev;		/* Linux device */
 	struct drm_device *dev;
 
+	struct dentry *debugfs_symlink;
 	struct dentry *debugfs_root;
 
 	struct list_head debugfs_list;
-- 
2.34.1


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

* [PATCH 4/5] drm/debugfs: remove dev->debugfs_list and debugfs_mutex v2
  2023-08-29 11:01 DRM debugfs cleanup take 6 Christian König
                   ` (2 preceding siblings ...)
  2023-08-29 11:01 ` [PATCH 3/5] drm/debugfs: rework debugfs directory creation v5 Christian König
@ 2023-08-29 11:01 ` Christian König
  2023-08-31 21:56   ` Andi Shyti
  2023-08-29 11:01 ` [PATCH 5/5] drm/debugfs: rework drm_debugfs_create_files implementation v2 Christian König
  4 siblings, 1 reply; 18+ messages in thread
From: Christian König @ 2023-08-29 11:01 UTC (permalink / raw)
  To: ogabbay, ttayar, dri-devel

The mutex was completely pointless in the first place since any
parallel adding of files to this list would result in random
behavior since the list is filled and consumed multiple times.

Completely drop that approach and just create the files directly but
return -ENODEV while opening the file when the minors are not
registered yet.

v2: rebase on debugfs directory rework, limit access before minors are
    registered.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/drm_debugfs.c     | 27 ++-------------------------
 drivers/gpu/drm/drm_drv.c         |  3 ---
 drivers/gpu/drm/drm_internal.h    |  5 -----
 drivers/gpu/drm/drm_mode_config.c |  2 --
 include/drm/drm_device.h          | 15 ---------------
 5 files changed, 2 insertions(+), 50 deletions(-)

diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index 5ec28c0e12d9..d0c6492d5de1 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -308,7 +308,6 @@ int drm_debugfs_register(struct drm_minor *minor, int minor_id,
 			 struct dentry *root)
 {
 	struct drm_device *dev = minor->dev;
-	struct drm_debugfs_entry *entry, *tmp;
 	char name[64];
 
 	INIT_LIST_HEAD(&minor->debugfs_list);
@@ -323,30 +322,9 @@ int drm_debugfs_register(struct drm_minor *minor, int minor_id,
 	if (dev->driver->debugfs_init && dev->render != minor)
 		dev->driver->debugfs_init(minor);
 
-	list_for_each_entry_safe(entry, tmp, &dev->debugfs_list, list) {
-		debugfs_create_file(entry->file.name, 0444,
-				    minor->debugfs_root, entry, &drm_debugfs_entry_fops);
-		list_del(&entry->list);
-	}
-
 	return 0;
 }
 
-void drm_debugfs_late_register(struct drm_device *dev)
-{
-	struct drm_minor *minor = dev->primary;
-	struct drm_debugfs_entry *entry, *tmp;
-
-	if (!minor)
-		return;
-
-	list_for_each_entry_safe(entry, tmp, &dev->debugfs_list, list) {
-		debugfs_create_file(entry->file.name, 0444,
-				    minor->debugfs_root, entry, &drm_debugfs_entry_fops);
-		list_del(&entry->list);
-	}
-}
-
 int drm_debugfs_remove_files(const struct drm_info_list *files, int count,
 			     struct drm_minor *minor)
 {
@@ -416,9 +394,8 @@ void drm_debugfs_add_file(struct drm_device *dev, const char *name,
 	entry->file.data = data;
 	entry->dev = dev;
 
-	mutex_lock(&dev->debugfs_mutex);
-	list_add(&entry->list, &dev->debugfs_list);
-	mutex_unlock(&dev->debugfs_mutex);
+	debugfs_create_file(name, 0444, dev->debugfs_root, entry,
+			    &drm_debugfs_entry_fops);
 }
 EXPORT_SYMBOL(drm_debugfs_add_file);
 
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index d28f415cd733..45053f3371ca 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -597,7 +597,6 @@ static void drm_dev_init_release(struct drm_device *dev, void *res)
 	mutex_destroy(&dev->clientlist_mutex);
 	mutex_destroy(&dev->filelist_mutex);
 	mutex_destroy(&dev->struct_mutex);
-	mutex_destroy(&dev->debugfs_mutex);
 	drm_legacy_destroy_members(dev);
 }
 
@@ -638,14 +637,12 @@ static int drm_dev_init(struct drm_device *dev,
 	INIT_LIST_HEAD(&dev->filelist_internal);
 	INIT_LIST_HEAD(&dev->clientlist);
 	INIT_LIST_HEAD(&dev->vblank_event_list);
-	INIT_LIST_HEAD(&dev->debugfs_list);
 
 	spin_lock_init(&dev->event_lock);
 	mutex_init(&dev->struct_mutex);
 	mutex_init(&dev->filelist_mutex);
 	mutex_init(&dev->clientlist_mutex);
 	mutex_init(&dev->master_mutex);
-	mutex_init(&dev->debugfs_mutex);
 
 	ret = drmm_add_action_or_reset(dev, drm_dev_init_release, NULL);
 	if (ret)
diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h
index dee75a9cc59e..ec8a1e9c19e8 100644
--- a/drivers/gpu/drm/drm_internal.h
+++ b/drivers/gpu/drm/drm_internal.h
@@ -185,7 +185,6 @@ void drm_debugfs_dev_register(struct drm_device *dev);
 int drm_debugfs_register(struct drm_minor *minor, int minor_id,
 			 struct dentry *root);
 void drm_debugfs_cleanup(struct drm_minor *minor);
-void drm_debugfs_late_register(struct drm_device *dev);
 void drm_debugfs_connector_add(struct drm_connector *connector);
 void drm_debugfs_connector_remove(struct drm_connector *connector);
 void drm_debugfs_crtc_add(struct drm_crtc *crtc);
@@ -210,10 +209,6 @@ static inline void drm_debugfs_cleanup(struct drm_minor *minor)
 {
 }
 
-static inline void drm_debugfs_late_register(struct drm_device *dev)
-{
-}
-
 static inline void drm_debugfs_connector_add(struct drm_connector *connector)
 {
 }
diff --git a/drivers/gpu/drm/drm_mode_config.c b/drivers/gpu/drm/drm_mode_config.c
index 87eb591fe9b5..8525ef851540 100644
--- a/drivers/gpu/drm/drm_mode_config.c
+++ b/drivers/gpu/drm/drm_mode_config.c
@@ -54,8 +54,6 @@ int drm_modeset_register_all(struct drm_device *dev)
 	if (ret)
 		goto err_connector;
 
-	drm_debugfs_late_register(dev);
-
 	return 0;
 
 err_connector:
diff --git a/include/drm/drm_device.h b/include/drm/drm_device.h
index 3cf12b14232d..c490977ee250 100644
--- a/include/drm/drm_device.h
+++ b/include/drm/drm_device.h
@@ -318,21 +318,6 @@ struct drm_device {
 	 */
 	struct dentry *debugfs_root;
 
-	/**
-	 * @debugfs_mutex:
-	 *
-	 * Protects &debugfs_list access.
-	 */
-	struct mutex debugfs_mutex;
-
-	/**
-	 * @debugfs_list:
-	 *
-	 * List of debugfs files to be created by the DRM device. The files
-	 * must be added during drm_dev_register().
-	 */
-	struct list_head debugfs_list;
-
 	/* Everything below here is for legacy driver, never use! */
 	/* private: */
 #if IS_ENABLED(CONFIG_DRM_LEGACY)
-- 
2.34.1


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

* [PATCH 5/5] drm/debugfs: rework drm_debugfs_create_files implementation v2
  2023-08-29 11:01 DRM debugfs cleanup take 6 Christian König
                   ` (3 preceding siblings ...)
  2023-08-29 11:01 ` [PATCH 4/5] drm/debugfs: remove dev->debugfs_list and debugfs_mutex v2 Christian König
@ 2023-08-29 11:01 ` Christian König
  2023-08-31 22:06   ` Andi Shyti
  4 siblings, 1 reply; 18+ messages in thread
From: Christian König @ 2023-08-29 11:01 UTC (permalink / raw)
  To: ogabbay, ttayar, dri-devel

Use managed memory allocation for this. That allows us to not keep
track of all the files any more.

v2: keep drm_debugfs_cleanup(), but rename to drm_debugfs_unregister(),
    we still need to cleanup the symlink

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/accel/drm_accel.c      |  2 -
 drivers/gpu/drm/drm_debugfs.c  | 70 ++++++++++------------------------
 drivers/gpu/drm/drm_drv.c      |  4 +-
 drivers/gpu/drm/drm_internal.h |  4 +-
 drivers/gpu/drm/tegra/dc.c     |  9 ++++-
 drivers/gpu/drm/tegra/dsi.c    |  1 +
 drivers/gpu/drm/tegra/hdmi.c   |  3 +-
 drivers/gpu/drm/tegra/sor.c    |  1 +
 include/drm/drm_debugfs.h      |  4 +-
 include/drm/drm_file.h         |  3 --
 10 files changed, 39 insertions(+), 62 deletions(-)

diff --git a/drivers/accel/drm_accel.c b/drivers/accel/drm_accel.c
index 8ba3db2ec5bb..94b4ac12cf24 100644
--- a/drivers/accel/drm_accel.c
+++ b/drivers/accel/drm_accel.c
@@ -99,8 +99,6 @@ void accel_debugfs_register(struct drm_device *dev)
 {
 	struct drm_minor *minor = dev->accel;
 
-	INIT_LIST_HEAD(&minor->debugfs_list);
-	mutex_init(&minor->debugfs_lock);
 	minor->debugfs_root = dev->debugfs_root;
 
 	drm_debugfs_create_files(accel_debugfs_list, ACCEL_DEBUGFS_ENTRIES,
diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index d0c6492d5de1..34c7d1a580e3 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -234,7 +234,7 @@ EXPORT_SYMBOL(drm_debugfs_gpuva_info);
  *
  * Create a given set of debugfs files represented by an array of
  * &struct drm_info_list in the given root directory. These files will be removed
- * automatically on drm_debugfs_cleanup().
+ * automatically on drm_debugfs_dev_fini().
  */
 void drm_debugfs_create_files(const struct drm_info_list *files, int count,
 			      struct dentry *root, struct drm_minor *minor)
@@ -249,7 +249,7 @@ void drm_debugfs_create_files(const struct drm_info_list *files, int count,
 		if (features && !drm_core_check_all_features(dev, features))
 			continue;
 
-		tmp = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL);
+		tmp = drmm_kzalloc(dev, sizeof(*tmp), GFP_KERNEL);
 		if (tmp == NULL)
 			continue;
 
@@ -258,14 +258,28 @@ void drm_debugfs_create_files(const struct drm_info_list *files, int count,
 						0444, root, tmp,
 						&drm_debugfs_fops);
 		tmp->info_ent = &files[i];
-
-		mutex_lock(&minor->debugfs_lock);
-		list_add(&tmp->list, &minor->debugfs_list);
-		mutex_unlock(&minor->debugfs_lock);
 	}
 }
 EXPORT_SYMBOL(drm_debugfs_create_files);
 
+int drm_debugfs_remove_files(const struct drm_info_list *files, int count,
+			     struct dentry *root, struct drm_minor *minor)
+{
+	int i;
+
+	for (i = 0; i < count; i++) {
+		struct dentry *dent = debugfs_lookup(files[i].name, root);
+
+		if (!dent)
+			continue;
+
+		drmm_kfree(minor->dev, d_inode(dent)->i_private);
+		debugfs_remove(dent);
+	}
+	return 0;
+}
+EXPORT_SYMBOL(drm_debugfs_remove_files);
+
 /**
  * drm_debugfs_dev_init - create debugfs directory for the device
  * @dev: the device which we want to create the directory for
@@ -310,8 +324,6 @@ int drm_debugfs_register(struct drm_minor *minor, int minor_id,
 	struct drm_device *dev = minor->dev;
 	char name[64];
 
-	INIT_LIST_HEAD(&minor->debugfs_list);
-	mutex_init(&minor->debugfs_lock);
 	sprintf(name, "%d", minor_id);
 	minor->debugfs_symlink = debugfs_create_symlink(name, root,
 							dev->unique);
@@ -325,48 +337,8 @@ int drm_debugfs_register(struct drm_minor *minor, int minor_id,
 	return 0;
 }
 
-int drm_debugfs_remove_files(const struct drm_info_list *files, int count,
-			     struct drm_minor *minor)
-{
-	struct list_head *pos, *q;
-	struct drm_info_node *tmp;
-	int i;
-
-	mutex_lock(&minor->debugfs_lock);
-	for (i = 0; i < count; i++) {
-		list_for_each_safe(pos, q, &minor->debugfs_list) {
-			tmp = list_entry(pos, struct drm_info_node, list);
-			if (tmp->info_ent == &files[i]) {
-				debugfs_remove(tmp->dent);
-				list_del(pos);
-				kfree(tmp);
-			}
-		}
-	}
-	mutex_unlock(&minor->debugfs_lock);
-	return 0;
-}
-EXPORT_SYMBOL(drm_debugfs_remove_files);
-
-static void drm_debugfs_remove_all_files(struct drm_minor *minor)
-{
-	struct drm_info_node *node, *tmp;
-
-	mutex_lock(&minor->debugfs_lock);
-	list_for_each_entry_safe(node, tmp, &minor->debugfs_list, list) {
-		debugfs_remove(node->dent);
-		list_del(&node->list);
-		kfree(node);
-	}
-	mutex_unlock(&minor->debugfs_lock);
-}
-
-void drm_debugfs_cleanup(struct drm_minor *minor)
+void drm_debugfs_unregister(struct drm_minor *minor)
 {
-	if (!minor->debugfs_symlink)
-		return;
-
-	drm_debugfs_remove_all_files(minor);
 	debugfs_remove(minor->debugfs_symlink);
 	minor->debugfs_symlink = NULL;
 }
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 45053f3371ca..535f16e7882e 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -198,7 +198,7 @@ static int drm_minor_register(struct drm_device *dev, enum drm_minor_type type)
 	return 0;
 
 err_debugfs:
-	drm_debugfs_cleanup(minor);
+	drm_debugfs_unregister(minor);
 	return ret;
 }
 
@@ -222,7 +222,7 @@ static void drm_minor_unregister(struct drm_device *dev, enum drm_minor_type typ
 
 	device_del(minor->kdev);
 	dev_set_drvdata(minor->kdev, NULL); /* safety belt */
-	drm_debugfs_cleanup(minor);
+	drm_debugfs_unregister(minor);
 }
 
 /*
diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h
index ec8a1e9c19e8..ab9a472f4a47 100644
--- a/drivers/gpu/drm/drm_internal.h
+++ b/drivers/gpu/drm/drm_internal.h
@@ -184,7 +184,7 @@ 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);
-void drm_debugfs_cleanup(struct drm_minor *minor);
+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);
 void drm_debugfs_crtc_add(struct drm_crtc *crtc);
@@ -205,7 +205,7 @@ static inline int drm_debugfs_register(struct drm_minor *minor, int minor_id,
 	return 0;
 }
 
-static inline void drm_debugfs_cleanup(struct drm_minor *minor)
+static inline void drm_debugfs_unregister(struct drm_minor *minor)
 {
 }
 
diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
index 13b182ab905f..be61c9d1a4f0 100644
--- a/drivers/gpu/drm/tegra/dc.c
+++ b/drivers/gpu/drm/tegra/dc.c
@@ -1746,8 +1746,15 @@ static void tegra_dc_early_unregister(struct drm_crtc *crtc)
 	unsigned int count = ARRAY_SIZE(debugfs_files);
 	struct drm_minor *minor = crtc->dev->primary;
 	struct tegra_dc *dc = to_tegra_dc(crtc);
+	struct dentry *root;
+
+#ifdef CONFIG_DEBUG_FS
+	root = crtc->debugfs_entry;
+#else
+	root = NULL;
+#endif
 
-	drm_debugfs_remove_files(dc->debugfs_files, count, minor);
+	drm_debugfs_remove_files(dc->debugfs_files, count, root, minor);
 	kfree(dc->debugfs_files);
 	dc->debugfs_files = NULL;
 }
diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
index a9870c828374..fbfe92a816d4 100644
--- a/drivers/gpu/drm/tegra/dsi.c
+++ b/drivers/gpu/drm/tegra/dsi.c
@@ -256,6 +256,7 @@ static void tegra_dsi_early_unregister(struct drm_connector *connector)
 	struct tegra_dsi *dsi = to_dsi(output);
 
 	drm_debugfs_remove_files(dsi->debugfs_files, count,
+				 connector->debugfs_entry,
 				 connector->dev->primary);
 	kfree(dsi->debugfs_files);
 	dsi->debugfs_files = NULL;
diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
index 80c760986d9e..0ba3ca3ac509 100644
--- a/drivers/gpu/drm/tegra/hdmi.c
+++ b/drivers/gpu/drm/tegra/hdmi.c
@@ -1116,7 +1116,8 @@ static void tegra_hdmi_early_unregister(struct drm_connector *connector)
 	unsigned int count = ARRAY_SIZE(debugfs_files);
 	struct tegra_hdmi *hdmi = to_hdmi(output);
 
-	drm_debugfs_remove_files(hdmi->debugfs_files, count, minor);
+	drm_debugfs_remove_files(hdmi->debugfs_files, count,
+				 connector->debugfs_entry, minor);
 	kfree(hdmi->debugfs_files);
 	hdmi->debugfs_files = NULL;
 }
diff --git a/drivers/gpu/drm/tegra/sor.c b/drivers/gpu/drm/tegra/sor.c
index 61b437a84806..d5a3d3f4fece 100644
--- a/drivers/gpu/drm/tegra/sor.c
+++ b/drivers/gpu/drm/tegra/sor.c
@@ -1708,6 +1708,7 @@ static void tegra_sor_early_unregister(struct drm_connector *connector)
 	struct tegra_sor *sor = to_sor(output);
 
 	drm_debugfs_remove_files(sor->debugfs_files, count,
+				 connector->debugfs_entry,
 				 connector->dev->primary);
 	kfree(sor->debugfs_files);
 	sor->debugfs_files = NULL;
diff --git a/include/drm/drm_debugfs.h b/include/drm/drm_debugfs.h
index cb2c1956a214..7213ce15e4ff 100644
--- a/include/drm/drm_debugfs.h
+++ b/include/drm/drm_debugfs.h
@@ -142,8 +142,8 @@ struct drm_debugfs_entry {
 void drm_debugfs_create_files(const struct drm_info_list *files,
 			      int count, struct dentry *root,
 			      struct drm_minor *minor);
-int drm_debugfs_remove_files(const struct drm_info_list *files,
-			     int count, struct drm_minor *minor);
+int drm_debugfs_remove_files(const struct drm_info_list *files, int count,
+			     struct dentry *root, struct drm_minor *minor);
 
 void drm_debugfs_add_file(struct drm_device *dev, const char *name,
 			  int (*show)(struct seq_file*, void*), void *data);
diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h
index 12930a08368c..489cc3758a82 100644
--- a/include/drm/drm_file.h
+++ b/include/drm/drm_file.h
@@ -81,9 +81,6 @@ struct drm_minor {
 
 	struct dentry *debugfs_symlink;
 	struct dentry *debugfs_root;
-
-	struct list_head debugfs_list;
-	struct mutex debugfs_lock; /* Protects debugfs_list. */
 };
 
 /**
-- 
2.34.1


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

* Re: [PATCH 2/5] drm/debugfs: disallow debugfs access when device isn't registered
  2023-08-29 11:01 ` [PATCH 2/5] drm/debugfs: disallow debugfs access when device isn't registered Christian König
@ 2023-08-29 11:31   ` Andi Shyti
  2023-08-29 11:35     ` Christian König
  0 siblings, 1 reply; 18+ messages in thread
From: Andi Shyti @ 2023-08-29 11:31 UTC (permalink / raw)
  To: Christian König; +Cc: ogabbay, ttayar, dri-devel

Hi Christian,

On Tue, Aug 29, 2023 at 01:01:12PM +0200, Christian König wrote:
> During device bringup it might be that we can't access the debugfs files.
> Return -ENODEV until the registration is completed on access.

just wondering, if the device is not registered, how do we get
there?

Andi

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

* Re: [PATCH 2/5] drm/debugfs: disallow debugfs access when device isn't registered
  2023-08-29 11:31   ` Andi Shyti
@ 2023-08-29 11:35     ` Christian König
  2023-08-29 11:38       ` Andi Shyti
  0 siblings, 1 reply; 18+ messages in thread
From: Christian König @ 2023-08-29 11:35 UTC (permalink / raw)
  To: Andi Shyti; +Cc: ogabbay, ttayar, dri-devel

Am 29.08.23 um 13:31 schrieb Andi Shyti:
> Hi Christian,
>
> On Tue, Aug 29, 2023 at 01:01:12PM +0200, Christian König wrote:
>> During device bringup it might be that we can't access the debugfs files.
>> Return -ENODEV until the registration is completed on access.
> just wondering, if the device is not registered, how do we get
> there?

The workflow is:
1. Creation (DRM)
2. Initialization (Driver)
3. Registration (DRM)
...
4. Unregistration (DRM)
5. Deinitialization (Driver)
6. Destruction (DRM)

It is possible that debugfs files are created during driver 
initialization, but Daniel insisted that they should not be accessible 
until the registration is done (which makes the other UAPI accessible as 
well).

Christian.

>
> Andi


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

* Re: [PATCH 2/5] drm/debugfs: disallow debugfs access when device isn't registered
  2023-08-29 11:35     ` Christian König
@ 2023-08-29 11:38       ` Andi Shyti
  2023-08-29 12:31         ` Christian König
  0 siblings, 1 reply; 18+ messages in thread
From: Andi Shyti @ 2023-08-29 11:38 UTC (permalink / raw)
  To: Christian König; +Cc: ogabbay, ttayar, dri-devel, Andi Shyti

> > > During device bringup it might be that we can't access the debugfs files.
> > > Return -ENODEV until the registration is completed on access.
> > just wondering, if the device is not registered, how do we get
> > there?
> 
> The workflow is:
> 1. Creation (DRM)
> 2. Initialization (Driver)
> 3. Registration (DRM)
> ...
> 4. Unregistration (DRM)
> 5. Deinitialization (Driver)
> 6. Destruction (DRM)
> 
> It is possible that debugfs files are created during driver initialization,
> but Daniel insisted that they should not be accessible until the
> registration is done (which makes the other UAPI accessible as well).

makes sense, but then why not -EAGAIN, or -EBUSY?

Thanks,
Andi

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

* Re: [PATCH 2/5] drm/debugfs: disallow debugfs access when device isn't registered
  2023-08-29 11:38       ` Andi Shyti
@ 2023-08-29 12:31         ` Christian König
  2023-08-30  7:57           ` Christian König
  0 siblings, 1 reply; 18+ messages in thread
From: Christian König @ 2023-08-29 12:31 UTC (permalink / raw)
  To: Andi Shyti; +Cc: ogabbay, ttayar, dri-devel

Am 29.08.23 um 13:38 schrieb Andi Shyti:
>>>> During device bringup it might be that we can't access the debugfs files.
>>>> Return -ENODEV until the registration is completed on access.
>>> just wondering, if the device is not registered, how do we get
>>> there?
>> The workflow is:
>> 1. Creation (DRM)
>> 2. Initialization (Driver)
>> 3. Registration (DRM)
>> ...
>> 4. Unregistration (DRM)
>> 5. Deinitialization (Driver)
>> 6. Destruction (DRM)
>>
>> It is possible that debugfs files are created during driver initialization,
>> but Daniel insisted that they should not be accessible until the
>> registration is done (which makes the other UAPI accessible as well).
> makes sense, but then why not -EAGAIN, or -EBUSY?

Good question.

I think the main use case for this is between 4 and 6. E.g. a device 
which is hot removed and now in the process of being torn down.

In this situation we might still have references from userspace (memory 
mapping etc...), so the drm file and with it the debugfs directory is 
still there but the physical device is gone. For the IOCTL UAPI we then 
also return -ENODEV as well, so this makes sense.

The time between 1 and 3 is interesting as well, but here it's more like 
we couldn't get the device initialized and are now stuck. This happens 
sometimes during early hardware bringup and I still disagree with Daniel 
that we should block that (well on the other hand it's trivial for a 
developer to comment those checks out).

Regards,
Christian.

>
> Thanks,
> Andi


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

* Re: [PATCH 2/5] drm/debugfs: disallow debugfs access when device isn't registered
  2023-08-29 12:31         ` Christian König
@ 2023-08-30  7:57           ` Christian König
  2023-08-30  8:48             ` Andi Shyti
  0 siblings, 1 reply; 18+ messages in thread
From: Christian König @ 2023-08-30  7:57 UTC (permalink / raw)
  To: Andi Shyti, Dave Airlie, Vetter, Daniel; +Cc: ogabbay, ttayar, dri-devel

Am 29.08.23 um 14:31 schrieb Christian König:
> Am 29.08.23 um 13:38 schrieb Andi Shyti:
>>>>> During device bringup it might be that we can't access the debugfs 
>>>>> files.
>>>>> Return -ENODEV until the registration is completed on access.
>>>> just wondering, if the device is not registered, how do we get
>>>> there?
>>> The workflow is:
>>> 1. Creation (DRM)
>>> 2. Initialization (Driver)
>>> 3. Registration (DRM)
>>> ...
>>> 4. Unregistration (DRM)
>>> 5. Deinitialization (Driver)
>>> 6. Destruction (DRM)
>>>
>>> It is possible that debugfs files are created during driver 
>>> initialization,
>>> but Daniel insisted that they should not be accessible until the
>>> registration is done (which makes the other UAPI accessible as well).
>> makes sense, but then why not -EAGAIN, or -EBUSY?
>
> Good question.
>
> I think the main use case for this is between 4 and 6. E.g. a device 
> which is hot removed and now in the process of being torn down.
>
> In this situation we might still have references from userspace 
> (memory mapping etc...), so the drm file and with it the debugfs 
> directory is still there but the physical device is gone. For the 
> IOCTL UAPI we then also return -ENODEV as well, so this makes sense.
>
> The time between 1 and 3 is interesting as well, but here it's more 
> like we couldn't get the device initialized and are now stuck. This 
> happens sometimes during early hardware bringup and I still disagree 
> with Daniel that we should block that (well on the other hand it's 
> trivial for a developer to comment those checks out).

Could I get an rb for this series or at least this patch from you?

I would really like to push that now as long as neither Dave nor Daniel 
have any objections (last time I checked the Intel CI was happy as well, 
but we could re-submit that once more of course).

Thanks,
Christian.

>
> Regards,
> Christian.
>
>>
>> Thanks,
>> Andi
>


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

* Re: [PATCH 1/5] drm/debugfs: drop debugfs_init() for the render and accel node v2
  2023-08-29 11:01 ` [PATCH 1/5] drm/debugfs: drop debugfs_init() for the render and accel node v2 Christian König
@ 2023-08-30  8:19   ` Andi Shyti
  2023-08-30 14:22     ` Christian König
  2023-09-01  8:00   ` Tomer Tayar
  1 sibling, 1 reply; 18+ messages in thread
From: Andi Shyti @ 2023-08-30  8:19 UTC (permalink / raw)
  To: Christian König; +Cc: ogabbay, ttayar, dri-devel

Hi Christian,

On Tue, Aug 29, 2023 at 01:01:11PM +0200, Christian König wrote:
> We want to remove per minor debugfs directories. Start by stopping
> drivers from adding anything inside of those in the mid layer callback.
> 
> v2: drop it for the accel node as well
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>
> Tested-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>

Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> 

Thanks,
Andi

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

* Re: [PATCH 2/5] drm/debugfs: disallow debugfs access when device isn't registered
  2023-08-30  7:57           ` Christian König
@ 2023-08-30  8:48             ` Andi Shyti
  0 siblings, 0 replies; 18+ messages in thread
From: Andi Shyti @ 2023-08-30  8:48 UTC (permalink / raw)
  To: Christian König
  Cc: ogabbay, dri-devel, ttayar, Andi Shyti, Vetter, Daniel,
	Dave Airlie

Hi Christian,

> > > > > > During device bringup it might be that we can't access
> > > > > > the debugfs files.
> > > > > > Return -ENODEV until the registration is completed on access.
> > > > > just wondering, if the device is not registered, how do we get
> > > > > there?
> > > > The workflow is:
> > > > 1. Creation (DRM)
> > > > 2. Initialization (Driver)
> > > > 3. Registration (DRM)
> > > > ...
> > > > 4. Unregistration (DRM)
> > > > 5. Deinitialization (Driver)
> > > > 6. Destruction (DRM)
> > > > 
> > > > It is possible that debugfs files are created during driver
> > > > initialization,
> > > > but Daniel insisted that they should not be accessible until the
> > > > registration is done (which makes the other UAPI accessible as well).
> > > makes sense, but then why not -EAGAIN, or -EBUSY?
> > 
> > Good question.
> > 
> > I think the main use case for this is between 4 and 6. E.g. a device
> > which is hot removed and now in the process of being torn down.
> > 
> > In this situation we might still have references from userspace (memory
> > mapping etc...), so the drm file and with it the debugfs directory is
> > still there but the physical device is gone. For the IOCTL UAPI we then
> > also return -ENODEV as well, so this makes sense.
> > 
> > The time between 1 and 3 is interesting as well, but here it's more like
> > we couldn't get the device initialized and are now stuck. This happens
> > sometimes during early hardware bringup and I still disagree with Daniel
> > that we should block that (well on the other hand it's trivial for a
> > developer to comment those checks out).
> 
> Could I get an rb for this series or at least this patch from you?

I took some time thinking of possible scenarios and use cases...

What I was thinking, indeed, was scenario 1-3 and I also think
that blocking is not the right thing. In any case the probability
that this might happen is too low, not just in early bring up but
also when modprobing where a little timer would do.

For both cases, 1-3 and 4-6, I believe that -EBUSY would be
better because the device is indeed busy in both cases.

Anyway it's a tiny detail we are talking about here :)

Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> 

Andi

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

* Re: [PATCH 1/5] drm/debugfs: drop debugfs_init() for the render and accel node v2
  2023-08-30  8:19   ` Andi Shyti
@ 2023-08-30 14:22     ` Christian König
  0 siblings, 0 replies; 18+ messages in thread
From: Christian König @ 2023-08-30 14:22 UTC (permalink / raw)
  To: Andi Shyti; +Cc: ogabbay, ttayar, dri-devel

Am 30.08.23 um 10:19 schrieb Andi Shyti:
> Hi Christian,
>
> On Tue, Aug 29, 2023 at 01:01:11PM +0200, Christian König wrote:
>> We want to remove per minor debugfs directories. Start by stopping
>> drivers from adding anything inside of those in the mid layer callback.
>>
>> v2: drop it for the accel node as well
>>
>> Signed-off-by: Christian König <christian.koenig@amd.com>
>> Tested-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
> Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>

Is that for just this patch or the whole series?

Thanks,
Christian.

>
> Thanks,
> Andi


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

* Re: [PATCH 3/5] drm/debugfs: rework debugfs directory creation v5
  2023-08-29 11:01 ` [PATCH 3/5] drm/debugfs: rework debugfs directory creation v5 Christian König
@ 2023-08-31 21:49   ` Andi Shyti
  0 siblings, 0 replies; 18+ messages in thread
From: Andi Shyti @ 2023-08-31 21:49 UTC (permalink / raw)
  To: Christian König; +Cc: ogabbay, ttayar, dri-devel

Hi Christian,

On Tue, Aug 29, 2023 at 01:01:13PM +0200, Christian König wrote:
> Instead of the per minor directories only create a single debugfs
> directory for the whole device directly when the device is initialized.
> 
> For DRM devices each minor gets a symlink to the per device directory
> for now until we can be sure that this isn't useful any more in any way.
> 
> Accel devices create only the per device directory and also drops the mid
> layer callback to create driver specific files.
> 
> v2: cleanup accel component as well
> v3: fix typo when debugfs is disabled
> v4: call drm_debugfs_dev_fini() during release as well,
>     some kerneldoc typos fixed
> v5: rebased and one more kerneldoc fix
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>

Looks reasonable...

Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> 

Andi

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

* Re: [PATCH 4/5] drm/debugfs: remove dev->debugfs_list and debugfs_mutex v2
  2023-08-29 11:01 ` [PATCH 4/5] drm/debugfs: remove dev->debugfs_list and debugfs_mutex v2 Christian König
@ 2023-08-31 21:56   ` Andi Shyti
  0 siblings, 0 replies; 18+ messages in thread
From: Andi Shyti @ 2023-08-31 21:56 UTC (permalink / raw)
  To: Christian König; +Cc: ogabbay, ttayar, dri-devel

Hi Christian,

On Tue, Aug 29, 2023 at 01:01:14PM +0200, Christian König wrote:
> The mutex was completely pointless in the first place since any
> parallel adding of files to this list would result in random
> behavior since the list is filled and consumed multiple times.
> 
> Completely drop that approach and just create the files directly but
> return -ENODEV while opening the file when the minors are not
> registered yet.
> 
> v2: rebase on debugfs directory rework, limit access before minors are
>     registered.
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>

Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> 

Andi

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

* Re: [PATCH 5/5] drm/debugfs: rework drm_debugfs_create_files implementation v2
  2023-08-29 11:01 ` [PATCH 5/5] drm/debugfs: rework drm_debugfs_create_files implementation v2 Christian König
@ 2023-08-31 22:06   ` Andi Shyti
  0 siblings, 0 replies; 18+ messages in thread
From: Andi Shyti @ 2023-08-31 22:06 UTC (permalink / raw)
  To: Christian König; +Cc: ogabbay, ttayar, dri-devel

Hi Christian,

On Tue, Aug 29, 2023 at 01:01:15PM +0200, Christian König wrote:
> Use managed memory allocation for this. That allows us to not keep
> track of all the files any more.
> 
> v2: keep drm_debugfs_cleanup(), but rename to drm_debugfs_unregister(),
>     we still need to cleanup the symlink
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>

Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> 

Andi

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

* Re: [PATCH 1/5] drm/debugfs: drop debugfs_init() for the render and accel node v2
  2023-08-29 11:01 ` [PATCH 1/5] drm/debugfs: drop debugfs_init() for the render and accel node v2 Christian König
  2023-08-30  8:19   ` Andi Shyti
@ 2023-09-01  8:00   ` Tomer Tayar
  1 sibling, 0 replies; 18+ messages in thread
From: Tomer Tayar @ 2023-09-01  8:00 UTC (permalink / raw)
  To: Christian König, ogabbay@kernel.org,
	dri-devel@lists.freedesktop.org

Hi Christian,

On 29/08/2023 14:01, Christian König wrote:
> We want to remove per minor debugfs directories. Start by stopping
> drivers from adding anything inside of those in the mid layer callback.
>
> v2: drop it for the accel node as well
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> Tested-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
> ---

For the whole series:
Reviewed-by: Tomer Tayar <ttayar@habana.ai>

And at least "accel-wise":
Tested-by: Tomer Tayar <ttayar@habana.ai>

Thanks,
Tomer

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

end of thread, other threads:[~2023-09-01  8:37 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-29 11:01 DRM debugfs cleanup take 6 Christian König
2023-08-29 11:01 ` [PATCH 1/5] drm/debugfs: drop debugfs_init() for the render and accel node v2 Christian König
2023-08-30  8:19   ` Andi Shyti
2023-08-30 14:22     ` Christian König
2023-09-01  8:00   ` Tomer Tayar
2023-08-29 11:01 ` [PATCH 2/5] drm/debugfs: disallow debugfs access when device isn't registered Christian König
2023-08-29 11:31   ` Andi Shyti
2023-08-29 11:35     ` Christian König
2023-08-29 11:38       ` Andi Shyti
2023-08-29 12:31         ` Christian König
2023-08-30  7:57           ` Christian König
2023-08-30  8:48             ` Andi Shyti
2023-08-29 11:01 ` [PATCH 3/5] drm/debugfs: rework debugfs directory creation v5 Christian König
2023-08-31 21:49   ` Andi Shyti
2023-08-29 11:01 ` [PATCH 4/5] drm/debugfs: remove dev->debugfs_list and debugfs_mutex v2 Christian König
2023-08-31 21:56   ` Andi Shyti
2023-08-29 11:01 ` [PATCH 5/5] drm/debugfs: rework drm_debugfs_create_files implementation v2 Christian König
2023-08-31 22:06   ` Andi Shyti

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.