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