From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: linux-s390@vger.kernel.org, qemu-devel@nongnu.org
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>,
Thomas Huth <thuth@redhat.com>,
Richard Henderson <richard.henderson@linaro.org>,
Harald Freudenberger <freude@linux.ibm.com>,
Holger Dengler <dengler@linux.ibm.com>
Subject: [PATCH qemu] target/s390x: support PRNO_TRNG instruction
Date: Tue, 12 Jul 2022 18:46:27 +0200 [thread overview]
Message-ID: <20220712164627.581570-1-Jason@zx2c4.com> (raw)
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-rc6.
Cc: Thomas Huth <thuth@redhat.com>
Cc: Richard Henderson <richard.henderson@linaro.org>
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 | 23 +++++++++++++++++++++++
2 files changed, 25 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..cefdfd114e 100644
--- a/target/s390x/tcg/crypto_helper.c
+++ b/target/s390x/tcg/crypto_helper.c
@@ -12,12 +12,28 @@
#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, uint64_t len)
+{
+ uint64_t addr = wrap_address(env, buf);
+ uint8_t tmp[256];
+
+ 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, addr++, tmp[i], ra);
+ len -= block;
+ }
+}
+
uint32_t HELPER(msa)(CPUS390XState *env, uint32_t r1, uint32_t r2, uint32_t r3,
uint32_t type)
{
@@ -52,6 +68,13 @@ 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: {
+ const uint64_t ucbuf = env->regs[r1], ucbuf_len = env->regs[r1 + 1];
+ const uint64_t cbuf = env->regs[r2], cbuf_len = env->regs[r2 + 1];
+ fill_buf_random(env, ra, ucbuf, ucbuf_len);
+ fill_buf_random(env, ra, cbuf, cbuf_len);
+ break;
+ }
default:
/* we don't implement any other subfunction yet */
g_assert_not_reached();
--
2.35.1
next reply other threads:[~2022-07-12 16:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-12 16:46 Jason A. Donenfeld [this message]
2022-07-19 9:54 ` [PATCH qemu] target/s390x: support PRNO_TRNG instruction David Hildenbrand
2022-07-19 11:23 ` Jason A. Donenfeld
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220712164627.581570-1-Jason@zx2c4.com \
--to=jason@zx2c4.com \
--cc=dengler@linux.ibm.com \
--cc=freude@linux.ibm.com \
--cc=linux-s390@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox