[PATCH 0/1] hw/arm/virt: add vhe option for nested virtualization

Haseeb Ashraf posted 1 patch 1 day, 18 hours ago
[PATCH 0/1] hw/arm/virt: add vhe option for nested virtualization
Posted by Haseeb Ashraf 1 day, 18 hours ago
Hi,

The virt board currently enables VHE whenever virtualization=on.  There
is no way to expose EL2 in nVHE mode to a type-1 guest hypervisor.

This series adds a vhe machine property, enabled by default for
compatibility.  Setting vhe=off propagates the requested mode to the
guest CPU, limits TCG's advertised VHE feature, and requests the KVM
HAS_EL2_E2H0 vCPU initialization feature.  Unsupported accelerators
and KVM hosts fail clearly instead of silently ignoring the option.

Validation was performed on an AmpereOne A192-32X (Ampere-1a) machine:

  - KVM with L0 kernels 6.18.29 and 7.2.11:
    - Linux 6.12.67 initializes KVM in nVHE mode with vhe=off and VHE
      mode with vhe=on.
    - QNX Hypervisor 8.0.5 detects the requested EL1/nVHE or EL2/VHE mode.
    - Xen dom0 boots with vhe=off.
    - Xen does not boot with vhe=on.
  - TCG:
    - QNX Hypervisor 8.0.5 boots to login with vhe=on and vhe=off.
    - Xen dom0 boots to login with vhe=off.
    - Both AArch64 KVM functional self-tests pass.
  - TCG-only, KVM-only, and aarch64-linux-user builds succeed.

Thanks,
Haseeb

Haseeb Ashraf (1):
  hw/arm/virt: add vhe option for nested virtualization
[RFC PATCH v2 0/3] arm/kvm: select an nVHE-only EL2 with SYSREG_ID_AA64MMFR1_EL1_VH
Posted by Haseeb Ashraf 1 day, 7 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.  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/20261030131406.461599-1-eric.auger@redhat.com/
[2] https://github.com/eauger/qemu/commits/arm-cpu-model-v11-rc
[3] https://patchew.org/QEMU/20261121095636.289814-1-haseebashraf091@gmail.com/

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(-)
[RFC PATCH v2 1/3] target/arm/kvm: Add kvm_arm_el2_e2h0_supported()
Posted by Haseeb Ashraf 1 day, 7 hours ago
From: Haseeb Ashraf <haseeb.ashraf@siemens.com>

Add a helper reporting whether KVM can limit a nested guest to an
nVHE-only EL2 (HCR_EL2.E2H RES0) through the
KVM_ARM_VCPU_HAS_EL2_E2H0 vCPU feature.  KVM advertises this with
KVM_CAP_ARM_EL2_E2H0.

The next patch uses it to let the user select an nVHE-only EL2.

Signed-off-by: Haseeb Ashraf <haseeb.ashraf@siemens.com>
---
 target/arm/kvm-stub.c |  5 +++++
 target/arm/kvm.c      |  5 +++++
 target/arm/kvm_arm.h  | 13 +++++++++++++
 3 files changed, 23 insertions(+)

diff --git a/target/arm/kvm-stub.c b/target/arm/kvm-stub.c
index c9387f5c8c..88e35909c4 100644
--- a/target/arm/kvm-stub.c
+++ b/target/arm/kvm-stub.c
@@ -42,6 +42,11 @@ bool kvm_arm_el2_supported(void)
     return false;
 }
 
+bool kvm_arm_el2_e2h0_supported(void)
+{
+    return false;
+}
+
 /*
  * These functions should never actually be called without KVM support.
  */
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
index 36a5faf537..8ef5597c68 100644
--- a/target/arm/kvm.c
+++ b/target/arm/kvm.c
@@ -2178,6 +2178,11 @@ bool kvm_arm_el2_supported(void)
     return kvm_check_extension(kvm_state, KVM_CAP_ARM_EL2);
 }
 
+bool kvm_arm_el2_e2h0_supported(void)
+{
+    return kvm_check_extension(kvm_state, KVM_CAP_ARM_EL2_E2H0);
+}
+
 bool kvm_arm_mte_supported(void)
 {
     return kvm_check_extension(kvm_state, KVM_CAP_ARM_MTE);
diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h
index 2e7e02e4a4..0916a5fdb4 100644
--- a/target/arm/kvm_arm.h
+++ b/target/arm/kvm_arm.h
@@ -200,6 +200,14 @@ bool kvm_arm_mte_supported(void);
  * Returns true if KVM can enable EL2 and false otherwise.
  */
 bool kvm_arm_el2_supported(void);
+
+/**
+ * kvm_arm_el2_e2h0_supported:
+ *
+ * Returns true if KVM can limit EL2 to nVHE (HCR_EL2.E2H RES0) through
+ * KVM_ARM_VCPU_HAS_EL2_E2H0, and false otherwise.
+ */
+bool kvm_arm_el2_e2h0_supported(void);
 #else
 
 static inline bool kvm_arm_aarch32_supported(void)
@@ -216,6 +224,11 @@ static inline bool kvm_arm_el2_supported(void)
 {
     return false;
 }
+
+static inline bool kvm_arm_el2_e2h0_supported(void)
+{
+    return false;
+}
 #endif
 
 /**
-- 
2.34.1
[RFC PATCH v2 2/3] target/arm/kvm: Let SYSREG_ID_AA64MMFR1_EL1_VH select an nVHE EL2
Posted by Haseeb Ashraf 1 day, 7 hours ago
From: Haseeb Ashraf <haseeb.ashraf@siemens.com>

KVM runs a nested guest with a VHE-only EL2 (HCR_EL2.E2H RES1) unless
KVM_ARM_VCPU_HAS_EL2_E2H0 is requested at KVM_ARM_VCPU_INIT time.  With
that feature FEAT_VHE is hidden: ID_AA64MMFR1_EL1.VH reads 0 and
HCR_EL2.E2H is RES0.  Guest hypervisors which only support nVHE, such as
Xen, can only run in the latter mode.

Do not add a dedicated machine or CPU option for it.  Derive the vCPU
init feature from the ID register field selected by the user instead:
SYSREG_ID_AA64MMFR1_EL1_VH=0 requests KVM_ARM_VCPU_HAS_EL2_E2H0.

KVM does not let userspace write ID_AA64MMFR1_EL1.VH, so the generic
"writable fields only" rule would not create the property.  Expose it
explicitly when the host supports KVM_CAP_ARM_EL2_E2H0.  As KVM already
reports the requested value after vCPU init, applying the property does
not need a KVM_SET_ONE_REG for this field, and the query-cpu-model-expansion
dry run on the scratch vCPU skips it.  Setting VH=0 without
virtualization=on is rejected.

Only ID_AA64MMFR1_EL1.VH is updated in QEMU's copy of the ID registers.
Other fields which KVM derives from E2H0 (e.g. ID_AA64MMFR4_EL1) are
not refreshed.

Suggested-by: Marc Zyngier <maz@kernel.org>
Suggested-by: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
Signed-off-by: Haseeb Ashraf <haseeb.ashraf@siemens.com>
---

v2:
 - Use Eric Auger's SYSREG framework instead of a dedicated vhe
   machine/CPU property.
 - Expose the init-driven VH field only when KVM supports E2H0.
 - Add the virtualization=on consistency check and document VH=0.
 docs/system/arm/cpu-features.rst | 22 ++++++++++++++
 target/arm/cpu-idregs.h          | 31 +++++++++++++++++++
 target/arm/cpu64.c               | 51 +++++++++++++++++++++++++-------
 target/arm/kvm.c                 | 24 +++++++++++++--
 4 files changed, 114 insertions(+), 14 deletions(-)

diff --git a/docs/system/arm/cpu-features.rst b/docs/system/arm/cpu-features.rst
index 13454783cf..cde26c04b9 100644
--- a/docs/system/arm/cpu-features.rst
+++ b/docs/system/arm/cpu-features.rst
@@ -579,6 +579,28 @@ either not writable with the specific host kernel, unknown to this QEMU
 build, or intentionally not exposed because it overlaps a legacy composite
 option.
 
+Selecting an nVHE-only EL2
+--------------------------
+
+With ``-machine virt,virtualization=on``, KVM presents a VHE-only EL2 to
+the guest (``HCR_EL2.E2H`` is RES1) by default.  A guest hypervisor which
+only supports nVHE, such as a type-1 hypervisor like Xen, needs VHE to be
+hidden.  This is done by setting ``ID_AA64MMFR1_EL1.VH`` to 0::
+
+  $ qemu-system-aarch64 -M virt,virtualization=on -accel kvm \
+        -cpu host,SYSREG_ID_AA64MMFR1_EL1_VH=0
+
+QEMU then requests ``KVM_ARM_VCPU_HAS_EL2_E2H0`` when initializing the
+vCPUs, so that ``HCR_EL2.E2H`` is RES0 for the guest.  Leaving the
+property unset, or setting it to 1, keeps the default VHE-only EL2.
+Setting it to 0 requires ``virtualization=on``.
+
+KVM does not allow userspace to write ``ID_AA64MMFR1_EL1.VH`` directly, so
+this is an exception to the rule that only writable fields get a
+property: the ``SYSREG_ID_AA64MMFR1_EL1_VH`` property is exposed when the
+host kernel supports ``KVM_CAP_ARM_EL2_E2H0``.  Without this support the
+property does not exist.
+
 A note on compatibility
 -----------------------
 
diff --git a/target/arm/cpu-idregs.h b/target/arm/cpu-idregs.h
index 465ec83c97..76d7b94858 100644
--- a/target/arm/cpu-idregs.h
+++ b/target/arm/cpu-idregs.h
@@ -73,4 +73,35 @@ int arm_cpu_apply_sysreg_props(ARMCPU *cpu, ARMSysregPropApplyFn accel_apply_fn,
 bool arm_cpu_validate_sysreg_prop(ARMCPU *cpu, ARM64SysRegField *field,
                                   uint64_t value, Error **errp);
 
+/**
+ * arm_cpu_sysreg_prop_get:
+ *
+ * Look up the value the user set through a SYSREG_<IDREG>_<FIELD>
+ * property, before it is applied to the vcpu.  Accelerators use it to
+ * derive vcpu init settings from the requested ID register values.
+ *
+ * @cpu: vcpu the property belongs to
+ * @reg_idx: ID register index (<REG>_EL1_IDX)
+ * @shift: lowest bit of the field
+ * @value: set to the requested field value when the property was set
+ *
+ * returns true if the property was set by the user
+ */
+bool arm_cpu_sysreg_prop_get(ARMCPU *cpu, int reg_idx, int shift,
+                             uint64_t *value);
+
+/**
+ * arm_cpu_sysreg_field_init_driven:
+ *
+ * Some fields cannot be written with the accelerator once the vcpu exists
+ * but are selected through a vcpu init feature instead (for instance
+ * ID_AA64MMFR1_EL1.VH with KVM_ARM_VCPU_HAS_EL2_E2H0).  Their SYSREG
+ * property is exposed even if the field is not writable.
+ *
+ * @field: ID register field
+ *
+ * returns true if @field is selected at vcpu init time on this host
+ */
+bool arm_cpu_sysreg_field_init_driven(ARM64SysRegField *field);
+
 #endif
diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
index c08eba7010..1fc3a4bb7c 100644
--- a/target/arm/cpu64.c
+++ b/target/arm/cpu64.c
@@ -835,6 +835,21 @@ static ARM64SysRegField *arm_sysreg_get_field(ARM64SysReg *reg, int bit)
     return NULL;
 }
 
+bool arm_cpu_sysreg_prop_get(ARMCPU *cpu, int reg_idx, int shift,
+                             uint64_t *value)
+{
+    gpointer value_ptr;
+    uint64_t key = IDREG_FIELD_KEY(reg_idx, shift);
+
+    if (!g_hash_table_lookup_extended(cpu->sysreg_props,
+                                      GUINT_TO_POINTER(key), NULL,
+                                      &value_ptr)) {
+        return false;
+    }
+    *value = GPOINTER_TO_UINT(value_ptr);
+    return true;
+}
+
 /**
  * arm_cpu_validate_sysreg_prop:
  *
@@ -879,6 +894,13 @@ bool arm_cpu_validate_sysreg_prop(ARMCPU *cpu, ARM64SysRegField *field,
             error_setg(errp, "%s is non null whereas pmu is unset", propname);
             return false;
         }
+    /* nVHE-only EL2, selected at vcpu init time */
+    } else if (!strcmp(propname, "SYSREG_ID_AA64MMFR1_EL1_VH")) {
+        if (value == 0 && !cpu->has_el2) {
+            error_setg(errp, "%s=0 requires -machine virtualization=on",
+                       propname);
+            return false;
+        }
     /* aarch64=off */
     } else if (!arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
         if ((!strcmp(propname, "SYSREG_ID_AA64PFR0_EL1_EL0") ||
@@ -988,17 +1010,9 @@ static void get_sysreg_prop(Object *obj, Visitor *v,
     int index = field->index;
     int lower = field->shift;
     int length = field->length;
-    gpointer value_ptr;
     uint64_t value;
-    uint64_t key = IDREG_FIELD_KEY(index, lower);
-    gboolean exists;
-
-    exists = g_hash_table_lookup_extended(cpu->sysreg_props,
-                                          GUINT_TO_POINTER(key), NULL,
-                                          &value_ptr);
-    if (exists) {
-        value = GPOINTER_TO_UINT(value_ptr);
-    } else {
+
+    if (!arm_cpu_sysreg_prop_get(cpu, index, lower, &value)) {
         uint64_t mask = MAKE_64BIT_MASK(lower, length);
         uint64_t *idregs = cpu->isar.idregs;
 
@@ -1028,6 +1042,20 @@ static const char * const aarch64_sysreg_prop_skip_list[] = {
     "SYSREG_ID_AA64ISAR2_EL1_GPA3",
 };
 
+/*
+ * Fields which KVM does not let userspace write with KVM_SET_ONE_REG,
+ * but which QEMU can still select through a vcpu init feature, see
+ * kvm_arm_vcpu_prepare_init_features().  ID_AA64MMFR1_EL1.VH is hidden
+ * by KVM_ARM_VCPU_HAS_EL2_E2H0, which requests an nVHE-only EL2.
+ */
+bool arm_cpu_sysreg_field_init_driven(ARM64SysRegField *field)
+{
+    /* Compare the field first: this runs for every ID register field */
+    return field->index == ID_AA64MMFR1_EL1_IDX &&
+           field->shift == R_ID_AA64MMFR1_VH_SHIFT &&
+           kvm_enabled() && kvm_arm_el2_e2h0_supported();
+}
+
 static bool aarch64_sysreg_prop_skipped(const char *prop_name)
 {
     for (int i = 0; i < ARRAY_SIZE(aarch64_sysreg_prop_skip_list); i++) {
@@ -1084,7 +1112,8 @@ aarch64_add_one_idreg_properties(Object *obj, ARM64SysReg *reg,
         }
         map = map & ~field_mask;
 
-        if (writable_only && !field_writable_mask) {
+        if (writable_only && !field_writable_mask &&
+            !arm_cpu_sysreg_field_init_driven(field)) {
             continue;
         }
 
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
index 8ef5597c68..bb4ca7e8d1 100644
--- a/target/arm/kvm.c
+++ b/target/arm/kvm.c
@@ -1324,9 +1324,15 @@ bool kvm_idreg_write_scratch_vcpu(ARMCPU *cpu, int cpufd,
         return false;
     }
 
-    ret = kvm_arm_override_idreg_field(cpufd, field, newfv, errp);
-    if (ret) {
-        return false;
+    /*
+     * Init-driven fields (e.g. VH) are selected through a vcpu init
+     * feature, which the scratch vcpu may not have: do not write them.
+     */
+    if (!arm_cpu_sysreg_field_init_driven(field)) {
+        ret = kvm_arm_override_idreg_field(cpufd, field, newfv, errp);
+        if (ret) {
+            return false;
+        }
     }
 
     cpu->isar.idregs[field->index] =
@@ -2239,7 +2245,19 @@ static void kvm_arm_vcpu_prepare_init_features(ARMCPU *cpu)
                                       1 << KVM_ARM_VCPU_PTRAUTH_GENERIC);
     }
     if (cpu->has_el2 && kvm_arm_el2_supported()) {
+        uint64_t vh;
+
         cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_HAS_EL2;
+        /*
+         * KVM exposes a VHE-only EL2 by default.  An nVHE-only EL2 can
+         * only be selected at vcpu init time, so derive it from the
+         * requested ID_AA64MMFR1_EL1.VH value.
+         */
+        if (arm_cpu_sysreg_prop_get(cpu, ID_AA64MMFR1_EL1_IDX,
+                                    R_ID_AA64MMFR1_VH_SHIFT, &vh) &&
+            vh == 0) {
+            cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_HAS_EL2_E2H0;
+        }
     }
 }
 
-- 
2.34.1
[RFC PATCH v2 3/3] tests/functional: Add a KVM selftest for an nVHE-only EL2
Posted by Haseeb Ashraf 1 day, 7 hours ago
From: Haseeb Ashraf <haseeb.ashraf@siemens.com>

Run the existing kvm-unit-tests smoke test with VHE hidden from the
guest hypervisor through SYSREG_ID_AA64MMFR1_EL1_VH=0.  The SYSREG_*
properties are available only for the host CPU model with KVM, so
select the accelerator and CPU model explicitly, and check that the
guest kernel initialized its hypervisor in nVHE mode.  The test is
skipped when the host kernel cannot limit EL2 to nVHE.

Signed-off-by: Haseeb Ashraf <haseeb.ashraf@siemens.com>
---

v2:
 - Select KVM and the host CPU model explicitly.
 - Verify the guest kernel reports nVHE mode.

 tests/functional/aarch64/test_kvm.py | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/tests/functional/aarch64/test_kvm.py b/tests/functional/aarch64/test_kvm.py
index c977e8c6d2..b7a4aceb66 100755
--- a/tests/functional/aarch64/test_kvm.py
+++ b/tests/functional/aarch64/test_kvm.py
@@ -30,7 +30,7 @@ class Aarch64VirtKVMTests(LinuxKernelTest):
     # base of tests
     KUT_BASE = "/usr/share/kvm-unit-tests/"
 
-    def _launch_guest(self, kvm_mode="nvhe"):
+    def _launch_guest(self, kvm_mode="nvhe", cpu="max", accel=None):
 
         self.set_machine('virt')
         kernel_path = self.ASSET_KVM_TEST_KERNEL.fetch()
@@ -39,7 +39,9 @@ def _launch_guest(self, kvm_mode="nvhe"):
         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
                                f"console=ttyAMA0 kvm-arm.mode={kvm_mode}")
 
-        self.vm.add_args("-cpu", "max")
+        if accel:
+            self.vm.add_args("-accel", accel)
+        self.vm.add_args("-cpu", cpu)
         self.vm.add_args("-machine", "virt,gic-version=3,virtualization=on",
                          '-kernel', kernel_path,
                          '-append', kernel_command_line)
@@ -50,6 +52,9 @@ def _launch_guest(self, kvm_mode="nvhe"):
         except VMLaunchFailure as excp:
             if "does not support providing Virtualization" in excp.output:
                 self.skipTest("accelerator has no virtualization support")
+            elif ("SYSREG_ID_AA64MMFR1_EL1_VH" in excp.output and
+                  "not found" in excp.output):
+                self.skipTest("host KVM cannot limit EL2 to nVHE")
             else:
                 self.log.info("unhandled launch failure: %s", excp.output)
                 raise excp
@@ -73,5 +78,18 @@ def test_aarch64_vhe_selftest(self):
         self._launch_guest("vhe")
         self._smoketest_kvm()
 
+    def test_aarch64_nvhe_only_selftest(self):
+        # Hiding VHE from the guest hypervisor is a KVM feature: the
+        # SYSREG_* properties only exist for the host CPU model with KVM.
+        self.require_accelerator("kvm")
+        self._launch_guest("nvhe", "host,SYSREG_ID_AA64MMFR1_EL1_VH=0",
+                           accel="kvm")
+        # The guest kernel must run its hypervisor in nVHE mode
+        ec_and_wait(self, "dmesg | grep -Eq "
+                    "'Hyp (nVHE )?mode initialized successfully' && "
+                    "! dmesg | grep -q ' VHE mode initialized'",
+                    self.OK_CMD)
+        self._smoketest_kvm()
+
 if __name__ == '__main__':
     LinuxKernelTest.main()
-- 
2.34.1
Re: [PATCH 0/1] hw/arm/virt: add vhe option for nested virtualization
Posted by Marc Zyngier 1 day, 14 hours ago
On Sat, 21 Nov 2026 09:56:35 +0000,
Haseeb Ashraf <haseebashraf091@gmail.com> wrote:
> 
> Hi,
> 
> The virt board currently enables VHE whenever virtualization=on.  There
> is no way to expose EL2 in nVHE mode to a type-1 guest hypervisor.
> 
> This series adds a vhe machine property, enabled by default for
> compatibility.  Setting vhe=off propagates the requested mode to the
> guest CPU, limits TCG's advertised VHE feature, and requests the KVM
> HAS_EL2_E2H0 vCPU initialization feature.  Unsupported accelerators
> and KVM hosts fail clearly instead of silently ignoring the option.

+ Eric

Adding yet another random property for something that is a feature of
the emulated CPU strikes me as going in the wrong direction.

I'd rather see this being directly driven by Eric's feature framework
as posted at [1], which lets *any* feature being selected by the user.
The KVM feature flag can then be derived from what the user has
selected (and matched against what the host can provide).

Thanks,

	M.

[1] https://lore.kernel.org/r/20261010133725.642498-1-eric.auger@redhat.com

-- 
Without deviation from the norm, progress is not possible.
Re: [PATCH 0/1] hw/arm/virt: add vhe option for nested virtualization
Posted by Mohamed Mediouni 1 day, 14 hours ago

> On 21. Nov 2026, at 14:52, Marc Zyngier <maz@kernel.org> wrote:
> 
> On Sat, 21 Nov 2026 09:56:35 +0000,
> Haseeb Ashraf <haseebashraf091@gmail.com> wrote:
>> 
>> Hi,
>> 
>> The virt board currently enables VHE whenever virtualization=on.  There
>> is no way to expose EL2 in nVHE mode to a type-1 guest hypervisor.
>> 
>> This series adds a vhe machine property, enabled by default for
>> compatibility.  Setting vhe=off propagates the requested mode to the
>> guest CPU, limits TCG's advertised VHE feature, and requests the KVM
>> HAS_EL2_E2H0 vCPU initialization feature.  Unsupported accelerators
>> and KVM hosts fail clearly instead of silently ignoring the option.
> 
> + Eric
> 
> Adding yet another random property for something that is a feature of
> the emulated CPU strikes me as going in the wrong direction.
> 
> I'd rather see this being directly driven by Eric's feature framework
> as posted at [1], which lets *any* feature being selected by the user.
> The KVM feature flag can then be derived from what the user has
> selected (and matched against what the host can provide).
> 
> Thanks,

Hi,

Relying on CPU features for nested virt comes with complexity for the HVF side,
where the nested virt configuration is part of the accelerator not a vCPU.

And it’s too late at vCPU creation time to re-configure this, that said I’ve
been considering whether it’d be wise to build a hack in HVF and WHP* to defer
VM creation until creation of the first vCPU but that adds other problems…

* currently, we have this behaviour on x86 there where nested virt is always 
set as enabled because of this, and -cpu host,vmx=on is only disabling exposing
the CPUID bit, not nested virt by itself.

> 
> M.
> 
> [1] https://lore.kernel.org/r/20261010133725.642498-1-eric.auger@redhat.com
> 
> -- 
> Without deviation from the norm, progress is not possible.
>