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 1D8DAC4332F for ; Mon, 5 Dec 2022 18:04:21 +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=j7sAoGxHwHIAzoMdozRGAuHYq1ccyLYLWXtmnybqqQA=; b=DLDZZOY8xueEdh 70RQ68ETTUvS2DrZVtJ0qN8vRuKWtzPEt+J6uIZnygaU6xnJSKg/FJ30WqgJRMVno0K69d1YdWLei vT1GJAeKSGvvZrAiPlmgl18wnK8Rg6PB1dTVx0fYw5I+4wfSqFcWLvyYJnSh4Ffw9Z2rzWmENCQAU 6Np/hKhS/T40YLKjJG9Ci19+hf4FQ12PFYvuB2ssl2CLZ5uLL0Gj/US5KnzT4enw/65wcx7SI81yK HpmsAvKF9PCzhxGB1T/b9THHrqYpg8Qdb9r8dEZwr5xsM6KZ8wufR7YWudO0CT1mg3OPVOyhST7Bj FsfzCuPbvePEokP0GvXA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p2FoD-0084I2-5H; Mon, 05 Dec 2022 18:03:17 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p2Fo8-00849I-Qn for linux-arm-kernel@lists.infradead.org; Mon, 05 Dec 2022 18:03:14 +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 4698EB80D99; Mon, 5 Dec 2022 18:03:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01D8AC433C1; Mon, 5 Dec 2022 18:03:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670263390; bh=oW1D+qSKh6SLQ7pQhhk43PMiigdVlm+ZiTRBvQ4dDYo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=oa9rg+2B3WrJnzBEiJRqPSPZUFTSqbbA8QIwdEgW6qHV/0Sg56q0gACZdc4x12pR+ MMGtUK59Uvg3ONQF/zYlBX6oTRI/YYp/ZekJ66kQDwlAm8gqZmoQsqjUp2pnuzQV8q Lac6SRiz923QIjJ4cTSuqNwNtkoOK0fX1B01n7s7p+V0P9UQuO4QD4eAs47Wbt/OAM dGmUz1cWIT4yYhu8bB6l2pDta/lktyUQsHxIGM86sZ305NV5cpYaygcQ+LrvAd6p7F DdcneodiyTb51MPXV2G6/drHuA6OfKZm9zdd2PYOVtc0NCwVItaVOey3itHN5XnnJt S67gpycVA0m0A== 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 1p2Fo3-00Adgw-Jq; Mon, 05 Dec 2022 18:03:07 +0000 Date: Mon, 05 Dec 2022 18:03:07 +0000 Message-ID: <86r0xdlodg.wl-maz@kernel.org> From: Marc Zyngier To: Mark Brown Cc: Catalin Marinas , Will Deacon , Lorenzo Pieralisi , Mark Rutland , Sami Mujawar , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev Subject: Re: [PATCH v2 08/14] arm64/cpufeature: Detect PE support for FEAT_NMI In-Reply-To: <20221112151708.175147-9-broonie@kernel.org> References: <20221112151708.175147-1-broonie@kernel.org> <20221112151708.175147-9-broonie@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/27.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: broonie@kernel.org, catalin.marinas@arm.com, will@kernel.org, lpieralisi@kernel.org, mark.rutland@arm.com, Sami.Mujawar@arm.com, tglx@linutronix.de, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev 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-20221205_100313_185154_6513A7FB X-CRM114-Status: GOOD ( 39.23 ) 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 Sat, 12 Nov 2022 15:17:02 +0000, Mark Brown wrote: > > Use of FEAT_NMI requires that all the PEs in the system and the GIC have NMI > support. This patch implements the PE part of that detection. > > In order to avoid problematic interactions between real and pseudo NMIs > we disable the architected feature if the user has enabled pseudo NMIs > on the command line. If this is done on a system where support for the > architected feature is detected then a warning is printed during boot in > order to help users spot what is likely to be a misconfiguration. > > Signed-off-by: Mark Brown > --- > arch/arm64/include/asm/cpufeature.h | 6 ++++ > arch/arm64/kernel/cpufeature.c | 55 ++++++++++++++++++++++++++++- > arch/arm64/tools/cpucaps | 1 + > 3 files changed, 61 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h > index f73f11b55042..85eeb331a0ef 100644 > --- a/arch/arm64/include/asm/cpufeature.h > +++ b/arch/arm64/include/asm/cpufeature.h > @@ -809,6 +809,12 @@ static __always_inline bool system_uses_irq_prio_masking(void) > cpus_have_const_cap(ARM64_HAS_IRQ_PRIO_MASKING); > } > > +static __always_inline bool system_uses_nmi(void) > +{ > + return IS_ENABLED(CONFIG_ARM64_NMI) && > + cpus_have_const_cap(ARM64_HAS_NMI); > +} > + > static inline bool system_supports_mte(void) > { > return IS_ENABLED(CONFIG_ARM64_MTE) && > diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c > index 6062454a9067..18ab50b76f50 100644 > --- a/arch/arm64/kernel/cpufeature.c > +++ b/arch/arm64/kernel/cpufeature.c > @@ -84,6 +84,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -243,6 +244,7 @@ static const struct arm64_ftr_bits ftr_id_aa64pfr0[] = { > }; > > static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = { > + ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_EL1_NMI_SHIFT, 4, 0), > ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SME), > FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_EL1_SME_SHIFT, 4, 0), > ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_EL1_MPAM_frac_SHIFT, 4, 0), > @@ -2008,9 +2010,11 @@ static void cpu_enable_e0pd(struct arm64_cpu_capabilities const *cap) > } > #endif /* CONFIG_ARM64_E0PD */ > > -#ifdef CONFIG_ARM64_PSEUDO_NMI > +#if IS_ENABLED(CONFIG_ARM64_PSEUDO_NMI) || IS_ENABLED(CONFIG_ARM64_NMI) > static bool enable_pseudo_nmi; > +#endif > > +#ifdef CONFIG_ARM64_PSEUDO_NMI > static int __init early_enable_pseudo_nmi(char *p) > { > return strtobool(p, &enable_pseudo_nmi); > @@ -2024,6 +2028,41 @@ static bool can_use_gic_priorities(const struct arm64_cpu_capabilities *entry, > } > #endif > > +#ifdef CONFIG_ARM64_NMI > +static bool has_nmi(const struct arm64_cpu_capabilities *entry, int scope) > +{ > + if (!has_cpuid_feature(entry, scope)) > + return false; > + > + /* > + * Having both real and pseudo NMIs enabled simultaneously is > + * likely to cause confusion. Since pseudo NMIs must be > + * enabled with an explicit command line option, if the user > + * has set that option on a system with real NMIs for some > + * reason assume they know what they're doing. > + */ > + if (IS_ENABLED(CONFIG_ARM64_PSEUDO_NMI) && enable_pseudo_nmi) { > + pr_info("Pseudo NMI enabled, not using architected NMI\n"); > + return false; > + } > + > + return true; > +} > + > +static void nmi_enable(const struct arm64_cpu_capabilities *__unused) > +{ > + /* > + * Enable use of NMIs controlled by ALLINT, SPINTMASK should > + * be clear by default but make it explicit that we are using > + * this mode. Ensure that ALLINT is clear first in order to > + * avoid leaving things masked. > + */ > + _allint_clear(); > + sysreg_clear_set(sctlr_el1, SCTLR_EL1_SPINTMASK, SCTLR_EL1_NMI); > + isb(); > +} > +#endif > + > #ifdef CONFIG_ARM64_BTI > static void bti_enable(const struct arm64_cpu_capabilities *__unused) > { > @@ -2640,6 +2679,20 @@ static const struct arm64_cpu_capabilities arm64_features[] = { > .matches = has_cpuid_feature, > .cpu_enable = cpu_trap_el0_impdef, > }, > +#ifdef CONFIG_ARM64_NMI > + { > + .desc = "Non-maskable Interrupts", > + .capability = ARM64_HAS_NMI, > + .type = ARM64_CPUCAP_BOOT_CPU_FEATURE, PSEUDO_NMI uses ARM64_CPUCAP_STRICT_BOOT_CPU_FEATURE. What is the rational for using a different policy here? > + .sys_reg = SYS_ID_AA64PFR1_EL1, > + .sign = FTR_UNSIGNED, > + .field_pos = ID_AA64PFR1_EL1_NMI_SHIFT, > + .field_width = 4, > + .min_field_value = ID_AA64PFR1_EL1_NMI_IMP, > + .matches = has_nmi, > + .cpu_enable = nmi_enable, > + }, > +#endif > {}, > }; The whole thing is way too restrictive: KVM definitely needs to know that the feature exists, even if there is no use for it in the host kernel. There is no reason why guests shouldn't be able to use this even if the host doesn't care about it. Which means you need two properties: one that advertises the availability of the feature, and one that makes use of it in the kernel. Thanks, M. -- 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