yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-s390x-Enable-KVM-huge-page-backing-support.patch

26ba25
From c9ff4b704e6be10e4309b5cdb8c2d3e7fc0d3d0f Mon Sep 17 00:00:00 2001
26ba25
From: David Hildenbrand <david@redhat.com>
26ba25
Date: Mon, 6 Aug 2018 14:18:41 +0100
26ba25
Subject: [PATCH 2/3] s390x: Enable KVM huge page backing support
26ba25
26ba25
RH-Author: David Hildenbrand <david@redhat.com>
26ba25
Message-id: <20180806141842.23963-3-david@redhat.com>
26ba25
Patchwork-id: 81645
26ba25
O-Subject: [RHEL-8.0 qemu-kvm PATCH v2 2/3] s390x: Enable KVM huge page backing support
26ba25
Bugzilla: 1610906
26ba25
RH-Acked-by: Thomas Huth <thuth@redhat.com>
26ba25
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
26ba25
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
26ba25
26ba25
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1610906
26ba25
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=17624600
26ba25
Upstream: N/A
26ba25
26ba25
Kernel part is in kvm/next, scheduled for 4.19. Patch has been reviewed
26ba25
upstream but cannot get picked up yet due to the outstanding linux
26ba25
header sync. Conflict to upstream patch: We have no units.h, therefore
26ba25
we have to unfold "4*KiB" and "1*MiB".
26ba25
26ba25
QEMU has had huge page support for a longer time already, but KVM
26ba25
memory management under s390x needed some changes to work with huge
26ba25
backings.
26ba25
26ba25
Now that we have support, let's enable it if requested and
26ba25
available. Otherwise we now properly tell the user if there is no
26ba25
support and back out instead of failing to run the VM later on.
26ba25
26ba25
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
26ba25
Reviewed-by: David Hildenbrand <david@redhat.com>
26ba25
Reviewed-by: Thomas Huth <thuth@redhat.com>
26ba25
Signed-off-by: David Hildenbrand <david@redhat.com>
26ba25
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
26ba25
---
26ba25
 target/s390x/kvm.c | 34 ++++++++++++++++++++++++++++++++--
26ba25
 1 file changed, 32 insertions(+), 2 deletions(-)
26ba25
26ba25
diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
26ba25
index fbccceb..3474310a9 100644
26ba25
--- a/target/s390x/kvm.c
26ba25
+++ b/target/s390x/kvm.c
26ba25
@@ -34,6 +34,7 @@
26ba25
 #include "qapi/error.h"
26ba25
 #include "qemu/error-report.h"
26ba25
 #include "qemu/timer.h"
26ba25
+#include "qemu/mmap-alloc.h"
26ba25
 #include "sysemu/sysemu.h"
26ba25
 #include "sysemu/hw_accel.h"
26ba25
 #include "hw/hw.h"
26ba25
@@ -140,6 +141,7 @@ static int cap_mem_op;
26ba25
 static int cap_s390_irq;
26ba25
 static int cap_ri;
26ba25
 static int cap_gs;
26ba25
+static int cap_hpage_1m;
26ba25
 
26ba25
 static int active_cmma;
26ba25
 
26ba25
@@ -221,9 +223,9 @@ static void kvm_s390_enable_cmma(void)
26ba25
         .attr = KVM_S390_VM_MEM_ENABLE_CMMA,
26ba25
     };
26ba25
 
26ba25
-    if (mem_path) {
26ba25
+    if (cap_hpage_1m) {
26ba25
         warn_report("CMM will not be enabled because it is not "
26ba25
-                    "compatible with hugetlbfs.");
26ba25
+                    "compatible with huge memory backings.");
26ba25
         return;
26ba25
     }
26ba25
     rc = kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
26ba25
@@ -282,10 +284,38 @@ void kvm_s390_crypto_reset(void)
26ba25
     }
26ba25
 }
26ba25
 
26ba25
+static int kvm_s390_configure_mempath_backing(KVMState *s)
26ba25
+{
26ba25
+    size_t path_psize = qemu_mempath_getpagesize(mem_path);
26ba25
+
26ba25
+    if (path_psize == 4 * 1024) {
26ba25
+        return 0;
26ba25
+    }
26ba25
+
26ba25
+    if (path_psize != 1024 * 1024) {
26ba25
+        error_report("Memory backing with 2G pages was specified, "
26ba25
+                     "but KVM does not support this memory backing");
26ba25
+        return -EINVAL;
26ba25
+    }
26ba25
+
26ba25
+    if (kvm_vm_enable_cap(s, KVM_CAP_S390_HPAGE_1M, 0)) {
26ba25
+        error_report("Memory backing with 1M pages was specified, "
26ba25
+                     "but KVM does not support this memory backing");
26ba25
+        return -EINVAL;
26ba25
+    }
26ba25
+
26ba25
+    cap_hpage_1m = 1;
26ba25
+    return 0;
26ba25
+}
26ba25
+
26ba25
 int kvm_arch_init(MachineState *ms, KVMState *s)
26ba25
 {
26ba25
     MachineClass *mc = MACHINE_GET_CLASS(ms);
26ba25
 
26ba25
+    if (mem_path && kvm_s390_configure_mempath_backing(s)) {
26ba25
+        return -EINVAL;
26ba25
+    }
26ba25
+
26ba25
     mc->default_cpu_type = S390_CPU_TYPE_NAME("host");
26ba25
     cap_sync_regs = kvm_check_extension(s, KVM_CAP_SYNC_REGS);
26ba25
     cap_async_pf = kvm_check_extension(s, KVM_CAP_ASYNC_PF);
26ba25
-- 
26ba25
1.8.3.1
26ba25