[PATCH v16 06/20] target/s390x: Adjust addressing mode checks for sha512 and sha256
Harald Freudenberger <[email protected]>
| Newsgroups | org.kernel.vger.linux-s390,org.nongnu.qemu-devel |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]> Suggested-by: Ilya Leoshkevich <[email protected]> --- target/s390x/tcg/cpacf_sha256.c | 16 +++++++++++++--- target/s390x/tcg/cpacf_sha512.c | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) 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. */ -- 2.43.0