Re: [PATCH v2 2/2] KVM: arm64: selftests: Verify HCR_EL2.NV1 is RES0 when E2H0 is NI_NV1

From: Oliver Upton

Date: Tue Nov 17 2026 - 17:50:05 EST


On Tue, Nov 17, 2026 at 08:45:35PM +0000, Colton Lewis wrote:
> In a VHE-only EL2 guest (KVM_ARM_VCPU_HAS_EL2 without
> KVM_ARM_VCPU_HAS_EL2_E2H0), KVM advertises ID_AA64MMFR4_EL1.E2H0 as
> NI_NV1, making HCR_EL2.E2H RES1 and HCR_EL2.NV1 RES0.
>
> Extend hello_el2 to attempt clearing HCR_EL2.E2H and setting HCR_EL2.NV1
> from userspace via KVM_SET_ONE_REG, verifying that HCR_EL2.E2H remains
> RES1 and HCR_EL2.NV1 is masked to RES0.
>
> Signed-off-by: Colton Lewis <coltonlewis@xxxxxxxxxx>
> ---
> tools/testing/selftests/kvm/arm64/hello_el2.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/tools/testing/selftests/kvm/arm64/hello_el2.c b/tools/testing/selftests/kvm/arm64/hello_el2.c
> index bbe6862c6ab16..5910497f8fbe4 100644
> --- a/tools/testing/selftests/kvm/arm64/hello_el2.c
> +++ b/tools/testing/selftests/kvm/arm64/hello_el2.c
> @@ -45,6 +45,7 @@ int main(void)
> struct kvm_vcpu *vcpu;
> struct kvm_vm *vm;
> struct ucall uc;
> + u64 hcr;
>
> TEST_REQUIRE(kvm_check_cap(KVM_CAP_ARM_EL2));
>
> @@ -66,6 +67,13 @@ int main(void)
> TEST_FAIL("Unhandled ucall: %ld\n", uc.cmd);
> }
>
> + hcr = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_HCR_EL2));
> + vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(SYS_HCR_EL2),
> + (hcr & ~HCR_EL2_E2H) | HCR_EL2_NV1);
> + hcr = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_HCR_EL2));
> + TEST_ASSERT(hcr & HCR_EL2_E2H, "HCR_EL2.E2H should be RES1");
> + TEST_ASSERT(!(hcr & HCR_EL2_NV1), "HCR_EL2.NV1 should be RES0");
> +

Again, comment would be helpful for why this is done from userspace,
i.e. the RESx as seen from the guest POV is stateful but the value is
ignored.

Thanks,
Oliver