From patchwork Tue Aug 23 17:28:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 111149 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6CC18B6F71 for ; Wed, 24 Aug 2011 03:28:25 +1000 (EST) Received: from localhost ([::1]:38054 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qvult-00068l-Fp for incoming@patchwork.ozlabs.org; Tue, 23 Aug 2011 13:28:17 -0400 Received: from eggs.gnu.org ([140.186.70.92]:33556) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qvulo-00068Y-Ou for qemu-devel@nongnu.org; Tue, 23 Aug 2011 13:28:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qvuln-0005QL-Ef for qemu-devel@nongnu.org; Tue, 23 Aug 2011 13:28:12 -0400 Received: from goliath.siemens.de ([192.35.17.28]:24928) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qvuln-0005QC-5r for qemu-devel@nongnu.org; Tue, 23 Aug 2011 13:28:11 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by goliath.siemens.de (8.13.6/8.13.6) with ESMTP id p7NHS94i023245; Tue, 23 Aug 2011 19:28:09 +0200 Received: from mchn199C.mchp.siemens.de ([139.25.109.49]) by mail1.siemens.de (8.13.6/8.13.6) with ESMTP id p7NHS8l2014258; Tue, 23 Aug 2011 19:28:08 +0200 Message-ID: <4E53E328.90601@siemens.com> Date: Tue, 23 Aug 2011 19:28:08 +0200 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: "Michael S. Tsirkin" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 192.35.17.28 Cc: Alex Williamson , qemu-devel Subject: [Qemu-devel] [PATCH] pci: Error on PCI capability collisions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Alex Williamson Nothing good can happen when we overlap capabilities [ Jan: rebased over qemu, minor formatting ] Signed-off-by: Jan Kiszka --- hw/pci.c | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-) 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 = pci_find_space(pdev, size); if (!offset) { return -ENOSPC; } + } else { + for (i = 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; + } + } } config = pdev->config + offset;