Skip to contentSkip to conversation

hvf: arm: add experimental VHE (x-vhe) toggle

PATCH In review Mohamed Mediouni 2 participants 9 messages Sep 4 – Sep 28

lore
Share & tools
lore
#0 lore raw

v2 cover hvf: arm: add experimental VHE (x-vhe) toggle

macOS 27.0 has a pre-release VHE implementation. Add support for it in QEMU.

The first patch in the series is an independent bugfix that should be backported to QEMU 11.1 too.

v2:

Add:
hvf: arm: expose E2H0
hvf: arm: ignore accesses to CNTKCTL_EL12

This is to have working KVM under the VHE configuration.

Mohamed Mediouni (5):
hvf: arm: advertise ID_AA64PFR0_EL1.GIC
hvf: arm: add experimental VHE toggle
hvf: arm: advertise EL3 support when VHE is on
hvf: arm: expose E2H0
hvf: arm: ignore accesses to CNTKCTL_EL12

 accel/hvf/hvf-all.c      |   2 +
 include/system/hvf_int.h |   1 +
 target/arm/hvf/hvf.c     | 114 +++++++++++++++++++++++++++++++++++++++
 target/i386/hvf/hvf.c    |   4 ++
 4 files changed, 121 insertions(+)
Signature · 1 line
2.54.0 (Apple Git-156)
#1 lore raw

PATCH v2 1/5 hvf: arm: advertise ID_AA64PFR0_EL1.GIC

For the kernel-irqchip=on case, advertise ID_AA64PFR0_EL1.GIC.

---
 target/arm/hvf/hvf.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
target/arm/hvf/hvf.c +12 -0
index da3ec521fc..f881d6cc67 100644
@@ -1229,6 +1229,18 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
         FIELD_DP64_IDREG(&host_isar, ID_AA64PFR1, SME, 0);
     }
 
+    /*
+     * On HVF, kernel-irqchip implies GICv3.
+     * The kernel-irqchip=off,gic-version=3 legacy case also supports
+     * the host CPU interface but advertising it in ID_AA64PFR0_EL1
+     * is not implemented yet.
+     */
+
+    if (hvf_irqchip_in_kernel()) {
+        /* Advertise the GIC system register interface */
+        FIELD_DP64_IDREG(&host_isar, ID_AA64PFR0, GIC, 1);
+    }
+
     ahcf->isar = host_isar;
 
     /*
Signature · 1 line
2.54.0 (Apple Git-156)
#2 lore raw

Re: [PATCH v2 1/5] hvf: arm: advertise ID_AA64PFR0_EL1.GIC

Quoted 17 lines · Mohamed Mediouni

For the kernel-irqchip=on case, advertise ID_AA64PFR0_EL1.GIC.

---
 target/arm/hvf/hvf.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
target/arm/hvf/hvf.c +1 -0
index da3ec521fc..f881d6cc67 100644
@@ -1229,6 +1229,18 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
         FIELD_DP64_IDREG(&host_isar, ID_AA64PFR1, SME, 0);
     }
 
+    /*

target/arm/hvf/hvf.c static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) · line 1242

Quoted 10 lines
target/arm/hvf/hvf.c +10 -0
+     * On HVF, kernel-irqchip implies GICv3.
+     * The kernel-irqchip=off,gic-version=3 legacy case also supports
+     * the host CPU interface but advertising it in ID_AA64PFR0_EL1
+     * is not implemented yet.
+     */
+
+    if (hvf_irqchip_in_kernel()) {
+        /* Advertise the GIC system register interface */
+        FIELD_DP64_IDREG(&host_isar, ID_AA64PFR0, GIC, 1);
+    }

How does this interact with the existing code in
hvf_arch_init_vcpu() that does:

    pfr = GET_IDREG(&arm_cpu->isar, ID_AA64PFR0);
    pfr |= env->gicv3state ? (1 << 24) : 0;
    ret = hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_ID_AA64PFR0_EL1, pfr);

?

env->gicv3state should be non-NULL for both HVF and TCG GICv3, I think, so aren't we already advertising the GIC in ID_AA64PFR0 ?

thanks
-- PMM

#3 lore raw

Re: [PATCH v2 1/5] hvf: arm: advertise ID_AA64PFR0_EL1.GIC

