Commit 4ed7ae88ec for qemu.org

commit 4ed7ae88ececad55c101685ea62c22bf7f58739d
Author: Harald Freudenberger <freude@linux.ibm.com>
Date:   Mon Aug 24 10:31:50 2026 +0200

    target/s390x: Adjust addressing mode checks for sha512 and sha256

    The handling for different addressing modes in the both sha
    implementations cpacf sha256 and sha512 was incomplete. Rework this
    addressing checking to clearly have support for s390 64 bit and 32 bit
    addressing mode but raise an exception otherwise.

    Also bail out early (for KIMD only) if length is 0.

    Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
    Suggested-by: Ilya Leoshkevich <iii@linux.ibm.com>
    Reviewed-by: Eric Farman <farman@linux.ibm.com>
    Link: https://lore.kernel.org/qemu-devel/20260824083204.40877-7-freude@linux.ibm.com
    Signed-off-by: Eric Farman <farman@linux.ibm.com>

diff --git a/target/s390x/tcg/cpacf_sha256.c b/target/s390x/tcg/cpacf_sha256.c
index 67321b565c..de305b6838 100644
--- a/target/s390x/tcg/cpacf_sha256.c
+++ b/target/s390x/tcg/cpacf_sha256.c
@@ -111,14 +111,24 @@ int cpacf_sha256(CPUS390XState *env, const int mmu_idx, uintptr_t ra,
 {
     enum { MAX_BLOCKS_PER_RUN = 128 }; /* 128 * 64 = 8K */
     uint64_t len = *len_reg, processed = 0;
-    int message_reg_len = 64;
+    int message_reg_len;
     uint32_t a[8];

     g_assert(type == S390_FEAT_TYPE_KIMD || type == S390_FEAT_TYPE_KLMD);

-    if (!(env->psw.mask & PSW_MASK_64)) {
+    /* check addressing mode, raise exception if not supported here */
+    if (env->psw.mask & PSW_MASK_64) {
+        message_reg_len = 64;
+    } else if (env->psw.mask & PSW_MASK_32) {
+        message_reg_len = 32;
         len = (uint32_t)len;
-        message_reg_len = (env->psw.mask & PSW_MASK_32) ? 32 : 24;
+    } else {
+        tcg_s390_program_interrupt(env, PGM_SPECIFICATION, ra);
+    }
+
+    /* for KIMD only: early bail out if length is zero */
+    if (type == S390_FEAT_TYPE_KIMD && !len) {
+        return 0;
     }

     /* KIMD: length has to be properly aligned. */
diff --git a/target/s390x/tcg/cpacf_sha512.c b/target/s390x/tcg/cpacf_sha512.c
index edd8dae78f..cad8e0e1bd 100644
--- a/target/s390x/tcg/cpacf_sha512.c
+++ b/target/s390x/tcg/cpacf_sha512.c
@@ -126,13 +126,23 @@ int cpacf_sha512(CPUS390XState *env, const int mmu_idx, uintptr_t ra,
 {
     enum { MAX_BLOCKS_PER_RUN = 64 }; /* Arbitrary: keep interactivity. */
     uint64_t len = *len_reg, a[8], processed = 0;
-    int message_reg_len = 64;
+    int message_reg_len;

     g_assert(type == S390_FEAT_TYPE_KIMD || type == S390_FEAT_TYPE_KLMD);

-    if (!(env->psw.mask & PSW_MASK_64)) {
+    /* check addressing mode, raise exception if not supported here */
+    if (env->psw.mask & PSW_MASK_64) {
+        message_reg_len = 64;
+    } else if (env->psw.mask & PSW_MASK_32) {
+        message_reg_len = 32;
         len = (uint32_t)len;
-        message_reg_len = (env->psw.mask & PSW_MASK_32) ? 32 : 24;
+    } else {
+        tcg_s390_program_interrupt(env, PGM_SPECIFICATION, ra);
+    }
+
+    /* for KIMD only: early bail out if length is zero */
+    if (type == S390_FEAT_TYPE_KIMD && !len) {
+        return 0;
     }

     /* KIMD: length has to be properly aligned. */