Skip to content

Commit 57f576e

Browse files
committed
RISC-V: KVM: Disable vstimecmp before exiting to user-space
If VS-timer expires when no VCPU running on a host CPU then WFI executed by such host CPU will be effective NOP resulting in no power savings. This is as-per RISC-V Privileged specificaiton which says: "WFI is also required to resume execution for locally enabled interrupts pending at any privilege level, regardless of the global interrupt enable at each privilege level." To address the above issue, vstimecmp CSR must be set to -1UL over here when VCPU is scheduled-out or exits to user space. Reviewed-by: Atish Patra <[email protected]> Tested-by: Atish Patra <[email protected]> Tested-by: Heinrich Schuchardt <[email protected]> Fixes: 8f5cb44 ("RISC-V: KVM: Support sstc extension") Fixes: cea8896 ("RISC-V: KVM: Fix kvm_riscv_vcpu_timer_pending() for Sstc") Reported-by: Heinrich Schuchardt <[email protected]> Closes: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2112578 Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Nutty Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
1 parent d7b8f8e commit 57f576e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

arch/riscv/kvm/vcpu_timer.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,24 @@ void kvm_riscv_vcpu_timer_save(struct kvm_vcpu *vcpu)
345345
/*
346346
* The vstimecmp CSRs are saved by kvm_riscv_vcpu_timer_sync()
347347
* upon every VM exit so no need to save here.
348+
*
349+
* If VS-timer expires when no VCPU running on a host CPU then
350+
* WFI executed by such host CPU will be effective NOP resulting
351+
* in no power savings. This is because as-per RISC-V Privileged
352+
* specificaiton: "WFI is also required to resume execution for
353+
* locally enabled interrupts pending at any privilege level,
354+
* regardless of the global interrupt enable at each privilege
355+
* level."
356+
*
357+
* To address the above issue, vstimecmp CSR must be set to -1UL
358+
* over here when VCPU is scheduled-out or exits to user space.
348359
*/
349360

361+
csr_write(CSR_VSTIMECMP, -1UL);
362+
#if defined(CONFIG_32BIT)
363+
csr_write(CSR_VSTIMECMPH, -1UL);
364+
#endif
365+
350366
/* timer should be enabled for the remaining operations */
351367
if (unlikely(!t->init_done))
352368
return;

0 commit comments

Comments
 (0)