From patchwork Thu Aug 25 10:17:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Liebler X-Patchwork-Id: 1670175 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=lFUb/tAk; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MCzSX1rC2z1yg7 for ; Thu, 25 Aug 2022 20:18:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 79543385841D for ; Thu, 25 Aug 2022 10:18:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 79543385841D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1661422697; bh=eDDvNDnXQnl6siqKXUIjEY3T7hK2ZeNAIxRVb2pSCNQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=lFUb/tAkeKl9sjrurq8G7tg636IJJ1YYdQ4F318kEX3eKtegM/LPvo/RhO5LAVkuz +q1vNhKx2O/3OTwriCQWJT5Tv84UZtZQqDkIbTOMAcJJhzyhkqSyu34Bx/R1IY9ml4 FfH2hsVzQVzNhw54/6P9PTJ9oi1vmssUk8r+bfWo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 1AF173858C2F for ; Thu, 25 Aug 2022 10:17:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1AF173858C2F Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27PAEhtl019741 for ; Thu, 25 Aug 2022 10:17:55 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3j675e839m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 25 Aug 2022 10:17:55 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 27PA7fRt010324 for ; Thu, 25 Aug 2022 10:17:53 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma06ams.nl.ibm.com with ESMTP id 3j2pvj69aj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 25 Aug 2022 10:17:53 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 27PAHot935389782 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Aug 2022 10:17:50 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1BC6F4C044; Thu, 25 Aug 2022 10:17:50 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E91594C040; Thu, 25 Aug 2022 10:17:49 +0000 (GMT) Received: from t3560004.lnxne.boe (unknown [9.152.108.100]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 25 Aug 2022 10:17:49 +0000 (GMT) To: libc-alpha@sourceware.org Subject: [PATCH] S390: Always use svc 0 Date: Thu, 25 Aug 2022 12:17:48 +0200 Message-Id: <20220825101748.2658723-1-stli@linux.ibm.com> X-Mailer: git-send-email 2.36.1 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: oTVqV98JEKgIl6Do27MIpOkxdhZdUMeC X-Proofpoint-ORIG-GUID: oTVqV98JEKgIl6Do27MIpOkxdhZdUMeC X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-25_05,2022-08-22_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=909 spamscore=0 priorityscore=1501 suspectscore=0 clxscore=1015 impostorscore=0 phishscore=0 malwarescore=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208250037 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Stefan Liebler via Libc-alpha From: Stefan Liebler Reply-To: Stefan Liebler Cc: Stefan Liebler Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" On s390x syscalls are triggered by svc instruction. One can pass the syscall number encoded in the instruction "svc 123" or by storing it in r1: lghi r1,123 svc 0 If the syscall number is encoded in the instruction, this can cause broken syscall restarts. Therefore this patch is now just passing the syscall number in r1. See also kernel-commit: "s390/signal: switch to using vdso for sigreturn and syscall restart" https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/arch/s390/[%e2%80%a6]call.c?h=v6.0-rc1&id=df29a7440c4b5c65765c8f60396b3b13063e24e9 As information, the "svc 0" feature was introduced in kernel 2.5.62: commit b5aad611393ef2e132e3648fa4c6e56a9cfa8708 --- sysdeps/unix/sysv/linux/s390/s390-32/clone.S | 14 ++++---- .../unix/sysv/linux/s390/s390-32/getcontext.S | 8 +++-- .../unix/sysv/linux/s390/s390-32/setcontext.S | 8 +++-- .../sysv/linux/s390/s390-32/swapcontext.S | 3 +- sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h | 4 --- sysdeps/unix/sysv/linux/s390/s390-32/vfork.S | 3 +- sysdeps/unix/sysv/linux/s390/s390-64/clone.S | 14 ++++---- .../unix/sysv/linux/s390/s390-64/getcontext.S | 8 +++-- .../unix/sysv/linux/s390/s390-64/setcontext.S | 8 +++-- .../sysv/linux/s390/s390-64/swapcontext.S | 3 +- sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h | 4 --- sysdeps/unix/sysv/linux/s390/s390-64/vfork.S | 3 +- sysdeps/unix/sysv/linux/s390/sysdep.h | 32 ++----------------- 13 files changed, 46 insertions(+), 66 deletions(-) diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/clone.S b/sysdeps/unix/sysv/linux/s390/s390-32/clone.S index 8b7d8dd39b..dc2d663387 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/clone.S +++ b/sysdeps/unix/sysv/linux/s390/s390-32/clone.S @@ -30,9 +30,10 @@ .text ENTRY(__clone) - st %r6,24(%r15) /* store %r6 to save area */ + stm %r6,%r7,24(%r15) /* Save registers. */ + cfi_offset (%r7, -68) cfi_offset (%r6, -72) - ltr %r1,%r2 /* check fn and move to %r1 */ + ltr %r7,%r2 /* check fn and move to %r7 */ jz error /* no NULL function pointers */ lhi %r0,-8 /* Align the child_stack to a ... */ nr %r3,%r0 /* double word boundary and ... */ @@ -43,10 +44,11 @@ ENTRY(__clone) lr %r4,%r6 /* move parent_tid to %r4 */ l %r5,100(%r15) /* load child_tid from stack */ l %r6,96(%r15) /* load tls from stack */ - svc SYS_ify(clone) + lhi %r1,SYS_ify(clone) + svc 0 ltr %r2,%r2 /* check return code */ jz thread_start - l %r6,24(%r15) /* restore %r6 */ + lm %r6,%r7,24(%r15) /* Load registers. */ jm SYSCALL_ERROR_LABEL br %r14 error: @@ -58,11 +60,11 @@ thread_start: cfi_startproc /* Mark r14 as undefined in order to stop unwinding here! */ cfi_undefined (r14) - /* fn is in gpr 1, arg in gpr 0 */ + /* fn is in gpr 7, arg in gpr 0 */ lr %r2,%r0 /* set first parameter to void *arg */ ahi %r15,-96 /* make room on the stack for the save area */ xc 0(4,%r15),0(%r15) - basr %r14,%r1 /* jump to fn */ + basr %r14,%r7 /* jump to fn */ DO_CALL (exit, 1) cfi_endproc diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/getcontext.S b/sysdeps/unix/sysv/linux/s390/s390-32/getcontext.S index 842ea28a4c..8825caa972 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/getcontext.S +++ b/sysdeps/unix/sysv/linux/s390/s390-32/getcontext.S @@ -32,16 +32,18 @@ other than the PRESERVED state. */ ENTRY(__getcontext) - lr %r1,%r2 + lr %r0,%r2 /* rt_sigprocmask (SIG_BLOCK, NULL, &sc->sc_mask, sigsetsize). */ + la %r4,SC_MASK(%r2) la %r2,SIG_BLOCK slr %r3,%r3 - la %r4,SC_MASK(%r1) lhi %r5,_NSIG8 - svc SYS_ify(rt_sigprocmask) + lhi %r1,SYS_ify(rt_sigprocmask) + svc 0 /* Store fpu context. */ + lr %r1,%r0 stfpc SC_FPC(%r1) std %f0,SC_FPRS(%r1) std %f1,SC_FPRS+8(%r1) diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/setcontext.S b/sysdeps/unix/sysv/linux/s390/s390-32/setcontext.S index 83fc2b436f..14251bc39c 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/setcontext.S +++ b/sysdeps/unix/sysv/linux/s390/s390-32/setcontext.S @@ -30,16 +30,18 @@ other than the PRESERVED state. */ ENTRY(__setcontext) - lr %r1,%r2 + lr %r0,%r2 /* rt_sigprocmask (SIG_SETMASK, &sc->sc_mask, NULL, sigsetsize). */ + la %r3,SC_MASK(%r2) la %r2,SIG_SETMASK - la %r3,SC_MASK(%r1) slr %r4,%r4 lhi %r5,_NSIG8 - svc SYS_ify(rt_sigprocmask) + lhi %r1,SYS_ify(rt_sigprocmask) + svc 0 /* Load fpu context. */ + lr %r1,%r0 lfpc SC_FPC(%r1) ld %f0,SC_FPRS(%r1) ld %f1,SC_FPRS+8(%r1) diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/swapcontext.S b/sysdeps/unix/sysv/linux/s390/s390-32/swapcontext.S index def4e8b163..b75bf7596b 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/swapcontext.S +++ b/sysdeps/unix/sysv/linux/s390/s390-32/swapcontext.S @@ -73,7 +73,8 @@ ENTRY(__swapcontext) la %r3,SC_MASK(%r5) la %r4,SC_MASK(%r1) lhi %r5,_NSIG8 - svc SYS_ify(rt_sigprocmask) + lhi %r1,SYS_ify(rt_sigprocmask) + svc 0 /* Load fpu context. */ lr %r5,%r0 diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h b/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h index 967949f231..e41106b377 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h +++ b/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h @@ -155,12 +155,8 @@ lr %r0,%r7; \ l %r7,96(%r15); \ .endif; \ - .if SYS_ify (syscall) < 256; \ - svc SYS_ify (syscall); \ - .else; \ lhi %r1,SYS_ify (syscall); \ svc 0; \ - .endif; \ .if args > 5; \ lr %r7,%r0; \ .endif diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/vfork.S b/sysdeps/unix/sysv/linux/s390/s390-32/vfork.S index bdf8cb9411..76a5570517 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/vfork.S +++ b/sysdeps/unix/sysv/linux/s390/s390-32/vfork.S @@ -28,7 +28,8 @@ ENTRY (__libc_vfork) /* Do vfork system call. */ - svc SYS_ify (vfork) + lhi %r1,SYS_ify (vfork) + svc 0 /* Check for error. */ lhi %r4,-4095 diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/clone.S b/sysdeps/unix/sysv/linux/s390/s390-64/clone.S index 0941a38279..8d33bc28ca 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-64/clone.S +++ b/sysdeps/unix/sysv/linux/s390/s390-64/clone.S @@ -31,9 +31,10 @@ .text ENTRY(__clone) - stg %r6,48(%r15) /* store %r6 to save area */ + stmg %r6,%r7,48(%r15) /* Save registers. */ + cfi_offset (%r7,-104) cfi_offset (%r6,-112) - ltgr %r1,%r2 /* check fn and move to %r1 */ + ltgr %r7,%r2 /* check fn and move to %r7 */ jz error /* no NULL function pointers */ lghi %r0,-16 /* Align the child_stack to a ... */ ngr %r3,%r0 /* double word boundary and ... */ @@ -44,10 +45,11 @@ ENTRY(__clone) lgr %r4,%r6 /* move parent_tid to %r4 */ lg %r5,168(%r15) /* load child_tid from stack */ lg %r6,160(%r15) /* load tls from stack */ - svc SYS_ify(clone) + lghi %r1,SYS_ify (clone) + svc 0 ltgr %r2,%r2 /* check return code */ jz thread_start - lg %r6,48(%r15) /* restore %r6 */ + lmg %r6,%r7,48(%r15) /* Restore registers. */ jgm SYSCALL_ERROR_LABEL br %r14 error: @@ -59,11 +61,11 @@ thread_start: cfi_startproc /* Mark r14 as undefined in order to stop unwinding here! */ cfi_undefined (r14) - /* fn is in gpr 1, arg in gpr 0 */ + /* fn is in gpr 7, arg in gpr 0 */ lgr %r2,%r0 /* set first parameter to void *arg */ aghi %r15,-160 /* make room on the stack for the save area */ xc 0(8,%r15),0(%r15) - basr %r14,%r1 /* jump to fn */ + basr %r14,%r7 /* jump to fn */ DO_CALL (exit, 1) cfi_endproc diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/getcontext.S b/sysdeps/unix/sysv/linux/s390/s390-64/getcontext.S index a0c70dc789..65a34fd3a2 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-64/getcontext.S +++ b/sysdeps/unix/sysv/linux/s390/s390-64/getcontext.S @@ -32,16 +32,18 @@ other than the PRESERVED state. */ ENTRY(__getcontext) - lgr %r1,%r2 + lgr %r0,%r2 /* rt_sigprocmask (SIG_BLOCK, NULL, &sc->sc_mask, sigsetsize). */ + la %r4,SC_MASK(%r2) la %r2,SIG_BLOCK slgr %r3,%r3 - la %r4,SC_MASK(%r1) lghi %r5,_NSIG8 - svc SYS_ify(rt_sigprocmask) + lghi %r1,SYS_ify(rt_sigprocmask) + svc 0 /* Store fpu context. */ + lgr %r1,%r0 stfpc SC_FPC(%r1) std %f0,SC_FPRS(%r1) std %f1,SC_FPRS+8(%r1) diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/setcontext.S b/sysdeps/unix/sysv/linux/s390/s390-64/setcontext.S index b5626b686e..3e32370236 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-64/setcontext.S +++ b/sysdeps/unix/sysv/linux/s390/s390-64/setcontext.S @@ -30,16 +30,18 @@ other than the PRESERVED state. */ ENTRY(__setcontext) - lgr %r1,%r2 + lgr %r0,%r2 /* sigprocmask (SIG_SETMASK, &sc->sc_mask, NULL). */ + la %r3,SC_MASK(%r2) la %r2,SIG_SETMASK - la %r3,SC_MASK(%r1) slgr %r4,%r4 lghi %r5,_NSIG8 - svc SYS_ify(rt_sigprocmask) + lghi %r1,SYS_ify(rt_sigprocmask) + svc 0 /* Load fpu context. */ + lgr %r1,%r0 lfpc SC_FPC(%r1) ld %f0,SC_FPRS(%r1) ld %f1,SC_FPRS+8(%r1) diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/swapcontext.S b/sysdeps/unix/sysv/linux/s390/s390-64/swapcontext.S index 29ee1fb47e..7b56b6cc19 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-64/swapcontext.S +++ b/sysdeps/unix/sysv/linux/s390/s390-64/swapcontext.S @@ -73,7 +73,8 @@ ENTRY(__swapcontext) la %r3,SC_MASK(%r5) la %r4,SC_MASK(%r1) lghi %r5,_NSIG8 - svc SYS_ify(rt_sigprocmask) + lghi %r1,SYS_ify(rt_sigprocmask) + svc 0 /* Load fpu context. */ lgr %r5,%r0 diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h b/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h index 1779af0a0f..150e33981a 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h +++ b/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h @@ -153,12 +153,8 @@ lgr %r0,%r7; \ lg %r7,160(%r15); \ .endif; \ - .if SYS_ify (syscall) < 256; \ - svc SYS_ify (syscall); \ - .else; \ lghi %r1,SYS_ify (syscall); \ svc 0; \ - .endif; \ .if args > 5; \ lgr %r7,%r0; \ .endif diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/vfork.S b/sysdeps/unix/sysv/linux/s390/s390-64/vfork.S index ddc1044fd3..52625fb92e 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-64/vfork.S +++ b/sysdeps/unix/sysv/linux/s390/s390-64/vfork.S @@ -28,7 +28,8 @@ ENTRY (__libc_vfork) /* Do vfork system call. */ - svc SYS_ify (vfork) + lghi %r1,SYS_ify (vfork) + svc 0 /* Check for error. */ lghi %r4,-4095 diff --git a/sysdeps/unix/sysv/linux/s390/sysdep.h b/sysdeps/unix/sysv/linux/s390/sysdep.h index 2d0a26779c..930d7efe03 100644 --- a/sysdeps/unix/sysv/linux/s390/sysdep.h +++ b/sysdeps/unix/sysv/linux/s390/sysdep.h @@ -21,32 +21,6 @@ #undef SYS_ify #define SYS_ify(syscall_name) __NR_##syscall_name -#undef INTERNAL_SYSCALL_DIRECT -#define INTERNAL_SYSCALL_DIRECT(name, nr, args...) \ - ({ \ - DECLARGS_##nr(args) \ - register long int _ret __asm__("2"); \ - __asm__ __volatile__ ( \ - "svc %b1\n\t" \ - : "=d" (_ret) \ - : "i" (__NR_##name) ASMFMT_##nr \ - : "memory" ); \ - _ret; }) - -#undef INTERNAL_SYSCALL_SVC0 -#define INTERNAL_SYSCALL_SVC0(name, nr, args...) \ - ({ \ - DECLARGS_##nr(args) \ - register unsigned long int _nr __asm__("1") = \ - (unsigned long int)(__NR_##name); \ - register long int _ret __asm__("2"); \ - __asm__ __volatile__ ( \ - "svc 0\n\t" \ - : "=d" (_ret) \ - : "d" (_nr) ASMFMT_##nr \ - : "memory" ); \ - _ret; }) - #undef INTERNAL_SYSCALL_NCS #define INTERNAL_SYSCALL_NCS(no, nr, args...) \ ({ \ @@ -61,10 +35,8 @@ _ret; }) #undef INTERNAL_SYSCALL -#define INTERNAL_SYSCALL(name, nr, args...) \ - (((__NR_##name) < 256) \ - ? INTERNAL_SYSCALL_DIRECT(name, nr, args) \ - : INTERNAL_SYSCALL_SVC0(name, nr, args)) +#define INTERNAL_SYSCALL(name, nr, args...) \ + INTERNAL_SYSCALL_NCS(__NR_##name, nr, args) #define DECLARGS_0() #define DECLARGS_1(arg1) \