From patchwork Wed Nov 18 14:47:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Castanho X-Patchwork-Id: 1402280 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: 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=IGLuT/nm; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cblyc3Vm6z9sRR for ; Thu, 19 Nov 2020 01:47:20 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AB49F39874FC; Wed, 18 Nov 2020 14:47:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB49F39874FC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1605710831; bh=3st6HbTKdUkliTCQVyX/XzGOzFYkGMUvMSzDU/NIRbc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=IGLuT/nm+WaRuirs4urr/5eB5saV/3HzaCdKX8OQRtFvwguj2Tn1az6OJPVj987JC fDAPVS+JLjXpubGQDm2QA+z45uMO7tvzTQnvou4qLCyeA1PqkMU61uU3VS/JFjhnIn jWiUvV9iQ4LMUp43hda5yylhQisSGzYsNKBBqKUo= 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 85FBE39874DC for ; Wed, 18 Nov 2020 14:47:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 85FBE39874DC Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0AIEVi9Z017348 for ; Wed, 18 Nov 2020 09:47:09 -0500 Received: from ppma04wdc.us.ibm.com (1a.90.2fa9.ip4.static.sl-reverse.com [169.47.144.26]) by mx0a-001b2d01.pphosted.com with ESMTP id 34w2tuxmfv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 18 Nov 2020 09:47:09 -0500 Received: from pps.filterd (ppma04wdc.us.ibm.com [127.0.0.1]) by ppma04wdc.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0AIEcN1r016471 for ; Wed, 18 Nov 2020 14:47:08 GMT Received: from b01cxnp22033.gho.pok.ibm.com (b01cxnp22033.gho.pok.ibm.com [9.57.198.23]) by ppma04wdc.us.ibm.com with ESMTP id 34t6v96w7g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 18 Nov 2020 14:47:08 +0000 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0AIEl7XP61211026 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 Nov 2020 14:47:07 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BC65AAC05F; Wed, 18 Nov 2020 14:47:07 +0000 (GMT) Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3B14AAC05B; Wed, 18 Nov 2020 14:47:07 +0000 (GMT) Received: from localhost (unknown [9.160.22.117]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 18 Nov 2020 14:47:07 +0000 (GMT) To: libc-alpha@sourceware.org Subject: [PATCH 1/4] powerpc: Replace brk.S with a C implementation Date: Wed, 18 Nov 2020 11:47:00 -0300 Message-Id: <20201118144703.75569-2-msc@linux.ibm.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201118144703.75569-1-msc@linux.ibm.com> References: <20201118144703.75569-1-msc@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-18_04:2020-11-17, 2020-11-18 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 lowpriorityscore=0 clxscore=1015 malwarescore=0 spamscore=0 phishscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011180100 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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 Cc: tuliom@linux.ibm.com Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" From: Tulio Magno Quites Machado Filho There is no need to maintain a separate assembly implementation of brk for powerpc. It basically does the same thing as the generic C-based version, so we can reuse that instead. --- .../linux/powerpc/{powerpc64/brk.S => brk.c} | 41 +++++++-------- sysdeps/unix/sysv/linux/powerpc/dl-brk.S | 1 - .../unix/sysv/linux/powerpc/powerpc32/brk.S | 52 ------------------- 3 files changed, 18 insertions(+), 76 deletions(-) rename sysdeps/unix/sysv/linux/powerpc/{powerpc64/brk.S => brk.c} (58%) delete mode 100644 sysdeps/unix/sysv/linux/powerpc/dl-brk.S delete mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc32/brk.S diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/brk.S b/sysdeps/unix/sysv/linux/powerpc/brk.c similarity index 58% rename from sysdeps/unix/sysv/linux/powerpc/powerpc64/brk.S rename to sysdeps/unix/sysv/linux/powerpc/brk.c index f206909b72..af7d1d73a2 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/brk.S +++ b/sysdeps/unix/sysv/linux/powerpc/brk.c @@ -1,6 +1,6 @@ -/* brk system call for Linux. PowerPC64 version. - Copyright (C) 1995-2020 Free Software Foundation, Inc. +/* Copyright (C) 2020 Free Software Foundation, Inc. This file is part of the GNU C Library. + Contributed by Chris Metcalf , 2011. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -13,31 +13,26 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see + License along with the GNU C Library. If not, see . */ +#include +#include #include -#define _ERRNO_H 1 -#include - .comm __curbrk,8,8 - .section ".toc","aw" -.LC__curbrk: - .tc __curbrk[TC],__curbrk - .section ".text" -ENTRY (__brk) - CALL_MCOUNT 1 +/* This must be initialized data because commons can't have aliases. */ +void *__curbrk = 0; - std r3,-8(r1) - DO_CALL(SYS_ify(brk)) - ld r6,-8(r1) - ld r5,.LC__curbrk@toc(r2) - std r3,0(r5) - cmpld r6,r3 - li r3,0 - blelr+ - li r3,ENOMEM - TAIL_CALL_SYSCALL_ERROR -END (__brk) +int +__brk (void *addr) +{ + __curbrk = (void *) INTERNAL_SYSCALL_CALL (brk, addr); + if (__curbrk < addr) + { + __set_errno (ENOMEM); + return -1; + } + return 0; +} weak_alias (__brk, brk) diff --git a/sysdeps/unix/sysv/linux/powerpc/dl-brk.S b/sysdeps/unix/sysv/linux/powerpc/dl-brk.S deleted file mode 100644 index eeb96544e3..0000000000 --- a/sysdeps/unix/sysv/linux/powerpc/dl-brk.S +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/brk.S b/sysdeps/unix/sysv/linux/powerpc/powerpc32/brk.S deleted file mode 100644 index f3b960795e..0000000000 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/brk.S +++ /dev/null @@ -1,52 +0,0 @@ -/* brk system call for Linux/ppc. - Copyright (C) 1995-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#define _ERRNO_H 1 -#include - - .comm __curbrk,4,4 - .section ".text" -ENTRY (__brk) - mflr r0 - stwu r1,-16(r1) - cfi_adjust_cfa_offset (16) - stw r3,8(r1) - stw r0,20(r1) - cfi_offset (lr, 4) - DO_CALL(SYS_ify(brk)) - lwz r6,8(r1) -#ifdef PIC - SETUP_GOT_ACCESS(r5,got_label) - addis r5,r5,__curbrk-got_label@ha - stw r3,__curbrk-got_label@l(r5) -#else - lis r4,__curbrk@ha - stw r3,__curbrk@l(r4) -#endif - lwz r0,20(r1) - cmplw r6,r3 - addi r1,r1,16 - mtlr r0 - li r3,0 - blelr+ - li r3,ENOMEM - b __syscall_error@local -END (__brk) - -weak_alias (__brk, brk) From patchwork Wed Nov 18 14:47:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Castanho X-Patchwork-Id: 1402281 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: 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=ELmtpcOJ; dkim-atps=neutral Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cblyj4yqWz9sRR for ; Thu, 19 Nov 2020 01:47:25 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 589263987503; Wed, 18 Nov 2020 14:47:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 589263987503 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1605710835; bh=8p2w4Y87dkfCYk2KjT56R1cu76IVAXi7PskQH7N4vjU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=ELmtpcOJKKCAZ8/jijMJMs5hNNw3Qgwt58LC7jFcf+eKSLkCDray2uOVpl8QScYG4 GgFBP08syRyqOMBBEyQjotAXIeZWTyG67pNGJYpJpt7+QVuVvHuwSpItb/I9qvPUFu AkSVICdFGZaVzBL1c4crhAFTETeQyT7/qTbtpHNc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id E9A9C3898035 for ; Wed, 18 Nov 2020 14:47:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E9A9C3898035 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0AIEVr2F079029 for ; Wed, 18 Nov 2020 09:47:12 -0500 Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0a-001b2d01.pphosted.com with ESMTP id 34w31vdyx3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 18 Nov 2020 09:47:12 -0500 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0AIEkjGC003512 for ; Wed, 18 Nov 2020 14:47:11 GMT Received: from b01cxnp22035.gho.pok.ibm.com (b01cxnp22035.gho.pok.ibm.com [9.57.198.25]) by ppma01dal.us.ibm.com with ESMTP id 34uttrkjf7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 18 Nov 2020 14:47:11 +0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0AIEl9Iv10355422 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 Nov 2020 14:47:10 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DF27AAE064; Wed, 18 Nov 2020 14:47:09 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 632ECAE05F; Wed, 18 Nov 2020 14:47:09 +0000 (GMT) Received: from localhost (unknown [9.160.22.117]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 18 Nov 2020 14:47:09 +0000 (GMT) To: libc-alpha@sourceware.org Subject: [PATCH 2/4] powerpc: Make PT_THREAD_POINTER available to assembly code Date: Wed, 18 Nov 2020 11:47:01 -0300 Message-Id: <20201118144703.75569-3-msc@linux.ibm.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201118144703.75569-1-msc@linux.ibm.com> References: <20201118144703.75569-1-msc@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-18_04:2020-11-17, 2020-11-18 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 spamscore=0 priorityscore=1501 clxscore=1015 malwarescore=0 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011180100 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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 Cc: tuliom@linux.ibm.com Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" PT_THREAD_POINTER is currenty defined inside a #ifndef __ASSEMBLER__ block, but its usage should not be limited to C code, as it can be useful when accessing the TLS from assembly code as well. Reviewed-by: Tulio Magno Quites Machado Filho --- sysdeps/powerpc/nptl/tls.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/sysdeps/powerpc/nptl/tls.h b/sysdeps/powerpc/nptl/tls.h index 261eecfd18..d585968d04 100644 --- a/sysdeps/powerpc/nptl/tls.h +++ b/sysdeps/powerpc/nptl/tls.h @@ -29,8 +29,24 @@ #else /* __ASSEMBLER__ */ # include +# define __ASSEMBLY__ +# include #endif /* __ASSEMBLER__ */ +#ifndef __powerpc64__ +/* Register r2 (tp) is reserved by the ABI as "thread pointer". */ +# define PT_THREAD_POINTER PT_R2 +# ifndef __ASSEMBLER__ +register void *__thread_register __asm__ ("r2"); +# endif + +#else /* __powerpc64__ */ +/* Register r13 (tp) is reserved by the ABI as "thread pointer". */ +# define PT_THREAD_POINTER PT_R13 +# ifndef __ASSEMBLER__ +register void *__thread_register __asm__ ("r13"); +# endif +#endif /* __powerpc64__ */ #ifndef __ASSEMBLER__ @@ -106,16 +122,6 @@ typedef struct (sizeof (struct pthread) \ + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1))) -# ifndef __powerpc64__ -/* Register r2 (tp) is reserved by the ABI as "thread pointer". */ -register void *__thread_register __asm__ ("r2"); -# define PT_THREAD_POINTER PT_R2 -# else -/* Register r13 (tp) is reserved by the ABI as "thread pointer". */ -register void *__thread_register __asm__ ("r13"); -# define PT_THREAD_POINTER PT_R13 -# endif - /* The following assumes that TP (R2 or R13) points to the end of the TCB + 0x7000 (per the ABI). This implies that TCB address is TP - 0x7000. As we define TLS_DTV_AT_TP we can From patchwork Wed Nov 18 14:47:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Castanho X-Patchwork-Id: 1402282 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: 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=luBWD5Eg; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cblyp4kClz9sRR for ; Thu, 19 Nov 2020 01:47:30 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E03123987447; Wed, 18 Nov 2020 14:47:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E03123987447 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1605710837; bh=bgHZz398oR69prN7NBDXFeoZ/SfQtLG7lLu/rliBPNs=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=luBWD5EgawajyDM2fpmq5/X+cqeLR+St22EShmQhkiM/BB4vaa8pj1aMnnQIAxFFK VUe0WBTaFCjrLRZ0X+ID4RLbaGkoYsIeyhvGOGt48cqd9WLbsReKH+SwPTBvvbhfCu /+QOtWp6G3rHdDGB0kSpoVxk4qlvuxB82pePuqeE= 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 0C4043987502 for ; Wed, 18 Nov 2020 14:47:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0C4043987502 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0AIEYdlr110153 for ; Wed, 18 Nov 2020 09:47:14 -0500 Received: from ppma02wdc.us.ibm.com (aa.5b.37a9.ip4.static.sl-reverse.com [169.55.91.170]) by mx0b-001b2d01.pphosted.com with ESMTP id 34w4sha227-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 18 Nov 2020 09:47:14 -0500 Received: from pps.filterd (ppma02wdc.us.ibm.com [127.0.0.1]) by ppma02wdc.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0AIEh1u8007890 for ; Wed, 18 Nov 2020 14:47:13 GMT Received: from b03cxnp07029.gho.boulder.ibm.com (b03cxnp07029.gho.boulder.ibm.com [9.17.130.16]) by ppma02wdc.us.ibm.com with ESMTP id 34vfja05q2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 18 Nov 2020 14:47:13 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0AIElCj463439170 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 Nov 2020 14:47:12 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 78903C6057; Wed, 18 Nov 2020 14:47:12 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E4765C6055; Wed, 18 Nov 2020 14:47:11 +0000 (GMT) Received: from localhost (unknown [9.160.22.117]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 18 Nov 2020 14:47:11 +0000 (GMT) To: libc-alpha@sourceware.org Subject: [PATCH 3/4] powerpc: Runtime selection between sc and scv for syscalls Date: Wed, 18 Nov 2020 11:47:02 -0300 Message-Id: <20201118144703.75569-4-msc@linux.ibm.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201118144703.75569-1-msc@linux.ibm.com> References: <20201118144703.75569-1-msc@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-18_04:2020-11-17, 2020-11-18 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 lowpriorityscore=0 suspectscore=0 impostorscore=0 malwarescore=0 spamscore=0 priorityscore=1501 adultscore=0 bulkscore=0 mlxlogscore=999 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011180100 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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 Cc: tuliom@linux.ibm.com Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Linux kernel v5.9 added support for system calls using the scv instruction for POWER9 and later. The new codepath provides better performance (see below) if compared to using sc. For the foreseeable future, both sc and scv mechanisms will co-exist, so this patch enables glibc to do a runtime check and always use scv when it is available. Before issuing the system call to the kernel, we check hwcap2 in the TCB for PPC_FEATURE2_SCV to see if scv is supported by the kernel. If not, we fallback to sc and keep the old behavior. The kernel implements a different error return convention for scv, so when returning from a system call we need to handle the return value differently depending on the instruction we used to enter the kernel. For syscalls implemented in ASM, entry and exit are implemented by different macros (PSEUDO and PSEUDO_RET, resp.), which may be used in sequence (e.g. for templated syscalls) or with other instructions in between (e.g. clone). To avoid accessing the TCB a second time on PSEUDO_RET to check which instruction we used, the value read from hwcap2 is cached on a non-volatile register. This is not needed when using INTERNAL_SYSCALL macro, since entry and exit are bundled into the same inline asm directive. Since system calls may be called before the TCB has been setup (e.g. inside the dynamic loader), we also check the value of the thread pointer before effectively accessing the TCB. For such situations in which the availability of scv cannot be determined, sc is always used. Support for scv in syscalls implemented in their own ASM file (clone and vfork) will be added later. For now simply use sc as before. Average performance over 1M calls for each syscall "type": - stat: C wrapper calling INTERNAL_SYSCALL - getpid: templated ASM syscall - syscall: call to gettid using syscall function Standard: stat : 1.573445 us / ~3619 cycles getpid : 0.164986 us / ~379 cycles syscall : 0.162743 us / ~374 cycles With scv: stat : 1.537049 us / ~3535 cycles <~ -84 cycles / -2.32% getpid : 0.109923 us / ~253 cycles <~ -126 cycles / -33.25% syscall : 0.116410 us / ~268 cycles <~ -106 cycles / -28.34% Tested on powerpc, powerpc64, powerpc64le (with and without scv) --- sysdeps/powerpc/powerpc32/sysdep.h | 19 ++-- sysdeps/powerpc/powerpc64/sysdep.h | 90 ++++++++++++++++++- .../unix/sysv/linux/powerpc/powerpc64/clone.S | 9 +- .../unix/sysv/linux/powerpc/powerpc64/vfork.S | 6 +- sysdeps/unix/sysv/linux/powerpc/syscall.S | 11 ++- sysdeps/unix/sysv/linux/powerpc/sysdep.h | 78 +++++++++++----- 6 files changed, 174 insertions(+), 39 deletions(-) diff --git a/sysdeps/powerpc/powerpc32/sysdep.h b/sysdeps/powerpc/powerpc32/sysdep.h index 829eec266a..bff18bdc8b 100644 --- a/sysdeps/powerpc/powerpc32/sysdep.h +++ b/sysdeps/powerpc/powerpc32/sysdep.h @@ -90,9 +90,12 @@ GOT_LABEL: ; \ cfi_endproc; \ ASM_SIZE_DIRECTIVE(name) -#define DO_CALL(syscall) \ - li 0,syscall; \ - sc +#define DO_CALL(syscall) \ + li 0,syscall; \ + DO_CALL_SC + +#define DO_CALL_SC \ + sc #undef JUMPTARGET #ifdef PIC @@ -106,14 +109,20 @@ GOT_LABEL: ; \ # define HIDDEN_JUMPTARGET(name) __GI_##name##@local #endif +#define TAIL_CALL_SYSCALL_ERROR \ + b __syscall_error@local + #define PSEUDO(name, syscall_name, args) \ .section ".text"; \ ENTRY (name) \ DO_CALL (SYS_ify (syscall_name)); +#define RET_SC \ + bnslr+; + #define PSEUDO_RET \ - bnslr+; \ - b __syscall_error@local + RET_SC; \ + TAIL_CALL_SYSCALL_ERROR #define ret PSEUDO_RET #undef PSEUDO_END diff --git a/sysdeps/powerpc/powerpc64/sysdep.h b/sysdeps/powerpc/powerpc64/sysdep.h index d557098898..2d7dde64da 100644 --- a/sysdeps/powerpc/powerpc64/sysdep.h +++ b/sysdeps/powerpc/powerpc64/sysdep.h @@ -17,6 +17,7 @@ . */ #include +#include #ifdef __ASSEMBLER__ @@ -263,10 +264,72 @@ LT_LABELSUFFIX(name,_name_end): ; \ TRACEBACK_MASK(name,mask); \ END_2(name) +/* We will allocate a new frame to save LR and the non-volatile register used to + read the TCB when checking for scv support on syscall code. We actually just + need the minimum frame size plus room for 1 reg (64 bits). But the ABI + mandates stack frames should be aligned at 16 Bytes, so we end up allocating + a bit more space then what will actually be used. */ +#define SCV_FRAME_SIZE (FRAME_MIN_SIZE+16) +#define SCV_FRAME_NVOLREG_SAVE FRAME_MIN_SIZE + +/* Allocate frame and save register */ +#define NVOLREG_SAVE \ + stdu r1,-SCV_FRAME_SIZE(r1); \ + std r31,SCV_FRAME_NVOLREG_SAVE(r1); \ + cfi_adjust_cfa_offset(SCV_FRAME_SIZE); + +/* Restore register and destroy frame */ +#define NVOLREG_RESTORE \ + ld r31,SCV_FRAME_NVOLREG_SAVE(r1); \ + addi r1,r1,SCV_FRAME_SIZE; \ + cfi_adjust_cfa_offset(-SCV_FRAME_SIZE); + +/* Check PPC_FEATURE2_SCV bit from hwcap2 in the TCB and update CR0 + * accordingly. First, we check if the thread pointer != 0, so we don't try to + * access the TCB before it has been initialized, e.g. inside the dynamic + * loader. If it is already initialized, check if scv is available. On both + * negative cases, go to JUMPFALSE (label given by the macro's caller). We + * save the value we read from the TCB in a non-volatile register so we can + * reuse it later when exiting from the syscall in PSEUDO_RET. */ + .macro CHECK_SCV_SUPPORT REG JUMPFALSE + + /* Check if thread pointer has already been setup */ + cmpdi r13,0 + beq \JUMPFALSE + + /* Read PPC_FEATURE2_SCV from TCB and store it in REG */ + ld \REG,TCB_HWCAP(PT_THREAD_POINTER) + andis. \REG,\REG,PPC_FEATURE2_SCV>>16 + + beq \JUMPFALSE + .endm + +/* Before doing the syscall, check if we can use scv. scv is supported by P9 + * and later with Linux v5.9 and later. If so, use it. Otherwise, fallback to + * sc. We use a non-volatile register to save hwcap2 from the TCB, so we need + * to save its content beforehand. */ #define DO_CALL(syscall) \ - li 0,syscall; \ + li r0,syscall; \ + NVOLREG_SAVE; \ + CHECK_SCV_SUPPORT r31 0f; \ + DO_CALL_SCV; \ + b 1f; \ +0: DO_CALL_SC; \ +1: + +/* DO_CALL_SC and DO_CALL_SCV expect the syscall number to be loaded on r0. */ +#define DO_CALL_SC \ sc +#define DO_CALL_SCV \ + mflr r9; \ + std r9,FRAME_LR_SAVE(r1); \ + cfi_offset(lr,FRAME_LR_SAVE); \ + scv 0; \ + ld r9,FRAME_LR_SAVE(r1); \ + mtlr r9; \ + cfi_restore(lr); + /* ppc64 is always PIC */ #undef JUMPTARGET #define JUMPTARGET(name) FUNC_LABEL(name) @@ -304,9 +367,26 @@ LT_LABELSUFFIX(name,_name_end): ; \ .endif #endif +/* This should only be called after a DO_CALL. In such cases, r31 contains the + * value of PPC_FEATURE2_SCV read from hwcap2 by CHECK_SCV_SUPPORT. If it is + * set, we know we have entered the kernel using scv, so handle the return code + * accordingly. */ #define PSEUDO_RET \ - bnslr+; \ - TAIL_CALL_SYSCALL_ERROR + cmpdi cr5,r31,0; \ + NVOLREG_RESTORE; \ + beq cr5,0f; \ + RET_SCV; \ + b 1f; \ +0: RET_SC; \ +1: TAIL_CALL_SYSCALL_ERROR + +#define RET_SCV \ + cmpdi r3,0; \ + bgelr+; \ + neg r3,r3; + +#define RET_SC \ + bnslr+; #define ret PSEUDO_RET @@ -319,7 +399,9 @@ LT_LABELSUFFIX(name,_name_end): ; \ ENTRY (name); \ DO_CALL (SYS_ify (syscall_name)) +/* This should only be called after a DO_CALL. */ #define PSEUDO_RET_NOERRNO \ + NVOLREG_RESTORE; \ blr #define ret_NOERRNO PSEUDO_RET_NOERRNO @@ -333,7 +415,9 @@ LT_LABELSUFFIX(name,_name_end): ; \ ENTRY (name); \ DO_CALL (SYS_ify (syscall_name)) +/* This should only be called after a DO_CALL. */ #define PSEUDO_RET_ERRVAL \ + NVOLREG_RESTORE; \ blr #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 b30641c805..fc496fa671 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S @@ -68,7 +68,8 @@ ENTRY (__clone) cfi_endproc /* Do the call. */ - DO_CALL(SYS_ify(clone)) + li r0,SYS_ify(clone) + DO_CALL_SC /* Check for child process. */ cmpdi cr1,r3,0 @@ -82,7 +83,8 @@ ENTRY (__clone) bctrl ld r2,FRAME_TOC_SAVE(r1) - DO_CALL(SYS_ify(exit)) + li r0,(SYS_ify(exit)) + DO_CALL_SC /* We won't ever get here but provide a nop so that the linker will insert a toc adjusting stub if necessary. */ nop @@ -104,7 +106,8 @@ L(parent): cfi_restore(r30) cfi_restore(r31) - PSEUDO_RET + RET_SC + TAIL_CALL_SYSCALL_ERROR END (__clone) diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S b/sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S index 17199fb14a..a71f69e929 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S @@ -28,9 +28,11 @@ ENTRY (__vfork) CALL_MCOUNT 0 - DO_CALL (SYS_ify (vfork)) + li r0,SYS_ify (vfork) + DO_CALL_SC - PSEUDO_RET + RET_SC + TAIL_CALL_SYSCALL_ERROR PSEUDO_END (__vfork) libc_hidden_def (__vfork) diff --git a/sysdeps/unix/sysv/linux/powerpc/syscall.S b/sysdeps/unix/sysv/linux/powerpc/syscall.S index 48dade4642..23ce2f69c9 100644 --- a/sysdeps/unix/sysv/linux/powerpc/syscall.S +++ b/sysdeps/unix/sysv/linux/powerpc/syscall.S @@ -25,6 +25,13 @@ ENTRY (syscall) mr r6,r7 mr r7,r8 mr r8,r9 - sc - PSEUDO_RET +#if defined(__PPC64__) || defined(__powerpc64__) + CHECK_SCV_SUPPORT r9 0f + DO_CALL_SCV + RET_SCV + b 1f +#endif +0: DO_CALL_SC + RET_SC +1: TAIL_CALL_SYSCALL_ERROR PSEUDO_END (syscall) diff --git a/sysdeps/unix/sysv/linux/powerpc/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/sysdep.h index b2bca598b9..19f4321c6b 100644 --- a/sysdeps/unix/sysv/linux/powerpc/sysdep.h +++ b/sysdeps/unix/sysv/linux/powerpc/sysdep.h @@ -64,39 +64,69 @@ #define INTERNAL_VSYSCALL_CALL(funcptr, nr, args...) \ INTERNAL_VSYSCALL_CALL_TYPE(funcptr, long int, nr, args) +#define DECLARE_REGS \ + register long int r0 __asm__ ("r0"); \ + register long int r3 __asm__ ("r3"); \ + register long int r4 __asm__ ("r4"); \ + register long int r5 __asm__ ("r5"); \ + register long int r6 __asm__ ("r6"); \ + register long int r7 __asm__ ("r7"); \ + register long int r8 __asm__ ("r8"); + +#define SYSCALL_SCV(nr) \ + ({ \ + __asm__ __volatile__ \ + ("scv 0\n\t" \ + "0:" \ + : "=&r" (r0), \ + "=&r" (r3), "=&r" (r4), "=&r" (r5), \ + "=&r" (r6), "=&r" (r7), "=&r" (r8) \ + : ASM_INPUT_##nr \ + : "r9", "r10", "r11", "r12", \ + "lr", "ctr", "memory"); \ + r3; \ + }) -#undef INTERNAL_SYSCALL -#define INTERNAL_SYSCALL_NCS(name, nr, args...) \ - ({ \ - register long int r0 __asm__ ("r0"); \ - register long int r3 __asm__ ("r3"); \ - register long int r4 __asm__ ("r4"); \ - register long int r5 __asm__ ("r5"); \ - register long int r6 __asm__ ("r6"); \ - register long int r7 __asm__ ("r7"); \ - register long int r8 __asm__ ("r8"); \ - LOADARGS_##nr (name, ##args); \ - __asm__ __volatile__ \ - ("sc\n\t" \ - "mfcr %0\n\t" \ - "0:" \ - : "=&r" (r0), \ - "=&r" (r3), "=&r" (r4), "=&r" (r5), \ - "=&r" (r6), "=&r" (r7), "=&r" (r8) \ - : ASM_INPUT_##nr \ - : "r9", "r10", "r11", "r12", \ - "cr0", "ctr", "memory"); \ - r0 & (1 << 28) ? -r3 : r3; \ +#define SYSCALL_SC(nr) \ + ({ \ + __asm__ __volatile__ \ + ("sc\n\t" \ + "mfcr %0\n\t" \ + "0:" \ + : "=&r" (r0), \ + "=&r" (r3), "=&r" (r4), "=&r" (r5), \ + "=&r" (r6), "=&r" (r7), "=&r" (r8) \ + : ASM_INPUT_##nr \ + : "r9", "r10", "r11", "r12", \ + "cr0", "ctr", "memory"); \ + r0 & (1 << 28) ? -r3 : r3; \ }) -#define INTERNAL_SYSCALL(name, nr, args...) \ - INTERNAL_SYSCALL_NCS (__NR_##name, nr, args) #if defined(__PPC64__) || defined(__powerpc64__) # define SYSCALL_ARG_SIZE 8 + +# define INTERNAL_SYSCALL_NCS(name, nr, args...) \ + ({ \ + DECLARE_REGS; \ + LOADARGS_##nr (name, ##args); \ + __thread_register != 0 && THREAD_GET_HWCAP() & PPC_FEATURE2_SCV ? \ + SYSCALL_SCV(nr) : SYSCALL_SC(nr); \ + }) #else # define SYSCALL_ARG_SIZE 4 + +# define INTERNAL_SYSCALL_NCS(name, nr, args...) \ + ({ \ + DECLARE_REGS; \ + LOADARGS_##nr (name, ##args); \ + SYSCALL_SC(nr); \ + }) #endif +#undef INTERNAL_SYSCALL +#define INTERNAL_SYSCALL(name, nr, args...) \ + INTERNAL_SYSCALL_NCS (__NR_##name, nr, args) + #define LOADARGS_0(name, dummy) \ r0 = name #define LOADARGS_1(name, __arg1) \ From patchwork Wed Nov 18 14:47:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Castanho X-Patchwork-Id: 1402283 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: 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=BJIV6f1K; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cblyw1fZ2z9sTv for ; Thu, 19 Nov 2020 01:47:36 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E194E398750C; Wed, 18 Nov 2020 14:47:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E194E398750C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1605710840; bh=rbUb/6V9vuemsLpuNuqCmoQZG53dmdwbv4f7qmGkuyQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=BJIV6f1KjkofRRkUwoPe+tCW34bAaOnv8qRMn8R28fjKGDzDQAVgJ1CesgpWyl3lz BtzBr1W7c73V9ErJhFPy/yAurAm07Nft9mVzOayh6T9wc14fXlfLGHtf3xBFUsBotz Gt7wcO+phuf1OyRys9yW02BLFNxSPjv8XMRr35D8= 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 CE77D39874DC for ; Wed, 18 Nov 2020 14:47:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CE77D39874DC Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0AIEZVhP142742 for ; Wed, 18 Nov 2020 09:47:16 -0500 Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0a-001b2d01.pphosted.com with ESMTP id 34w32248pj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 18 Nov 2020 09:47:16 -0500 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0AIEkh0w003499 for ; Wed, 18 Nov 2020 14:47:15 GMT Received: from b01cxnp22033.gho.pok.ibm.com (b01cxnp22033.gho.pok.ibm.com [9.57.198.23]) by ppma01dal.us.ibm.com with ESMTP id 34uttrkjfr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 18 Nov 2020 14:47:15 +0000 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0AIElE6s35717452 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 Nov 2020 14:47:14 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7C7D4AC05E; Wed, 18 Nov 2020 14:47:14 +0000 (GMT) Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DDF37AC059; Wed, 18 Nov 2020 14:47:13 +0000 (GMT) Received: from localhost (unknown [9.160.22.117]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 18 Nov 2020 14:47:13 +0000 (GMT) To: libc-alpha@sourceware.org Subject: [PATCH 4/4] powerpc: Use scv instruction on clone when available Date: Wed, 18 Nov 2020 11:47:03 -0300 Message-Id: <20201118144703.75569-5-msc@linux.ibm.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201118144703.75569-1-msc@linux.ibm.com> References: <20201118144703.75569-1-msc@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-18_04:2020-11-17, 2020-11-18 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 malwarescore=0 lowpriorityscore=0 adultscore=0 mlxscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 phishscore=0 mlxlogscore=708 clxscore=1015 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011180100 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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 Cc: tuliom@linux.ibm.com Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" clone already uses r31 to temporarily save input arguments before doing the syscall, so we use a different register to read from the TCB. We can also avoid allocating another stack frame, which is not needed since we can simply extend the usage of the red zone. --- .../unix/sysv/linux/powerpc/powerpc64/clone.S | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S b/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S index fc496fa671..247e0de68c 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S @@ -38,9 +38,11 @@ ENTRY (__clone) beq- cr0,L(badargs) /* Save some regs in the "red zone". */ + std r28,-32(r1) 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) @@ -69,11 +71,26 @@ ENTRY (__clone) /* Do the call. */ li r0,SYS_ify(clone) - DO_CALL_SC + 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. */ + mflr r9 + std r9,FRAME_LR_SAVE(r1) + scv 0 + ld r9,FRAME_LR_SAVE(r1) + mtlr r9 + + /* Check for child process. */ + /* When using scv, error is indicated by negative r3. */ + cmpdi cr1,r3,0 + b 1f +0: DO_CALL_SC /* Check for child process. */ + /* With sc, error is indicated by cr0.SO. */ cmpdi cr1,r3,0 crandc cr1*4+eq,cr1*4+eq,cr0*4+so +1: bne- cr1,L(parent) /* The '-' is to minimise the race. */ std r2,FRAME_TOC_SAVE(r1) @@ -95,19 +112,29 @@ L(badargs): TAIL_CALL_SYSCALL_ERROR L(parent): + /* Check if scv is available. */ + cmpdi cr1,r28,0 + /* Parent. Restore registers & return. */ + cfi_offset(r28,-32) 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) - RET_SC - TAIL_CALL_SYSCALL_ERROR + beq cr1,0f + RET_SCV + b 1f +0: RET_SC +1: TAIL_CALL_SYSCALL_ERROR + END (__clone)