Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-22 Thread Stanislaw Gruszka
On Fri, Feb 17, 2023 at 08:38:28PM +0100, Daniel Vetter wrote:
> > > > > I'm firmly in the camp that debugfs does not need to work under all
> > > > > conditions, but that it must fail gracefully instead of crashing.
> > > > Yeah I mean once we talk bring-up, you can just hand-roll the necessary
> > > > bring debugfs things that you need to work before the driver is ready to
> > > > do anything.
> > > > 
> > > > But bring-up debugfs fun is rather special, same way pre-silicon support
> > > > tends to be rather special. Shipping that in distros does not sound 
> > > > like a
> > > > good idea at all to me.
> > > 
> > > Yeah, that's indeed a really good point.
> > > 
> > > I can't remember how often I had to note that module parameters would also
> > > be used by end users.
> > > 
> > > How about if the create the debugfs directory with a "." as name prefix
> > > first and then rename it as soon as the device is registered?
> > 
> > Good idea. Or the dir could have this drm_dev->unique name and be created
> > during alloc, and link in minor created during registration. That would
> > mean minor link is safe to use and unique potentially dangerous before
> > registration.
> > 
> > > Alternatively
> > > we could clear the i_mode of the directory.
> > 
> > I checked that yesterday and this does not prevent to access the file
> > for root user. Perhaps there is other smart way for blocking
> > root access in vfs just by modifying some inode field, but just
> > 'chmod  file' does not prevent that.
> > 
> > > If a power user or engineer wants to debug startup problems stuff it 
> > > should
> > > be trivial to work around that from userspace, and if people do such 
> > > things
> > > they should also know the potential consequences.
> > 
> > Fully agree.
> 
> So what about a drm module option instead (that taints the kernel as usual
> for these), which:
> - registers the debugfs dir right away
> - registers any debugfs files as soon as they get populated, instead of
>   postponing until drm_dev_register
> 
> It would only neatly work with the add_file stuff, but I guess drivers
> could still hand-roll this if needed.
> 
> I think funny games with trying to hide the files while not hiding them is
> not a great idea, and explicit "I'm debugging stuff, please stand back"
> knob sounds much better to me.

I prepared debugfs patch that allow to create not accessible directory
and publish it once everything is ready. I hope it would be accepted
by Greg KH and we could use it to make drm_debugfs_* simpler.

Would be nice if someone could test it and/or comment,
before I would post it further.

Thanks
Stanislaw

>From 6bb4d38d90428904ac59a2717970697621a32a79 Mon Sep 17 00:00:00 2001
From: Stanislaw Gruszka 
Date: Tue, 21 Feb 2023 10:39:47 +0100
Subject: [PATCH] debugfs: introduce support for partially-initialized drivers

The i915 driver, among others, includes multiple subsystems that create
debugfs files in different parts of the code. It's important that these
files are not accessed before the driver is fully initialized, as doing
so could cause issues.

This patch adds support for creating a debugfs directory that will
prevent access to its files until a certain point in initialization is
reached, at which point the driver can signal that it's safe to access
the directory. This ensures that debugfs files are accessed only when
it's safe to do so.

Signed-off-by: Stanislaw Gruszka 
---
 fs/debugfs/inode.c  | 59 ++---
 fs/debugfs/internal.h   |  7 +
 include/linux/debugfs.h |  3 +++
 3 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 2e8e112b1993..04b88a5fab61 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -55,12 +55,23 @@ static int debugfs_setattr(struct user_namespace 
*mnt_userns,
return simple_setattr(_user_ns, dentry, ia);
 }
 
