* [PATCH v3 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap
@ 2021-07-09 16:04 Jonathan Albrecht
2021-07-09 16:04 ` [PATCH v3 1/2] " Jonathan Albrecht
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Jonathan Albrecht @ 2021-07-09 16:04 UTC (permalink / raw)
To: qemu-devel
Cc: ruixin.bao, Jonathan Albrecht, iii, david, cohuck,
richard.henderson, laurent, borntraeger, qemu-s390x, krebbel
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 v6 0/2] target/s390x: Fix SIGILL and SIGFPE
psw.addr reporting
https://lore.kernel.org/qemu-devel/20210705210434.45824-1-iii@linux.ibm.com/
Based-on: 20210705210434.45824-1-iii@linux.ibm.com
v1 -> v2:
- Update to latest version of '... psw.addr reporting' patch
- Rebase to master and fix conflicts in tests/tcg/s390x/Makefile.target
v2 -> v3:
- Check for non-simulated IEEE exception DXC codes explicitly when
getting si_codes
- Ensure si_code is set in all cases
- Improve comments
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 | 54 ++++++++++-------
tests/tcg/s390x/Makefile.target | 1 +
tests/tcg/s390x/trap.c | 102 ++++++++++++++++++++++++++++++++
3 files changed, 137 insertions(+), 20 deletions(-)
create mode 100644 tests/tcg/s390x/trap.c
--
2.31.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3 1/2] linux-user/s390x: signal with SIGFPE on compare-and-trap
2021-07-09 16:04 [PATCH v3 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap Jonathan Albrecht
@ 2021-07-09 16:04 ` Jonathan Albrecht
2021-07-09 16:50 ` Richard Henderson
2021-07-09 16:04 ` [PATCH v3 2/2] tests/tcg: Test that compare-and-trap raises SIGFPE Jonathan Albrecht
2021-07-12 20:02 ` [PATCH v3 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap Laurent Vivier
2 siblings, 1 reply; 7+ messages in thread
From: Jonathan Albrecht @ 2021-07-09 16:04 UTC (permalink / raw)
To: qemu-devel
Cc: ruixin.bao, Jonathan Albrecht, iii, david, cohuck,
richard.henderson, laurent, borntraeger, qemu-s390x, krebbel
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 20210705210434.45824-2-iii@linux.ibm.com, this fixes
crashes in the java jdk such as the linked bug.
Buglink: https://bugs.launchpad.net/qemu/+bug/1920913
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/319
Signed-off-by: Jonathan Albrecht <jonathan.albrecht@linux.vnet.ibm.com>
---
linux-user/s390x/cpu_loop.c | 54 +++++++++++++++++++++++--------------
1 file changed, 34 insertions(+), 20 deletions(-)
diff --git a/linux-user/s390x/cpu_loop.c b/linux-user/s390x/cpu_loop.c
index 22f2e89c62..6a69a6dd26 100644
--- a/linux-user/s390x/cpu_loop.c
+++ b/linux-user/s390x/cpu_loop.c
@@ -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);
--
2.31.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 2/2] tests/tcg: Test that compare-and-trap raises SIGFPE
2021-07-09 16:04 [PATCH v3 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap Jonathan Albrecht
2021-07-09 16:04 ` [PATCH v3 1/2] " Jonathan Albrecht
@ 2021-07-09 16:04 ` Jonathan Albrecht
2021-07-12 20:02 ` [PATCH v3 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap Laurent Vivier
2 siblings, 0 replies; 7+ messages in thread
From: Jonathan Albrecht @ 2021-07-09 16:04 UTC (permalink / raw)
To: qemu-devel
Cc: ruixin.bao, Jonathan Albrecht, iii, david, cohuck,
richard.henderson, laurent, borntraeger, qemu-s390x, krebbel
Signed-off-by: Jonathan Albrecht <jonathan.albrecht@linux.vnet.ibm.com>
---
tests/tcg/s390x/Makefile.target | 1 +
tests/tcg/s390x/trap.c | 102 ++++++++++++++++++++++++++++++++
2 files changed, 103 insertions(+)
create mode 100644 tests/tcg/s390x/trap.c
diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target
index 0a5b25c156..d440ecd6f7 100644
--- a/tests/tcg/s390x/Makefile.target
+++ b/tests/tcg/s390x/Makefile.target
@@ -9,6 +9,7 @@ TESTS+=exrl-trtr
TESTS+=pack
TESTS+=mvo
TESTS+=mvc
+TESTS+=trap
# This triggers failures on s390x hosts about 4% of the time
run-signals: signals
diff --git a/tests/tcg/s390x/trap.c b/tests/tcg/s390x/trap.c
new file mode 100644
index 0000000000..d4c61c7f52
--- /dev/null
+++ b/tests/tcg/s390x/trap.c
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2021 IBM Corp.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <signal.h>
+
+static void error1(const char *filename, int line, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ fprintf(stderr, "%s:%d: ", filename, line);
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, "\n");
+ va_end(ap);
+ exit(1);
+}
+
+static int __chk_error(const char *filename, int line, int ret)
+{
+ if (ret < 0) {
+ error1(filename, line, "%m (ret=%d, errno=%d/%s)",
+ ret, errno, strerror(errno));
+ }
+ return ret;
+}
+
+#define error(fmt, ...) error1(__FILE__, __LINE__, fmt, ## __VA_ARGS__)
+
+#define chk_error(ret) __chk_error(__FILE__, __LINE__, (ret))
+
+int sigfpe_count;
+int sigill_count;
+
+static void sig_handler(int sig, siginfo_t *si, void *puc)
+{
+ if (sig == SIGFPE) {
+ if (si->si_code != 0) {
+ error("unexpected si_code: 0x%x != 0", si->si_code);
+ }
+ ++sigfpe_count;
+ return;
+ }
+
+ if (sig == SIGILL) {
+ ++sigill_count;
+ return;
+ }
+
+ error("unexpected signal 0x%x\n", sig);
+}
+
+int main(int argc, char **argv)
+{
+ sigfpe_count = sigill_count = 0;
+
+ struct sigaction act;
+
+ /* Set up SIG handler */
+ act.sa_sigaction = sig_handler;
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = SA_SIGINFO;
+ chk_error(sigaction(SIGFPE, &act, NULL));
+ chk_error(sigaction(SIGILL, &act, NULL));
+
+ uint64_t z = 0x0ull;
+ uint64_t lz = 0xffffffffffffffffull;
+ asm volatile (
+ "lg %%r13,%[lz]\n"
+ "cgitne %%r13,0\n" /* SIGFPE */
+ "lg %%r13,%[z]\n"
+ "cgitne %%r13,0\n" /* no trap */
+ "nopr\n"
+ "lg %%r13,%[lz]\n"
+ "citne %%r13,0\n" /* SIGFPE */
+ "lg %%r13,%[z]\n"
+ "citne %%r13,0\n" /* no trap */
+ "nopr\n"
+ :
+ : [z] "m" (z), [lz] "m" (lz)
+ : "memory", "r13");
+
+ if (sigfpe_count != 2) {
+ error("unexpected SIGFPE count: %d != 2", sigfpe_count);
+ }
+ if (sigill_count != 0) {
+ error("unexpected SIGILL count: %d != 0", sigill_count);
+ }
+
+ printf("PASS\n");
+ return 0;
+}
--
2.31.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3 1/2] linux-user/s390x: signal with SIGFPE on compare-and-trap
2021-07-09 16:04 ` [PATCH v3 1/2] " Jonathan Albrecht
@ 2021-07-09 16:50 ` Richard Henderson
0 siblings, 0 replies; 7+ messages in thread
From: Richard Henderson @ 2021-07-09 16:50 UTC (permalink / raw)
To: Jonathan Albrecht, qemu-devel
Cc: ruixin.bao, iii, david, cohuck, laurent, borntraeger, qemu-s390x,
krebbel
On 7/9/21 9:04 AM, Jonathan Albrecht wrote:
> 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 on20210705210434.45824-2-iii@linux.ibm.com, this fixes
> crashes in the java jdk such as the linked bug.
>
> Buglink:https://bugs.launchpad.net/qemu/+bug/1920913
> Resolves:https://gitlab.com/qemu-project/qemu/-/issues/319
> Signed-off-by: Jonathan Albrecht<jonathan.albrecht@linux.vnet.ibm.com>
> ---
> linux-user/s390x/cpu_loop.c | 54 +++++++++++++++++++++++--------------
> 1 file changed, 34 insertions(+), 20 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap
2021-07-09 16:04 [PATCH v3 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap Jonathan Albrecht
2021-07-09 16:04 ` [PATCH v3 1/2] " Jonathan Albrecht
2021-07-09 16:04 ` [PATCH v3 2/2] tests/tcg: Test that compare-and-trap raises SIGFPE Jonathan Albrecht
@ 2021-07-12 20:02 ` Laurent Vivier
2021-07-12 21:29 ` jonathan.albrecht
2 siblings, 1 reply; 7+ messages in thread
From: Laurent Vivier @ 2021-07-12 20:02 UTC (permalink / raw)
To: Jonathan Albrecht, qemu-devel
Cc: ruixin.bao, iii, david, cohuck, richard.henderson, borntraeger,
qemu-s390x, krebbel
Le 09/07/2021 à 18:04, Jonathan Albrecht a écrit :
> 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 v6 0/2] target/s390x: Fix SIGILL and SIGFPE
> psw.addr reporting
> https://lore.kernel.org/qemu-devel/20210705210434.45824-1-iii@linux.ibm.com/
>
> Based-on: 20210705210434.45824-1-iii@linux.ibm.com
>
> v1 -> v2:
> - Update to latest version of '... psw.addr reporting' patch
> - Rebase to master and fix conflicts in tests/tcg/s390x/Makefile.target
>
> v2 -> v3:
> - Check for non-simulated IEEE exception DXC codes explicitly when
> getting si_codes
> - Ensure si_code is set in all cases
> - Improve comments
>
> 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 | 54 ++++++++++-------
> tests/tcg/s390x/Makefile.target | 1 +
> tests/tcg/s390x/trap.c | 102 ++++++++++++++++++++++++++++++++
> 3 files changed, 137 insertions(+), 20 deletions(-)
> create mode 100644 tests/tcg/s390x/trap.c
>
Series applied to my linux-user-for-6.1 branch.
Thanks,
Laurent
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap
2021-07-12 20:02 ` [PATCH v3 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap Laurent Vivier
@ 2021-07-12 21:29 ` jonathan.albrecht
2021-07-13 12:01 ` Laurent Vivier
0 siblings, 1 reply; 7+ messages in thread
From: jonathan.albrecht @ 2021-07-12 21:29 UTC (permalink / raw)
To: Laurent Vivier
Cc: ruixin.bao, iii, david, cohuck, richard.henderson, qemu-devel,
borntraeger, qemu-s390x, krebbel
On 2021-07-12 4:02 pm, Laurent Vivier wrote:
> Le 09/07/2021 à 18:04, Jonathan Albrecht a écrit :
>> 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 v6 0/2] target/s390x: Fix SIGILL and
>> SIGFPE
>> psw.addr reporting
>> https://lore.kernel.org/qemu-devel/20210705210434.45824-1-iii@linux.ibm.com/
>>
>> Based-on: 20210705210434.45824-1-iii@linux.ibm.com
>>
>>
>
> Series applied to my linux-user-for-6.1 branch.
>
Thanks Laurent, I see this series has been applied to
https://github.com/vivier/qemu/commits/linux-user-for-6.1 but the
following series that this is based on also needs to be applied:
https://lore.kernel.org/qemu-devel/20210705210434.45824-1-iii@linux.ibm.com/
Did some local testing and looks like missing that series caused
https://app.travis-ci.com/github/vivier/qemu/jobs/523853464 to fail.
Oh, just saw Ilya's email that the test patch has not been reviewed.
Hopefully that can happen so they can both make it in.
Thanks,
Jon
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap
2021-07-12 21:29 ` jonathan.albrecht
@ 2021-07-13 12:01 ` Laurent Vivier
0 siblings, 0 replies; 7+ messages in thread
From: Laurent Vivier @ 2021-07-13 12:01 UTC (permalink / raw)
To: jonathan.albrecht
Cc: ruixin.bao, iii, david, cohuck, richard.henderson, qemu-devel,
borntraeger, qemu-s390x, krebbel
Le 12/07/2021 à 23:29, jonathan.albrecht a écrit :
> On 2021-07-12 4:02 pm, Laurent Vivier wrote:
>> Le 09/07/2021 à 18:04, Jonathan Albrecht a écrit :
>>> 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 v6 0/2] target/s390x: Fix SIGILL and SIGFPE
>>> psw.addr reporting
>>> https://lore.kernel.org/qemu-devel/20210705210434.45824-1-iii@linux.ibm.com/
>>>
>>> Based-on: 20210705210434.45824-1-iii@linux.ibm.com
>>>
>>>
>>
>> Series applied to my linux-user-for-6.1 branch.
>>
>
> Thanks Laurent, I see this series has been applied to
> https://github.com/vivier/qemu/commits/linux-user-for-6.1 but the following series that this is
> based on also needs to be applied:
>
> https://lore.kernel.org/qemu-devel/20210705210434.45824-1-iii@linux.ibm.com/
>
> Did some local testing and looks like missing that series caused
> https://app.travis-ci.com/github/vivier/qemu/jobs/523853464 to fail.
>
> Oh, just saw Ilya's email that the test patch has not been reviewed. Hopefully that can happen so
> they can both make it in.
I've removed these two patches from my patch queue. I'll do a new one with both series when they
will be ready.
Thanks,
Laurent
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-07-13 12:02 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-09 16:04 [PATCH v3 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap Jonathan Albrecht
2021-07-09 16:04 ` [PATCH v3 1/2] " Jonathan Albrecht
2021-07-09 16:50 ` Richard Henderson
2021-07-09 16:04 ` [PATCH v3 2/2] tests/tcg: Test that compare-and-trap raises SIGFPE Jonathan Albrecht
2021-07-12 20:02 ` [PATCH v3 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap Laurent Vivier
2021-07-12 21:29 ` jonathan.albrecht
2021-07-13 12:01 ` Laurent Vivier
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.