All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap
@ 2021-06-21 14:14 Jonathan Albrecht
  2021-06-21 14:14 ` [PATCH 1/2] " Jonathan Albrecht
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Jonathan Albrecht @ 2021-06-21 14:14 UTC (permalink / raw)
  To: qemu-devel
  Cc: 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 v3 0/2] target/s390x: Fix SIGILL psw.addr
reporting.
https://lore.kernel.org/qemu-devel/20210602002210.3144559-1-iii@linux.ibm.com/

Based-on: 20210602002210.3144559-1-iii@linux.ibm.com

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

-- 
2.31.1



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] linux-user/s390x: signal with SIGFPE on compare-and-trap
  2021-06-21 14:14 [PATCH 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap Jonathan Albrecht
@ 2021-06-21 14:14 ` Jonathan Albrecht
  2021-06-23  2:27   ` Ilya Leoshkevich
  2021-06-21 14:14 ` [PATCH 2/2] tests/tcg: Test that compare-and-trap raises SIGFPE Jonathan Albrecht
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Jonathan Albrecht @ 2021-06-21 14:14 UTC (permalink / raw)
  To: qemu-devel
  Cc: 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 an IEEE exception, raise SIGFPE with correct si_code
 * Raise SIGFPE with si_code == 0 for everything else