Quoted 40 lines · Peter Maydell
Quoted 17 lines · Mohamed Mediouni

For the kernel-irqchip=on case, advertise ID_AA64PFR0_EL1.GIC.

---
target/arm/hvf/hvf.c | 12 ++++++++++++

1 file changed, 12 insertions(+)
target/arm/hvf/hvf.c +1 -0
index da3ec521fc..f881d6cc67 100644
@@ -1229,6 +1229,18 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
        FIELD_DP64_IDREG(&host_isar, ID_AA64PFR1, SME, 0);
    }
 
+    /*

target/arm/hvf/hvf.c static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) · line 1242

Quoted 10 lines
target/arm/hvf/hvf.c +10 -0
+     * On HVF, kernel-irqchip implies GICv3.
+     * The kernel-irqchip=off,gic-version=3 legacy case also supports
+     * the host CPU interface but advertising it in ID_AA64PFR0_EL1
+     * is not implemented yet.
+     */
+
+    if (hvf_irqchip_in_kernel()) {
+        /* Advertise the GIC system register interface */
+        FIELD_DP64_IDREG(&host_isar, ID_AA64PFR0, GIC, 1);
+    }

How does this interact with the existing code in
hvf_arch_init_vcpu() that does:

   pfr = GET_IDREG(&arm_cpu->isar, ID_AA64PFR0);
   pfr |= env->gicv3state ? (1 << 24) : 0;
   ret = hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_ID_AA64PFR0_EL1, pfr);
Quoted 5 lines

?

env->gicv3state should be non-NULL for both HVF and TCG GICv3, I think, so aren't we already advertising the GIC in ID_AA64PFR0 ?

Hi,

Without this patch HVF GICv3 doesn’t show up, will look deeper at why that check you noted is not effective…

Maybe it’s a question of ordering?

Quoted 4 lines

thanks
-- PMM

#4 lore raw

PATCH v2 2/5 hvf: arm: add experimental VHE toggle

In reply to Mohamed Mediouni

macOS 27.0 ships with an experimental VHE enablement private API. Expose support for it as x-vhe.

---
 accel/hvf/hvf-all.c      |  2 +
 include/system/hvf_int.h |  1 +
 target/arm/hvf/hvf.c     | 89 ++++++++++++++++++++++++++++++++++++++++
 target/i386/hvf/hvf.c    |  4 ++
 4 files changed, 96 insertions(+)
accel/hvf/hvf-all.c +2 -0
index 8bd9154a50..bbff3c6867 100644
@@ -282,6 +282,8 @@ static void hvf_accel_class_init(ObjectClass *oc, const void *data)
         NULL, NULL);
     object_class_property_set_description(oc, "kernel-irqchip",
         "Configure HVF irqchip");
+
+    hvf_arch_accel_class_init(oc);
 }
 
 static const TypeInfo hvf_accel_type = {
include/system/hvf_int.h +1 -0
index a01691ce17..44ae2e7c4c 100644
@@ -110,5 +110,6 @@ int hvf_update_guest_debug(CPUState *cpu);
 bool hvf_arch_cpu_realize(CPUState *cpu, Error **errp);
 uint32_t hvf_arch_get_default_ipa_bit_size(void);
 uint32_t hvf_arch_get_max_ipa_bit_size(void);
+void hvf_arch_accel_class_init(ObjectClass *oc);
 
 #endif
target/arm/hvf/hvf.c +89 -0

119 lines not on this page · raw message

target/i386/hvf/hvf.c +4 -0
index 150598418e..5a39a82492 100644
@@ -1068,3 +1068,7 @@ void hvf_arch_remove_all_gdbstub_hw_breakpoints(void)
 void hvf_arch_update_guest_debug(CPUState *cpu)
 {
 }
+
+void hvf_arch_accel_class_init(ObjectClass *oc)
+{
+}
Signature · 1 line
2.54.0 (Apple Git-156)
#5 lore raw

PATCH v2 3/5 hvf: arm: advertise EL3 support when VHE is on

In reply to Mohamed Mediouni

This replicates the typical KVM configuration, and Hyper-V wants it.

---
 target/arm/hvf/hvf.c | 2 ++
 1 file changed, 2 insertions(+)
target/arm/hvf/hvf.c +2 -0
index b61554e108..c54a92c2aa 100644
@@ -1286,6 +1286,8 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
         if (hvf_get_vhe()) {
             FIELD_DP64_IDREG(&host_isar, ID_AA64MMFR1, VH, 0x1);
         }
+        /* Hyper-V doesn't launch if EL3 isn't advertised. */
+        FIELD_DP64_IDREG(&host_isar, ID_AA64PFR0, EL3, 0x1);
     }
 
     /*
Signature · 1 line
2.54.0 (Apple Git-156)
#6 lore raw

PATCH v2 4/5 hvf: arm: expose E2H0

In reply to Mohamed Mediouni

In the VHE mode, nVHE is not available. As such, only expose VHE.

---
 target/arm/hvf/hvf.c | 1 +
 1 file changed, 1 insertion(+)
target/arm/hvf/hvf.c +1 -0
index c54a92c2aa..47eeaa0f30 100644
@@ -1285,6 +1285,7 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
         FIELD_DP64_IDREG(&host_isar, ID_AA64PFR1, SME, 0);
         if (hvf_get_vhe()) {
             FIELD_DP64_IDREG(&host_isar, ID_AA64MMFR1, VH, 0x1);
+            FIELD_DP64_IDREG(&host_isar, ID_AA64MMFR4, E2H0, 0xf);
         }
         /* Hyper-V doesn't launch if EL3 isn't advertised. */
         FIELD_DP64_IDREG(&host_isar, ID_AA64PFR0, EL3, 0x1);
