From patchwork Wed Sep 23 20:23:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 521847 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 988771401AF for ; Thu, 24 Sep 2015 06:29:37 +1000 (AEST) Received: from localhost ([::1]:50560 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZeqfX-0001cc-Ld for incoming@patchwork.ozlabs.org; Wed, 23 Sep 2015 16:29:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42859) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zeqa2-0001He-DT for qemu-devel@nongnu.org; Wed, 23 Sep 2015 16:23:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zeqa1-0003Fz-H9 for qemu-devel@nongnu.org; Wed, 23 Sep 2015 16:23:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41656) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zeqa1-0003F3-Ar for qemu-devel@nongnu.org; Wed, 23 Sep 2015 16:23:53 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 0525391588 for ; Wed, 23 Sep 2015 20:23:53 +0000 (UTC) Received: from gimli.home (ovpn-113-42.phx2.redhat.com [10.3.113.42]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8NKNq9V021736; Wed, 23 Sep 2015 16:23:52 -0400 From: Alex Williamson To: qemu-devel@nongnu.org Date: Wed, 23 Sep 2015 14:23:52 -0600 Message-ID: <20150923202352.6569.87078.stgit@gimli.home> In-Reply-To: <20150923202200.6569.64538.stgit@gimli.home> References: <20150923202200.6569.64538.stgit@gimli.home> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 09/19] vfio/pci: Cleanup ROM blacklist quirk 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 Create a vendor:device ID helper that we'll also use as we rework the rest of the quirks. Re-reading the config entries, even if we get more blacklist entries, is trivial overhead and only incurred during device setup. There's no need to typedef the blacklist structure, it's a static private data type used once. The elements get bumped up to uint32_t to avoid future maintenance issues if PCI_ANY_ID gets used for a blacklist entry (avoiding an actual hardware match). Our test loop is also crying out to be simplified as a for loop. Signed-off-by: Alex Williamson --- hw/vfio/pci-quirks.c | 40 +++++++++++++++++++++++++--------------- hw/vfio/pci.h | 5 ----- trace-events | 3 +++ 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c index 1f9a809..17e300a 100644 --- a/hw/vfio/pci-quirks.c +++ b/hw/vfio/pci-quirks.c @@ -14,6 +14,19 @@ #include "trace.h" #include "qemu/range.h" +#define PCI_ANY_ID (~0) + +/* Use uin32_t for vendor & device so PCI_ANY_ID expands and cannot match hw */ +static bool vfio_pci_is(VFIOPCIDevice *vdev, uint32_t vendor, uint32_t device) +{ + PCIDevice *pdev = &vdev->pdev; + + return (vendor == PCI_ANY_ID || + vendor == pci_get_word(pdev->config + PCI_VENDOR_ID)) && + (device == PCI_ANY_ID || + device == pci_get_word(pdev->config + PCI_DEVICE_ID)); +} + /* * List of device ids/vendor ids for which to disable * option rom loading. This avoids the guest hangs during rom @@ -27,28 +40,25 @@ * your card/environment details and information that could * help in debugging to the bug tracking this issue */ -static const VFIORomBlacklistEntry romblacklist[] = { - /* Broadcom BCM 57810 */ - { 0x14e4, 0x168e } +static const struct { + uint32_t vendor; + uint32_t device; +} romblacklist[] = { + { 0x14e4, 0x168e }, /* Broadcom BCM 57810 */ }; bool vfio_blacklist_opt_rom(VFIOPCIDevice *vdev) { - PCIDevice *pdev = &vdev->pdev; - uint16_t vendor_id, device_id; - int count = 0; - - vendor_id = pci_get_word(pdev->config + PCI_VENDOR_ID); - device_id = pci_get_word(pdev->config + PCI_DEVICE_ID); + int i; - while (count < ARRAY_SIZE(romblacklist)) { - if (romblacklist[count].vendor_id == vendor_id && - romblacklist[count].device_id == device_id) { - return true; + for (i = 0 ; i < ARRAY_SIZE(romblacklist); i++) { + if (vfio_pci_is(vdev, romblacklist[i].vendor, romblacklist[i].device)) { + trace_vfio_quirk_rom_blacklisted(vdev->vbasedev.name, + romblacklist[i].vendor, + romblacklist[i].device); + return true; } - count++; } - return false; } diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index ff94929..f6dbe7f 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -150,11 +150,6 @@ typedef struct VFIOPCIDevice { bool no_kvm_msix; } VFIOPCIDevice; -typedef struct VFIORomBlacklistEntry { - uint16_t vendor_id; - uint16_t device_id; -} VFIORomBlacklistEntry; - uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len); void vfio_pci_write_config(PCIDevice *pdev, uint32_t addr, uint32_t val, int len); diff --git a/trace-events b/trace-events index 545cec3..f783a6a 100644 --- a/trace-events +++ b/trace-events @@ -1585,6 +1585,9 @@ vfio_pci_reset(const char *name) " (%s)" vfio_pci_reset_flr(const char *name) "%s FLR/VFIO_DEVICE_RESET" vfio_pci_reset_pm(const char *name) "%s PCI PM Reset" +# hw/vfio/pci-quirks. +vfio_quirk_rom_blacklisted(const char *name, uint16_t vid, uint16_t did) "%s %04x:%04x" + # hw/vfio/vfio-common.c vfio_region_write(const char *name, int index, uint64_t addr, uint64_t data, unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)" vfio_region_read(char *name, int index, uint64_t addr, unsigned size, uint64_t data) " (%s:region%d+0x%"PRIx64", %d) = 0x%"PRIx64