When applied on 20210602002210.3144559-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 | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/linux-user/s390x/cpu_loop.c b/linux-user/s390x/cpu_loop.c
index 72ba9170ed..def5c046f7 100644
--- a/linux-user/s390x/cpu_loop.c
+++ b/linux-user/s390x/cpu_loop.c
@@ -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);
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] tests/tcg: Test that compare-and-trap raises SIGFPE
  2021-06-21 14:14 [PATCH 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap Jonathan Albrecht
  2021-06-21 14:14 ` [PATCH 1/2] " Jonathan Albrecht
@ 2021-06-21 14:14 ` Jonathan Albrecht
  2021-06-21 14:24 ` [PATCH 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap no-reply
  2021-07-05  9:29 ` Cornelia Huck
  3 siblings, 0 replies; 7+ messages in thread
From: Jonathan Albrecht @ 2021-06-21 14:14 UTC (permalink / raw)
  To: qemu-devel
  Cc: 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          | 100 ++++++++++++++++++++++++++++++++
 2 files changed, 101 insertions(+)
 create mode 100644 tests/tcg/s390x/trap.c

diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target
index cdb7d85316..4bd6db6679 100644
--- a/tests/tcg/s390x/Makefile.target
+++ b/tests/tcg/s390x/Makefile.target
@@ -9,3 +9,4 @@ TESTS+=pack
 TESTS+=mvo
 TESTS+=mvc
 TESTS+=signal
+TESTS+=trap
diff --git a/tests/tcg/s390x/trap.c b/tests/tcg/s390x/trap.c
new file mode 100644
index 0000000000..d48ad070d4
--- /dev/null
+++ b/tests/tcg/s390x/trap.c
@@ -0,0 +1,100 @@
+/*
+ * 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 = 0;
+int sigill_count = 0;
+
+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)
+{
+    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 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap
  2021-06-21 14:14 [PATCH 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap Jonathan Albrecht
  2021-06-21 14:14 ` [PATCH 1/2] " Jonathan Albrecht
  2021-06-21 14:14 ` [PATCH 2/2] tests/tcg: Test that compare-and-trap raises SIGFPE Jonathan Albrecht
@ 2021-06-21 14:24 ` no-reply
  2021-07-05  9:29 ` Cornelia Huck
  3 siblings, 0 replies; 7+ messages in thread
From: no-reply @ 2021-06-21 14:24 UTC (permalink / raw)
  To: jonathan.albrecht
  Cc: jonathan.albrecht, iii, david, cohuck, richard.henderson,
	qemu-devel, laurent, borntraeger, qemu-s390x, krebbel

Patchew URL: https://patchew.org/QEMU/20210621141452.2045-1-jonathan.albrecht@linux.vnet.ibm.com/



Hi,

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

Type: series
Message-id: 20210621141452.2045-1-jonathan.albrecht@linux.vnet.ibm.com
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/20210526142438.281477-1-f4bug@amsat.org -> patchew/20210526142438.281477-1-f4bug@amsat.org
 - [tag update]      patchew/20210614083800.1166166-1-richard.henderson@linaro.org -> patchew/20210614083800.1166166-1-richard.henderson@linaro.org
 * [new tag]         patchew/20210621141452.2045-1-jonathan.albrecht@linux.vnet.ibm.com -> patchew/20210621141452.2045-1-jonathan.albrecht@linux.vnet.ibm.com
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/20210621141452.2045-1-jonathan.albrecht@linux.vnet.ibm.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] linux-user/s390x: signal with SIGFPE on compare-and-trap
  2021-06-21 14:14 ` [PATCH 1/2] " Jonathan Albrecht
@ 2021-06-23  2:27   ` Ilya Leoshkevich
  0 siblings, 0 replies; 7+ messages in thread
From: Ilya Leoshkevich @ 2021-06-23  2:27 UTC (permalink / raw)
  To: Jonathan Albrecht, qemu-devel
  Cc: david, cohuck, richard.henderson, laurent, borntraeger,
	qemu-s390x, krebbel

On Mon, 2021-06-21 at 10:14 -0400, 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 an IEEE exception, raise SIGFPE with correct si_code
>  * Raise SIGFPE with si_code == 0 for everything else
> 
> When applied on 20210602002210.3144559-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 | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)

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

Acked-by: Ilya Leoshkevich <iii@linux.ibm.com>
Tested-by: Ilya Leoshkevich <iii@linux.ibm.com>



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap
  2021-06-21 14:14 [PATCH 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap Jonathan Albrecht
                   ` (2 preceding siblings ...)
  2021-06-21 14:24 ` [PATCH 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap no-reply
@ 2021-07-05  9:29 ` Cornelia Huck
  2021-07-06 18:47   ` jonathan.albrecht
  3 siblings, 1 reply; 7+ messages in thread
From: Cornelia Huck @ 2021-07-05  9:29 UTC (permalink / raw)
  To: Jonathan Albrecht, qemu-devel
  Cc: Jonathan Albrecht, iii, david, richard.henderson, laurent,
	borntraeger, qemu-s390x, krebbel

On Mon, Jun 21 2021, Jonathan Albrecht <jonathan.albrecht@linux.vnet.ibm.com> wrote:

> 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/20210602002210.3144559-1-iii@linux.ibm.com/
>
> Based-on: 20210602002210.3144559-1-iii@linux.ibm.com
>
> 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

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

Acked-by: Cornelia Huck <cohuck@redhat.com>



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap
  2021-07-05  9:29 ` Cornelia Huck
@ 2021-07-06 18:47   ` jonathan.albrecht
  0 siblings, 0 replies; 7+ messages in thread
From: jonathan.albrecht @ 2021-07-06 18:47 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: qemu-s390x, iii, david, richard.henderson, laurent, qemu-devel,
	borntraeger, qemu-s390x, krebbel

On 2021-07-05 5:29 am, Cornelia Huck wrote:
> On Mon, Jun 21 2021, Jonathan Albrecht
> <jonathan.albrecht@linux.vnet.ibm.com> wrote:
> 
>> 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/20210602002210.3144559-1-iii@linux.ibm.com/
>> 
>> Based-on: 20210602002210.3144559-1-iii@linux.ibm.com
>> 
>> 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
> 
> Assuming that this will also go through the linux-user tree:
> 
> Acked-by: Cornelia Huck <cohuck@redhat.com>

Thanks and yes, IIUC, 
https://lore.kernel.org/qemu-devel/20210705210434.45824-1-iii@linux.ibm.com/
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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-07-06 18:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-21 14:14 [PATCH 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap Jonathan Albrecht
2021-06-21 14:14 ` [PATCH 1/2] " Jonathan Albrecht
2021-06-23  2:27   ` Ilya Leoshkevich
2021-06-21 14:14 ` [PATCH 2/2] tests/tcg: Test that compare-and-trap raises SIGFPE Jonathan Albrecht
2021-06-21 14:24 ` [PATCH 0/2] linux-user/s390x: signal with SIGFPE on compare-and-trap no-reply
2021-07-05  9:29 ` Cornelia Huck
2021-07-06 18:47   ` jonathan.albrecht

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.