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 5C6CFC61DF4 for ; Fri, 24 Nov 2023 13:48:49 +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:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zt1Y24OLF0KIgEtOKTzwgHNSoakvccGm9c+4G29PVhY=; b=SJS0zsRGEG+NT4 wHh8RuZ//FK4HXD9k3G0KvqLBgxKC0arb8gw3ccDs/rWo5DxUJ5vm4C8YPM2M38Z0Iivc7DRPTymd QYKk29+YQgsdeLA4AbiwUMkRxtum2EncUdtOjGUtANMD1TaHxUHgsE9K9OCovudq68TKOQY2JOVo+ m7UZc0vJFy18gv4TQU6v3z0OEjW9fMmne/Viok0/ausP5mWj3JDQeXMN8l5QNedSX6U//sfC8mnmJ S3QWVGGudUqUhl+1isnUWjq1ZcKw4ho9zjGYuB+RCrb4Rwitn/IIyZ3Twecrb1ygZR3+nWXS2e4AJ 1aYSjDL3oBW9Fqwad2Aw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r6WXb-007Lp5-1P; Fri, 24 Nov 2023 13:48:19 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r6WXY-007Loj-1K for linux-arm-kernel@lists.infradead.org; Fri, 24 Nov 2023 13:48:17 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 9CBB762251; Fri, 24 Nov 2023 13:48:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D6E3C433C7; Fri, 24 Nov 2023 13:48:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700833695; bh=VOWOZMgL7pRhphmJL9q5UlA45MNXTo4fYc41RO7yZ6Y=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Hy31Ne/mGz/hLqEyf4l9AOb8RkQqRf50XRprOqj1Cwijo4HJKy40fdlun/LCNbiCA zv0mR/3s+RmjZS4EHyCx0GkiI0T9F419iIQHVhB9yNDJlxb7gl6c2Ur2HD0+8c0g15 yoyyVvEavUOh7NN5X5KSLKa7ydi6kp68o4yggULGvFLMFBab0CiJD3qHqhE5esZtF6 nqD8ifS/B+RKKG6onQT/2SqpWsIO9UbP0wrLQx2BGVm+WoS+vE9msAHPAIsm5eRM3w 4RviKbmBVz4VsgHReU83ocMvyBAlq/TXwrNR/KuMPy+ZhIHqXQYwKa8wimqe9NLGkj aE+m2cff62Q6g== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1r6WXV-00G79Z-4F; Fri, 24 Nov 2023 13:48:13 +0000 Date: Fri, 24 Nov 2023 13:48:12 +0000 Message-ID: <86msv3cler.wl-maz@kernel.org> From: Marc Zyngier To: Ard Biesheuvel Cc: Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Will Deacon , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook Subject: Re: [PATCH v5 29/39] arm64: Add helpers to probe local CPU for PAC and BTI support In-Reply-To: References: <20231124101840.944737-41-ardb@google.com> <20231124101840.944737-70-ardb@google.com> <86plzzcooi.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: ardb@kernel.org, ardb@google.com, linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, ryan.roberts@arm.com, anshuman.khandual@arm.com, keescook@chromium.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231124_054816_540241_E90B309B X-CRM114-Status: GOOD ( 34.41 ) 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, 24 Nov 2023 13:08:33 +0000, Ard Biesheuvel wrote: > > On Fri, 24 Nov 2023 at 13:37, Marc Zyngier wrote: > > > > On Fri, 24 Nov 2023 10:19:09 +0000, > > Ard Biesheuvel wrote: > > > > > > From: Ard Biesheuvel > > > > > > Add some helpers that will be used by the early kernel mapping code to > > > check feature support on the local CPU. This permits the early kernel > > > mapping to be created with the right attributes, removing the need for > > > tearing it down and recreating it. > > > > > > Signed-off-by: Ard Biesheuvel > > > --- > > > arch/arm64/include/asm/cpufeature.h | 44 ++++++++++++++++++++ > > > 1 file changed, 44 insertions(+) > > > > > > diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h > > > index 99c01417e544..301d4d2211d5 100644 > > > --- a/arch/arm64/include/asm/cpufeature.h > > > +++ b/arch/arm64/include/asm/cpufeature.h > > > @@ -921,6 +921,50 @@ static inline bool kaslr_disabled_cmdline(void) > > > u32 get_kvm_ipa_limit(void); > > > void dump_cpu_features(void); > > > > > > +static inline bool cpu_has_bti(void) > > > +{ > > > + u64 pfr1; > > > + > > > + if (!IS_ENABLED(CONFIG_ARM64_BTI)) > > > + return false; > > > + > > > + pfr1 = read_cpuid(ID_AA64PFR1_EL1); > > > + pfr1 &= ~id_aa64pfr1_override.mask; > > > + pfr1 |= id_aa64pfr1_override.val; > > > > There is a potential gotcha here. If the override failed because a > > filter rejected it, val will be set to full ones for the size of the > > failed override field, and the corresponding mask will be set to 0 > > (see match_options()). > > > > A safer pattern would be: > > > > pfr1 |= id_aa64pfr1_override.val & id_aa64pfr1_override.mask; > > > > although we currently don't have such a filter for BTI nor PAC, so the > > code is OK for now. > > > > This confuses me. > > What is the point of a value/mask pair if the mask is applied to the > value, and not to the quantity that is being overridden? Surely, not > setting those bits in 'value' to begin with makes the whole mask > redundant, no? > > If the filter is supposed to prevent the override from taking effect, > wouldn't it be better to use 0/0 for the mask/value pair? > > (/me likely misses some context here) 0/0 would be fine for the purpose of not applying the override. However, this hack is used to report the failed override at boot time instead of silently ignoring it (see [1]). Is it crap? Absolutely. But I didn't have a better idea at the time (and still don't). Alternatively, we can drop the reporting and be done with it. M. [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/kernel/cpufeature.c#n923 -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel