linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Yicong Yang <yangyicong@huawei.com>
Cc: <catalin.marinas@arm.com>, <will@kernel.org>,
	<oliver.upton@linux.dev>, <linux-arm-kernel@lists.infradead.org>,
	<kvmarm@lists.linux.dev>, <joey.gouly@arm.com>,
	<suzuki.poulose@arm.com>, <shameerali.kolothum.thodi@huawei.com>,
	<jonathan.cameron@huawei.com>, <prime.zeng@hisilicon.com>,
	<xuwei5@huawei.com>, <yangyicong@hisilicon.com>,
	<linuxarm@huawei.com>
Subject: Re: [PATCH 2/3] arm64/cpufeature: Add cpucap for HCR_EL2.E2H RES1 (!FEAT_E2H0)
Date: Sat, 29 Mar 2025 08:12:38 +0000	[thread overview]
Message-ID: <87semwz24p.wl-maz@kernel.org> (raw)
In-Reply-To: <20250329034409.21354-3-yangyicong@huawei.com>

On Sat, 29 Mar 2025 03:44:08 +0000,
Yicong Yang <yangyicong@huawei.com> wrote:
> 
> From: Yicong Yang <yangyicong@hisilicon.com>
> 
> Arm introduced a "new" feature FEAT_E2H0 indicates that HCR_EL2.E2H can
> be programmed to the value 0 for legacy hardwares supported VHE. The
> feature is indicated by ID_AA64MMFR4_EL1.E2H0 == 0. It is needed to
> detect this feature for KVM mode initialization. Instead of bothering
> the existed hardwares, introduce a new cpucap HAS_E2H_RES1 to indicate
> FEAT_E2H0 is not supported. Make this a ARM64_CPUCAP_SYSTEM_FEATURE
> just like VHE.
> 
> Introduce cpu_has_e2h_res1() for checking the feature's support
> which can be used in the early boot stage where CPU capabilities
> are not initialized.
> 
> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
> ---
>  arch/arm64/include/asm/cpufeature.h | 23 +++++++++++++++++++++++
>  arch/arm64/kernel/cpufeature.c      | 12 ++++++++++++
>  arch/arm64/tools/cpucaps            |  1 +
>  3 files changed, 36 insertions(+)
> 
> diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h
> index c4326f1cb917..b35d393da28d 100644
> --- a/arch/arm64/include/asm/cpufeature.h
> +++ b/arch/arm64/include/asm/cpufeature.h
> @@ -889,6 +889,29 @@ static inline bool cpu_has_hw_af(void)
>  						ID_AA64MMFR1_EL1_HAFDBS_SHIFT);
>  }
>  
> +/*
> + * Check whether FEAT_E2H0 is not supported, in which case HCR_EL2.E2H
> + * is implemented as RES1.
> + */
> +static __always_inline bool cpu_has_e2h_res1(void)
> +{
> +	u64 mmfr4;
> +	u32 val;
> +
> +	/*
> +	 * It's also used for checking the kvm mode cfg in early_param()
> +	 * where boot capabilities is not initialized. In such case read
> +	 * mmfr4 directly. This works same after boot stage since
> +	 * ARM64_HAS_E2H_RES1 is a system feature, the cached sanitised
> +	 * value keeps same with every single CPU.
> +	 */
> +	mmfr4 = read_sysreg_s(SYS_ID_AA64MMFR4_EL1);

This will result in traps to EL2 with nested. Are you expecting this
to be used on any form of hot paths?

> +	val = cpuid_feature_extract_signed_field(mmfr4,
> +						 ID_AA64MMFR4_EL1_E2H0_SHIFT);
> +
> +	return val != ID_AA64MMFR4_EL1_E2H0_IMP;

This is going to break badly on Apple HW, which predate the
"!FEAT_E2H0" relaxation and yet have HCR_EL2.E2H RAO/WI and
ID_AA64MMFR4_EL1.E2H0==0.

The curent code was carefully designed to *avoid* doing this, because
the kernel doesn't really need to know anything about FEAT_E2H0 apart
from the very early boot.

What do we gain with this?

	M.

-- 
Jazz isn't dead. It just smells funny.


  reply	other threads:[~2025-03-29  8:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-29  3:44 [PATCH 0/3] Two minor fixups around FEAT_E2H0 Yicong Yang
2025-03-29  3:44 ` [PATCH 1/3] arm64/cpufeature: Add missing id_aa64mmfr4 feature reg update Yicong Yang
2025-03-29  3:44 ` [PATCH 2/3] arm64/cpufeature: Add cpucap for HCR_EL2.E2H RES1 (!FEAT_E2H0) Yicong Yang
2025-03-29  8:12   ` Marc Zyngier [this message]
2025-03-29  8:41     ` Yicong Yang
2025-03-29 10:41       ` Marc Zyngier
2025-03-31  8:00         ` Yicong Yang
2025-03-29  3:44 ` [PATCH 3/3] KVM: arm64: Fix boot warning with kvm-arm.mode=nvhe on !FEAT_E2H0 platforms Yicong Yang
2025-04-29 20:27 ` [PATCH 0/3] Two minor fixups around FEAT_E2H0 Will Deacon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87semwz24p.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=joey.gouly@arm.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linuxarm@huawei.com \
    --cc=oliver.upton@linux.dev \
    --cc=prime.zeng@hisilicon.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    --cc=xuwei5@huawei.com \
    --cc=yangyicong@hisilicon.com \
    --cc=yangyicong@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).