mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: Patrick Mochel <mochel@osdl.org>
Cc: Roman Zippel <zippel@linux-m68k.org>,
	Werner Almesberger <wa@almesberger.net>
Cc: Greg KH <greg@kroah.com>, Oliver Neukum <oliver@neukum.name>,
	Linux Kernel List <linux-kernel@vger.kernel.org>,
	Ivan Kokshaysky <ink@jurassic.park.msu.ru>,
	Jeff Garzik <jgarzik@pobox.com>
Subject: Re: PCI driver module unload race?
Date: Mon, 17 Mar 2003 00:05:51 +1100	[thread overview]
Message-ID: <20030317174406.9ABE42C26D@lists.samba.org> (raw)
In-Reply-To: Your message of "Tue, 11 Mar 2003 09:27:27 MDT." <Pine.LNX.4.33.0303110916540.1003-100000@localhost.localdomain>

In message <Pine.LNX.4.33.0303110916540.1003-100000@localhost.localdomain> you 
write:
> The driver has an unload_sem that is locked until the driver's refcount 
> goes to 0. When it does, it's unlocked. A driver_unregister() call will 
> try and take this semaphore while unregistering, meaning it will block 
> until outstanding references go away. 

That sounds like an odd way of doing it.  More normal would be either
a rw lock of some kind (ie. always hold read when calling through
functions), or if recursion is a worry, a lock, an atomic reference
count, and a "who is waiting for it to be unloaded" task ptr.  As one
example, see net/core/netfilter.c: nf_unregister_hook uses a br_lock,
nf_unregister_sockopt uses the refcount approach.

Any way it's done, the effect is the same: deregisteration sleeps
until the object is unused.

> I don't particularly love it, but it's simple enough and it works.  
> Ideally, we'd have one reference count and this wouldn't be an issue.  
> However, with the evolution of the driver core and the module core in 2.5,
> these details haven't had a chance to be worked. I hope in 2.7, we can
> achieve more unification between the two. 

Unfortunately, I think that will require changing every module *and*
every registration function, and noone has produced a reasonable model
which has the "unload only if noone is using the module" semantics
(which requires atomic "deactivation" of interfaces, like
try_module_get).

Currently, if you go for a full dynamic interface (ie. can be
unregistered and structures destroyed at any time, not just on module
unload), you don't have a race, but you don't bump module refcounts
which users expect (ie. module appears "unused" and hangs on rmmod),
which can be a problem depending on the interface (mainly whether the
rmmod hang would be infinite).

If you just use a module pointer and try_module_get, the interface
can't be safely used in *general* (Werner's "unregister_xxx then
kfree(xxx)" problem), but as long as the lifetime of the objects are
tied to module lifetime (as many are), it works.

Yes, this means some code has to do both.  But it's simple, doesn't
significantly effect code using the interface, and is easy to rip out
when Something Better comes along.

> Greg, and Rusty, are right. Dealing with this is a PITA, and I think will 
> always be. I'm willing to take the Nancy Reagan platform, too. 

And another reason that I like the "easy to remove" nature of
try_module_get, for all its flaws.

Cheers,
Rusty.
--
  Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

      parent reply	other threads:[~2003-03-17 17:33 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-08 10:47 Russell King
2003-03-08 19:12 ` Greg KH
2003-03-08 19:47   ` Petr Vandrovec
2003-03-08 19:51     ` Greg KH
2003-03-09  2:33       ` Petr Vandrovec
2003-03-08 20:03     ` Russell King
2003-03-08 20:09   ` Russell King
2003-03-08 20:21     ` Greg KH
2003-03-10 21:44       ` Greg KH
2003-03-10 23:48         ` Oliver Neukum
2003-03-10 23:51           ` Greg KH
2003-03-11  1:04             ` Roman Zippel
2003-03-11  1:15               ` Greg KH
2003-03-11  9:00                 ` Oliver Neukum
2003-03-11 15:06                   ` Patrick Mochel
2003-03-11 16:07                     ` Oliver Neukum
2003-03-16 13:13                       ` Rusty Russell
2003-03-11 11:05                 ` Roman Zippel
2003-03-11 15:27                   ` Patrick Mochel
2003-03-11 20:09                     ` Roman Zippel
2003-03-11 19:15                       ` Patrick Mochel
2003-03-12  2:28                         ` Roman Zippel
2003-03-16 13:05                     ` Rusty Russell [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=20030317174406.9ABE42C26D@lists.samba.org \
    --to=rusty@rustcorp.com.au \
    --cc=mochel@osdl.org \
    --cc=wa@almesberger.net \
    --cc=zippel@linux-m68k.org \
    /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

all inboxes | Powered by JetHome®