62547e
From 95c229506a6e7261fce184488e880a94f9ba0789 Mon Sep 17 00:00:00 2001
62547e
From: Janosch Frank <frankja@linux.ibm.com>
62547e
Date: Mon, 17 Oct 2022 08:38:21 +0000
62547e
Subject: [PATCH 40/42] s390x: Add KVM PV dump interface
62547e
MIME-Version: 1.0
62547e
Content-Type: text/plain; charset=UTF-8
62547e
Content-Transfer-Encoding: 8bit
62547e
62547e
RH-Author: Cédric Le Goater <clg@redhat.com>
62547e
RH-MergeRequest: 226: s390: Enhanced Interpretation for PCI Functions and Secure Execution guest dump
62547e
RH-Bugzilla: 1664378 2043909
62547e
RH-Acked-by: Thomas Huth <thuth@redhat.com>
62547e
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
62547e
RH-Acked-by: Jon Maloy <jmaloy@redhat.com>
62547e
RH-Commit: [40/41] 5df512a63b2ed17991489565b70f89f4efc0b639
62547e
62547e
Let's add a few bits of code which hide the new KVM PV dump API from
62547e
us via new functions.
62547e
62547e
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
62547e
Reviewed-by: Janis Schoetterl-Glausch <scgl@linux.ibm.com>
62547e
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
62547e
[ Marc-André: fix up for compilation issue ]
62547e
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
62547e
Message-Id: <20221017083822.43118-10-frankja@linux.ibm.com>
62547e
(cherry picked from commit 753ca06f4706cd6e57750a606afb08c5c5299643)
62547e
Signed-off-by: Cédric Le Goater <clg@redhat.com>
62547e
---
62547e
 hw/s390x/pv.c         | 51 +++++++++++++++++++++++++++++++++++++++++++
62547e
 include/hw/s390x/pv.h |  9 ++++++++
62547e
 2 files changed, 60 insertions(+)
62547e
62547e
diff --git a/hw/s390x/pv.c b/hw/s390x/pv.c
62547e
index 4c012f2eeb..728ba24547 100644
62547e
--- a/hw/s390x/pv.c
62547e
+++ b/hw/s390x/pv.c
62547e
@@ -175,6 +175,57 @@ bool kvm_s390_pv_info_basic_valid(void)
62547e
     return info_valid;
62547e
 }
62547e
 
62547e
+static int s390_pv_dump_cmd(uint64_t subcmd, uint64_t uaddr, uint64_t gaddr,
62547e
+                            uint64_t len)
62547e
+{
62547e
+    struct kvm_s390_pv_dmp dmp = {
62547e
+        .subcmd = subcmd,
62547e
+        .buff_addr = uaddr,
62547e
+        .buff_len = len,
62547e
+        .gaddr = gaddr,
62547e
+    };
62547e
+    int ret;
62547e
+
62547e
+    ret = s390_pv_cmd(KVM_PV_DUMP, (void *)&dmp);
62547e
+    if (ret) {
62547e
+        error_report("KVM DUMP command %ld failed", subcmd);
62547e
+    }
62547e
+    return ret;
62547e
+}
62547e
+
62547e
+int kvm_s390_dump_cpu(S390CPU *cpu, void *buff)
62547e
+{
62547e
+    struct kvm_s390_pv_dmp dmp = {
62547e
+        .subcmd = KVM_PV_DUMP_CPU,
62547e
+        .buff_addr = (uint64_t)buff,
62547e
+        .gaddr = 0,
62547e
+        .buff_len = info_dump.dump_cpu_buffer_len,
62547e
+    };
62547e
+    struct kvm_pv_cmd pv = {
62547e
+        .cmd = KVM_PV_DUMP,
62547e
+        .data = (uint64_t)&dmp,
62547e
+    };
62547e
+
62547e
+    return kvm_vcpu_ioctl(CPU(cpu), KVM_S390_PV_CPU_COMMAND, &pv;;
62547e
+}
62547e
+
62547e
+int kvm_s390_dump_init(void)
62547e
+{
62547e
+    return s390_pv_dump_cmd(KVM_PV_DUMP_INIT, 0, 0, 0);
62547e
+}
62547e
+
62547e
+int kvm_s390_dump_mem_state(uint64_t gaddr, size_t len, void *dest)
62547e
+{
62547e
+    return s390_pv_dump_cmd(KVM_PV_DUMP_CONFIG_STOR_STATE, (uint64_t)dest,
62547e
+                            gaddr, len);
62547e
+}
62547e
+
62547e
+int kvm_s390_dump_completion_data(void *buff)
62547e
+{
62547e
+    return s390_pv_dump_cmd(KVM_PV_DUMP_COMPLETE, (uint64_t)buff, 0,
62547e
+                            info_dump.dump_config_finalize_len);
62547e
+}
62547e
+
62547e
 #define TYPE_S390_PV_GUEST "s390-pv-guest"
62547e
 OBJECT_DECLARE_SIMPLE_TYPE(S390PVGuest, S390_PV_GUEST)
62547e
 
62547e
diff --git a/include/hw/s390x/pv.h b/include/hw/s390x/pv.h
62547e
index e5ea0eca16..9360aa1091 100644
62547e
--- a/include/hw/s390x/pv.h
62547e
+++ b/include/hw/s390x/pv.h
62547e
@@ -51,6 +51,10 @@ uint64_t kvm_s390_pv_dmp_get_size_cpu(void);
62547e
 uint64_t kvm_s390_pv_dmp_get_size_mem_state(void);
62547e
 uint64_t kvm_s390_pv_dmp_get_size_completion_data(void);
62547e
 bool kvm_s390_pv_info_basic_valid(void);
62547e
+int kvm_s390_dump_init(void);
62547e
+int kvm_s390_dump_cpu(S390CPU *cpu, void *buff);
62547e
+int kvm_s390_dump_mem_state(uint64_t addr, size_t len, void *dest);
62547e
+int kvm_s390_dump_completion_data(void *buff);
62547e
 #else /* CONFIG_KVM */
62547e
 static inline bool s390_is_pv(void) { return false; }
62547e
 static inline int s390_pv_query_info(void) { return 0; }
62547e
@@ -66,6 +70,11 @@ static inline uint64_t kvm_s390_pv_dmp_get_size_cpu(void) { return 0; }
62547e
 static inline uint64_t kvm_s390_pv_dmp_get_size_mem_state(void) { return 0; }
62547e
 static inline uint64_t kvm_s390_pv_dmp_get_size_completion_data(void) { return 0; }
62547e
 static inline bool kvm_s390_pv_info_basic_valid(void) { return false; }
62547e
+static inline int kvm_s390_dump_init(void) { return 0; }
62547e
+static inline int kvm_s390_dump_cpu(S390CPU *cpu, void *buff) { return 0; }
62547e
+static inline int kvm_s390_dump_mem_state(uint64_t addr, size_t len,
62547e
+                                          void *dest) { return 0; }
62547e
+static inline int kvm_s390_dump_completion_data(void *buff) { return 0; }
62547e
 #endif /* CONFIG_KVM */
62547e
 
62547e
 int s390_pv_kvm_init(ConfidentialGuestSupport *cgs, Error **errp);
62547e
-- 
62547e
2.37.3
62547e