cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-warn-if-num-cpus-is-greater-than-num-recommended.patch

218e99
From 453a94cf85a041792086990022d182bcc4f939cb Mon Sep 17 00:00:00 2001
218e99
From: Andrew Jones <drjones@redhat.com>
218e99
Date: Tue, 24 Sep 2013 13:29:36 +0200
218e99
Subject: [PATCH 05/11] kvm: warn if num cpus is greater than num recommended
218e99
218e99
RH-Author: Andrew Jones <drjones@redhat.com>
218e99
Message-id: <1380029376-20391-1-git-send-email-drjones@redhat.com>
218e99
Patchwork-id: 54526
218e99
O-Subject: [RHEL7.0 qemu-kvm PATCH] kvm: warn if num cpus is greater than num recommended
218e99
Bugzilla: 1010881
218e99
RH-Acked-by: Radim Krcmar <rkrcmar@redhat.com>
218e99
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
218e99
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
218e99
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1010881
218e99
Brewing: https://brewweb.devel.redhat.com/taskinfo?taskID=6322066
218e99
218e99
(cherry picked from commit 670436ced08738802e15764039d03ab0dbab2bf3
218e99
 of uq/master)
218e99
218e99
===
218e99
218e99
The comment in kvm_max_vcpus() states that it's using the recommended
218e99
procedure from the kernel API documentation to get the max number
218e99
of vcpus that kvm supports. It is, but by always returning the
218e99
maximum number supported. The maximum number should only be used
218e99
for development purposes. qemu should check KVM_CAP_NR_VCPUS for
218e99
the recommended number of vcpus. This patch adds a warning if a user
218e99
specifies a number of cpus between the recommended and max.
218e99
218e99
Signed-off-by: Andrew Jones <drjones@redhat.com>
218e99
Acked-by: Marcelo Tosatti <mtosatti@redhat.com>
218e99
Signed-off-by: Gleb Natapov <gleb@redhat.com>
218e99
---
218e99
 kvm-all.c | 69 ++++++++++++++++++++++++++++++++++++---------------------------
218e99
 1 file changed, 40 insertions(+), 29 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 kvm-all.c |   69 +++++++++++++++++++++++++++++++++++-------------------------
218e99
 1 files changed, 40 insertions(+), 29 deletions(-)
218e99
218e99
diff --git a/kvm-all.c b/kvm-all.c
218e99
index d0a7c21..f2f68d6 100644
218e99
--- a/kvm-all.c
218e99
+++ b/kvm-all.c
218e99
@@ -1280,24 +1280,20 @@ static int kvm_irqchip_create(KVMState *s)
218e99
     return 0;
218e99
 }
218e99
 
218e99
-static int kvm_max_vcpus(KVMState *s)
218e99
+/* Find number of supported CPUs using the recommended
218e99
+ * procedure from the kernel API documentation to cope with
218e99
+ * older kernels that may be missing capabilities.
218e99
+ */
218e99
+static int kvm_recommended_vcpus(KVMState *s)
218e99
 {
218e99
-    int ret;
218e99
-
218e99
-    /* Find number of supported CPUs using the recommended
218e99
-     * procedure from the kernel API documentation to cope with
218e99
-     * older kernels that may be missing capabilities.
218e99
-     */
218e99
-    ret = kvm_check_extension(s, KVM_CAP_MAX_VCPUS);
218e99
-    if (ret) {
218e99
-        return ret;
218e99
-    }
218e99
-    ret = kvm_check_extension(s, KVM_CAP_NR_VCPUS);
218e99
-    if (ret) {
218e99
-        return ret;
218e99
-    }
218e99
+    int ret = kvm_check_extension(s, KVM_CAP_NR_VCPUS);
218e99
+    return (ret) ? ret : 4;
218e99
+}
218e99
 
218e99
-    return 4;
218e99
+static int kvm_max_vcpus(KVMState *s)
218e99
+{
218e99
+    int ret = kvm_check_extension(s, KVM_CAP_MAX_VCPUS);
218e99
+    return (ret) ? ret : kvm_recommended_vcpus(s);
218e99
 }
218e99
 
218e99
 int kvm_init(void)
218e99
@@ -1305,11 +1301,19 @@ int kvm_init(void)
218e99
     static const char upgrade_note[] =
218e99
         "Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n"
218e99
         "(see http://sourceforge.net/projects/kvm).\n";
218e99
+    struct {
218e99
+        const char *name;
218e99
+        int num;
218e99
+    } num_cpus[] = {
218e99
+        { "SMP",          smp_cpus },
218e99
+        { "hotpluggable", max_cpus },
218e99
+        { NULL, }
218e99
+    }, *nc = num_cpus;
218e99
+    int soft_vcpus_limit, hard_vcpus_limit;
218e99
     KVMState *s;
218e99
     const KVMCapabilityInfo *missing_cap;
218e99
     int ret;
218e99
     int i;
218e99
-    int max_vcpus;
218e99
 
218e99
     s = g_malloc0(sizeof(KVMState));
218e99
 
218e99
@@ -1350,19 +1354,26 @@ int kvm_init(void)
218e99
         goto err;
218e99
     }
218e99
 
218e99
-    max_vcpus = kvm_max_vcpus(s);
218e99
-    if (smp_cpus > max_vcpus) {
218e99
-        ret = -EINVAL;
218e99
-        fprintf(stderr, "Number of SMP cpus requested (%d) exceeds max cpus "
218e99
-                "supported by KVM (%d)\n", smp_cpus, max_vcpus);
218e99
-        goto err;
218e99
-    }
218e99
+    /* check the vcpu limits */
218e99
+    soft_vcpus_limit = kvm_recommended_vcpus(s);
218e99
+    hard_vcpus_limit = kvm_max_vcpus(s);
218e99
 
218e99
-    if (max_cpus > max_vcpus) {
218e99
-        ret = -EINVAL;
218e99
-        fprintf(stderr, "Number of hotpluggable cpus requested (%d) exceeds max cpus "
218e99
-                "supported by KVM (%d)\n", max_cpus, max_vcpus);
218e99
-        goto err;
218e99
+    while (nc->name) {
218e99
+        if (nc->num > soft_vcpus_limit) {
218e99
+            fprintf(stderr,
218e99
+                    "Warning: Number of %s cpus requested (%d) exceeds "
218e99
+                    "the recommended cpus supported by KVM (%d)\n",
218e99
+                    nc->name, nc->num, soft_vcpus_limit);
218e99
+
218e99
+            if (nc->num > hard_vcpus_limit) {
218e99
+                ret = -EINVAL;
218e99
+                fprintf(stderr, "Number of %s cpus requested (%d) exceeds "
218e99
+                        "the maximum cpus supported by KVM (%d)\n",
218e99
+                        nc->name, nc->num, hard_vcpus_limit);
218e99
+                goto err;
218e99
+            }
218e99
+        }
218e99
+        nc++;
218e99
     }
218e99
 
218e99
     s->vmfd = kvm_ioctl(s, KVM_CREATE_VM, 0);
218e99
-- 
218e99
1.7.1
218e99