[{"id":1773458,"web_url":"http://patchwork.ozlabs.org/comment/1773458/","msgid":"<20170922101501.GI4998@umbus.fritz.box>","list_archive_url":null,"date":"2017-09-22T10:15:01","subject":"Re: [Qemu-devel] [PATCH v2 1/2] kvm: check KVM_CAP_SYNC_MMU 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 21, 2017 at 06:00:53PM +0200, Greg Kurz wrote:\n> On a server-class ppc host, this capability depends on the KVM type,\n> ie, HV or PR. If both KVM are present in the kernel, we will always\n> get the HV specific value, even if we explicitely requested PR on\n> the command line.\n> \n> This can have an impact if we're using hugepages or a balloon device.\n> \n> Since we've already created the VM at the time any user calls\n> kvm_has_sync_mmu(), switching to kvm_vm_check_extension() is\n> enough to fix any potential issue.\n> \n> It is okay for the other archs that also implement KVM_CAP_SYNC_MMU,\n> ie, mips, s390, x86 and arm, because they don't depend on the VM being\n> created or not.\n> \n> While here, let's cache the state of this extension in a bool variable,\n> since it has several users in the code, as suggested by Thomas Huth.\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    |    8 +++++---\n>  accel/stubs/kvm-stub.c |    4 ++--\n>  include/sysemu/kvm.h   |    2 +-\n>  3 files changed, 8 insertions(+), 6 deletions(-)\n> \n> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c\n> index b0181d722083..4d96c1fee9fe 100644\n> --- a/accel/kvm/kvm-all.c\n> +++ b/accel/kvm/kvm-all.c\n> @@ -87,6 +87,7 @@ struct KVMState\n>  #endif\n>      int many_ioeventfds;\n>      int intx_set_mask;\n> +    bool sync_mmu;\n>      /* The man page (and posix) say ioctl numbers are signed int, but\n>       * they're not.  Linux, glibc and *BSD all treat ioctl numbers as\n>       * unsigned, and treating them as signed here can break things */\n> @@ -1665,6 +1666,8 @@ static int kvm_init(MachineState *ms)\n>  \n>      s->many_ioeventfds = kvm_check_many_ioeventfds();\n>  \n> +    s->sync_mmu = !!kvm_vm_check_extension(kvm_state, KVM_CAP_SYNC_MMU);\n> +\n>      return 0;\n>  \n>  err:\n> @@ -2131,10 +2134,9 @@ int kvm_device_access(int fd, int group, uint64_t attr,\n>      return err;\n>  }\n>  \n> -/* Return 1 on success, 0 on failure */\n> -int kvm_has_sync_mmu(void)\n> +bool kvm_has_sync_mmu(void)\n>  {\n> -    return kvm_check_extension(kvm_state, KVM_CAP_SYNC_MMU);\n> +    return kvm_state->sync_mmu;\n>  }\n>  \n>  int kvm_has_vcpu_events(void)\n> diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c\n> index 3965c528d348..c964af3e1c97 100644\n> --- a/accel/stubs/kvm-stub.c\n> +++ b/accel/stubs/kvm-stub.c\n> @@ -64,9 +64,9 @@ int kvm_cpu_exec(CPUState *cpu)\n>      abort();\n>  }\n>  \n> -int kvm_has_sync_mmu(void)\n> +bool kvm_has_sync_mmu(void)\n>  {\n> -    return 0;\n> +    return false;\n>  }\n>  \n>  int kvm_has_many_ioeventfds(void)\n> diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h\n> index 3a458f50e9f4..bbf12a172339 100644\n> --- a/include/sysemu/kvm.h\n> +++ b/include/sysemu/kvm.h\n> @@ -207,7 +207,7 @@ extern KVMState *kvm_state;\n>  /* external API */\n>  \n>  bool kvm_has_free_slot(MachineState *ms);\n> -int kvm_has_sync_mmu(void);\n> +bool kvm_has_sync_mmu(void);\n>  int kvm_has_vcpu_events(void);\n>  int kvm_has_robust_singlestep(void);\n>  int kvm_has_debugregs(void);\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=\"j4UhJDqS\"; \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 3xz8sT1LZCz9sNw\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 22 Sep 2017 20:31:25 +1000 (AEST)","from localhost ([::1]:57853 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 1dvLEw-0004R1-Rs\n\tfor incoming@patchwork.ozlabs.org; Fri, 22 Sep 2017 06:31:23 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:56890)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <dgibson@ozlabs.org>) id 1dvLEQ-0004Qt-Jk\n\tfor qemu-devel@nongnu.org; Fri, 22 Sep 2017 06:30:51 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <dgibson@ozlabs.org>) id 1dvLEP-0004t2-Dr\n\tfor qemu-devel@nongnu.org; Fri, 22 Sep 2017 06:30:50 -0400","from ozlabs.org ([2401:3900:2:1::2]:39639)\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 1dvLEP-0004rE-1m; Fri, 22 Sep 2017 06:30:49 -0400","by ozlabs.org (Postfix, from userid 1007)\n\tid 3xz8rj16mBz9sNc; Fri, 22 Sep 2017 20:30:45 +1000 (AEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple;\n\td=gibson.dropbear.id.au; s=201602; t=1506076245;\n\tbh=gL6/iI39lZ6dOS3Ax5qWyJACxYc7zHiFUQe/o7xZGfY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=j4UhJDqSQlMYlPII2z8NR6s3x+AioZQZ+9ZrWEqWJvV0s31/ipI3fhWFcw2t7pnCT\n\tBk3BweBKFtUqd8JFeaymgegBYCWuhyQZ4f9qI88oUXLpSUDgCWObpbJ4VC46FVxqau\n\tn2pj73JOY01PkUsd4v9IAfd1JBR1QtSTnOoicbiE=","Date":"Fri, 22 Sep 2017 20:15:01 +1000","From":"David Gibson <david@gibson.dropbear.id.au>","To":"Greg Kurz <groug@kaod.org>","Message-ID":"<20170922101501.GI4998@umbus.fritz.box>","References":"<150600964184.30533.472565821627831467.stgit@bahia.lan>\n\t<150600965332.30533.14702405809647835716.stgit@bahia.lan>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"81JctsDUVPekGcy+\"","Content-Disposition":"inline","In-Reply-To":"<150600965332.30533.14702405809647835716.stgit@bahia.lan>","User-Agent":"Mutt/1.9.0 (2017-09-02)","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 v2 1/2] kvm: check KVM_CAP_SYNC_MMU 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","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>"}}]