Message ID | 20230711140418.3059-6-christian.koenig@amd.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [1/5] drm/debugfs: drop debugfs_init() for the render and accel node v2 | expand |
On 11/07/2023 17:04, Christian König wrote: > Use managed memory allocation for this. That allows us to not keep > track of all the files any more. > > Signed-off-by: Christian König <christian.koenig@amd.com> > --- > drivers/accel/drm_accel.c | 2 - > drivers/gpu/drm/drm_debugfs.c | 75 +++++++++------------------------- > drivers/gpu/drm/drm_drv.c | 2 - > drivers/gpu/drm/drm_internal.h | 5 --- > 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 | 4 -- > 10 files changed, 34 insertions(+), 72 deletions(-) > > diff --git a/drivers/accel/drm_accel.c b/drivers/accel/drm_accel.c > index 82c5fcbbc164..02ccf6520d27 100644 > --- a/drivers/accel/drm_accel.c > +++ b/drivers/accel/drm_accel.c > @@ -100,8 +100,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 d723143852e3..7aea06cb6be9 100644 > --- a/drivers/gpu/drm/drm_debugfs.c > +++ b/drivers/gpu/drm/drm_debugfs.c > @@ -208,7 +208,7 @@ void drm_debugfs_create_files(const struct drm_info_list *files, int count, Need to remove the "These files will be removed automatically on drm_debugfs_cleanup()" sentence from the description of drm_debugfs_create_files(), because drm_debugfs_cleanup() is removed in this patch. > 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; > > @@ -217,14 +217,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 > @@ -267,11 +281,8 @@ 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); > + debugfs_create_symlink(name, root, dev->unique); Is it okay to not track the symlink for a later removal? Will it be removed as part of the new drm_debugfs_remove_files()? Thanks, Tomer > > /* TODO: Only for compatibility with drivers */ > minor->debugfs_root = dev->debugfs_root; > @@ -282,52 +293,6 @@ 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) > -{ > - if (!minor->debugfs_symlink) > - return; > - > - drm_debugfs_remove_all_files(minor); > - debugfs_remove(minor->debugfs_symlink); > - minor->debugfs_symlink = NULL; > -} > - > /** > * drm_debugfs_add_file - Add a given file to the DRM device debugfs file list > * @dev: drm device for the ioctl > diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c > index 521d3d75a585..3d5eaea12922 100644 > --- a/drivers/gpu/drm/drm_drv.c > +++ b/drivers/gpu/drm/drm_drv.c > @@ -198,7 +198,6 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type) > return 0; > > err_debugfs: > - drm_debugfs_cleanup(minor); > return ret; > } > > @@ -222,7 +221,6 @@ static void drm_minor_unregister(struct drm_device *dev, unsigned int type) > > device_del(minor->kdev); > dev_set_drvdata(minor->kdev, NULL); /* safety belt */ > - drm_debugfs_cleanup(minor); > } > > /* > diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h > index 5a98fd1613ee..a8f20fd58b50 100644 > --- a/drivers/gpu/drm/drm_internal.h > +++ b/drivers/gpu/drm/drm_internal.h > @@ -184,7 +184,6 @@ 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_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,10 +204,6 @@ 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_connector_add(struct drm_connector *connector) > { > } > diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c > index 6e78416e64b0..d7fdc63a6632 100644 > --- a/drivers/gpu/drm/tegra/dc.c > +++ b/drivers/gpu/drm/tegra/dc.c > @@ -1745,8 +1745,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 6eac54ae1205..d953d0a0325a 100644 > --- a/drivers/gpu/drm/tegra/hdmi.c > +++ b/drivers/gpu/drm/tegra/hdmi.c > @@ -1114,7 +1114,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 fbb63d755496..b45c569e6a0b 100644 > --- a/drivers/gpu/drm/tegra/sor.c > +++ b/drivers/gpu/drm/tegra/sor.c > @@ -1707,6 +1707,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 7616f457ce70..84ee27dc2317 100644 > --- a/include/drm/drm_debugfs.h > +++ b/include/drm/drm_debugfs.h > @@ -126,8 +126,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 016fb715b9b6..ccdc793a8264 100644 > --- a/include/drm/drm_file.h > +++ b/include/drm/drm_file.h > @@ -79,11 +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; > - struct mutex debugfs_lock; /* Protects debugfs_list. */ > }; > > /**
diff --git a/drivers/accel/drm_accel.c b/drivers/accel/drm_accel.c index 82c5fcbbc164..02ccf6520d27 100644 --- a/drivers/accel/drm_accel.c +++ b/drivers/accel/drm_accel.c @@ -100,8 +100,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 d723143852e3..7aea06cb6be9 100644 --- a/drivers/gpu/drm/drm_debugfs.c +++ b/drivers/gpu/drm/drm_debugfs.c @@ -208,7 +208,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; @@ -217,14 +217,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 @@ -267,11 +281,8 @@ 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); + debugfs_create_symlink(name, root, dev->unique); /* TODO: Only for compatibility with drivers */ minor->debugfs_root = dev->debugfs_root; @@ -282,52 +293,6 @@ 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) -{ - if (!minor->debugfs_symlink) - return; - - drm_debugfs_remove_all_files(minor); - debugfs_remove(minor->debugfs_symlink); - minor->debugfs_symlink = NULL; -} - /** * drm_debugfs_add_file - Add a given file to the DRM device debugfs file list * @dev: drm device for the ioctl diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 521d3d75a585..3d5eaea12922 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -198,7 +198,6 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type) return 0; err_debugfs: - drm_debugfs_cleanup(minor); return ret; } @@ -222,7 +221,6 @@ static void drm_minor_unregister(struct drm_device *dev, unsigned int type) device_del(minor->kdev); dev_set_drvdata(minor->kdev, NULL); /* safety belt */ - drm_debugfs_cleanup(minor); } /* diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h index 5a98fd1613ee..a8f20fd58b50 100644 --- a/drivers/gpu/drm/drm_internal.h +++ b/drivers/gpu/drm/drm_internal.h @@ -184,7 +184,6 @@ 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_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,10 +204,6 @@ 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_connector_add(struct drm_connector *connector) { } diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c index 6e78416e64b0..d7fdc63a6632 100644 --- a/drivers/gpu/drm/tegra/dc.c +++ b/drivers/gpu/drm/tegra/dc.c @@ -1745,8 +1745,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 6eac54ae1205..d953d0a0325a 100644 --- a/drivers/gpu/drm/tegra/hdmi.c +++ b/drivers/gpu/drm/tegra/hdmi.c @@ -1114,7 +1114,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 fbb63d755496..b45c569e6a0b 100644 --- a/drivers/gpu/drm/tegra/sor.c +++ b/drivers/gpu/drm/tegra/sor.c @@ -1707,6 +1707,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 7616f457ce70..84ee27dc2317 100644 --- a/include/drm/drm_debugfs.h +++ b/include/drm/drm_debugfs.h @@ -126,8 +126,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 016fb715b9b6..ccdc793a8264 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -79,11 +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; - struct mutex debugfs_lock; /* Protects debugfs_list. */ }; /**
Use managed memory allocation for this. That allows us to not keep track of all the files any more. Signed-off-by: Christian König <christian.koenig@amd.com> --- drivers/accel/drm_accel.c | 2 - drivers/gpu/drm/drm_debugfs.c | 75 +++++++++------------------------- drivers/gpu/drm/drm_drv.c | 2 - drivers/gpu/drm/drm_internal.h | 5 --- 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 | 4 -- 10 files changed, 34 insertions(+), 72 deletions(-)