From patchwork Wed Jun 2 20:43:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Castanho X-Patchwork-Id: 43660 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9B249388E802 for ; Wed, 2 Jun 2021 20:45:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B249388E802 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1622666708; bh=uT0Dd4znEFmVm60y5y85trKW9DMVHvrSC6w+ot/ToII=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=xwMKruP5O3BQB1SZEYI6j7qUAICUyv9857dpxwP4qwO8Sx1WsqYsPbmaWbnv+dnRc M/FCf36ccElFdAjy4qoJX4Y5CCD37vEbz65yhBeA5oADvl8ZO9x9EKw3cM5aME7H7d WFHYtCoN/KqVg7PTfLvJzOAqZTBQvVccz5gNQ7n4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 4C539388CC10 for ; Wed, 2 Jun 2021 20:43:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4C539388CC10 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 152KYa3K087534 for ; Wed, 2 Jun 2021 16:43:17 -0400 Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com with ESMTP id 38xgwd8g6f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 02 Jun 2021 16:43:16 -0400 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 152KgjsR007541 for ; Wed, 2 Jun 2021 20:43:16 GMT Received: from b03cxnp07028.gho.boulder.ibm.com (b03cxnp07028.gho.boulder.ibm.com [9.17.130.15]) by ppma03dal.us.ibm.com with ESMTP id 38ud8ab2gw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 02 Jun 2021 20:43:16 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 152KhF1D6947110 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 2 Jun 2021 20:43:15 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1DB06C605D for ; Wed, 2 Jun 2021 20:43:15 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9CF07C6057 for ; Wed, 2 Jun 2021 20:43:13 +0000 (GMT) Received: from localhost (unknown [9.77.147.61]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP for ; Wed, 2 Jun 2021 20:43:13 +0000 (GMT) To: libc-alpha@sourceware.org Subject: [PATCH] Add build option to disable usage of scv on powerpc Date: Wed, 2 Jun 2021 17:43:12 -0300 Message-Id: <20210602204312.56956-1-msc@linux.ibm.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: U2I2i_N7UVXShYes_oZuVlZBwTdB3pjQ X-Proofpoint-ORIG-GUID: U2I2i_N7UVXShYes_oZuVlZBwTdB3pjQ X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-06-02_10:2021-06-02, 2021-06-02 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 mlxlogscore=885 lowpriorityscore=0 bulkscore=0 malwarescore=0 mlxscore=0 clxscore=1015 adultscore=0 spamscore=0 priorityscore=1501 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2106020129 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Matheus Castanho via Libc-alpha From: Matheus Castanho Reply-To: Matheus Castanho Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Commit 68ab82f566 added support for the scv syscall ABI on powerpc. Since then systems that have kernel and processor support started using scv. However adding the proper support for a new syscall ABI requires changes to several other projects (e.g. qemu, valgrind, strace, kernel), which are gradually receiving support. Meanwhile, having a way to disable scv on glibc at build time can be useful for distros that may encounter conflicts with projects that still do not support the scv ABI, buying time until proper support is added. This commit adds a --disable-scv option that disables scv support and uses sc for all syscalls, just like before commit 68ab82f566. --- NEWS | 3 +++ config.h.in | 3 +++ configure | 16 ++++++++++++++++ configure.ac | 8 ++++++++ sysdeps/powerpc/powerpc64/sysdep.h | 16 ++++++++-------- .../unix/sysv/linux/powerpc/powerpc64/clone.S | 14 +++++++++++--- sysdeps/unix/sysv/linux/powerpc/syscall.S | 2 +- sysdeps/unix/sysv/linux/powerpc/sysdep.h | 2 +- 8 files changed, 51 insertions(+), 13 deletions(-) diff --git a/NEWS b/NEWS index 1bf3daa502..e0fe9d70f0 100644 --- a/NEWS +++ b/NEWS @@ -31,6 +31,9 @@ Major new features: __STDC_WANT_IEC_60559_BFP_EXT__, as specified in TS 18661-1, is defined, and when _GNU_SOURCE is defined. +* On powerpc64*, glibc can now be compiled without scv support using the + --disable-scv configure option. + Deprecated and removed features, and other changes affecting compatibility: * The function pthread_mutex_consistent_np has been deprecated; programs diff --git a/config.h.in b/config.h.in index dbeb7c6243..8b45a3a61d 100644 --- a/config.h.in +++ b/config.h.in @@ -26,6 +26,9 @@ /* On powerpc64, define if the compiler supports -mcpu=power10. */ #undef USE_PPC64_MCPU_POWER10 +/* On powerpc*, define if scv should be used for syscalls (when available). */ +#undef USE_PPC_SCV + /* Define if _Unwind_Find_FDE should be exported from glibc. */ #undef EXPORT_UNWIND_FIND_FDE diff --git a/configure b/configure index 5dde2ba355..c588c90d21 100755 --- a/configure +++ b/configure @@ -791,6 +791,7 @@ enable_pt_chown enable_tunables enable_mathvec enable_cet +enable_scv with_cpu ' ac_precious_vars='build_alias @@ -1463,6 +1464,8 @@ Optional Features: depends on architecture] --enable-cet enable Intel Control-flow Enforcement Technology (CET), x86 only + --disable-scv syscalls will not use scv instruction, even if the + kernel supports it, powerpc only Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] @@ -3776,6 +3779,19 @@ else fi +# Check whether --enable-scv was given. +if test "${enable_scv+set}" = set; then : + enableval=$enable_scv; use_scv=$enableval +else + use_scv=yes +fi + + +if test "$use_scv" != "no"; then : + $as_echo "#define USE_PPC_SCV 1" >>confdefs.h + +fi + # We keep the original values in `$config_*' and never modify them, so we # can write them unchanged into config.make. Everything else uses # $machine, $vendor, and $os, and changes them whenever convenient. diff --git a/configure.ac b/configure.ac index 19051b8ee0..857e237e1b 100644 --- a/configure.ac +++ b/configure.ac @@ -470,6 +470,14 @@ AC_ARG_ENABLE([cet], [enable_cet=$enableval], [enable_cet=$libc_cv_compiler_default_cet]) +AC_ARG_ENABLE([scv], + AC_HELP_STRING([--disable-scv], + [syscalls will not use scv instruction, even if the kernel supports it, powerpc only]), + [use_scv=$enableval], + [use_scv=yes]) + +AS_IF([[test "$use_scv" != "no"]],[AC_DEFINE(USE_PPC_SCV)]) + # We keep the original values in `$config_*' and never modify them, so we # can write them unchanged into config.make. Everything else uses # $machine, $vendor, and $os, and changes them whenever convenient. diff --git a/sysdeps/powerpc/powerpc64/sysdep.h b/sysdeps/powerpc/powerpc64/sysdep.h index 1ea4c3b917..589f7c8d18 100644 --- a/sysdeps/powerpc/powerpc64/sysdep.h +++ b/sysdeps/powerpc/powerpc64/sysdep.h @@ -306,7 +306,7 @@ LT_LABELSUFFIX(name,_name_end): ; \ beq \JUMPFALSE .endm -#if IS_IN(rtld) +#if !defined(USE_PPC_SCV) || IS_IN(rtld) # define DO_CALL(syscall) \ li r0,syscall; \ DO_CALL_SC @@ -323,7 +323,7 @@ LT_LABELSUFFIX(name,_name_end): ; \ b 1f; \ 0: DO_CALL_SC; \ 1: -#endif /* IS_IN(rtld) */ +#endif /* !defined(USE_PPC_SCV) || IS_IN(rtld) */ /* DO_CALL_SC and DO_CALL_SCV expect the syscall number to be in r0. */ #define DO_CALL_SC \ @@ -378,7 +378,7 @@ LT_LABELSUFFIX(name,_name_end): ; \ .endif #endif -#if IS_IN(rtld) +#if !defined(USE_PPC_SCV) || IS_IN(rtld) # define PSEUDO_RET \ RET_SC; \ TAIL_CALL_SYSCALL_ERROR @@ -395,7 +395,7 @@ LT_LABELSUFFIX(name,_name_end): ; \ b 1f; \ 0: RET_SC; \ 1: TAIL_CALL_SYSCALL_ERROR -#endif +#endif /* !defined(USE_PPC_SCV) || IS_IN(rtld) */ #define RET_SCV \ li r9,-4095; \ @@ -417,7 +417,7 @@ LT_LABELSUFFIX(name,_name_end): ; \ ENTRY (name); \ DO_CALL (SYS_ify (syscall_name)) -#if IS_IN(rtld) +#if !defined(USE_PPC_SCV) || IS_IN(rtld) # define PSEUDO_RET_NOERRNO \ blr #else @@ -425,7 +425,7 @@ LT_LABELSUFFIX(name,_name_end): ; \ # define PSEUDO_RET_NOERRNO \ NVOLREG_RESTORE; \ blr -#endif /* IS_IN(rtld) */ +#endif /* !defined(USE_PPC_SCV) || IS_IN(rtld) */ #define ret_NOERRNO PSEUDO_RET_NOERRNO @@ -438,7 +438,7 @@ LT_LABELSUFFIX(name,_name_end): ; \ ENTRY (name); \ DO_CALL (SYS_ify (syscall_name)) -#if IS_IN(rtld) +#if !defined(USE_PPC_SCV) || IS_IN(rtld) # define PSEUDO_RET_ERRVAL \ blr #else @@ -446,7 +446,7 @@ LT_LABELSUFFIX(name,_name_end): ; \ # define PSEUDO_RET_ERRVAL \ NVOLREG_RESTORE; \ blr -#endif /* IS_IN(rtld) */ +#endif /* !defined(USE_PPC_SCV) || IS_IN(rtld) */ #define ret_ERRVAL PSEUDO_RET_ERRVAL diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S b/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S index e9bd8cb960..777ead80b0 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S @@ -38,11 +38,13 @@ ENTRY (__clone) beq- cr0,L(badargs) /* Save some regs in the "red zone". */ +#ifdef USE_PPC_SCV std r28,-32(r1) + cfi_offset(r28,-32) +#endif std r29,-24(r1) std r30,-16(r1) std r31,-8(r1) - cfi_offset(r28,-32) cfi_offset(r29,-24) cfi_offset(r30,-16) cfi_offset(r31,-8) @@ -71,6 +73,7 @@ ENTRY (__clone) /* Do the call. */ li r0,SYS_ify(clone) +#ifdef USE_PPC_SCV CHECK_SCV_SUPPORT r28 0f /* This is equivalent to DO_CALL_SCV, but we cannot use the macro here because it uses CFI directives and we just called cfi_endproc. */ @@ -87,6 +90,7 @@ ENTRY (__clone) /* When using scv, error is indicated by negative r3. */ cmpdi cr1,r3,0 b 1f +#endif /* USE_PPC_SCV */ 0: DO_CALL_SC /* Check for child process. */ @@ -119,22 +123,26 @@ L(parent): cmpdi cr1,r28,0 /* Parent. Restore registers & return. */ +#ifdef USE_PPC_SCV cfi_offset(r28,-32) + ld r28,-32(r1) + cfi_restore(r28) +#endif cfi_offset(r29,-24) cfi_offset(r30,-16) cfi_offset(r31,-8) - ld r28,-32(r1) ld r29,-24(r1) ld r30,-16(r1) ld r31,-8(r1) - cfi_restore(r28) cfi_restore(r29) cfi_restore(r30) cfi_restore(r31) +#ifdef USE_PPC_SCV beq cr1,0f RET_SCV b 1f +#endif 0: RET_SC 1: TAIL_CALL_SYSCALL_ERROR diff --git a/sysdeps/unix/sysv/linux/powerpc/syscall.S b/sysdeps/unix/sysv/linux/powerpc/syscall.S index d6ec87f006..a29652feaf 100644 --- a/sysdeps/unix/sysv/linux/powerpc/syscall.S +++ b/sysdeps/unix/sysv/linux/powerpc/syscall.S @@ -25,7 +25,7 @@ ENTRY (syscall) mr r6,r7 mr r7,r8 mr r8,r9 -#if !IS_IN(rtld) && (defined(__PPC64__) || defined(__powerpc64__)) +#if defined(USE_PPC_SCV) && !IS_IN(rtld) && (defined(__PPC64__) || defined(__powerpc64__)) CHECK_SCV_SUPPORT r9 0f DO_CALL_SCV RET_SCV diff --git a/sysdeps/unix/sysv/linux/powerpc/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/sysdep.h index 2f31f9177b..4b9d43c636 100644 --- a/sysdeps/unix/sysv/linux/powerpc/sysdep.h +++ b/sysdeps/unix/sysv/linux/powerpc/sysdep.h @@ -125,7 +125,7 @@ /* When inside the dynamic loader, the thread pointer may not have been initialized yet, so don't check for scv support in that case. */ -# if !IS_IN(rtld) +# if defined(USE_PPC_SCV) && !IS_IN(rtld) # undef TRY_SYSCALL_SCV # define TRY_SYSCALL_SCV(nr) \ CHECK_THREAD_POINTER && THREAD_GET_HWCAP() & PPC_FEATURE2_SCV ? \