+static int debugfs_permission(struct user_namespace *mnt_userns, struct inode 
*inode, int mask)
+{
+   unsigned long priv = (unsigned long) inode->i_private;
+
+   if (S_ISDIR(inode->i_mode) && (priv & DEBUGFS_DIR_PREPARING))
+   return (priv & DEBUGFS_ALLOW_CREATE) ? 0 : -EPERM;
+
+   return generic_permission(mnt_userns, inode, mask);
+}
+
 static const struct inode_operations debugfs_file_inode_operations = {
.setattr= debugfs_setattr,
 };
 static const struct inode_operations debugfs_dir_inode_operations = {
.lookup = simple_lookup,
.setattr= debugfs_setattr,
+   .permission = debugfs_permission,
 };
 static const struct inode_operations debugfs_symlink_inode_operations = {
.get_link   = simple_get_link,
@@ -340,6 +351,7 @@ EXPORT_SYMBOL_GPL(debugfs_lookup);
 static struct dentry *start_creating(const char *name, struct dentry *parent)
 {
struct dentry *dentry;
+   unsigned long priv;
int error;
 
if (!(debugfs_allow & DEBUGFS_ALLOW_API))

Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-17 Thread Christian König

Am 17.02.23 um 20:38 schrieb Daniel Vetter:

On Fri, Feb 17, 2023 at 11:01:18AM +0100, Stanislaw Gruszka wrote:

On Fri, Feb 17, 2023 at 10:22:25AM +0100, Christian König wrote:

Am 16.02.23 um 20:54 schrieb Daniel Vetter:

On Thu, Feb 16, 2023 at 07:08:49PM +0200, Jani Nikula wrote:

On Thu, 16 Feb 2023, Christian König  wrote:

Am 16.02.23 um 17:46 schrieb Jani Nikula:

On Thu, 16 Feb 2023, Christian König  wrote:

Am 16.02.23 um 12:33 schrieb Daniel Vetter:

On Thu, Feb 09, 2023 at 09:18:38AM +0100, 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.

This also re-adds the debugfs files to the render node directory and
removes drm_debugfs_late_register().

Signed-off-by: Christian König 
---
 drivers/gpu/drm/drm_debugfs.c | 32 +++
 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, 7 insertions(+), 50 deletions(-)

diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index 558e3a7271a5..a40288e67264 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -246,31 +246,9 @@ void drm_debugfs_dev_register(struct drm_device *dev)
 void drm_debugfs_minor_register(struct drm_minor *minor)
 {
struct drm_device *dev = minor->dev;
-   struct drm_debugfs_entry *entry, *tmp;
if (dev->driver->debugfs_init)
dev->driver->debugfs_init(minor);
-
-   list_for_each_entry_safe(entry, tmp, >debugfs_list, list) {
-   debugfs_create_file(entry->file.name, 0444,
-   minor->debugfs_root, entry, 
_debugfs_entry_fops);
-   list_del(>list);
-   }
-}
-
-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, >debugfs_list, list) {
-   debugfs_create_file(entry->file.name, 0444,
-   minor->debugfs_root, entry, 
_debugfs_entry_fops);
-   list_del(>list);
-   }
 }
 int drm_debugfs_remove_files(const struct drm_info_list *files, int count,
@@ -343,9 +321,13 @@ void drm_debugfs_add_file(struct drm_device *dev, const 
char *name,
entry->file.data = data;
entry->dev = dev;
-   mutex_lock(>debugfs_mutex);
-   list_add(>list, >debugfs_list);
-   mutex_unlock(>debugfs_mutex);
+   debugfs_create_file(name, 0444, dev->primary->debugfs_root, entry,
+   _debugfs_entry_fops);
+
+   /* TODO: This should probably only be a symlink */
+   if (dev->render)
+   debugfs_create_file(name, 0444, dev->render->debugfs_root,
+   entry, _debugfs_entry_fops);

Nope. You are fundamentally missing the point of all this, which is:

- drivers create debugfs files whenever they want to, as long as it's
  _before_ drm_dev_register is called.

- drm_dev_register will set them all up.

This is necessary because otherwise you have the potential for some nice
oops and stuff when userspace tries to access these files before the
driver is ready.

Note that with sysfs all this infrastructure already exists, which is why
you can create sysfs files whenever you feel like, and things wont go
boom.

Well Yeah I've considered that, I just don't think it's a good idea for
debugfs.

debugfs is meant to be a helper for debugging things and that especially
includes the time between drm_dev_init() and drm_dev_register() because
that's where we probe the hardware and try to get it working.

Not having the debugfs files which allows for things like hardware
register access and reading internal state during that is a really and I
mean REALLY bad idea. This is essentially what we have those files for.

So you mean you want to have early debugfs so you can have some script
hammering the debugfs to get info out between init and register during
probe?

Well not hammering. What we usually do in bringup is to set firmware
timeout to infinity and the driver then sits and waits for the hw.

The tool used to access registers then goes directly through the PCI bar
at the moment, but that's essentially a bad idea for registers which you
grab a lock for to access (like index/data).


I just think registering debugfs before everything is ready is a recipe
for disaster. All of the debugfs needs to check all the conditions that
they need across all of the probe stages. It'll be difficult to get it
right. And you'll get cargo culted checks copy pasted 

Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-17 Thread Christian König

Am 17.02.23 um 20:42 schrieb Daniel Vetter:

On Fri, Feb 17, 2023 at 04:55:27PM +0100, Christian König wrote:

Am 17.02.23 um 13:37 schrieb Jani Nikula:

On Fri, 17 Feb 2023, Christian König  wrote:

If i915 have such structural problems then I strongly suggest to solve
them inside i915 and not make common code out of that.

All other things aside, that's just a completely unnecessary and
unhelpful remark.

Sorry, but why?

We have gone through the same problems on radeon and it was massively
painful, what I try here is to prevent others from using this bad design as
well. And yes I think devm_ and drmm_ is a bit questionable in that regard
as well.

The goal is not to make it as simple as possible to write a driver, but
rather as defensive as possible. In other words automatically releasing
memory when an object is destroyed might be helpful, but it isn't
automatically a good idea.

What can easily happen for example is that you run into use after free
situations on object reference decommissions, e.g. parent is freed before
child for example.

I know that radeon/amd are going different paths on this, but I think it's
also very clear that you're not really representing the consensus here.
For smaller drivers especially there really isn't anyone arguing against
devm/drmm.


Which I completely agree on. It's just that we shouldn't promote it as 
"Hey this magically makes everything work in your very complex use case".


It can be a good tool to have such stuff which makes sense in a lot of 
use case, but everybody using it should always keep its downsides in 
mind as well.



Similar for uapi interfaces that just do the right thing and prevent
races. You're the very first one who argued this is a good thing to have.
kernfs/kobj/sysfs people spend endless amounts of engineer on trying to
build something that's impossible to get wrong, or at least get as close
to that as feasible.


Yeah, for kernfs/kobj/sysfs it does make complete sense because those 
files are actually sometimes waited on by userspace tools to appear.


I just find it extremely questionable for debugfs.

Regards,
Christian.


I mean the entire rust endeavour flies under that flag too.
-Daniel




Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-17 Thread Daniel Vetter
On Fri, Feb 17, 2023 at 04:55:27PM +0100, Christian König wrote:
> Am 17.02.23 um 13:37 schrieb Jani Nikula:
> > On Fri, 17 Feb 2023, Christian König  
> > wrote:
> > > If i915 have such structural problems then I strongly suggest to solve
> > > them inside i915 and not make common code out of that.
> > All other things aside, that's just a completely unnecessary and
> > unhelpful remark.
> 
> Sorry, but why?
> 
> We have gone through the same problems on radeon and it was massively
> painful, what I try here is to prevent others from using this bad design as
> well. And yes I think devm_ and drmm_ is a bit questionable in that regard
> as well.
> 
> The goal is not to make it as simple as possible to write a driver, but
> rather as defensive as possible. In other words automatically releasing
> memory when an object is destroyed might be helpful, but it isn't
> automatically a good idea.
> 
> What can easily happen for example is that you run into use after free
> situations on object reference decommissions, e.g. parent is freed before
> child for example.

I know that radeon/amd are going different paths on this, but I think it's
also very clear that you're not really representing the consensus here.
For smaller drivers especially there really isn't anyone arguing against
devm/drmm.

Similar for uapi interfaces that just do the right thing and prevent
races. You're the very first one who argued this is a good thing to have.
kernfs/kobj/sysfs people spend endless amounts of engineer on trying to
build something that's impossible to get wrong, or at least get as close
to that as feasible.

I mean the entire rust endeavour flies under that flag too.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-17 Thread Daniel Vetter
On Fri, Feb 17, 2023 at 11:01:18AM +0100, Stanislaw Gruszka wrote:
> On Fri, Feb 17, 2023 at 10:22:25AM +0100, Christian König wrote:
> > Am 16.02.23 um 20:54 schrieb Daniel Vetter:
> > > On Thu, Feb 16, 2023 at 07:08:49PM +0200, Jani Nikula wrote:
> > > > On Thu, 16 Feb 2023, Christian König  wrote:
> > > > > Am 16.02.23 um 17:46 schrieb Jani Nikula:
> > > > > > On Thu, 16 Feb 2023, Christian König  
> > > > > > wrote:
> > > > > > > Am 16.02.23 um 12:33 schrieb Daniel Vetter:
> > > > > > > > On Thu, Feb 09, 2023 at 09:18:38AM +0100, 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.
> > > > > > > > > 
> > > > > > > > > This also re-adds the debugfs files to the render node 
> > > > > > > > > directory and
> > > > > > > > > removes drm_debugfs_late_register().
> > > > > > > > > 
> > > > > > > > > Signed-off-by: Christian König 
> > > > > > > > > ---
> > > > > > > > > drivers/gpu/drm/drm_debugfs.c | 32 
> > > > > > > > > +++
> > > > > > > > > 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, 7 insertions(+), 50 deletions(-)
> > > > > > > > > 
> > > > > > > > > diff --git a/drivers/gpu/drm/drm_debugfs.c 
> > > > > > > > > b/drivers/gpu/drm/drm_debugfs.c
> > > > > > > > > index 558e3a7271a5..a40288e67264 100644
> > > > > > > > > --- a/drivers/gpu/drm/drm_debugfs.c
> > > > > > > > > +++ b/drivers/gpu/drm/drm_debugfs.c
> > > > > > > > > @@ -246,31 +246,9 @@ void drm_debugfs_dev_register(struct 
> > > > > > > > > drm_device *dev)
> > > > > > > > > void drm_debugfs_minor_register(struct drm_minor *minor)
> > > > > > > > > {
> > > > > > > > >   struct drm_device *dev = minor->dev;
> > > > > > > > > - struct drm_debugfs_entry *entry, *tmp;
> > > > > > > > >   if (dev->driver->debugfs_init)
> > > > > > > > >   dev->driver->debugfs_init(minor);
> > > > > > > > > -
> > > > > > > > > - list_for_each_entry_safe(entry, tmp, 
> > > > > > > > > >debugfs_list, list) {
> > > > > > > > > - debugfs_create_file(entry->file.name, 0444,
> > > > > > > > > - minor->debugfs_root, entry, 
> > > > > > > > > _debugfs_entry_fops);
> > > > > > > > > - list_del(>list);
> > > > > > > > > - }
> > > > > > > > > -}
> > > > > > > > > -
> > > > > > > > > -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, 
> > > > > > > > > >debugfs_list, list) {
> > > > > > > > > - debugfs_create_file(entry->file.name, 0444,
> > > > > > > > > - minor->debugfs_root, entry, 
> > > > > > > > > _debugfs_entry_fops);
> > > > > > > > > - list_del(>list);
> > > > > > > > > - }
> > > > > > > > > }
> > > > > > > > > int drm_debugfs_remove_files(const struct drm_info_list 
> > > > > > > > > *files, int count,
> > > > > > > > > @@ -343,9 +321,13 @@ void drm_debugfs_add_file(struct 
> > > > > > > > > drm_device *dev, const char *name,
> > > > > > > > >   entry->file.data = data;
> > > > > > > > >   entry->dev = dev;
> > > > > > > > > - mutex_lock(>debugfs_mutex);
> > > > > > > > > - list_add(>list, >debugfs_list);
> > > > > > > > > - mutex_unlock(>debugfs_mutex);
> > > > > > > > > + debugfs_create_file(name, 0444, 
> > > > > > > > > dev->primary->debugfs_root, entry,
> > > > > > > > > + _debugfs_entry_fops);
> > > > > > > > > +
> > > > > > > > > + /* TODO: This should probably only be a symlink */
> > > > > > > > > + if (dev->render)
> > > > > > > > > + debugfs_create_file(name, 0444, 
> > > > > > > > > dev->render->debugfs_root,
> > > > > > > > > + entry, 
> > > > > > > > > _debugfs_entry_fops);
> > > > > > > > Nope. You are fundamentally missing the point of all this, 
> > > > > > > > which is:
> > > > > > > > 
> > > > > > > > - drivers create debugfs files whenever they want to, as long 
> > > > > > > > as it's
> > > > > > > >  _before_ drm_dev_register is called.
> > > > > > > > 
> > > > > > > > - drm_dev_register will set them all up.
> > > > > > > > 
> > > 

Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-17 Thread Christian König

Am 17.02.23 um 13:37 schrieb Jani Nikula:

On Fri, 17 Feb 2023, Christian König  wrote:

If i915 have such structural problems then I strongly suggest to solve
them inside i915 and not make common code out of that.

All other things aside, that's just a completely unnecessary and
unhelpful remark.


Sorry, but why?

We have gone through the same problems on radeon and it was massively 
painful, what I try here is to prevent others from using this bad design 
as well. And yes I think devm_ and drmm_ is a bit questionable in that 
regard as well.


The goal is not to make it as simple as possible to write a driver, but 
rather as defensive as possible. In other words automatically releasing 
memory when an object is destroyed might be helpful, but it isn't 
automatically a good idea.


What can easily happen for example is that you run into use after free 
situations on object reference decommissions, e.g. parent is freed 
before child for example.


Regards,
Christian.




BR,
Jani.






Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-17 Thread Jani Nikula
On Fri, 17 Feb 2023, Christian König  wrote:
> If i915 have such structural problems then I strongly suggest to solve 
> them inside i915 and not make common code out of that.

All other things aside, that's just a completely unnecessary and
unhelpful remark.


BR,
Jani.


-- 
Jani Nikula, Intel Open Source Graphics Center


Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-17 Thread Christian König

Am 17.02.23 um 12:36 schrieb Stanislaw Gruszka:

On Fri, Feb 17, 2023 at 12:49:41PM +0200, Jani Nikula wrote:

On Fri, 17 Feb 2023, Stanislaw Gruszka  
wrote:

On Thu, Feb 16, 2023 at 07:06:46PM +0200, Jani Nikula wrote:

But should not this the driver responsibility, call drm_debugfs_add_file()
whenever you are ready to handle operations on added file ?

In theory, yes, but in practice it's pretty hard for a non-trivial
driver to maintain that all the conditions are met.

Hmmm...


In i915 we call debugfs register all over the place only after we've
called drm_dev_register(), because it's the only sane way. But it means
we need the init and register separated everywhere, instead of init
adding files to a list to be registered later.

Isn't this done this way in i915 only because it was not possible
(and still isn't) to call drm_debugfs_create_file() before registration ?

I think it's should be ok by i915 subsystem to create it's debugfs
files and allow to access to them just after that subsystem init.

Or there are some complex dependencies between i915 subsystems,
that reading registers from one subsystem will corrupt some
other subsystem that did non finish initialization yet?

That's the point. It's really hard to figure it all out. Why bother?

I see.

Just hope we could get something simpler to limit debugfs access
before registration: unix hidden file, permissions or other way.
Because current drm_debufs_add_file() implementation looks
really over convoluted to me.


Completely agree.

We have intentionally removed exactly that approach from radeon because 
it just lead to and over all bad driver design and more problems than it 
solved.


If i915 have such structural problems then I strongly suggest to solve 
them inside i915 and not make common code out of that. This just 
encourages others to follow that lead.


Regards,
Christian.



Regards
Stanislaw





Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-17 Thread Stanislaw Gruszka
On Fri, Feb 17, 2023 at 12:49:41PM +0200, Jani Nikula wrote:
> On Fri, 17 Feb 2023, Stanislaw Gruszka  
> wrote:
> > On Thu, Feb 16, 2023 at 07:06:46PM +0200, Jani Nikula wrote:
> >> >
> >> > But should not this the driver responsibility, call 
> >> > drm_debugfs_add_file()
> >> > whenever you are ready to handle operations on added file ?
> >> 
> >> In theory, yes, but in practice it's pretty hard for a non-trivial
> >> driver to maintain that all the conditions are met.
> >
> > Hmmm... 
> >
> >> In i915 we call debugfs register all over the place only after we've
> >> called drm_dev_register(), because it's the only sane way. But it means
> >> we need the init and register separated everywhere, instead of init
> >> adding files to a list to be registered later.
> >
> > Isn't this done this way in i915 only because it was not possible
> > (and still isn't) to call drm_debugfs_create_file() before registration ?
> >
> > I think it's should be ok by i915 subsystem to create it's debugfs
> > files and allow to access to them just after that subsystem init.
> >
> > Or there are some complex dependencies between i915 subsystems,
> > that reading registers from one subsystem will corrupt some
> > other subsystem that did non finish initialization yet?
> 
> That's the point. It's really hard to figure it all out. Why bother?

I see. 

Just hope we could get something simpler to limit debugfs access
before registration: unix hidden file, permissions or other way.
Because current drm_debufs_add_file() implementation looks
really over convoluted to me.

Regards
Stanislaw



Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-17 Thread Jani Nikula
On Fri, 17 Feb 2023, Stanislaw Gruszka  
wrote:
> On Thu, Feb 16, 2023 at 07:06:46PM +0200, Jani Nikula wrote:
>> >
>> > But should not this the driver responsibility, call drm_debugfs_add_file()
>> > whenever you are ready to handle operations on added file ?
>> 
>> In theory, yes, but in practice it's pretty hard for a non-trivial
>> driver to maintain that all the conditions are met.
>
> Hmmm... 
>
>> In i915 we call debugfs register all over the place only after we've
>> called drm_dev_register(), because it's the only sane way. But it means
>> we need the init and register separated everywhere, instead of init
>> adding files to a list to be registered later.
>
> Isn't this done this way in i915 only because it was not possible
> (and still isn't) to call drm_debugfs_create_file() before registration ?
>
> I think it's should be ok by i915 subsystem to create it's debugfs
> files and allow to access to them just after that subsystem init.
>
> Or there are some complex dependencies between i915 subsystems,
> that reading registers from one subsystem will corrupt some
> other subsystem that did non finish initialization yet?

That's the point. It's really hard to figure it all out. Why bother?

BR,
Jani.


>
> Regards
> Stanislaw

-- 
Jani Nikula, Intel Open Source Graphics Center


Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-17 Thread Stanislaw Gruszka
On Thu, Feb 16, 2023 at 07:06:46PM +0200, Jani Nikula wrote:
> >
> > But should not this the driver responsibility, call drm_debugfs_add_file()
> > whenever you are ready to handle operations on added file ?
> 
> In theory, yes, but in practice it's pretty hard for a non-trivial
> driver to maintain that all the conditions are met.

Hmmm... 

> In i915 we call debugfs register all over the place only after we've
> called drm_dev_register(), because it's the only sane way. But it means
> we need the init and register separated everywhere, instead of init
> adding files to a list to be registered later.

Isn't this done this way in i915 only because it was not possible
(and still isn't) to call drm_debugfs_create_file() before registration ?

I think it's should be ok by i915 subsystem to create it's debugfs
files and allow to access to them just after that subsystem init.

Or there are some complex dependencies between i915 subsystems,
that reading registers from one subsystem will corrupt some
other subsystem that did non finish initialization yet?

Regards
Stanislaw


Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-17 Thread Stanislaw Gruszka
On Fri, Feb 17, 2023 at 10:22:25AM +0100, Christian König wrote:
> Am 16.02.23 um 20:54 schrieb Daniel Vetter:
> > On Thu, Feb 16, 2023 at 07:08:49PM +0200, Jani Nikula wrote:
> > > On Thu, 16 Feb 2023, Christian König  wrote:
> > > > Am 16.02.23 um 17:46 schrieb Jani Nikula:
> > > > > On Thu, 16 Feb 2023, Christian König  wrote:
> > > > > > Am 16.02.23 um 12:33 schrieb Daniel Vetter:
> > > > > > > On Thu, Feb 09, 2023 at 09:18:38AM +0100, 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.
> > > > > > > > 
> > > > > > > > This also re-adds the debugfs files to the render node 
> > > > > > > > directory and
> > > > > > > > removes drm_debugfs_late_register().
> > > > > > > > 
> > > > > > > > Signed-off-by: Christian König 
> > > > > > > > ---
> > > > > > > > drivers/gpu/drm/drm_debugfs.c | 32 
> > > > > > > > +++
> > > > > > > > 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, 7 insertions(+), 50 deletions(-)
> > > > > > > > 
> > > > > > > > diff --git a/drivers/gpu/drm/drm_debugfs.c 
> > > > > > > > b/drivers/gpu/drm/drm_debugfs.c
> > > > > > > > index 558e3a7271a5..a40288e67264 100644
> > > > > > > > --- a/drivers/gpu/drm/drm_debugfs.c
> > > > > > > > +++ b/drivers/gpu/drm/drm_debugfs.c
> > > > > > > > @@ -246,31 +246,9 @@ void drm_debugfs_dev_register(struct 
> > > > > > > > drm_device *dev)
> > > > > > > > void drm_debugfs_minor_register(struct drm_minor *minor)
> > > > > > > > {
> > > > > > > > struct drm_device *dev = minor->dev;
> > > > > > > > -   struct drm_debugfs_entry *entry, *tmp;
> > > > > > > > if (dev->driver->debugfs_init)
> > > > > > > > dev->driver->debugfs_init(minor);
> > > > > > > > -
> > > > > > > > -   list_for_each_entry_safe(entry, tmp, 
> > > > > > > > >debugfs_list, list) {
> > > > > > > > -   debugfs_create_file(entry->file.name, 0444,
> > > > > > > > -   minor->debugfs_root, entry, 
> > > > > > > > _debugfs_entry_fops);
> > > > > > > > -   list_del(>list);
> > > > > > > > -   }
> > > > > > > > -}
> > > > > > > > -
> > > > > > > > -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, 
> > > > > > > > >debugfs_list, list) {
> > > > > > > > -   debugfs_create_file(entry->file.name, 0444,
> > > > > > > > -   minor->debugfs_root, entry, 
> > > > > > > > _debugfs_entry_fops);
> > > > > > > > -   list_del(>list);
> > > > > > > > -   }
> > > > > > > > }
> > > > > > > > int drm_debugfs_remove_files(const struct drm_info_list 
> > > > > > > > *files, int count,
> > > > > > > > @@ -343,9 +321,13 @@ void drm_debugfs_add_file(struct 
> > > > > > > > drm_device *dev, const char *name,
> > > > > > > > entry->file.data = data;
> > > > > > > > entry->dev = dev;
> > > > > > > > -   mutex_lock(>debugfs_mutex);
> > > > > > > > -   list_add(>list, >debugfs_list);
> > > > > > > > -   mutex_unlock(>debugfs_mutex);
> > > > > > > > +   debugfs_create_file(name, 0444, 
> > > > > > > > dev->primary->debugfs_root, entry,
> > > > > > > > +   _debugfs_entry_fops);
> > > > > > > > +
> > > > > > > > +   /* TODO: This should probably only be a symlink */
> > > > > > > > +   if (dev->render)
> > > > > > > > +   debugfs_create_file(name, 0444, 
> > > > > > > > dev->render->debugfs_root,
> > > > > > > > +   entry, 
> > > > > > > > _debugfs_entry_fops);
> > > > > > > Nope. You are fundamentally missing the point of all this, which 
> > > > > > > is:
> > > > > > > 
> > > > > > > - drivers create debugfs files whenever they want to, as long as 
> > > > > > > it's
> > > > > > >  _before_ drm_dev_register is called.
> > > > > > > 
> > > > > > > - drm_dev_register will set them all up.
> > > > > > > 
> > > > > > > This is necessary because otherwise you have the potential for 
> > > > > > > some nice
> > > > > > > oops and stuff when userspace tries to access these files before 
> > > > > > > the
> > > > > > > driver is ready.
> > > > 

Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-17 Thread Christian König

Am 16.02.23 um 20:54 schrieb Daniel Vetter:

On Thu, Feb 16, 2023 at 07:08:49PM +0200, Jani Nikula wrote:

On Thu, 16 Feb 2023, Christian König  wrote:

Am 16.02.23 um 17:46 schrieb Jani Nikula:

On Thu, 16 Feb 2023, Christian König  wrote:

Am 16.02.23 um 12:33 schrieb Daniel Vetter:

On Thu, Feb 09, 2023 at 09:18:38AM +0100, 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.

This also re-adds the debugfs files to the render node directory and
removes drm_debugfs_late_register().

Signed-off-by: Christian König 
---
drivers/gpu/drm/drm_debugfs.c | 32 +++
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, 7 insertions(+), 50 deletions(-)

diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index 558e3a7271a5..a40288e67264 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -246,31 +246,9 @@ void drm_debugfs_dev_register(struct drm_device *dev)
void drm_debugfs_minor_register(struct drm_minor *minor)
{
struct drm_device *dev = minor->dev;
-   struct drm_debugfs_entry *entry, *tmp;

	if (dev->driver->debugfs_init)

dev->driver->debugfs_init(minor);
-
-   list_for_each_entry_safe(entry, tmp, >debugfs_list, list) {
-   debugfs_create_file(entry->file.name, 0444,
-   minor->debugfs_root, entry, 
_debugfs_entry_fops);
-   list_del(>list);
-   }
-}
-
-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, >debugfs_list, list) {
-   debugfs_create_file(entry->file.name, 0444,
-   minor->debugfs_root, entry, 
_debugfs_entry_fops);
-   list_del(>list);
-   }
}

int drm_debugfs_remove_files(const struct drm_info_list *files, int count,

@@ -343,9 +321,13 @@ void drm_debugfs_add_file(struct drm_device *dev, const 
char *name,
entry->file.data = data;
entry->dev = dev;

-	mutex_lock(>debugfs_mutex);

-   list_add(>list, >debugfs_list);
-   mutex_unlock(>debugfs_mutex);
+   debugfs_create_file(name, 0444, dev->primary->debugfs_root, entry,
+   _debugfs_entry_fops);
+
+   /* TODO: This should probably only be a symlink */
+   if (dev->render)
+   debugfs_create_file(name, 0444, dev->render->debugfs_root,
+   entry, _debugfs_entry_fops);

Nope. You are fundamentally missing the point of all this, which is:

- drivers create debugfs files whenever they want to, as long as it's
 _before_ drm_dev_register is called.

- drm_dev_register will set them all up.

This is necessary because otherwise you have the potential for some nice
oops and stuff when userspace tries to access these files before the
driver is ready.

Note that with sysfs all this infrastructure already exists, which is why
you can create sysfs files whenever you feel like, and things wont go
boom.

Well Yeah I've considered that, I just don't think it's a good idea for
debugfs.

debugfs is meant to be a helper for debugging things and that especially
includes the time between drm_dev_init() and drm_dev_register() because
that's where we probe the hardware and try to get it working.

Not having the debugfs files which allows for things like hardware
register access and reading internal state during that is a really and I
mean REALLY bad idea. This is essentially what we have those files for.

So you mean you want to have early debugfs so you can have some script
hammering the debugfs to get info out between init and register during
probe?

Well not hammering. What we usually do in bringup is to set firmware
timeout to infinity and the driver then sits and waits for the hw.

The tool used to access registers then goes directly through the PCI bar
at the moment, but that's essentially a bad idea for registers which you
grab a lock for to access (like index/data).


I just think registering debugfs before everything is ready is a recipe
for disaster. All of the debugfs needs to check all the conditions that
they need across all of the probe stages. It'll be difficult to get it
right. And you'll get cargo culted checks copy pasted all over the
place.

Yeah, but it's debugfs. That is not supposed to work under all conditions.

Just try to read amdgpu_regs on a not existing register index. This will
just hang or 

Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-16 Thread Daniel Vetter
On Thu, Feb 16, 2023 at 07:06:46PM +0200, Jani Nikula wrote:
> On Thu, 16 Feb 2023, Stanislaw Gruszka  
> wrote:
> > On Thu, Feb 16, 2023 at 12:33:08PM +0100, Daniel Vetter wrote:
> >> On Thu, Feb 09, 2023 at 09:18:38AM +0100, 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.
> >> > 
> >> > This also re-adds the debugfs files to the render node directory and
> >> > removes drm_debugfs_late_register().
> >> > 
> >> > Signed-off-by: Christian König 
> >> > ---
> >> >  drivers/gpu/drm/drm_debugfs.c | 32 +++
> >> >  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, 7 insertions(+), 50 deletions(-)
> >> > 
> >> > diff --git a/drivers/gpu/drm/drm_debugfs.c 
> >> > b/drivers/gpu/drm/drm_debugfs.c
> >> > index 558e3a7271a5..a40288e67264 100644
> >> > --- a/drivers/gpu/drm/drm_debugfs.c
> >> > +++ b/drivers/gpu/drm/drm_debugfs.c
> >> > @@ -246,31 +246,9 @@ void drm_debugfs_dev_register(struct drm_device 
> >> > *dev)
> >> >  void drm_debugfs_minor_register(struct drm_minor *minor)
> >> >  {
> >> >  struct drm_device *dev = minor->dev;
> >> > -struct drm_debugfs_entry *entry, *tmp;
> >> >  
> >> >  if (dev->driver->debugfs_init)
> >> >  dev->driver->debugfs_init(minor);
> >> > -
> >> > -list_for_each_entry_safe(entry, tmp, >debugfs_list, list) {
> >> > -debugfs_create_file(entry->file.name, 0444,
> >> > -minor->debugfs_root, entry, 
> >> > _debugfs_entry_fops);
> >> > -list_del(>list);
> >> > -}
> >> > -}
> >> > -
> >> > -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, >debugfs_list, list) {
> >> > -debugfs_create_file(entry->file.name, 0444,
> >> > -minor->debugfs_root, entry, 
> >> > _debugfs_entry_fops);
> >> > -list_del(>list);
> >> > -}
> >> >  }
> >> >  
> >> >  int drm_debugfs_remove_files(const struct drm_info_list *files, int 
> >> > count,
> >> > @@ -343,9 +321,13 @@ void drm_debugfs_add_file(struct drm_device *dev, 
> >> > const char *name,
> >> >  entry->file.data = data;
> >> >  entry->dev = dev;
> >> >  
> >> > -mutex_lock(>debugfs_mutex);
> >> > -list_add(>list, >debugfs_list);
> >> > -mutex_unlock(>debugfs_mutex);
> >> > +debugfs_create_file(name, 0444, dev->primary->debugfs_root, 
> >> > entry,
> >> > +_debugfs_entry_fops);
> >> > +
> >> > +/* TODO: This should probably only be a symlink */
> >> > +if (dev->render)
> >> > +debugfs_create_file(name, 0444, 
> >> > dev->render->debugfs_root,
> >> > +entry, _debugfs_entry_fops);
> >> 
> >> Nope. You are fundamentally missing the point of all this, which is:
> >> 
> >> - drivers create debugfs files whenever they want to, as long as it's
> >>   _before_ drm_dev_register is called.
> >> 
> >> - drm_dev_register will set them all up.
> >> 
> >> This is necessary because otherwise you have the potential for some nice
> >> oops and stuff when userspace tries to access these files before the
> >> driver is ready.
> >
> > But should not this the driver responsibility, call drm_debugfs_add_file()
> > whenever you are ready to handle operations on added file ?
> 
> In theory, yes, but in practice it's pretty hard for a non-trivial
> driver to maintain that all the conditions are met.
> 
> In i915 we call debugfs register all over the place only after we've
> called drm_dev_register(), because it's the only sane way. But it means
> we need the init and register separated everywhere, instead of init
> adding files to a list to be registered later.

Yup, it just forces a ton of boilerplate on drivers for no gain.

Like devm_* and drmm_* are also not needed in the strict sense, and they
are all optional. But you're a fool for not using them when you can.

Same thing with these debugfs helpers here, you can outright bypass them,
and then end up doing what amdgpu/i915 currently do: A massive and
somewhat fragile parallel function call hierarchy.

Which is just not very nice thing to be forced into.
-Daniel

> BR,
> Jani.
> 
> 
> 
> >
> > Regards
> > Stanislaw
> >
> >> Note that with sysfs all this 

Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-16 Thread Daniel Vetter
On Thu, Feb 16, 2023 at 07:08:49PM +0200, Jani Nikula wrote:
> On Thu, 16 Feb 2023, Christian König  wrote:
> > Am 16.02.23 um 17:46 schrieb Jani Nikula:
> >> On Thu, 16 Feb 2023, Christian König  wrote:
> >>> Am 16.02.23 um 12:33 schrieb Daniel Vetter:
>  On Thu, Feb 09, 2023 at 09:18:38AM +0100, 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.
> >
> > This also re-adds the debugfs files to the render node directory and
> > removes drm_debugfs_late_register().
> >
> > Signed-off-by: Christian König 
> > ---
> >drivers/gpu/drm/drm_debugfs.c | 32 
> > +++
> >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, 7 insertions(+), 50 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/drm_debugfs.c 
> > b/drivers/gpu/drm/drm_debugfs.c
> > index 558e3a7271a5..a40288e67264 100644
> > --- a/drivers/gpu/drm/drm_debugfs.c
> > +++ b/drivers/gpu/drm/drm_debugfs.c
> > @@ -246,31 +246,9 @@ void drm_debugfs_dev_register(struct drm_device 
> > *dev)
> >void drm_debugfs_minor_register(struct drm_minor *minor)
> >{
> > struct drm_device *dev = minor->dev;
> > -   struct drm_debugfs_entry *entry, *tmp;
> >
> > if (dev->driver->debugfs_init)
> > dev->driver->debugfs_init(minor);
> > -
> > -   list_for_each_entry_safe(entry, tmp, >debugfs_list, list) {
> > -   debugfs_create_file(entry->file.name, 0444,
> > -   minor->debugfs_root, entry, 
> > _debugfs_entry_fops);
> > -   list_del(>list);
> > -   }
> > -}
> > -
> > -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, >debugfs_list, list) {
> > -   debugfs_create_file(entry->file.name, 0444,
> > -   minor->debugfs_root, entry, 
> > _debugfs_entry_fops);
> > -   list_del(>list);
> > -   }
> >}
> >
> >int drm_debugfs_remove_files(const struct drm_info_list *files, int 
> > count,
> > @@ -343,9 +321,13 @@ void drm_debugfs_add_file(struct drm_device *dev, 
> > const char *name,
> > entry->file.data = data;
> > entry->dev = dev;
> >
> > -   mutex_lock(>debugfs_mutex);
> > -   list_add(>list, >debugfs_list);
> > -   mutex_unlock(>debugfs_mutex);
> > +   debugfs_create_file(name, 0444, dev->primary->debugfs_root, 
> > entry,
> > +   _debugfs_entry_fops);
> > +
> > +   /* TODO: This should probably only be a symlink */
> > +   if (dev->render)
> > +   debugfs_create_file(name, 0444, 
> > dev->render->debugfs_root,
> > +   entry, _debugfs_entry_fops);
>  Nope. You are fundamentally missing the point of all this, which is:
> 
>  - drivers create debugfs files whenever they want to, as long as it's
>  _before_ drm_dev_register is called.
> 
>  - drm_dev_register will set them all up.
> 
>  This is necessary because otherwise you have the potential for some nice
>  oops and stuff when userspace tries to access these files before the
>  driver is ready.
> 
>  Note that with sysfs all this infrastructure already exists, which is why
>  you can create sysfs files whenever you feel like, and things wont go
>  boom.
> >>> Well Yeah I've considered that, I just don't think it's a good idea for
> >>> debugfs.
> >>>
> >>> debugfs is meant to be a helper for debugging things and that especially
> >>> includes the time between drm_dev_init() and drm_dev_register() because
> >>> that's where we probe the hardware and try to get it working.
> >>>
> >>> Not having the debugfs files which allows for things like hardware
> >>> register access and reading internal state during that is a really and I
> >>> mean REALLY bad idea. This is essentially what we have those files for.
> >> So you mean you want to have early debugfs so you can have some script
> >> hammering the debugfs to get info out between init and register during
> >> probe?
> >
> > Well not hammering. What we 

Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-16 Thread Jani Nikula
On Thu, 16 Feb 2023, Stanislaw Gruszka  
wrote:
> On Thu, Feb 16, 2023 at 12:33:08PM +0100, Daniel Vetter wrote:
>> On Thu, Feb 09, 2023 at 09:18:38AM +0100, 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.
>> > 
>> > This also re-adds the debugfs files to the render node directory and
>> > removes drm_debugfs_late_register().
>> > 
>> > Signed-off-by: Christian König 
>> > ---
>> >  drivers/gpu/drm/drm_debugfs.c | 32 +++
>> >  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, 7 insertions(+), 50 deletions(-)
>> > 
>> > diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
>> > index 558e3a7271a5..a40288e67264 100644
>> > --- a/drivers/gpu/drm/drm_debugfs.c
>> > +++ b/drivers/gpu/drm/drm_debugfs.c
>> > @@ -246,31 +246,9 @@ void drm_debugfs_dev_register(struct drm_device *dev)
>> >  void drm_debugfs_minor_register(struct drm_minor *minor)
>> >  {
>> >struct drm_device *dev = minor->dev;
>> > -  struct drm_debugfs_entry *entry, *tmp;
>> >  
>> >if (dev->driver->debugfs_init)
>> >dev->driver->debugfs_init(minor);
>> > -
>> > -  list_for_each_entry_safe(entry, tmp, >debugfs_list, list) {
>> > -  debugfs_create_file(entry->file.name, 0444,
>> > -  minor->debugfs_root, entry, 
>> > _debugfs_entry_fops);
>> > -  list_del(>list);
>> > -  }
>> > -}
>> > -
>> > -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, >debugfs_list, list) {
>> > -  debugfs_create_file(entry->file.name, 0444,
>> > -  minor->debugfs_root, entry, 
>> > _debugfs_entry_fops);
>> > -  list_del(>list);
>> > -  }
>> >  }
>> >  
>> >  int drm_debugfs_remove_files(const struct drm_info_list *files, int count,
>> > @@ -343,9 +321,13 @@ void drm_debugfs_add_file(struct drm_device *dev, 
>> > const char *name,
>> >entry->file.data = data;
>> >entry->dev = dev;
>> >  
>> > -  mutex_lock(>debugfs_mutex);
>> > -  list_add(>list, >debugfs_list);
>> > -  mutex_unlock(>debugfs_mutex);
>> > +  debugfs_create_file(name, 0444, dev->primary->debugfs_root, entry,
>> > +  _debugfs_entry_fops);
>> > +
>> > +  /* TODO: This should probably only be a symlink */
>> > +  if (dev->render)
>> > +  debugfs_create_file(name, 0444, dev->render->debugfs_root,
>> > +  entry, _debugfs_entry_fops);
>> 
>> Nope. You are fundamentally missing the point of all this, which is:
>> 
>> - drivers create debugfs files whenever they want to, as long as it's
>>   _before_ drm_dev_register is called.
>> 
>> - drm_dev_register will set them all up.
>> 
>> This is necessary because otherwise you have the potential for some nice
>> oops and stuff when userspace tries to access these files before the
>> driver is ready.
>
> But should not this the driver responsibility, call drm_debugfs_add_file()
> whenever you are ready to handle operations on added file ?

In theory, yes, but in practice it's pretty hard for a non-trivial
driver to maintain that all the conditions are met.

In i915 we call debugfs register all over the place only after we've
called drm_dev_register(), because it's the only sane way. But it means
we need the init and register separated everywhere, instead of init
adding files to a list to be registered later.

BR,
Jani.



>
> Regards
> Stanislaw
>
>> Note that with sysfs all this infrastructure already exists, which is why
>> you can create sysfs files whenever you feel like, and things wont go
>> boom.
>> 
>> So yeah we need the list.
>> 
>> This also means that we really should not create the debugfs directories
>> _before_ drm_dev_register is called. That's just fundamentally not how
>> device interface setup should work:
>> 
>> 1. you allocate stucts and stuff
>> 2. you fully init everything
>> 3. you register interfaces so they become userspace visible
>> -Daniel
>> 
>> >  }
>> >  EXPORT_SYMBOL(drm_debugfs_add_file);
>> >  
>> > diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
>> > index 2cbe028e548c..e7b88b65866c 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(>clientlist_mutex);
>> >mutex_destroy(>filelist_mutex);
>> >

Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-16 Thread Jani Nikula
On Thu, 16 Feb 2023, Christian König  wrote:
> Am 16.02.23 um 17:46 schrieb Jani Nikula:
>> On Thu, 16 Feb 2023, Christian König  wrote:
>>> Am 16.02.23 um 12:33 schrieb Daniel Vetter:
 On Thu, Feb 09, 2023 at 09:18:38AM +0100, 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.
>
> This also re-adds the debugfs files to the render node directory and
> removes drm_debugfs_late_register().
>
> Signed-off-by: Christian König 
> ---
>drivers/gpu/drm/drm_debugfs.c | 32 +++
>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, 7 insertions(+), 50 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
> index 558e3a7271a5..a40288e67264 100644
> --- a/drivers/gpu/drm/drm_debugfs.c
> +++ b/drivers/gpu/drm/drm_debugfs.c
> @@ -246,31 +246,9 @@ void drm_debugfs_dev_register(struct drm_device *dev)
>void drm_debugfs_minor_register(struct drm_minor *minor)
>{
>   struct drm_device *dev = minor->dev;
> - struct drm_debugfs_entry *entry, *tmp;
>
>   if (dev->driver->debugfs_init)
>   dev->driver->debugfs_init(minor);
> -
> - list_for_each_entry_safe(entry, tmp, >debugfs_list, list) {
> - debugfs_create_file(entry->file.name, 0444,
> - minor->debugfs_root, entry, 
> _debugfs_entry_fops);
> - list_del(>list);
> - }
> -}
> -
> -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, >debugfs_list, list) {
> - debugfs_create_file(entry->file.name, 0444,
> - minor->debugfs_root, entry, 
> _debugfs_entry_fops);
> - list_del(>list);
> - }
>}
>
>int drm_debugfs_remove_files(const struct drm_info_list *files, int 
> count,
> @@ -343,9 +321,13 @@ void drm_debugfs_add_file(struct drm_device *dev, 
> const char *name,
>   entry->file.data = data;
>   entry->dev = dev;
>
> - mutex_lock(>debugfs_mutex);
> - list_add(>list, >debugfs_list);
> - mutex_unlock(>debugfs_mutex);
> + debugfs_create_file(name, 0444, dev->primary->debugfs_root, entry,
> + _debugfs_entry_fops);
> +
> + /* TODO: This should probably only be a symlink */
> + if (dev->render)
> + debugfs_create_file(name, 0444, dev->render->debugfs_root,
> + entry, _debugfs_entry_fops);
 Nope. You are fundamentally missing the point of all this, which is:

 - drivers create debugfs files whenever they want to, as long as it's
 _before_ drm_dev_register is called.

 - drm_dev_register will set them all up.

 This is necessary because otherwise you have the potential for some nice
 oops and stuff when userspace tries to access these files before the
 driver is ready.

 Note that with sysfs all this infrastructure already exists, which is why
 you can create sysfs files whenever you feel like, and things wont go
 boom.
>>> Well Yeah I've considered that, I just don't think it's a good idea for
>>> debugfs.
>>>
>>> debugfs is meant to be a helper for debugging things and that especially
>>> includes the time between drm_dev_init() and drm_dev_register() because
>>> that's where we probe the hardware and try to get it working.
>>>
>>> Not having the debugfs files which allows for things like hardware
>>> register access and reading internal state during that is a really and I
>>> mean REALLY bad idea. This is essentially what we have those files for.
>> So you mean you want to have early debugfs so you can have some script
>> hammering the debugfs to get info out between init and register during
>> probe?
>
> Well not hammering. What we usually do in bringup is to set firmware 
> timeout to infinity and the driver then sits and waits for the hw.
>
> The tool used to access registers then goes directly through the PCI bar 
> at the moment, but that's essentially a bad idea for registers which you 
> grab a lock for to access (like index/data).
>
>>
>> I just think registering debugfs before everything is ready is a recipe
>> for disaster. All of the debugfs needs to check all the 

Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-16 Thread Christian König

Am 16.02.23 um 17:46 schrieb Jani Nikula:

On Thu, 16 Feb 2023, Christian König  wrote:

Am 16.02.23 um 12:33 schrieb Daniel Vetter:

On Thu, Feb 09, 2023 at 09:18:38AM +0100, 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.

This also re-adds the debugfs files to the render node directory and
removes drm_debugfs_late_register().

Signed-off-by: Christian König 
---
   drivers/gpu/drm/drm_debugfs.c | 32 +++
   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, 7 insertions(+), 50 deletions(-)

diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index 558e3a7271a5..a40288e67264 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -246,31 +246,9 @@ void drm_debugfs_dev_register(struct drm_device *dev)
   void drm_debugfs_minor_register(struct drm_minor *minor)
   {
struct drm_device *dev = minor->dev;
-   struct drm_debugfs_entry *entry, *tmp;
   
   	if (dev->driver->debugfs_init)

dev->driver->debugfs_init(minor);
-
-   list_for_each_entry_safe(entry, tmp, >debugfs_list, list) {
-   debugfs_create_file(entry->file.name, 0444,
-   minor->debugfs_root, entry, 
_debugfs_entry_fops);
-   list_del(>list);
-   }
-}
-
-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, >debugfs_list, list) {
-   debugfs_create_file(entry->file.name, 0444,
-   minor->debugfs_root, entry, 
_debugfs_entry_fops);
-   list_del(>list);
-   }
   }
   
   int drm_debugfs_remove_files(const struct drm_info_list *files, int count,

@@ -343,9 +321,13 @@ void drm_debugfs_add_file(struct drm_device *dev, const 
char *name,
entry->file.data = data;
entry->dev = dev;
   
-	mutex_lock(>debugfs_mutex);

-   list_add(>list, >debugfs_list);
-   mutex_unlock(>debugfs_mutex);
+   debugfs_create_file(name, 0444, dev->primary->debugfs_root, entry,
+   _debugfs_entry_fops);
+
+   /* TODO: This should probably only be a symlink */
+   if (dev->render)
+   debugfs_create_file(name, 0444, dev->render->debugfs_root,
+   entry, _debugfs_entry_fops);

Nope. You are fundamentally missing the point of all this, which is:

- drivers create debugfs files whenever they want to, as long as it's
_before_ drm_dev_register is called.

- drm_dev_register will set them all up.

This is necessary because otherwise you have the potential for some nice
oops and stuff when userspace tries to access these files before the
driver is ready.

Note that with sysfs all this infrastructure already exists, which is why
you can create sysfs files whenever you feel like, and things wont go
boom.

Well Yeah I've considered that, I just don't think it's a good idea for
debugfs.

debugfs is meant to be a helper for debugging things and that especially
includes the time between drm_dev_init() and drm_dev_register() because
that's where we probe the hardware and try to get it working.

Not having the debugfs files which allows for things like hardware
register access and reading internal state during that is a really and I
mean REALLY bad idea. This is essentially what we have those files for.

So you mean you want to have early debugfs so you can have some script
hammering the debugfs to get info out between init and register during
probe?


Well not hammering. What we usually do in bringup is to set firmware 
timeout to infinity and the driver then sits and waits for the hw.


The tool used to access registers then goes directly through the PCI bar 
at the moment, but that's essentially a bad idea for registers which you 
grab a lock for to access (like index/data).




I just think registering debugfs before everything is ready is a recipe
for disaster. All of the debugfs needs to check all the conditions that
they need across all of the probe stages. It'll be difficult to get it
right. And you'll get cargo culted checks copy pasted all over the
place.


Yeah, but it's debugfs. That is not supposed to work under all conditions.

Just try to read amdgpu_regs on a not existing register index. This will 
just hang or reboot your box immediately on APUs.


Regards,
Christian.




BR,
Jani.



So yeah we need the list.

This also means that we really should not create the 

Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-16 Thread Stanislaw Gruszka
On Thu, Feb 16, 2023 at 12:33:08PM +0100, Daniel Vetter wrote:
> On Thu, Feb 09, 2023 at 09:18:38AM +0100, 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.
> > 
> > This also re-adds the debugfs files to the render node directory and
> > removes drm_debugfs_late_register().
> > 
> > Signed-off-by: Christian König 
> > ---
> >  drivers/gpu/drm/drm_debugfs.c | 32 +++
> >  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, 7 insertions(+), 50 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
> > index 558e3a7271a5..a40288e67264 100644
> > --- a/drivers/gpu/drm/drm_debugfs.c
> > +++ b/drivers/gpu/drm/drm_debugfs.c
> > @@ -246,31 +246,9 @@ void drm_debugfs_dev_register(struct drm_device *dev)
> >  void drm_debugfs_minor_register(struct drm_minor *minor)
> >  {
> > struct drm_device *dev = minor->dev;
> > -   struct drm_debugfs_entry *entry, *tmp;
> >  
> > if (dev->driver->debugfs_init)
> > dev->driver->debugfs_init(minor);
> > -
> > -   list_for_each_entry_safe(entry, tmp, >debugfs_list, list) {
> > -   debugfs_create_file(entry->file.name, 0444,
> > -   minor->debugfs_root, entry, 
> > _debugfs_entry_fops);
> > -   list_del(>list);
> > -   }
> > -}
> > -
> > -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, >debugfs_list, list) {
> > -   debugfs_create_file(entry->file.name, 0444,
> > -   minor->debugfs_root, entry, 
> > _debugfs_entry_fops);
> > -   list_del(>list);
> > -   }
> >  }
> >  
> >  int drm_debugfs_remove_files(const struct drm_info_list *files, int count,
> > @@ -343,9 +321,13 @@ void drm_debugfs_add_file(struct drm_device *dev, 
> > const char *name,
> > entry->file.data = data;
> > entry->dev = dev;
> >  
> > -   mutex_lock(>debugfs_mutex);
> > -   list_add(>list, >debugfs_list);
> > -   mutex_unlock(>debugfs_mutex);
> > +   debugfs_create_file(name, 0444, dev->primary->debugfs_root, entry,
> > +   _debugfs_entry_fops);
> > +
> > +   /* TODO: This should probably only be a symlink */
> > +   if (dev->render)
> > +   debugfs_create_file(name, 0444, dev->render->debugfs_root,
> > +   entry, _debugfs_entry_fops);
> 
> Nope. You are fundamentally missing the point of all this, which is:
> 
> - drivers create debugfs files whenever they want to, as long as it's
>   _before_ drm_dev_register is called.
> 
> - drm_dev_register will set them all up.
> 
> This is necessary because otherwise you have the potential for some nice
> oops and stuff when userspace tries to access these files before the
> driver is ready.

But should not this the driver responsibility, call drm_debugfs_add_file()
whenever you are ready to handle operations on added file ?

Regards
Stanislaw

> Note that with sysfs all this infrastructure already exists, which is why
> you can create sysfs files whenever you feel like, and things wont go
> boom.
> 
> So yeah we need the list.
> 
> This also means that we really should not create the debugfs directories
> _before_ drm_dev_register is called. That's just fundamentally not how
> device interface setup should work:
> 
> 1. you allocate stucts and stuff
> 2. you fully init everything
> 3. you register interfaces so they become userspace visible
> -Daniel
> 
> >  }
> >  EXPORT_SYMBOL(drm_debugfs_add_file);
> >  
> > diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> > index 2cbe028e548c..e7b88b65866c 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(>clientlist_mutex);
> > mutex_destroy(>filelist_mutex);
> > mutex_destroy(>struct_mutex);
> > -   mutex_destroy(>debugfs_mutex);
> > drm_legacy_destroy_members(dev);
> >  }
> >  
> > @@ -638,14 +637,12 @@ static int drm_dev_init(struct drm_device *dev,
> > INIT_LIST_HEAD(>filelist_internal);
> > INIT_LIST_HEAD(>clientlist);
> > INIT_LIST_HEAD(>vblank_event_list);
> > -   INIT_LIST_HEAD(>debugfs_list);
> >  
> > spin_lock_init(>event_lock);
> > mutex_init(>struct_mutex);
> > mutex_init(>filelist_mutex);
> > mutex_init(>clientlist_mutex);
> > mutex_init(>master_mutex);
> 

Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-16 Thread Jani Nikula
On Thu, 16 Feb 2023, Christian König  wrote:
> Am 16.02.23 um 12:33 schrieb Daniel Vetter:
>> On Thu, Feb 09, 2023 at 09:18:38AM +0100, 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.
>>>
>>> This also re-adds the debugfs files to the render node directory and
>>> removes drm_debugfs_late_register().
>>>
>>> Signed-off-by: Christian König 
>>> ---
>>>   drivers/gpu/drm/drm_debugfs.c | 32 +++
>>>   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, 7 insertions(+), 50 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
>>> index 558e3a7271a5..a40288e67264 100644
>>> --- a/drivers/gpu/drm/drm_debugfs.c
>>> +++ b/drivers/gpu/drm/drm_debugfs.c
>>> @@ -246,31 +246,9 @@ void drm_debugfs_dev_register(struct drm_device *dev)
>>>   void drm_debugfs_minor_register(struct drm_minor *minor)
>>>   {
>>> struct drm_device *dev = minor->dev;
>>> -   struct drm_debugfs_entry *entry, *tmp;
>>>   
>>> if (dev->driver->debugfs_init)
>>> dev->driver->debugfs_init(minor);
>>> -
>>> -   list_for_each_entry_safe(entry, tmp, >debugfs_list, list) {
>>> -   debugfs_create_file(entry->file.name, 0444,
>>> -   minor->debugfs_root, entry, 
>>> _debugfs_entry_fops);
>>> -   list_del(>list);
>>> -   }
>>> -}
>>> -
>>> -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, >debugfs_list, list) {
>>> -   debugfs_create_file(entry->file.name, 0444,
>>> -   minor->debugfs_root, entry, 
>>> _debugfs_entry_fops);
>>> -   list_del(>list);
>>> -   }
>>>   }
>>>   
>>>   int drm_debugfs_remove_files(const struct drm_info_list *files, int count,
>>> @@ -343,9 +321,13 @@ void drm_debugfs_add_file(struct drm_device *dev, 
>>> const char *name,
>>> entry->file.data = data;
>>> entry->dev = dev;
>>>   
>>> -   mutex_lock(>debugfs_mutex);
>>> -   list_add(>list, >debugfs_list);
>>> -   mutex_unlock(>debugfs_mutex);
>>> +   debugfs_create_file(name, 0444, dev->primary->debugfs_root, entry,
>>> +   _debugfs_entry_fops);
>>> +
>>> +   /* TODO: This should probably only be a symlink */
>>> +   if (dev->render)
>>> +   debugfs_create_file(name, 0444, dev->render->debugfs_root,
>>> +   entry, _debugfs_entry_fops);
>> Nope. You are fundamentally missing the point of all this, which is:
>>
>> - drivers create debugfs files whenever they want to, as long as it's
>>_before_ drm_dev_register is called.
>>
>> - drm_dev_register will set them all up.
>>
>> This is necessary because otherwise you have the potential for some nice
>> oops and stuff when userspace tries to access these files before the
>> driver is ready.
>>
>> Note that with sysfs all this infrastructure already exists, which is why
>> you can create sysfs files whenever you feel like, and things wont go
>> boom.
>
> Well Yeah I've considered that, I just don't think it's a good idea for 
> debugfs.
>
> debugfs is meant to be a helper for debugging things and that especially 
> includes the time between drm_dev_init() and drm_dev_register() because 
> that's where we probe the hardware and try to get it working.
>
> Not having the debugfs files which allows for things like hardware 
> register access and reading internal state during that is a really and I 
> mean REALLY bad idea. This is essentially what we have those files for.

So you mean you want to have early debugfs so you can have some script
hammering the debugfs to get info out between init and register during
probe?

I just think registering debugfs before everything is ready is a recipe
for disaster. All of the debugfs needs to check all the conditions that
they need across all of the probe stages. It'll be difficult to get it
right. And you'll get cargo culted checks copy pasted all over the
place.


BR,
Jani.


>
>> So yeah we need the list.
>>
>> This also means that we really should not create the debugfs directories
>> _before_ drm_dev_register is called. That's just fundamentally not how
>> device interface setup should work:
>>
>> 1. you allocate stucts and stuff
>> 2. you fully init everything
>> 3. you register interfaces so they become userspace visible
>
> How about we create the debugfs directory early and only delay the files 
> registered through this 

Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-16 Thread Christian König

Am 16.02.23 um 12:33 schrieb Daniel Vetter:

On Thu, Feb 09, 2023 at 09:18:38AM +0100, 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.

This also re-adds the debugfs files to the render node directory and
removes drm_debugfs_late_register().

Signed-off-by: Christian König 
---
  drivers/gpu/drm/drm_debugfs.c | 32 +++
  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, 7 insertions(+), 50 deletions(-)

diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index 558e3a7271a5..a40288e67264 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -246,31 +246,9 @@ void drm_debugfs_dev_register(struct drm_device *dev)
  void drm_debugfs_minor_register(struct drm_minor *minor)
  {
struct drm_device *dev = minor->dev;
-   struct drm_debugfs_entry *entry, *tmp;
  
  	if (dev->driver->debugfs_init)

dev->driver->debugfs_init(minor);
-
-   list_for_each_entry_safe(entry, tmp, >debugfs_list, list) {
-   debugfs_create_file(entry->file.name, 0444,
-   minor->debugfs_root, entry, 
_debugfs_entry_fops);
-   list_del(>list);
-   }
-}
-
-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, >debugfs_list, list) {
-   debugfs_create_file(entry->file.name, 0444,
-   minor->debugfs_root, entry, 
_debugfs_entry_fops);
-   list_del(>list);
-   }
  }
  
  int drm_debugfs_remove_files(const struct drm_info_list *files, int count,

@@ -343,9 +321,13 @@ void drm_debugfs_add_file(struct drm_device *dev, const 
char *name,
entry->file.data = data;
entry->dev = dev;
  
-	mutex_lock(>debugfs_mutex);

-   list_add(>list, >debugfs_list);
-   mutex_unlock(>debugfs_mutex);
+   debugfs_create_file(name, 0444, dev->primary->debugfs_root, entry,
+   _debugfs_entry_fops);
+
+   /* TODO: This should probably only be a symlink */
+   if (dev->render)
+   debugfs_create_file(name, 0444, dev->render->debugfs_root,
+   entry, _debugfs_entry_fops);

Nope. You are fundamentally missing the point of all this, which is:

- drivers create debugfs files whenever they want to, as long as it's
   _before_ drm_dev_register is called.

- drm_dev_register will set them all up.

This is necessary because otherwise you have the potential for some nice
oops and stuff when userspace tries to access these files before the
driver is ready.

Note that with sysfs all this infrastructure already exists, which is why
you can create sysfs files whenever you feel like, and things wont go
boom.


Well Yeah I've considered that, I just don't think it's a good idea for 
debugfs.


debugfs is meant to be a helper for debugging things and that especially 
includes the time between drm_dev_init() and drm_dev_register() because 
that's where we probe the hardware and try to get it working.


Not having the debugfs files which allows for things like hardware 
register access and reading internal state during that is a really and I 
mean REALLY bad idea. This is essentially what we have those files for.



So yeah we need the list.

This also means that we really should not create the debugfs directories
_before_ drm_dev_register is called. That's just fundamentally not how
device interface setup should work:

1. you allocate stucts and stuff
2. you fully init everything
3. you register interfaces so they become userspace visible


How about we create the debugfs directory early and only delay the files 
registered through this drm_debugfs interface until registration time?


This way drivers can still decide if they want the files available 
immediately or only after registration.


What drivers currently do is like radeon setting an accel_working flag 
and registering anyway even if halve the hardware doesn't work.


Regards,
Christian.


-Daniel


  }
  EXPORT_SYMBOL(drm_debugfs_add_file);
  
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c

index 2cbe028e548c..e7b88b65866c 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(>clientlist_mutex);
mutex_destroy(>filelist_mutex);
mutex_destroy(>struct_mutex);
-   

Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-16 Thread Daniel Vetter
On Thu, Feb 16, 2023 at 12:33:08PM +0100, Daniel Vetter wrote:
> On Thu, Feb 09, 2023 at 09:18:38AM +0100, 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.
> > 
> > This also re-adds the debugfs files to the render node directory and
> > removes drm_debugfs_late_register().
> > 
> > Signed-off-by: Christian König 
> > ---
> >  drivers/gpu/drm/drm_debugfs.c | 32 +++
> >  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, 7 insertions(+), 50 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
> > index 558e3a7271a5..a40288e67264 100644
> > --- a/drivers/gpu/drm/drm_debugfs.c
> > +++ b/drivers/gpu/drm/drm_debugfs.c
> > @@ -246,31 +246,9 @@ void drm_debugfs_dev_register(struct drm_device *dev)
> >  void drm_debugfs_minor_register(struct drm_minor *minor)
> >  {
> > struct drm_device *dev = minor->dev;
> > -   struct drm_debugfs_entry *entry, *tmp;
> >  
> > if (dev->driver->debugfs_init)
> > dev->driver->debugfs_init(minor);
> > -
> > -   list_for_each_entry_safe(entry, tmp, >debugfs_list, list) {
> > -   debugfs_create_file(entry->file.name, 0444,
> > -   minor->debugfs_root, entry, 
> > _debugfs_entry_fops);
> > -   list_del(>list);
> > -   }
> > -}
> > -
> > -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, >debugfs_list, list) {
> > -   debugfs_create_file(entry->file.name, 0444,
> > -   minor->debugfs_root, entry, 
> > _debugfs_entry_fops);
> > -   list_del(>list);
> > -   }
> >  }
> >  
> >  int drm_debugfs_remove_files(const struct drm_info_list *files, int count,
> > @@ -343,9 +321,13 @@ void drm_debugfs_add_file(struct drm_device *dev, 
> > const char *name,
> > entry->file.data = data;
> > entry->dev = dev;
> >  
> > -   mutex_lock(>debugfs_mutex);
> > -   list_add(>list, >debugfs_list);
> > -   mutex_unlock(>debugfs_mutex);
> > +   debugfs_create_file(name, 0444, dev->primary->debugfs_root, entry,
> > +   _debugfs_entry_fops);
> > +
> > +   /* TODO: This should probably only be a symlink */
> > +   if (dev->render)
> > +   debugfs_create_file(name, 0444, dev->render->debugfs_root,
> > +   entry, _debugfs_entry_fops);
> 
> Nope. You are fundamentally missing the point of all this, which is:
> 
> - drivers create debugfs files whenever they want to, as long as it's
>   _before_ drm_dev_register is called.
> 
> - drm_dev_register will set them all up.
> 
> This is necessary because otherwise you have the potential for some nice
> oops and stuff when userspace tries to access these files before the
> driver is ready.
> 
> Note that with sysfs all this infrastructure already exists, which is why
> you can create sysfs files whenever you feel like, and things wont go
> boom.
> 
> So yeah we need the list.
> 
> This also means that we really should not create the debugfs directories
> _before_ drm_dev_register is called. That's just fundamentally not how
> device interface setup should work:
> 
> 1. you allocate stucts and stuff
> 2. you fully init everything
> 3. you register interfaces so they become userspace visible

What I forgot to add: The mutex seems surplus and could probably be
removed. But we need the mutex once this infra is extracted to other drm
things like connector/crtc debugfs files, because you can hotplug
connectors. But maybe the mutex isn't even need in that case (since for a
single object you still should not multi-thread anything).

So removing the mutex here seems like a reasonable thing to do, but
funamentally the list and the entire delayed debugfs setup must stay.
Otherwise we cannot remove the entire debugfs_init midlayer mess without
creating huge amounts of driver bugs in the init sequencing.
-Daniel


> -Daniel
> 
> >  }
> >  EXPORT_SYMBOL(drm_debugfs_add_file);
> >  
> > diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> > index 2cbe028e548c..e7b88b65866c 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(>clientlist_mutex);
> > mutex_destroy(>filelist_mutex);
> > mutex_destroy(>struct_mutex);
> > -   mutex_destroy(>debugfs_mutex);
> > 

Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-16 Thread Daniel Vetter
On Thu, Feb 09, 2023 at 09:18:38AM +0100, 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.
> 
> This also re-adds the debugfs files to the render node directory and
> removes drm_debugfs_late_register().
> 
> Signed-off-by: Christian König 
> ---
>  drivers/gpu/drm/drm_debugfs.c | 32 +++
>  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, 7 insertions(+), 50 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
> index 558e3a7271a5..a40288e67264 100644
> --- a/drivers/gpu/drm/drm_debugfs.c
> +++ b/drivers/gpu/drm/drm_debugfs.c
> @@ -246,31 +246,9 @@ void drm_debugfs_dev_register(struct drm_device *dev)
>  void drm_debugfs_minor_register(struct drm_minor *minor)
>  {
>   struct drm_device *dev = minor->dev;
> - struct drm_debugfs_entry *entry, *tmp;
>  
>   if (dev->driver->debugfs_init)
>   dev->driver->debugfs_init(minor);
> -
> - list_for_each_entry_safe(entry, tmp, >debugfs_list, list) {
> - debugfs_create_file(entry->file.name, 0444,
> - minor->debugfs_root, entry, 
> _debugfs_entry_fops);
> - list_del(>list);
> - }
> -}
> -
> -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, >debugfs_list, list) {
> - debugfs_create_file(entry->file.name, 0444,
> - minor->debugfs_root, entry, 
> _debugfs_entry_fops);
> - list_del(>list);
> - }
>  }
>  
>  int drm_debugfs_remove_files(const struct drm_info_list *files, int count,
> @@ -343,9 +321,13 @@ void drm_debugfs_add_file(struct drm_device *dev, const 
> char *name,
>   entry->file.data = data;
>   entry->dev = dev;
>  
> - mutex_lock(>debugfs_mutex);
> - list_add(>list, >debugfs_list);
> - mutex_unlock(>debugfs_mutex);
> + debugfs_create_file(name, 0444, dev->primary->debugfs_root, entry,
> + _debugfs_entry_fops);
> +
> + /* TODO: This should probably only be a symlink */
> + if (dev->render)
> + debugfs_create_file(name, 0444, dev->render->debugfs_root,
> + entry, _debugfs_entry_fops);

Nope. You are fundamentally missing the point of all this, which is:

- drivers create debugfs files whenever they want to, as long as it's
  _before_ drm_dev_register is called.

- drm_dev_register will set them all up.

This is necessary because otherwise you have the potential for some nice
oops and stuff when userspace tries to access these files before the
driver is ready.

Note that with sysfs all this infrastructure already exists, which is why
you can create sysfs files whenever you feel like, and things wont go
boom.

So yeah we need the list.

This also means that we really should not create the debugfs directories
_before_ drm_dev_register is called. That's just fundamentally not how
device interface setup should work:

1. you allocate stucts and stuff
2. you fully init everything
3. you register interfaces so they become userspace visible
-Daniel

>  }
>  EXPORT_SYMBOL(drm_debugfs_add_file);
>  
> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> index 2cbe028e548c..e7b88b65866c 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(>clientlist_mutex);
>   mutex_destroy(>filelist_mutex);
>   mutex_destroy(>struct_mutex);
> - mutex_destroy(>debugfs_mutex);
>   drm_legacy_destroy_members(dev);
>  }
>  
> @@ -638,14 +637,12 @@ static int drm_dev_init(struct drm_device *dev,
>   INIT_LIST_HEAD(>filelist_internal);
>   INIT_LIST_HEAD(>clientlist);
>   INIT_LIST_HEAD(>vblank_event_list);
> - INIT_LIST_HEAD(>debugfs_list);
>  
>   spin_lock_init(>event_lock);
>   mutex_init(>struct_mutex);
>   mutex_init(>filelist_mutex);
>   mutex_init(>clientlist_mutex);
>   mutex_init(>master_mutex);
> - mutex_init(>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 5ff7bf88f162..e215d00ba65c 100644
> --- a/drivers/gpu/drm/drm_internal.h
> +++ b/drivers/gpu/drm/drm_internal.h
> @@ -188,7 +188,6 @@ int drm_debugfs_init(struct 

Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-14 Thread Stanislaw Gruszka
On Tue, Feb 14, 2023 at 01:19:51PM +0100, Stanislaw Gruszka wrote:
> On Thu, Feb 09, 2023 at 09:18:38AM +0100, Christian König wrote:
> > -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, >debugfs_list, list) {
> > -   debugfs_create_file(entry->file.name, 0444,
> > -   minor->debugfs_root, entry, 
> > _debugfs_entry_fops);
> > -   list_del(>list);
> > -   }
> >  }
> >  
> >  int drm_debugfs_remove_files(const struct drm_info_list *files, int count,
> > @@ -343,9 +321,13 @@ void drm_debugfs_add_file(struct drm_device *dev, 
> > const char *name,
> > entry->file.data = data;
> > entry->dev = dev;
> >  
> > -   mutex_lock(>debugfs_mutex);
> > -   list_add(>list, >debugfs_list);
> > -   mutex_unlock(>debugfs_mutex);
> > +   debugfs_create_file(name, 0444, dev->primary->debugfs_root, entry,
> > +   _debugfs_entry_fops);
> > +
> > +   /* TODO: This should probably only be a symlink */
> > +   if (dev->render)
> > +   debugfs_create_file(name, 0444, dev->render->debugfs_root,
> > +   entry, _debugfs_entry_fops);
> 
> For accel we would need conditional check for DRM_MINOR_ACCEL here as
> well.

Actually my comment make no sense, since we do not have minor pointer
here. What is needed is additional dev->accel code like for dev->render,
perhaps also make dev->primary conditional.

Alternatively we can just create separate helper: accel_debugfs_add_file.

> With this change and one from first patch, drm_debugfs_add_file() should
> work for accel as well. We could get rid of debugfs_init from 
> accel_debugfs_init().
> 
> However we still need support for writable files. I think we can just
> add helper for providing debugfs dir to drivers i.e:
> 
> struct dentry *accel_debugfs_dir(struct drm_device *drm) 
> {
>   return drm->accel->debugfs_root;
> }

or just this :-)

Regards
Stanislaw



Re: [PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-14 Thread Stanislaw Gruszka
On Thu, Feb 09, 2023 at 09:18:38AM +0100, Christian König wrote:
> -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, >debugfs_list, list) {
> - debugfs_create_file(entry->file.name, 0444,
> - minor->debugfs_root, entry, 
> _debugfs_entry_fops);
> - list_del(>list);
> - }
>  }
>  
>  int drm_debugfs_remove_files(const struct drm_info_list *files, int count,
> @@ -343,9 +321,13 @@ void drm_debugfs_add_file(struct drm_device *dev, const 
> char *name,
>   entry->file.data = data;
>   entry->dev = dev;
>  
> - mutex_lock(>debugfs_mutex);
> - list_add(>list, >debugfs_list);
> - mutex_unlock(>debugfs_mutex);
> + debugfs_create_file(name, 0444, dev->primary->debugfs_root, entry,
> + _debugfs_entry_fops);
> +
> + /* TODO: This should probably only be a symlink */
> + if (dev->render)
> + debugfs_create_file(name, 0444, dev->render->debugfs_root,
> + entry, _debugfs_entry_fops);

For accel we would need conditional check for DRM_MINOR_ACCEL here as
well.

With this change and one from first patch, drm_debugfs_add_file() should
work for accel as well. We could get rid of debugfs_init from 
accel_debugfs_init().

However we still need support for writable files. I think we can just
add helper for providing debugfs dir to drivers i.e:

struct dentry *accel_debugfs_dir(struct drm_device *drm) 
{
return drm->accel->debugfs_root;
}

Then individual accel driver could create files with different permissions 
there.

Regards
Stanislaw



[PATCH 3/3] drm/debugfs: remove dev->debugfs_list and debugfs_mutex

2023-02-09 Thread 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.

Completely drop that approach and just create the files directly.

This also re-adds the debugfs files to the render node directory and
removes drm_debugfs_late_register().

Signed-off-by: Christian König 
---
 drivers/gpu/drm/drm_debugfs.c | 32 +++
 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, 7 insertions(+), 50 deletions(-)

diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index 558e3a7271a5..a40288e67264 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -246,31 +246,9 @@ void drm_debugfs_dev_register(struct drm_device *dev)
 void drm_debugfs_minor_register(struct drm_minor *minor)
 {
struct drm_device *dev = minor->dev;
-   struct drm_debugfs_entry *entry, *tmp;
 
if (dev->driver->debugfs_init)
dev->driver->debugfs_init(minor);
-
-   list_for_each_entry_safe(entry, tmp, >debugfs_list, list) {
-   debugfs_create_file(entry->file.name, 0444,
-   minor->debugfs_root, entry, 
_debugfs_entry_fops);
-   list_del(>list);
-   }
-}
-
-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, >debugfs_list, list) {
-   debugfs_create_file(entry->file.name, 0444,
-   minor->debugfs_root, entry, 
_debugfs_entry_fops);
-   list_del(>list);
-   }
 }
 
 int drm_debugfs_remove_files(const struct drm_info_list *files, int count,
@@ -343,9 +321,13 @@ void drm_debugfs_add_file(struct drm_device *dev, const 
char *name,
entry->file.data = data;
entry->dev = dev;
 
-   mutex_lock(>debugfs_mutex);
-   list_add(>list, >debugfs_list);
-   mutex_unlock(>debugfs_mutex);
+   debugfs_create_file(name, 0444, dev->primary->debugfs_root, entry,
+   _debugfs_entry_fops);
+
+   /* TODO: This should probably only be a symlink */
+   if (dev->render)
+   debugfs_create_file(name, 0444, dev->render->debugfs_root,
+   entry, _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 2cbe028e548c..e7b88b65866c 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(>clientlist_mutex);
mutex_destroy(>filelist_mutex);
mutex_destroy(>struct_mutex);
-   mutex_destroy(>debugfs_mutex);
drm_legacy_destroy_members(dev);
 }
 
@@ -638,14 +637,12 @@ static int drm_dev_init(struct drm_device *dev,
INIT_LIST_HEAD(>filelist_internal);
INIT_LIST_HEAD(>clientlist);
INIT_LIST_HEAD(>vblank_event_list);
-   INIT_LIST_HEAD(>debugfs_list);
 
spin_lock_init(>event_lock);
mutex_init(>struct_mutex);
mutex_init(>filelist_mutex);
mutex_init(>clientlist_mutex);
mutex_init(>master_mutex);
-   mutex_init(>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 5ff7bf88f162..e215d00ba65c 100644
--- a/drivers/gpu/drm/drm_internal.h
+++ b/drivers/gpu/drm/drm_internal.h
@@ -188,7 +188,6 @@ int drm_debugfs_init(struct drm_minor *minor, int minor_id,
 void drm_debugfs_dev_register(struct drm_device *dev);
 void drm_debugfs_minor_register(struct drm_minor *minor);
 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);
@@ -205,10 +204,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;
 
-