[{"id":1768927,"web_url":"http://patchwork.ozlabs.org/comment/1768927/","msgid":"<20170915010021.GC5250@umbus.fritz.box>","list_archive_url":null,"date":"2017-09-15T01:00:21","subject":"Re: [Qemu-devel] [PATCH 2/3] kvm: check KVM_CAP_NR_VCPUS with\n\tkvm_vm_check_extension()","submitter":{"id":47,"url":"http://patchwork.ozlabs.org/api/people/47/","name":"David Gibson","email":"david@gibson.dropbear.id.au"},"content":"On Thu, Sep 14, 2017 at 09:25:32PM +0200, Greg Kurz wrote:\n1;4803;0c> On a modern server-class ppc host with the following CPU topology:\n> \n> Architecture:          ppc64le\n> Byte Order:            Little Endian\n> CPU(s):                32\n> On-line CPU(s) list:   0,8,16,24\n> Off-line CPU(s) list:  1-7,9-15,17-23,25-31\n> Thread(s) per core:    1\n> \n> If both KVM PR and KVM HV loaded and we pass:\n> \n>         -machine pseries,accel=kvm,kvm-type=PR -smp 8\n> \n> We expect QEMU to warn that this exceeds the number of online CPUs:\n> \n> Warning: Number of SMP cpus requested (8) exceeds the recommended\n>  cpus supported by KVM (4)\n> Warning: Number of hotpluggable cpus requested (8) exceeds the\n>  recommended cpus supported by KVM (4)\n> \n> but nothing is printed...\n> \n> This happens because on ppc the KVM_CAP_NR_VCPUS capability is VM\n> specific  ndreally depends on the KVM type, but we currently use it\n> as a global capability. And KVM returns a fallback value based on\n> KVM HV being present. Maybe KVM on POWER shouldn't presume anything\n> as long as it doesn't have a VM, but in all cases, we should call\n> KVM_CREATE_VM first and use KVM_CAP_NR_VCPUS as a VM capability.\n> \n> This patch hence changes kvm_recommended_vcpus() accordingly and\n> moves the sanity checking of smp_cpus after the VM creation.\n> \n> It is okay for the other archs that also implement KVM_CAP_NR_VCPUS,\n> ie, mips, s390, x86 and arm, because they don't depend on the VM\n> being created or not.\n> \n> Signed-off-by: Greg Kurz <groug@kaod.org>\n\nReviewed-by: David Gibson <david@gibson.dropbear.id.au>\n\n> ---\n>  accel/kvm/kvm-all.c |   45 +++++++++++++++++++++++----------------------\n>  1 file changed, 23 insertions(+), 22 deletions(-)\n> \n> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c\n> index 323c567cfb68..d10534de2da1 100644\n> --- a/accel/kvm/kvm-all.c\n> +++ b/accel/kvm/kvm-all.c\n> @@ -1533,7 +1533,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> @@ -1623,27 +1623,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> -            fprintf(stderr,\n> -                    \"Warning: Number of %s cpus requested (%d) exceeds \"\n> -                    \"the recommended cpus supported by KVM (%d)\\n\",\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> @@ -1678,6 +1657,28 @@ 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> +            fprintf(stderr,\n> +                    \"Warning: Number of %s cpus requested (%d) exceeds \"\n> +                    \"the recommended cpus supported by KVM (%d)\\n\",\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>","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>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=gibson.dropbear.id.au\n\theader.i=@gibson.dropbear.id.au header.b=\"c1ucNGry\"; \n\tdkim-atps=neutral"],"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 3xtgBj5p76z9sCZ\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 15 Sep 2017 13:00:45 +1000 (AEST)","from localhost ([::1]:50877 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 1dsgrz-0005XF-RC\n\tfor incoming@patchwork.ozlabs.org; Thu, 14 Sep 2017 23:00:43 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:46620)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <dgibson@ozlabs.org>) id 1dsgrC-0005WO-MV\n\tfor qemu-devel@nongnu.org; Thu, 14 Sep 2017 22:59:56 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <dgibson@ozlabs.org>) id 1dsgrB-0002ZR-E7\n\tfor qemu-devel@nongnu.org; Thu, 14 Sep 2017 22:59:54 -0400","from ozlabs.org ([2401:3900:2:1::2]:54575)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <dgibson@ozlabs.org>)\n\tid 1dsgrB-0002Yg-0w; Thu, 14 Sep 2017 22:59:53 -0400","by ozlabs.org (Postfix, from userid 1007)\n\tid 3xtg9d4ryhz9sCZ; Fri, 15 Sep 2017 12:59:49 +1000 (AEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple;\n\td=gibson.dropbear.id.au; s=201602; t=1505444389;\n\tbh=6kO0ctGDID0pCkYCV+JPtve8nZb7qB8LiAvc+Z9Sljo=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=c1ucNGryGxKGVzsxsgf+KXyrDcAbArgMcfLB2+hRb+D0mhqPzQdj5iNTKjtCMGuXr\n\tS2oUtkkco2iR/U5sYpElvwLUavmuN4vx/wh/JuDF3bsMTSEN0pI0wgz+Bcyxu/wnop\n\tiNr5dDfIGc+ohAoHIHIwnWL+bgUMeJTnBgmA4i30=","Date":"Fri, 15 Sep 2017 11:00:21 +1000","From":"David Gibson <david@gibson.dropbear.id.au>","To":"Greg Kurz <groug@kaod.org>","Message-ID":"<20170915010021.GC5250@umbus.fritz.box>","References":"<150541711102.1616.2690784964841960181.stgit@bahia.lan>\n\t<150541713284.1616.15291547955159941369.stgit@bahia.lan>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"c3bfwLpm8qysLVxt\"","Content-Disposition":"inline","In-Reply-To":"<150541713284.1616.15291547955159941369.stgit@bahia.lan>","User-Agent":"Mutt/1.8.3 (2017-05-23)","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2401:3900:2:1::2","Subject":"Re: [Qemu-devel] [PATCH 2/3] 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, qemu-devel@nongnu.org,\n\tSam Bobroff <sam.bobroff@au1.ibm.com>","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>"}},{"id":1768949,"web_url":"http://patchwork.ozlabs.org/comment/1768949/","msgid":"<abd784d6-ae05-e248-5f81-c6df281d01bb@redhat.com>","list_archive_url":null,"date":"2017-09-15T05:34:59","subject":"Re: [Qemu-devel] [PATCH 2/3] kvm: check KVM_CAP_NR_VCPUS with\n\tkvm_vm_check_extension()","submitter":{"id":66152,"url":"http://patchwork.ozlabs.org/api/people/66152/","name":"Thomas Huth","email":"thuth@redhat.com"},"content":"On 14.09.2017 21:25, Greg Kurz wrote:\n> On a modern server-class ppc host with the following CPU topology:\n> \n> Architecture:          ppc64le\n> Byte Order:            Little Endian\n> CPU(s):                32\n> On-line CPU(s) list:   0,8,16,24\n> Off-line CPU(s) list:  1-7,9-15,17-23,25-31\n> Thread(s) per core:    1\n> \n> If both KVM PR and KVM HV loaded and we pass:\n> \n>         -machine pseries,accel=kvm,kvm-type=PR -smp 8\n> \n> We expect QEMU to warn that this exceeds the number of online CPUs:\n> \n> Warning: Number of SMP cpus requested (8) exceeds the recommended\n>  cpus supported by KVM (4)\n> Warning: Number of hotpluggable cpus requested (8) exceeds the\n>  recommended cpus supported by KVM (4)\n> \n> but nothing is printed...\n> \n> This happens because on ppc the KVM_CAP_NR_VCPUS capability is VM\n> specific  ndreally depends on the KVM type, but we currently use it\n> as a global capability. And KVM returns a fallback value based on\n> KVM HV being present. Maybe KVM on POWER shouldn't presume anything\n> as long as it doesn't have a VM, but in all cases, we should call\n> KVM_CREATE_VM first and use KVM_CAP_NR_VCPUS as a VM capability.\n> \n> This patch hence changes kvm_recommended_vcpus() accordingly and\n> moves the sanity checking of smp_cpus after the VM creation.\n> \n> It is okay for the other archs that also implement KVM_CAP_NR_VCPUS,\n> ie, mips, s390, x86 and arm, because they don't depend on the VM\n> being created or not.\n> \n> Signed-off-by: Greg Kurz <groug@kaod.org>\n> ---\n>  accel/kvm/kvm-all.c |   45 +++++++++++++++++++++++----------------------\n>  1 file changed, 23 insertions(+), 22 deletions(-)\n> \n> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c\n> index 323c567cfb68..d10534de2da1 100644\n> --- a/accel/kvm/kvm-all.c\n> +++ b/accel/kvm/kvm-all.c\n> @@ -1533,7 +1533,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> @@ -1623,27 +1623,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> -            fprintf(stderr,\n> -                    \"Warning: Number of %s cpus requested (%d) exceeds \"\n> -                    \"the recommended cpus supported by KVM (%d)\\n\",\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> @@ -1678,6 +1657,28 @@ 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> +            fprintf(stderr,\n> +                    \"Warning: Number of %s cpus requested (%d) exceeds \"\n> +                    \"the recommended cpus supported by KVM (%d)\\n\",\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> \n\nReviewed-by: Thomas Huth <thuth@redhat.com>","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>)","ext-mx07.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx07.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=thuth@redhat.com"],"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 3xtkdN3xZ8z9t2Z\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 15 Sep 2017 15:35:36 +1000 (AEST)","from localhost ([::1]:51389 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 1dsjHq-0006BD-Nm\n\tfor incoming@patchwork.ozlabs.org; Fri, 15 Sep 2017 01:35:34 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:48650)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <thuth@redhat.com>) id 1dsjHQ-00069c-5n\n\tfor qemu-devel@nongnu.org; Fri, 15 Sep 2017 01:35:09 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <thuth@redhat.com>) id 1dsjHM-0008Uz-7S\n\tfor qemu-devel@nongnu.org; Fri, 15 Sep 2017 01:35:08 -0400","from mx1.redhat.com ([209.132.183.28]:49635)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <thuth@redhat.com>)\n\tid 1dsjHL-0008UZ-VG; Fri, 15 Sep 2017 01:35:04 -0400","from smtp.corp.redhat.com\n\t(int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id C4F1FC04B946;\n\tFri, 15 Sep 2017 05:35:02 +0000 (UTC)","from [10.36.116.76] (ovpn-116-76.ams2.redhat.com [10.36.116.76])\n\tby smtp.corp.redhat.com (Postfix) with ESMTPS id 1C49C785F3;\n\tFri, 15 Sep 2017 05:35:00 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com C4F1FC04B946","To":"Greg Kurz <groug@kaod.org>, qemu-devel@nongnu.org","References":"<150541711102.1616.2690784964841960181.stgit@bahia.lan>\n\t<150541713284.1616.15291547955159941369.stgit@bahia.lan>","From":"Thomas Huth <thuth@redhat.com>","Message-ID":"<abd784d6-ae05-e248-5f81-c6df281d01bb@redhat.com>","Date":"Fri, 15 Sep 2017 07:34:59 +0200","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<150541713284.1616.15291547955159941369.stgit@bahia.lan>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-US","Content-Transfer-Encoding":"7bit","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.12","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.31]);\n\tFri, 15 Sep 2017 05:35:03 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"Re: [Qemu-devel] [PATCH 2/3] 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>, qemu-ppc@nongnu.org,\n\tSam Bobroff <sam.bobroff@au1.ibm.com>,\n\tDavid 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>"}}]