From: Eric Farman <farman@linux.ibm.com>
To: qemu-devel@nongnu.org
Cc: qemu-s390x@nongnu.org, Matthew Rosato <mjrosato@linux.ibm.com>,
Cornelia Huck <cohuck@redhat.com>,
Ilya Leoshkevich <iii@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
qemu-stable@nongnu.org,
Richard Henderson <richard.henderson@linaro.org>,
Harald Freudenberger <freude@linux.ibm.com>,
Eric Farman <farman@linux.ibm.com>
Subject: [PULL 01/15] target/s390x: Make PRNO TRNG interruptible
Date: Wed, 12 Aug 2026 13:16:53 -0400 [thread overview]
Message-ID: <20260812171707.1605637-2-farman@linux.ibm.com> (raw)
In-Reply-To: <20260812171707.1605637-1-farman@linux.ibm.com>
From: Ilya Leoshkevich <iii@linux.ibm.com>
fill_buf_random() writes the entire guest-requested amount of random
bytes in one go. Since the length is a full 64-bit value, a guest can
request several gigabytes and keep the vCPU spinning inside the helper,
without a chance to react to interrupts.
Do the same thing as HELPER(mvcl): check cpu_loop_exit_requested() at the
bottom of the loop, and when a return to the main loop is pending, stop
and report partial completion with condition code 3.
Reported-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Fixes: 3dbc5fdacb5a ("target/s390x: support PRNO_TRNG instruction")
Cc: qemu-stable@nongnu.org
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Harald Freudenberger <freude@linux.ibm.com>
Link: https://lore.kernel.org/qemu-devel/20260714191948.342204-2-iii@linux.ibm.com
Signed-off-by: Eric Farman <farman@linux.ibm.com>
---
target/s390x/tcg/crypto_helper.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/target/s390x/tcg/crypto_helper.c b/target/s390x/tcg/crypto_helper.c
index 8fe0a22219..6a5dbe1caf 100644
--- a/target/s390x/tcg/crypto_helper.c
+++ b/target/s390x/tcg/crypto_helper.c
@@ -16,6 +16,7 @@
#include "qemu/guest-random.h"
#include "s390x-internal.h"
#include "tcg_s390x.h"
+#include "exec/cpu-common.h"
#include "exec/helper-proto.h"
#include "accel/tcg/cpu-ldst-common.h"
#include "accel/tcg/cpu-mmu-index.h"
@@ -242,8 +243,8 @@ static int cpacf_sha512(CPUS390XState *env, const int mmu_idx, uintptr_t ra,
return !len ? 0 : 3;
}
-static void fill_buf_random(CPUS390XState *env, const int mmu_idx, uintptr_t ra,
- uint64_t *buf_reg, uint64_t *len_reg)
+static int fill_buf_random(CPUS390XState *env, const int mmu_idx, uintptr_t ra,
+ uint64_t *buf_reg, uint64_t *len_reg)
{
const MemOpIdx oi = make_memop_idx(MO_8, mmu_idx);
uint8_t tmp[256];
@@ -265,7 +266,13 @@ static void fill_buf_random(CPUS390XState *env, const int mmu_idx, uintptr_t ra,
--*len_reg;
}
len -= block;
+
+ if (cpu_loop_exit_requested(env_cpu(env))) {
+ break;
+ }
}
+
+ return len == 0 ? 0 : 3;
}
uint32_t HELPER(msa)(CPUS390XState *env, uint32_t r1, uint32_t r2, uint32_t r3,
@@ -278,6 +285,7 @@ uint32_t HELPER(msa)(CPUS390XState *env, uint32_t r1, uint32_t r2, uint32_t r3,
uint8_t subfunc[16] = { 0 };
uint64_t param_addr;
MemOpIdx oi;
+ int cc;
switch (type) {
case S390_FEAT_TYPE_KMAC:
@@ -308,9 +316,13 @@ uint32_t HELPER(msa)(CPUS390XState *env, uint32_t r1, uint32_t r2, uint32_t r3,
return cpacf_sha512(env, mmu_idx, ra, env->regs[1], &env->regs[r2],
&env->regs[r2 + 1], type);
case 114: /* CPACF_PRNO_TRNG */
- fill_buf_random(env, mmu_idx, ra, &env->regs[r1], &env->regs[r1 + 1]);
- fill_buf_random(env, mmu_idx, ra, &env->regs[r2], &env->regs[r2 + 1]);
- break;
+ cc = fill_buf_random(env, mmu_idx, ra,
+ &env->regs[r1], &env->regs[r1 + 1]);
+ if (cc == 0) {
+ cc = fill_buf_random(env, mmu_idx, ra,
+ &env->regs[r2], &env->regs[r2 + 1]);
+ }
+ return cc;
default:
/* we don't implement any other subfunction yet */
g_assert_not_reached();
--
2.55.0
next prev parent reply other threads:[~2026-08-12 17:20 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-12 17:16 [PULL 00/15] s390x queue Eric Farman
2026-08-12 17:16 ` Eric Farman [this message]
2026-08-12 17:16 ` [PULL 02/15] tests/tcg/s390x: Test PRNO TRNG interruptibility Eric Farman
2026-08-12 17:16 ` [PULL 03/15] target/s390x: Fix DR/D INT64_MIN / -1 host crash Eric Farman
2026-08-12 17:16 ` [PULL 04/15] tests/tcg/s390x: Test DR overflow (INT64_MIN / -1) Eric Farman
2026-08-12 17:16 ` [PULL 05/15] hw/char/sclpconsole-lm: avoid guest triggerable assert Eric Farman
2026-08-12 17:16 ` [PULL 06/15] s390x/ipl: validate num_comp against iplb length before iterating Eric Farman
2026-08-12 17:16 ` [PULL 07/15] pc-bios/s390-ccw: fix out-of-bounds read in iso_get_file_size() Eric Farman
2026-08-12 17:17 ` [PULL 08/15] pc-bios/s390-ccw: bounds-check zipl menu entry index before array write Eric Farman
2026-08-12 17:17 ` [PULL 09/15] pc-bios/s390-ccw: bound zipl menu strlen and replace VLA in zipl_print_entry Eric Farman
2026-08-12 17:17 ` [PULL 10/15] pc-bios/s390-ccw: Fix off-by-one errors with loadparm and boot entries Eric Farman
2026-08-12 17:17 ` [PULL 11/15] target/s390x/tcg: Set STCK/STCKF condition code after the store Eric Farman
2026-08-12 17:17 ` [PULL 12/15] tests/tcg/s390x: Test STCKF condition code on a faulting store Eric Farman
2026-08-12 17:17 ` [PULL 13/15] target/s390x: Allow 2G hugepages guest backing Eric Farman
2026-08-12 17:17 ` [PULL 14/15] hw: add compat machines for 11.2 Eric Farman
2026-08-12 17:17 ` [PULL 15/15] pc-bios/s390-ccw.img: update s390x bios Eric Farman
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=20260812171707.1605637-2-farman@linux.ibm.com \
--to=farman@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=cohuck@redhat.com \
--cc=freude@linux.ibm.com \
--cc=iii@linux.ibm.com \
--cc=mjrosato@linux.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=richard.henderson@linaro.org \
/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 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.