From patchwork Wed Dec 15 23:02:40 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: 12696355 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 4470EC433EF for ; Wed, 15 Dec 2021 23:04:25 +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=jvETrsOKueDiFYF06UpTEdHBZrHQyAB9obTLIOpwHj8=; b=FigisQXRXX8s7w YX3I75V+YBx01I+Qjsozbozw98/If/TZJvl57CyH1yHTwTMj0awUMd2nVx6pkAUl2/lyIc1D7ctk0 3cnxJpeQzpASPSn6aPZVZW+HgHLLrI0duNwcNsIl/LSV8FEe9PyrEtLMY0b8P19vNdD4DQx/Kzgj2 fzdpO6wEvHd/0IQHDVuTYsoXH3aRZw9BeGB8FvE83uRy/Bi0lAQSKo65YM79haRozfLMxot4JaWwu 0hvT4cagR8YU8ATJRMOG6uknEBEBH/n2V8BGDDXxFBZ6gd6+ZTvZajpjY4MvrkC+FRP9MIbhBTVqN dttPWi0la2JMzDzEUsEA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxdIT-0033Ro-E7; Wed, 15 Dec 2021 23:02:53 +0000 Received: from mail-sn1anam02on2072e.outbound.protection.outlook.com ([2a01:111:f400:7ea9::72e] helo=NAM02-SN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxdIQ-0033R5-8a for linux-arm-kernel@lists.infradead.org; Wed, 15 Dec 2021 23:02:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k10wmPmEoxStTxDC3Vyo/QUPaSuDGEsWio3jxtFFAeJ+hC+jBMADAXarcbhpkk4hnB7jAkWJB6UEgC+GYh8I7QJzCY2Lorc0pGZFZjXUedLM7e15E6CBw690qO3oz38XhFW0V2DjCKcmeL1umALio3si+cyXfv6nHFMRJweMs46W8jVZOUw7u2yd0aY/4dnLfOMt0w7QpKc5prGepjcvM+PCOEkC/WGc67ArWfbmJvnbCRjOxJSHV75MYuSfjChIiISdBjPSEG2gw9TBI99f4SWwWKnFemfcUqnBeKJs6fZ1O10fhcVNQz87TQ+taXS65J65E5HQ4HdkVlV2gGmF2g== 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=UZUFOZGKEV7C4QSyai4QQDnwqVmiiNCqEyUnVH0Te68=; b=mscr8nMk5AWm8bEZ99V6kng3v31QCUKnH8xxzTTPdGJ2L2aDGCpJU3MiO/quU8hzJPi67kVfnK/nqEuc0r4EFcuGfyLm+h2aUvmYObF9w21yvdNsVEzWR60Y2iSELApMov+xSVper1KFmbnJx3ZifkKlNUT/wBbwPALBE3Zb3U1cpEqYvBQlFPX07Veh4gOfgwOYIBOw0V+34Xj8onS6lITf7jEb6FC0fCKFb9bXhMDm20sA7gy8mJ6Y7JHyRSH9Bmm/pDbbdW1KHwX54QHEXUtvbvmZq1nBFwJQbct5ypaVuc2CRhmQ3hv3lAqHLlXcmmDNYJ51+snvTbjqTPa5xQ== 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=UZUFOZGKEV7C4QSyai4QQDnwqVmiiNCqEyUnVH0Te68=; b=UrrcgEMrEz5HKiGaauMyJLhH+aS+BRwgJw/WROjDfp/MslXxyV6lVGJP5uODibgOFbSvTQMzv1PpL7CkcTFH8EFgYL6npoHerJfyHWitCeoS0ZtoTtOxLBzWWT8NQZgYlu6Gvy9sSPuVI2z27jWsLrpMrKZpvX6psvXmlZRhhvY= 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 MWHPR01MB2526.prod.exchangelabs.com (2603:10b6:300:3f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4801.14; Wed, 15 Dec 2021 23:02:44 +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; Wed, 15 Dec 2021 23:02:44 +0000 From: D Scott Phillips To: linux-arm-kernel@lists.infradead.org Cc: Marc Zyngier , Will Deacon , Darren Hart , patches@amperecomputing.com Subject: [PATCH] arm64: errata: Fix exec handling in erratum 1418040 workaround Date: Wed, 15 Dec 2021 15:02:40 -0800 Message-Id: <20211215230240.604489-1-scott@os.amperecomputing.com> X-Mailer: git-send-email 2.31.1 X-ClientProxiedBy: CH0P220CA0024.NAMP220.PROD.OUTLOOK.COM (2603:10b6:610:ef::16) To MWHPR0101MB2893.prod.exchangelabs.com (2603:10b6:301:33::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 157358a4-4ed5-4066-e92a-08d9c01f011a X-MS-TrafficTypeDiagnostic: MWHPR01MB2526:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1107; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mWWhQ043pNIAGd/mKFQtZNgxnI2TI59EZGrhSW0lZvX2KqVCtxckZvjbyPEnZn/m7RrlsnJcpdJcBZB2Lsq29GboWuXTqeWdgput9EkC9ThZyJPzDx6UmGi/1n3TiqChmZ7BLAnJta+JGfl/EU1KShOe3R0rd6nRGSGBQG8xmFZ7A/Umakfxsq8QqpKCY0JkzVeIVW+1xTXGmfvxqTuA6+e5s39m8ZBdCn+KRiMH5+r64mLiF/qjIqrjrqEFgdUDsBTwl0QebJlIgOIDnSHBXjuw0thXehNyRMChQ8pgSRJutKz7+Y8H73oi6fDtr+dT1nBDY9A3WVKP/2fsocN35biiyD5rjhxegFjouCOHulHGU6ugSWxEZLy8yvtzUKfJYNL9kxLzs+J0ytdgM70MdRhxMJwuWoY0S0jtSYyIEWHfUKgsIE++L0MasQoDb+AQSFQCA5Y9xpJQXnKm1E+G2ttCJ7VlAvqQEuy/IKtW+BLdVYtE5+KWf4SVLlNDjaf4ELwBADLkAHnfkkhOgEp+W6RS2q5+bSiWpfrGaOpksgmrJVd2bn0SDgo+h6ef6hi6fV9opMptTalMJA2hxP3ITidLXPHzoiVUnuGkcAiN7kGYc+r2XrkV2qS2EByXxkd1BsowrwqNTClfGiiNPa30UVkefrgTub2PSbFBK4y1dE6MXFna9XvAT0r3YYQey03TqU2acwFNDNQkTXgXrNmqCg== 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)(66946007)(38100700002)(38350700002)(83380400001)(66556008)(66476007)(1076003)(2906002)(4326008)(316002)(86362001)(6506007)(508600001)(54906003)(107886003)(2616005)(6486002)(52116002)(186003)(6512007)(8676002)(5660300002)(26005)(6916009)(8936002)(6666004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6zC52aX5ptY2j9bJX2uGBLqIUnehA+wdkPlq62edNy4L1cDgjXoxqrG4/hWSBbbs7AD5p1XUFZflc/CrBDNf8GOKXUQLPLjGP/guDVNivPDKvzLjVwVTO2lhIZIbAieJOhpvXMS/swXy7Qn9vmyB5eYzE9wUdlfwIoGsIvm3/CCwZdfgVKN7qPx97030ghOSmg8zeM4ZVtzSnUTThNuT2jXD7JxGOoLwAnA+pq1yJw6k2wB0xmkYRmum/3+FzFIgMVAhwc+bS5wF1CV7lmXhzBpmN7Y8l5XVd6ihatRINv6y9NSuwVA5zOZ2GIiW6nF7hksgARV5pZW0/q3PvyVAMcPk9aVYvguA6b0m0ULHySMDXIcBG/+gTYBaWeQJ5OQyygqhcXY7zk+trEIRwWN18f3JHm8fwZRwH6XUqCxCOLHERPmuhYiaUjOI6vMznmA48Tc/YOi4bE/Q7d3aWMqRg9HQm5Qf3Utc/bFaRWk2S5J20JZcE90A4W63IyDgvBJjnDz+jOLUi2TicJX3zM8Wt26Fgb7nKaGS4cnzL7c82U8DD6RCG+K3nwVhHDmv5kCSxR3DmtcASeGf7E0DyW+Kvs5KpOA1rVGdgXTFaCSfabeg6tTn8iflwVkGMHZ9YdBhKQ6CEMhmVTm6GjoFXrL7u6BtvT17N5Vgj5Jp5Kaz3pDwRe6cvrlk4aOoU3n6ffo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-Exchange-CrossTenant-Network-Message-Id: 157358a4-4ed5-4066-e92a-08d9c01f011a X-MS-Exchange-CrossTenant-AuthSource: MWHPR0101MB2893.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2021 23:02:44.7820 (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: VZvjFh0bI3CQiFFXpH8xsQ1SKIoUrWmlREJ4TKGNnFhG6DTjnBU+XdmeqYcSLBB/M3JHW6zLZosiTjwsfFrBn36io2Qd7v99edMv8SKs718ZOyZE2cbdGvFadQ9e/z96 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR01MB2526 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211215_150250_421149_3DB648E3 X-CRM114-Status: UNSURE ( 8.97 ) 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 Cc: # 5.4.x Reviewed-by: Marc Zyngier --- arch/arm64/include/asm/elf.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h index 97932fbf973d..463ff8f00aa7 100644 --- a/arch/arm64/include/asm/elf.h +++ b/arch/arm64/include/asm/elf.h @@ -160,8 +160,18 @@ 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 (this_cpu_has_cap(ARM64_WORKAROUND_1418040)) { \ + u64 val; \ + val = read_sysreg(cntkctl_el1); \ + val |= ARCH_TIMER_USR_VCT_ACCESS_EN; \ + write_sysreg(val, cntkctl_el1); \ + } \ + 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 +233,17 @@ 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 (this_cpu_has_cap(ARM64_WORKAROUND_1418040)) { \ + u64 val; \ + val = read_sysreg(cntkctl_el1); \ + val &= ~ARCH_TIMER_USR_VCT_ACCESS_EN; \ + write_sysreg(val, cntkctl_el1); \ + } \ + if (IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040)) \ + preempt_enable(); \ }) #ifdef CONFIG_COMPAT_VDSO #define COMPAT_ARCH_DLINFO \