Signature · 1 line
2.54.0 (Apple Git-156)
#7 lore raw

PATCH v2 5/5 hvf: arm: ignore accesses to CNTKCTL_EL12

In reply to Mohamed Mediouni

This makes KVM work, with runnable virtual machines.

---
 target/arm/hvf/hvf.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
target/arm/hvf/hvf.c +10 -0
index 47eeaa0f30..c32c705ddd 100644
@@ -305,6 +305,10 @@ void hvf_arm_init_debug(void)
 #define SYSREG_CNTHCTL_EL2    SYSREG(3, 4, 14, 1, 0)
 #define SYSREG_MDCCINT_EL1    SYSREG(2, 0, 0, 2, 0)
 
+/* VHE registers */
+#define SYSREG_CNTKCTL_EL12 SYSREG(3, 5, 14, 1, 0)
+
+
 #define WFX_IS_WFE (1 << 0)
 
 #define TMR_CTL_ENABLE  (1 << 0)
@@ -1857,6 +1861,9 @@ static int hvf_sysreg_read(CPUState *cpu, uint32_t reg, uint64_t *val)
             assert_hvf_ok(hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTHCTL_EL2, val));
         }
         return 0;
+    case SYSREG_CNTKCTL_EL12:
+        /* Ignore for now */
+        return 0;
     case SYSREG_MDCCINT_EL1:
         assert_hvf_ok(hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_MDCCINT_EL1, val));
         return 0;
@@ -2155,6 +2162,9 @@ static int hvf_sysreg_write(CPUState *cpu, uint32_t reg, uint64_t val)
             assert_hvf_ok(hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTHCTL_EL2, val));
         }
         return 0;
+    case SYSREG_CNTKCTL_EL12:
+        /* Ignore for now */
+        return 0;
     case SYSREG_MDCCINT_EL1:
         assert_hvf_ok(hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_MDCCINT_EL1, val));
         return 0;
Signature · 1 line
2.54.0 (Apple Git-156)
#8 lore raw
In reply to Mohamed Mediouni
Quoted 11 lines · Mohamed Mediouni

macOS 27.0 has a pre-release VHE implementation. Add support for it in QEMU.

The first patch in the series is an independent bugfix that should be backported to QEMU 11.1 too.

v2:

Add:
hvf: arm: expose E2H0
hvf: arm: ignore accesses to CNTKCTL_EL12

Quoted 8 lines

This is to have working KVM under the VHE configuration.

Mohamed Mediouni (5):
hvf: arm: advertise ID_AA64PFR0_EL1.GIC
hvf: arm: add experimental VHE toggle
hvf: arm: advertise EL3 support when VHE is on
hvf: arm: expose E2H0
hvf: arm: ignore accesses to CNTKCTL_EL12

I would prefer to wait with this until the interface for VHE is not a "private API you have to get at by playing games with dlopen()" setup.

thanks
-- PMM