[PW_SID:1140571] [v3] RISC-V: KVM: Add kvm-riscv.wfi_trap_policy to control VS-mode WFI trapping - #2414
[PW_SID:1140571] [v3] RISC-V: KVM: Add kvm-riscv.wfi_trap_policy to control VS-mode WFI trapping#2414linux-riscv-bot wants to merge 2 commits into
Conversation
…pping
Add a kernel command-line option, kvm-riscv.wfi_trap_policy=trap|auto,
that controls whether a WFI executed by a VS-mode guest traps into KVM
(HS-mode) or executes natively.
HSTATUS.VTW governs VS-mode WFI: when set, the WFI traps into KVM, which
blocks the vCPU through kvm_vcpu_halt() and releases the CPU to other
runnable tasks; when clear, the guest runs WFI natively. Because RISC-V
WFI is only a hint (it may be a no-op on some implementations), the
policy is re-evaluated before each guest entry rather than fixed once
at reset.
trap : always trap VS-mode WFI into KVM (HSTATUS.VTW=1). This is the
default and preserves the previous unconditional behavior.
auto : clear HSTATUS.VTW so the guest runs WFI natively only when the
vCPU is the sole runnable task on the current CPU; otherwise
keep trapping. When the vCPU is alone, skipping the
virtual-instruction exit cannot starve another task, and on
hardware that honors WFI the hart blocks until a VS-mode
interrupt. The policy is re-evaluated before every guest entry,
so when another task becomes runnable the next entry traps
again and KVM blocks the vCPU through kvm_vcpu_halt(), yielding
the CPU. The vCPU therefore never monopolizes the CPU the way
an unconditional native WFI would: it either blocks through
kvm_vcpu_halt(), or runs WFI natively only when no other task
needs the CPU.
Measured on QEMU TCG (-smp 1, -cpu max): wfi_exit_stat delta and guest
wake count over a 3 s window. "busy" adds a CPU-bound competitor that
shares the vCPU's CPU so that single_task_running() reports false:
policy busy exits wakes cpu% note
------ ---- ----- ----- ---- ------------------------
trap off 286 285 6.5 default; no regression
trap on 291 290 101.0 trap is unconditional
auto off 4 287 5.0 sole task: native WFI
auto on 285 284 101.5 competitor -> traps
With "auto", WFI exits drop to ~0 when the vCPU is the only runnable
task, and rise back to the trap level as soon as a competitor appears,
which is the desired dynamic behavior. Host CPU stays low in the
sole-task case; the ~101% in the busy cases is the forked competitor,
not the vCPU.
Assisted-by: YuanSheng:deepseek-v4-pro
Co-developed-by: Quan Zhou <zhouquan@iscas.ac.cn>
Signed-off-by: Quan Zhou <zhouquan@iscas.ac.cn>
Signed-off-by: Yuhang.Chen <yhchen312@gmail.com>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202608051354.KYOXP5po-lkp@intel.com/
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
|
Patch 1: "[v3] RISC-V: KVM: Add kvm-riscv.wfi_trap_policy to control VS-mode WFI trapping" |
|
Patch 1: "[v3] RISC-V: KVM: Add kvm-riscv.wfi_trap_policy to control VS-mode WFI trapping" |
|
Patch 1: "[v3] RISC-V: KVM: Add kvm-riscv.wfi_trap_policy to control VS-mode WFI trapping" |
|
Patch 1: "[v3] RISC-V: KVM: Add kvm-riscv.wfi_trap_policy to control VS-mode WFI trapping" |
|
Patch 1: "[v3] RISC-V: KVM: Add kvm-riscv.wfi_trap_policy to control VS-mode WFI trapping" |
|
Patch 1: "[v3] RISC-V: KVM: Add kvm-riscv.wfi_trap_policy to control VS-mode WFI trapping" |
|
Patch 1: "[v3] RISC-V: KVM: Add kvm-riscv.wfi_trap_policy to control VS-mode WFI trapping" |
|
Patch 1: "[v3] RISC-V: KVM: Add kvm-riscv.wfi_trap_policy to control VS-mode WFI trapping" |
|
Patch 1: "[v3] RISC-V: KVM: Add kvm-riscv.wfi_trap_policy to control VS-mode WFI trapping" |
|
Patch 1: "[v3] RISC-V: KVM: Add kvm-riscv.wfi_trap_policy to control VS-mode WFI trapping" |
|
Patch 1: "[v3] RISC-V: KVM: Add kvm-riscv.wfi_trap_policy to control VS-mode WFI trapping" |
|
Patch 1: "[v3] RISC-V: KVM: Add kvm-riscv.wfi_trap_policy to control VS-mode WFI trapping" |
abf8962 to
9fa746d
Compare
PR for series 1140571 applied to workflow__riscv__fixes
Name: [v3] RISC-V: KVM: Add kvm-riscv.wfi_trap_policy to control VS-mode WFI trapping
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1140571
Version: 3