From nobody Wed May 15 18:24:20 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625665482232195.5773646541395; Wed, 7 Jul 2021 06:44:42 -0700 (PDT) Received: from localhost ([::1]:37012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m17qw-0002a0-8g for importer@patchew.org; Wed, 07 Jul 2021 09:44:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44804) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m17pb-0007H3-CI; Wed, 07 Jul 2021 09:43:15 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:19278) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m17pZ-00064i-IQ; Wed, 07 Jul 2021 09:43:15 -0400 Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 167DXLrl149449; Wed, 7 Jul 2021 09:43:11 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 39m8bn8bbd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Jul 2021 09:43:10 -0400 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 167DZi31159527; Wed, 7 Jul 2021 09:43:10 -0400 Received: from ppma03wdc.us.ibm.com (ba.79.3fa9.ip4.static.sl-reverse.com [169.63.121.186]) by mx0a-001b2d01.pphosted.com with ESMTP id 39m8bn8bar-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Jul 2021 09:43:10 -0400 Received: from pps.filterd (ppma03wdc.us.ibm.com [127.0.0.1]) by ppma03wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 167DXw3D014477; Wed, 7 Jul 2021 13:43:09 GMT Received: from b01cxnp23034.gho.pok.ibm.com (b01cxnp23034.gho.pok.ibm.com [9.57.198.29]) by ppma03wdc.us.ibm.com with ESMTP id 39jfhc3m1p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Jul 2021 13:43:09 +0000 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 167Dh7om31064528 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 7 Jul 2021 13:43:08 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DBE1628064; Wed, 7 Jul 2021 13:43:07 +0000 (GMT) Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2ECF02805C; Wed, 7 Jul 2021 13:43:07 +0000 (GMT) Received: from LAPTOP-K4LLPL5U.localdomain (unknown [9.77.134.179]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 7 Jul 2021 13:43:07 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : mime-version; s=pp1; bh=nqcs/NsggCxxFDjE6owXYXZXYVHv5F5+XWeYeJFBfso=; b=kTt6tE40AckPUub9TWeS/5X1urLDST3G+UHKB/Sg14k5GiABec/s3eI1esD1C4rP5ZRD E+j8hMJB8r96iqkus/HO+y8mlasLzecD4qx2Ao4zNrykOw451tdinoevC/MQdhzkk7tJ yO3cCpUwllN01wtO8TfCHspyWKxDvUv+Mi5j2LDSIzCaS5ikr3cRahIHHEbUMCF/hezz Ab/EgcLoNQsvispnscmPNH2sfZfZzJT/P93C64XjjXtxX/hAlTcb+4GmoSkLno4gxksS shbfVFCVo9q/Y9VFZRbg4k37jzLEQvPsQcnac8gMreuVlDxALOw4oTpAeb6wb1Yj3UFa ug== From: Jonathan Albrecht To: qemu-devel@nongnu.org Subject: [PATCH v2 1/2] linux-user/s390x: signal with SIGFPE on compare-and-trap Date: Wed, 7 Jul 2021 09:42:30 -0400 Message-Id: <20210707134231.1835-2-jonathan.albrecht@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210707134231.1835-1-jonathan.albrecht@linux.vnet.ibm.com> References: <20210707134231.1835-1-jonathan.albrecht@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Dz4ERQ12hgzdSoPZGScvyMrNmmiWF254 X-Proofpoint-ORIG-GUID: UkTCqfLzxQgQIJIfluJt5TB2q7jiQ18U Content-Transfer-Encoding: quoted-printable X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-07_06:2021-07-06, 2021-07-07 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 impostorscore=0 clxscore=1015 spamscore=0 mlxscore=0 bulkscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107070081 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=148.163.156.1; envelope-from=jonathan.albrecht@linux.vnet.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ruixin.bao@ibm.com, Jonathan Albrecht , iii@linux.ibm.com, david@redhat.com, cohuck@redhat.com, richard.henderson@linaro.org, laurent@vivier.eu, borntraeger@de.ibm.com, qemu-s390x@nongnu.org, krebbel@linux.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625665484644100001 Content-Type: text/plain; charset="utf-8" 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 =3D=3D 0 * If DXC matches an IEEE exception, raise SIGFPE with correct si_code * Raise SIGFPE with si_code =3D=3D 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 --- 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 22f2e89c62..6e7dfb290a 100644 --- a/linux-user/s390x/cpu_loop.c +++ b/linux-user/s390x/cpu_loop.c @@ -106,11 +106,13 @@ void cpu_loop(CPUS390XState *env) =20 case PGM_DATA: n =3D (env->fpc >> 8) & 0xff; - if (n =3D=3D 0xff) { - /* compare-and-trap */ + if (n =3D=3D 0) { goto do_sigill_opn; - } else { - /* An IEEE exception, simulated or otherwise. */ + } + + sig =3D TARGET_SIGFPE; + if ((n & 0x03) =3D=3D 0) { + /* An IEEE exception, simulated or otherwise. */ if (n & 0x80) { n =3D TARGET_FPE_FLTINV; } else if (n & 0x40) { @@ -121,13 +123,12 @@ void cpu_loop(CPUS390XState *env) n =3D TARGET_FPE_FLTUND; } else if (n & 0x08) { n =3D TARGET_FPE_FLTRES; - } else { - /* ??? Quantum exception; BFP, DFP error. */ - goto do_sigill_opn; } - sig =3D TARGET_SIGFPE; - goto do_signal_pc; + } else { + /* compare-and-trap */ + n =3D 0; } + goto do_signal_pc; =20 default: fprintf(stderr, "Unhandled program exception: %#x\n", n); --=20 2.31.1 From nobody Wed May 15 18:24:20 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625665462982540.5789901952584; Wed, 7 Jul 2021 06:44:22 -0700 (PDT) Received: from localhost ([::1]:35550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m17qf-0001cy-Vg for importer@patchew.org; Wed, 07 Jul 2021 09:44:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m17pd-0007MJ-CE; Wed, 07 Jul 2021 09:43:17 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:63826) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m17pb-00064y-Gk; Wed, 07 Jul 2021 09:43:17 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 167DXtvf165678; Wed, 7 Jul 2021 09:43:13 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 39mts0ke9h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Jul 2021 09:43:13 -0400 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 167DY5Fq166214; Wed, 7 Jul 2021 09:43:13 -0400 Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0a-001b2d01.pphosted.com with ESMTP id 39mts0ke96-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Jul 2021 09:43:12 -0400 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 167DXwVb012938; Wed, 7 Jul 2021 13:43:12 GMT Received: from b01cxnp22033.gho.pok.ibm.com (b01cxnp22033.gho.pok.ibm.com [9.57.198.23]) by ppma04dal.us.ibm.com with ESMTP id 39jfhd27f1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Jul 2021 13:43:12 +0000 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 167DhAQr35979622 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 7 Jul 2021 13:43:11 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DBE192805A; Wed, 7 Jul 2021 13:43:10 +0000 (GMT) Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3DF5F28065; Wed, 7 Jul 2021 13:43:10 +0000 (GMT) Received: from LAPTOP-K4LLPL5U.localdomain (unknown [9.77.134.179]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 7 Jul 2021 13:43:10 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=PPvyftQaSoVUV5zvRZWbw99RoIbePRuZu1v4EQhjEOA=; b=kWalRqnWCsvT5tLc4mXCKf7UUt4B8j1Y6qwAanTDfSVpVKKR1O2wD7Y9PtO2rUM3CsNK L/u7j1xh4IWJNFFp7PX6zNDRCTyXcW6dm4+Afi8GHWWkZeyHa9+CmTZNfQ8PLNfsyWQ+ L/ozndooPSCZE6fRapL87Zc3sCq0uvXfAVGbBMJ4YthOPWilDK7AIEMjR6Xisbv1t4mB Sfz0nH+lM7YJpJflt4Cx4QJh4X5ZX3Tl/nUbRWOf1kcn4KdFJl3GQ3nYTJVk9LiHCHTf 0KiNQ8kMvnSmFUM3CYjSC1WuhXVfPUH33eWp6uAdglVKNExTpifwiEOLInW6nMHJm7rY CQ== From: Jonathan Albrecht To: qemu-devel@nongnu.org Subject: [PATCH v2 2/2] tests/tcg: Test that compare-and-trap raises SIGFPE Date: Wed, 7 Jul 2021 09:42:31 -0400 Message-Id: <20210707134231.1835-3-jonathan.albrecht@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210707134231.1835-1-jonathan.albrecht@linux.vnet.ibm.com> References: <20210707134231.1835-1-jonathan.albrecht@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 2R3JQxPkfue5HQcNVcUQVyg3H2Bf9M18 X-Proofpoint-GUID: CaPXvVMZKGPPzzxsUxOLfGCqTPyJBglK X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-07_06:2021-07-06, 2021-07-07 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 spamscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 priorityscore=1501 clxscore=1015 adultscore=0 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107070081 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=148.163.156.1; envelope-from=jonathan.albrecht@linux.vnet.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ruixin.bao@ibm.com, Jonathan Albrecht , iii@linux.ibm.com, david@redhat.com, cohuck@redhat.com, richard.henderson@linaro.org, laurent@vivier.eu, borntraeger@de.ibm.com, qemu-s390x@nongnu.org, krebbel@linux.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625665464954100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jonathan Albrecht Reviewed-by: Richard Henderson --- 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.tar= get index 0a5b25c156..d440ecd6f7 100644 --- a/tests/tcg/s390x/Makefile.target +++ b/tests/tcg/s390x/Makefile.target @@ -9,6 +9,7 @@ TESTS+=3Dexrl-trtr TESTS+=3Dpack TESTS+=3Dmvo TESTS+=3Dmvc +TESTS+=3Dtrap =20 # 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 +#include +#include +#include +#include +#include +#include +#include + +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=3D%d, errno=3D%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 =3D=3D SIGFPE) { + if (si->si_code !=3D 0) { + error("unexpected si_code: 0x%x !=3D 0", si->si_code); + } + ++sigfpe_count; + return; + } + + if (sig =3D=3D SIGILL) { + ++sigill_count; + return; + } + + error("unexpected signal 0x%x\n", sig); +} + +int main(int argc, char **argv) +{ + sigfpe_count =3D sigill_count =3D 0; + + struct sigaction act; + + /* Set up SIG handler */ + act.sa_sigaction =3D sig_handler; + sigemptyset(&act.sa_mask); + act.sa_flags =3D SA_SIGINFO; + chk_error(sigaction(SIGFPE, &act, NULL)); + chk_error(sigaction(SIGILL, &act, NULL)); + + uint64_t z =3D 0x0ull; + uint64_t lz =3D 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 !=3D 2) { + error("unexpected SIGFPE count: %d !=3D 2", sigfpe_count); + } + if (sigill_count !=3D 0) { + error("unexpected SIGILL count: %d !=3D 0", sigill_count); + } + + printf("PASS\n"); + return 0; +} --=20 2.31.1