bf143f
From 760236b3633a8f532631256a899cab969e772196 Mon Sep 17 00:00:00 2001
bf143f
From: Janosch Frank <frankja@linux.ibm.com>
bf143f
Date: Mon, 17 Oct 2022 08:38:19 +0000
bf143f
Subject: [PATCH 38/42] s390x: Introduce PV query interface
bf143f
MIME-Version: 1.0
bf143f
Content-Type: text/plain; charset=UTF-8
bf143f
Content-Transfer-Encoding: 8bit
bf143f
bf143f
RH-Author: Cédric Le Goater <clg@redhat.com>
bf143f
RH-MergeRequest: 226: s390: Enhanced Interpretation for PCI Functions and Secure Execution guest dump
bf143f
RH-Bugzilla: 1664378 2043909
bf143f
RH-Acked-by: Thomas Huth <thuth@redhat.com>
bf143f
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
bf143f
RH-Acked-by: Jon Maloy <jmaloy@redhat.com>
bf143f
RH-Commit: [38/41] 3090615d81ec6b9e4c306f7fc3709e1935ff5a79
bf143f
bf143f
Introduce an interface over which we can get information about UV data.
bf143f
bf143f
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
bf143f
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
bf143f
Reviewed-by: Janis Schoetterl-Glausch <scgl@linux.ibm.com>
bf143f
Acked-by: Thomas Huth <thuth@redhat.com>
bf143f
Message-Id: <20221017083822.43118-8-frankja@linux.ibm.com>
bf143f
(cherry picked from commit 03d83ecfae46bf5e0074cb5808043b30df34064b)
bf143f
Signed-off-by: Cédric Le Goater <clg@redhat.com>
bf143f
---
bf143f
 hw/s390x/pv.c              | 61 ++++++++++++++++++++++++++++++++++++++
bf143f
 hw/s390x/s390-virtio-ccw.c |  6 ++++
bf143f
 include/hw/s390x/pv.h      | 10 +++++++
bf143f
 3 files changed, 77 insertions(+)
bf143f
bf143f
diff --git a/hw/s390x/pv.c b/hw/s390x/pv.c
bf143f
index 401b63d6cb..4c012f2eeb 100644
bf143f
--- a/hw/s390x/pv.c
bf143f
+++ b/hw/s390x/pv.c
bf143f
@@ -20,6 +20,11 @@
bf143f
 #include "exec/confidential-guest-support.h"
bf143f
 #include "hw/s390x/ipl.h"
bf143f
 #include "hw/s390x/pv.h"
bf143f
+#include "target/s390x/kvm/kvm_s390x.h"
bf143f
+
bf143f
+static bool info_valid;
bf143f
+static struct kvm_s390_pv_info_vm info_vm;
bf143f
+static struct kvm_s390_pv_info_dump info_dump;
bf143f
 
bf143f
 static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data)
bf143f
 {
bf143f
@@ -56,6 +61,42 @@ static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data)
bf143f
     }                                  \
bf143f
 }
bf143f
 
bf143f
+int s390_pv_query_info(void)
bf143f
+{
bf143f
+    struct kvm_s390_pv_info info = {
bf143f
+        .header.id = KVM_PV_INFO_VM,
bf143f
+        .header.len_max = sizeof(info.header) + sizeof(info.vm),
bf143f
+    };
bf143f
+    int rc;
bf143f
+
bf143f
+    /* Info API's first user is dump so they are bundled */
bf143f
+    if (!kvm_s390_get_protected_dump()) {
bf143f
+        return 0;
bf143f
+    }
bf143f
+
bf143f
+    rc = s390_pv_cmd(KVM_PV_INFO, &info;;
bf143f
+    if (rc) {
bf143f
+        error_report("KVM PV INFO cmd %x failed: %s",
bf143f
+                     info.header.id, strerror(-rc));
bf143f
+        return rc;
bf143f
+    }
bf143f
+    memcpy(&info_vm, &info.vm, sizeof(info.vm));
bf143f
+
bf143f
+    info.header.id = KVM_PV_INFO_DUMP;
bf143f
+    info.header.len_max = sizeof(info.header) + sizeof(info.dump);
bf143f
+    rc = s390_pv_cmd(KVM_PV_INFO, &info;;
bf143f
+    if (rc) {
bf143f
+        error_report("KVM PV INFO cmd %x failed: %s",
bf143f
+                     info.header.id, strerror(-rc));
bf143f
+        return rc;
bf143f
+    }
bf143f
+
bf143f
+    memcpy(&info_dump, &info.dump, sizeof(info.dump));
bf143f
+    info_valid = true;
bf143f
+
bf143f
+    return rc;
bf143f
+}
bf143f
+
bf143f
 int s390_pv_vm_enable(void)
bf143f
 {
bf143f
     return s390_pv_cmd(KVM_PV_ENABLE, NULL);
bf143f
@@ -114,6 +155,26 @@ void s390_pv_inject_reset_error(CPUState *cs)
bf143f
     env->regs[r1 + 1] = DIAG_308_RC_INVAL_FOR_PV;
bf143f
 }
bf143f
 
bf143f
+uint64_t kvm_s390_pv_dmp_get_size_cpu(void)
bf143f
+{
bf143f
+    return info_dump.dump_cpu_buffer_len;
bf143f
+}
bf143f
+
bf143f
+uint64_t kvm_s390_pv_dmp_get_size_completion_data(void)
bf143f
+{
bf143f
+    return info_dump.dump_config_finalize_len;
bf143f
+}
bf143f
+
bf143f
+uint64_t kvm_s390_pv_dmp_get_size_mem_state(void)
bf143f
+{
bf143f
+    return info_dump.dump_config_mem_buffer_per_1m;
bf143f
+}
bf143f
+
bf143f
+bool kvm_s390_pv_info_basic_valid(void)
bf143f
+{
bf143f
+    return info_valid;
bf143f
+}
bf143f
+
bf143f
 #define TYPE_S390_PV_GUEST "s390-pv-guest"
bf143f
 OBJECT_DECLARE_SIMPLE_TYPE(S390PVGuest, S390_PV_GUEST)
bf143f
 
bf143f
diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
bf143f
index bd80e72cf8..a9617ab79f 100644
bf143f
--- a/hw/s390x/s390-virtio-ccw.c
bf143f
+++ b/hw/s390x/s390-virtio-ccw.c
bf143f
@@ -365,6 +365,12 @@ static int s390_machine_protect(S390CcwMachineState *ms)
bf143f
 
bf143f
     ms->pv = true;
bf143f
 
bf143f
+    /* Will return 0 if API is not available since it's not vital */
bf143f
+    rc = s390_pv_query_info();
bf143f
+    if (rc) {
bf143f
+        goto out_err;
bf143f
+    }
bf143f
+
bf143f
     /* Set SE header and unpack */
bf143f
     rc = s390_ipl_prepare_pv_header();
bf143f
     if (rc) {
bf143f
diff --git a/include/hw/s390x/pv.h b/include/hw/s390x/pv.h
bf143f
index 1f1f545bfc..e5ea0eca16 100644
bf143f
--- a/include/hw/s390x/pv.h
bf143f
+++ b/include/hw/s390x/pv.h
bf143f
@@ -38,6 +38,7 @@ static inline bool s390_is_pv(void)
bf143f
     return ccw->pv;
bf143f
 }
bf143f
 
bf143f
+int s390_pv_query_info(void);
bf143f
 int s390_pv_vm_enable(void);
bf143f
 void s390_pv_vm_disable(void);
bf143f
 int s390_pv_set_sec_parms(uint64_t origin, uint64_t length);
bf143f
@@ -46,8 +47,13 @@ void s390_pv_prep_reset(void);
bf143f
 int s390_pv_verify(void);
bf143f
 void s390_pv_unshare(void);
bf143f
 void s390_pv_inject_reset_error(CPUState *cs);
bf143f
+uint64_t kvm_s390_pv_dmp_get_size_cpu(void);
bf143f
+uint64_t kvm_s390_pv_dmp_get_size_mem_state(void);
bf143f
+uint64_t kvm_s390_pv_dmp_get_size_completion_data(void);
bf143f
+bool kvm_s390_pv_info_basic_valid(void);
bf143f
 #else /* CONFIG_KVM */
bf143f
 static inline bool s390_is_pv(void) { return false; }
bf143f
+static inline int s390_pv_query_info(void) { return 0; }
bf143f
 static inline int s390_pv_vm_enable(void) { return 0; }
bf143f
 static inline void s390_pv_vm_disable(void) {}
bf143f
 static inline int s390_pv_set_sec_parms(uint64_t origin, uint64_t length) { return 0; }
bf143f
@@ -56,6 +62,10 @@ static inline void s390_pv_prep_reset(void) {}
bf143f
 static inline int s390_pv_verify(void) { return 0; }
bf143f
 static inline void s390_pv_unshare(void) {}
bf143f
 static inline void s390_pv_inject_reset_error(CPUState *cs) {};
bf143f
+static inline uint64_t kvm_s390_pv_dmp_get_size_cpu(void) { return 0; }
bf143f
+static inline uint64_t kvm_s390_pv_dmp_get_size_mem_state(void) { return 0; }
bf143f
+static inline uint64_t kvm_s390_pv_dmp_get_size_completion_data(void) { return 0; }
bf143f
+static inline bool kvm_s390_pv_info_basic_valid(void) { return false; }
bf143f
 #endif /* CONFIG_KVM */
bf143f
 
bf143f
 int s390_pv_kvm_init(ConfidentialGuestSupport *cgs, Error **errp);
bf143f
-- 
bf143f
2.37.3
bf143f