From patchwork Thu Dec 16 19:16:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: D Scott Phillips X-Patchwork-Id: 12696527 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 04175C433F5 for ; Thu, 16 Dec 2021 19:18:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=qRt3RvW/iorD2L7qxVEcIT4R7IlODXtWedqzEY48Q+I=; b=MK47YIxjCvgzPl N9AipyleWtplc9vPy9b4DpFf3s3VxhTozCxn6OMLu7+cNbyUAUvziY5O1X88u4kgD+E2s1EzBbAwW ur5xr7XHmogUdKpLAQ5u32BnrlBp2P+4xRXpCTD2bYP+t+4GsGxOxAR47U7+3FHQItbrPGoq1d12y 8m1KhovhSTalRCpCaNy8ZNTDU0cZEYcw7Od6TJxr5BwuZSKvP4PcOAfATmqGs8Ckz0y0aBMhWCR2U D+cb0IfKQ+rM4wnG6C3xpPCkuRAaJO1Btq0mMaBVyD7KhSQYV4CiNnuqkbzxWaW6NQu8J0LM8CCK0 1Fo2PyvSbSK6cGaBIfgQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxwF6-007Kj6-WC; Thu, 16 Dec 2021 19:16:41 +0000 Received: from mail-bn7nam10on2099.outbound.protection.outlook.com ([40.107.92.99] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxwF1-007KiT-0q for linux-arm-kernel@lists.infradead.org; Thu, 16 Dec 2021 19:16:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=atK7E7RgcMZiwc7Lzd6QshE6FxY/Nr3SOkG0V/FsuvghLGqoxCMrM4RKfPcXohEhd7AGtxVUapGZ+wTGPf6wwu6VHbqsJMUEWY5ULdL0SiJwGHsUawOiUD6JCfhCD4FFrnkCnYpw95bpwM4DJhpeIjKrkH7MMQyNK/YTl72605ikMItanUCwtTTZEynKgHJM7s0PCanuDIXkAOAnjejPEPPLMDwmZR+++Cxh3EgfJVrd92ZP2hRpEi2UXcyj0OHSliMIw2szzVnyCciuB6r0jLdJ8xa3+Kq1cQeICEPBbI/FOJjnBOS/K0sVRoin89hUy5p3obdWaNb84X5g9wOHOw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1VCywf5PfTmCfI7velMPrAPyRu0GqPFQXcJ69Ctd/yk=; b=DjFniN+aU3vD3aMDUIhqjwzNO7jAbmSp1nni550iOkxZRu4CT21N6ukBSnKoIEn9HKUV9+OHHPzUF1dKuaRRg7cK1IeAAxqdeXYje4OR7LKi64QskFMKHqjZJW/OHwfPWAQNhOLnVtNrDSVIbtjsXYwgve3ZA4qGtnS32YlPhEys8TaI0O1JYS2ZlQ2I+rKvwzo7Sa9dCbJwb7u/t+v4xS96xpQ6sOvoMRAR26TnJim4H71jvUEa5wxnKcLrGw2fORZzNzXIp3v9ubqj52X0Y9sZOs/UVRZgbmKZZVdGG7SAAyqRx7j9Kbr3KX9jwEuv6FYPRajBDztGnpuWjJo2hg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1VCywf5PfTmCfI7velMPrAPyRu0GqPFQXcJ69Ctd/yk=; b=kEsyc11Taz7L5dSXvygRrW6JgoRJXF84ClsX/VylDla0HxFWk/vnH4FQL3V9Vz3xZyOS5VdUxEhIKQXjYYBVY3NPIEtTJ4Ve1N2fgc7c3BR+PImSbs/5s2NKGo1jj9bBcZ/7j19/kdN1yewDHFNxb4Xl2zMaRc9F92WsUJNBWvQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from MWHPR0101MB2893.prod.exchangelabs.com (2603:10b6:301:33::25) by MWHPR01MB2223.prod.exchangelabs.com (2603:10b6:300:25::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.17; Thu, 16 Dec 2021 19:16:21 +0000 Received: from MWHPR0101MB2893.prod.exchangelabs.com ([fe80::526:8374:e93f:3648]) by MWHPR0101MB2893.prod.exchangelabs.com ([fe80::526:8374:e93f:3648%4]) with mapi id 15.20.4778.015; Thu, 16 Dec 2021 19:16:21 +0000 From: D Scott Phillips To: linux-arm-kernel@lists.infradead.org Cc: Marc Zyngier , Will Deacon , Darren Hart , patches@amperecomputing.com Subject: [PATCH v2] arm64: errata: Fix exec handling in erratum 1418040 workaround Date: Thu, 16 Dec 2021 11:16:18 -0800 Message-Id: <20211216191618.972956-1-scott@os.amperecomputing.com> X-Mailer: git-send-email 2.31.1 X-ClientProxiedBy: CH2PR20CA0020.namprd20.prod.outlook.com (2603:10b6:610:58::30) To MWHPR0101MB2893.prod.exchangelabs.com (2603:10b6:301:33::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 897b1993-3956-4ecd-1c2f-08d9c0c88ae5 X-MS-TrafficTypeDiagnostic: MWHPR01MB2223:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3631; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JJ2Sj71sI7u5xcQ3lG4Jw6ODIhQQteoplrf6A/hsNwWaggozRyulabGEHZNTcz5YNF4dy2GTS1Cz9kISqGp365bx6Iu8Ad6dSuzS8Z2O3Z1WuxMnurCJzHOd3SAlBE6czc9y8Q1SOoeAWocUzvsmTxSZx8CtzzJuOxyLzMY2VQG7fTne122UqMaaWcBvGP1fvkIf2+Y8056AZwpXVb62djiJGU4YExkSXEWyF8PvYwQ+eto9qcas1RR2UUChUgJx+Dq26dyafQMMth+oYX8raTMZplXPaHyiVzePsVUsisAjowHIVwcy5vFomcVbXYWtR8Yw43AHXiMpCJ436CInHBCcBUVLuS+kLR8t9ZIbiJyPd+Y6DPQhMp6m2AAmKm9B+RjAwjHwU8SL8tzKyqVNlkFUDqMJEw29ykkIq+j+0jeVVouVbfpWmkeVjEfEwkvukzZGVqFL/NKHQ/A6rTldL3h2QWYmB6Dl4dq6cLpa7mzDWXpukaxY7AGjlYM78165D/3pcLIpMuI0coXRYUK+m9GD3HMnydAx4piXIePTo0ndmsB6kEfGLKU6FaKHoz/HeTnKdkzVEejmRclWkLt5nZxoYhITSLtqRmbfnRAck+4zjnX+RUN5CeCCFOxJU6Sj2ybgfU3OuAbDCppz50sjGgfVk2agReR+X8jAvLKRjd+iMY64/rpUfAk7Y5x/lHdJqSazFPTzoABnSRqmdGODsQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MWHPR0101MB2893.prod.exchangelabs.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(54906003)(52116002)(508600001)(6512007)(86362001)(8936002)(316002)(66946007)(8676002)(26005)(1076003)(6666004)(66476007)(6506007)(107886003)(38100700002)(186003)(2906002)(66556008)(5660300002)(38350700002)(4326008)(6916009)(6486002)(2616005)(83380400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: l0+1J0lZCLgnnCLYXkr8F0kfLTD6ta7xzmy+O+JbdEM+8zmyoGtd5Bd+H5MJ57e7fcNxtQNV8Sg4eF0vGLeIHB/XWH5ZnMt/dz9uIFc+GB9BE3bbRVAtdf6Q0a9X2Rkujkj9iN1c34G/yuLPNQug61cja8LtC/xcMdk8hTfj2+u1A2VultUKtAv5/sWCOZYTbAnry2IRlDz8IBHAdmFfAz0neMPzUAM07OWd8xu6w/uDDqArnJCz243TaUG7pN3RijEAbg5wpn0OuYr0Z59XNiyFyhOohWoEXVb7LfQQjz3NHCwcrvBn7qhtTnznteeOkMhIsmhbecm1autHMrTRqZgFzxJ46jEihY0n1xS2bIXPD899Nb2orERaBh5P0TsvXIkH7Vb1mGI04G2cbL7Su85zfhPLwTTL0HNYiH+v7TqSbZd7DDUe+6NveQc2KSCr7JFefOIouwMKURT4cAK7+mS4TRb9eU0w9OoKF6pe7HUEKVzpI3CyV2vrCuyTjRyJBCA6mQnsmjiqGQeWUWhZPkR6dh/egeM7RndFBmVfHe7Xl6FZWp/DZI8UCbEpWTU+lcFSJHfg4ZdTAlsp7bJXMl9qxfnJqXXRA1qrOxxkZsmheIRkj+tSsP2I9FbSCupkL7z3RLQDsYEj9JoeR6v69xuRfhBy2UkJnC2zOtX55S3y8Z5hV0FVr+P9YeffXnwt6CLlpP3uE0PU9shdDCs3B9S3I3EzjjijgE0RhJ0wJ9qHwOS+I1L/bTv9POnB90H+/hOxeMhlDu5sswJS2j3779ZY3oD66fTss5C90CUpgOBviGHtxmUhNl3ijH20znyl5uHDiTCPxrU7KxYAgP1cLUaq8YlVXrlSUzN8FR12XPbIn+OtqlBNG6dqvRqZZE3v7LdSeV7nTQNrRhU9wiiCVUt/58y+LtPa7u63iRJuRCwt++sgISMBE67KZo0bbR6xb0aJ6Cwj0qODon6FVFjtx9glVDFDOTPwleW2YJS8fX0TFCEENKzqso78t5lzJMLk0iPY4hwuXDPSwsn4Pjt8UGBBZi3O+NCj/nG+lKZzd9xZCpNiLb2aft8xBiYhw3wVSmGLlitMzs7XzLJnGdwqRkRIQaeE3xXpCV2a4Gx7UeRkF/0PODKMw06w9A3viLBC7Qrh2tI2V68qaqVZd1pX6IXhLtlbLtkgYC+lyYarmtyMRXNmkkjyRJuRM4v5bZyoA3CnmWYSp+IrWfp65Sn1iJHu3eWp5IEuaQTQ52JmiGbQWZceL8zMUEfpPGzzHtsg2z2bP3Kh9TUqYl30DxIs0YM2VbHpbx+W3Fa9mqMFVeZRi8WGaCD8ud+x/KXlZmF61J4YsgoyRvMh70NX2r2eKeuxZIXYkcGFdyfImGKjPanZtG+STAzo7CFdyPOFgZCPelsYGKqkfG5tSjEAKUM6H0av1nP2iXAlls2agkATpIsWPTKBbYaOLfPM4unUKxS5kNqb/s3+zrJ98hyXDonAugoq45gCjesTektYB1XYif/t47KPnACCtsidDYwHj8dmZWamNf939yydT7C9fe+yT99/bZsRYG62pnuF3+fl46k0JJQq+0Nci1tUurvma7jYoS8xZU+6g6sYEUoISTyFKp/XhVLlVhLHSOrZw4GIJy/qaustNx65icmyWDbP8juffH+/lSy+u4erF3XCDUPXve1W4v24mZoG2ze6O5Hc0rYyAqWWz7vubOQE+hEwCUsU+3dt5xjBotbCHY/NXkWS1A== X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 897b1993-3956-4ecd-1c2f-08d9c0c88ae5 X-MS-Exchange-CrossTenant-AuthSource: MWHPR0101MB2893.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Dec 2021 19:16:20.9648 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9soAyGeJus+U178EIgNNjTjkOIAMXGSCaBRDbUhkCDLeTMg+26THXGAwxDNkp960MYfsd6ETHZOK7rCoqcfzUbUh9DGwBZ56s/dOlVDQNqkJOr7FItNw5nitpP1riXU1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR01MB2223 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211216_111635_150623_6CE6966B X-CRM114-Status: UNSURE ( 9.31 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The erratum 1418040 workaround changes vct access trapping when switching between compat and non-compat threads. The workaround logic assumes that the hardware vct trapping state matches the previous task's compat-ness. However, when a non-compat task execs a compat binary or vice versa, the cntkctl state and task compat-ness get out of sync. Keep the hardware trapping state in sync with the task personality. Fixes: d49f7d7376d0 ("arm64: Move handling of erratum 1418040 into C code") Signed-off-by: D Scott Phillips Reviewed-by: Marc Zyngier Cc: # 5.4.x --- v2: - Use sysreg_clear_set instead of open coding (Marc) - guard this_cpu_has_cap() check under IS_ENABLED() to avoid tons of WARN_ON(preemptible()) when built with !CONFIG_ARM64_ERRATUM_1418040 arch/arm64/include/asm/elf.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h index 97932fbf973d..24036b914226 100644 --- a/arch/arm64/include/asm/elf.h +++ b/arch/arm64/include/asm/elf.h @@ -160,8 +160,16 @@ typedef struct user_fpsimd_state elf_fpregset_t; #define SET_PERSONALITY(ex) \ ({ \ + if (IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040)) \ + preempt_disable(); \ clear_thread_flag(TIF_32BIT); \ current->personality &= ~READ_IMPLIES_EXEC; \ + if (IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040)) { \ + if (this_cpu_has_cap(ARM64_WORKAROUND_1418040)) \ + sysreg_clear_set(cntkctl_el1, 0, \ + ARCH_TIMER_USR_VCT_ACCESS_EN); \ + preempt_enable(); \ + } \ }) /* update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */ @@ -223,7 +231,16 @@ int compat_elf_check_arch(const struct elf32_hdr *); */ #define COMPAT_SET_PERSONALITY(ex) \ ({ \ + if (IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040)) \ + preempt_disable(); \ set_thread_flag(TIF_32BIT); \ + if (IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040)) { \ + if (this_cpu_has_cap(ARM64_WORKAROUND_1418040)) \ + sysreg_clear_set(cntkctl_el1, \ + ARCH_TIMER_USR_VCT_ACCESS_EN, \ + 0); \ + preempt_enable(); \ + } \ }) #ifdef CONFIG_COMPAT_VDSO #define COMPAT_ARCH_DLINFO \