On 28.01.21 17:55, Peter Maydell wrote: > On Wed, 20 Jan 2021 at 22:44, Alexander Graf <ag...@csgraf.de> wrote: >> Now that we have working system register sync, we push more target CPU >> properties into the virtual machine. That might be useful in some >> situations, but is not the typical case that users want. >> >> So let's add a -cpu host option that allows them to explicitly pass all >> CPU capabilities of their host CPU into the guest. >> >> Signed-off-by: Alexander Graf <ag...@csgraf.de> >> Acked-by: Roman Bolshakov <r.bolsha...@yadro.com> >> --- >> include/sysemu/hvf.h | 2 ++ >> target/arm/cpu.c | 9 ++++++--- >> target/arm/cpu.h | 2 ++ >> target/arm/hvf/hvf.c | 41 +++++++++++++++++++++++++++++++++++++++++ >> target/arm/kvm_arm.h | 2 -- >> 5 files changed, 51 insertions(+), 5 deletions(-) >> >> diff --git a/include/sysemu/hvf.h b/include/sysemu/hvf.h >> index f893768df9..7eb61cf094 100644 >> --- a/include/sysemu/hvf.h >> +++ b/include/sysemu/hvf.h >> @@ -19,6 +19,8 @@ >> #ifdef CONFIG_HVF >> uint32_t hvf_get_supported_cpuid(uint32_t func, uint32_t idx, >> int reg); >> +struct ARMCPU; > Yuck. >
[...] >> + hv_vcpu_t fd; >> + hv_vcpu_exit_t *exit; >> + int i; >> + >> + cpu->dtb_compatible = "arm,arm-v8"; >> + cpu->env.features = (1ULL << ARM_FEATURE_V8) | >> + (1ULL << ARM_FEATURE_NEON) | >> + (1ULL << ARM_FEATURE_AARCH64) | >> + (1ULL << ARM_FEATURE_PMU) | >> + (1ULL << ARM_FEATURE_GENERIC_TIMER); >> + >> + /* We set up a small vcpu to extract host registers */ >> + >> + assert_hvf_ok(hv_vcpu_create(&fd, &exit, NULL)); >> + for (i = 0; i < ARRAY_SIZE(regs); i++) { >> + assert_hvf_ok(hv_vcpu_get_sys_reg(fd, regs[i].reg, regs[i].val)); >> + } >> + assert_hvf_ok(hv_vcpu_get_sys_reg(fd, HV_SYS_REG_MIDR_EL1, &cpu->midr)); >> + assert_hvf_ok(hv_vcpu_destroy(fd)); > Nicer to follow the KVM approach of only doing this once > and caching the results in arm_host_cpu_features, so that > for a many-cores VM you don't do it once per core. I tend to disagree. This scales nicely with the number of cores you have in the system and it's blazingly fast :). I would rather like to optimize for simplicity here. The rest of the comments I agree with and will address them in v7 :) Alex