All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH qemu] target/s390x: support PRNO_TRNG instruction
@ 2022-07-12 16:46 Jason A. Donenfeld
  2022-07-19  9:54 ` David Hildenbrand
  2022-07-19 10:00 ` [PATCH qemu] " Thomas Huth
  0 siblings, 2 replies; 53+ messages in thread
From: Jason A. Donenfeld @ 2022-07-12 16:46 UTC (permalink / raw)
  To: linux-s390, qemu-devel
  Cc: Jason A. Donenfeld, Thomas Huth, Richard Henderson,
	Harald Freudenberger, Holger Dengler

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


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

end of thread, other threads:[~2022-09-21 11:04 UTC | newest]

Thread overview: 53+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-12 16:46 [PATCH qemu] target/s390x: support PRNO_TRNG instruction Jason A. Donenfeld
2022-07-19  9:54 ` David Hildenbrand
2022-07-19 11:23   ` Jason A. Donenfeld
2022-07-19 11:43     ` [PATCH v2] " Jason A. Donenfeld
2022-07-20 11:43       ` David Hildenbrand
2022-07-20 11:58         ` Jason A. Donenfeld
2022-07-20 12:08           ` [PATCH v3] " Jason A. Donenfeld
2022-07-20 18:41             ` David Hildenbrand
2022-07-20 19:44               ` Jason A. Donenfeld
2022-07-27  1:35               ` Jason A. Donenfeld
2022-07-27  6:32                 ` Thomas Huth
2022-07-27 11:58                   ` Jason A. Donenfeld
2022-08-02 13:26             ` Christian Borntraeger
2022-08-02 13:54               ` David Hildenbrand
2022-08-02 14:01                 ` Christian Borntraeger
2022-08-02 14:53                   ` David Hildenbrand
2022-08-02 15:15                     ` Christian Borntraeger
2022-08-02 15:16                       ` David Hildenbrand
2022-08-02 15:28                         ` Jason A. Donenfeld
2022-08-02 15:32                           ` David Hildenbrand
2022-08-02 18:59                             ` Jason A. Donenfeld
2022-08-02 19:00                               ` [PATCH v4 0/2] MSA EXT 5 for s390x Jason A. Donenfeld
2022-08-02 19:00                                 ` [PATCH v4 1/2] target/s390x: support PRNO_TRNG instruction Jason A. Donenfeld
2022-08-02 19:00                                 ` [PATCH v4 2/2] target/s390x: support SHA-512 extensions Jason A. Donenfeld
2022-08-03 11:55                                   ` David Hildenbrand
2022-08-03 12:14                                     ` Jason A. Donenfeld
2022-08-03 12:47                                       ` Jason A. Donenfeld
2022-08-03 12:51                                         ` [PATCH v5 1/2] target/s390x: support PRNO_TRNG instruction Jason A. Donenfeld
2022-08-03 12:51                                           ` [PATCH v5 2/2] target/s390x: support SHA-512 extensions Jason A. Donenfeld
2022-08-03 17:15                                             ` [PATCH 1/2] target/s390x: support PRNO_TRNG instruction Jason A. Donenfeld
2022-08-03 17:15                                               ` [PATCH 2/2] target/s390x: support SHA-512 extensions Jason A. Donenfeld
2022-08-03 17:15                                             ` [PATCH v6 1/2] target/s390x: support PRNO_TRNG instruction Jason A. Donenfeld
2022-08-03 17:15                                               ` [PATCH v6 2/2] target/s390x: support SHA-512 extensions Jason A. Donenfeld
2022-08-05 11:28                                                 ` David Hildenbrand
2022-08-05 13:01                                                   ` Jason A. Donenfeld
2022-08-09 15:03                                                     ` [PATCH v7 1/2] " Jason A. Donenfeld
2022-08-09 15:03                                                       ` [PATCH v7 2/2] target/s390x: support PRNO_TRNG instruction Jason A. Donenfeld
2022-08-26 11:28                                                         ` Thomas Huth
2022-08-29 16:29                                                           ` Jason A. Donenfeld
2022-09-21 10:59                                                             ` Thomas Huth
2022-08-26 10:21                                                       ` [PATCH v7 1/2] target/s390x: support SHA-512 extensions Thomas Huth
2022-08-29 16:27                                                         ` Jason A. Donenfeld
2022-08-11 16:37                                                     ` [PATCH v6 2/2] " David Hildenbrand
2022-08-04  6:51                                       ` [PATCH v4 " Harald Freudenberger
2022-08-04  6:56                                         ` Christian Borntraeger
2022-08-04 12:09                                           ` Jason A. Donenfeld
2022-08-04  8:10                                         ` David Hildenbrand
2022-08-04 12:07                                           ` Jason A. Donenfeld
2022-08-02 17:55             ` [PATCH v3] target/s390x: support PRNO_TRNG instruction Jason A. Donenfeld
2022-07-20 18:01           ` [PATCH v2] " David Hildenbrand
2022-08-02 11:54       ` Harald Freudenberger
2022-07-19 10:00 ` [PATCH qemu] " Thomas Huth
2022-07-19 11:27   ` Jason A. Donenfeld

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.