Re: [PATCH v3 1/2] KVM: arm64: Force HCR_EL2.NV1 to RES0 unconditionally
From: Leonardo Bras
Date: Thu Nov 19 2026 - 07:09:52 EST
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@xxxxxxxxxx>
> Signed-off-by: Colton Lewis <coltonlewis@xxxxxxxxxx>
> ---
> 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@xxxxxxx>
Thanks!
Leo