Skip to contentSkip to conversation

linux-user/s390x: signal with SIGFPE on compare-and-trap

PATCH Superseded Jonathan Albrecht 4 participants 7 messages Jun 21, 2021 – Jul 6, 2021

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover linux-user/s390x: signal with SIGFPE on compare-and-trap

qemu-s390x signals with SIGILL on compare-and-trap instructions. This breaks OpenJDK which expects SIGFPE in its implementation of implicit exceptions.

This patch depends on [PATCH v3 0/2] target/s390x: Fix SIGILL psw.addr reporting.
https://lore.kernel.org/qemu-devel/[email protected]/

Based-on: [email protected]

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     |  19 +++---
 tests/tcg/s390x/Makefile.target |   1 +
 tests/tcg/s390x/trap.c          | 100 ++++++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+), 9 deletions(-)
 create mode 100644 tests/tcg/s390x/trap.c
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/2 linux-user/s390x: signal with SIGFPE on compare-and-trap

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 an 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

---
 linux-user/s390x/cpu_loop.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
linux-user/s390x/cpu_loop.c +10 -9
index 72ba9170ed..def5c046f7 100644
@@ -117,11 +117,13 @@ 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.  */
+                }
+
+                sig = TARGET_SIGFPE;
+                if ((n & 0x03) == 0) {
+                    /* An IEEE exception, simulated or otherwise. */
                     if (n & 0x80) {
                         n = TARGET_FPE_FLTINV;
                     } else if (n & 0x40) {
@@ -132,13 +134,12 @@ void cpu_loop(CPUS390XState *env)
                         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;
+                } else {
+                    /* compare-and-trap */
+                    n = 0;
                 }
+                goto do_signal_pc;
 
             default:
                 fprintf(stderr, "Unhandled program exception: %#x\n", n);
Signature · 1 line
2.31.1
Acked-by Tested-by on v1 1/2
#2 lore raw
Quoted 12 lines · Jonathan Albrecht

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 an 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.

Quoted 7 lines

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/319
Signed-off-by: Jonathan Albrecht < [email protected]>
---
 linux-user/s390x/cpu_loop.c | 19 ++++++++++---------

 1 file changed, 10 insertions(+), 9 deletions(-)

I tried this on top of my SIGILL patch to run Maven, it worked without issues.

#3 lore raw

PATCH 2/2 tests/tcg: Test that compare-and-trap raises SIGFPE

In reply to Jonathan Albrecht
---
 tests/tcg/s390x/Makefile.target |   1 +
 tests/tcg/s390x/trap.c          | 100 ++++++++++++++++++++++++++++++++
 2 files changed, 101 insertions(+)
 create mode 100644 tests/tcg/s390x/trap.c
tests/tcg/s390x/Makefile.target +1 -0
index cdb7d85316..4bd6db6679 100644
@@ -9,3 +9,4 @@ TESTS+=pack
 TESTS+=mvo
 TESTS+=mvc
 TESTS+=signal
+TESTS+=trap
tests/tcg/s390x/trap.c new file +100 -0

100 lines not on this page · raw message

Signature · 1 line
2.31.1
#4 lore raw
In reply to Jonathan Albrecht
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [PATCH 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu

 - [tag update]      patchew/[email protected] -> patchew/[email protected]
 - [tag update]      patchew/[email protected] -> patchew/[email protected]
 * [new tag]         patchew/[email protected] -> patchew/[email protected]

Switched to a new branch 'test'
c6b3ba6 tests/tcg: Test that compare-and-trap raises SIGFPE 7bab442 linux-user/s390x: signal with SIGFPE on compare-and-trap

=== OUTPUT BEGIN ===
1/2 Checking commit 7bab4427a5e9 (linux-user/s390x: signal with SIGFPE on compare-and-trap) 2/2 Checking commit c6b3ba625805 (tests/tcg: Test that compare-and-trap raises SIGFPE)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #25:
new file mode 100644

ERROR: do not initialise globals to 0 or NULL
#71: FILE: tests/tcg/s390x/trap.c:42:
+int sigfpe_count = 0;

ERROR: do not initialise globals to 0 or NULL
#72: FILE: tests/tcg/s390x/trap.c:43:
+int sigill_count = 0;

ERROR: trailing whitespace
#83: FILE: tests/tcg/s390x/trap.c:54:
+ $

ERROR: trailing whitespace
#116: FILE: tests/tcg/s390x/trap.c:87:
+ : $

total: 4 errors, 1 warnings, 104 lines checked

Patch 2/2 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

Acked-by on the v1 series
#5 lore raw
In reply to Jonathan Albrecht
Quoted 14 lines · Jonathan Albrecht

qemu-s390x signals with SIGILL on compare-and-trap instructions. This breaks OpenJDK which expects SIGFPE in its implementation of implicit exceptions.

This patch depends on [PATCH v3 0/2] target/s390x: Fix SIGILL psw.addr reporting.
https://lore.kernel.org/qemu-devel/[email protected]/

Based-on: [email protected]

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

Quoted 5 lines
 linux-user/s390x/cpu_loop.c     |  19 +++---
 tests/tcg/s390x/Makefile.target |   1 +
 tests/tcg/s390x/trap.c          | 100 ++++++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+), 9 deletions(-)
 create mode 100644 tests/tcg/s390x/trap.c

Assuming that this will also go through the linux-user tree:

#6 lore raw
Quoted 24 lines · Cornelia Huck
Quoted 14 lines · Jonathan Albrecht

qemu-s390x signals with SIGILL on compare-and-trap instructions. This breaks OpenJDK which expects SIGFPE in its implementation of implicit exceptions.

This patch depends on [PATCH v3 0/2] target/s390x: Fix SIGILL psw.addr reporting.
https://lore.kernel.org/qemu-devel/[email protected]/

Based-on: [email protected]

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

Quoted 6 lines
 linux-user/s390x/cpu_loop.c     |  19 +++---
 tests/tcg/s390x/Makefile.target |   1 +
 tests/tcg/s390x/trap.c          | 100 
++++++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+), 9 deletions(-)
 create mode 100644 tests/tcg/s390x/trap.c
Quoted 3 lines

Assuming that this will also go through the linux-user tree:

Thanks and yes, IIUC, https://lore.kernel.org/qemu-devel/[email protected]/
is going through the linux-user tree so this should as well.

I'm going to send a v2 of this patch shortly to fix conflicts with the latest tests/tcg/s390x/Makefile.target changes.

Jon