yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
902636
From ebcd74c2267d69fe09ca03cb8bfed7bef5ea3a85 Mon Sep 17 00:00:00 2001
902636
From: Thomas Huth <thuth@redhat.com>
902636
Date: Fri, 29 May 2020 05:54:08 -0400
902636
Subject: [PATCH 26/42] s390x: Add SIDA memory ops
902636
902636
RH-Author: Thomas Huth <thuth@redhat.com>
902636
Message-id: <20200529055420.16855-27-thuth@redhat.com>
902636
Patchwork-id: 97033
902636
O-Subject: [RHEL-8.3.0 qemu-kvm PATCH v2 26/38] s390x: Add SIDA memory ops
902636
Bugzilla: 1828317
902636
RH-Acked-by: Claudio Imbrenda <cimbrend@redhat.com>
902636
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
902636
RH-Acked-by: David Hildenbrand <david@redhat.com>
902636
902636
From: Janosch Frank <frankja@linux.ibm.com>
902636
902636
Protected guests save the instruction control blocks in the SIDA
902636
instead of QEMU/KVM directly accessing the guest's memory.
902636
902636
Let's introduce new functions to access the SIDA.
902636
902636
The memops for doing so are available with KVM_CAP_S390_PROTECTED, so
902636
let's check for that.
902636
902636
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
902636
Reviewed-by: David Hildenbrand <david@redhat.com>
902636
Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
902636
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
902636
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
902636
Message-Id: <20200319131921.2367-8-frankja@linux.ibm.com>
902636
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
902636
(cherry picked from commit 1cca8265499d394d9ed4bfb75bd6e7265b529f89)
902636
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
902636
---
902636
 target/s390x/cpu.h        |  7 ++++++-
902636
 target/s390x/kvm.c        | 26 ++++++++++++++++++++++++++
902636
 target/s390x/kvm_s390x.h  |  2 ++
902636
 target/s390x/mmu_helper.c | 14 ++++++++++++++
902636
 4 files changed, 48 insertions(+), 1 deletion(-)
