]> xenbits.xensource.com Git - libvirt.git/commitdiff
tools/virt-host-validate: Fix IOMMU check on s390x
authorThomas Huth <thuth@redhat.com>
Fri, 1 Mar 2019 11:10:26 +0000 (12:10 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 8 Mar 2019 08:16:00 +0000 (09:16 +0100)
When running virt-host-validate on an s390x host, the tool currently warns
that it is "Unknown if this platform has IOMMU support". We can use the
common check for entries in /sys/kernel/iommu_groups here, too, but it only
makes sense to check it if there are also PCI devices available. It's also
common on s390x that there are no PCI devices assigned to the LPAR, and in
that case there is no need for the PCI-related IOMMU, so without PCI devices
we should simply skip this test.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
tools/virt-host-validate-common.c

index 73e3bdb34c13336cb2b61f6ce9ec6399d1f9abcf..40f7367b0cc7a761e9f53d6ec9777e21de398f5a 100644 (file)
@@ -337,7 +337,12 @@ int virHostValidateIOMMU(const char *hvname,
     virBitmapPtr flags;
     struct stat sb;
     const char *bootarg = NULL;
-    bool isAMD = false, isIntel = false, isPPC = false;
+    bool isAMD = false, isIntel = false;
+    virArch arch = virArchFromHost();
+    struct dirent *dent;
+    DIR *dir;
+    int rc;
+
     flags = virHostValidateGetCPUFlags();
 
     if (flags && virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_VMX))
@@ -347,8 +352,6 @@ int virHostValidateIOMMU(const char *hvname,
 
     virBitmapFree(flags);
 
-    isPPC = ARCH_IS_PPC64(virArchFromHost());
-
     if (isIntel) {
         virHostMsgCheck(hvname, "%s", _("for device assignment IOMMU support"));
         if (access("/sys/firmware/acpi/tables/DMAR", F_OK) == 0) {
@@ -373,8 +376,19 @@ int virHostValidateIOMMU(const char *hvname,
                            "hardware platform");
             return -1;
         }
-    } else if (isPPC) {
+    } else if (ARCH_IS_PPC64(arch)) {
         /* Empty Block */
+    } else if (ARCH_IS_S390(arch)) {
+        /* On s390x, we skip the IOMMU check if there are no PCI
+         * devices (which is quite usual on s390x). If there are
+         * no PCI devices the directory is still there but is
+         * empty. */
+        if (!virDirOpen(&dir, "/sys/bus/pci/devices"))
+            return 0;
+        rc = virDirRead(dir, &dent, NULL);
+        VIR_DIR_CLOSE(dir);
+        if (rc <= 0)
+            return 0;
     } else {
         virHostMsgFail(level,
                        "Unknown if this platform has IOMMU support");
@@ -391,7 +405,7 @@ int virHostValidateIOMMU(const char *hvname,
 
     virHostMsgCheck(hvname, "%s", _("if IOMMU is enabled by kernel"));
     if (sb.st_nlink <= 2) {
-        if (!isPPC)
+        if (bootarg)
             virHostMsgFail(level,
                            "IOMMU appears to be disabled in kernel. "
                            "Add %s to kernel cmdline arguments", bootarg);