public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Chris Wright <chris@wirex.com>
To: Greg KH <greg@kroah.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [RFC] PCI device list locking - take 2
Date: Wed, 18 Jun 2003 15:33:24 -0700	[thread overview]
Message-ID: <20030618153324.A20212@figure1.int.wirex.com> (raw)
In-Reply-To: <20030618212921.GA1807@kroah.com>; from greg@kroah.com on Wed, Jun 18, 2003 at 02:29:21PM -0700

* Greg KH (greg@kroah.com) wrote:
>  static void *pci_seq_start(struct seq_file *m, loff_t *pos)
>  {
> -	struct list_head *p = &pci_devices;
> +	struct pci_dev *dev = NULL;
>  	loff_t n = *pos;
>  
> -	/* XXX: surely we need some locking for traversing the list? */
> +	dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev);
>  	while (n--) {
> -		p = p->next;
> -		if (p == &pci_devices)
> -			return NULL;
> +		dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev);
> +		if (dev == NULL)
> +			goto exit;

I think this still has the same problem.  pci_get_device grabs lock,
walks list, gets ref, and drops lock.  But the ref doesn't hold it on the
list, right?.  So some pci_remove_* could do list_del(&dev->global_list),
poison the prev/next pointers.  Subsequent pci_get_device would do ->next
and oops.  It seems the lock needs to be held for entire start/next/stop
sequence, or the ref needs to keep it on list.

> +struct pci_dev * 
> +pci_get_subsys(unsigned int vendor, unsigned int device,
<snip>
> +exit:
> +	if (from)
> +		pci_put_dev(from);
> +	if (dev)
> +		pci_get_dev(dev);

Heh, the hch in me notes that pci_{put,get}_dev already check NULL device ;-)

thanks,
-chris
-- 
Linux Security Modules     http://lsm.immunix.org     http://lsm.bkbits.net

  reply	other threads:[~2003-06-18 22:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-18 21:29 [RFC] PCI device list locking - take 2 Greg KH
2003-06-18 22:33 ` Chris Wright [this message]
2003-06-18 22:46   ` Greg KH
2003-06-18 23:32     ` Chris Wright
2003-06-18 23:52       ` Greg KH
2003-06-19  0:20         ` Chris Wright

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=20030618153324.A20212@figure1.int.wirex.com \
    --to=chris@wirex.com \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.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