Skip to contentSkip to conversation

s390x fixes

GIT PULL Applied Thomas Huth 2 participants 5 messages Aug 3, 2021 – Aug 4, 2021

lore
Share & tools
lore
#0 lore raw

Hi Peter!

The following changes since commit 7f1cab9c628a798ae2607940993771e6300e9e00:

Merge remote-tracking branch 'remotes/bonzini-gitlab/tags/for-upstream' into staging (2021-08-02 17:21:50 +0100)

are available in the Git repository at:

https://gitlab.com/thuth/qemu.git tags/pull-request-2021-08-03

for you to fetch changes up to 50e36dd61652a4a4f2af245655ed3ca08ef0a3ed:

tests/tcg: Test that compare-and-trap raises SIGFPE (2021-08-03 15:17:38 +0200)

----------------------------------------------------------------
* Fixes for SIGILL and SIGFPE of the s390x linux-user target

----------------------------------------------------------------
Ilya Leoshkevich (1):

      target/s390x: Fix SIGILL and SIGFPE psw.addr reporting

Jonathan Albrecht (2):
linux-user/s390x: signal with SIGFPE on compare-and-trap tests/tcg: Test that compare-and-trap raises SIGFPE

 linux-user/s390x/cpu_loop.c     |  66 +++++++++++++++++---------
 tests/tcg/s390x/Makefile.target |   2 +-
 tests/tcg/s390x/trap.c          | 102 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 148 insertions(+), 22 deletions(-)
 create mode 100644 tests/tcg/s390x/trap.c
#1 lore raw

[PULL 1/3] target/s390x: Fix SIGILL and SIGFPE psw.addr reporting

From: Ilya Leoshkevich <[email protected]>

For SIGILL, SIGFPE and SIGTRAP the PSW must point after the instruction, and at the instruction for other signals. Currently under qemu-user for SIGFILL and SIGFPE it points at the instruction.

Fix by advancing psw.addr for these signals.

Message-Id: <[email protected]>

---
 linux-user/s390x/cpu_loop.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
linux-user/s390x/cpu_loop.c +11 -1
index f2d1215fb1..22f2e89c62 100644
@@ -64,7 +64,13 @@ void cpu_loop(CPUS390XState *env)
         case EXCP_DEBUG:
             sig = TARGET_SIGTRAP;
             n = TARGET_TRAP_BRKPT;
