From patchwork Thu Dec 16 20:48:32 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: 12696529 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 7D25EC433F5 for ; Thu, 16 Dec 2021 20:50:09 +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=01wNkKSCZFL595pXdRLA80hAzZ60B9EY3/aO7z+x04I=; b=T3TWI3XLHzmM6T AEgfYe8mbySSe7Gyn1fY2bDzLhBsuxORwgksKwJBJea7G+eLuc+oJ9EWBZI406MRVnr+0glRUSdhW pFPUhu5pejwG36Qy/9kHmLzOHltNlg1wkSYTGNc3ip8gAV5d9s/5Vt8AluOZej908f5aYsiMcvp7E 2i2r1dyiX09q//lUuox7wnYe8f899nAAIyLeCJk58/14yQc8UDd7E0We0eEoyLQSICfhj9nsiwc2S YGb3bIvWC++a1EGCzb7Q1Ceq7FTohigsLuGUEMAuZU1R4TFDC5RtP9Hos60eEiYtfZBsqbL3Sm1gV EDSy5h/+56bNqVCISohQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxxg8-007YKK-5J; Thu, 16 Dec 2021 20:48:40 +0000 Received: from mail-dm6nam12on2126.outbound.protection.outlook.com ([40.107.243.126] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxxg4-007YJI-QB for linux-arm-kernel@lists.infradead.org; Thu, 16 Dec 2021 20:48:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nxUoP4VdRVQijQMmFVMJMV/zPgg0qDrtOjJRFpdTtJBOGCHIZV1v9vMeadPuFTHkQ6D2Ztiraczl5XcUrW/xhn9nyYxAASjIAnCU44055SIvm0283CPwPbTjWeKg5zu2ZgfJWuWlXR+FXJWacT+JIcnLtA8YSkQC64I0ke8DMSHlIqBqCHKOl0e8W0Kkyb+chSjujPdAOcld+LZpYckGmA14tqWLQdH1d5q6Hr6kt+s7+JG0obVvusb9AnIJrAVJip8hKHkRuwrfzA39MtpUW4q1UgGVGtVnpb9awYi/eMoHZFVsOt1/WGUidKFzZBhZu+6+OYX0ZjskQb12psOh0A== 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=0lqZNFPGewo4S/l+VEwSv3EqIGIuQ6xW8NzyovEzJss=; b=ViLHvAANJ6HQC/loPeDKqId/ofkOXaeAfdnXHN5cvKIFX+EB92z8FrDNxpeK98hF9Lr10XME5OWuwL7qZ/Qo0U5XIIFaUmO36XIoLaN4XTChiwywa4u6hWTLexYmn0yWD99xrf30I2aDC4/zBv+NhCNsP1firRZPani9O1kwRJG7USXnwOMyhimLGmVFbLr7c2oXQ9oN+qrC5hM22wtBukOacIUXcJ7xhs1oJcUuLUr/5b+j7H+qo3qfbfF2Ns/TzRXMO5KoxijB+2e6yotnToO04H0pf42Si4/1rDTiFJ4cRTqxXtWnpK8eIPwmjBJBIqrMqO1cs5klfZyRo9zadw== 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=0lqZNFPGewo4S/l+VEwSv3EqIGIuQ6xW8NzyovEzJss=; b=YRDs3DW4mZTaTZlFN82ZHsR1kvi63vRW+a6PKJ5pWd9K6K8G1EmzDYlkhLVe+za2g07LwJLZZeEVXCw+vSPTxG/VANSfYBUqrfznILk9DW3jMCepXMKfmgpCLRe5eN/rMqWcWFkCe7w2p29JM81JnGZLmMf24rsZS5eFWWytvSU= 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 CO1PR01MB6727.prod.exchangelabs.com (2603:10b6:303:d4::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4801.14; Thu, 16 Dec 2021 20:48:34 +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 20:48:34 +0000 From: D Scott Phillips To: linux-arm-kernel@lists.infradead.org Cc: Marc Zyngier , Will Deacon , Darren Hart , patches@amperecomputing.com Subject: [PATCH v3] arm64: errata: Fix exec handling in erratum 1418040 workaround Date: Thu, 16 Dec 2021 12:48:32 -0800 Message-Id: <20211216204832.973813-1-scott@os.amperecomputing.com> X-Mailer: git-send-email 2.31.1 X-ClientProxiedBy: CY4PR01CA0005.prod.exchangelabs.com (2603:10b6:903:1f::15) To MWHPR0101MB2893.prod.exchangelabs.com (2603:10b6:301:33::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 097bbb2f-c19b-4bbd-4713-08d9c0d56cd9 X-MS-TrafficTypeDiagnostic: CO1PR01MB6727: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: rj1hfvIuhkRaE3n/BaWV/s/kkKHmffKQslL9+ysYkwjpwD0Yew1qd9tSzKRrq0PPJ5OziIap134dwy04A4xbDfv16KRbmfxlc4ElF5afptcx3PFWRBtEg1Alk9ORoq9MLqHRIrLCNWwN9kffOPlfkqSOH8RinG7Sw9hYAdHkGrioIyCCfiZ6KAivTEOQjh0vCeXP9w47BlpK/oLiYMud2B4i06VnOvcWgbUbOExc+0ukslybxfsqZ0ioN6bb/NNsZ2InBcaX4+9I7RtgzfNx3/pHH+1f+0rFxl+IMBmBKtml0RSraZVnXSjbnepTf0/0bEqlyH7wvw/mTzgxGb9UIRf4302CuKhYYysxh/7p/o3XF5S64Weu07hgcHvyeSqlL4ByHeTwvW4dx3i9FKPzMEZ9E3hbanHvmFBLeU/6Legph5FGc7uBatTFTrQyIx74N/7wYMlaEk286nRrnaFEsXkbIXDRN/u1oP/2QSksuzWCWAFY/tz0YwipaLz9LBJXFe/PqS9Xfh2ZYVgtvGyLkYJtrIsejKGnaIuN+JhTOzG+woOSQZWbhYaWQD0LOQ/PL6LOuA+GlHbxHsvypLrBPHsC8FmG7lYav5JraCh01CUYp5xRdEJeMm0NsaQvzRh0x7H2dCQAoJzyA0yj2dUb+EfOUabsi/VuAuQ1KoEMtIbD8PUJtn4kqlS8qHg9RczfK+d4WYneJvgnZ1Ah7an4qw== 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)(107886003)(186003)(38100700002)(38350700002)(6916009)(6512007)(54906003)(1076003)(2906002)(26005)(6486002)(66556008)(66946007)(66476007)(52116002)(8936002)(4326008)(8676002)(83380400001)(5660300002)(508600001)(6506007)(316002)(2616005)(86362001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bxL8N+TT+0WB5rAKnMmoApzYrmUk08srPBTK8lBfvHPJTAWpuKotj9f3K3dyISFVfAZX16xz4jG7skpvX+zOQqjFM4HVg8GbaQw9JxJZAAmjeP01Y+CHC6PCnj+t8MGl71adfYSqGDci/5IJr04NmcURRNtBoCwpVAxWgBV/B8snyFQALs09TNldefZCIYohYvvU3WVJbgWxHkR5TBVkY3NhiSY3+3cXr550T3upb1BsIzozzC+VrdIKwidZJFvxjNhwtXUdYhlmGLxMkGpAaV/b0Qc6AQl2QnDOg7K2m5k1wLuKHkG6jeuQKW6ikh50Z/J7rh46N0Zn2G4D2SUTfCzDP4TFIrMLTi8Y3sCSFypv/gBiP62jlry9MA8GpY9glr9Bp7AWPkACrcbzXf8gd2IOVSY2PpTPv+Sujjqq9GZ+S+Eh6Z1UEfG09QVPRMLGUUp6mSuV7HWyRylFGLwdWNHl28VkS2uADsH5at8S5W0UkjrDvNAzw8xSGUMOBQOtRRY0h7Lar6sePA2ypOrx5xJXcbnoYDBg7XrUfEirTSoFvqSW1/fnhq1wS68jd1oPJ9/QAu4FvR+EGUxU/oE9j2vwVx4/D2rHCMUexGJtCDcfxqlfZZjcbmypBXXKmjT3bP8vxObOpaayztJPoYJbDGrM1+3zibBTLkM9kbFkWHl+le28YPgU1EhYSC5IOn8nxeed3N7Ac7gdE10bF5BWmIoB1pR3WBYWD9JRudKGX2WyJ1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cd9 X-MS-Exchange-CrossTenant-AuthSource: MWHPR0101MB2893.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Dec 2021 20:48:34.0287 (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: 1vM1Q7vzgeycMQVABQHEOLw9st4tCkUpfsRIDA0A+qPzI76O6ktmYQPRFgjt13pvPdj7Md/8xcTJpluiuLzlrUcB9UJ5u8tHikIIi1HhQXAXfFmgkXYF14SxXy/rvIA0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR01MB6727 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211216_124836_944326_0246C94A X-CRM114-Status: UNSURE ( 9.50 ) 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 --- v3: - Un-nest conditionals (Marc) 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 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h index 97932fbf973d..77b2e85b3e8d 100644 --- a/arch/arm64/include/asm/elf.h +++ b/arch/arm64/include/asm/elf.h @@ -160,8 +160,19 @@ 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) && \ + this_cpu_has_cap(ARM64_WORKAROUND_1418040)) \ + sysreg_clear_set(cntkctl_el1, 0, \ + ARCH_TIMER_USR_VCT_ACCESS_EN); \ + \ + if (IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040)) \ + preempt_enable(); \ }) /* update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */ @@ -223,7 +234,18 @@ 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) && \ + this_cpu_has_cap(ARM64_WORKAROUND_1418040)) \ + sysreg_clear_set(cntkctl_el1, \ + ARCH_TIMER_USR_VCT_ACCESS_EN, 0); \ + \ + if (IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040)) \ + preempt_enable(); \ }) #ifdef CONFIG_COMPAT_VDSO #define COMPAT_ARCH_DLINFO \