From: "Michael S. Tsirkin" <mst@redhat.com>
To: Jan Kiszka <jan.kiszka@siemens.com>
Cc: Alex Williamson <alex.williamson@redhat.com>,
"ddutile@redhat.com" <ddutile@redhat.com>,
qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH v2] pci: Error on PCI capability collisions
Date: Wed, 24 Aug 2011 15:53:21 +0300 [thread overview]
Message-ID: <20110824125321.GA18920@redhat.com> (raw)
In-Reply-To: <4E54EEAA.7020707@siemens.com>
On Wed, Aug 24, 2011 at 02:29:30PM +0200, Jan Kiszka wrote:
> Nothing good can happen when we overlap capabilities. This may happen
> when plugging in assigned devices or when devices models contain bugs.
> Detect the overlap and report it.
>
> Based on qemu-kvm commit by Alex Williamson.
>
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Applied, thanks everyone.
> ---
> hw/pci.c | 34 ++++++++++++++++++++++++++++++++++
> 1 files changed, 34 insertions(+), 0 deletions(-)
>
> Changes in v2:
> - properly find the conflicting CAP
> - adjust error code
>
> diff --git a/hw/pci.c b/hw/pci.c
> index 6124790..634e789 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -1811,6 +1811,25 @@ static uint8_t pci_find_capability_list(PCIDevice *pdev, uint8_t cap_id,
> return next;
> }
>
> +static uint8_t pci_find_capability_at_offset(PCIDevice *pdev, uint8_t offset)
> +{
> + uint8_t next, prev, found = 0;
> +
> + if (!(pdev->used[offset])) {
> + return 0;
> + }
> +
> + assert(pdev->config[PCI_STATUS] & PCI_STATUS_CAP_LIST);
> +
> + for (prev = PCI_CAPABILITY_LIST; (next = pdev->config[prev]);
> + prev = next + PCI_CAP_LIST_NEXT) {
> + if (next <= offset && next > found) {
> + found = next;
> + }
> + }
> + return found;
> +}
> +
> /* Patch the PCI vendor and device ids in a PCI rom image if necessary.
> This is needed for an option rom which is used for more than one device. */
> static void pci_patch_ids(PCIDevice *pdev, uint8_t *ptr, int size)
> @@ -1952,11 +1971,26 @@ int pci_add_capability(PCIDevice *pdev, uint8_t cap_id,
> uint8_t offset, uint8_t size)
> {
> uint8_t *config;
> + int i, overlapping_cap;
> +
> if (!offset) {
> offset = pci_find_space(pdev, size);
> if (!offset) {
> return -ENOSPC;
> }
> + } else {
> + for (i = offset; i < offset + size; i++) {
> + overlapping_cap = pci_find_capability_at_offset(pdev, i);
> + if (overlapping_cap) {
> + fprintf(stderr, "ERROR: %04x:%02x:%02x.%x "
> + "Attempt to add PCI capability %x at offset "
> + "%x overlaps existing capability %x at offset %x\n",
> + pci_find_domain(pdev->bus), pci_bus_num(pdev->bus),
> + PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
> + cap_id, offset, overlapping_cap, i);
> + return -EINVAL;
> + }
> + }
> }
>
> config = pdev->config + offset;
> --
> 1.7.3.4
prev parent reply other threads:[~2011-08-24 12:52 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-23 17:28 [Qemu-devel] [PATCH] pci: Error on PCI capability collisions Jan Kiszka
2011-08-23 18:17 ` Michael S. Tsirkin
2011-08-23 18:21 ` Alex Williamson
2011-08-23 18:26 ` Michael S. Tsirkin
2011-08-23 19:12 ` Alex Williamson
2011-08-23 19:30 ` Michael S. Tsirkin
2011-08-23 19:38 ` Alex Williamson
2011-08-23 20:59 ` Don Dutile
2011-08-24 9:51 ` Michael S. Tsirkin
2011-08-24 10:04 ` Michael S. Tsirkin
2011-08-24 10:10 ` Jan Kiszka
2011-08-24 11:01 ` Michael S. Tsirkin
2011-08-24 11:58 ` Michael S. Tsirkin
2011-08-24 12:29 ` Jan Kiszka
2011-08-24 12:34 ` Michael S. Tsirkin
2011-08-24 12:36 ` Jan Kiszka
2011-08-24 12:39 ` Michael S. Tsirkin
2011-08-24 12:39 ` Jan Kiszka
2011-08-24 12:29 ` [Qemu-devel] [PATCH v2] " Jan Kiszka
2011-08-24 12:53 ` Michael S. Tsirkin [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=20110824125321.GA18920@redhat.com \
--to=mst@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=ddutile@redhat.com \
--cc=jan.kiszka@siemens.com \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).