Re: [PATCH] RISC-V: KVM: Add kvm-riscv.wfi_trap_policy to control VS-mode WFI trapping
Anup Patel <[email protected]> Tue, 28 Jul 2026 21:23:49 +0530
| 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 | <CAAhSdy2r8Ei9ESdSJB8McC1T=Atp0yNa2MxEbOWNVRTUM_8YFA@mail.gmail.com> |
On Thu, Jul 9, 2026 at 5:26 PM Yuhang.chen <[email protected]> wrote: > > Add a kernel command-line option, kvm-riscv.wfi_trap_policy=trap|notrap, > that controls whether a WFI executed by a VS-mode guest traps into KVM > (HS-mode) or executes natively. > > Measured results (wfi_exit_stat delta / guest wake count over 3 s): > > policy WFI_EXITS WAKE_CNT > ---------- --------- -------- > default 295 294 (== trap, no regression) > trap 295 294 > notrap 0 298 > > Assisted-by: YuanSheng:deepseek-v4-pro > Co-developed-by: Quan Zhou <[email protected]> > Signed-off-by: Quan Zhou <[email protected]> > Signed-off-by: Yuhang.chen <[email protected]> > --- > .../admin-guide/kernel-parameters.txt | 14 ++++++ > arch/riscv/kvm/vcpu.c | 44 ++++++++++++++++++- > 2 files changed, 57 insertions(+), 1 deletion(-) > > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt > index b5493a7f8f22..ee6603b30033 100644 > --- a/Documentation/admin-guide/kernel-parameters.txt > +++ b/Documentation/admin-guide/kernel-parameters.txt > @@ -3254,6 +3254,20 @@ Kernel parameters > > notrap: clear WFI instruction trap > > + kvm-riscv.wfi_trap_policy= > + [KVM,RISCV] Control when to set the WFI instruction > + trap for KVM VMs. When set, a VS-mode WFI traps into > + KVM and is emulated; when clear, the guest executes > + WFI natively and blocks until a VS-mode interrupt > + (e.g. the sstc timer) is pending. > + > + trap: set WFI instruction trap (HSTATUS.VTW=1) > + > + notrap: clear WFI instruction trap (HSTATUS.VTW=0) > + > + Defaults to trap, preserving the previous > + unconditional behavior. > + 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 ? Regards, Anup _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv