Re: [PATCH] RISC-V: KVM: Add kvm-riscv.wfi_trap_policy to control VS-mode WFI trapping
"Yuhang.Chen" <[email protected]> Tue, 4 Aug 2026 10:48:22 +0800
| Newsgroups | org.infradead.lists.linux-riscv,org.infradead.lists.kvm-riscv,org.kernel.vger.kvm,org.kernel.vger.linux-doc,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
Hi Anup, Thanks for the review. On Tue, 28 Jul 2026, Anup Patel <[email protected]> wrote: > This would mean that for the "notrap" policy the VCPU would never > sleep and increase host CPU utilization even when VCPU is idle. > Is this expected behaviour ? No, that was not intended. With "notrap", HSTATUS.VTW is cleared unconditionally, so a VS-mode WFI never traps and the vCPU never reaches kvm_vcpu_halt(); since WFI is only a hint, the vCPU thread can keep spinning even while the guest is idle - the high host CPU you point out. v2 drops "notrap" and replaces it with "auto": HSTATUS.VTW is cleared only when the vCPU is the sole runnable task on its CPU (single_task_running()), otherwise WFI traps and KVM blocks the vCPU through kvm_vcpu_halt() as before. The default stays "trap", so there is no regression, and the policy is re-evaluated on each vcpu_load() so a vCPU that stops being the sole runnable task switches back to trapping. So to answer your question: the vCPU no longer stays busy at the expense of other tasks - it either blocks through kvm_vcpu_halt(), or runs WFI natively only when nothing else needs the CPU. On QEMU TCG, host CPU stays around 5% while the vCPU is the sole task and rises back to the trap level as soon as a competitor appears. I have posted v2 as a new thread: [PATCH v2] RISC-V: KVM: Add kvm-riscv.wfi_trap_policy to control VS-mode WFI trapping Regards, Yuhang _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv