From nobody Tue Feb 10 08:41:05 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505417269658539.2932452742368; Thu, 14 Sep 2017 12:27:49 -0700 (PDT) Received: from localhost ([::1]:49654 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsZng-00032Z-U5 for importer@patchew.org; Thu, 14 Sep 2017 15:27:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53699) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsZld-0001XZ-MS for qemu-devel@nongnu.org; Thu, 14 Sep 2017 15:25:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsZlb-00062l-NN for qemu-devel@nongnu.org; Thu, 14 Sep 2017 15:25:41 -0400 Received: from 4.mo2.mail-out.ovh.net ([87.98.172.75]:35555) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsZlb-00062I-DA for qemu-devel@nongnu.org; Thu, 14 Sep 2017 15:25:39 -0400 Received: from player770.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo2.mail-out.ovh.net (Postfix) with ESMTP id 68855ABC36 for ; Thu, 14 Sep 2017 21:25:38 +0200 (CEST) Received: from bahia.lan (gar31-1-82-66-74-139.fbx.proxad.net [82.66.74.139]) (Authenticated sender: groug@kaod.org) by player770.ha.ovh.net (Postfix) with ESMTPA id 12C463C006B; Thu, 14 Sep 2017 21:25:33 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Thu, 14 Sep 2017 21:25:32 +0200 Message-ID: <150541713284.1616.15291547955159941369.stgit@bahia.lan> In-Reply-To: <150541711102.1616.2690784964841960181.stgit@bahia.lan> References: <150541711102.1616.2690784964841960181.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: quoted-printable X-Ovh-Tracer-Id: 15542485265153562930 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelledrgeeigddugedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 87.98.172.75 Subject: [Qemu-devel] [PATCH 2/3] kvm: check KVM_CAP_NR_VCPUS with kvm_vm_check_extension() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Thomas Huth , qemu-ppc@nongnu.org, Sam Bobroff , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 On a modern server-class ppc host with the following CPU topology: Architecture: ppc64le Byte Order: Little Endian CPU(s): 32 On-line CPU(s) list: 0,8,16,24 Off-line CPU(s) list: 1-7,9-15,17-23,25-31 Thread(s) per core: 1 If both KVM PR and KVM HV loaded and we pass: -machine pseries,accel=3Dkvm,kvm-type=3DPR -smp 8 We expect QEMU to warn that this exceeds the number of online CPUs: Warning: Number of SMP cpus requested (8) exceeds the recommended cpus supported by KVM (4) Warning: Number of hotpluggable cpus requested (8) exceeds the recommended cpus supported by KVM (4) but nothing is printed... This happens because on ppc the KVM_CAP_NR_VCPUS capability is VM specific ndreally depends on the KVM type, but we currently use it as a global capability. And KVM returns a fallback value based on KVM HV being present. Maybe KVM on POWER shouldn't presume anything as long as it doesn't have a VM, but in all cases, we should call KVM_CREATE_VM first and use KVM_CAP_NR_VCPUS as a VM capability. This patch hence changes kvm_recommended_vcpus() accordingly and moves the sanity checking of smp_cpus after the VM creation. It is okay for the other archs that also implement KVM_CAP_NR_VCPUS, ie, mips, s390, x86 and arm, because they don't depend on the VM being created or not. Signed-off-by: Greg Kurz Reviewed-by: David Gibson Reviewed-by: Thomas Huth --- accel/kvm/kvm-all.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 323c567cfb68..d10534de2da1 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -1533,7 +1533,7 @@ static void kvm_irqchip_create(MachineState *machine,= KVMState *s) */ static int kvm_recommended_vcpus(KVMState *s) { - int ret =3D kvm_check_extension(s, KVM_CAP_NR_VCPUS); + int ret =3D kvm_vm_check_extension(s, KVM_CAP_NR_VCPUS); return (ret) ? ret : 4; } =20 @@ -1623,27 +1623,6 @@ static int kvm_init(MachineState *ms) s->nr_slots =3D 32; } =20 - /* check the vcpu limits */ - soft_vcpus_limit =3D kvm_recommended_vcpus(s); - hard_vcpus_limit =3D kvm_max_vcpus(s); - - while (nc->name) { - if (nc->num > soft_vcpus_limit) { - fprintf(stderr, - "Warning: Number of %s cpus requested (%d) exceeds " - "the recommended cpus supported by KVM (%d)\n", - nc->name, nc->num, soft_vcpus_limit); - - if (nc->num > hard_vcpus_limit) { - fprintf(stderr, "Number of %s cpus requested (%d) exceeds " - "the maximum cpus supported by KVM (%d)\n", - nc->name, nc->num, hard_vcpus_limit); - exit(1); - } - } - nc++; - } - kvm_type =3D qemu_opt_get(qemu_get_machine_opts(), "kvm-type"); if (mc->kvm_type) { type =3D mc->kvm_type(kvm_type); @@ -1678,6 +1657,28 @@ static int kvm_init(MachineState *ms) } =20 s->vmfd =3D ret; + + /* check the vcpu limits */ + soft_vcpus_limit =3D kvm_recommended_vcpus(s); + hard_vcpus_limit =3D kvm_max_vcpus(s); + + while (nc->name) { + if (nc->num > soft_vcpus_limit) { + fprintf(stderr, + "Warning: Number of %s cpus requested (%d) exceeds " + "the recommended cpus supported by KVM (%d)\n", + nc->name, nc->num, soft_vcpus_limit); + + if (nc->num > hard_vcpus_limit) { + fprintf(stderr, "Number of %s cpus requested (%d) exceeds " + "the maximum cpus supported by KVM (%d)\n", + nc->name, nc->num, hard_vcpus_limit); + exit(1); + } + } + nc++; + } + missing_cap =3D kvm_check_extension_list(s, kvm_required_capabilites); if (!missing_cap) { missing_cap =3D