All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leonardo Bras <leo.bras@arm.com>
To: Colton Lewis <coltonlewis@google.com>
Cc: Leonardo Bras <leo.bras@arm.com>, Marc Zyngier <maz@kernel.org>,
	Oliver Upton <oupton@kernel.org>, Joey Gouly <joey.gouly@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	Fuad Tabba <fuad.tabba@linux.dev>,
	kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/2] KVM: arm64: Force HCR_EL2.NV1 to RES0 unconditionally
Date: Thu, 19 Nov 2026 12:09:29 +0000	[thread overview]
Message-ID: <av7m-W5ataGJ8dNc@LeoBrasDK> (raw)
In-Reply-To: <20261118203625.743428-2-coltonlewis@google.com>

On Wed, Nov 18, 2026 at 08:36:24PM +0000, Colton Lewis wrote:
> ID_AA64MMFR4_EL1.E2H0 is a signed 4-bit field where:
>   - 0b0000 (IMP, 0): FEAT_E2H0 is implemented.
>   - 0b1111 (NI, -1): FEAT_E2H0 is not implemented, except HCR_EL2.NV1
>     is implemented.
>   - 0b1110 (NI_NV1, -2): Neither HCR_EL2.E2H == 0 nor HCR_EL2.NV1 is
>     implemented, and HCR_EL2.NV1 is RES0.
> 
> When commit b2a324ff01fe ("KVM: arm64: Use HCR_EL2 feature map to drive
> fixed-value bits") converted HCR_EL2 to hcr_feat_map[], feat_nv2_e2h0_ni()
> was written as !kvm_has_feat(kvm, FEAT_E2H0), where FEAT_E2H0 checks
> E2H0 >= IMP (0). This inverted the condition: feat_nv2_e2h0_ni() evaluates
> to true when E2H0 < 0 (including NI_NV1), leaving HCR_EL2.NV1 writable
> instead of RES0 for VHE-only nested guests where KVM advertises
> ID_AA64MMFR4_EL1.E2H0 = NI_NV1.
> 
> In practice, KVM cannot handle HCR_EL2.NV1 being non-RES0 in any
> configuration: limit_nv_id_reg() exposes either VHE-only EL2 with
> ID_AA64MMFR4_EL1.E2H0 = NI_NV1 (and E2H0 is not userspace-writable), or
> FEAT_E2H0 without FEAT_VHE or FEAT_NV. Checking E2H0 in a feature helper
> is therefore unnecessary.
> 
> Drop feat_nv2_e2h0_ni() and mark HCR_EL2_NV1 as an unconditional RES0 bit
> using NEEDS_FEAT_FLAG(HCR_EL2_NV1, FORCE_RESx) in hcr_feat_map[] (shared
> by HCR_EL2 and NVHCR_EL2). Because HCR_EL2_NV1 is not part of the
> architectural HCR_EL2_RES0 mask, check_feat_map() accounts for it as an
> implementation-defined FORCE_RESx bit.
> 
> Fixes: b2a324ff01fe ("KVM: arm64: Use HCR_EL2 feature map to drive fixed-value bits")
> Suggested-by: Marc Zyngier <maz@kernel.org>
> Signed-off-by: Colton Lewis <coltonlewis@google.com>
> ---
>  arch/arm64/kvm/config.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/arch/arm64/kvm/config.c b/arch/arm64/kvm/config.c
> index adaf26ab93b85..2e81f45dc9921 100644
> --- a/arch/arm64/kvm/config.c
> +++ b/arch/arm64/kvm/config.c
> @@ -256,11 +256,6 @@ static bool feat_nv2(struct kvm *kvm)
>  		kvm_has_feat(kvm, ID_AA64MMFR2_EL1, NV, NV2));
>  }
>  
> -static bool feat_nv2_e2h0_ni(struct kvm *kvm)
> -{
> -	return feat_nv2(kvm) && !kvm_has_feat(kvm, FEAT_E2H0);
> -}
> -
>  static bool feat_rasv1p1(struct kvm *kvm)
>  {
>  	return (kvm_has_feat(kvm, ID_AA64PFR0_EL1, RAS, V1P1) ||
> @@ -1034,7 +1029,7 @@ static const struct reg_bits_to_feat_map hcr_feat_map[] = {
>  		   HCR_EL2_NV2		|
>  		   HCR_EL2_NV,
>  		   feat_nv2),
> -	NEEDS_FEAT(HCR_EL2_NV1, feat_nv2_e2h0_ni), /* Missing from JSON */
> +	NEEDS_FEAT_FLAG(HCR_EL2_NV1, FORCE_RESx), /* Missing from JSON, RES0 as an IMPDEF choice */
>  	NEEDS_FEAT(HCR_EL2_API		|
>  		   HCR_EL2_APK,
>  		   feat_pauth),
> -- 
> 2.56.1.750.gf70dc682cf-goog
> 

Right,
KVM nested requires VHE, which uses E2H, which conflicts with NV1.

FWIW:
Reviewed-by: Leonardo Bras <leo.bras@arm.com>

Thanks!
Leo

  reply	other threads:[~2026-11-19 12:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 20:36 [PATCH v3 0/2] KVM: arm64: Force HCR_EL2.NV1 to RES0 unconditionally Colton Lewis
2026-11-18 20:36 ` [PATCH v3 1/2] " Colton Lewis
2026-11-19 12:09   ` Leonardo Bras [this message]
2026-11-18 20:36 ` [PATCH v3 2/2] KVM: arm64: selftests: Verify HCR_EL2.NV1 is RES0 when E2H0 is NI_NV1 Colton Lewis
2026-11-19 12:43   ` Leonardo Bras
2026-11-19 12:43 ` [PATCH v3 0/2] KVM: arm64: Force HCR_EL2.NV1 to RES0 unconditionally Marc Zyngier

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=av7m-W5ataGJ8dNc@LeoBrasDK \
    --to=leo.bras@arm.com \
    --cc=coltonlewis@google.com \
    --cc=fuad.tabba@linux.dev \
    --cc=joey.gouly@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=suzuki.poulose@arm.com \
    --cc=yuzenghui@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.