hvf: arm: fixes for QEMU 11.2
cover hvf: arm: fixes for QEMU 11.2
- workaround for presumed Hypervisor.framework issue
- save/restore SME state only when SME is on for the CPU
- add ID_AA64PFR0_EL1.GIC sync to advertise the system register interface
Adrien Kohlbecker (1):
target/arm: sync vCPU state after PSCI CPU_ON reset
Mohamed Mediouni (5):
hvf: gicv3: manually set GICD_ISPENDR on edge triggered interrupts
hvf: arm: save/restore SME state only when SME on
hvf: arm: remove broken ID_AA64PFR0_EL1.GIC sync
hvf: arm: advertise ID_AA64PFR0_EL1.GIC
hvf: arm: fetch more features
hw/intc/arm_gicv3_hvf.c | 20 ++++++++++++++++++++ target/arm/arm-powerctl.c | 3 +++ target/arm/hvf/hvf.c | 37 +++++++++++++++++++++++++++++++------ 3 files changed, 54 insertions(+), 6 deletions(-)
Signature · 1 line
2.54.0 (Apple Git-157)
PATCH 1/6 hvf: gicv3: manually set GICD_ISPENDR on edge triggered interrupts
This addresses stability issues with Windows as a guest.
--- hw/intc/arm_gicv3_hvf.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
hw/intc/arm_gicv3_hvf.c +20 -0
@@ -603,7 +603,27 @@ static void hvf_gicv3_set_irq(void *opaque, int irq, int level)if (irq > s->num_irq) {return ; } +hv_gic_set_spi (GIC_INTERNAL + irq, !!level); + +if (level) { +/* Fetching state from the vGIC */ +hvf_dist_get_edge_trigger (s,HV_GIC_DISTRIBUTOR_REG_GICD_ICFGR0 , + s->edge_trigger); + +/* +* 0->1 edges latch the pending bit for edge-triggered interrupts. +* +* Hypervisor.framework does not seem to do this for us as expected. +*/ +if (gicv3_gicd_edge_trigger_test (s,GIC_INTERNAL + irq)) { +hvf_dist_getbmp (s,HV_GIC_DISTRIBUTOR_REG_GICD_ISPENDR0 , + s->pending); +gicv3_gicd_pending_set (s,GIC_INTERNAL + irq); +hvf_dist_putbmp (s,HV_GIC_DISTRIBUTOR_REG_GICD_ISPENDR0 , +HV_GIC_DISTRIBUTOR_REG_GICD_ICPENDR0 , s->pending); + } + } }static void hvf_gicv3_icc_reset (CPUARMState *env,const ARMCPRegInfo *ri)
Signature · 1 line
2.54.0 (Apple Git-157)
Re: [PATCH 1/6] hvf: gicv3: manually set GICD_ISPENDR on edge triggered interrupts
Quoted 28 lines · Mohamed Mediouni
This addresses stability issues with Windows as a guest.
Signed-off-by Mohamed Mediouni <[email protected]>--- hw/intc/arm_gicv3_hvf.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)hw/intc/arm_gicv3_hvf.c +11
-0@@ -603,7 +603,27 @@ static void hvf_gicv3_set_irq(void *opaque, int irq, int level)if (irq > s->num_irq) {return ; } +hv_gic_set_spi (GIC_INTERNAL + irq, !!level); + +if (level) { +/* Fetching state from the vGIC */ +hvf_dist_get_edge_trigger (s,HV_GIC_DISTRIBUTOR_REG_GICD_ICFGR0 , + s->edge_trigger); + +/* +* 0->1 edges latch the pending bit for edge-triggered interrupts. +* +* Hypervisor.framework does not seem to do this for us as expected.
hw/intc/arm_gicv3_hvf.c static void hvf_gicv3_set_irq(void *opaque, int irq, int level) · line 627
Quoted 10 lines
hw/intc/arm_gicv3_hvf.c +9
-0+*/ +if (gicv3_gicd_edge_trigger_test (s,GIC_INTERNAL + irq)) { +hvf_dist_getbmp (s,HV_GIC_DISTRIBUTOR_REG_GICD_ISPENDR0 , + s->pending); +gicv3_gicd_pending_set (s,GIC_INTERNAL + irq); +hvf_dist_putbmp (s,HV_GIC_DISTRIBUTOR_REG_GICD_ISPENDR0 , +HV_GIC_DISTRIBUTOR_REG_GICD_ICPENDR0 , s->pending); + } + } }
This basically would amount to "hvf doesn't implement edge triggered interrupts". That seems very unlikely, because basically every guest is going to use edge-triggered interrupts, and the documentation for hv_gic_set_spi() says that it handles edge triggers.
I would want a lot more evidence of hvf being broken plus a bug report to Apple about it before taking something like this.
thanks
-- PMM
PATCH 2/6 target/arm: sync vCPU state after PSCI CPU_ON reset
In reply to Mohamed MediouniFrom: Adrien Kohlbecker <[email protected]>
arm_set_cpu_on_async_work() resets the target CPU and sets its entry point and context ID in CPUARMState, but never tells the accelerator that the register state changed. TCG reads CPUARMState directly, and KVM re-pushes state on reset, but HVF only writes CPUARMState back to the hardware vCPU when cpu->vcpu_dirty is set.
A vCPU that reached PSCI_OFF is left clean: its last hv_vcpu_run() exit was a WFI or a cancel, and flush_cpu_state() cleared the flag. A later CPU_ON then resets and re-points only the QEMU-side copy. The vCPU resumes in its old context, with the old MMU state and vector table, and never runs the requested entry point.
This shows up when a guest that already onlined and offlined its secondary CPUs boots another kernel, for example kexec on Apple Silicon:
the new kernel logs "CPUn: failed to come online" for every secondary. Fresh vCPUs are created dirty and single-CPU guests never issue CPU_ON, so the ordinary boot path is unaffected.
Call cpu_synchronize_post_reset() after resetting the target, in both arm_set_cpu_on_async_work() and arm_set_cpu_on_and_reset_async_work(). It is a no-op for TCG.
--- target/arm/arm-powerctl.c | 3 +++ 1 file changed, 3 insertions(+)
target/arm/arm-powerctl.c +3 -0
@@ -16,6 +16,7 @@#include "qemu/log.h" #include "qemu/main-loop.h" #include "system/tcg.h" +#include "system/hw_accel.h" #include "target/arm/multiprocessing.h" #include "trace.h"
@@ -80,6 +81,7 @@ static void arm_set_cpu_on_async_work(CPUState *target_cpu_state,/* Start the new CPU at the requested address */ cpu_set_pc (target_cpu_state, info->entry); +cpu_synchronize_post_reset (target_cpu_state);g_free (info);
@@ -189,6 +191,7 @@ static void arm_set_cpu_on_and_reset_async_work(CPUState *target_cpu_state,/* Initialize the cpu we are turning on */ cpu_reset (target_cpu_state); +cpu_synchronize_post_reset (target_cpu_state); target_cpu_state->halted =0 ;/* Finally set the power status */
Signature · 1 line
2.54.0 (Apple Git-157)
Re: [PATCH 2/6] target/arm: sync vCPU state after PSCI CPU_ON reset
Quoted 8 lines · Mohamed Mediouni
From: Adrien Kohlbecker <[email protected]>
arm_set_cpu_on_async_work()resets the target CPU and sets its entry point and context ID in CPUARMState, but never tells the accelerator that the register state changed. TCG reads CPUARMState directly, and KVM re-pushes state on reset, but HVF only writes CPUARMState back to the hardware vCPU whencpu->vcpu_dirtyis set.
My first reaction to "this works on KVM but HVF does something differently and it doesn't work" is "so why are we doing things differently?".
Quoted 34 lines
A vCPU that reached
PSCI_OFFis left clean: its lasthv_vcpu_run()exit was a WFI or a cancel, andflush_cpu_state()cleared the flag. A laterCPU_ONthen resets and re-points only the QEMU-side copy. The vCPU resumes in its old context, with the old MMU state and vector table, and never runs the requested entry point.This shows up when a guest that already onlined and offlined its secondary CPUs boots another kernel, for example kexec on Apple Silicon:
the new kernel logs "CPUn: failed to come online" for every secondary. Fresh vCPUs are created dirty and single-CPU guests never issueCPU_ON, so the ordinary boot path is unaffected.Call
cpu_synchronize_post_reset()after resetting the target, in botharm_set_cpu_on_async_work()andarm_set_cpu_on_and_reset_async_work(). It is a no-op for TCG.Signed-off-by Adrien Kohlbecker <[email protected]>--- target/arm/arm-powerctl.c | 3 +++ 1 file changed, 3 insertions(+)target/arm/arm-powerctl.c +1
-0@@ -16,6 +16,7 @@#include "qemu/log.h" #include "qemu/main-loop.h" #include "system/tcg.h" +#include "system/hw_accel.h" #include "target/arm/multiprocessing.h" #include "trace.h"
target/arm/arm-powerctl.c static void arm_set_cpu_on_async_work(CPUState *target_cpu_state, · line 84
Quoted 4 lines
target/arm/arm-powerctl.c +1
-0@@ -80,6 +81,7 @@ static void arm_set_cpu_on_async_work(CPUState *target_cpu_state,/* Start the new CPU at the requested address */ cpu_set_pc (target_cpu_state, info->entry); +cpu_synchronize_post_reset (target_cpu_state);
This isn't a CPU reset, so do we really needcpu_synchronize_post_reset ?
target/arm/arm-powerctl.c static void arm_set_cpu_on_and_reset_async_work(CPUState *target_cpu_state, · line 194
Quoted 7 lines
target/arm/arm-powerctl.c +1
-0g_free (info);@@ -189,6 +191,7 @@ static void arm_set_cpu_on_and_reset_async_work(CPUState *target_cpu_state,/* Initialize the cpu we are turning on */ cpu_reset (target_cpu_state); +cpu_synchronize_post_reset (target_cpu_state);
I'm not sure whether cpu_synchronize_post_reset() is supposed to be "after we just did a full system reset" (the way i386 uses it) or also "after we did a single cpu reset" (the way s390 uses it).
target/arm/arm-powerctl.c static void arm_set_cpu_on_and_reset_async_work(CPUState *target_cpu_state, · line 197
Quoted 3 lines
target/arm/arm-powerctl.c +0
-0target_cpu_state->halted =0 ;/* Finally set the power status */
-- PMM
Re: [PATCH 2/6] target/arm: sync vCPU state after PSCI CPU_ON reset
Hi Peter,
Thanks for the review. I should say I'm not very familiar with QEMU's
internals: I hit this as a user, while trying to kexec in an HVF guest on a Mac, and the patch is the smallest change I found that made it work. So I can't really answer your questions about which sync call is the right one, and I'd defer to you and Mohamed on that.
On KVM: the same kexec works for me on KVM (an AWS Graviton host), but I don't know why, so the KVM sentence in the commit message is a guess and I'm happy to drop it.
What I can offer is a simple way to reproduce it. Boot the Ubuntu 24.04 arm64 cloud image on an Apple Silicon Mac with "-M virt -accel hvf -cpu host -smp 2", then as root:
echo 0 > /sys/devices/system/cpu/cpu1/online
echo 1 > /sys/devices/system/cpu/cpu1/online
With QEMU 11.0.1 the guest panics on the second command ("kernel BUG at arch/arm64/kernel/smp.c:388", in cpu_die()). It did that every time I tried (5 runs). With my patch applied, CPU1 comes back and the guest keeps running.
I also tried calling cpu_synchronize_state() before cpu_reset() instead of cpu_synchronize_post_reset() after it, in case that is a better fit. That fixes the reproducer too (4 runs).
I'm happy to test whatever version you think is right.
Thanks,
Adrien
Quoted 73 lines · Peter Maydell
Quoted 8 lines · Mohamed Mediouni
From: Adrien Kohlbecker <[email protected]>
arm_set_cpu_on_async_work()resets the target CPU and sets its entry point and context ID in CPUARMState, but never tells the accelerator that the register state changed. TCG reads CPUARMState directly, and KVM re-pushes state on reset, but HVF only writes CPUARMState back to the hardware vCPU whencpu->vcpu_dirtyis set.My first reaction to "this works on KVM but HVF does something differently and it doesn't work" is "so why are we doing things differently?".
Quoted 34 lines
A vCPU that reached
PSCI_OFFis left clean: its lasthv_vcpu_run()exit was a WFI or a cancel, andflush_cpu_state()cleared the flag. A laterCPU_ONthen resets and re-points only the QEMU-side copy. The vCPU resumes in its old context, with the old MMU state and vector table, and never runs the requested entry point.This shows up when a guest that already onlined and offlined its secondary CPUs boots another kernel, for example kexec on Apple Silicon:
the new kernel logs "CPUn: failed to come online" for every secondary. Fresh vCPUs are created dirty and single-CPU guests never issueCPU_ON, so the ordinary boot path is unaffected.Call
cpu_synchronize_post_reset()after resetting the target, in botharm_set_cpu_on_async_work()andarm_set_cpu_on_and_reset_async_work(). It is a no-op for TCG.Signed-off-by Adrien Kohlbecker <[email protected]>--- target/arm/arm-powerctl.c | 3 +++ 1 file changed, 3 insertions(+)target/arm/arm-powerctl.c +1
-0@@ -16,6 +16,7 @@#include "qemu/log.h" #include "qemu/main-loop.h" #include "system/tcg.h" +#include "system/hw_accel.h" #include "target/arm/multiprocessing.h" #include "trace.h" target/arm/arm-powerctl.c static void arm_set_cpu_on_async_work(CPUState *target_cpu_state, · line 84
Quoted 4 lines
target/arm/arm-powerctl.c +1
-0@@ -80,6 +81,7 @@ static void arm_set_cpu_on_async_work(CPUState *target_cpu_state,/* Start the new CPU at the requested address */ cpu_set_pc (target_cpu_state, info->entry); +cpu_synchronize_post_reset (target_cpu_state);This isn't a CPU reset, so do we really need
cpu_synchronize_post_reset?target/arm/arm-powerctl.c static void arm_set_cpu_on_and_reset_async_work(CPUState *target_cpu_state, · line 194
Quoted 7 lines
target/arm/arm-powerctl.c +1
-0g_free (info);@@ -189,6 +191,7 @@ static void arm_set_cpu_on_and_reset_async_work(CPUState *target_cpu_state,/* Initialize the cpu we are turning on */ cpu_reset (target_cpu_state); +cpu_synchronize_post_reset (target_cpu_state);I'm not sure whether
cpu_synchronize_post_reset()is supposed to be "after we just did a full system reset" (the way i386 uses it) or also "after we did a single cpu reset" (the way s390 uses it).target/arm/arm-powerctl.c static void arm_set_cpu_on_and_reset_async_work(CPUState *target_cpu_state, · line 197
Quoted 3 lines
target/arm/arm-powerctl.c +0
-0target_cpu_state->halted =0 ;/* Finally set the power status */ -- PMM
PATCH 3/6 hvf: arm: save/restore SME state only when SME on
In reply to Mohamed MediouniWhen SME is disabled as part of the CPU configuration, do not restore SME state.
--- target/arm/hvf/hvf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/arm/hvf/hvf.c +2 -2
@@ -1394,7 +1394,7 @@ int hvf_arch_init_vcpu(CPUState *cpu)int i; if (__builtin_available(macOS 15.2, *)) { -if (hvf_arm_sme2_supported ()) { +if (hvf_arm_sme2_supported () &&cpu_isar_feature (aa64_sme, arm_cpu)) { sregs_match_len +=ARRAY_SIZE (hvf_sreg_list_sme2) +1 ; }
@@ -1444,7 +1444,7 @@ int hvf_arch_init_vcpu(CPUState *cpu) } } if (__builtin_available(macOS 15.2, *)) { -if (hvf_arm_sme2_supported ()) { +if (hvf_arm_sme2_supported () &&cpu_isar_feature (aa64_sme, arm_cpu)) {for (i =0 ; i <ARRAY_SIZE (hvf_sreg_list_sme2); i++) {hv_sys_reg_t hvf_id = hvf_sreg_list_sme2[i].sreg;uint64_t kvm_id =HVF_TO_KVMID (hvf_id);
Signature · 1 line
2.54.0 (Apple Git-157)
Re: [PATCH 3/6] hvf: arm: save/restore SME state only when SME on
Quoted 22 lines · Mohamed Mediouni
When SME is disabled as part of the CPU configuration, do not restore SME state.
Signed-off-by Mohamed Mediouni <[email protected]>--- target/arm/hvf/hvf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/arm/hvf/hvf.c +1
-1@@ -1394,7 +1394,7 @@ int hvf_arch_init_vcpu(CPUState *cpu)int i; if (__builtin_available(macOS 15.2, *)) { -if (hvf_arm_sme2_supported ()) { +if (hvf_arm_sme2_supported () &&cpu_isar_feature (aa64_sme, arm_cpu)) { sregs_match_len +=ARRAY_SIZE (hvf_sreg_list_sme2) +1 ; }
target/arm/hvf/hvf.c int hvf_arch_init_vcpu(CPUState *cpu) · line 1450
Quoted 8 lines
target/arm/hvf/hvf.c +1
-1@@ -1444,7 +1444,7 @@ int hvf_arch_init_vcpu(CPUState *cpu) } } if (__builtin_available(macOS 15.2, *)) { -if (hvf_arm_sme2_supported ()) { +if (hvf_arm_sme2_supported () &&cpu_isar_feature (aa64_sme, arm_cpu)) {for (i =0 ; i <ARRAY_SIZE (hvf_sreg_list_sme2); i++) {hv_sys_reg_t hvf_id = hvf_sreg_list_sme2[i].sreg;uint64_t kvm_id =HVF_TO_KVMID (hvf_id);
Do we need to check both, or at the point where this code is called will we already have updated the ID registers to not report aa64_sme if the host hvf doesn't have sme2 support?
thanks
-- PMM
PATCH 4/6 hvf: arm: remove broken ID_AA64PFR0_EL1.GIC sync
In reply to Mohamed MediouniThe GIC is only realised after this executes
in arm_gicv3_common_realize.
--- target/arm/hvf/hvf.c | 1 - 1 file changed, 1 deletion(-)
target/arm/hvf/hvf.c +0 -1
@@ -1480,7 +1480,6 @@ int hvf_arch_init_vcpu(CPUState *cpu)assert_hvf_ok (ret); 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);assert_hvf_ok (ret);
Signature · 1 line
2.54.0 (Apple Git-157)
Re: [PATCH 4/6] hvf: arm: remove broken ID_AA64PFR0_EL1.GIC sync
Quoted 5 lines · Mohamed Mediouni
The GIC is only realised after this executes
inarm_gicv3_common_realize.Signed-off-by Mohamed Mediouni <[email protected]>
thanks
-- PMM
PATCH 5/6 hvf: arm: advertise ID_AA64PFR0_EL1.GIC
In reply to Mohamed MediouniFor 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
@@ -1230,6 +1230,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-157)
Re: [PATCH 5/6] hvf: arm: advertise ID_AA64PFR0_EL1.GIC
Quoted 19 lines · Mohamed Mediouni
For the kernel-irqchip=on case, advertise ID_AA64PFR0_EL1.GIC.
Signed-off-by Mohamed Mediouni <[email protected]>--- target/arm/hvf/hvf.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)target/arm/hvf/hvf.c +3
-0@@ -1230,6 +1230,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
target/arm/hvf/hvf.c static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) · line 1245
Quoted 10 lines
target/arm/hvf/hvf.c +9
-0+* 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;
thanks
-- PMM
PATCH 6/6 hvf: arm: fetch more features
In reply to Mohamed MediounimacOS 27.0 has some more feature registers available. Fetch them (but not using the values yet).
Also fetch DCZID_EL0 at the same time.
--- target/arm/hvf/hvf.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
target/arm/hvf/hvf.c +17 -3
@@ -1142,16 +1142,14 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) } regs[] = { { HV_FEATURE_REG_ID_AA64PFR0_EL1, ID_AA64PFR0_EL1_IDX }, { HV_FEATURE_REG_ID_AA64PFR1_EL1, ID_AA64PFR1_EL1_IDX }, - /* Add ID_AA64PFR2_EL1 here when HVF supports it */ { HV_FEATURE_REG_ID_AA64DFR0_EL1, ID_AA64DFR0_EL1_IDX }, { HV_FEATURE_REG_ID_AA64DFR1_EL1, ID_AA64DFR1_EL1_IDX }, { HV_FEATURE_REG_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_IDX }, { HV_FEATURE_REG_ID_AA64ISAR1_EL1, ID_AA64ISAR1_EL1_IDX }, - /* Add ID_AA64ISAR2_EL1 here when HVF supports it */ { HV_FEATURE_REG_ID_AA64MMFR0_EL1, ID_AA64MMFR0_EL1_IDX }, { HV_FEATURE_REG_ID_AA64MMFR1_EL1, ID_AA64MMFR1_EL1_IDX }, { HV_FEATURE_REG_ID_AA64MMFR2_EL1, ID_AA64MMFR2_EL1_IDX }, - /* Add ID_AA64MMFR3_EL1 here when HVF supports it */ + { HV_FEATURE_REG_DCZID_EL0, DCZID_EL0_IDX}, }; hv_return_t r = HV_SUCCESS; hv_vcpu_config_t config = hv_vcpu_config_create();
@@ -1191,6 +1189,22 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) } } + if (__builtin_available(macOS 27.0, *)) { +static const struct isar_regs { +hv_feature_reg_t reg; +ARMIDRegisterIdx index; + } new_regs[] = { + {HV_FEATURE_REG_ID_AA64ISAR2_EL1 ,ID_AA64ISAR2_EL1_IDX }, + {HV_FEATURE_REG_ID_AA64PFR2_EL1 ,ID_AA64PFR2_EL1_IDX }, + {HV_FEATURE_REG_ID_AA64MMFR3_EL1 ,ID_AA64MMFR3_EL1_IDX }, + {HV_FEATURE_REG_ID_AA64MMFR4_EL1 ,ID_AA64MMFR4_EL1_IDX }, + }; +for (i =0 ; i <ARRAY_SIZE (new_regs); i++) { + r |=hv_vcpu_config_get_feature_reg (config, new_regs[i].reg, + &host_isar.idregs[new_regs[i].index]); + } + } +os_release (config);/*
Signature · 1 line
2.54.0 (Apple Git-157)
Re: [PATCH 6/6] hvf: arm: fetch more features
Quoted 35 lines · Mohamed Mediouni
macOS 27.0 has some more feature registers available. Fetch them (but not using the values yet).
Also fetch
DCZID_EL0at the same time.Signed-off-by Mohamed Mediouni <[email protected]>--- target/arm/hvf/hvf.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)target/arm/hvf/hvf.c +1
-3@@ -1142,16 +1142,14 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) } regs[] = { { HV_FEATURE_REG_ID_AA64PFR0_EL1, ID_AA64PFR0_EL1_IDX }, { HV_FEATURE_REG_ID_AA64PFR1_EL1, ID_AA64PFR1_EL1_IDX }, - /* Add ID_AA64PFR2_EL1 here when HVF supports it */ { HV_FEATURE_REG_ID_AA64DFR0_EL1, ID_AA64DFR0_EL1_IDX }, { HV_FEATURE_REG_ID_AA64DFR1_EL1, ID_AA64DFR1_EL1_IDX }, { HV_FEATURE_REG_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_IDX }, { HV_FEATURE_REG_ID_AA64ISAR1_EL1, ID_AA64ISAR1_EL1_IDX }, - /* Add ID_AA64ISAR2_EL1 here when HVF supports it */ { HV_FEATURE_REG_ID_AA64MMFR0_EL1, ID_AA64MMFR0_EL1_IDX }, { HV_FEATURE_REG_ID_AA64MMFR1_EL1, ID_AA64MMFR1_EL1_IDX }, { HV_FEATURE_REG_ID_AA64MMFR2_EL1, ID_AA64MMFR2_EL1_IDX }, - /* Add ID_AA64MMFR3_EL1 here when HVF supports it */ + { HV_FEATURE_REG_DCZID_EL0, DCZID_EL0_IDX}, }; hv_return_t r = HV_SUCCESS; hv_vcpu_config_t config = hv_vcpu_config_create();@@ -1191,6 +1189,22 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) } }
target/arm/hvf/hvf.c static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) · line 1200
Quoted 10 lines
target/arm/hvf/hvf.c +9
-0+ if (__builtin_available(macOS 27.0, *)) { +static const struct isar_regs { +hv_feature_reg_t reg; +ARMIDRegisterIdx index; + } new_regs[] = { + {HV_FEATURE_REG_ID_AA64ISAR2_EL1 ,ID_AA64ISAR2_EL1_IDX }, + {HV_FEATURE_REG_ID_AA64PFR2_EL1 ,ID_AA64PFR2_EL1_IDX }, + {HV_FEATURE_REG_ID_AA64MMFR3_EL1 ,ID_AA64MMFR3_EL1_IDX }, + {HV_FEATURE_REG_ID_AA64MMFR4_EL1 ,ID_AA64MMFR4_EL1_IDX },
Spaces after { and before } to match the existing code, please.
target/arm/hvf/hvf.c static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) · line 1206
Quoted 6 lines
target/arm/hvf/hvf.c +6
-0+ }; +for (i =0 ; i <ARRAY_SIZE (new_regs); i++) { + r |=hv_vcpu_config_get_feature_reg (config, new_regs[i].reg, + &host_isar.idregs[new_regs[i].index]); + } + }
Otherwise
I note that we now have three places in this function which duplicate this "array which repeats the definition of struct isar_regs, and loop around calling hv_vcpu_config_get_feature_reg()" pattern. We could factor that out into a proper typedef for the struct and a helper function that does the "iterate through getting the values" part.
thanks
-- PMM