--- src/conf/capabilities.c | 6 ++++++ src/conf/capabilities.h | 3 +++ src/util/virutil.c | 28 ++++++++++++++++++++++++++++ src/util/virutil.h | 2 ++ 4 files changed, 39 insertions(+) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index dd2fc77f91..ba19d5db8c 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1743,3 +1743,9 @@ virCapabilitiesInitCaches(virCapsPtr caps) virBitmapFree(cpus); return ret; } + +void +virCapabilitiesHostInitIOMMU(virCapsPtr caps) +{ + caps->host.iommu = virHostHasIOMMU(); +} diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index f0a06a24df..fe1b9ea455 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -183,6 +183,7 @@ struct _virCapsHost { int nPagesSize; /* size of pagesSize array */ unsigned int *pagesSize; /* page sizes support on the system */ unsigned char host_uuid[VIR_UUID_BUFLEN]; + bool iommu; }; typedef int (*virDomainDefNamespaceParse)(xmlDocPtr, xmlNodePtr, @@ -327,4 +328,6 @@ void virCapsHostCacheBankFree(virCapsHostCacheBankPtr ptr); int virCapabilitiesInitCaches(virCapsPtr caps); +void virCapabilitiesHostInitIOMMU(virCapsPtr caps); + #endif /* __VIR_CAPABILITIES_H */ diff --git a/src/util/virutil.c b/src/util/virutil.c index bb4474acd5..7edcda0ee7 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -2090,3 +2090,31 @@ virMemoryMaxValue(bool capped) else return LLONG_MAX; } + +bool +virHostHasIOMMU(void) +{ + DIR *iommuDir = NULL; + struct dirent *iommuGroup = NULL; + bool ret = false; + int direrr; + + /* condition 1 - /sys/kernel/iommu_groups/ contains entries */ + if (virDirOpenQuiet(&iommuDir, "/sys/kernel/iommu_groups/") < 0) + goto cleanup; + + while ((direrr = virDirRead(iommuDir, &iommuGroup, NULL)) > 0) { + /* assume we found a group */ + break; + } + + if (direrr < 0 || !iommuGroup) + goto cleanup; + /* okay, iommu is on and recognizes groups */ + + ret = true; + + cleanup: + VIR_DIR_CLOSE(iommuDir); + return ret; +} diff --git a/src/util/virutil.h b/src/util/virutil.h index be0f6b0ea8..1ba9635bd9 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -216,6 +216,8 @@ unsigned long long virMemoryLimitTruncate(unsigned long long value); bool virMemoryLimitIsSet(unsigned long long value); unsigned long long virMemoryMaxValue(bool ulong) ATTRIBUTE_NOINLINE; +bool virHostHasIOMMU(void); + /** * VIR_ASSIGN_IS_OVERFLOW: * @rvalue: value that is checked (evaluated twice) -- 2.17.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list