From nobody Thu Nov 28 16:31:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1521099425568868.8941083996256; Thu, 15 Mar 2018 00:37:05 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A87F7FDD2; Thu, 15 Mar 2018 07:37:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0ADF45D72B; Thu, 15 Mar 2018 07:37:04 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C575D4CAB4; Thu, 15 Mar 2018 07:37:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2EHGJZV024059 for ; Wed, 14 Mar 2018 13:16:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id CE98D5C1AB; Wed, 14 Mar 2018 17:16:19 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C6E4F5C25E for ; Wed, 14 Mar 2018 17:16:17 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 223D27E9D4 for ; Wed, 14 Mar 2018 17:16:16 +0000 (UTC) Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2EHFwXg142876 for ; Wed, 14 Mar 2018 13:16:15 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gq44ukw9r-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Wed, 14 Mar 2018 13:16:15 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 14 Mar 2018 17:16:13 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 14 Mar 2018 17:16:11 -0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2EHGBql655676 for ; Wed, 14 Mar 2018 17:16:11 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EB4DBAE045 for ; Wed, 14 Mar 2018 17:06:37 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 34073AE059 for ; Wed, 14 Mar 2018 17:06:37 +0000 (GMT) Received: from localhost.localdomain (unknown [9.79.182.166]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Wed, 14 Mar 2018 17:06:36 +0000 (GMT) From: Shivaprasad G Bhat To: libvir-list@redhat.com Date: Wed, 14 Mar 2018 22:46:09 +0530 In-Reply-To: <152104711186.10112.1077788328340024644.stgit@localhost.localdomain> References: <152104711186.10112.1077788328340024644.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18031417-0008-0000-0000-000004DD78D8 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18031417-0009-0000-0000-00001E707E92 Message-Id: <152104771883.10112.2463440741770922800.stgit@localhost.localdomain> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-03-14_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803140192 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 14 Mar 2018 17:16:16 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 14 Mar 2018 17:16:16 +0000 (UTC) for IP:'148.163.156.1' DOMAIN:'mx0a-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'sbhat@linux.vnet.ibm.com' RCPT:'' X-RedHat-Spam-Score: -0.701 (RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2) 148.163.156.1 mx0a-001b2d01.pphosted.com 148.163.156.1 mx0a-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 02/28] util: move hostdev passthrough support functions to utility X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 15 Mar 2018 07:37:04 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" There is some duplicity of code here. Move them to common place. Signed-off-by: Shivaprasad G Bhat --- src/libvirt_private.syms | 2 + src/qemu/qemu_capabilities.c | 5 +-- src/qemu/qemu_driver.c | 5 +-- src/qemu/qemu_hostdev.c | 70 ++------------------------------------= ---- src/qemu/qemu_hostdev.h | 3 -- src/util/virhostdev.c | 63 ++++++++++++++++++++++++++++++++++++++ src/util/virhostdev.h | 3 ++ tests/virhostdevtest.c | 31 ------------------- 8 files changed, 75 insertions(+), 107 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c67bce7389..e1bdaa127e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1915,6 +1915,8 @@ virHostCPUStatsAssign; =20 # util/virhostdev.h virHostdevFindUSBDevice; +virHostdevHostSupportsPassthroughKVM; +virHostdevHostSupportsPassthroughVFIO; virHostdevIsSCSIDevice; virHostdevManagerGetDefault; virHostdevPCINodeDeviceDetach; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 3eb5ed6d1a..943e92a3d3 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -42,7 +42,6 @@ #include "virhostcpu.h" #include "qemu_monitor.h" #include "virstring.h" -#include "qemu_hostdev.h" #include "qemu_domain.h" #define __QEMU_CAPSPRIV_H_ALLOW__ #include "qemu_capspriv.h" @@ -5725,8 +5724,8 @@ static int virQEMUCapsFillDomainDeviceHostdevCaps(virQEMUCapsPtr qemuCaps, virDomainCapsDeviceHostdevPtr hostd= ev) { - bool supportsPassthroughKVM =3D qemuHostdevHostSupportsPassthroughLega= cy(); - bool supportsPassthroughVFIO =3D qemuHostdevHostSupportsPassthroughVFI= O(); + bool supportsPassthroughKVM =3D virHostdevHostSupportsPassthroughKVM(); + bool supportsPassthroughVFIO =3D virHostdevHostSupportsPassthroughVFIO= (); =20 hostdev->supported =3D true; /* VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES is for containers only */ diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8c872c1f08..0ade86d6a9 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -52,7 +52,6 @@ #include "qemu_command.h" #include "qemu_parse_command.h" #include "qemu_cgroup.h" -#include "qemu_hostdev.h" #include "qemu_hotplug.h" #include "qemu_monitor.h" #include "qemu_process.h" @@ -12963,8 +12962,8 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, int ret =3D -1; virNodeDeviceDefPtr def =3D NULL; char *xml =3D NULL; - bool legacy =3D qemuHostdevHostSupportsPassthroughLegacy(); - bool vfio =3D qemuHostdevHostSupportsPassthroughVFIO(); + bool legacy =3D virHostdevHostSupportsPassthroughKVM(); + bool vfio =3D virHostdevHostSupportsPassthroughVFIO(); virHostdevManagerPtr hostdev_mgr =3D driver->hostdevMgr; =20 virCheckFlags(0, -1); diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index 73d26f4c63..c110cf7816 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -121,78 +121,14 @@ qemuHostdevUpdateActiveDomainDevices(virQEMUDriverPtr= driver, return 0; } =20 -bool -qemuHostdevHostSupportsPassthroughVFIO(void) -{ - DIR *iommuDir =3D NULL; - struct dirent *iommuGroup =3D NULL; - bool ret =3D false; - int direrr; - - /* condition 1 - /sys/kernel/iommu_groups/ contains entries */ - if (virDirOpenQuiet(&iommuDir, "/sys/kernel/iommu_groups/") < 0) - goto cleanup; - - while ((direrr =3D virDirRead(iommuDir, &iommuGroup, NULL)) > 0) { - /* assume we found a group */ - break; - } - - if (direrr < 0 || !iommuGroup) - goto cleanup; - /* okay, iommu is on and recognizes groups */ - - /* condition 2 - /dev/vfio/vfio exists */ - if (!virFileExists("/dev/vfio/vfio")) - goto cleanup; - - ret =3D true; - - cleanup: - VIR_DIR_CLOSE(iommuDir); - return ret; -} - - -#if HAVE_LINUX_KVM_H -# include -bool -qemuHostdevHostSupportsPassthroughLegacy(void) -{ - int kvmfd =3D -1; - bool ret =3D false; - - if ((kvmfd =3D open("/dev/kvm", O_RDONLY)) < 0) - goto cleanup; - -# ifdef KVM_CAP_IOMMU - if ((ioctl(kvmfd, KVM_CHECK_EXTENSION, KVM_CAP_IOMMU)) <=3D 0) - goto cleanup; - - ret =3D true; -# endif - - cleanup: - VIR_FORCE_CLOSE(kvmfd); - - return ret; -} -#else -bool -qemuHostdevHostSupportsPassthroughLegacy(void) -{ - return false; -} -#endif - =20 static bool qemuHostdevPreparePCIDevicesCheckSupport(virDomainHostdevDefPtr *hostdevs, size_t nhostdevs, virQEMUCapsPtr qemuCaps) { - bool supportsPassthroughKVM =3D qemuHostdevHostSupportsPassthroughLega= cy(); - bool supportsPassthroughVFIO =3D qemuHostdevHostSupportsPassthroughVFI= O(); + bool supportsPassthroughKVM =3D virHostdevHostSupportsPassthroughKVM(); + bool supportsPassthroughVFIO =3D virHostdevHostSupportsPassthroughVFIO= (); size_t i; =20 /* assign defaults for hostdev passthrough */ @@ -330,7 +266,7 @@ qemuHostdevPrepareMediatedDevices(virQEMUDriverPtr driv= er, int nhostdevs) { virHostdevManagerPtr hostdev_mgr =3D driver->hostdevMgr; - bool supportsVFIO =3D qemuHostdevHostSupportsPassthroughVFIO(); + bool supportsVFIO =3D virHostdevHostSupportsPassthroughVFIO(); size_t i; =20 for (i =3D 0; i < nhostdevs; i++) { diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h index 9a7c7f143c..bdc51f9d9e 100644 --- a/src/qemu/qemu_hostdev.h +++ b/src/qemu/qemu_hostdev.h @@ -27,9 +27,6 @@ # include "qemu_conf.h" # include "domain_conf.h" =20 -bool qemuHostdevHostSupportsPassthroughLegacy(void); -bool qemuHostdevHostSupportsPassthroughVFIO(void); - int qemuHostdevUpdateActiveMediatedDevices(virQEMUDriverPtr driver, virDomainDefPtr def); int qemuHostdevUpdateActivePCIDevices(virQEMUDriverPtr driver, diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index a12224c58f..e0133cdeec 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -2299,3 +2299,66 @@ virHostdevUpdateActiveDomainDevices(virHostdevManage= rPtr mgr, =20 return 0; } + +bool +virHostdevHostSupportsPassthroughVFIO(void) +{ + DIR *iommuDir =3D NULL; + struct dirent *iommuGroup =3D NULL; + bool ret =3D false; + int direrr; + + /* condition 1 - /sys/kernel/iommu_groups/ contains entries */ + if (virDirOpenQuiet(&iommuDir, "/sys/kernel/iommu_groups/") < 0) + goto cleanup; + + while ((direrr =3D virDirRead(iommuDir, &iommuGroup, NULL)) > 0) { + /* assume we found a group */ + break; + } + + if (direrr < 0 || !iommuGroup) + goto cleanup; + /* okay, iommu is on and recognizes groups */ + + /* condition 2 - /dev/vfio/vfio exists */ + if (!virFileExists("/dev/vfio/vfio")) + goto cleanup; + + ret =3D true; + + cleanup: + VIR_DIR_CLOSE(iommuDir); + return ret; +} + +#if HAVE_LINUX_KVM_H +# include +bool +virHostdevHostSupportsPassthroughKVM(void) +{ + int kvmfd =3D -1; + bool ret =3D false; + + if ((kvmfd =3D open("/dev/kvm", O_RDONLY)) < 0) + goto cleanup; + +# ifdef KVM_CAP_IOMMU + if ((ioctl(kvmfd, KVM_CHECK_EXTENSION, KVM_CAP_IOMMU)) <=3D 0) + goto cleanup; + + ret =3D true; +# endif + + cleanup: + VIR_FORCE_CLOSE(kvmfd); + + return ret; +} +#else +bool +virHostdevHostSupportsPassthroughKVM(void) +{ + return false; +} +#endif diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h index 54e1c66be3..d5efffbac2 100644 --- a/src/util/virhostdev.h +++ b/src/util/virhostdev.h @@ -203,4 +203,7 @@ int virHostdevPCINodeDeviceReset(virHostdevManagerPtr m= gr, virPCIDevicePtr pci) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 +bool virHostdevHostSupportsPassthroughKVM(void); +bool virHostdevHostSupportsPassthroughVFIO(void); + #endif /* __VIR_HOSTDEV_H__ */ diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index 5b03cb6aee..e4fee567a2 100644 --- a/tests/virhostdevtest.c +++ b/tests/virhostdevtest.c @@ -130,37 +130,6 @@ myInit(void) return -1; } =20 -# if HAVE_LINUX_KVM_H -# include -static bool -virHostdevHostSupportsPassthroughKVM(void) -{ - int kvmfd =3D -1; - bool ret =3D false; - - if ((kvmfd =3D open("/dev/kvm", O_RDONLY)) < 0) - goto cleanup; - -# ifdef KVM_CAP_IOMMU - if ((ioctl(kvmfd, KVM_CHECK_EXTENSION, KVM_CAP_IOMMU)) <=3D 0) - goto cleanup; - - ret =3D true; -# endif - - cleanup: - VIR_FORCE_CLOSE(kvmfd); - - return ret; -} -# else -static bool -virHostdevHostSupportsPassthroughKVM(void) -{ - return false; -} -# endif - static int testVirHostdevPreparePCIHostdevs_unmanaged(void) { -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list