Re: [PATCH 11/16] accel/kvm: Consistently return CPU halt state from process_async_events
Paolo Bonzini <[email protected]>
| Newsgroups | org.nongnu.qemu-arm,org.kernel.vger.kvm,org.nongnu.qemu-devel,org.nongnu.qemu-riscv |
|---|---|
| Message-ID | <[email protected]> |
On 8/13/26 20:16, Philippe Mathieu-Daudé wrote:
> When comparing the KVM implementations, RISCV and ARM differ
> from S390x / PPC and LoongArch. The caller expects a non-zero
> value to return pausing execution with the EXCP_HLT exception:
>
> 3427 int kvm_cpu_exec(CPUState *cpu)
> 3428 {
> ...
> 3434 if (kvm_arch_process_async_events(cpu)) {
> 3435 return EXCP_HLT;
> 3436 }
> 3437
> 3438 bql_unlock();
> 3439 cpu_exec_start(cpu);
> 3440
> 3441 /* Inner vCPU loop */
> 3442 do {
> ...
Your patch is correct because, even if cpu_thread_is_idle() sees
cpu->halted == false, the flag could become true during
process_queued_cpu_work() because it releases the BQL.
However, I think the better fix is to remove the return code, and check
cpu->halted in kvm_cpu_exec().
Thanks,
Paolo
> Change ARM and RISC-V to return cs->halted for consistent behavior.
>
> Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
> ---
> target/arm/kvm.c | 2 +-
> target/riscv/kvm/kvm-cpu.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/target/arm/kvm.c b/target/arm/kvm.c
> index d40a6a98591..5caabfab63f 100644
> --- a/target/arm/kvm.c
> +++ b/target/arm/kvm.c
> @@ -1575,7 +1575,7 @@ bool kvm_arch_stop_on_emulation_error(CPUState *cs)
>
> int kvm_arch_process_async_events(CPUState *cs)
> {
> - return 0;
> + return cs->halted;
> }
>
> /**
> diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
> index 97069bf597a..1a61cd5ef37 100644
> --- a/target/riscv/kvm/kvm-cpu.c
> +++ b/target/riscv/kvm/kvm-cpu.c
> @@ -1568,7 +1568,7 @@ int kvm_arch_irqchip_create(KVMState *s)
>
> int kvm_arch_process_async_events(CPUState *cs)
> {
> - return 0;
> + return cs->halted;
> }
>
> void kvm_arch_pre_run(CPUState *cs, struct kvm_run *run)