qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] DIAG 308: extend subcode 10 to return UVC cmd id, RC and RRC values upon failure to enter secure mode
@ 2025-04-14 15:48 Gautam Gala
  2025-04-14 15:48 ` [PATCH v2 1/3] target/s390x: Introduce constant when checking if PV header couldn't be decrypted Gautam Gala
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Gautam Gala @ 2025-04-14 15:48 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel; +Cc: Christian Borntraeger, Thomas Huth, seiden

DIAG 308 (subcode 10 - performing secure execution unpack) response
code when the configuration is unable to enter secure mode has limited
usability as it is a fixed value (0xa02) for variety of different
reasons. The aim is to extend this DIAG to return UVC command ID, RC
and RRC values in addition to the diag response code. This feature can
be used by the stage3a bootloader (s390-tools/rust/pvimg/boot) to read
these new values from the corresponding register and print an
appropriate error message to help pin point the cause.

The response code, UVC RC, RRC, and command ID are returned in bit
positions 48-63, 32-47, 16-31, and 0-15 of register R1 + 1 if the
function does not complete successfully (Previously, only the
response code was returned in bits 48-63).

These patches contains updates based on feedback from Steffen Eiden
from message-ID <20250414133845.61624-D-seiden@linux.ibm.com> and
<20250414140340.61624-E-seiden@linux.ibm.com>

Gautam Gala (3):
  target/s390x: Introduce constant when checking if PV header couldn't
    be decrypted
  target/s390x: introduce function when exiting PV
  target/s390x: Return UVC cmd code, RC and RRC value when DIAG 308
    Subcode 10 fails to enter secure mode

 hw/s390x/ipl.c             | 11 ++++---
 hw/s390x/ipl.h             |  5 ++--
 hw/s390x/s390-virtio-ccw.c | 24 ++++++++++++----
 target/s390x/kvm/pv.c      | 59 +++++++++++++++++++++++---------------
 target/s390x/kvm/pv.h      | 27 +++++++++++------
 5 files changed, 83 insertions(+), 43 deletions(-)

-- 
2.49.0



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/3] target/s390x: Introduce constant when checking if PV header couldn't be decrypted
  2025-04-14 15:48 [PATCH v2 0/3] DIAG 308: extend subcode 10 to return UVC cmd id, RC and RRC values upon failure to enter secure mode Gautam Gala
@ 2025-04-14 15:48 ` Gautam Gala
  2025-04-14 15:48 ` [PATCH v2 2/3] target/s390x: introduce function when exiting PV Gautam Gala
  2025-04-14 15:48 ` [PATCH v2 3/3] target/s390x: Return UVC cmd code, RC and RRC value when DIAG 308 Subcode 10 fails to enter secure mode Gautam Gala
  2 siblings, 0 replies; 9+ messages in thread
From: Gautam Gala @ 2025-04-14 15:48 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel; +Cc: Christian Borntraeger, Thomas Huth, seiden

Introduce a named constant when checking the Set Secure Configuration parameters
UV call return code for the case where no valid host key was found and therefore
the PV header couldn't be decrypted (0x108).

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Gautam Gala <ggala@linux.ibm.com>
---
 target/s390x/kvm/pv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/target/s390x/kvm/pv.c b/target/s390x/kvm/pv.c
index b191a4a68a..3a0a971f0b 100644
--- a/target/s390x/kvm/pv.c
+++ b/target/s390x/kvm/pv.c
@@ -147,6 +147,7 @@ bool s390_pv_vm_try_disable_async(S390CcwMachineState *ms)
     return true;
 }
 
