public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [RFC] add kobject to struct module
Date: Wed, 10 Sep 2003 16:06:14 -0700	[thread overview]
Message-ID: <20030910230614.GB5758@kroah.com> (raw)
In-Reply-To: <20030910080955.9318E2C0EB@lists.samba.org>

On Wed, Sep 10, 2003 at 06:07:35PM +1000, Rusty Russell wrote:
> In message <20030910041122.GE9760@kroah.com> you write:
> > On Wed, Sep 10, 2003 at 01:31:02PM +1000, Rusty Russell wrote:
> > > Because kobject does not have a "struct module *owner", we can't
> > > simply add in the refcount.
> > 
> > Um, I don't understand.  There is no "struct module *owner in struct
> > kobject.  There is one in struct attribute, but I don't set it, so it
> > doesn't matter for this usage.
> 
> Your parser broke, I think 8)

Ok, let's try again. :)

Why are you detaching the kobject from struct module?
In my patch I accounted for the kobject's reference count in the module
reference count (just not the count exported to userspace, as to not
break the userspace tools.)  So if a user has a module sysfs file open
(like the "refcount" file), the module reference count is incremented
and the module is not allowed to be unloaded until that count drops.
This removes any race condition with the kobject being in use when the
module structure is freed.

Does that make sense?

> > > The module reference count is defined to never go from zero to one
> > > when the module is dying, which means callers must use
> > > try_module_get().  I grab the reference on read/write, which means
> > > opening the file won't hold the module, either.
> > 
> > read/write of what?  The attribute?  Sure, why not set the module
> > attribute sysfs file to the module that way the reference count will be
> > incremented if the sysfs file is opened.
> 
> Hmm, because there's one attribute: which module would own it?  You're
> going to creation attributes per module later (for module parameters),
> so when you do that it might make sense to do this too.

The attribute "refcount" is "owned" by the module itself.  The kobject
count is incremented if the file is opened by the sysfs core, thus
preventing the module from being able to be unloaded.

The same thing will happen for module paramaters.  They are owned by the
module structure as well.

It all "just works" :)

> > But in looking at your patch, I don't see why you want to separate the
> > module from the kobject?  What benefit does it have?
> 
> The lifetimes are separate, each controlled by their own reference
> count.  I *know* this will work even if someone holds a reference to
> the kobject (for some reason in the future) even as the module is
> removed.

But my patch prevented that from ever happening.  If someone grabbed the
kobject, the module could not be unloaded.  That fixes all kinds of
races.

> > > Were you intending to put all the info currently in /proc/modules
> > > under sysfs?  Makes sense I think.  For the options you'll need a
> > > subdir to avoid name clashes.
> > 
> > Yes, I was going to add it, this patch was more of a "test" to see how
> > receptive you were to it.
> 
> More more! 8)

But whose patch to build on, mine, or your version?  :)

thanks,

greg k-h

  parent reply	other threads:[~2003-09-10 23:06 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-09 22:24 [RFC] add kobject to struct module Greg KH
2003-09-10  0:13 ` Greg KH
2003-09-10  3:31 ` Rusty Russell
2003-09-10  4:11   ` Greg KH
2003-09-10  8:07     ` Rusty Russell
2003-09-10 15:26       ` Patrick Mochel
2003-09-11  1:13         ` Rusty Russell
2003-09-11  6:26           ` Greg KH
2003-09-11  8:18             ` Rusty Russell
2003-09-11 17:15               ` Greg KH
2004-02-24 23:29           ` Greg KH
2004-03-05 14:34             ` Rusty Russell
2004-05-07 21:28               ` Greg KH
2003-09-10 23:06       ` Greg KH [this message]
2003-09-11  2:33         ` Rusty Russell
2003-09-10 23:32 ` Russell King
2003-09-10 23:45   ` Greg KH
2003-09-11  0:04     ` Mike Fedyk
2003-09-11  0:21       ` Greg KH
2003-09-11  2:10       ` Rusty Russell
2003-09-11  2:04   ` Rusty Russell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030910230614.GB5758@kroah.com \
    --to=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox