* [PATCH 0/1] hw/arm/virt: add vhe option for nested virtualization
@ 2026-11-21 9:56 Haseeb Ashraf
2026-11-21 9:56 ` [PATCH 1/1] " Haseeb Ashraf
2026-11-21 13:52 ` [PATCH 0/1] " Marc Zyngier
0 siblings, 2 replies; 3+ messages in thread
From: Haseeb Ashraf @ 2026-11-21 9:56 UTC (permalink / raw)
To: Peter Maydell, qemu-arm
Cc: Pierrick Bouvier, Paolo Bonzini, Volodymyr Babchuk, Haseeb Ashraf,
qemu-devel, kvm
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/1] hw/arm/virt: add vhe option for nested virtualization
2026-11-21 9:56 [PATCH 0/1] hw/arm/virt: add vhe option for nested virtualization Haseeb Ashraf
@ 2026-11-21 9:56 ` Haseeb Ashraf
2026-11-21 13:52 ` [PATCH 0/1] " Marc Zyngier
1 sibling, 0 replies; 3+ messages in thread
From: Haseeb Ashraf @ 2026-11-21 9:56 UTC (permalink / raw)
To: Peter Maydell, qemu-arm
Cc: Haseeb Ashraf, Pierrick Bouvier, Paolo Bonzini, Volodymyr Babchuk,
qemu-devel, kvm
From: Haseeb Ashraf <haseeb.ashraf@siemens.com>
Add a vhe machine property for the virt board. When virtualization=on,
VHE remains enabled by default, but vhe=off allows nVHE/type-1 guest
hypervisors to run without VHE.
Propagate the setting to the ARM CPU, limit TCG to nVHE mode, and request
the KVM_ARM_VCPU_HAS_EL2_E2H0 vCPU initialization flag when VHE is
disabled. Reject vhe=off when the selected accelerator cannot provide
the requested behavior. The option has no effect unless
virtualization=on is also set.
Document the option, and make the nested virtualization functional test
pass a vhe setting matching the kernel mode.
Tested nested virtualization with KVM on arm64 hosts using L0 kernel
versions 6.18.29 and 7.2.11. A Linux 6.12.67 guest initialized KVM in
nVHE mode with vhe=off and VHE mode with vhe=on. QNX Hypervisor 8.0.5
detected EL1 host hypervisor support with vhe=off and EL2 host
hypervisor support with vhe=on. Xen booted dom0 to the login prompt with
vhe=off, but did not boot with vhe=on.
Tested with TCG on an AmpereOne A192-32X host. QNX Hypervisor 8.0.5
boots with both vhe settings, and Xen boots its dom0 with vhe=off.
Suggested-by: Volodymyr Babchuk <volodymyr.babchuk@epam.com>
Signed-off-by: Haseeb Ashraf <haseeb.ashraf@siemens.com>
---
docs/system/arm/virt.rst | 10 ++++++++
hw/arm/virt.c | 37 ++++++++++++++++++++++++++++
include/hw/arm/virt.h | 1 +
target/arm/cpu.c | 15 +++++++++++
target/arm/cpu.h | 2 ++
target/arm/kvm-stub.c | 5 ++++
target/arm/kvm.c | 8 ++++++
target/arm/kvm_arm.h | 12 +++++++++
tests/functional/aarch64/test_kvm.py | 10 +++++---
9 files changed, 97 insertions(+), 3 deletions(-)
diff --git a/docs/system/arm/virt.rst b/docs/system/arm/virt.rst
index 5f6dd17978..31f0878788 100644
--- a/docs/system/arm/virt.rst
+++ b/docs/system/arm/virt.rst
@@ -116,6 +116,16 @@ virtualization
Set ``on``/``off`` to enable/disable emulating a guest CPU which implements the
Arm Virtualization Extensions. The default is ``off``.
+vhe
+ Set ``on``/``off`` to allow/disallow a guest hypervisor to use the Arm
+ Virtualization Host Extensions (``FEAT_VHE``) when ``virtualization`` is
+ ``on``. The default is ``on``, which places no restriction on the selected
+ CPU model (it does not add VHE to a CPU model which lacks it). ``off``
+ exposes EL2 in nVHE mode for a type-1 guest hypervisor: with TCG this hides
+ ``FEAT_VHE``, with KVM it requires host ``E2H0`` support, and it is not
+ supported with HVF. This option has no effect when ``virtualization`` is
+ ``off``.
+
mte
Set ``on``/``off`` to enable/disable emulating a guest CPU which implements the
Arm Memory Tagging Extensions. The default is ``off``.
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 0b11f7e328..1a987faa19 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -3025,6 +3025,12 @@ static void machvirt_init(MachineState *machine)
exit(1);
}
+ if (vms->virt && !vms->vhe && hvf_enabled()) {
+ error_report("mach-virt: %s does not support disabling VHE",
+ current_accel_name());
+ exit(1);
+ }
+
if (vms->mte && hvf_enabled()) {
error_report("mach-virt: %s does not support providing "
"MTE to the guest CPU",
@@ -3069,6 +3075,10 @@ static void machvirt_init(MachineState *machine)
object_property_set_bool(cpuobj, "has_el2", false, NULL);
}
+ if (vms->virt && object_property_find(cpuobj, "has_vhe")) {
+ object_property_set_bool(cpuobj, "has_vhe", vms->vhe, NULL);
+ }
+
if (vmc->no_kvm_steal_time &&
object_property_find(cpuobj, "kvm-steal-time")) {
object_property_set_bool(cpuobj, "kvm-steal-time", false, NULL);
@@ -3308,6 +3318,20 @@ static void virt_set_virt(Object *obj, bool value, Error **errp)
hvf_nested_virt_enable(value);
}
+static bool virt_get_vhe(Object *obj, Error **errp)
+{
+ VirtMachineState *vms = VIRT_MACHINE(obj);
+
+ return vms->vhe;
+}
+
+static void virt_set_vhe(Object *obj, bool value, Error **errp)
+{
+ VirtMachineState *vms = VIRT_MACHINE(obj);
+
+ vms->vhe = value;
+}
+
static bool virt_get_highmem(Object *obj, Error **errp)
{
VirtMachineState *vms = VIRT_MACHINE(obj);
@@ -4235,6 +4259,13 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data)
"guest CPU which implements the ARM "
"Virtualization Extensions");
+ object_class_property_add_bool(oc, "vhe", virt_get_vhe,
+ virt_set_vhe);
+ object_class_property_set_description(oc, "vhe",
+ "Set on/off to enable/disable the ARM "
+ "Virtualization Host Extensions (applicable "
+ "only when virtualization=on)");
+
object_class_property_add_bool(oc, "highmem", virt_get_highmem,
virt_set_highmem);
object_class_property_set_description(oc, "highmem",
@@ -4375,6 +4406,12 @@ static void virt_instance_init(Object *obj)
/* EL2 is also disabled by default, for similar reasons */
vms->virt = false;
+ /*
+ * VHE is unrestricted by default when virtualization=on is set.
+ * With vhe=off, EL2 is limited to nVHE mode.
+ */
+ vms->vhe = true;
+
/* High memory is enabled by default */
vms->highmem = true;
vms->highmem_compact = !vmc->no_highmem_compact;
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
index 22e66d1a11..bd0065efb1 100644
--- a/include/hw/arm/virt.h
+++ b/include/hw/arm/virt.h
@@ -174,6 +174,7 @@ struct VirtMachineState {
bool highmem_redists;
bool tcg_its;
bool virt;
+ bool vhe;
bool ras;
bool mte;
bool dtb_randomness;
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index dde03ffdd6..4d272b5388 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -1326,6 +1326,9 @@ static const Property arm_cpu_reset_hivecs_property =
static const Property arm_cpu_has_el2_property =
DEFINE_PROP_BOOL("has_el2", ARMCPU, has_el2, true);
+static const Property arm_cpu_has_vhe_property =
+ DEFINE_PROP_BOOL("has_vhe", ARMCPU, has_vhe, true);
+
static const Property arm_cpu_has_el3_property =
DEFINE_PROP_BOOL("has_el3", ARMCPU, has_el3, true);
@@ -1622,6 +1625,7 @@ static void arm_cpu_post_init(Object *obj)
if (arm_feature(&cpu->env, ARM_FEATURE_EL2)) {
qdev_property_add_static(DEVICE(obj), &arm_cpu_has_el2_property);
+ qdev_property_add_static(DEVICE(obj), &arm_cpu_has_vhe_property);
}
#endif
@@ -1872,6 +1876,13 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
return;
}
+ if (cpu->has_el2 && !cpu->has_vhe && kvm_enabled() &&
+ !kvm_arm_el2_e2h0_supported()) {
+ error_setg(errp, "KVM does not support disabling VHE (E2H0 "
+ "unavailable)");
+ return;
+ }
+
#ifndef CONFIG_USER_ONLY
/* The NVIC and M-profile CPU are two halves of a single piece of
* hardware; trying to use one without the other is a command line
@@ -2246,6 +2257,10 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
unset_feature(env, ARM_FEATURE_EL2);
}
+ if (cpu->has_el2 && !cpu->has_vhe && tcg_enabled()) {
+ FIELD_DP64_IDREG(isar, ID_AA64MMFR1, VH, 0);
+ }
+
if (!cpu->has_pmu) {
unset_feature(env, ARM_FEATURE_PMU);
}
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index b2f393f501..2f94fdae7b 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -1022,6 +1022,8 @@ struct ArchCPU {
bool has_el2;
/* CPU has security extension */
bool has_el3;
+ /* CPU has virtualization host extensions */
+ bool has_vhe;
/* CPU has PMU (Performance Monitor Unit) */
bool has_pmu;
/* CPU has VFP */
diff --git a/target/arm/kvm-stub.c b/target/arm/kvm-stub.c
index 88cbe8d85c..6eb9e1366a 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 df86ad387c..6b95ed1da8 100644
--- a/target/arm/kvm.c
+++ b/target/arm/kvm.c
@@ -2003,6 +2003,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);
@@ -2060,6 +2065,9 @@ static void kvm_arm_vcpu_prepare_init_features(ARMCPU *cpu)
}
if (cpu->has_el2 && kvm_arm_el2_supported()) {
cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_HAS_EL2;
+ if (!cpu->has_vhe) {
+ cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_HAS_EL2_E2H0;
+ }
}
}
diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h
index 9c7e7f654a..24828e9c07 100644
--- a/target/arm/kvm_arm.h
+++ b/target/arm/kvm_arm.h
@@ -182,6 +182,13 @@ 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 supports limiting EL2 to E2H=0, and false otherwise.
+ */
+bool kvm_arm_el2_e2h0_supported(void);
#else
static inline bool kvm_arm_aarch32_supported(void)
@@ -198,6 +205,11 @@ static inline bool kvm_arm_el2_supported(void)
{
return false;
}
+
+static inline bool kvm_arm_el2_e2h0_supported(void)
+{
+ return false;
+}
#endif
/**
diff --git a/tests/functional/aarch64/test_kvm.py b/tests/functional/aarch64/test_kvm.py
index c977e8c6d2..502060a109 100755
--- a/tests/functional/aarch64/test_kvm.py
+++ b/tests/functional/aarch64/test_kvm.py
@@ -40,7 +40,9 @@ def _launch_guest(self, kvm_mode="nvhe"):
f"console=ttyAMA0 kvm-arm.mode={kvm_mode}")
self.vm.add_args("-cpu", "max")
- self.vm.add_args("-machine", "virt,gic-version=3,virtualization=on",
+ vhe = "on" if kvm_mode == "vhe" else "off"
+ self.vm.add_args("-machine",
+ f"virt,gic-version=3,virtualization=on,vhe={vhe}",
'-kernel', kernel_path,
'-append', kernel_command_line)
self.vm.add_args("-smp", "2", "-m", "320")
@@ -48,8 +50,10 @@ def _launch_guest(self, kvm_mode="nvhe"):
try:
self.vm.launch()
except VMLaunchFailure as excp:
- if "does not support providing Virtualization" in excp.output:
- self.skipTest("accelerator has no virtualization support")
+ if ("does not support providing Virtualization" in excp.output or
+ "does not support disabling VHE" in excp.output):
+ self.skipTest("accelerator lacks the required virtualization "
+ "support")
else:
self.log.info("unhandled launch failure: %s", excp.output)
raise excp
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 0/1] hw/arm/virt: add vhe option for nested virtualization
2026-11-21 9:56 [PATCH 0/1] hw/arm/virt: add vhe option for nested virtualization Haseeb Ashraf
2026-11-21 9:56 ` [PATCH 1/1] " Haseeb Ashraf
@ 2026-11-21 13:52 ` Marc Zyngier
1 sibling, 0 replies; 3+ messages in thread
From: Marc Zyngier @ 2026-11-21 13:52 UTC (permalink / raw)
To: Haseeb Ashraf
Cc: Peter Maydell, qemu-arm, Pierrick Bouvier, Paolo Bonzini,
Volodymyr Babchuk, Haseeb Ashraf, qemu-devel, kvm, Eric Auger
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-21 13:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 9:56 [PATCH 0/1] hw/arm/virt: add vhe option for nested virtualization Haseeb Ashraf
2026-11-21 9:56 ` [PATCH 1/1] " Haseeb Ashraf
2026-11-21 13:52 ` [PATCH 0/1] " Marc Zyngier
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.