public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@zip.com.au>
To: Jeff Garzik <jgarzik@mandrakesoft.com>
Cc: Alexander Viro <viro@math.psu.edu>,
	Linus Torvalds <torvalds@transmeta.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC] races in access to pci_devices
Date: Thu, 15 Nov 2001 00:28:22 -0800	[thread overview]
Message-ID: <3BF37CA6.92CA12E7@zip.com.au> (raw)
In-Reply-To: <Pine.GSO.4.21.0111142257510.1095-100000@weyl.math.psu.edu> <3BF37508.6EA78A85@mandrakesoft.com>

Jeff Garzik wrote:
> 
> I haven't looked at it in over a year, but from a quick look, all the
> list access look like they can be protected by a simple spinlock.

I don't think so?   We do things like calling driver probe methods
in the middle of a driver list walk.

An rwsem _may_ be suitable, but I'm not sure that we don't do
a nested walk in some circumstances, and AFAIK our rwsems
still are not safe for the same thread to do a down_read() twice.

Then there's the bus list, and the order of its lock wrt the device
list.

One approach would be to use a spinlock and a per-device refcount.
So something like:

	spin_lock(&pci_dev_lock);
        dev = pci_dev_g(pci_devices.next);
	while (dev != pci_dev_g(&pci_devices)) {
		struct pci_dev *next;

		pci_dev_get(dev);
		spin_unlock(&pci_dev_lock);
		diddle(dev);
		spin_lock(&pci_dev_lock);
		next = pci_dev_g(dev->global_list.next);
		pci_dev_put(dev);
		dev = next;
        }
	spin_unlock(&pci_dev_lock);

pci_dev_get(struct pci_dev *dev)
{
#ifdef CONFIG_SMP
	if (!spin_is_locked(&pci_dev_lock))
		BUG();
#endif
	dev->refcount++;
}

pci_dev_put(struct pci_dev *dev)
{
#ifdef CONFIG_SMP
	if (!spin_is_locked(&pci_dev_lock))
		BUG();
#endif
	dev->refcount--;
	if (dev->refcount == 0)
		kfree(dev);
}

I _think_ all this list traversal happens in process context now.
Not sure about the PCI hotplug driver though.

It's really sticky.  Which is why it isn't fixed :(

Sigh.  Maybe go for an rwsem in 2.5, backport when it stops
deadlocking?


-

  parent reply	other threads:[~2001-11-15  8:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-15  4:00 [RFC] races in access to pci_devices Alexander Viro
2001-11-15  5:24 ` Greg KH
2001-11-15  7:55 ` Jeff Garzik
2001-11-15  8:00   ` Alexander Viro
2001-11-15  8:28   ` Andrew Morton [this message]
2001-11-15 16:35     ` Patrick Mochel

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=3BF37CA6.92CA12E7@zip.com.au \
    --to=akpm@zip.com.au \
    --cc=jgarzik@mandrakesoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    --cc=viro@math.psu.edu \
    /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