From patchwork Tue May 12 10:14:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 38962 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 A33B2395447D; Tue, 12 May 2020 10:15:13 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-eopbgr40044.outbound.protection.outlook.com [40.107.4.44]) by sourceware.org (Postfix) with ESMTPS id 03FA9393C8A0 for ; Tue, 12 May 2020 10:15:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 03FA9393C8A0 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Szabolcs.Nagy@arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gCl6sW7mCoCA//0zWG2acz3tD0gfnzy9/7fzgEUKjyo=; b=QPmBTh6BrbakaVhqaRXd0+PQPCo+i6nl2+JePFnO23AcfHSfPwI51X4Vdvve+CGGLFqxtrpW1mA/6lbJ7/QO9rOqj2kcb7ejkIJ1nZNbl2Xu+GlXhgzSoUoV+gfxTEXtolyMdKzpd6edRtnetlzcWWLZRRcATU/LdjJT+I1yhME= Received: from AM5PR0201CA0015.eurprd02.prod.outlook.com (2603:10a6:203:3d::25) by DB6PR0801MB2023.eurprd08.prod.outlook.com (2603:10a6:4:75::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.33; Tue, 12 May 2020 10:15:06 +0000 Received: from AM5EUR03FT021.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:3d:cafe::3e) by AM5PR0201CA0015.outlook.office365.com (2603:10a6:203:3d::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.29 via Frontend Transport; Tue, 12 May 2020 10:15:06 +0000 Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; sourceware.org; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT021.mail.protection.outlook.com (10.152.16.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.27 via Frontend Transport; Tue, 12 May 2020 10:15:05 +0000 Received: ("Tessian outbound e88319d7ccd0:v54"); Tue, 12 May 2020 10:15:05 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: b94957e418bd7f38 X-CR-MTA-TID: 64aa7808 Received: from c0d9ef014f6e.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 3BCA5F99-8A1F-45EA-95D7-65B803DE1C7C.1; Tue, 12 May 2020 10:15:00 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id c0d9ef014f6e.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 12 May 2020 10:15:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GtbBVnGoTQ1hrSjjkynB1pG6l+IuL1IVpkMiJc6GS0HG3x6XOggMDDmkYL8YShfPHfBxbaTmkdQUWHiDLnEyTwhSUbeRPWUPw3uXuA17/Az0Jlv8E3eGmLFY3tzLvsy86HsaZTVDWDrnGOvy+xS6rzeEnNEvIzgAqnSR7ISk+802awlSKEA5y6BkfiSix3sjwff8WJxHYeouywDrmMfr+v9bBeNappxTyAywOpFKW3WATJtkUcOTIUQRmPLtnHaPNGGd0dMzU9wBUbsHiw4qQJ/SAtC57PYzbV2nx57E2TsPqBgov6z2Zu7w2WBZDvXAE92Vy9M9mw5gHtQNeG1HdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gCl6sW7mCoCA//0zWG2acz3tD0gfnzy9/7fzgEUKjyo=; b=O3DYl3UPeD8GpckKRJcHDcC+PnFGwhMX0RAx1gcP8og/CfFLvONuo8oPKXb2WBLo3i+teyEXuXYbRV4dQ4zj2cD0Lixb8YsLjNAmlq+0T+WG7ZpqkumkH43rsVsREoGpm9Dh9c6k4sjIKv7oIuF10YVBw4wzlQeqi7qNIAGoFpbgFEp2gy03Eqd0QsAueoChwvZkp3GO/hz2DKANM2Dp3fbXqOgj6ftVOJKvp/dP/J8Vgw+0rrjkIyoXnvBS0OZOeBStWpXr9uZq/6vYma8V1FTzF7Jaj0cRzbypdFK+kZLS0xIX8Bv3djHKaBGVOaMwklrSTMRbgS+W3ZT2vJIp8w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gCl6sW7mCoCA//0zWG2acz3tD0gfnzy9/7fzgEUKjyo=; b=QPmBTh6BrbakaVhqaRXd0+PQPCo+i6nl2+JePFnO23AcfHSfPwI51X4Vdvve+CGGLFqxtrpW1mA/6lbJ7/QO9rOqj2kcb7ejkIJ1nZNbl2Xu+GlXhgzSoUoV+gfxTEXtolyMdKzpd6edRtnetlzcWWLZRRcATU/LdjJT+I1yhME= Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) by AM6PR08MB2982.eurprd08.prod.outlook.com (2603:10a6:209:43::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.28; Tue, 12 May 2020 10:14:59 +0000 Received: from AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::49fd:6ded:4da7:8862]) by AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::49fd:6ded:4da7:8862%7]) with mapi id 15.20.2979.033; Tue, 12 May 2020 10:14:59 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v2 07/13] aarch64: fix swapcontext for BTI Date: Tue, 12 May 2020 11:14:43 +0100 Message-Id: <595544959bbbcb6aeb16c9bd5344a9684788f2cd.1589277641.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: CWLP123CA0056.GBRP123.PROD.OUTLOOK.COM (2603:10a6:401:59::20) To AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.55) by CWLP123CA0056.GBRP123.PROD.OUTLOOK.COM (2603:10a6:401:59::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.27 via Frontend Transport; Tue, 12 May 2020 10:14:58 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [217.140.106.55] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 601d107a-acd3-4207-00a6-08d7f65d57a7 X-MS-TrafficTypeDiagnostic: AM6PR08MB2982:|DB6PR0801MB2023: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:10000;OLM:10000; X-Forefront-PRVS: 0401647B7F X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: PF1kD3dZQnHfpoAjV90xfd2GKsJGTtiM9KlFTthYyLuLdcj+EVnDyKGXlYP5ERk39WM6zN+aWw+kh+IoVI0duJbkNjRf0aw19BT3tdgTpiHQ3BeoED0Ku3lKz78i6H86DgyqvMDxb8TtY7sF8PccocG77z5h8uHZfgZ5LsAuz96p7hV0YlqA9C2c9gIrdENo+OcWVZERLgjiUFx14xhBwjGG677Facnz8UnwtTnavmuiAWJv8+ip/f2bMVrOXxZQUeuq1JPHogCJhe6MYWEvauW9cZ3e/iCHTwhLq6EjKKc089o03hWWi44sI9gIfdx1Aur6s6sjScXIjMqwO1v/L9hvQyUqsBjcnvqYry4ZwT86RCsrLBHAp8VRzEKDyXWsq/lQwnX1d5rFfXkcOXxYEp2SAUMsJtVBraiBLGx2nt3gmlYID/bHJuhtJy6JujOkGyxkzbkRud7TIJWCKZdJiUobc4Uzs3O2xKTN7gXgP0948P7en+qjtA04mH9JDeyyRvDHnMOgEvbEONKDSz0SY8SzbKXePJLKve6VHq++3Fq79QVaUGFOR6vUG9zmUP2XFE1qBoSGhMx2Q0oKC6BY7Yq6UbD+iE/Zb5rwEkojGrU= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB3047.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(39860400002)(136003)(376002)(396003)(346002)(366004)(33430700001)(6916009)(16526019)(66556008)(66476007)(36756003)(44832011)(5660300002)(52116002)(86362001)(956004)(8676002)(66946007)(69590400007)(2906002)(6486002)(186003)(316002)(2616005)(33440700001)(6666004)(478600001)(6506007)(6512007)(8936002)(26005)(136400200001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: U8BrhvZ/Gp3fVVczO3rfIuWpcZCThZhQa0lm1+i/NWpyzplPhAsU75crdeEJaMf3VVM3ih7PVWLpnafN/OpSUACK+UNCIKh6TWDegmiW/REiBVJkepgS30Ow4WNZ2WGoar88QMAlCLvLERuiIKRLbYWKG0QwQ9Xh6J8Pn8MN+O+jCJbCRz+C2Uzhp7HEBq7ga9mAG0agatVirjoUQUE8eFWccp//RXuNRyJ6SbII2BclPgwcjQMg7YXIH7H7igz3YJFG1wPM3Q/7RvFpjsfnUhfsa4AooxrAU+Fhp/3xOGrcJmnHnF6EZ1nvB5ZAIetoOkId2mqGzXY08H4uyhh/eYAXRiURIyl+ZZiqn3/zx/qrKjs5kYOgqdz20lwd2Xgb/ibd7WHbwdYXKE5V0OStMS2KofjvKYjXt1IYE0MvijqLLgSpBW22FpWMls1QIzbw+gBMhKdm9eF78dwq7kse4ysawGqszD5LJPDQEORgxYtbBbUtDpdNf3g4b1QSomJ3 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB2982 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT021.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFTY:; SFS:(4636009)(39860400002)(136003)(376002)(396003)(346002)(46966005)(33430700001)(186003)(2616005)(336012)(44832011)(2906002)(47076004)(956004)(6666004)(5660300002)(26005)(6916009)(69590400007)(16526019)(6512007)(6506007)(82310400002)(356005)(8676002)(82740400003)(316002)(8936002)(6486002)(36756003)(70206006)(70586007)(33440700001)(86362001)(36906005)(478600001)(81166007)(136400200001); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 06a9072e-6296-4ba4-2202-08d7f65d5358 X-Forefront-PRVS: 0401647B7F X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yrk++Ep6KZAyN69He69IH4hI7KAgyCJKidzPHZL57P0mqU6Q7El3nwpWqWgRD1QNpH530umlVFRN746fw0ZGmldDUjgYDnxe8v7cHxgjOabDEyoGjG/aj8hlPp7hxOtrvH8RDz/99H3Z2KnSnlDML8NVnyjlNA/B9uFZZte/8SNqpzwNFhRHz9H7Q+nON8BcSCqnG/oClt5KMqcfmF+PjaJPa+YcFoaykX5FwG6CLk0cBiQCOTbmz4xD0QAJwTcuprSBBBjY4HKQvAFKw45xvRybgFFk4L/YSqiaCV1Aa7lWdUsQkkSyGRs9mCXP8P7ZShIp0oCM66U9A3Z9Qr5WIOv1SyXlTp5VH/DOUCOmf+yraU8Jzzy/6DVH3Bl+xU07fIw9JDqhponaBmsaD9PLGs4VXqS9neQioKL4Y5yulsKovy3zyr5mwUzNWU3CumLMcIPORYEaUh1vywldaLrdl+rJEuXvsTGSDYwleI7v8ryjHLxNgo6ya48UvinjuZ27b2evjgNGZk8dg3IbFbS9RQSziWI5nsOx44u3+L0MhUyRWBGv2/SvQj7CFofy9Pvow5Ncw8aZotlHMPViWzfh+2sRFjaVkhitBvZP0f+pZkXQ+61FhK9rVqiSxunXTA72R1+c4bibKyZYrl1LNa5lYA== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2020 10:15:05.8538 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 601d107a-acd3-4207-00a6-08d7f65d57a7 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB2023 X-Spam-Status: No, score=-19.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_STOCKGEN, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY 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: , Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" setcontext returns to the specified context via an indirect jump, so there should be a BTI j. In case of getcontext (and all other returns_twice functions) the compiler adds BTI j at the call site, but swapcontext is a normal c call that is currently not handled specially by the compiler. So we change swapcontext such that the saved context returns to a local address that has BTI j and then swapcontext returns to the caller via a normal RET. For this we save the original return address in the slot for x1 of the context because x1 need not be preserved by swapcontext but it is restored when the context saved by swapcontext is resumed. The alternative fix (which is done on x86) would make swapcontext special in the compiler so BTI j is emitted at call sites, on x86 there is an indirect_return attribute for this, on AArch64 we would have to use returns_twice. It was decided against because such fix may need user code updates: the attribute has to be added when swapcontext is called via a function pointer and it breaks always_inline functions with swapcontext. Reviewed-by: Adhemerval Zanella --- sysdeps/unix/sysv/linux/aarch64/swapcontext.S | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/sysdeps/unix/sysv/linux/aarch64/swapcontext.S b/sysdeps/unix/sysv/linux/aarch64/swapcontext.S index d30c543e6f..b60cf04c92 100644 --- a/sysdeps/unix/sysv/linux/aarch64/swapcontext.S +++ b/sysdeps/unix/sysv/linux/aarch64/swapcontext.S @@ -28,8 +28,12 @@ .text ENTRY(__swapcontext) DELOUSE (0) - /* Set the value returned when swapcontext() returns in this context. */ - str xzr, [x0, oX0 + 0 * SZREG] + /* Set the value returned when swapcontext() returns in this context. + And set up x1 to become the return address of the caller, so we + can return there with a normal RET instead of an indirect jump. */ + stp xzr, x30, [x0, oX0 + 0 * SZREG] + /* Arrange the oucp context to return to 2f. */ + adr x30, 2f stp x18, x19, [x0, oX0 + 18 * SZREG] stp x20, x21, [x0, oX0 + 20 * SZREG] @@ -97,5 +101,12 @@ ENTRY(__swapcontext) 1: b C_SYMBOL_NAME(__syscall_error) +2: + /* The oucp context is restored here via an indirect branch, + x1 must be restored too which has the real return address. */ + BTI_J + mov x30, x1 + RET PSEUDO_END (__swapcontext) weak_alias (__swapcontext, swapcontext) +END_FILE