public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: Mikulas Patocka <mpatocka@redhat.com>
Cc: Kay Sievers <kay.sievers@vrfy.org>,
	linux-kernel@vger.kernel.org, dm-devel@redhat.com
Subject: Re: kobject_put vs module unload
Date: Sat, 8 Jan 2011 15:49:49 -0800	[thread overview]
Message-ID: <20110108234949.GA4262@suse.de> (raw)
In-Reply-To: <Pine.LNX.4.64.1101081340250.1879@hs20-bc2-1.build.redhat.com>

On Sat, Jan 08, 2011 at 01:50:50PM -0500, Mikulas Patocka wrote:
> 
> 
> On Sat, 8 Jan 2011, Kay Sievers wrote:
> 
> > On Sat, Jan 8, 2011 at 19:01, Mikulas Patocka <mpatocka@redhat.com> wrote:
> > > On Sat, 8 Jan 2011, Kay Sievers wrote:
> > >> On Sat, Jan 8, 2011 at 14:19, Mikulas Patocka <mpatocka@redhat.com> wrote:
> > >> > On Fri, 7 Jan 2011, Greg KH wrote:
> > >>
> > >> >> > 4) the reference obtained at point 1) is dropped, kobject reference count
> > >> >> > reaches zero and the release callback is called. But that callback points
> > >> >> > to an unloaded module and causes a crash.
> > >> >> >
> > >> >> > How is it solved? Am I missing something?
> > >> >>
> > >> >> You have the code that creates and frees the object, to not be in the
> > >> >> module that could have been unloaded.  It's really just that simple.
> > >> >
> > >> > If the whole device mapper subsystem can be a module, where can I put the
> > >> > code?
> > >> >
> > >> > I think a similar bug exists in md, it can also be unloaded as a module
> > >> > and it has "release" method in its module code.
> > >>
> > >> If you still have data structures hanging around, these structures are
> > >> supposed to take a reference on the module -- and you can not unload
> > >> the module as long as this is the case.
> > >>
> > >> Kay
> > >
> > > kobject references don't increase module reference count. If kobject held
> > > module references, it would be a fix for this bug, but could cause other
> > > bugs (some modules could be unloadable due to self-references to its own
> > > kobjects).
> > 
> > Sure, they don't automatically take references. It's the job of the
> > driver/module, to make sure to pin the module for any data of it,
> > which might be still in use.
> > 
> > Kay
> 
> A module can't unpin itself. If it does, the module can be unloaded 
> immediatelly after module_put(THIS_MODULE) call and the function that 
> called module_put crashes.
> 
> A module must be unpinned by someone else. The question is: who unpins the 
> module when kobject references are gone?

Who ever you decide to have unpin it.

Seriously, it's up to you to handle this properly, it's not something
built into the kobject/driver model at all due to it being something
that can be done in a number of different ways.

thanks,

greg k-h

      reply	other threads:[~2011-01-08 23:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-08  3:42 kobject_put vs module unload Mikulas Patocka
2011-01-08  5:56 ` Greg KH
2011-01-08 13:19   ` Mikulas Patocka
2011-01-08 17:23     ` Kay Sievers
2011-01-08 18:01       ` Mikulas Patocka
2011-01-08 18:09         ` Kay Sievers
2011-01-08 18:50           ` Mikulas Patocka
2011-01-08 23:49             ` Greg KH [this message]

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=20110108234949.GA4262@suse.de \
    --to=gregkh@suse.de \
    --cc=dm-devel@redhat.com \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpatocka@redhat.com \
    /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