From patchwork Fri Jun 12 13:29:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 39578 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 5E327395B06E; Fri, 12 Jun 2020 13:30:01 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2055.outbound.protection.outlook.com [40.107.20.55]) by sourceware.org (Postfix) with ESMTPS id 8F8DC395B04C for ; Fri, 12 Jun 2020 13:29:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8F8DC395B04C 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=1B/jWlnGw6SE/g7p1Ew3WX2EXXdb7IFvovtKhBA1zHE=; b=OHBjULOhP0u42/EjUtWWjD5GafCXwjFnFT8OX6Lv7UxOPLzu8PoETpRwHYKDSfcvcNhrwCK77za+hv43jolOoOgInKttt/NBzro4rAIfxUzwkzYlkMGHBk9FLhPXxYh+ymC1X2aS45ZnMU7Os2iK0e1/lXH1wiCQIqadKIfNsgY= Received: from AM6PR05CA0013.eurprd05.prod.outlook.com (2603:10a6:20b:2e::26) by VE1PR08MB4686.eurprd08.prod.outlook.com (2603:10a6:802:af::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.18; Fri, 12 Jun 2020 13:29:55 +0000 Received: from AM5EUR03FT050.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:2e:cafe::2c) by AM6PR05CA0013.outlook.office365.com (2603:10a6:20b:2e::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.21 via Frontend Transport; Fri, 12 Jun 2020 13:29:55 +0000 X-MS-Exchange-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 AM5EUR03FT050.mail.protection.outlook.com (10.152.17.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.18 via Frontend Transport; Fri, 12 Jun 2020 13:29:55 +0000 Received: ("Tessian outbound d3ae83885012:v59"); Fri, 12 Jun 2020 13:29:55 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 64f412ceeef552ca X-CR-MTA-TID: 64aa7808 Received: from 343435107846.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 5A743880-748C-4BF3-95E7-A7F5CB364941.1; Fri, 12 Jun 2020 13:29:50 +0000 Received: from EUR02-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 343435107846.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 12 Jun 2020 13:29:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Hev/Vph3tlDmz+M1uhxuFONVV/Cs/NDmzLaCG54LVwb6ZxROJORMN1C5HGqND+DdsK9TnW3O250N9QN3DvsUFgJ9Rdsbd36m6/mGBUG5WJoSSJFmbchFzfDMAID7w6gcKOXEQuq0Snlij9QEvSZ4rxunu4LynyqejliA6JtYJyL9tW7XgHFx6kBW3rcEazmyjMeSzaq/izc3YPCi+gA5MODUKK8M9X+eS5LZ5kfZF12w+obLZXST61M4u9BNqkchZLlifPrpRpc+n4++VFqJ0E4ZLg787zA28dav/1GMnqEXSBM51dplyDns7zYlHqbcZBol2mfGWN6UIPwIq4/u9Q== 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=1B/jWlnGw6SE/g7p1Ew3WX2EXXdb7IFvovtKhBA1zHE=; b=NEzaFoHZk72TZPGbeGoGjpPp9v9zQSezuTxWwkAsuVcOyAwDfm0doA/LUv/krgjCeJ3Z76FpFlvhgs6loQ1OEe9w56le4A3rUMgQEwqkZBPNSH+iNDWgS1U4zwzC383GwTlc+b+v9BFOVKKmPbMKW4eI4ZQhP5vXHQBHDtjQfSTzmRZSYNXXNxxuGg8nJX9l3MepAL3HC0sMd/TRrfNY7xSzIfMK9LRHjo8XRJ6Hj0p5DqUvlvTDsUcvCmEILq1JnTeabvVND0lkBcNjmjrQRbWFVYQyKVYgMXg686BdAqLTxt9VyyWkOQFQ26QWYqBOK/TXEh9VF6odJOnlN+6vJQ== 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=1B/jWlnGw6SE/g7p1Ew3WX2EXXdb7IFvovtKhBA1zHE=; b=OHBjULOhP0u42/EjUtWWjD5GafCXwjFnFT8OX6Lv7UxOPLzu8PoETpRwHYKDSfcvcNhrwCK77za+hv43jolOoOgInKttt/NBzro4rAIfxUzwkzYlkMGHBk9FLhPXxYh+ymC1X2aS45ZnMU7Os2iK0e1/lXH1wiCQIqadKIfNsgY= 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 AM6PR08MB3912.eurprd08.prod.outlook.com (2603:10a6:20b:86::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.24; Fri, 12 Jun 2020 13:29:49 +0000 Received: from AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::2404:de9f:78c0:313c]) by AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::2404:de9f:78c0:313c%6]) with mapi id 15.20.3088.022; Fri, 12 Jun 2020 13:29:48 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v4 05/12] aarch64: fix swapcontext for BTI Date: Fri, 12 Jun 2020 14:29:23 +0100 Message-Id: <205587f38dc8ad7cda68f64c323ed0d9bcf56583.1591899092.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SA9PR03CA0017.namprd03.prod.outlook.com (2603:10b6:806:20::22) 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.53) by SA9PR03CA0017.namprd03.prod.outlook.com (2603:10b6:806:20::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.20 via Frontend Transport; Fri, 12 Jun 2020 13:29:47 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [217.140.106.53] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 7bb40deb-2422-4cab-1658-08d80ed4b21f X-MS-TrafficTypeDiagnostic: AM6PR08MB3912:|VE1PR08MB4686: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:10000;OLM:10000; X-Forefront-PRVS: 0432A04947 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: ge5X3cU/LuobpnqCnM82AaORA5B0AWnYYJbmC2WDlZac5BaQfTNEzaA4oDKRdrrxPbMSJv3CAG6nydmwEHv/mC8HIYrJgwWTwejlita3rQNht7F2t4KV5SVfFmHEY85/TrP44Wa1PNiG2aLpqYvP3JKA6mPM+3VL3Nh/YroFsNkDgcc/18udRjov2YHgPWpIVwsXWeZioYuuLa0UjRFWAl3vOpJF66LEr0T1m+U2eSu7lFhYn44MF5f7HJp8l6CmJzyHqFWZj5Z3a51wQYa595RIPMfNxFNuF9YohfLrisI871PVtJH9KOEn1B2IIHT28T6uzeDiYgSo3U5Jyuo2UIdgduTRFy3aD+pD1J/NXW7rY9LqQN+jLQzuzWbNUdathdOUWdk8NVCXlduUgD67hS5SAsh1Eb7yHXLtdXJB35M= 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)(136003)(376002)(346002)(396003)(39860400002)(366004)(956004)(66476007)(66556008)(66946007)(6506007)(26005)(6512007)(5660300002)(6916009)(6666004)(2906002)(8676002)(6486002)(52116002)(8936002)(44832011)(186003)(16526019)(36756003)(2616005)(316002)(86362001)(83380400001)(69590400007)(478600001)(136400200001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: pg3LV3juQoKPYctFFsKVsKe78u3Gb2TEkPaSOgDakYKyUxdk8usN5Kkts4UyoUC7GERVpXkYZExRxdHveRM+yOD9ts5E16GDxZY1Jhd8Y+LuDmaJWi0S0ND3dm2SEkAta3ktWlx7VaXFOS0uF8+g5KIs58kDOMwlpGAKYQrRK6vT9ng/9K23/vU9S+acXnR8mkSFXe5TxdShkd0eo8nBIWwxYLwj2gBTX5mXWRm0C6ZqyWF7NAFUdj8+L7M3kG9AuQbN7sNc6nPlmez+E0jnF/rpvfJnWY6SV4EMzeqW7kJQprM+61lm2xMCvC0YqobHjsDlK3HP1hDvSa65eC5DUNe/om3dGdIMdd9HcoBI2d47HpYbTp83u1pUhMqsBJ1sZL9jwKA7REm/F245pS0GubITBQIDX/VPdJQIdZUDk2w4VcaaFbgzGQkCHJ5njM/eI97IGFp7KcLJf598vsF3PcLWHnYXQDGfBS3aV6x/+aS6Mee/JGRq75fLTD4DyLLJ X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3912 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: AM5EUR03FT050.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)(376002)(136003)(396003)(346002)(46966005)(356005)(36906005)(69590400007)(8676002)(2616005)(6506007)(956004)(44832011)(336012)(2906002)(316002)(36756003)(86362001)(6512007)(5660300002)(83380400001)(26005)(47076004)(16526019)(186003)(6486002)(82310400002)(6916009)(8936002)(81166007)(478600001)(6666004)(70206006)(82740400003)(70586007)(136400200001); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: d9823608-850d-4b3b-b72c-08d80ed4ada7 X-Forefront-PRVS: 0432A04947 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XVoKjs7kXMVH5iu9EtoDzsvUPgbmj7JK/wwuQOZDsN4CldGf8o/GvsyKVTvKz8bxp2JrDegl8pXUcQrt4/EhryLmtrKxC/lnc+K8jJFbJCKH7Gx7qGFWi1g5EhBm8oK3eJYRDCjBl8Fy317g4iSiVMrJP8n34G4I2ZL3rMaB2a2H7bDZfWvUZkOtOv438+71AkBJs++w9G/qUC2swvJXk4hDw45zEcijlKNHMx0YYBEOKFIFc6iOWZ/QUph3GTyjDsTjAM3qQKCmya9UuKmFNbZColVOY4yzeM0/Q5GA4uoSonsaj+B8WGsSlm0IdCxNz82SW947Uxzl8wBuxvO4ZN0v+ZD2BLUaZIk1ZdQpiNiQcV+KVZG4IrUoNIEIz3PCb0ba6jQJaAhckHyx3CwQPNEYrMdycUSbyCVfBEySBX5rV/m6Jjt/n7NHgtNaHhfVXOJKKDdH27HlCkoM5LYN2A== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2020 13:29:55.6542 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7bb40deb-2422-4cab-1658-08d80ed4b21f 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: VE1PR08MB4686 X-Spam-Status: No, score=-16.6 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 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sysdeps/unix/sysv/linux/aarch64/swapcontext.S b/sysdeps/unix/sysv/linux/aarch64/swapcontext.S index d30c543e6f..f8c66f0ef0 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,11 @@ 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)