mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Petr Vandrovec <vandrove@vc.cvut.cz>
To: Greg KH <greg@kroah.com>
Cc: Linux Kernel List <linux-kernel@vger.kernel.org>,
	Patrick Mochel <mochel@osdl.org>,
	Ivan Kokshaysky <ink@jurassic.park.msu.ru>,
	Jeff Garzik <jgarzik@pobox.com>,
	Rusty Russell <rusty@rustcorp.com.au>
Subject: Re: PCI driver module unload race?
Date: Sun, 9 Mar 2003 03:33:43 +0100	[thread overview]
Message-ID: <20030309023343.GA3519@vana.vc.cvut.cz> (raw)
In-Reply-To: <20030308195117.GE26374@kroah.com>

[Scroll to the end...]

> The case where while probe() is called, the module is unloaded.
> Same thing for remove().
> 
> That's all.
> 
> > After driver calls pci_unregister_driver,
> > it is sure that there are no other users of this pci driver.
> 
> Sure, but that's not the case of what we are protecting here.  We want
> pci_unregister_driver() (which is usually called from the module_exit()

Usually! pci_unregister_driver has nothing to do with module_exit(), unless
there is some rule which says that pci_unregister_driver may be called
from module_exit() only.

> function), to not be called if we are in the middle of calling either
> probe() or release().
> 
> Do you have a way of protecting the race that is described by Russell
> here that differs from my patch?

There must be normal subsystem locking which prevents you from such race.

Russel King wrote:

> Load PCI driver.

> PCI driver registers using pci_module_init(), and adds itself to sysfs.

> Hot-plugin a PCI device which uses this driver.  sysfs matches the PCI
> driver, and calls the PCI drivers probe function.

> The probe function calls kmalloc or some other function which sleeps
> (or gets preempted, if CONFIG_PREEMPT is enabled.)

> We switch to another thread, which happens to be rmmod for this PCI
> driver.  We remove the driver since it has a use count of zero.

> We switch back to the PCI driver.  Oops.

Both calls to ->probe (& ->remove) must happen under same lock which
is used by pci_(un)register_driver. Driver expects that there is no
device registered after return from pci_unregister_driver, and
your if (try_module_get())... violates this - you simply skip call
to ->remove if module is in unloading state - although I see no reason
why you could not enter driver's ->remove function long before
pci_unregister_driver is called.

Also pci_unregister_driver() expects ->remove to be called for all
registered devices. If you'll guard this call by try_module_get(),
no device will get unregistered from driver, causing memory leaks or
even crashes.

Well, and after reading sysfs code: there is no problem (I would be
really surprised otherwise), as both hotplug event and driver 
registration/removal are guarded by bus->subsys.rwsem semaphore, 
so pci_unregister_driver() succeeds after previous ->remove 
(or ->probe or ...) finishes.

Just make sure that people do not call device_release_driver
unless they really know what they are doing. Proper interface is
bus_remove_device or bus_remove_driver...
					Best regards,
						Petr Vandrovec
						vandrove@vc.cvut.cz

					

  reply	other threads:[~2003-03-09  2:23 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 [this message]
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

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=20030309023343.GA3519@vana.vc.cvut.cz \
    --to=vandrove@vc.cvut.cz \
    --cc=greg@kroah.com \
    --cc=ink@jurassic.park.msu.ru \
    --cc=jgarzik@pobox.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mochel@osdl.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

all inboxes | Powered by JetHome®