Re: Unregistering interfaces

Alan Stern
2004-03-30T23:56:30Z

On Tue, 30 Mar 2004, Andrew Morton wrote:

> Greg KH <greg@kroah.com> wrote:
> >
> > I think we need to do this now, as it is not a correct fix, and causes
> > more problems than good at this time.
>
> But the patch was correct. sysfs retains a pointer to the kobject, it
> should take a ref on it?
>
> > I suggest you try to fix the oops
> > you were seeing in either another way, or in a way that does not break
> > other things :)
>
> Didn't we demonstrate that the code which broke was already broken? And
> that it has other problems regardless of the kobject pinning fix, such as the
> userpace-holding-a-file-open-wedges-khubd problem?
>
> Worried that this is all heading in the wrong direction...

There are two problems to consider:

(1) sysfs retains pointers to kobjects long after they have been
unregistered because of the negative dentrys.

(2) khubd blocks when removing configurations.

Maneesh's change caused (1) because it grabbed a reference to protect an
existing pointer. The way to repair the damage is to delete the pointer
ASAP so the reference can be dropped. That will require changing several
other sysfs routines that assume the pointer is valid.

Such a change is needed because otherwise module unloading can be delayed
indefinitely, until the system decides it needs to reuse the negative
dentry.

(2) has been repaired temporarily. We're still discussing the right way
to fix it permanently, though. The underlying cause for the reason that
khubd blocked is an odd feature of sysfs: it's willing to delete
directories that contain subdirectories, while leaving the subdirectories
in existence. (The connection to khubd is slightly obscure but it can be
traced.)

Greg has proposed using an awkward scheme for repeatedly parsing and
creating dynamic data structures from USB configuration descriptors to fix
(2). I'm in favor of changing the behavior of sysfs, so that either it
refuses to delete directories that contain subdirectories or else it
recursively deletes the subdirectories first. At this point nothing has
been settled.

Alan Stern