From nobody Fri May 17 08:24:44 2024 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 1506010026199887.3353034597424; Thu, 21 Sep 2017 09:07:06 -0700 (PDT) Received: from localhost ([::1]:54489 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dv40H-0005BI-Bm for importer@patchew.org; Thu, 21 Sep 2017 12:07:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48773) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dv3uR-0007gl-P6 for qemu-devel@nongnu.org; Thu, 21 Sep 2017 12:01:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dv3uN-0005D8-ON for qemu-devel@nongnu.org; Thu, 21 Sep 2017 12:01:03 -0400 Received: from 5.mo173.mail-out.ovh.net ([46.105.40.148]:47773) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dv3uN-0005CS-Iy for qemu-devel@nongnu.org; Thu, 21 Sep 2017 12:00:59 -0400 Received: from player687.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo173.mail-out.ovh.net (Postfix) with ESMTP id D4DAB73737 for ; Thu, 21 Sep 2017 18:00:57 +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 player687.ha.ovh.net (Postfix) with ESMTPA id 88A0E2C008C; Thu, 21 Sep 2017 18:00:53 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Thu, 21 Sep 2017 18:00:53 +0200 Message-ID: <150600965332.30533.14702405809647835716.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: quoted-printable X-Ovh-Tracer-Id: 16301060328624986574 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] [fuzzy] X-Received-From: 46.105.40.148 Subject: [Qemu-devel] [PATCH v2 1/2] kvm: check KVM_CAP_SYNC_MMU 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, 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 server-class ppc host, this capability depends on the KVM type, ie, HV or PR. If both KVM are present in the kernel, we will always get the HV specific value, even if we explicitely requested PR on the command line. This can have an impact if we're using hugepages or a balloon device. Since we've already created the VM at the time any user calls kvm_has_sync_mmu(), switching to kvm_vm_check_extension() is enough to fix any potential issue. It is okay for the other archs that also implement KVM_CAP_SYNC_MMU, ie, mips, s390, x86 and arm, because they don't depend on the VM being created or not. While here, let's cache the state of this extension in a bool variable, since it has several users in the code, as suggested by Thomas Huth. Signed-off-by: Greg Kurz Reviewed-by: David Gibson --- accel/kvm/kvm-all.c | 8 +++++--- accel/stubs/kvm-stub.c | 4 ++-- include/sysemu/kvm.h | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index b0181d722083..4d96c1fee9fe 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -87,6 +87,7 @@ struct KVMState #endif int many_ioeventfds; int intx_set_mask; + bool sync_mmu; /* The man page (and posix) say ioctl numbers are signed int, but * they're not. Linux, glibc and *BSD all treat ioctl numbers as * unsigned, and treating them as signed here can break things */ @@ -1665,6 +1666,8 @@ static int kvm_init(MachineState *ms) =20 s->many_ioeventfds =3D kvm_check_many_ioeventfds(); =20 + s->sync_mmu =3D !!kvm_vm_check_extension(kvm_state, KVM_CAP_SYNC_MMU); + return 0; =20 err: @@ -2131,10 +2134,9 @@ int kvm_device_access(int fd, int group, uint64_t at= tr, return err; } =20 -/* Return 1 on success, 0 on failure */ -int kvm_has_sync_mmu(void) +bool kvm_has_sync_mmu(void) { - return kvm_check_extension(kvm_state, KVM_CAP_SYNC_MMU); + return kvm_state->sync_mmu; } =20 int kvm_has_vcpu_events(void) diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c index 3965c528d348..c964af3e1c97 100644 --- a/accel/stubs/kvm-stub.c +++ b/accel/stubs/kvm-stub.c @@ -64,9 +64,9 @@ int kvm_cpu_exec(CPUState *cpu) abort(); } =20 -int kvm_has_sync_mmu(void) +bool kvm_has_sync_mmu(void) { - return 0; + return false; } =20 int kvm_has_many_ioeventfds(void) diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 3a458f50e9f4..bbf12a172339 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -207,7 +207,7 @@ extern KVMState *kvm_state; /* external API */ =20 bool kvm_has_free_slot(MachineState *ms); -int kvm_has_sync_mmu(void); +bool kvm_has_sync_mmu(void); int kvm_has_vcpu_events(void); int kvm_has_robust_singlestep(void); int kvm_has_debugregs(void); From nobody Fri May 17 08:24:44 2024 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 1506009988220789.9770738280978; Thu, 21 Sep 2017 09:06:28 -0700 (PDT) Received: from localhost ([::1]:54487 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dv3zf-0004jX-Ay for importer@patchew.org; Thu, 21 Sep 2017 12:06:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48944) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dv3uf-00084P-CX for qemu-devel@nongnu.org; Thu, 21 Sep 2017 12:01:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dv3uX-0005KY-2Y for qemu-devel@nongnu.org; Thu, 21 Sep 2017 12:01:17 -0400 Received: from 4.mo173.mail-out.ovh.net ([46.105.34.219]:34608) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dv3uW-0005Jb-Sx for qemu-devel@nongnu.org; Thu, 21 Sep 2017 12:01:09 -0400 Received: from player687.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo173.mail-out.ovh.net (Postfix) with ESMTP id 60CE470FFD for ; Thu, 21 Sep 2017 18:01:07 +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 player687.ha.ovh.net (Postfix) with ESMTPA id 168DC2C0091; Thu, 21 Sep 2017 18:01:03 +0200 (CEST) From: Greg Kurz 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: quoted-printable 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] [fuzzy] X-Received-From: 46.105.34.219 Subject: [Qemu-devel] [PATCH v2 2/2] 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, 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 | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 4d96c1fee9fe..b81d373bc5f9 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -1441,7 +1441,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 @@ -1531,26 +1531,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) { - warn_report("Number of %s cpus requested (%d) exceeds " - "the recommended cpus supported by KVM (%d)", - 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); @@ -1585,6 +1565,27 @@ 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) { + warn_report("Number of %s cpus requested (%d) exceeds " + "the recommended cpus supported by KVM (%d)", + 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