902636
902636
diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h
902636
index 1ff84e6b3a..edf8391504 100644
902636
--- a/target/s390x/cpu.h
902636
+++ b/target/s390x/cpu.h
902636
@@ -828,7 +828,12 @@ int s390_cpu_virt_mem_rw(S390CPU *cpu, vaddr laddr, uint8_t ar, void *hostbuf,
902636
 #define s390_cpu_virt_mem_check_write(cpu, laddr, ar, len)   \
902636
         s390_cpu_virt_mem_rw(cpu, laddr, ar, NULL, len, true)
902636
 void s390_cpu_virt_mem_handle_exc(S390CPU *cpu, uintptr_t ra);
902636
-
902636
+int s390_cpu_pv_mem_rw(S390CPU *cpu, unsigned int offset, void *hostbuf,
902636
+                       int len, bool is_write);
902636
+#define s390_cpu_pv_mem_read(cpu, offset, dest, len)    \
902636
+        s390_cpu_pv_mem_rw(cpu, offset, dest, len, false)
902636
+#define s390_cpu_pv_mem_write(cpu, offset, dest, len)       \
902636
+        s390_cpu_pv_mem_rw(cpu, offset, dest, len, true)
902636
 
902636
 /* sigp.c */
902636
 int s390_cpu_restart(S390CPU *cpu);
902636
diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
902636
index af50b2c253..f67bb5ce2c 100644
902636
--- a/target/s390x/kvm.c
902636
+++ b/target/s390x/kvm.c
902636
@@ -154,6 +154,7 @@ static int cap_ri;
902636
 static int cap_gs;
902636
 static int cap_hpage_1m;
902636
 static int cap_vcpu_resets;
902636
+static int cap_protected;
902636
 
902636
 static int active_cmma;
902636
 
902636
@@ -351,6 +352,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
902636
     cap_mem_op = kvm_check_extension(s, KVM_CAP_S390_MEM_OP);
902636
     cap_s390_irq = kvm_check_extension(s, KVM_CAP_S390_INJECT_IRQ);
902636
     cap_vcpu_resets = kvm_check_extension(s, KVM_CAP_S390_VCPU_RESETS);
902636
+    cap_protected = kvm_check_extension(s, KVM_CAP_S390_PROTECTED);
902636
 
902636
     if (!kvm_check_extension(s, KVM_CAP_S390_GMAP)
902636
         || !kvm_check_extension(s, KVM_CAP_S390_COW)) {
902636
@@ -848,6 +850,30 @@ int kvm_s390_mem_op(S390CPU *cpu, vaddr addr, uint8_t ar, void *hostbuf,
902636
     return ret;
902636
 }
902636
 
902636
+int kvm_s390_mem_op_pv(S390CPU *cpu, uint64_t offset, void *hostbuf,
902636
+                       int len, bool is_write)
902636
+{
902636
+    struct kvm_s390_mem_op mem_op = {
902636
+        .sida_offset = offset,
902636
+        .size = len,
902636
+        .op = is_write ? KVM_S390_MEMOP_SIDA_WRITE
902636
+                       : KVM_S390_MEMOP_SIDA_READ,
902636
+        .buf = (uint64_t)hostbuf,
902636
+    };
902636
+    int ret;
902636
+
902636
+    if (!cap_mem_op || !cap_protected) {
902636
+        return -ENOSYS;
902636
+    }
902636
+
902636
+    ret = kvm_vcpu_ioctl(CPU(cpu), KVM_S390_MEM_OP, &mem_op);
902636
+    if (ret < 0) {
902636
+        error_report("KVM_S390_MEM_OP failed: %s", strerror(-ret));
902636
+        abort();
902636
+    }
902636
+    return ret;
902636
+}
902636
+
902636
 /*
902636
  * Legacy layout for s390:
902636
  * Older S390 KVM requires the topmost vma of the RAM to be
902636
diff --git a/target/s390x/kvm_s390x.h b/target/s390x/kvm_s390x.h
902636
index dea813f450..6ab17c81b7 100644
902636
--- a/target/s390x/kvm_s390x.h
902636
+++ b/target/s390x/kvm_s390x.h
902636
@@ -19,6 +19,8 @@ void kvm_s390_vcpu_interrupt(S390CPU *cpu, struct kvm_s390_irq *irq);
902636
 void kvm_s390_access_exception(S390CPU *cpu, uint16_t code, uint64_t te_code);
902636
 int kvm_s390_mem_op(S390CPU *cpu, vaddr addr, uint8_t ar, void *hostbuf,
902636
                     int len, bool is_write);
902636
+int kvm_s390_mem_op_pv(S390CPU *cpu, vaddr addr, void *hostbuf, int len,
902636
+                       bool is_write);
902636
 void kvm_s390_program_interrupt(S390CPU *cpu, uint16_t code);
902636
 int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state);
902636
 void kvm_s390_vcpu_interrupt_pre_save(S390CPU *cpu);
902636
diff --git a/target/s390x/mmu_helper.c b/target/s390x/mmu_helper.c
902636
index c9f3f34750..ec8befbdc8 100644
902636
--- a/target/s390x/mmu_helper.c
902636
+++ b/target/s390x/mmu_helper.c
902636
@@ -474,6 +474,20 @@ static int translate_pages(S390CPU *cpu, vaddr addr, int nr_pages,
902636
     return 0;
902636
 }
902636
 
902636
+int s390_cpu_pv_mem_rw(S390CPU *cpu, unsigned int offset, void *hostbuf,
902636
+                       int len, bool is_write)
902636
+{
902636
+    int ret;
902636
+
902636
+    if (kvm_enabled()) {
902636
+        ret = kvm_s390_mem_op_pv(cpu, offset, hostbuf, len, is_write);
902636
+    } else {
902636
+        /* Protected Virtualization is a KVM/Hardware only feature */
902636
+        g_assert_not_reached();
902636
+    }
902636
+    return ret;
902636
+}
902636
+
902636
 /**
902636
  * s390_cpu_virt_mem_rw:
902636
  * @laddr:     the logical start address
902636
-- 
902636
2.27.0
902636