Re: [PATCH 14/16] target/i386/hvf: Lock BQL outside of the vCPU inner execution loop

Paolo Bonzini <[email protected]>
Newsgroups org.nongnu.qemu-riscv,org.kernel.vger.kvm,org.nongnu.qemu-arm,org.nongnu.qemu-devel
Message-ID <[email protected]>
On 8/13/26 20:16, Philippe Mathieu-Daudé wrote:
> Reduce lock contention by acquiring / releasing the BQL
> outside of the entire vCPU inner loop.
> 
> Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
> ---
>   target/i386/hvf/hvf.c | 19 +++++++++++--------
>   1 file changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
> index 0ffa3658dc5..f8bc01d38d3 100644
> --- a/target/i386/hvf/hvf.c
> +++ b/target/i386/hvf/hvf.c
> @@ -1009,6 +1009,9 @@ int hvf_arch_vcpu_exec(CPUState *cpu)
>           return EXCP_HLT;
>       }
>   
> +    bql_unlock();
> +    cpu_exec_start(cpu);
> +
>       /* Inner vCPU loop */
>       do {
>           if (cpu->vcpu_dirty) {
> @@ -1017,26 +1020,26 @@ int hvf_arch_vcpu_exec(CPUState *cpu)
>           }
>   
>           if (hvf_inject_interrupts(cpu)) {

Nope, hvf_inject_interrupts() calls cpu_get_pic_interrupt() which needs 
the BQL.

Paolo

> -            return EXCP_INTERRUPT;
> +            ret = EXCP_INTERRUPT;
> +            break;
>           }
> +
>           vmx_update_tpr(cpu);
>   
> -        bql_unlock();
>           if (!cpu_is_bsp(X86_CPU(cpu)) && cpu->halted) {

This is also incorrect by the way - chceking cpu->halted needs the BQL. 
So bql_unlock() must be moved right before cpu_exec_start().  Can you 
fix it?

Thanks,

Paolo

> -            bql_lock();
> -            return EXCP_HLT;
> +            ret = EXCP_HLT;
> +            break;
>           }
>   
> -        cpu_exec_start(cpu);
> -
>           hv_return_t r = hv_vcpu_run_until(cpu->accel->fd, HV_DEADLINE_FOREVER);
>           assert_hvf_ok(r);
>   
> -        cpu_exec_end(cpu);
> -
>           ret = hvf_handle_vmexit(cpu);
>       } while (ret == 0);
>   
> +    cpu_exec_end(cpu);
> +    bql_lock();
> +
>       return ret;
>   }
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.