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 9863EE784AF for ; Mon, 2 Oct 2023 10:26:05 +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=Issi6P34ciI1mTY6NfEdx31AeFAUSBhm7J321ILGj80=; b=VUC10SimoOao1B YydPe7j5aZUA6jRatbTwbXqvlKVlLC7ll5B2IYJr04zbREcI6Qm6Y1I66h5FgoLtdKHi1I5L+dCIn zUf092exgO2/irn3d61UtMKGaFSEwUCGtYajfO9faNs90hNQryIxn3aBmGBHGWRV3Z/IbbdEgnciU Evx7LC64ndLEPanbDgUQbGEc4hYfZxAb/S9hiN4Wmn73wWmm/j74rR26PPFK1AVSRIBH86TM59HSz zxOiAShn5u+yjuZ1cpaTdVlcyspqDf3LDmelk4j1pPgjdYVqzU81Yp+Fift6RmZhA6GRoZX6yoV2R M+Vug4w95J4+Q8ns45WQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qnG7J-00CLqa-2m; Mon, 02 Oct 2023 10:25:33 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qnG7G-00CLnW-20 for linux-arm-kernel@lists.infradead.org; Mon, 02 Oct 2023 10:25:32 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 35E4DC15; Mon, 2 Oct 2023 03:26:05 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.93.182]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 390763F762; Mon, 2 Oct 2023 03:25:24 -0700 (PDT) Date: Mon, 2 Oct 2023 11:25:18 +0100 From: Mark Rutland To: Suzuki K Poulose Cc: linux-arm-kernel@lists.infradead.org, ardb@kernel.org, bertrand.marquis@arm.com, boris.ostrovsky@oracle.com, broonie@kernel.org, catalin.marinas@arm.com, daniel.lezcano@linaro.org, james.morse@arm.com, jgross@suse.com, maz@kernel.org, oliver.upton@linux.dev, pcc@google.com, sstabellini@kernel.org, tglx@linutronix.de, vladimir.murzin@arm.com, will@kernel.org Subject: Re: [PATCH 05/37] arm64: Add cpus_have_final_boot_cap() Message-ID: References: <20230919092850.1940729-1-mark.rutland@arm.com> <20230919092850.1940729-6-mark.rutland@arm.com> <55c9f428-b715-a2ae-5b89-d125a0104ea3@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231002_032530_776013_EE340183 X-CRM114-Status: GOOD ( 44.16 ) 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, Sep 22, 2023 at 11:26:21AM +0100, Suzuki K Poulose wrote: > On 21/09/2023 17:36, Mark Rutland wrote: > > On Thu, Sep 21, 2023 at 10:13:31AM +0100, Suzuki K Poulose wrote: > > > Hi Mark > > > > > > On 19/09/2023 10:28, Mark Rutland wrote: > > > > The cpus_have_final_boot_cap() function can be used to test a cpucap > > > > > > nit: cpus_have_final_cap() > > > > Thanks; fixed now. > > > > > > while also verifying that we do not consume the cpucap until system > > > > capabilities have been finalized. It would be helpful if we could do > > > > likewise for boot cpucaps. > > > > > > > > This patch adds a new cpus_have_final_boot_cap() helper which can be > > > > used to test a cpucap while also verifying that boot capabilities have > > > > been finalized. Users will be added in subsequent patches. > > > > > > > > Signed-off-by: Mark Rutland > > > > Cc: Catalin Marinas > > > > Cc: Mark Brown > > > > Cc: Suzuki K Poulose > > > > Cc: Will Deacon > > > > --- > > > > arch/arm64/include/asm/cpufeature.h | 27 +++++++++++++++++++++++++-- > > > > 1 file changed, 25 insertions(+), 2 deletions(-) > > > > > > > > diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h > > > > index 7d5317bc2429f..e832b86c6b57f 100644 > > > > --- a/arch/arm64/include/asm/cpufeature.h > > > > +++ b/arch/arm64/include/asm/cpufeature.h > > > > @@ -438,6 +438,11 @@ unsigned long cpu_get_elf_hwcap2(void); > > > > #define cpu_set_named_feature(name) cpu_set_feature(cpu_feature(name)) > > > > #define cpu_have_named_feature(name) cpu_have_feature(cpu_feature(name)) > > > > +static __always_inline bool boot_capabilities_finalized(void) > > > > +{ > > > > + return alternative_has_cap_likely(ARM64_ALWAYS_BOOT); > > > > +} > > > > + > > > > static __always_inline bool system_capabilities_finalized(void) > > > > { > > > > return alternative_has_cap_likely(ARM64_ALWAYS_SYSTEM); > > > > @@ -473,8 +478,26 @@ static __always_inline bool __cpus_have_const_cap(int num) > > > > /* > > > > * Test for a capability without a runtime check. > > > > * > > > > - * Before capabilities are finalized, this will BUG(). > > > > - * After capabilities are finalized, this is patched to avoid a runtime check. > > > > + * Before boot capabilities are finalized, this will BUG(). > > > > + * After boot capabilities are finalized, this is patched to avoid a runtime > > > > + * check. > > > > + * > > > > + * @num must be a compile-time constant. > > > > + */ > > > > +static __always_inline bool cpus_have_final_boot_cap(int num) > > > > +{ > > > > + if (boot_capabilities_finalized()) > > > > > > Does this need to make sure the cap is really a "BOOT" cap ? It is a bit of > > > an overkill, but prevents users from incorrectly assuming the cap is > > > finalised ? > > > > Do you have an idea in mind for how to do that? > > > > I had also wanted that, but we don't have the information available when > > compiling the callsites today since that's determined by the > > arm64_cpu_capabilities::type flags. > > > > We could us an alternative callback for boot_capabilities_finalized() that > > goes and checks the arm64_cpu_capabilities::type flags, but that doesn't seem > > very nice. > > > Thats what I had initially in mind, and is why I called it an > overkill. > > But may be another option is to have a different alternative construct > for all capabilities, which defaults to BUG() and then patched to > "false" or "true" based on the real status ? This may be more > complicated. I think that's possible with something like the ARM64_CB_BIT bit to say "this alternative is applied when this cap is finalized", and either a bitmap of finalized alternatives, or another walk over the arm64_cpu_capabilities when applying alternatives. I'll have a look and see how painful that is. > > Otherwise, given this only has a few users, I could have those directly use: > > > > BUG_ON(!boot_capabilities_finalized()); > > > > ... and remove cpus_have_final_boot_cap() for now? > > I don't think that is necessary. We could keep your patch > as is, if we can't verify the boot capability easily. Thanks! Mark. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel