* Re: [PATCH v5 2/2] target/arm/hvf: Sync CNTV_CTL_EL0 & CNTV_CVAL_EL0
2026-01-18 21:59 ` [PATCH v5 2/2] target/arm/hvf: Sync CNTV_CTL_EL0 & CNTV_CVAL_EL0 Philippe Mathieu-Daudé
@ 2026-02-12 15:05 ` Zenghui Yu
2026-02-17 21:36 ` Philippe Mathieu-Daudé
2026-02-15 10:15 ` Mohamed Mediouni
2026-02-23 13:47 ` Lucas Kornicki
2 siblings, 1 reply; 12+ messages in thread
From: Zenghui Yu @ 2026-02-12 15:05 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: qemu-devel, Mohamed Mediouni, qemu-arm, Peter Maydell,
Alexander Graf, Cameron Esfahani, Mads Ynddal, Akihiko Odaki
Hi,
On 1/19/26 5:59 AM, Philippe Mathieu-Daudé wrote:
> Keep CNTV_CTL_EL0 and CNTV_CVAL_EL0 synchronized with the
> host hardware accelerator.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> target/arm/hvf/hvf.c | 25 +++++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
> index fcb7fa3b30c..9ce720793d8 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)
> @@ -502,6 +505,7 @@ int hvf_arch_get_registers(CPUState *cpu)
> uint64_t val;
> hv_simd_fp_uchar16_t fpval;
> int i, n;
> + bool b;
>
> for (i = 0; i < ARRAY_SIZE(hvf_reg_match); i++) {
> ret = hv_vcpu_get_reg(cpu->accel->fd, hvf_reg_match[i].reg, &val);
> @@ -631,6 +635,16 @@ int hvf_arch_get_registers(CPUState *cpu)
>
> aarch64_restore_sp(env, arm_current_el(env));
>
> + ret = hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CVAL_EL0, &val);
> + assert_hvf_ok(ret);
> + b = hvf_sysreg_write_cp(cpu, "VTimer", SYSREG_CNTV_CVAL_EL0, val);
> + assert(b);
> +
> + ret = hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CTL_EL0, &val);
> + assert_hvf_ok(ret);
> + b = hvf_sysreg_write_cp(cpu, "VTimer", SYSREG_CNTV_CTL_EL0, val);
> + assert(b);
> +
> return 0;
> }
>
> @@ -642,6 +656,7 @@ int hvf_arch_put_registers(CPUState *cpu)
> uint64_t val;
> hv_simd_fp_uchar16_t fpval;
> int i, n;
> + bool b;
>
> for (i = 0; i < ARRAY_SIZE(hvf_reg_match); i++) {
> val = *(uint64_t *)((void *)env + hvf_reg_match[i].offset);
> @@ -756,6 +771,16 @@ int hvf_arch_put_registers(CPUState *cpu)
> ret = hv_vcpu_set_vtimer_offset(cpu->accel->fd, hvf_state->vtimer_offset);
> assert_hvf_ok(ret);
>
> + b = hvf_sysreg_read_cp(cpu, "VTimer", SYSREG_CNTV_CVAL_EL0, &val);
> + assert(b);
> + ret = hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CVAL_EL0, val);
> + assert_hvf_ok(ret);
> +
> + b = hvf_sysreg_read_cp(cpu, "VTimer", SYSREG_CNTV_CTL_EL0, &val);
> + assert(b);
> + ret = hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CTL_EL0, val);
> + assert_hvf_ok(ret);
> +
> return 0;
> }
My Linux guest has been unable to start since this patch. I tested it on
M1 (macOS Tahoe 26.2). Not sure if this can be reproduced on your side.
Thanks,
Zenghui
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v5 2/2] target/arm/hvf: Sync CNTV_CTL_EL0 & CNTV_CVAL_EL0
2026-02-12 15:05 ` Zenghui Yu
@ 2026-02-17 21:36 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-02-17 21:36 UTC (permalink / raw)
To: Zenghui Yu
Cc: qemu-devel, Mohamed Mediouni, qemu-arm, Peter Maydell,
Alexander Graf, Cameron Esfahani, Mads Ynddal, Akihiko Odaki
Hi,
On 12/2/26 16:05, Zenghui Yu wrote:
> Hi,
>
> On 1/19/26 5:59 AM, Philippe Mathieu-Daudé wrote:
>> Keep CNTV_CTL_EL0 and CNTV_CVAL_EL0 synchronized with the
>> host hardware accelerator.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>> target/arm/hvf/hvf.c | 25 +++++++++++++++++++++++++
>> 1 file changed, 25 insertions(+)
> My Linux guest has been unable to start since this patch. I tested it on
> M1 (macOS Tahoe 26.2). Not sure if this can be reproduced on your side.
I apologize for this (it was tested on 15.7). I don't have spare time
(nor hardware) to look at this right now, so better to revert, as
suggested by Mohamed.
Regards,
Phil.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v5 2/2] target/arm/hvf: Sync CNTV_CTL_EL0 & CNTV_CVAL_EL0
2026-01-18 21:59 ` [PATCH v5 2/2] target/arm/hvf: Sync CNTV_CTL_EL0 & CNTV_CVAL_EL0 Philippe Mathieu-Daudé
2026-02-12 15:05 ` Zenghui Yu
@ 2026-02-15 10:15 ` Mohamed Mediouni
2026-02-17 21:37 ` Philippe Mathieu-Daudé
2026-02-23 13:47 ` Lucas Kornicki
2 siblings, 1 reply; 12+ messages in thread
From: Mohamed Mediouni @ 2026-02-15 10:15 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: qemu-devel, qemu-arm, Peter Maydell, Alexander Graf,
Cameron Esfahani, Mads Ynddal, Akihiko Odaki
> On 18. Jan 2026, at 22:59, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> Keep CNTV_CTL_EL0 and CNTV_CVAL_EL0 synchronized with the
> host hardware accelerator.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> target/arm/hvf/hvf.c | 25 +++++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
Hello,
This broke VM save/restore on my setup. Will have a commit to revert this in my next revision
of the HVF nested virt series.
Thanks,
-Mohamed
>
> diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
> index fcb7fa3b30c..9ce720793d8 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)
> @@ -502,6 +505,7 @@ int hvf_arch_get_registers(CPUState *cpu)
> uint64_t val;
> hv_simd_fp_uchar16_t fpval;
> int i, n;
> + bool b;
>
> for (i = 0; i < ARRAY_SIZE(hvf_reg_match); i++) {
> ret = hv_vcpu_get_reg(cpu->accel->fd, hvf_reg_match[i].reg, &val);
> @@ -631,6 +635,16 @@ int hvf_arch_get_registers(CPUState *cpu)
>
> aarch64_restore_sp(env, arm_current_el(env));
>
> + ret = hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CVAL_EL0, &val);
> + assert_hvf_ok(ret);
> + b = hvf_sysreg_write_cp(cpu, "VTimer", SYSREG_CNTV_CVAL_EL0, val);
> + assert(b);
> +
> + ret = hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CTL_EL0, &val);
> + assert_hvf_ok(ret);
> + b = hvf_sysreg_write_cp(cpu, "VTimer", SYSREG_CNTV_CTL_EL0, val);
> + assert(b);
> +
> return 0;
> }
>
> @@ -642,6 +656,7 @@ int hvf_arch_put_registers(CPUState *cpu)
> uint64_t val;
> hv_simd_fp_uchar16_t fpval;
> int i, n;
> + bool b;
>
> for (i = 0; i < ARRAY_SIZE(hvf_reg_match); i++) {
> val = *(uint64_t *)((void *)env + hvf_reg_match[i].offset);
> @@ -756,6 +771,16 @@ int hvf_arch_put_registers(CPUState *cpu)
> ret = hv_vcpu_set_vtimer_offset(cpu->accel->fd, hvf_state->vtimer_offset);
> assert_hvf_ok(ret);
>
> + b = hvf_sysreg_read_cp(cpu, "VTimer", SYSREG_CNTV_CVAL_EL0, &val);
> + assert(b);
> + ret = hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CVAL_EL0, val);
> + assert_hvf_ok(ret);
> +
> + b = hvf_sysreg_read_cp(cpu, "VTimer", SYSREG_CNTV_CTL_EL0, &val);
> + assert(b);
> + ret = hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CTL_EL0, val);
> + assert_hvf_ok(ret);
> +
> return 0;
> }
>
> --
> 2.52.0
>
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v5 2/2] target/arm/hvf: Sync CNTV_CTL_EL0 & CNTV_CVAL_EL0
2026-02-15 10:15 ` Mohamed Mediouni
@ 2026-02-17 21:37 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-02-17 21:37 UTC (permalink / raw)
To: Mohamed Mediouni
Cc: qemu-devel, qemu-arm, Peter Maydell, Alexander Graf,
Cameron Esfahani, Mads Ynddal, Akihiko Odaki
On 15/2/26 11:15, Mohamed Mediouni wrote:
>
>
>> On 18. Jan 2026, at 22:59, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>>
>> Keep CNTV_CTL_EL0 and CNTV_CVAL_EL0 synchronized with the
>> host hardware accelerator.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>> target/arm/hvf/hvf.c | 25 +++++++++++++++++++++++++
>> 1 file changed, 25 insertions(+)
> Hello,
>
> This broke VM save/restore on my setup. Will have a commit to revert this in my next revision
> of the HVF nested virt series.
LGTM, thanks for taking care of it Mohamed!
>
> Thanks,
> -Mohamed
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v5 2/2] target/arm/hvf: Sync CNTV_CTL_EL0 & CNTV_CVAL_EL0
2026-01-18 21:59 ` [PATCH v5 2/2] target/arm/hvf: Sync CNTV_CTL_EL0 & CNTV_CVAL_EL0 Philippe Mathieu-Daudé
2026-02-12 15:05 ` Zenghui Yu
2026-02-15 10:15 ` Mohamed Mediouni
@ 2026-02-23 13:47 ` Lucas Kornicki
2026-03-02 12:18 ` Zenghui Yu
2 siblings, 1 reply; 12+ messages in thread
From: Lucas Kornicki @ 2026-02-23 13:47 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Mohamed Mediouni, qemu-arm, Peter Maydell, Alexander Graf,
Cameron Esfahani, Mads Ynddal, Akihiko Odaki
[-- Attachment #1: Type: text/plain, Size: 3245 bytes --]
Hi. I've found this patch to break EDK2 UEFI on MacOS 15.7
With it applied, the vm is usually stuck on display not initialized, but
sometimes it will init and hang on the tianocore logo.
I've narrowed it down to
b = hvf_sysreg_write_cp(cpu, "VTimer", SYSREG_CNTV_CVAL_EL0, val);
in hvf_arch_get_registers.
On a related note, I've noticed that when using accel=hvf on aarch64,
the cpu usage is maxing out all assigned cores even if the guest is
idle. It looks like it's constantly getting woken up from WFI. Could
this patch be part of the solution?
On 1/18/26 22:59, Philippe Mathieu-Daudé wrote:
> Keep CNTV_CTL_EL0 and CNTV_CVAL_EL0 synchronized with the
> host hardware accelerator.
>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
> target/arm/hvf/hvf.c | 25 +++++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
> index fcb7fa3b30c..9ce720793d8 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)
> @@ -502,6 +505,7 @@ int hvf_arch_get_registers(CPUState *cpu)
> uint64_t val;
> hv_simd_fp_uchar16_t fpval;
> int i, n;
> + bool b;
>
> for (i = 0; i < ARRAY_SIZE(hvf_reg_match); i++) {
> ret = hv_vcpu_get_reg(cpu->accel->fd, hvf_reg_match[i].reg, &val);
> @@ -631,6 +635,16 @@ int hvf_arch_get_registers(CPUState *cpu)
>
> aarch64_restore_sp(env, arm_current_el(env));
>
> + ret = hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CVAL_EL0, &val);
> + assert_hvf_ok(ret);
> + b = hvf_sysreg_write_cp(cpu, "VTimer", SYSREG_CNTV_CVAL_EL0, val);
> + assert(b);
> +
> + ret = hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CTL_EL0, &val);
> + assert_hvf_ok(ret);
> + b = hvf_sysreg_write_cp(cpu, "VTimer", SYSREG_CNTV_CTL_EL0, val);
> + assert(b);
> +
> return 0;
> }
>
> @@ -642,6 +656,7 @@ int hvf_arch_put_registers(CPUState *cpu)
> uint64_t val;
> hv_simd_fp_uchar16_t fpval;
> int i, n;
> + bool b;
>
> for (i = 0; i < ARRAY_SIZE(hvf_reg_match); i++) {
> val = *(uint64_t *)((void *)env + hvf_reg_match[i].offset);
> @@ -756,6 +771,16 @@ int hvf_arch_put_registers(CPUState *cpu)
> ret = hv_vcpu_set_vtimer_offset(cpu->accel->fd, hvf_state->vtimer_offset);
> assert_hvf_ok(ret);
>
> + b = hvf_sysreg_read_cp(cpu, "VTimer", SYSREG_CNTV_CVAL_EL0, &val);
> + assert(b);
> + ret = hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CVAL_EL0, val);
> + assert_hvf_ok(ret);
> +
> + b = hvf_sysreg_read_cp(cpu, "VTimer", SYSREG_CNTV_CTL_EL0, &val);
> + assert(b);
> + ret = hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CTL_EL0, val);
> + assert_hvf_ok(ret);
> +
> return 0;
> }
>
[-- Attachment #2: Type: text/html, Size: 3860 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v5 2/2] target/arm/hvf: Sync CNTV_CTL_EL0 & CNTV_CVAL_EL0
2026-02-23 13:47 ` Lucas Kornicki
@ 2026-03-02 12:18 ` Zenghui Yu
0 siblings, 0 replies; 12+ messages in thread
From: Zenghui Yu @ 2026-03-02 12:18 UTC (permalink / raw)
To: Lucas Kornicki
Cc: Philippe Mathieu-Daudé, qemu-devel, Mohamed Mediouni,
qemu-arm, Peter Maydell, Alexander Graf, Cameron Esfahani,
Mads Ynddal, Akihiko Odaki
Hi,
On 2/23/26 9:47 PM, Lucas Kornicki wrote:
> Hi. I've found this patch to break EDK2 UEFI on MacOS 15.7
> With it applied, the vm is usually stuck on display not initialized, but
> sometimes it will init and hang on the tianocore logo.
> I've narrowed it down to
>
> b = hvf_sysreg_write_cp(cpu, "VTimer", SYSREG_CNTV_CVAL_EL0, val);
>
> in hvf_arch_get_registers.
It was fixed by a revert. See commit 28b0ed32b32c in master.
>
> On a related note, I've noticed that when using accel=hvf on aarch64,
> the cpu usage is maxing out all assigned cores even if the guest is
> idle. It looks like it's constantly getting woken up from WFI. Could
> this patch be part of the solution?
This is another issue which I had also reported in [*]. It looks to me
that commit b5f8f7727177 has made the WFI handling "an immediate
re-entering in guest" which results in the high CPU utilization.
Before someone familiar with the code acknowledges it, I just reverted
b5f8f7727177 locally for power saving. ;-)
[*]
https://lore.kernel.org/qemu-devel/92a63a78-2ab8-481a-8b78-3a86fa130fe8@linux.dev
Thanks,
Zenghui
^ permalink raw reply [flat|nested] 12+ messages in thread