From patchwork Mon Mar 21 10:08:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cao jin X-Patchwork-Id: 600035 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 3qTBSF70w1z9s3T for ; Mon, 21 Mar 2016 21:11:25 +1100 (AEDT) Received: from localhost ([::1]:56681 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahwnz-0007Ht-Q7 for incoming@patchwork.ozlabs.org; Mon, 21 Mar 2016 06:11:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahwk6-0008GL-6h for qemu-devel@nongnu.org; Mon, 21 Mar 2016 06:07:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ahwk5-0006FL-3s for qemu-devel@nongnu.org; Mon, 21 Mar 2016 06:07:22 -0400 Received: from [59.151.112.132] (port=46748 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahwk4-000667-Kl for qemu-devel@nongnu.org; Mon, 21 Mar 2016 06:07:21 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="4799101" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 21 Mar 2016 18:07:02 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id D6E9A408D260; Mon, 21 Mar 2016 18:06:59 +0800 (CST) Received: from G08FNSTD140223.g08.fujitsu.local (10.167.226.69) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.279.2; Mon, 21 Mar 2016 18:06:59 +0800 From: Cao jin To: Date: Mon, 21 Mar 2016 18:08:41 +0800 Message-ID: <1458554926-7844-6-git-send-email-caoj.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1458554926-7844-1-git-send-email-caoj.fnst@cn.fujitsu.com> References: <1458554926-7844-1-git-send-email-caoj.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.69] X-yoursite-MailScanner-ID: D6E9A408D260.AD660 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: caoj.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: chen.fan.fnst@cn.fujitsu.com, izumi.taku@jp.fujitsu.com, alex.williamson@redhat.com, mst@redhat.com Subject: [Qemu-devel] [PATCH v4 05/10] vfio: extending function vfio_pci_host_match to support mask func number 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: Chen Fan Signed-off-by: Chen Fan --- hw/vfio/pci.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 0516d94..8842b7f 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2060,14 +2060,25 @@ static void vfio_pci_post_reset(VFIOPCIDevice *vdev) vfio_intx_enable(vdev); } -static bool vfio_pci_host_match(PCIHostDeviceAddress *addr, const char *name) +#define HOST_CMP_FUNC_MASK (1 << 0) +static bool vfio_pci_host_match(PCIHostDeviceAddress *addr, const char *name, + uint8_t mask) { - char tmp[13]; + PCIHostDeviceAddress tmp; - sprintf(tmp, "%04x:%02x:%02x.%1x", addr->domain, - addr->bus, addr->slot, addr->function); + if (strlen(name) != 12) { + return false; + } + + if (sscanf(name, "%04x:%02x:%02x.%1x", &tmp.domain, + &tmp.bus, &tmp.slot, &tmp.function) != 4) { + return false; + } - return (strcmp(tmp, name) == 0); + return (tmp.domain == addr->domain && tmp.bus == addr->bus && + tmp.slot == addr->slot && + ((mask & HOST_CMP_FUNC_MASK) ? + 1 : (tmp.function == addr->function))); } static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single) @@ -2109,7 +2120,7 @@ static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single) trace_vfio_pci_hot_reset_dep_devices(host.domain, host.bus, host.slot, host.function, devices[i].group_id); - if (vfio_pci_host_match(&host, vdev->vbasedev.name)) { + if (vfio_pci_host_match(&host, vdev->vbasedev.name, 0)) { continue; } @@ -2135,7 +2146,7 @@ static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single) continue; } tmp = container_of(vbasedev_iter, VFIOPCIDevice, vbasedev); - if (vfio_pci_host_match(&host, tmp->vbasedev.name)) { + if (vfio_pci_host_match(&host, tmp->vbasedev.name, 0)) { if (single) { ret = -EINVAL; goto out_single; @@ -2170,7 +2181,7 @@ out: host.slot = PCI_SLOT(devices[i].devfn); host.function = PCI_FUNC(devices[i].devfn); - if (vfio_pci_host_match(&host, vdev->vbasedev.name)) { + if (vfio_pci_host_match(&host, vdev->vbasedev.name, 0)) { continue; } @@ -2189,7 +2200,7 @@ out: continue; } tmp = container_of(vbasedev_iter, VFIOPCIDevice, vbasedev); - if (vfio_pci_host_match(&host, tmp->vbasedev.name)) { + if (vfio_pci_host_match(&host, tmp->vbasedev.name, 0)) { vfio_pci_post_reset(tmp); break; }