target/s390x: Fix DR/D INT64_MIN / -1 host crash
PATCH 2/2 tests/tcg/s390x: Test DR overflow (INT64_MIN / -1)
In reply to Ilya LeoshkevichCheck that DR with a non-representable quotient raises SIGFPE rather than crashing the emulator.
--- tests/tcg/s390x/div.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
tests/tcg/s390x/div.c +37 -0
@@ -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 }; + registerint32_t r0 asm("r0" ); + registerint32_t r1 asm("r1" ); +int32_t b =-1 ; +int err; + + err =sigaction (SIGFPE , &act,NULL ); +assert (err ==0 ); + signum =-1 ; + + r0 =0x80000000 ; + r1 =0 ; + asmvolatile ("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 ; }
Signature · 1 line
2.55.0
cover target/s390x: Fix DR/D INT64_MIN / -1 host crash
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(-)
Signature · 1 line
2.55.0
PATCH 1/2 target/s390x: Fix DR/D INT64_MIN / -1 host crash
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().
--- target/s390x/tcg/int_helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target/s390x/tcg/int_helper.c +2 -1
@@ -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 ()); }
Signature · 1 line
2.55.0
Quoted 11 lines · Ilya Leoshkevich
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 tohelper_divs32().
Quoted 7 lines
Reported-by Christian Borntraeger<[email protected]>Fixes b4e2bd3563af ("target-s390: Send signals for divide")Signed-off-by Ilya Leoshkevich<[email protected]>--- target/s390x/tcg/int_helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
r~
Re: [PATCH 2/2] tests/tcg/s390x: Test DR overflow (INT64_MIN / -1)
In reply to Ilya LeoshkevichQuoted 7 lines · Ilya Leoshkevich
Check that DR with a non-representable quotient raises SIGFPE rather than crashing the emulator.
Signed-off-by Ilya Leoshkevich<[email protected]>--- tests/tcg/s390x/div.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
r~
Eric Farman
AppliedQuoted 6 lines · 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.
Quoted 6 lines
Best regards,
IlyaIlya Leoshkevich (2):
target/s390x: Fix DR/D INT64_MIN / -1 host crash tests/tcg/s390x: Test DR overflow (INT64_MIN / -1)
Thanks! Applied for 11.2
Quoted 5 lines
target/s390x/tcg/int_helper.c | 3 ++- tests/tcg/s390x/div.c | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-)