From patchwork Thu Jun 29 00:24:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 9815671 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B463A602B9 for ; Thu, 29 Jun 2017 00:27:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E69128497 for ; Thu, 29 Jun 2017 00:27:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8103F284C7; Thu, 29 Jun 2017 00:27:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F358828497 for ; Thu, 29 Jun 2017 00:27:28 +0000 (UTC) Received: from localhost ([::1]:36220 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQNIt-0001sW-9v for patchwork-qemu-devel@patchwork.kernel.org; Wed, 28 Jun 2017 20:27:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34618) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQNHd-0001rp-DK for qemu-devel@nongnu.org; Wed, 28 Jun 2017 20:26:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQNHY-000345-74 for qemu-devel@nongnu.org; Wed, 28 Jun 2017 20:26:09 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:39775 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQNHX-00033L-U0 for qemu-devel@nongnu.org; Wed, 28 Jun 2017 20:26:04 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v5T0OJRp115992 for ; Wed, 28 Jun 2017 20:26:03 -0400 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0b-001b2d01.pphosted.com with ESMTP id 2bcnmqajm4-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 28 Jun 2017 20:26:03 -0400 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 28 Jun 2017 18:26:02 -0600 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 28 Jun 2017 18:25:58 -0600 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v5T0Pwfl066004; Wed, 28 Jun 2017 17:25:58 -0700 Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 07C7E6E03F; Wed, 28 Jun 2017 18:25:58 -0600 (MDT) Received: from localhost (unknown [9.80.98.208]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP id BF57F6E038; Wed, 28 Jun 2017 18:25:57 -0600 (MDT) From: Michael Roth To: libvir-list@redhat.com Date: Wed, 28 Jun 2017 19:24:58 -0500 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498695900-1648-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1498695900-1648-1-git-send-email-mdroth@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17062900-0016-0000-0000-00000710BCB8 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007292; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000214; SDB=6.00880137; UDB=6.00438730; IPR=6.00660291; BA=6.00005445; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015996; XFM=3.00000015; UTC=2017-06-29 00:26:01 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17062900-0017-0000-0000-00003A565FDD Message-Id: <1498695900-1648-4-git-send-email-mdroth@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-28_15:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706290006 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [RFC PATCH 3/5] virpci: introduce virPCIIOMMUGroupIterate() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pkrempa@redhat.com, aik@ozlabs.ru, mprivozn@redhat.com, qemu-devel@nongnu.org, abologna@redhat.com, alex.williamson@redhat.com, qemu-ppc@nongnu.org, sbhat@linux.vnet.ibm.com, laine@laine.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This serves a similar purpose to virPCIDeviceAddressIOMMUGroupIterate, but uses the iommu group number to find matches instead of a device within the group. We refactor the code to use this new function and also export it for use in subsequent patches. Signed-off-by: Michael Roth --- src/util/virpci.c | 42 ++++++++++++++++++++++++++++++------------ src/util/virpci.h | 3 +++ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 2c1b758..b842f44 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -49,6 +49,7 @@ VIR_LOG_INIT("util.pci"); #define PCI_SYSFS "/sys/bus/pci/" +#define IOMMU_GROUP_SYSFS "/sys/kernel/iommu_groups/" #define PCI_ID_LEN 10 /* "XXXX XXXX" */ #define PCI_ADDR_LEN 13 /* "XXXX:XX:XX.X" */ @@ -2178,16 +2179,13 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev, return ret; } - -/* virPCIDeviceAddressIOMMUGroupIterate: - * Call @actor for all devices in the same iommu_group as orig - * (including orig itself) Even if there is no iommu_group for the - * device, call @actor once for orig. +/* virPCIIOMMUGroupIterate: + * Call @actor for all devices in a particular iommu_group. */ int -virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig, - virPCIDeviceAddressActor actor, - void *opaque) +virPCIIOMMUGroupIterate(int iommu_group, + virPCIDeviceAddressActor actor, + void *opaque) { char *groupPath = NULL; DIR *groupDir = NULL; @@ -2196,13 +2194,11 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig, int direrr; if (virAsprintf(&groupPath, - PCI_SYSFS "devices/%04x:%02x:%02x.%x/iommu_group/devices", - orig->domain, orig->bus, orig->slot, orig->function) < 0) + IOMMU_GROUP_SYSFS "%d/devices", + iommu_group) < 0) goto cleanup; if (virDirOpenQuiet(&groupDir, groupPath) < 0) { - /* just process the original device, nothing more */ - ret = (actor)(orig, opaque); goto cleanup; } @@ -2230,6 +2226,28 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig, return ret; } +/* virPCIDeviceAddressIOMMUGroupIterate: + * Call @actor for all devices in the same iommu_group as orig + * (including orig itself) Even if there is no iommu_group for the + * device, call @actor once for orig. + */ +int +virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig, + virPCIDeviceAddressActor actor, + void *opaque) +{ + int ret = -1; + + ret = virPCIIOMMUGroupIterate(virPCIDeviceAddressGetIOMMUGroupNum(orig), + actor, opaque); + if (ret < 0) { + /* just process the original device, nothing more */ + ret = (actor)(orig, opaque); + } + + return ret; +} + static int virPCIDeviceGetIOMMUGroupAddOne(virPCIDeviceAddressPtr newDevAddr, void *opaque) diff --git a/src/util/virpci.h b/src/util/virpci.h index 570684e..5ec1306 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -176,6 +176,9 @@ typedef int (*virPCIDeviceAddressActor)(virPCIDeviceAddressPtr addr, int virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig, virPCIDeviceAddressActor actor, void *opaque); +int virPCIIOMMUGroupIterate(int iommu_group, + virPCIDeviceAddressActor actor, + void *opaque); virPCIDeviceListPtr virPCIDeviceGetIOMMUGroupList(virPCIDevicePtr dev); int virPCIDeviceAddressGetIOMMUGroupAddresses(virPCIDeviceAddressPtr devAddr, virPCIDeviceAddressPtr **iommuGroupDevices,