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