Blame SOURCES/kvm-check-KVM_CAP_SYNC_MMU-with-kvm_vm_check_extensi.patch

9ae3a8
From 53c0d0dcad838ef8b9b0faf0c8066d47380f2cf1 Mon Sep 17 00:00:00 2001
9ae3a8
From: Alex Williamson <alex.williamson@redhat.com>
9ae3a8
Date: Thu, 13 Dec 2018 21:55:04 +0100
9ae3a8
Subject: [PATCH 3/5] kvm: check KVM_CAP_SYNC_MMU with kvm_vm_check_extension()
9ae3a8
9ae3a8
RH-Author: Alex Williamson <alex.williamson@redhat.com>
9ae3a8
Message-id: <154473810399.22725.17809569801460658619.stgit@gimli.home>
9ae3a8
Patchwork-id: 83495
9ae3a8
O-Subject: [RHEL-7.7 qemu-kvm PATCH 3/5] kvm: check KVM_CAP_SYNC_MMU with kvm_vm_check_extension()
9ae3a8
Bugzilla: 1659229
9ae3a8
RH-Acked-by: Peter Xu <peterx@redhat.com>
9ae3a8
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
9ae3a8
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
9ae3a8
9ae3a8
From: Greg Kurz <groug@kaod.org>
9ae3a8
9ae3a8
Bugzilla: 1659229
9ae3a8
Notes: We don't have kvm_vm_check_extension() but we can still
9ae3a8
       cache the result, which gives us the same hook to trigger
9ae3a8
       the balloon inhibitor here.
9ae3a8
9ae3a8
On a server-class ppc host, this capability depends on the KVM type,
9ae3a8
ie, HV or PR. If both KVM are present in the kernel, we will always
9ae3a8
get the HV specific value, even if we explicitely requested PR on
9ae3a8
the command line.
9ae3a8
9ae3a8
This can have an impact if we're using hugepages or a balloon device.
9ae3a8
9ae3a8
Since we've already created the VM at the time any user calls
9ae3a8
kvm_has_sync_mmu(), switching to kvm_vm_check_extension() is
9ae3a8
enough to fix any potential issue.
9ae3a8
9ae3a8
It is okay for the other archs that also implement KVM_CAP_SYNC_MMU,
9ae3a8
ie, mips, s390, x86 and arm, because they don't depend on the VM being
9ae3a8
created or not.
9ae3a8
9ae3a8
While here, let's cache the state of this extension in a bool variable,
9ae3a8
since it has several users in the code, as suggested by Thomas Huth.
9ae3a8
9ae3a8
Signed-off-by: Greg Kurz <groug@kaod.org>
9ae3a8
Message-Id: <150600965332.30533.14702405809647835716.stgit@bahia.lan>
9ae3a8
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
9ae3a8
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
(cherry picked from commit 62dd4edaaf859b60f74a51f2a526d4d3d85d0248)
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 include/sysemu/kvm.h | 2 +-
9ae3a8
 kvm-all.c            | 7 +++++--
9ae3a8
 kvm-stub.c           | 4 ++--
9ae3a8
 3 files changed, 8 insertions(+), 5 deletions(-)
9ae3a8
9ae3a8
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
9ae3a8
index 49cfc42..e4403be 100644
9ae3a8
--- a/include/sysemu/kvm.h
9ae3a8
+++ b/include/sysemu/kvm.h
9ae3a8
@@ -135,7 +135,7 @@ extern KVMState *kvm_state;
9ae3a8
 
9ae3a8
 int kvm_init(void);
9ae3a8
 
9ae3a8
-int kvm_has_sync_mmu(void);
9ae3a8
+bool kvm_has_sync_mmu(void);
9ae3a8
 int kvm_has_vcpu_events(void);
9ae3a8
 int kvm_has_robust_singlestep(void);
9ae3a8
 int kvm_has_debugregs(void);
9ae3a8
diff --git a/kvm-all.c b/kvm-all.c
9ae3a8
index 9486b9a..f5b7958 100644
9ae3a8
--- a/kvm-all.c
9ae3a8
+++ b/kvm-all.c
9ae3a8
@@ -92,6 +92,7 @@ struct KVMState
9ae3a8
     int xsave, xcrs;
9ae3a8
     int many_ioeventfds;
9ae3a8
     int intx_set_mask;
9ae3a8
+    bool sync_mmu;
9ae3a8
     /* The man page (and posix) say ioctl numbers are signed int, but
9ae3a8
      * they're not.  Linux, glibc and *BSD all treat ioctl numbers as
9ae3a8
      * unsigned, and treating them as signed here can break things */
9ae3a8
@@ -1479,6 +1480,8 @@ int kvm_init(void)
9ae3a8
 
9ae3a8
     cpu_interrupt_handler = kvm_handle_interrupt;
9ae3a8
 
9ae3a8
+    s->sync_mmu = !!kvm_check_extension(kvm_state, KVM_CAP_SYNC_MMU);
9ae3a8
+
9ae3a8
     return 0;
9ae3a8
 
9ae3a8
 err:
9ae3a8
@@ -1775,9 +1778,9 @@ int kvm_vcpu_ioctl(CPUState *cpu, int type, ...)
9ae3a8
     return ret;
9ae3a8
 }
9ae3a8
 
9ae3a8
-int kvm_has_sync_mmu(void)
9ae3a8
+bool kvm_has_sync_mmu(void)
9ae3a8
 {
9ae3a8
-    return kvm_check_extension(kvm_state, KVM_CAP_SYNC_MMU);
9ae3a8
+    return kvm_state->sync_mmu;
9ae3a8
 }
9ae3a8
 
9ae3a8
 int kvm_has_vcpu_events(void)
9ae3a8
diff --git a/kvm-stub.c b/kvm-stub.c
9ae3a8
index 22eaff0..ca6ddd7 100644
9ae3a8
--- a/kvm-stub.c
9ae3a8
+++ b/kvm-stub.c
9ae3a8
@@ -59,9 +59,9 @@ int kvm_cpu_exec(CPUArchState *env)
9ae3a8
     abort ();
9ae3a8
 }
9ae3a8
 
9ae3a8
-int kvm_has_sync_mmu(void)
9ae3a8
+bool kvm_has_sync_mmu(void)
9ae3a8
 {
9ae3a8
-    return 0;
9ae3a8
+    return false;
9ae3a8
 }
9ae3a8
 
9ae3a8
 int kvm_has_many_ioeventfds(void)
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8