From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:44539) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QwAJL-0007ro-S6 for qemu-devel@nongnu.org; Wed, 24 Aug 2011 06:03:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QwAJK-0004MC-OS for qemu-devel@nongnu.org; Wed, 24 Aug 2011 06:03:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41917) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QwAJK-0004M5-F8 for qemu-devel@nongnu.org; Wed, 24 Aug 2011 06:03:50 -0400 Date: Wed, 24 Aug 2011 13:04:39 +0300 From: "Michael S. Tsirkin" Message-ID: <20110824100439.GA17255@redhat.com> References: <4E53E328.90601@siemens.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <4E53E328.90601@siemens.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] pci: Error on PCI capability collisions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jan Kiszka Cc: Alex Williamson , qemu-devel On Tue, Aug 23, 2011 at 07:28:08PM +0200, Jan Kiszka wrote: > From: Alex Williamson >=20 > Nothing good can happen when we overlap capabilities >=20 > [ Jan: rebased over qemu, minor formatting ] >=20 > Signed-off-by: Jan Kiszka This doesn't build for me: /scm/qemu/hw/pci.c: In function =E2=80=98pci_add_capability=E2=80=99: /scm/qemu/hw/pci.c:1970:45: error: =E2=80=98PCIDevice=E2=80=99 has no mem= ber named =E2=80=98config_map=E2=80=99 I think that what that includes is the capability including each given offset, right? It would be easy to write some code scanning the capability list to figure this value out. Something along the lines of (untested): static uint8_t pci_find_capability_at_offset(PCIDevice *pdev, uint8_t offset) { =20 uint8_t next, prev, found =3D 0; if (!(pdev->config[PCI_STATUS] & PCI_STATUS_CAP_LIST)) return 0; for (prev =3D PCI_CAPABILITY_LIST; (next =3D pdev->config[prev]); prev =3D next + PCI_CAP_LIST_NEXT) if (next <=3D offset && next > found) found =3D next; return found; } > --- > hw/pci.c | 14 ++++++++++++++ > 1 files changed, 14 insertions(+), 0 deletions(-) >=20 > diff --git a/hw/pci.c b/hw/pci.c > index 6124790..ff20631 100644 > --- a/hw/pci.c > +++ b/hw/pci.c > @@ -1952,11 +1952,25 @@ int pci_add_capability(PCIDevice *pdev, uint8_t= cap_id, > uint8_t offset, uint8_t size) > { > uint8_t *config; > + int i; > + > if (!offset) { > offset =3D pci_find_space(pdev, size); > if (!offset) { > return -ENOSPC; > } > + } else { > + for (i =3D offset; i < offset + size; i++) { > + if (pdev->used[i]) { > + 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, pdev->config_map[i], i); > + return -EFAULT; > + } > + } > } > =20 > config =3D pdev->config + offset; > --=20 > 1.7.3.4