Skip to content

RFC arm/kvm: select an nVHE-only EL2 with SYSREG_ID_AA64MMFR1_EL1_VH

Haseeb Ashraf kvm qemu-arm qemu-devel 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 RFC Latest3 patches 0 repliesNew

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3target/arm/kvm: Add kvm_arm_el2_e2h0_supported()target/arm/kvm-stub.c target/arm/kvm.c target/arm/kvm_arm.h+23 -00 replies
2/3target/arm/kvm: Let SYSREG_ID_AA64MMFR1_EL1_VH select an nVHE EL2docs/system/arm/cpu-features.rst target/arm/cpu-idregs.h target/arm/cpu64.c +1 more+114 -140 replies
3/3tests/functional: Add a KVM selftest for an nVHE-only EL2tests/functional/aarch64/test_kvm.py+20 -20 replies

Reviews trailers per patch

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

Read the v2 thread

Cover letter [RFC PATCH v2 0/3] arm/kvm: select an nVHE-only EL2 with SYSREG_ID_AA64MMFR1_EL1_VH

From: Haseeb Ashraf <[email protected]>

Hi,

KVM presents a VHE-only EL2 (HCR_EL2.E2H RES1) to a nested guest unless KVM_ARM_VCPU_HAS_EL2_E2H0 is requested at vCPU initialization. Guest hypervisors which only support nVHE, such as Xen, cannot run in that mode. This series lets the user select an nVHE-only EL2 with:

  -M virt,virtualization=on -accel kvm \
      -cpu host,SYSREG_ID_AA64MMFR1_EL1_VH=0

Following Marc's feedback on v1, this is built on Eric Auger's SYSREG_<REG>_<FIELD> framework instead of a new machine or CPU property. It is an RFC because that framework is not merged yet.

Dependencies
------------

The series applies on top of the remaining patches of Eric's v11 [1], which are on his arm-cpu-model-v11-rc branch [2], rebased on current master. On current master those patches need two mechanical build
fixes: object_property_add() now takes &uint64_type_info, and kvm_feature_idx_to_idregs_idx() must sit after kvm_arm_sve_get_vls() instead of inside it. The fixes belong to Eric's series and are not part of these three patches.

Questions
---------

- KVM does not let userspace write ID_AA64MMFR1_EL1.VH, so the generic "writable fields only" rule would not create the property. Patch 2 treats VH as selected through a vCPU init feature and exposes it as an exception. Is that acceptable, or would you prefer a generic representation of such fields in the framework?
- Only VH is updated in QEMU's copy of the ID registers. Other fields which KVM derives from E2H0, for example ID_AA64MMFR4_EL1, are not refreshed. Is that acceptable, or should QEMU re-read the ID registers after vCPU initialization?

Scope
-----

TCG and HVF are unchanged by design. The property is available for the host (and max) CPU model with KVM, when the host kernel advertises KVM_CAP_ARM_EL2_E2H0. Xen and QNX already boot with TCG, where HCR_EL2.E2H is under the control of the guest.

Changes since v1 [3]:

- Removed the dedicated virt machine and ARM CPU "vhe" properties.
- Switched to Eric's SYSREG ID-register framework and use SYSREG_ID_AA64MMFR1_EL1_VH to select an nVHE-only EL2.
- Exposed the property only when KVM advertises

    KVM_CAP_ARM_EL2_E2H0.

- Derived KVM_ARM_VCPU_HAS_EL2_E2H0 from VH and rejected VH=0 when virtualization is disabled.
- Added documentation and a KVM functional selftest which verifies that the guest hypervisor initializes in nVHE mode.

Testing
-------

Validation was performed on an AmpereOne A192-32X (Ampere-1a) running host kernel 6.18.29+3-arm64:

- TCG-only, KVM-only and aarch64-linux-user builds succeeded.
- TCG rejects SYSREG_ID_AA64MMFR1_EL1_VH because the property does not exist for that accelerator.
- The existing AArch64 KVM nVHE and VHE selftests pass under TCG.
- The arm-cpu-features qtest passes.
- Linux 6.12.67 initialized KVM in nVHE mode with VH=0 and in VHE mode with VH=1; both boots reached login.
- QNX Hypervisor 8.0.5 reached login with both values and reported the corresponding ID register state.
- Xen dom0 reached login with VH=0. With VH=1, Xen did not boot.
- The complete AArch64 KVM functional suite passed, including the new nVHE-only selftest.

Not tested: live migration, and hosts other than AmpereOne.

[1] https://patchew.org/QEMU/[email protected]/
[2] https://github.com/eauger/qemu/commits/arm-cpu-model-v11-rc
[3] https://patchew.org/QEMU/[email protected]/

Thanks,
Haseeb

Haseeb Ashraf (3):
target/arm/kvm: Add kvm_arm_el2_e2h0_supported() target/arm/kvm: Let SYSREG_ID_AA64MMFR1_EL1_VH select an nVHE EL2 tests/functional: Add a KVM selftest for an nVHE-only EL2

 docs/system/arm/cpu-features.rst     | 22 ++++++++++++
 target/arm/cpu-idregs.h              | 31 +++++++++++++++++
 target/arm/cpu64.c                   | 51 ++++++++++++++++++++++------
 target/arm/kvm-stub.c                |  5 +++
 target/arm/kvm.c                     | 29 ++++++++++++++--
 target/arm/kvm_arm.h                 | 13 +++++++
 tests/functional/aarch64/test_kvm.py | 22 ++++++++++--
 7 files changed, 157 insertions(+), 16 deletions(-)