DRM debugfs cleanup take 6
Subsystems (6)
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.
PATCH 1/5 drm/debugfs: drop debugfs_init() for the render and accel node v2
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
--- drivers/accel/drm_accel.c | 3 --- drivers/gpu/drm/drm_debugfs.c | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-)
drivers/accel/drm_accel.c +0 -3
@@ -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); }/**
drivers/gpu/drm/drm_debugfs.c +1 -1
@@ -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) {
Signature · 1 line
2.34.1
Re: [PATCH 1/5] drm/debugfs: drop debugfs_init() for the render and accel node v2
Hi Christian,
Quoted 7 lines · Christian König
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 <[email protected]>Tested-by Stanislaw Gruszka <[email protected]>
Thanks,
Andi
Re: [PATCH 1/5] drm/debugfs: drop debugfs_init() for the render and accel node v2
Am 30.08.23 um 10:19 schrieb Andi Shyti:
Quoted 11 lines
Hi Christian,
Quoted 7 lines · Christian König
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 <[email protected]>Tested-by Stanislaw Gruszka <[email protected]>Reviewed-by Andi Shyti <[email protected]>
Is that for just this patch or the whole series?
Thanks,
Christian.
Quoted 3 lines
Thanks,
Andi
Re: [PATCH 1/5] drm/debugfs: drop debugfs_init() for the render and accel node v2
In reply to Christian KönigHi Christian,
Quoted 8 lines · Christian König
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 <[email protected]>Tested-by Stanislaw Gruszka <[email protected]>---
For the whole series:
And at least "accel-wise":
Thanks,
Tomer
PATCH 2/5 drm/debugfs: disallow debugfs access when device isn't registered
In reply to Christian KönigDuring device bringup it might be that we can't access the debugfs files. Return -ENODEV until the registration is completed on access.
--- drivers/gpu/drm/drm_debugfs.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/gpu/drm/drm_debugfs.c +7 -0
@@ -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); }
Signature · 1 line
2.34.1
Re: [PATCH 2/5] drm/debugfs: disallow debugfs access when device isn't registered
Hi Christian,
Quoted 2 lines · Christian König
During device bringup it might be that we can't access the debugfs files. Return
-ENODEVuntil the registration is completed on access.
just wondering, if the device is not registered, how do we get there?
Andi
Re: [PATCH 2/5] drm/debugfs: disallow debugfs access when device isn't registered
Am 29.08.23 um 13:31 schrieb Andi Shyti:
Quoted 7 lines
Hi Christian,
Quoted 2 lines · Christian König
During device bringup it might be that we can't access the debugfs files. Return
-ENODEVuntil 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.
Quoted 2 lines
Andi
Re: [PATCH 2/5] drm/debugfs: disallow debugfs access when device isn't registered
Quoted 14 lines
Quoted 4 lines
Quoted 2 lines
During device bringup it might be that we can't access the debugfs files. Return
-ENODEVuntil 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)
Quoted 3 lines
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
Re: [PATCH 2/5] drm/debugfs: disallow debugfs access when device isn't registered
Am 29.08.23 um 13:38 schrieb Andi Shyti:
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
Quoted 2 lines
During device bringup it might be that we can't access the debugfs files. Return
-ENODEVuntil 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)
Quoted 4 lines
Quoted 3 lines
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.
Quoted 3 lines
Thanks,
Andi
Re: [PATCH 2/5] drm/debugfs: disallow debugfs access when device isn't registered
Am 29.08.23 um 14:31 schrieb Christian König:
Quoted 19 lines
Am 29.08.23 um 13:38 schrieb Andi Shyti:
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
Quoted 2 lines
During device bringup it might be that we can't access the debugfs files. Return
-ENODEVuntil 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)Quoted 4 lines
Quoted 3 lines
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?
Quoted 7 lines
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
-ENODEVas 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.
Quoted 8 lines
Regards,
Christian.Quoted 3 lines
Thanks,
Andi
Andi Shyti
Reviewed-byRe: [PATCH 2/5] drm/debugfs: disallow debugfs access when device isn't registered
Hi Christian,
Quoted 30 lines
Quoted 30 lines
Quoted 14 lines
Quoted 14 lines
Quoted 5 lines
Quoted 3 lines
During device bringup it might be that we can't access the debugfs files.
Return-ENODEVuntil 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)Quoted 5 lines
Quoted 4 lines
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
-ENODEVas well, so this makes sense.
Quoted 7 lines
Quoted 5 lines
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 :)
Andi
PATCH 3/5 drm/debugfs: rework debugfs directory creation v5
In reply to Christian KönigInstead 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
--- 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(-)
drivers/accel/drm_accel.c +18 -12
@@ -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); }/**
drivers/gpu/drm/drm_atomic.c +2 -2
@@ -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
drivers/gpu/drm/drm_bridge.c +2 -2
@@ -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
drivers/gpu/drm/drm_client.c +2 -2
@@ -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
drivers/gpu/drm/drm_crtc_internal.h +1 -1
@@ -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,
drivers/gpu/drm/drm_debugfs.c +52 -24
120 lines not on this page · raw message
drivers/gpu/drm/drm_drv.c +17 -4
@@ -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);
drivers/gpu/drm/drm_framebuffer.c +2 -2
@@ -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
drivers/gpu/drm/drm_internal.h +15 -5
@@ -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);
include/drm/drm_accel.h +7 -2
@@ -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) { }
include/drm/drm_bridge.h +1 -1
@@ -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
include/drm/drm_client.h +1 -1
@@ -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
include/drm/drm_device.h +7 -0
@@ -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: *
include/drm/drm_drv.h +8 -0
@@ -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
include/drm/drm_file.h +1 -0
@@ -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;
Signature · 1 line
2.34.1
Re: [PATCH 3/5] drm/debugfs: rework debugfs directory creation v5
Hi Christian,
Quoted 9 lines · Christian König
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.
Quoted 7 lines
v2: cleanup accel component as well
v3: fix typo when debugfs is disabled
v4: calldrm_debugfs_dev_fini()during release as well,
some kerneldoc typos fixed
v5: rebased and one more kerneldoc fixSigned-off-by Christian König <[email protected]>
Looks reasonable...
Andi
PATCH 4/5 drm/debugfs: remove dev->debugfs_list and debugfs_mutex v2
In reply to Christian KönigThe 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.
--- 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(-)
drivers/gpu/drm/drm_debugfs.c +2 -25
@@ -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);
drivers/gpu/drm/drm_drv.c +0 -3
@@ -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)
drivers/gpu/drm/drm_internal.h +0 -5
@@ -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) { }
drivers/gpu/drm/drm_mode_config.c +0 -2
@@ -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:
include/drm/drm_device.h +0 -15
@@ -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 )
Signature · 1 line
2.34.1
Re: [PATCH 4/5] drm/debugfs: remove dev->debugfs_list and debugfs_mutex v2
Hi Christian,
Quoted 4 lines · Christian König
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.
Quoted 8 lines
Completely drop that approach and just create the files directly but return
-ENODEVwhile 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 <[email protected]>
Andi
PATCH 5/5 drm/debugfs: rework drm_debugfs_create_files implementation v2
In reply to Christian KönigUse 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
--- 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(-)
drivers/accel/drm_accel.c +0 -2
@@ -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,
drivers/gpu/drm/drm_debugfs.c +21 -49
105 lines not on this page · raw message
drivers/gpu/drm/drm_drv.c +2 -2
@@ -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 typdevice_del (minor->kdev);dev_set_drvdata (minor->kdev,NULL );/* safety belt */ -drm_debugfs_cleanup (minor); +drm_debugfs_unregister (minor); }/*
drivers/gpu/drm/drm_internal.h +2 -2
@@ -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) { }
drivers/gpu/drm/tegra/dc.c +8 -1
@@ -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 ; }
drivers/gpu/drm/tegra/dsi.c +1 -0
@@ -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 ;
drivers/gpu/drm/tegra/hdmi.c +2 -1
@@ -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 ; }
drivers/gpu/drm/tegra/sor.c +1 -0
@@ -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 ;
include/drm/drm_debugfs.h +2 -2
@@ -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);
include/drm/drm_file.h +0 -3
@@ -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. */ };/**
Signature · 1 line
2.34.1
Re: [PATCH 5/5] drm/debugfs: rework drm_debugfs_create_files implementation v2
Hi Christian,
Quoted 7 lines · Christian König
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 todrm_debugfs_unregister(),
we still need to cleanup the symlinkSigned-off-by Christian König <[email protected]>
Andi