On 2025/11/03 19:10, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> target/arm/hvf/hvf.c | 39 +++++++++++++++++++++++++++++++++++++++
> 1 file changed, 39 insertions(+)
>
> diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
> index 268a0bcd8ea..60378075882 100644
> --- a/target/arm/hvf/hvf.c
> +++ b/target/arm/hvf/hvf.c
> @@ -200,6 +200,9 @@ void hvf_arm_init_debug(void)
> #define SYSREG_PMCEID0_EL0 SYSREG(3, 3, 9, 12, 6)
> #define SYSREG_PMCEID1_EL0 SYSREG(3, 3, 9, 12, 7)
> #define SYSREG_PMCCNTR_EL0 SYSREG(3, 3, 9, 13, 0)
> +
> +#define SYSREG_CNTV_CTL_EL0 SYSREG(3, 3, 14, 3, 1)
> +#define SYSREG_CNTV_CVAL_EL0 SYSREG(3, 3, 14, 3, 2)
> #define SYSREG_PMCCFILTR_EL0 SYSREG(3, 3, 14, 15, 7)
>
> #define SYSREG_ICC_AP0R0_EL1 SYSREG(3, 0, 12, 8, 4)
> @@ -2017,13 +2020,49 @@ static int hvf_handle_vmexit(CPUState *cpu, hv_vcpu_exit_t *exit)
> return ret;
> }
>
> +static void hvf_sync_vtimer_pre_exec(CPUState *cpu)
> +{
> + hv_return_t r;
> + uint64_t val;
> + bool b;
> +
> + b = hvf_sysreg_read_cp(cpu, "VTimer", SYSREG_CNTV_CVAL_EL0, &val);
> + assert(b);
> + r = hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CVAL_EL0, val);
> + assert_hvf_ok(r);
> +
> + b = hvf_sysreg_read_cp(cpu, "VTimer", SYSREG_CNTV_CTL_EL0, &val);
> + assert(b);
> + r = hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CTL_EL0, val);
> + assert_hvf_ok(r);
> +}
> +
> +static void hvf_sync_vtimer_post_exec(CPUState *cpu)
> +{
> + hv_return_t r;
> + uint64_t val;
> + bool b;
> +
> + r = hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CVAL_EL0, &val);
> + assert_hvf_ok(r);
> + b = hvf_sysreg_write_cp(cpu, "VTimer", SYSREG_CNTV_CVAL_EL0, val);
> + assert(b);
> +
> + r = hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CTL_EL0, &val);
> + assert_hvf_ok(r);
> + b = hvf_sysreg_write_cp(cpu, "VTimer", SYSREG_CNTV_CTL_EL0, val);
> + assert(b);
> +}
> +
> void hvf_arch_cpu_synchronize_pre_exec(CPUState *cpu)
> {
> + hvf_sync_vtimer_pre_exec(cpu);
Perhaps this should be called from hvf_put_registers(). It will gate the
logic behind the vcpu_dirty flag, and, after all, hvf_put_registers() is
a function for setting registers like what hvf_sync_vtimer_pre_exec() sets.
> flush_cpu_state(cpu);
> }
>
> void hvf_arch_cpu_synchronize_post_exec(CPUState *cpu)
> {
> + hvf_sync_vtimer_post_exec(cpu);
> }
>
> int hvf_arch_vcpu_exec(CPUState *cpu)