+#define DIAG_308_UV_RC_INVAL_HOSTKEY    0x0108
 int s390_pv_set_sec_parms(uint64_t origin, uint64_t length, Error **errp)
 {
     int ret, pvrc;
@@ -158,7 +159,7 @@ int s390_pv_set_sec_parms(uint64_t origin, uint64_t length, Error **errp)
     ret = s390_pv_cmd_pvrc(KVM_PV_SET_SEC_PARMS, &args, &pvrc);
     if (ret) {
         error_setg(errp, "Failed to set secure execution parameters");
-        if (pvrc == 0x108) {
+        if (pvrc == DIAG_308_UV_RC_INVAL_HOSTKEY) {
             error_append_hint(errp, "Please check whether the image is "
                                     "correctly encrypted for this host\n");
         }
-- 
2.49.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/3] target/s390x: introduce function when exiting PV
  2025-04-14 15:48 [PATCH v2 0/3] DIAG 308: extend subcode 10 to return UVC cmd id, RC and RRC values upon failure to enter secure mode Gautam Gala
  2025-04-14 15:48 ` [PATCH v2 1/3] target/s390x: Introduce constant when checking if PV header couldn't be decrypted Gautam Gala
@ 2025-04-14 15:48 ` Gautam Gala
  2025-04-15  9:07   ` Steffen Eiden
  2025-04-15  9:44   ` Thomas Huth
  2025-04-14 15:48 ` [PATCH v2 3/3] target/s390x: Return UVC cmd code, RC and RRC value when DIAG 308 Subcode 10 fails to enter secure mode Gautam Gala
  2 siblings, 2 replies; 9+ messages in thread
From: Gautam Gala @ 2025-04-14 15:48 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel; +Cc: Christian Borntraeger, Thomas Huth, seiden

introduce a static function when exiting PV. The function replaces an
existing macro (s390_pv_cmd_exit).

Signed-off-by: Gautam Gala <ggala@linux.ibm.com>
---
 target/s390x/kvm/pv.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/target/s390x/kvm/pv.c b/target/s390x/kvm/pv.c
index 3a0a971f0b..66194caaae 100644
--- a/target/s390x/kvm/pv.c
+++ b/target/s390x/kvm/pv.c
@@ -59,14 +59,12 @@ static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data,
  */
 #define s390_pv_cmd(cmd, data) __s390_pv_cmd(cmd, #cmd, data, NULL)
 #define s390_pv_cmd_pvrc(cmd, data, pvrc) __s390_pv_cmd(cmd, #cmd, data, pvrc)
-#define s390_pv_cmd_exit(cmd, data)    \
-{                                      \
-    int rc;                            \
-                                       \
-    rc = __s390_pv_cmd(cmd, #cmd, data, NULL); \
-    if (rc) {                          \
-        exit(1);                       \
-    }                                  \
+
+static void s390_pv_cmd_exit(uint32_t cmd, void *data)
+{
+    if (s390_pv_cmd(cmd, data)) {
+        exit(1);
+    }
 }
 
 int s390_pv_query_info(void)
-- 
2.49.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 3/3] target/s390x: Return UVC cmd code, RC and RRC value when DIAG 308 Subcode 10 fails to enter secure mode
  2025-04-14 15:48 [PATCH v2 0/3] DIAG 308: extend subcode 10 to return UVC cmd id, RC and RRC values upon failure to enter secure mode Gautam Gala
  2025-04-14 15:48 ` [PATCH v2 1/3] target/s390x: Introduce constant when checking if PV header couldn't be decrypted Gautam Gala
  2025-04-14 15:48 ` [PATCH v2 2/3] target/s390x: introduce function when exiting PV Gautam Gala
@ 2025-04-14 15:48 ` Gautam Gala
  2025-04-15  9:59   ` Thomas Huth
  2 siblings, 1 reply; 9+ messages in thread
From: Gautam Gala @ 2025-04-14 15:48 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel; +Cc: Christian Borntraeger, Thomas Huth, seiden

Extend DIAG308 subcode 10 to return the UVC RC, RRC and command code
in bit positions 32-47, 16-31, and 0-15 of register R1 + 1 if the
function does not complete successfully (in addition to the
previously returned diag response code in bit position 47-63).

Signed-off-by: Gautam Gala <ggala@linux.ibm.com>
---
 hw/s390x/ipl.c             | 11 ++++++----
 hw/s390x/ipl.h             |  5 +++--
 hw/s390x/s390-virtio-ccw.c | 24 +++++++++++++++------
 target/s390x/kvm/pv.c      | 44 +++++++++++++++++++++++++-------------
 target/s390x/kvm/pv.h      | 27 ++++++++++++++++-------
 5 files changed, 76 insertions(+), 35 deletions(-)

diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c
index ce6f6078d7..09adc8b72e 100644
--- a/hw/s390x/ipl.c
+++ b/hw/s390x/ipl.c
@@ -676,7 +676,8 @@ static void s390_ipl_prepare_qipl(S390CPU *cpu)
     cpu_physical_memory_unmap(addr, len, 1, len);
 }
 
-int s390_ipl_prepare_pv_header(Error **errp)
+int s390_ipl_prepare_pv_header(uint16_t *pv_cmd, uint16_t *pv_rc,
+                               uint16_t *pv_rrc, Error **errp)
 {
     IplParameterBlock *ipib = s390_ipl_get_iplb_pv();
     IPLBlockPV *ipib_pv = &ipib->pv;
@@ -685,12 +686,13 @@ int s390_ipl_prepare_pv_header(Error **errp)
 
     cpu_physical_memory_read(ipib_pv->pv_header_addr, hdr,
                              ipib_pv->pv_header_len);
-    rc = s390_pv_set_sec_parms((uintptr_t)hdr, ipib_pv->pv_header_len, errp);
+    rc = s390_pv_set_sec_parms((uintptr_t)hdr, ipib_pv->pv_header_len,
+                               pv_cmd, pv_rc, pv_rrc, errp);
     g_free(hdr);
     return rc;
 }
 
-int s390_ipl_pv_unpack(void)
+int s390_ipl_pv_unpack(uint16_t *pv_cmd, uint16_t *pv_rc, uint16_t *pv_rrc)
 {
     IplParameterBlock *ipib = s390_ipl_get_iplb_pv();
     IPLBlockPV *ipib_pv = &ipib->pv;
@@ -699,7 +701,8 @@ int s390_ipl_pv_unpack(void)
     for (i = 0; i < ipib_pv->num_comp; i++) {
         rc = s390_pv_unpack(ipib_pv->components[i].addr,
                             TARGET_PAGE_ALIGN(ipib_pv->components[i].size),
-                            ipib_pv->components[i].tweak_pref);
+                            ipib_pv->components[i].tweak_pref,
+                            pv_cmd, pv_rc, pv_rrc);
         if (rc) {
             break;
         }
diff --git a/hw/s390x/ipl.h b/hw/s390x/ipl.h
index 8e3882d506..0ff0d46b5f 100644
--- a/hw/s390x/ipl.h
+++ b/hw/s390x/ipl.h
@@ -26,8 +26,9 @@ void s390_ipl_convert_loadparm(char *ascii_lp, uint8_t *ebcdic_lp);
 void s390_ipl_fmt_loadparm(uint8_t *loadparm, char *str, Error **errp);
 void s390_rebuild_iplb(uint16_t index, IplParameterBlock *iplb);
 void s390_ipl_update_diag308(IplParameterBlock *iplb);
-int s390_ipl_prepare_pv_header(Error **errp);
-int s390_ipl_pv_unpack(void);
+int s390_ipl_prepare_pv_header(uint16_t *pv_cmd, uint16_t *pv_rc,
+                               uint16_t *pv_rrc, Error **errp);
+int s390_ipl_pv_unpack(uint16_t *pv_cmd, uint16_t *pv_rc, uint16_t *pv_rrc);
 void s390_ipl_prepare_cpu(S390CPU *cpu);
 IplParameterBlock *s390_ipl_get_iplb(void);
 IplParameterBlock *s390_ipl_get_iplb_pv(void);
diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index d9e683c5b4..e35997acbd 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -53,6 +53,13 @@
 
 static Error *pv_mig_blocker;
 
+struct Diag308Response {
+    uint16_t pv_cmd;
+    uint16_t pv_rrc;
+    uint16_t pv_rc;
+    uint16_t diag_rc;
+};
+
 static S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id,
                               Error **errp)
 {
@@ -364,7 +371,10 @@ static void s390_machine_unprotect(S390CcwMachineState *ms)
     ram_block_discard_disable(false);
 }
 
-static int s390_machine_protect(S390CcwMachineState *ms)
+static int s390_machine_protect(S390CcwMachineState *ms,
+                                uint16_t *pv_cmd,
+                                uint16_t *pv_rc,
+                                uint16_t *pv_rrc)
 {
     Error *local_err = NULL;
     int rc;
@@ -407,19 +417,19 @@ static int s390_machine_protect(S390CcwMachineState *ms)
     }
 
     /* Set SE header and unpack */
-    rc = s390_ipl_prepare_pv_header(&local_err);
+    rc = s390_ipl_prepare_pv_header(pv_cmd, pv_rc, pv_rrc, &local_err);
     if (rc) {
         goto out_err;
     }
 
     /* Decrypt image */
-    rc = s390_ipl_pv_unpack();
+    rc = s390_ipl_pv_unpack(pv_cmd, pv_rc, pv_rrc);
     if (rc) {
         goto out_err;
     }
 
     /* Verify integrity */
-    rc = s390_pv_verify();
+    rc = s390_pv_verify(pv_cmd, pv_rc, pv_rrc);
     if (rc) {
         goto out_err;
     }
@@ -451,6 +461,7 @@ static void s390_pv_prepare_reset(S390CcwMachineState *ms)
 static void s390_machine_reset(MachineState *machine, ResetType type)
 {
     S390CcwMachineState *ms = S390_CCW_MACHINE(machine);
+    struct Diag308Response resp;
     enum s390_reset reset_type;
     CPUState *cs, *t;
     S390CPU *cpu;
@@ -539,8 +550,9 @@ static void s390_machine_reset(MachineState *machine, ResetType type)
         }
         run_on_cpu(cs, s390_do_cpu_reset, RUN_ON_CPU_NULL);
 
-        if (s390_machine_protect(ms)) {
-            s390_pv_inject_reset_error(cs);
+        if (s390_machine_protect(ms, &resp.pv_cmd, &resp.pv_rc, &resp.pv_rrc)) {
+            resp.diag_rc = DIAG_308_RC_INVAL_FOR_PV;
+            s390_pv_inject_reset_error(cs, (uint64_t *)(&resp));
             /*
              * Continue after the diag308 so the guest knows something
              * went wrong.
diff --git a/target/s390x/kvm/pv.c b/target/s390x/kvm/pv.c
index 66194caaae..9f85e8c1a1 100644
--- a/target/s390x/kvm/pv.c
+++ b/target/s390x/kvm/pv.c
@@ -30,7 +30,7 @@ static struct kvm_s390_pv_info_vm info_vm;
 static struct kvm_s390_pv_info_dump info_dump;
 
 static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data,
-                         int *pvrc)
+                         uint16_t *pv_rc, uint16_t *pv_rrc)
 {
     struct kvm_pv_cmd pv_cmd = {
         .cmd = cmd,
@@ -47,9 +47,13 @@ static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data,
                      "IOCTL rc: %d", cmd, cmdname, pv_cmd.rc, pv_cmd.rrc,
                      rc);
     }
-    if (pvrc) {
-        *pvrc = pv_cmd.rc;
+    if (pv_rc) {
+        *pv_rc = pv_cmd.rc;
     }
+    if (pv_rrc) {
+        *pv_rrc = pv_cmd.rrc;
+    }
+
     return rc;
 }
 
@@ -57,8 +61,11 @@ static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data,
  * This macro lets us pass the command as a string to the function so
  * we can print it on an error.
  */
-#define s390_pv_cmd(cmd, data) __s390_pv_cmd(cmd, #cmd, data, NULL)
-#define s390_pv_cmd_pvrc(cmd, data, pvrc) __s390_pv_cmd(cmd, #cmd, data, pvrc)
+#define s390_pv_cmd(cmd, data)  __s390_pv_cmd(cmd, #cmd, data, NULL, NULL)
+#define s390_pv_cmd_pvrc(cmd, data, pv_rc) \
+                                __s390_pv_cmd(cmd, #cmd, data, pv_rc, NULL)
+#define s390_pv_cmd_pvrc_pvrrc(cmd, data, pv_rc, pv_rrc) \
+                                __s390_pv_cmd(cmd, #cmd, data, pv_rc, pv_rrc)
 
 static void s390_pv_cmd_exit(uint32_t cmd, void *data)
 {
@@ -146,18 +153,21 @@ bool s390_pv_vm_try_disable_async(S390CcwMachineState *ms)
 }
 
 #define DIAG_308_UV_RC_INVAL_HOSTKEY    0x0108
-int s390_pv_set_sec_parms(uint64_t origin, uint64_t length, Error **errp)
+int s390_pv_set_sec_parms(uint64_t origin, uint64_t length,
+                          uint16_t *pv_cmd, uint16_t *pv_rc,
+                          uint16_t *pv_rrc, Error **errp)
 {
-    int ret, pvrc;
+    int ret;
     struct kvm_s390_pv_sec_parm args = {
         .origin = origin,
         .length = length,
     };
 
-    ret = s390_pv_cmd_pvrc(KVM_PV_SET_SEC_PARMS, &args, &pvrc);
+    *pv_cmd = KVM_PV_SET_SEC_PARMS;
+    ret = s390_pv_cmd_pvrc_pvrrc(*pv_cmd, &args, pv_rc, pv_rrc);
     if (ret) {
         error_setg(errp, "Failed to set secure execution parameters");
-        if (pvrc == DIAG_308_UV_RC_INVAL_HOSTKEY) {
+        if (*pv_rc == DIAG_308_UV_RC_INVAL_HOSTKEY) {
             error_append_hint(errp, "Please check whether the image is "
                                     "correctly encrypted for this host\n");
         }
@@ -169,7 +179,9 @@ int s390_pv_set_sec_parms(uint64_t origin, uint64_t length, Error **errp)
 /*
  * Called for each component in the SE type IPL parameter block 0.
  */
-int s390_pv_unpack(uint64_t addr, uint64_t size, uint64_t tweak)
+int s390_pv_unpack(uint64_t addr, uint64_t size,
+                   uint64_t tweak, uint16_t *pv_cmd,
+                   uint16_t *pv_rc, uint16_t *pv_rrc)
 {
     struct kvm_s390_pv_unp args = {
         .addr = addr,
@@ -177,7 +189,8 @@ int s390_pv_unpack(uint64_t addr, uint64_t size, uint64_t tweak)
         .tweak = tweak,
     };
 
-    return s390_pv_cmd(KVM_PV_UNPACK, &args);
+    *pv_cmd = KVM_PV_UNPACK;
+    return s390_pv_cmd_pvrc_pvrrc(*pv_cmd, &args, pv_rc, pv_rrc);
 }
 
 void s390_pv_prep_reset(void)
@@ -185,9 +198,10 @@ void s390_pv_prep_reset(void)
     s390_pv_cmd_exit(KVM_PV_PREP_RESET, NULL);
 }
 
-int s390_pv_verify(void)
+int s390_pv_verify(uint16_t *pv_cmd, uint16_t *pv_rc, uint16_t *pv_rrc)
 {
-    return s390_pv_cmd(KVM_PV_VERIFY, NULL);
+    *pv_cmd = KVM_PV_VERIFY;
+    return s390_pv_cmd_pvrc_pvrrc(*pv_cmd, NULL, pv_rc, pv_rrc);
 }
 
 void s390_pv_unshare(void)
@@ -195,13 +209,13 @@ void s390_pv_unshare(void)
     s390_pv_cmd_exit(KVM_PV_UNSHARE_ALL, NULL);
 }
 
-void s390_pv_inject_reset_error(CPUState *cs)
+void s390_pv_inject_reset_error(CPUState *cs, uint64_t *resp)
 {
     int r1 = (cs->kvm_run->s390_sieic.ipa & 0x00f0) >> 4;
     CPUS390XState *env = &S390_CPU(cs)->env;
 
     /* Report that we are unable to enter protected mode */
-    env->regs[r1 + 1] = DIAG_308_RC_INVAL_FOR_PV;
+    env->regs[r1 + 1] = *resp;
 }
 
 uint64_t kvm_s390_pv_dmp_get_size_cpu(void)
diff --git a/target/s390x/kvm/pv.h b/target/s390x/kvm/pv.h
index 5e9c8bd351..035c4cab92 100644
--- a/target/s390x/kvm/pv.h
+++ b/target/s390x/kvm/pv.h
@@ -42,12 +42,16 @@ int s390_pv_query_info(void);
 int s390_pv_vm_enable(void);
 void s390_pv_vm_disable(void);
 bool s390_pv_vm_try_disable_async(S390CcwMachineState *ms);
-int s390_pv_set_sec_parms(uint64_t origin, uint64_t length, Error **errp);
-int s390_pv_unpack(uint64_t addr, uint64_t size, uint64_t tweak);
+int s390_pv_set_sec_parms(uint64_t origin, uint64_t length,
+                          uint16_t *pv_cmd, uint16_t *pv_rc,
+                          uint16_t *pv_rrc, Error **errp);
+int s390_pv_unpack(uint64_t addr, uint64_t size,
+                   uint64_t tweak, uint16_t *pv_cmd,
+                   uint16_t *pv_rc, uint16_t *pv_rrc);
 void s390_pv_prep_reset(void);
-int s390_pv_verify(void);
+int s390_pv_verify(uint16_t *pv_cmd, uint16_t *pv_rc, uint16_t *pv_rrc);
 void s390_pv_unshare(void);
-void s390_pv_inject_reset_error(CPUState *cs);
+void s390_pv_inject_reset_error(CPUState *cs, uint64_t *resp);
 uint64_t kvm_s390_pv_dmp_get_size_cpu(void);
 uint64_t kvm_s390_pv_dmp_get_size_mem_state(void);
 uint64_t kvm_s390_pv_dmp_get_size_completion_data(void);
@@ -63,12 +67,19 @@ static inline int s390_pv_vm_enable(void) { return 0; }
 static inline void s390_pv_vm_disable(void) {}
 static inline bool s390_pv_vm_try_disable_async(S390CcwMachineState *ms) { return false; }
 static inline int s390_pv_set_sec_parms(uint64_t origin, uint64_t length,
-                                        Error **errp) { return 0; }
-static inline int s390_pv_unpack(uint64_t addr, uint64_t size, uint64_t tweak) { return 0; }
+                                        uint16_t *pv_cmd, uint16_t *pv_rc,
+                                        uint16_t *pv_rrc, Error **errp)
+                                        { return 0; }
+static inline int s390_pv_unpack(uint64_t addr, uint64_t size,
+                                 uint64_t tweak, uint16_t *pv_cmd,
+                                 uint16_t *pv_rc, uint16_t *pv_rrc)
+                                 { return 0; }
 static inline void s390_pv_prep_reset(void) {}
-static inline int s390_pv_verify(void) { return 0; }
+static inline int s390_pv_verify(uint16_t *pv_cmd,
+                                 uint16_t *pv_rc,
+                                 uint16_t *pv_rrc) { return 0; }
 static inline void s390_pv_unshare(void) {}
-static inline void s390_pv_inject_reset_error(CPUState *cs) {};
+static inline void s390_pv_inject_reset_error(CPUState *cs, uint64_t *resp) {};
 static inline uint64_t kvm_s390_pv_dmp_get_size_cpu(void) { return 0; }
 static inline uint64_t kvm_s390_pv_dmp_get_size_mem_state(void) { return 0; }
 static inline uint64_t kvm_s390_pv_dmp_get_size_completion_data(void) { return 0; }
-- 
2.49.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 2/3] target/s390x: introduce function when exiting PV
  2025-04-14 15:48 ` [PATCH v2 2/3] target/s390x: introduce function when exiting PV Gautam Gala
@ 2025-04-15  9:07   ` Steffen Eiden
  2025-04-15  9:44   ` Thomas Huth
  1 sibling, 0 replies; 9+ messages in thread
From: Steffen Eiden @ 2025-04-15  9:07 UTC (permalink / raw)
  To: Gautam Gala; +Cc: qemu-s390x, qemu-devel, Christian Borntraeger, Thomas Huth

On Mon, Apr 14, 2025 at 05:48:37PM +0200, Gautam Gala wrote:
> introduce a static function when exiting PV. The function replaces an
> existing macro (s390_pv_cmd_exit).
> 

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
> Signed-off-by: Gautam Gala <ggala@linux.ibm.com>

Nit:
start with capital letters at beginning of sentences and after a colon.

...
 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 2/3] target/s390x: introduce function when exiting PV
  2025-04-14 15:48 ` [PATCH v2 2/3] target/s390x: introduce function when exiting PV Gautam Gala
  2025-04-15  9:07   ` Steffen Eiden
@ 2025-04-15  9:44   ` Thomas Huth
  2025-04-15 12:04     ` Gautam Gala
  1 sibling, 1 reply; 9+ messages in thread
From: Thomas Huth @ 2025-04-15  9:44 UTC (permalink / raw)
  To: Gautam Gala, qemu-s390x, qemu-devel; +Cc: Christian Borntraeger, seiden

On 14/04/2025 17.48, Gautam Gala wrote:
> introduce a static function when exiting PV. The function replaces an
> existing macro (s390_pv_cmd_exit).

You describe here what you're doing, but not why ... so may I ask: Why is 
this change necessary?

  Thomas


> Signed-off-by: Gautam Gala <ggala@linux.ibm.com>
> ---
>   target/s390x/kvm/pv.c | 14 ++++++--------
>   1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/target/s390x/kvm/pv.c b/target/s390x/kvm/pv.c
> index 3a0a971f0b..66194caaae 100644
> --- a/target/s390x/kvm/pv.c
> +++ b/target/s390x/kvm/pv.c
> @@ -59,14 +59,12 @@ static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data,
>    */
>   #define s390_pv_cmd(cmd, data) __s390_pv_cmd(cmd, #cmd, data, NULL)
>   #define s390_pv_cmd_pvrc(cmd, data, pvrc) __s390_pv_cmd(cmd, #cmd, data, pvrc)
> -#define s390_pv_cmd_exit(cmd, data)    \
> -{                                      \
> -    int rc;                            \
> -                                       \
> -    rc = __s390_pv_cmd(cmd, #cmd, data, NULL); \
> -    if (rc) {                          \
> -        exit(1);                       \
> -    }                                  \
> +
> +static void s390_pv_cmd_exit(uint32_t cmd, void *data)
> +{
> +    if (s390_pv_cmd(cmd, data)) {
> +        exit(1);
> +    }
>   }
>   
>   int s390_pv_query_info(void)



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 3/3] target/s390x: Return UVC cmd code, RC and RRC value when DIAG 308 Subcode 10 fails to enter secure mode
  2025-04-14 15:48 ` [PATCH v2 3/3] target/s390x: Return UVC cmd code, RC and RRC value when DIAG 308 Subcode 10 fails to enter secure mode Gautam Gala
@ 2025-04-15  9:59   ` Thomas Huth
  0 siblings, 0 replies; 9+ messages in thread
From: Thomas Huth @ 2025-04-15  9:59 UTC (permalink / raw)
  To: Gautam Gala, qemu-s390x, qemu-devel; +Cc: Christian Borntraeger, seiden

  Hi!

On 14/04/2025 17.48, Gautam Gala wrote:
> Extend DIAG308 subcode 10 to return the UVC RC, RRC and command code
> in bit positions 32-47, 16-31, and 0-15 of register R1 + 1 if the
> function does not complete successfully (in addition to the
> previously returned diag response code in bit position 47-63).
> 
> Signed-off-by: Gautam Gala <ggala@linux.ibm.com>
> ---
...
> diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
> index d9e683c5b4..e35997acbd 100644
> --- a/hw/s390x/s390-virtio-ccw.c
> +++ b/hw/s390x/s390-virtio-ccw.c
> @@ -53,6 +53,13 @@
>   
>   static Error *pv_mig_blocker;
>   
> +struct Diag308Response {
> +    uint16_t pv_cmd;
> +    uint16_t pv_rrc;
> +    uint16_t pv_rc;
> +    uint16_t diag_rc;
> +};
> +
>   static S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id,
>                                 Error **errp)
>   {
> @@ -364,7 +371,10 @@ static void s390_machine_unprotect(S390CcwMachineState *ms)
>       ram_block_discard_disable(false);
>   }
>   
> -static int s390_machine_protect(S390CcwMachineState *ms)
> +static int s390_machine_protect(S390CcwMachineState *ms,
> +                                uint16_t *pv_cmd,
> +                                uint16_t *pv_rc,
> +                                uint16_t *pv_rrc)

Instead of adding these three pointer parameters to each and every 
functions, how's about only adding a Diag308Response pointer instead?

...
> @@ -539,8 +550,9 @@ static void s390_machine_reset(MachineState *machine, ResetType type)
>           }
>           run_on_cpu(cs, s390_do_cpu_reset, RUN_ON_CPU_NULL);
>   
> -        if (s390_machine_protect(ms)) {
> -            s390_pv_inject_reset_error(cs);
> +        if (s390_machine_protect(ms, &resp.pv_cmd, &resp.pv_rc, &resp.pv_rrc)) {
> +            resp.diag_rc = DIAG_308_RC_INVAL_FOR_PV;
> +            s390_pv_inject_reset_error(cs, (uint64_t *)(&resp));

Uh, this smells like it could break strict aliasing rules, please don't do 
type-punning like this. I'd suggest to either wrap Diag308Response in an 
union with an uint64_t as second field, or calculate the value by shifting 
the individual fields and pass that 64-bit result to the function.

  Thanks,
   Thomas


> -void s390_pv_inject_reset_error(CPUState *cs)
> +void s390_pv_inject_reset_error(CPUState *cs, uint64_t *resp)
>   {
>       int r1 = (cs->kvm_run->s390_sieic.ipa & 0x00f0) >> 4;
>       CPUS390XState *env = &S390_CPU(cs)->env;
>   
>       /* Report that we are unable to enter protected mode */
> -    env->regs[r1 + 1] = DIAG_308_RC_INVAL_FOR_PV;
> +    env->regs[r1 + 1] = *resp;
>   }
>   



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 2/3] target/s390x: introduce function when exiting PV
  2025-04-15  9:44   ` Thomas Huth
@ 2025-04-15 12:04     ` Gautam Gala
  2025-04-15 12:40       ` Thomas Huth
  0 siblings, 1 reply; 9+ messages in thread
From: Gautam Gala @ 2025-04-15 12:04 UTC (permalink / raw)
  To: Thomas Huth; +Cc: qemu-s390x, qemu-devel, Christian Borntraeger, seiden

Hi,

The change is not really necessary. The existing macro looked almost like a
function, and since I was making changes in the area, it felt like a good 
opportunity to change it to an actual function.

Thanks,
Gautam

On Tue, Apr 15, 2025 at 11:44:35AM +0200, Thomas Huth wrote:
> On 14/04/2025 17.48, Gautam Gala wrote:
> > introduce a static function when exiting PV. The function replaces an
> > existing macro (s390_pv_cmd_exit).
> 
> You describe here what you're doing, but not why ... so may I ask: Why is
> this change necessary?
> 
>  Thomas
> 
> 
> > Signed-off-by: Gautam Gala <ggala@linux.ibm.com>
> > ---
> >   target/s390x/kvm/pv.c | 14 ++++++--------
> >   1 file changed, 6 insertions(+), 8 deletions(-)
> > 
> > diff --git a/target/s390x/kvm/pv.c b/target/s390x/kvm/pv.c
> > index 3a0a971f0b..66194caaae 100644
> > --- a/target/s390x/kvm/pv.c
> > +++ b/target/s390x/kvm/pv.c
> > @@ -59,14 +59,12 @@ static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data,
> >    */
> >   #define s390_pv_cmd(cmd, data) __s390_pv_cmd(cmd, #cmd, data, NULL)
> >   #define s390_pv_cmd_pvrc(cmd, data, pvrc) __s390_pv_cmd(cmd, #cmd, data, pvrc)
> > -#define s390_pv_cmd_exit(cmd, data)    \
> > -{                                      \
> > -    int rc;                            \
> > -                                       \
> > -    rc = __s390_pv_cmd(cmd, #cmd, data, NULL); \
> > -    if (rc) {                          \
> > -        exit(1);                       \
> > -    }                                  \
> > +
> > +static void s390_pv_cmd_exit(uint32_t cmd, void *data)
> > +{
> > +    if (s390_pv_cmd(cmd, data)) {
> > +        exit(1);
> > +    }
> >   }
> >   int s390_pv_query_info(void)
> 
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 2/3] target/s390x: introduce function when exiting PV
  2025-04-15 12:04     ` Gautam Gala
@ 2025-04-15 12:40       ` Thomas Huth
  0 siblings, 0 replies; 9+ messages in thread
From: Thomas Huth @ 2025-04-15 12:40 UTC (permalink / raw)
  To: Gautam Gala; +Cc: qemu-s390x, qemu-devel, Christian Borntraeger, seiden

On 15/04/2025 14.04, Gautam Gala wrote:
> Hi,
> 
> The change is not really necessary. The existing macro looked almost like a
> function, and since I was making changes in the area, it felt like a good
> opportunity to change it to an actual function.

Ok, makes sense, but please add that information to the patch description!

  Thanks,
   Thomas

> 
> On Tue, Apr 15, 2025 at 11:44:35AM +0200, Thomas Huth wrote:
>> On 14/04/2025 17.48, Gautam Gala wrote:
>>> introduce a static function when exiting PV. The function replaces an
>>> existing macro (s390_pv_cmd_exit).
>>
>> You describe here what you're doing, but not why ... so may I ask: Why is
>> this change necessary?
>>
>>   Thomas
>>
>>
>>> Signed-off-by: Gautam Gala <ggala@linux.ibm.com>
>>> ---
>>>    target/s390x/kvm/pv.c | 14 ++++++--------
>>>    1 file changed, 6 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/target/s390x/kvm/pv.c b/target/s390x/kvm/pv.c
>>> index 3a0a971f0b..66194caaae 100644
>>> --- a/target/s390x/kvm/pv.c
>>> +++ b/target/s390x/kvm/pv.c
>>> @@ -59,14 +59,12 @@ static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data,
>>>     */
>>>    #define s390_pv_cmd(cmd, data) __s390_pv_cmd(cmd, #cmd, data, NULL)
>>>    #define s390_pv_cmd_pvrc(cmd, data, pvrc) __s390_pv_cmd(cmd, #cmd, data, pvrc)
>>> -#define s390_pv_cmd_exit(cmd, data)    \
>>> -{                                      \
>>> -    int rc;                            \
>>> -                                       \
>>> -    rc = __s390_pv_cmd(cmd, #cmd, data, NULL); \
>>> -    if (rc) {                          \
>>> -        exit(1);                       \
>>> -    }                                  \
>>> +
>>> +static void s390_pv_cmd_exit(uint32_t cmd, void *data)
>>> +{
>>> +    if (s390_pv_cmd(cmd, data)) {
>>> +        exit(1);
>>> +    }
>>>    }
>>>    int s390_pv_query_info(void)
>>
>>
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-04-15 12:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-14 15:48 [PATCH v2 0/3] DIAG 308: extend subcode 10 to return UVC cmd id, RC and RRC values upon failure to enter secure mode Gautam Gala
2025-04-14 15:48 ` [PATCH v2 1/3] target/s390x: Introduce constant when checking if PV header couldn't be decrypted Gautam Gala
2025-04-14 15:48 ` [PATCH v2 2/3] target/s390x: introduce function when exiting PV Gautam Gala
2025-04-15  9:07   ` Steffen Eiden
2025-04-15  9:44   ` Thomas Huth
2025-04-15 12:04     ` Gautam Gala
2025-04-15 12:40       ` Thomas Huth
2025-04-14 15:48 ` [PATCH v2 3/3] target/s390x: Return UVC cmd code, RC and RRC value when DIAG 308 Subcode 10 fails to enter secure mode Gautam Gala
2025-04-15  9:59   ` Thomas Huth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).