]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: arm64: Mark HCR.EL2.{NV*,AT} RES0 when ID_AA64MMFR4_EL1.NV_frac is 0
authorMarc Zyngier <maz@kernel.org>
Thu, 20 Feb 2025 13:48:57 +0000 (13:48 +0000)
committerOliver Upton <oliver.upton@linux.dev>
Mon, 24 Feb 2025 19:06:55 +0000 (11:06 -0800)
Enforce HCR_EL2.{NV*,AT} being RES0 when NV2 is disabled, so that
we can actually rely on these bits never being flipped behind our back.

This of course relies on our earlier ID reg sanitising.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Joey Gouly <joey.gouly@arm.com>
Link: https://lore.kernel.org/r/20250220134907.554085-5-maz@kernel.org
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
arch/arm64/kvm/nested.c

index ed3add7d32f66647783e52fd8d412c0efa423189..9f140560a6f5d8e32f46bad6840169fb6d5efd3a 100644 (file)
@@ -1021,10 +1021,11 @@ int kvm_init_nv_sysregs(struct kvm_vcpu *vcpu)
                res0 |= HCR_FIEN;
        if (!kvm_has_feat(kvm, ID_AA64MMFR2_EL1, FWB, IMP))
                res0 |= HCR_FWB;
-       if (!kvm_has_feat(kvm, ID_AA64MMFR2_EL1, NV, NV2))
-               res0 |= HCR_NV2;
-       if (!kvm_has_feat(kvm, ID_AA64MMFR2_EL1, NV, IMP))
-               res0 |= (HCR_AT | HCR_NV1 | HCR_NV);
+       /* Implementation choice: NV2 is the only supported config */
+       if (!kvm_has_feat(kvm, ID_AA64MMFR4_EL1, NV_frac, NV2_ONLY))
+               res0 |= (HCR_NV2 | HCR_NV | HCR_AT);
+       if (!kvm_has_feat(kvm, ID_AA64MMFR4_EL1, E2H0, NI))
+               res0 |= HCR_NV1;
        if (!(kvm_vcpu_has_feature(kvm, KVM_ARM_VCPU_PTRAUTH_ADDRESS) &&
              kvm_vcpu_has_feature(kvm, KVM_ARM_VCPU_PTRAUTH_GENERIC)))
                res0 |= (HCR_API | HCR_APK);