From mboxrd@z Thu Jan 1 00:00:00 1970 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 B90C1C433F5 for ; Fri, 17 Dec 2021 18:52:22 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bOPC9EPBoy42D3QizrtjEXXcY4EtbExQdCGFxejLWp8=; b=Rs4hF6iM8XiimD 0kf/6XKsEDIu4eGiko1lt8vjMwENxYaK4bPFtqjtpkSl77z+VhcwYX+11O++OxYBUlI6s1RfkhqRX 7UO4Xr6ZsSYGgWXAdOF5FoOq3qiUH42M81R1IBSzUbXkdOdnR8miGzdtsM82+wigrwqhFF4EPISBN kAqdyoZbpnULMKaUsf9QL+fD5unG7UfMkCgXX9EIR/gi1NRovZePy8fXvlXcE5NawnlDkjEzpxxRv cu6b69xIUuGOD/yZvn3wch9TTHo0aKjAsOUiZV4ez/T28y5Dz5yvyA5QqXSAghFA4KnD9iBFdq2Ay yBrPWCMxTMIHMlZV2GKA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1myIJd-00C0Ai-PI; Fri, 17 Dec 2021 18:50:50 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1myI8I-00Bug0-5G for linux-arm-kernel@lists.infradead.org; Fri, 17 Dec 2021 18:39:08 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0DB9AB8299B; Fri, 17 Dec 2021 18:39:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0FEAC36AE1; Fri, 17 Dec 2021 18:39:00 +0000 (UTC) Date: Fri, 17 Dec 2021 18:38:57 +0000 From: Catalin Marinas To: D Scott Phillips Cc: linux-arm-kernel@lists.infradead.org, Marc Zyngier , Will Deacon , Darren Hart , patches@amperecomputing.com Subject: Re: [PATCH v2] arm64: errata: Fix exec handling in erratum 1418040 workaround Message-ID: References: <20211216191618.972956-1-scott@os.amperecomputing.com> <86r1abtc86.fsf@scott-ph-mail.amperecomputing.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <86r1abtc86.fsf@scott-ph-mail.amperecomputing.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211217_103906_436413_33AFEB61 X-CRM114-Status: GOOD ( 22.04 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Dec 17, 2021 at 08:42:01AM -0800, D Scott Phillips wrote: > Catalin Marinas writes: > > On Thu, Dec 16, 2021 at 11:16:18AM -0800, D Scott Phillips wrote: > >> 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(); \ > >> + } \ > > > > I don't particularly like adding more to these macros. There's > > arch_setup_new_exec() that gets called after SET_PERSONALITY, so you can > > check whether the task is compat or not. > > If the task is preemptible between the update to TIF_32BIT and the > update to cntkctl then a window exists where preemption will confuse the > workaround logic we have in switch_to, causing the desync between compat > state and counter access trapping to propagate into other tasks. > > Agreed that this change gunks up a previously simple macro though. Maybe > we could have SET_PERSONALITY only set a flag in arch_elf_state and > arch_setup_new_exec() take over setting TIF_32BIT? Or move > set_personality's implementation to a helper? Or something else? Is reading ckntkctl_el1 as expensive as the write? If not we could change the __switch_to() logic to simply check that the bit is set or cleared depending on is_compat_thread() and skip the comparison with the previous task. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel