[PATCH] virt-host-validate: warn if kvm_hv is not loaded for POWER hosts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



POWER hosts does not implement CPU virtualization extensions like
x86 or s390x. Instead, all bare-metal POWER hosts are considered
to be virtualization ready.

For POWER, the validation is done by checking the virtualization
kernel modules, kvm_hv and kvm_pr, to see if they are either not
installed or not loaded in the host. If the KVM modules aren't
present, we should not just warn but fail to validate.

This patch implements this support. If kvm_hv is not installed,
which can be determined by 'modinfo' returning not-zero return
code, fail the verification. If kvm_hv is installed but not
loaded, show a warning. The exception are POWER8 hosts, which can
work with kvm_pr. In its case, ACK the use of kvm_pr if kvm_hv
is not loaded/present.

Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 tools/virt-host-validate-common.c | 136 ++++++++++++++++++++++++++++++
 tools/virt-host-validate-common.h |   2 +
 tools/virt-host-validate-qemu.c   |   6 ++
 3 files changed, 144 insertions(+)

diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-common.c
index bce0f14917..e6d7986758 100644
--- a/tools/virt-host-validate-common.c
+++ b/tools/virt-host-validate-common.c
@@ -411,3 +411,139 @@ int virHostValidateIOMMU(const char *hvname,
     virHostMsgPass();
     return 0;
 }
+
+
+static bool virHostCPUIsPower8(void)
+{
+   FILE *fp;
+   bool ret = false;
+
+    if (!(fp = fopen("/proc/cpuinfo", "r")))
+        return false;
+
+    do {
+        char line[1024];
+
+        if (!fgets(line, sizeof(line), fp))
+            break;
+
+        /* Looks for the 'model name' line. This is more common for
+         * Intel /proc/cpuinfo formats, but let's account for it
+         * too. */
+        if (STRPREFIX(line, "model name")) {
+            if (strstr(line, "POWER8"))
+                ret = true;
+            break;
+        }
+
+        /* Looks for the 'cpu:' line which is more commonly present
+         * in /proc/cpuinfo Power systems. To ensure this is not
+         * 'cpu id' or any other cpu attribute, peek at the next char
+         * after the first whitespace. A tab, whitespace or ':'
+         * indicates we're on the right line */
+        if (STRPREFIX(line, "cpu") &&
+            (line[3] == '\t' || line[3] == ':' || line[3] == ' ')) {
+             if (strstr(line, "POWER8"))
+                ret = true;
+            break;
+        }
+
+    } while (1);
+
+    VIR_FORCE_FCLOSE(fp);
+
+    return ret;
+}
+
+
+static bool virHostKernelModuleExists(const char *module)
+{
+    g_autofree char *cmd = g_strdup_printf("modinfo %s", module);
+    g_autofree char *stdout = NULL;
+    g_autofree char *stderr = NULL;
+    g_autoptr(GError) err = NULL;
+    int errStatus;
+
+    if (g_spawn_command_line_sync(cmd, &stdout, &stderr, &errStatus, &err))
+        return true;
+
+    return false;
+}
+
+
+static bool virHostKernelModuleIsLoaded(const char *module)
+{
+    FILE *fp;
+    bool ret = false;
+
+    if (!(fp = fopen("/proc/modules", "r")))
+        return false;
+
+    do {
+        char line[1024];
+
+        if (!fgets(line, sizeof(line), fp))
+            break;
+
+        if (STRPREFIX(line, module)) {
+            ret = true;
+            break;
+        }
+
+    } while (1);
+
+    VIR_FORCE_FCLOSE(fp);
+
+    return ret;
+}
+
+
+int virHostValidatePowerPCModules(void)
+{
+    bool kvm_pr_exists = virHostKernelModuleExists("kvm_pr");
+    bool kvm_pr_loaded = kvm_pr_exists && virHostKernelModuleIsLoaded("kvm_pr");
+    bool kvm_hv_exists = virHostKernelModuleExists("kvm_hv");
+    bool kvm_hv_loaded = kvm_hv_exists && virHostKernelModuleIsLoaded("kvm_hv");
+    bool hostIsP8 = virHostCPUIsPower8();
+
+    virHostMsgCheck("QEMU", "%s", _("for PowerPC KVM modules loaded"));
+
+    /* No Power KVM virtualization modules present on the host. */
+    if (!kvm_hv_exists && !kvm_pr_exists) {
+        virHostMsgFail(VIR_HOST_VALIDATE_FAIL,
+                           _("No kvm_hv or kvm_pr module present in "
+                             "the host"));
+        return -1;
+    }
+
+    /* Bail out for all non-Power8 CPUs if kvm_hv is not present. */
+    if (!kvm_hv_exists && !hostIsP8) {
+        virHostMsgFail(VIR_HOST_VALIDATE_FAIL,
+                       _("No kvm_hv module present in the host"));
+        return -1;
+    }
+
+    /* Power8 CPUs virtualization works with any of kvm_hv and kvm_pr.
+     * Issue a warning if none are loaded. */
+    if (hostIsP8) {
+        if (!kvm_hv_loaded && !kvm_pr_loaded) {
+            virHostMsgFail(VIR_HOST_VALIDATE_WARN,
+                           _("Load kvm_hv or kvm_pr module "
+                             "for better performance"));
+            return 0;
+        }
+
+        virHostMsgPass();
+        return 0;
+    }
+
+    /* For non-Power8 hosts, show a warning if kvm_hv is not loaded. */
+    if (!kvm_hv_loaded) {
+        virHostMsgFail(VIR_HOST_VALIDATE_WARN,
+                      _("Load kvm_hv for better performance"));
+        return 0;
+    }
+
+    virHostMsgPass();
+    return 0;
+}
diff --git a/tools/virt-host-validate-common.h b/tools/virt-host-validate-common.h
index 1b7e93e520..7a2933c8fd 100644
--- a/tools/virt-host-validate-common.h
+++ b/tools/virt-host-validate-common.h
@@ -83,3 +83,5 @@ int virHostValidateCGroupControllers(const char *hvname,
 
 int virHostValidateIOMMU(const char *hvname,
                          virHostValidateLevel level);
+
+int virHostValidatePowerPCModules(void);
\ No newline at end of file
diff --git a/tools/virt-host-validate-qemu.c b/tools/virt-host-validate-qemu.c
index ff3c1f0231..8753c6a31d 100644
--- a/tools/virt-host-validate-qemu.c
+++ b/tools/virt-host-validate-qemu.c
@@ -57,6 +57,12 @@ int virHostValidateQEMU(void)
         if (virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_SIE))
             hasHwVirt = true;
         break;
+    case VIR_ARCH_PPC64:
+    case VIR_ARCH_PPC64LE:
+        hasVirtFlag = true;
+        if (virHostValidatePowerPCModules() == 0)
+            hasHwVirt = true;
+        break;
     default:
         hasHwVirt = false;
     }
-- 
2.23.0


--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux