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

Haseeb Ashraf posted 3 patches 1 day, 19 hours ago
Failed in applying to current master (apply log)
docs/system/arm/cpu-features.rst     | 22 ++++++++++
target/arm/arm-qmp-cmds.c            | 38 +++++++++++++++++
target/arm/cpu-idregs.h              | 31 ++++++++++++++
target/arm/cpu64.c                   | 51 +++++++++++++++++-----
target/arm/kvm-stub.c                | 10 +++++
target/arm/kvm.c                     | 63 ++++++++++++++++++++++++++--
target/arm/kvm_arm.h                 | 21 ++++++++++
tests/functional/aarch64/test_kvm.py | 22 +++++++++-
8 files changed, 242 insertions(+), 16 deletions(-)
[RFC PATCH v3 0/3] arm/kvm: select an nVHE-only EL2 with SYSREG_ID_AA64MMFR1_EL1_VH
Posted by Haseeb Ashraf 1 day, 19 hours ago
From: Haseeb Ashraf <haseeb.ashraf@siemens.com>

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. This RFC
lets an nVHE-only guest hypervisor request that mode through:

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

The series builds on Eric Auger's remaining v11 SYSREG framework. It is
based on the rebased prerequisite commit corresponding to Eric's
arm-cpu-model-v11-rc tip e32893ddcbe643d47919f55ae33ff71be2609a77.
This dependency is intentional: a version which works without that
framework would have to introduce a separate machine or CPU property,
which was the approach rejected by Marc in v1.

References:

  - Eric's v11 series:
    https://patchew.org/QEMU/20261030131406.461599-1-eric.auger@redhat.com/
  - Eric's v11-rc branch:
    https://github.com/eauger/qemu/commits/arm-cpu-model-v11-rc
  - My v1:
    https://patchew.org/QEMU/20261121095636.289814-1-haseebashraf091@gmail.com/

Changes since v2:

  - Apply init-driven SYSREG properties before creating the scratch
    vCPU, so full CPU-model expansion reflects the requested init mode.
  - Refresh ID_AA64MMFR1_EL1 and ID_AA64MMFR4_EL1 from KVM after vCPU
    initialization, keeping QEMU's cached model and QMP expansion in
    sync with the guest-visible registers.

Eric correctly pointed out that KVM already updates the guest-visible
derived ID registers. The v2 gap was limited to QEMU's cache/model
expansion view; v3 fixes that without changing the guest-visible
behavior.  With VH=0, query-cpu-model-expansion now reports
ID_AA64MMFR4_EL1.NV_frac=0; with VH=1 it reports 1.

For the init-driven property question, this series keeps VH as an
explicit exception because KVM_CAP_ARM_EL2_E2H0 currently exposes no
writable-ID-register equivalent.  A generic framework table can be
considered if more such fields arise; there is no need to add a broader
abstraction for this single case.

This RFC therefore also asks maintainers to confirm that using a
SYSREG_<REG>_<FIELD> property for a value selected at vCPU init is an
acceptable extension of Eric's framework. If that model is not
accepted, this nVHE functionality should wait for the framework
direction to settle. The standalone-property implementation from v1 is
available as a fallback for the implementation discussion, but I would
prefer not to make that upstream direction the default again.

TCG and HVF are unchanged by design.

Testing on an AmpereOne A192-32X with host kernel 6.18.29-arm64:

  - TCG-only and KVM-only builds succeeded.
  - TCG rejects SYSREG_ID_AA64MMFR1_EL1_VH.
  - arm-cpu-features passed.
  - All three AArch64 KVM functional selftests passed.
  - QMP full expansion reports the KVM-derived MMFR4 state for both
    VH=0 and VH=1.
  - Linux 6.12.67 initialized KVM in nVHE mode with VH=0 and VHE mode
    with VH=1; QNX Hypervisor 8.0.5 reached login with both values.
  - Xen dom0 reached login with VH=0 and did not boot with VH=1.

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/arm-qmp-cmds.c            | 38 +++++++++++++++++
 target/arm/cpu-idregs.h              | 31 ++++++++++++++
 target/arm/cpu64.c                   | 51 +++++++++++++++++-----
 target/arm/kvm-stub.c                | 10 +++++
 target/arm/kvm.c                     | 63 ++++++++++++++++++++++++++--
 target/arm/kvm_arm.h                 | 21 ++++++++++
 tests/functional/aarch64/test_kvm.py | 22 +++++++++-
 8 files changed, 242 insertions(+), 16 deletions(-)
-- 
2.34.1
Re: [RFC PATCH v3 0/3] arm/kvm: select an nVHE-only EL2 with SYSREG_ID_AA64MMFR1_EL1_VH
Posted by Khushit Shah 1 day, 19 hours ago

> On 26 Nov 2026, at 10:57 AM, Haseeb Ashraf <haseebashraf091@gmail.com> wrote:
> 
> !-------------------------------------------------------------------|
>  CAUTION: External Email
> 
> |-------------------------------------------------------------------!
> 
> From: Haseeb Ashraf <haseeb.ashraf@siemens.com>
> 
> 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. This RFC
> lets an nVHE-only guest hypervisor request that mode through:
> 
>  -M virt,virtualization=on -accel kvm \
>      -cpu host,SYSREG_ID_AA64MMFR1_EL1_VH=0
> 
> The series builds on Eric Auger's remaining v11 SYSREG framework. It is
> based on the rebased prerequisite commit corresponding to Eric's
> arm-cpu-model-v11-rc tip e32893ddcbe643d47919f55ae33ff71be2609a77.
> This dependency is intentional: a version which works without that
> framework would have to introduce a separate machine or CPU property,
> which was the approach rejected by Marc in v1.
> 
> References:
> 
>  - Eric's v11 series:
>    https://urldefense.proofpoint.com/v2/url?u=https-3A__patchew.org_QEMU_20261030131406.461599-2D1-2Deric.auger-40redhat.com_&d=DwIDAg&c=s883GpUCOChKOHiocYtGcg&r=PGWMyignA0NiDmTlyP7vOTHozBws_VN86yrVmSMkBp0&m=x45rO9ktlL_N_DqruwZCqdxIKJMqZVba_77ghKIlKoGk02-X8HO-rG_CnCF5WE52&s=5PdtSrSqg2BFk_IuGIK9Crkvyj98oCgRTmTB9Qpw5Bo&e= 
>  - Eric's v11-rc branch:
>    https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_eauger_qemu_commits_arm-2Dcpu-2Dmodel-2Dv11-2Drc&d=DwIDAg&c=s883GpUCOChKOHiocYtGcg&r=PGWMyignA0NiDmTlyP7vOTHozBws_VN86yrVmSMkBp0&m=x45rO9ktlL_N_DqruwZCqdxIKJMqZVba_77ghKIlKoGk02-X8HO-rG_CnCF5WE52&s=xs9AECI1g2J6lF0ajI3MWrseWIxJik2nbNg61Sser4I&e= 
>  - My v1:
>    https://urldefense.proofpoint.com/v2/url?u=https-3A__patchew.org_QEMU_20261121095636.289814-2D1-2Dhaseebashraf091-40gmail.com_&d=DwIDAg&c=s883GpUCOChKOHiocYtGcg&r=PGWMyignA0NiDmTlyP7vOTHozBws_VN86yrVmSMkBp0&m=x45rO9ktlL_N_DqruwZCqdxIKJMqZVba_77ghKIlKoGk02-X8HO-rG_CnCF5WE52&s=cxnvVEn7tWyGO1QnnlIwe3YKIqfxSwt6Ies6eCTJEzM&e= 
> 
> Changes since v2:
> 
>  - Apply init-driven SYSREG properties before creating the scratch
>    vCPU, so full CPU-model expansion reflects the requested init mode.
>  - Refresh ID_AA64MMFR1_EL1 and ID_AA64MMFR4_EL1 from KVM after vCPU
>    initialization, keeping QEMU's cached model and QMP expansion in
>    sync with the guest-visible registers.
> 
> Eric correctly pointed out that KVM already updates the guest-visible
> derived ID registers. The v2 gap was limited to QEMU's cache/model
> expansion view; v3 fixes that without changing the guest-visible
> behavior.  With VH=0, query-cpu-model-expansion now reports
> ID_AA64MMFR4_EL1.NV_frac=0; with VH=1 it reports 1.
> 
> For the init-driven property question, this series keeps VH as an
> explicit exception because KVM_CAP_ARM_EL2_E2H0 currently exposes no
> writable-ID-register equivalent.  A generic framework table can be
> considered if more such fields arise; there is no need to add a broader
> abstraction for this single case.
There are many such fields like PAuth (APA, GPA, …) and SVE. They are not
part of the SYSREG_ framework as there already exists boolean properties
for them.
(Another way to do this is having -cpu …,vhe=on/off property)

> 
> This RFC therefore also asks maintainers to confirm that using a
> SYSREG_<REG>_<FIELD> property for a value selected at vCPU init is an
> acceptable extension of Eric's framework. If that model is not
> accepted, this nVHE functionality should wait for the framework
> direction to settle. The standalone-property implementation from v1 is
> available as a fallback for the implementation discussion, but I would
> prefer not to make that upstream direction the default again.
> 
> TCG and HVF are unchanged by design.
> 
> Testing on an AmpereOne A192-32X with host kernel 6.18.29-arm64:
> 
>  - TCG-only and KVM-only builds succeeded.
>  - TCG rejects SYSREG_ID_AA64MMFR1_EL1_VH.
>  - arm-cpu-features passed.
>  - All three AArch64 KVM functional selftests passed.
>  - QMP full expansion reports the KVM-derived MMFR4 state for both
>    VH=0 and VH=1.
>  - Linux 6.12.67 initialized KVM in nVHE mode with VH=0 and VHE mode
>    with VH=1; QNX Hypervisor 8.0.5 reached login with both values.
>  - Xen dom0 reached login with VH=0 and did not boot with VH=1.
> 
> 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/arm-qmp-cmds.c            | 38 +++++++++++++++++
> target/arm/cpu-idregs.h              | 31 ++++++++++++++
> target/arm/cpu64.c                   | 51 +++++++++++++++++-----
> target/arm/kvm-stub.c                | 10 +++++
> target/arm/kvm.c                     | 63 ++++++++++++++++++++++++++--
> target/arm/kvm_arm.h                 | 21 ++++++++++
> tests/functional/aarch64/test_kvm.py | 22 +++++++++-
> 8 files changed, 242 insertions(+), 16 deletions(-)
> -- 
> 2.34.1
> 

Re: [RFC PATCH v3 0/3] arm/kvm: select an nVHE-only EL2 with SYSREG_ID_AA64MMFR1_EL1_VH
Posted by Haseeb Ashraf 1 day, 18 hours ago
Hi Khushit,

On 26/11/26 11:38, Khushit Shah wrote:

> There are many such fields like PAuth (APA, GPA, …) and SVE. They are
> not part of the SYSREG_ framework as there already exists boolean
> properties for them.
> (Another way to do this is having -cpu …,vhe=on/off property)

The v1 series was closer to what you are suggesting: it added a
standalone `vhe=on/off` property and used it to select the
requested KVM vCPU initialization mode.

Could you please also review the v1 implementation?

https://lore.kernel.org/qemu-devel/20261121095636.289814-1-haseebashraf091@gmail.com/

I changed direction for v2 following Marc's feedback against adding a
separate property.

Thanks,
Haseeb

Re: [RFC PATCH v3 0/3] arm/kvm: select an nVHE-only EL2 with SYSREG_ID_AA64MMFR1_EL1_VH
Posted by Eric Auger 1 day, 8 hours ago
Hi Haseeb, Khushit,

On 11/26/26 7:20 AM, Haseeb Ashraf wrote:
> Hi Khushit,
> 
> On 26/11/26 11:38, Khushit Shah wrote:
> 
>> There are many such fields like PAuth (APA, GPA, …) and SVE. They are
>> not part of the SYSREG_ framework as there already exists boolean
>> properties for them.
>> (Another way to do this is having -cpu …,vhe=on/off property)
> 
> The v1 series was closer to what you are suggesting: it added a
> standalone `vhe=on/off` property and used it to select the
> requested KVM vCPU initialization mode.
> 
> Could you please also review the v1 implementation?
> 
> https://lore.kernel.org/qemu-devel/20261121095636.289814-1-haseebashraf091@gmail.com/

It is a valid point to question the addition of new vcpu properties (especially low level ones like this one) while we plan to introduce those SYSREG low level properties. For composite properties which stand at higher level (tweaking several knobs at KVM VCPU init or IDREG field level) it still makes sense though.

Until now we have proposed for the host vcpu to expose SYSREG props only for KVM writable ID reg fields. On the other hand, named vcpu models require to have ALL ID reg fields exposed. If we were to extend this infra to other archs or TCG, we may also need to expose ALL fields and just have different implementation for setters/getters depending on the writability mode (REG WRITE or VCPU init or anything else). 

Thanks

Eric> 
> I changed direction for v2 following Marc's feedback against adding a
> separate property.
> 
> Thanks,
> Haseeb
Re: [RFC PATCH v3 0/3] arm/kvm: select an nVHE-only EL2 with SYSREG_ID_AA64MMFR1_EL1_VH
Posted by Mohamed Mediouni 1 day, 7 hours ago

> On 26. Nov 2026, at 18:13, Eric Auger <eauger@redhat.com> wrote:
> 
> Hi Haseeb, Khushit,
> 
> On 11/26/26 7:20 AM, Haseeb Ashraf wrote:
>> Hi Khushit,
>> 
>> On 26/11/26 11:38, Khushit Shah wrote:
>> 
>>> There are many such fields like PAuth (APA, GPA, …) and SVE. They are
>>> not part of the SYSREG_ framework as there already exists boolean
>>> properties for them.
>>> (Another way to do this is having -cpu …,vhe=on/off property)
>> 
>> The v1 series was closer to what you are suggesting: it added a
>> standalone `vhe=on/off` property and used it to select the
>> requested KVM vCPU initialization mode.
>> 
>> Could you please also review the v1 implementation?
>> 
>> https://lore.kernel.org/qemu-devel/20261121095636.289814-1-haseebashraf091@gmail.com/
> 
> It is a valid point to question the addition of new vcpu properties (especially low level ones like this one) while we plan to introduce those SYSREG low level properties. For composite properties which stand at higher level (tweaking several knobs at KVM VCPU init or IDREG field level) it still makes sense though.
> 
> Until now we have proposed for the host vcpu to expose SYSREG props only for KVM writable ID reg fields. On the other hand, named vcpu models require to have ALL ID reg fields exposed. If we were to extend this infra to other archs or TCG, we may also need to expose ALL fields and just have different implementation for setters/getters depending on the writability mode (REG WRITE or VCPU init or anything else).

Hi,

Given that for HVF we need to say whether it’s VHE or nVHE before vCPU creation time, I think
that maybe bolting it on as a vCPU property isn’t the best idea…

Thank you,
-Mohamed
> 
> Thanks
> 
> Eric>
>> I changed direction for v2 following Marc's feedback against adding a
>> separate property.
>> 
>> Thanks,
>> Haseeb
> 
>