Skip to content

KVM: arm64: Fix inverted E2H0 check for HCR_EL2.NV1

Colton Lewis kvm kvmarm linux-arm-kernel lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 5 repliesIn review
  2. v12 patches 5 repliesSuperseded

Changes in v2 from the cover letter

- Rename feat_nv2_e2h0_ni() to feat_nv2_nv1_not_res0() to match the condition it checks (Leonardo).
- Drop the guest EL2 MSR/MRS HCR_EL2 check in hello_el2, as RESx read-back from the guest is not architecturally guaranteed to return the effective value and ID_AA64MMFR4_EL1 reads do not necessarily
trap without FEAT_FGT (Marc).
- Link to v1: https://lore.kernel.org/r/[email protected]

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2KVM: arm64: Fix inverted E2H0 check for HCR_EL2.NV1arch/arm64/kvm/config.c+4 -33 replies
2/2KVM: arm64: selftests: Verify HCR_EL2.NV1 is RES0 when E2H0 is NI_NV1tools/testing/selftests/kvm/arm64/hello_el2.c+8 -02 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/2] KVM: arm64: Fix inverted E2H0 check for HCR_EL2.NV1

When commit b2a324ff01fe ("KVM: arm64: Use HCR_EL2 feature map to drive fixed-value bits") migrated HCR_EL2 fixed-bit masking to hcr_feat_map, feat_nv2_e2h0_ni() was written as !kvm_has_feat(kvm, FEAT_E2H0). Because ID_AA64MMFR4_EL1.E2H0 is a signed 4-bit field where IMP is 0, NI is -1, and NI_NV1 is -2, !kvm_has_feat(kvm, FEAT_E2H0) tests E2H0 < 0 and returns true for NI_NV1 (-2), leaving HCR_EL2.NV1 writable instead of RES0 for VHE-only nested guests (and conversely treating HCR_EL2.NV1 as RES0 when E2H0 is IMP).

Patch 1 restores the check to kvm_has_feat(kvm, ID_AA64MMFR4_EL1, E2H0, NI) (E2H0 >= -1) so that HCR_EL2.NV1 is implemented for IMP and NI and forced to RES0 for NI_NV1, and renames the helper from feat_nv2_e2h0_ni() to feat_nv2_nv1_not_res0().
Patch 2 extends the arm64 hello_el2 selftest to verify via KVM_SET_ONE_REG and KVM_GET_ONE_REG that HCR_EL2.E2H remains RES1 and HCR_EL2.NV1 remains RES0 when E2H0 is NI_NV1.

Changes in v2:
- Rename feat_nv2_e2h0_ni() to feat_nv2_nv1_not_res0() to match the condition it checks (Leonardo).
- Drop the guest EL2 MSR/MRS HCR_EL2 check in hello_el2, as RESx read-back from the guest is not architecturally guaranteed to return the effective value and ID_AA64MMFR4_EL1 reads do not necessarily
trap without FEAT_FGT (Marc).
- Link to v1: https://lore.kernel.org/r/[email protected]

Colton Lewis (2):
KVM: arm64: Fix inverted E2H0 check for HCR_EL2.NV1
KVM: arm64: selftests: Verify HCR_EL2.NV1 is RES0 when E2H0 is NI_NV1

 arch/arm64/kvm/config.c                       | 7 ++++---
 tools/testing/selftests/kvm/arm64/hello_el2.c | 8 ++++++++
 2 files changed, 12 insertions(+), 3 deletions(-)

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3

Signature · 1 line
2.56.1.750.gf70dc682cf-goog