{"id":816997,"url":"http://patchwork.ozlabs.org/api/patches/816997/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/150600966286.30533.10909862523552370889.stgit@bahia.lan/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<150600966286.30533.10909862523552370889.stgit@bahia.lan>","list_archive_url":null,"date":"2017-09-21T16:01:02","name":"[v2,2/2] kvm: check KVM_CAP_NR_VCPUS with kvm_vm_check_extension()","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"86f5c4c5f8c9f1e9274e6048216a41735502b5b3","submitter":{"id":69178,"url":"http://patchwork.ozlabs.org/api/people/69178/?format=json","name":"Greg Kurz","email":"groug@kaod.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/150600966286.30533.10909862523552370889.stgit@bahia.lan/mbox/","series":[{"id":4429,"url":"http://patchwork.ozlabs.org/api/series/4429/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=4429","date":"2017-09-21T16:00:41","name":"kvm: use kvm_vm_check_extension() with VM capabilities","version":2,"mbox":"http://patchwork.ozlabs.org/series/4429/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/816997/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/816997/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xyhKf74sZz9t42\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 22 Sep 2017 02:05:42 +1000 (AEST)","from localhost ([::1]:54470 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dv3yv-00043U-0W\n\tfor incoming@patchwork.ozlabs.org; Thu, 21 Sep 2017 12:05:41 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:48944)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <groug@kaod.org>) id 1dv3uf-00084P-CX\n\tfor qemu-devel@nongnu.org; Thu, 21 Sep 2017 12:01:23 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <groug@kaod.org>) id 1dv3uX-0005KY-2Y\n\tfor qemu-devel@nongnu.org; Thu, 21 Sep 2017 12:01:17 -0400","from 4.mo173.mail-out.ovh.net ([46.105.34.219]:34608)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <groug@kaod.org>) id 1dv3uW-0005Jb-Sx\n\tfor qemu-devel@nongnu.org; Thu, 21 Sep 2017 12:01:09 -0400","from player687.ha.ovh.net (b9.ovh.net [213.186.33.59])\n\tby mo173.mail-out.ovh.net (Postfix) with ESMTP id 60CE470FFD\n\tfor <qemu-devel@nongnu.org>; Thu, 21 Sep 2017 18:01:07 +0200 (CEST)","from bahia.lan (gar31-1-82-66-74-139.fbx.proxad.net [82.66.74.139])\n\t(Authenticated sender: groug@kaod.org)\n\tby player687.ha.ovh.net (Postfix) with ESMTPA id 168DC2C0091;\n\tThu, 21 Sep 2017 18:01:03 +0200 (CEST)"],"From":"Greg Kurz <groug@kaod.org>","To":"qemu-devel@nongnu.org","Date":"Thu, 21 Sep 2017 18:01:02 +0200","Message-ID":"<150600966286.30533.10909862523552370889.stgit@bahia.lan>","In-Reply-To":"<150600964184.30533.472565821627831467.stgit@bahia.lan>","References":"<150600964184.30533.472565821627831467.stgit@bahia.lan>","User-Agent":"StGit/0.17.1-46-g6855-dirty","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"7bit","X-Ovh-Tracer-Id":"16303875076874017230","X-VR-SPAMSTATE":"OK","X-VR-SPAMSCORE":"-100","X-VR-SPAMCAUSE":"gggruggvucftvghtrhhoucdtuddrfeelledriedvgdellecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"46.105.34.219","Subject":"[Qemu-devel] [PATCH v2 2/2] kvm: check KVM_CAP_NR_VCPUS with\n\tkvm_vm_check_extension()","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Paolo Bonzini <pbonzini@redhat.com>, Thomas Huth <thuth@redhat.com>,\n\tqemu-ppc@nongnu.org, David Gibson <david@gibson.dropbear.id.au>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"On a modern server-class ppc host with the following CPU topology:\n\nArchitecture:          ppc64le\nByte Order:            Little Endian\nCPU(s):                32\nOn-line CPU(s) list:   0,8,16,24\nOff-line CPU(s) list:  1-7,9-15,17-23,25-31\nThread(s) per core:    1\n\nIf both KVM PR and KVM HV loaded and we pass:\n\n        -machine pseries,accel=kvm,kvm-type=PR -smp 8\n\nWe expect QEMU to warn that this exceeds the number of online CPUs:\n\nWarning: Number of SMP cpus requested (8) exceeds the recommended\n cpus supported by KVM (4)\nWarning: Number of hotpluggable cpus requested (8) exceeds the\n recommended cpus supported by KVM (4)\n\nbut nothing is printed...\n\nThis happens because on ppc the KVM_CAP_NR_VCPUS capability is VM\nspecific  ndreally depends on the KVM type, but we currently use it\nas a global capability. And KVM returns a fallback value based on\nKVM HV being present. Maybe KVM on POWER shouldn't presume anything\nas long as it doesn't have a VM, but in all cases, we should call\nKVM_CREATE_VM first and use KVM_CAP_NR_VCPUS as a VM capability.\n\nThis patch hence changes kvm_recommended_vcpus() accordingly and\nmoves the sanity checking of smp_cpus after the VM creation.\n\nIt is okay for the other archs that also implement KVM_CAP_NR_VCPUS,\nie, mips, s390, x86 and arm, because they don't depend on the VM\nbeing created or not.\n\nSigned-off-by: Greg Kurz <groug@kaod.org>\nReviewed-by: David Gibson <david@gibson.dropbear.id.au>\nReviewed-by: Thomas Huth <thuth@redhat.com>\n---\n accel/kvm/kvm-all.c |   43 ++++++++++++++++++++++---------------------\n 1 file changed, 22 insertions(+), 21 deletions(-)","diff":"diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c\nindex 4d96c1fee9fe..b81d373bc5f9 100644\n--- a/accel/kvm/kvm-all.c\n+++ b/accel/kvm/kvm-all.c\n@@ -1441,7 +1441,7 @@ static void kvm_irqchip_create(MachineState *machine, KVMState *s)\n  */\n static int kvm_recommended_vcpus(KVMState *s)\n {\n-    int ret = kvm_check_extension(s, KVM_CAP_NR_VCPUS);\n+    int ret = kvm_vm_check_extension(s, KVM_CAP_NR_VCPUS);\n     return (ret) ? ret : 4;\n }\n \n@@ -1531,26 +1531,6 @@ static int kvm_init(MachineState *ms)\n         s->nr_slots = 32;\n     }\n \n-    /* check the vcpu limits */\n-    soft_vcpus_limit = kvm_recommended_vcpus(s);\n-    hard_vcpus_limit = kvm_max_vcpus(s);\n-\n-    while (nc->name) {\n-        if (nc->num > soft_vcpus_limit) {\n-            warn_report(\"Number of %s cpus requested (%d) exceeds \"\n-                        \"the recommended cpus supported by KVM (%d)\",\n-                        nc->name, nc->num, soft_vcpus_limit);\n-\n-            if (nc->num > hard_vcpus_limit) {\n-                fprintf(stderr, \"Number of %s cpus requested (%d) exceeds \"\n-                        \"the maximum cpus supported by KVM (%d)\\n\",\n-                        nc->name, nc->num, hard_vcpus_limit);\n-                exit(1);\n-            }\n-        }\n-        nc++;\n-    }\n-\n     kvm_type = qemu_opt_get(qemu_get_machine_opts(), \"kvm-type\");\n     if (mc->kvm_type) {\n         type = mc->kvm_type(kvm_type);\n@@ -1585,6 +1565,27 @@ static int kvm_init(MachineState *ms)\n     }\n \n     s->vmfd = ret;\n+\n+    /* check the vcpu limits */\n+    soft_vcpus_limit = kvm_recommended_vcpus(s);\n+    hard_vcpus_limit = kvm_max_vcpus(s);\n+\n+    while (nc->name) {\n+        if (nc->num > soft_vcpus_limit) {\n+            warn_report(\"Number of %s cpus requested (%d) exceeds \"\n+                        \"the recommended cpus supported by KVM (%d)\",\n+                        nc->name, nc->num, soft_vcpus_limit);\n+\n+            if (nc->num > hard_vcpus_limit) {\n+                fprintf(stderr, \"Number of %s cpus requested (%d) exceeds \"\n+                        \"the maximum cpus supported by KVM (%d)\\n\",\n+                        nc->name, nc->num, hard_vcpus_limit);\n+                exit(1);\n+            }\n+        }\n+        nc++;\n+    }\n+\n     missing_cap = kvm_check_extension_list(s, kvm_required_capabilites);\n     if (!missing_cap) {\n         missing_cap =\n","prefixes":["v2","2/2"]}