* [PATCH 0/2] target/s390x: Fix DR/D INT64_MIN / -1 host crash
@ 2026-07-14 19:02 Ilya Leoshkevich
2026-07-14 19:02 ` [PATCH 1/2] " Ilya Leoshkevich
2026-07-14 19:02 ` [PATCH 2/2] tests/tcg/s390x: Test DR overflow (INT64_MIN / -1) Ilya Leoshkevich
0 siblings, 2 replies; 3+ messages in thread
From: Ilya Leoshkevich @ 2026-07-14 19:02 UTC (permalink / raw)
To: Richard Henderson, Cornelia Huck, Eric Farman, Matthew Rosato
Cc: David Hildenbrand, qemu-s390x, qemu-devel, Ilya Leoshkevich
Hi,
Christian reported that INT64_MIN / -1 crashes the emulator itself
instead of the guest program. This series fixes the issue and adds a
test.
Best regards,
Ilya
Ilya Leoshkevich (2):
target/s390x: Fix DR/D INT64_MIN / -1 host crash
tests/tcg/s390x: Test DR overflow (INT64_MIN / -1)
target/s390x/tcg/int_helper.c | 3 ++-
tests/tcg/s390x/div.c | 37 +++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 1 deletion(-)
--
2.55.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] target/s390x: Fix DR/D INT64_MIN / -1 host crash
2026-07-14 19:02 [PATCH 0/2] target/s390x: Fix DR/D INT64_MIN / -1 host crash Ilya Leoshkevich
@ 2026-07-14 19:02 ` Ilya Leoshkevich
2026-07-14 19:02 ` [PATCH 2/2] tests/tcg/s390x: Test DR overflow (INT64_MIN / -1) Ilya Leoshkevich
1 sibling, 0 replies; 3+ messages in thread
From: Ilya Leoshkevich @ 2026-07-14 19:02 UTC (permalink / raw)
To: Richard Henderson, Cornelia Huck, Eric Farman, Matthew Rosato
Cc: David Hildenbrand, qemu-s390x, qemu-devel, Ilya Leoshkevich,
Christian Borntraeger, qemu-stable
helper_divs32() divides the 64-bit dividend by the 32-bit divisor as a 64-bit
host operation, guarding only against a zero divisor. INT64_MIN / -1 therefore
overflows the host division before the representability check runs; on hosts
that trap this, QEMU is killed with SIGFPE instead of raising the
fixed-point-divide exception the guest expects:
qemu-s390x: QEMU internal SIGFPE {code=INTDIV, addr=...}
helper_divs64() already guards the same case; add the missing check to
helper_divs32().
Reported-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Fixes: b4e2bd3563af ("target-s390: Send signals for divide")
Cc: qemu-stable@nongnu.org
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
target/s390x/tcg/int_helper.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/target/s390x/tcg/int_helper.c b/target/s390x/tcg/int_helper.c
index fbda396f5b4..5aedd1405bf 100644
--- a/target/s390x/tcg/int_helper.c
+++ b/target/s390x/tcg/int_helper.c
@@ -39,7 +39,8 @@ uint64_t HELPER(divs32)(CPUS390XState *env, int64_t a, int64_t b64)
int32_t b = b64;
int64_t q, r;
- if (b == 0) {
+ /* Catch divide by zero, and non-representable quotient (MIN / -1). */
+ if (b == 0 || (b == -1 && a == (1ll << 63))) {
tcg_s390_program_interrupt(env, PGM_FIXPT_DIVIDE, GETPC());
}
--
2.55.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] tests/tcg/s390x: Test DR overflow (INT64_MIN / -1)
2026-07-14 19:02 [PATCH 0/2] target/s390x: Fix DR/D INT64_MIN / -1 host crash Ilya Leoshkevich
2026-07-14 19:02 ` [PATCH 1/2] " Ilya Leoshkevich
@ 2026-07-14 19:02 ` Ilya Leoshkevich
1 sibling, 0 replies; 3+ messages in thread
From: Ilya Leoshkevich @ 2026-07-14 19:02 UTC (permalink / raw)
To: Richard Henderson, Cornelia Huck, Eric Farman, Matthew Rosato
Cc: David Hildenbrand, qemu-s390x, qemu-devel, Ilya Leoshkevich
Check that DR with a non-representable quotient raises SIGFPE rather than
crashing the emulator.
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
tests/tcg/s390x/div.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/tests/tcg/s390x/div.c b/tests/tcg/s390x/div.c
index 6ad9900e082..124c9ecc339 100644
--- a/tests/tcg/s390x/div.c
+++ b/tests/tcg/s390x/div.c
@@ -1,6 +1,15 @@
#include <assert.h>
+#include <signal.h>
#include <stdint.h>
+/* Set asynchronously by the signal handler. */
+static volatile int signum;
+
+static void signal_handler(int n)
+{
+ signum = n;
+}
+
static void test_dr(void)
{
register int32_t r0 asm("r0") = -1;
@@ -65,11 +74,39 @@ static void test_dlgr(void)
assert(r == 1);
}
+/*
+ * The most negative dividend divided by -1 yields a quotient that does not
+ * fit into 32 bits, so DR must raise a fixed-point-divide exception.
+ */
+static void test_dr_overflow(void)
+{
+ struct sigaction act = { .sa_handler = signal_handler };
+ register int32_t r0 asm("r0");
+ register int32_t r1 asm("r1");
+ int32_t b = -1;
+ int err;
+
+ err = sigaction(SIGFPE, &act, NULL);
+ assert(err == 0);
+ signum = -1;
+
+ r0 = 0x80000000;
+ r1 = 0;
+ asm volatile("dr %[r0],%[b]"
+ : [r0] "+r" (r0), [r1] "+r" (r1)
+ : [b] "r" (b)
+ : "cc");
+ assert(signum == SIGFPE);
+
+ signal(SIGFPE, SIG_DFL);
+}
+
int main(void)
{
test_dr();
test_dlr();
test_dsgr();
test_dlgr();
+ test_dr_overflow();
return 0;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-14 19:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-14 19:02 [PATCH 0/2] target/s390x: Fix DR/D INT64_MIN / -1 host crash Ilya Leoshkevich
2026-07-14 19:02 ` [PATCH 1/2] " Ilya Leoshkevich
2026-07-14 19:02 ` [PATCH 2/2] tests/tcg/s390x: Test DR overflow (INT64_MIN / -1) Ilya Leoshkevich
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.