[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v6 1/2] target/s390x: support PRNO_TRNG instruction
From: |
Jason A. Donenfeld |
Subject: |
[PATCH v6 1/2] target/s390x: support PRNO_TRNG instruction |
Date: |
Wed, 3 Aug 2022 19:15:35 +0200 |
In order for hosts running inside of TCG to initialize the kernel's
random number generator, we should support the PRNO_TRNG instruction,
backed in the usual way with the qemu_guest_getrandom helper. This is
confirmed working on Linux 5.19.
Cc: Thomas Huth <thuth@redhat.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Richard Henderson <richard.henderson@linaro.org>
Cc: Cornelia Huck <cohuck@redhat.com>
Cc: Harald Freudenberger <freude@linux.ibm.com>
Cc: Holger Dengler <dengler@linux.ibm.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
target/s390x/gen-features.c | 2 ++
target/s390x/tcg/crypto_helper.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/target/s390x/gen-features.c b/target/s390x/gen-features.c
index ad140184b9..3d333e2789 100644
--- a/target/s390x/gen-features.c
+++ b/target/s390x/gen-features.c
@@ -749,6 +749,8 @@ static uint16_t qemu_V7_0[] = {
*/
static uint16_t qemu_MAX[] = {
S390_FEAT_VECTOR_ENH2,
+ S390_FEAT_MSA_EXT_5,
+ S390_FEAT_PRNO_TRNG,
};
/****** END FEATURE DEFS ******/
diff --git a/target/s390x/tcg/crypto_helper.c b/target/s390x/tcg/crypto_helper.c
index 138d9e7ad9..8ad4ef1ace 100644
--- a/target/s390x/tcg/crypto_helper.c
+++ b/target/s390x/tcg/crypto_helper.c
@@ -12,12 +12,38 @@
#include "qemu/osdep.h"
#include "qemu/main-loop.h"
+#include "qemu/guest-random.h"
#include "s390x-internal.h"
#include "tcg_s390x.h"
#include "exec/helper-proto.h"
#include "exec/exec-all.h"
#include "exec/cpu_ldst.h"
+static void fill_buf_random(CPUS390XState *env, uintptr_t ra,
+ uint64_t *buf_reg, uint64_t *len_reg)
+{
+ uint8_t tmp[256];
+ uint64_t len = *len_reg;
+ int reg_len = 64;
+
+ if (!(env->psw.mask & PSW_MASK_64)) {
+ len = (uint32_t)len;
+ reg_len = (env->psw.mask & PSW_MASK_32) ? 32 : 24;
+ }
+
+ while (len) {
+ size_t block = MIN(len, sizeof(tmp));
+
+ qemu_guest_getrandom_nofail(tmp, block);
+ for (size_t i = 0; i < block; ++i) {
+ cpu_stb_data_ra(env, wrap_address(env, *buf_reg), tmp[i], ra);
+ *buf_reg = deposit64(*buf_reg, 0, reg_len, *buf_reg + 1);
+ --*len_reg;
+ }
+ len -= block;
+ }
+}
+
uint32_t HELPER(msa)(CPUS390XState *env, uint32_t r1, uint32_t r2, uint32_t r3,
uint32_t type)
{
@@ -52,6 +78,10 @@ uint32_t HELPER(msa)(CPUS390XState *env, uint32_t r1,
uint32_t r2, uint32_t r3,
cpu_stb_data_ra(env, param_addr, subfunc[i], ra);
}
break;
+ case 114: /* CPACF_PRNO_TRNG */
+ fill_buf_random(env, ra, &env->regs[r1], &env->regs[r1 + 1]);
+ fill_buf_random(env, ra, &env->regs[r2], &env->regs[r2 + 1]);
+ break;
default:
/* we don't implement any other subfunction yet */
g_assert_not_reached();
--
2.35.1
- [PATCH v4 0/2] MSA EXT 5 for s390x, (continued)
- [PATCH v4 0/2] MSA EXT 5 for s390x, Jason A. Donenfeld, 2022/08/02
- [PATCH v4 1/2] target/s390x: support PRNO_TRNG instruction, Jason A. Donenfeld, 2022/08/02
- [PATCH v4 2/2] target/s390x: support SHA-512 extensions, Jason A. Donenfeld, 2022/08/02
- Re: [PATCH v4 2/2] target/s390x: support SHA-512 extensions, David Hildenbrand, 2022/08/03
- Re: [PATCH v4 2/2] target/s390x: support SHA-512 extensions, Jason A. Donenfeld, 2022/08/03
- Re: [PATCH v4 2/2] target/s390x: support SHA-512 extensions, Jason A. Donenfeld, 2022/08/03
- [PATCH v5 1/2] target/s390x: support PRNO_TRNG instruction, Jason A. Donenfeld, 2022/08/03
- [PATCH v5 2/2] target/s390x: support SHA-512 extensions, Jason A. Donenfeld, 2022/08/03
- [PATCH 1/2] target/s390x: support PRNO_TRNG instruction, Jason A. Donenfeld, 2022/08/03
- [PATCH 2/2] target/s390x: support SHA-512 extensions, Jason A. Donenfeld, 2022/08/03
- [PATCH v6 1/2] target/s390x: support PRNO_TRNG instruction,
Jason A. Donenfeld <=
- [PATCH v6 2/2] target/s390x: support SHA-512 extensions, Jason A. Donenfeld, 2022/08/03
- Re: [PATCH v6 2/2] target/s390x: support SHA-512 extensions, David Hildenbrand, 2022/08/05
- Re: [PATCH v6 2/2] target/s390x: support SHA-512 extensions, Jason A. Donenfeld, 2022/08/05
- [PATCH v7 1/2] target/s390x: support SHA-512 extensions, Jason A. Donenfeld, 2022/08/09
- [PATCH v7 2/2] target/s390x: support PRNO_TRNG instruction, Jason A. Donenfeld, 2022/08/09
- Re: [PATCH v7 2/2] target/s390x: support PRNO_TRNG instruction, Thomas Huth, 2022/08/26
- Re: [PATCH v7 2/2] target/s390x: support PRNO_TRNG instruction, Jason A. Donenfeld, 2022/08/29
- Re: [PATCH v7 1/2] target/s390x: support SHA-512 extensions, Thomas Huth, 2022/08/26
- Re: [PATCH v7 1/2] target/s390x: support SHA-512 extensions, Jason A. Donenfeld, 2022/08/29
- Re: [PATCH v6 2/2] target/s390x: support SHA-512 extensions, David Hildenbrand, 2022/08/11