-            goto do_signal_pc;
+            /*
+             * For SIGTRAP the PSW must point after the instruction, which it
+             * already does thanks to s390x_tr_tb_stop(). si_addr doesn't need
+             * to be filled.
+             */
+            addr = 0;
+            goto do_signal;
         case EXCP_PGM:
             n = env->int_pgm_code;
             switch (n) {
@@ -132,6 +138,10 @@ void cpu_loop(CPUS390XState *env)
 
         do_signal_pc:
             addr = env->psw.addr;
+            /*
+             * For SIGILL and SIGFPE the PSW must point after the instruction.
+             */
+            env->psw.addr += env->int_pgm_ilen;
         do_signal:
             info.si_signo = sig;
             info.si_errno = 0;
Signature · 1 line
2.27.0
#2 lore raw

[PULL 3/3] tests/tcg: Test that compare-and-trap raises SIGFPE

In reply to Thomas Huth

From: Jonathan Albrecht <[email protected]>

Message-Id: <[email protected]>

---
 tests/tcg/s390x/Makefile.target |   2 +-
 tests/tcg/s390x/trap.c          | 102 ++++++++++++++++++++++++++++++++
 2 files changed, 103 insertions(+), 1 deletion(-)
 create mode 100644 tests/tcg/s390x/trap.c
tests/tcg/s390x/Makefile.target +1 -1
index 5d3de1b27a..bd084c7840 100644
@@ -8,4 +8,4 @@ TESTS+=exrl-trtr
 TESTS+=pack
 TESTS+=mvo
 TESTS+=mvc
-
+TESTS+=trap
tests/tcg/s390x/trap.c new file +102 -0

102 lines not on this page · raw message

Signature · 1 line
2.27.0
#3 lore raw

[PULL 2/3] linux-user/s390x: signal with SIGFPE on compare-and-trap

In reply to Thomas Huth

From: Jonathan Albrecht <[email protected]>

Currently when a compare-and-trap instruction is executed, qemu will always raise a SIGILL signal. On real hardware, a SIGFPE is raised.

Change the PGM_DATA case in cpu_loop to follow the behavior in linux kernel /arch/s390/kernel/traps.c.
* Only raise SIGILL if DXC == 0
* If DXC matches a non-simulated IEEE exception, raise SIGFPE with correct si_code
* Raise SIGFPE with si_code == 0 for everything else

When applied on [email protected], this fixes crashes in the java jdk such as the linked bug.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/319
Message-Id: <[email protected]>

---
 linux-user/s390x/cpu_loop.c | 54 +++++++++++++++++++++++--------------
 1 file changed, 34 insertions(+), 20 deletions(-)
linux-user/s390x/cpu_loop.c +34 -20
index 22f2e89c62..6a69a6dd26 100644
@@ -25,6 +25,35 @@
 /* s390x masks the fault address it reports in si_addr for SIGSEGV and SIGBUS */
 #define S390X_FAIL_ADDR_MASK -4096LL
 
+static int get_pgm_data_si_code(int dxc_code)
+{
+    switch (dxc_code) {
+    /* Non-simulated IEEE exceptions */
+    case 0x80:
+        return TARGET_FPE_FLTINV;
+    case 0x40:
+        return TARGET_FPE_FLTDIV;
+    case 0x20:
+    case 0x28:
+    case 0x2c:
+        return TARGET_FPE_FLTOVF;
+    case 0x10:
+    case 0x18:
+    case 0x1c:
+        return TARGET_FPE_FLTUND;
+    case 0x08:
+    case 0x0c:
+        return TARGET_FPE_FLTRES;
+    }
+    /*
+     * Non-IEEE and simulated IEEE:
+     * Includes compare-and-trap, quantum exception, etc.
+     * Simulated IEEE are included here to match current
+     * s390x linux kernel.
+     */
+    return 0;
+}
+
 void cpu_loop(CPUS390XState *env)
 {
     CPUState *cs = env_cpu(env);
@@ -106,29 +135,14 @@ void cpu_loop(CPUS390XState *env)
 
             case PGM_DATA:
                 n = (env->fpc >> 8) & 0xff;
-                if (n == 0xff) {
-                    /* compare-and-trap */
+                if (n == 0) {
                     goto do_sigill_opn;
-                } else {
-                    /* An IEEE exception, simulated or otherwise.  */
-                    if (n & 0x80) {
-                        n = TARGET_FPE_FLTINV;
-                    } else if (n & 0x40) {
-                        n = TARGET_FPE_FLTDIV;
-                    } else if (n & 0x20) {
-                        n = TARGET_FPE_FLTOVF;
-                    } else if (n & 0x10) {
-                        n = TARGET_FPE_FLTUND;
-                    } else if (n & 0x08) {
-                        n = TARGET_FPE_FLTRES;
-                    } else {
-                        /* ??? Quantum exception; BFP, DFP error.  */
-                        goto do_sigill_opn;
-                    }
-                    sig = TARGET_SIGFPE;
-                    goto do_signal_pc;
                 }
 
+                sig = TARGET_SIGFPE;
+                n = get_pgm_data_si_code(n);
+                goto do_signal_pc;
+
             default:
                 fprintf(stderr, "Unhandled program exception: %#x\n", n);
                 cpu_dump_state(cs, stderr, 0);
Signature · 1 line
2.27.0
#4 lore raw
In reply to Thomas Huth
Quoted 11 lines · Thomas Huth

Hi Peter!

The following changes since commit 7f1cab9c628a798ae2607940993771e6300e9e00:

Merge remote-tracking branch 'remotes/bonzini-gitlab/tags/for-upstream' into staging (2021-08-02 17:21:50 +0100)

are available in the Git repository at:

https://gitlab.com/thuth/qemu.git tags/pull-request-2021-08-03

Quoted 8 lines

for you to fetch changes up to 50e36dd61652a4a4f2af245655ed3ca08ef0a3ed:

tests/tcg: Test that compare-and-trap raises SIGFPE (2021-08-03 15:17:38 +0200)

----------------------------------------------------------------
* Fixes for SIGILL and SIGFPE of the s390x linux-user target

----------------------------------------------------------------

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/6.1
for any user-visible changes.

-- PMM