From: Yu Zhao <yu.zhao@uniscape.net>
To: Matthew Wilcox <matthew@wil.cx>
Cc: Jesse Barnes <jbarnes@virtuousgeek.org>,
linux-pci@vger.kernel.org, greg@kroah.com,
akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
stable@kernel.org, Rakib Mullick <rakib.mullick@gmail.com>
Subject: Re: [PATCH] pci: Fixing drivers/pci/search.c compilation warning.
Date: Sun, 26 Oct 2008 20:51:25 +0800 [thread overview]
Message-ID: <490467CD.3000402@uniscape.net> (raw)
In-Reply-To: <20081021011308.GA3889@parisc-linux.org>
Matthew Wilcox wrote:
> This patch seems to have been overlooked. It also seems to have had
> some kind of midair collision with a patch from Greg that ignored the
> real bug I found.
>
> Here's an updated version. I think it should also be applied to
> -stable.
>
> ----
>
> Subject: [PCI] Fix reference counting bug
>
> pci_get_subsys() will decrement the reference count of the device that
> it starts searching from. Unfortunately, the pci_find_device() interface
> will already have decremented the reference count of the device earlier,
> so the device will end up losing all reference counts and be freed.
>
> We can fix this by incrementing the reference count of the device to
> start searching from before calling pci_get_subsys().
>
> Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
>
> diff --git a/drivers/pci/search.c b/drivers/pci/search.c
> index 4edfc47..5af8bd5 100644
> --- a/drivers/pci/search.c
> +++ b/drivers/pci/search.c
> @@ -166,6 +166,7 @@ struct pci_dev *pci_find_device(unsigned int vendor, unsigned int device,
> {
> struct pci_dev *pdev;
>
> + pci_dev_get(from);
> pdev = pci_get_subsys(vendor, device, PCI_ANY_ID, PCI_ANY_ID, from);
> pci_dev_put(pdev);
> return pdev;
> @@ -270,12 +271,8 @@ static struct pci_dev *pci_get_dev_by_id(const struct pci_device_id *id,
> struct pci_dev *pdev = NULL;
>
> WARN_ON(in_interrupt());
> - if (from) {
> - /* FIXME
> - * take the cast off, when bus_find_device is made const.
> - */
> - dev_start = (struct device *)&from->dev;
> - }
> + if (from)
> + dev_start = &from->dev;
> dev = bus_find_device(&pci_bus_type, dev_start, (void *)id,
> match_pci_dev_by_id);
> if (dev)
This reminds me of other problems of PCI search functions.
The 'dev_start' is passed to bus_find_device(), and its 'knode_bus'
reference count is decreased by klist_iter_init_node() in that function.
The problem is the reference count may be already decrease to 0 because
the PCI device 'from' is hot-plugged off (e.g., pci_remove_bus) when the
search goes. A warning is fired when klist_iter_init_node() detects the
reference count becomes 0.
Some code uses pci_find_device() in a way that is not safe with the
hotplug, because a device may be destroyed after bus_find_device()
returns it and before it's held by pci_dev_get() in the next round.
Following is an example from a random grep:
for ( ;; )
{
if ((dev_netjet = pci_find_device(PCI_VENDOR_ID_TIGERJET,
PCI_DEVICE_ID_TIGERJET_300, dev_netjet))) {
ret = njs_pci_probe(dev_netjet, cs);
...
}
...
}
And some others use pci_get_bus_and_slot(), which has similar problem as
above.
Thanks,
Yu
next prev parent reply other threads:[~2008-10-26 12:58 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <b9df5fa10809280816u23ef3021k7eee287a237b72ae@mail.gmail.com>
2008-09-28 16:32 ` [PATCH] pci: Fixing drivers/pci/search.c compilation warning Matthew Wilcox
2008-10-21 1:13 ` Matthew Wilcox
2008-10-21 1:29 ` Jesse Barnes
2008-10-21 17:24 ` Jesse Barnes
2008-10-26 12:51 ` Yu Zhao [this message]
2008-10-26 18:34 ` Matthew Wilcox
2008-10-27 3:18 ` Zhao, Yu
2008-10-27 7:07 ` Matthew Wilcox
2008-10-27 7:13 ` Zhao, Yu
2008-10-27 7:21 ` Matthew Wilcox
2008-10-27 7:34 ` Zhao, Yu
2008-10-27 7:43 ` Zhao, Yu
2008-10-27 7:45 ` Matthew Wilcox
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=490467CD.3000402@uniscape.net \
--to=yu.zhao@uniscape.net \
--cc=akpm@linux-foundation.org \
--cc=greg@kroah.com \
--cc=jbarnes@virtuousgeek.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=matthew@wil.cx \
--cc=rakib.mullick@gmail.com \
--cc=stable@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