* [PATCH] KVM: riscv: Avoid redundant interrupt check for pending timers
@ 2026-08-14 12:35 Jinyu Tang
2026-08-25 9:58 ` Nutty.Liu
2026-10-03 9:19 ` Anup Patel
0 siblings, 2 replies; 3+ messages in thread
From: Jinyu Tang @ 2026-08-14 12:35 UTC (permalink / raw)
To: Anup Patel, Anup Patel, Atish Patra
Cc: kvm, kvm-riscv, linux-riscv, linux-kernel, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Nutty Liu, Jinyu Tang,
Jinyu Tang
kvm_vcpu_check_block() calls kvm_arch_vcpu_runnable() before
checking whether a timer is pending. On RISC-V, kvm_arch_vcpu_runnable()
already checks all pending guest interrupts through
kvm_riscv_vcpu_has_interrupts(vcpu, -1UL), including IRQ_VS_TIMER.
Drop the repeated IRQ_VS_TIMER pending-interrupt check from
kvm_riscv_vcpu_timer_pending() and keep the helper focused on the timer
deadline state. If the timer becomes pending after the runnable check,
the timer path still injects IRQ_VS_TIMER and kicks the vCPU through the
normal wakeup path.
Signed-off-by: Jinyu Tang <jinyu.tang@linux.dev>
---
arch/riscv/kvm/vcpu_timer.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/arch/riscv/kvm/vcpu_timer.c b/arch/riscv/kvm/vcpu_timer.c
index ae53133c7ab0..0e01bd793772 100644
--- a/arch/riscv/kvm/vcpu_timer.c
+++ b/arch/riscv/kvm/vcpu_timer.c
@@ -132,11 +132,7 @@ bool kvm_riscv_vcpu_timer_pending(struct kvm_vcpu *vcpu)
struct kvm_vcpu_timer *t = &vcpu->arch.timer;
struct kvm_guest_timer *gt = &vcpu->kvm->arch.timer;
- if (!kvm_riscv_delta_cycles2ns(t->next_cycles, gt, t) ||
- kvm_riscv_vcpu_has_interrupts(vcpu, 1UL << IRQ_VS_TIMER))
- return true;
- else
- return false;
+ return !kvm_riscv_delta_cycles2ns(t->next_cycles, gt, t);
}
static void kvm_riscv_vcpu_timer_blocking(struct kvm_vcpu *vcpu)
--
2.43.0
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: riscv: Avoid redundant interrupt check for pending timers
2026-08-14 12:35 [PATCH] KVM: riscv: Avoid redundant interrupt check for pending timers Jinyu Tang
@ 2026-08-25 9:58 ` Nutty.Liu
2026-10-03 9:19 ` Anup Patel
1 sibling, 0 replies; 3+ messages in thread
From: Nutty.Liu @ 2026-08-25 9:58 UTC (permalink / raw)
To: Jinyu Tang, Anup Patel, Anup Patel, Atish Patra
Cc: kvm, kvm-riscv, linux-riscv, linux-kernel, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Alexandre Ghiti, Jinyu Tang
On 8/14/2026 8:35 PM, Jinyu Tang wrote:
> kvm_vcpu_check_block() calls kvm_arch_vcpu_runnable() before
> checking whether a timer is pending. On RISC-V, kvm_arch_vcpu_runnable()
> already checks all pending guest interrupts through
> kvm_riscv_vcpu_has_interrupts(vcpu, -1UL), including IRQ_VS_TIMER.
>
> Drop the repeated IRQ_VS_TIMER pending-interrupt check from
> kvm_riscv_vcpu_timer_pending() and keep the helper focused on the timer
> deadline state. If the timer becomes pending after the runnable check,
> the timer path still injects IRQ_VS_TIMER and kicks the vCPU through the
> normal wakeup path.
>
> Signed-off-by: Jinyu Tang <jinyu.tang@linux.dev>
Reviewed-by: Nutty Liu <nutty.liu@hotmail.com>
Thanks,
Nutty
> ---
> arch/riscv/kvm/vcpu_timer.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/arch/riscv/kvm/vcpu_timer.c b/arch/riscv/kvm/vcpu_timer.c
> index ae53133c7ab0..0e01bd793772 100644
> --- a/arch/riscv/kvm/vcpu_timer.c
> +++ b/arch/riscv/kvm/vcpu_timer.c
> @@ -132,11 +132,7 @@ bool kvm_riscv_vcpu_timer_pending(struct kvm_vcpu *vcpu)
> struct kvm_vcpu_timer *t = &vcpu->arch.timer;
> struct kvm_guest_timer *gt = &vcpu->kvm->arch.timer;
>
> - if (!kvm_riscv_delta_cycles2ns(t->next_cycles, gt, t) ||
> - kvm_riscv_vcpu_has_interrupts(vcpu, 1UL << IRQ_VS_TIMER))
> - return true;
> - else
> - return false;
> + return !kvm_riscv_delta_cycles2ns(t->next_cycles, gt, t);
> }
>
> static void kvm_riscv_vcpu_timer_blocking(struct kvm_vcpu *vcpu)
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: riscv: Avoid redundant interrupt check for pending timers
2026-08-14 12:35 [PATCH] KVM: riscv: Avoid redundant interrupt check for pending timers Jinyu Tang
2026-08-25 9:58 ` Nutty.Liu
@ 2026-10-03 9:19 ` Anup Patel
1 sibling, 0 replies; 3+ messages in thread
From: Anup Patel @ 2026-10-03 9:19 UTC (permalink / raw)
To: Jinyu Tang
Cc: Anup Patel, Atish Patra, kvm, kvm-riscv, linux-riscv,
linux-kernel, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, Nutty Liu, Jinyu Tang
On Fri, Aug 14, 2026 at 6:06 PM Jinyu Tang <jinyu.tang@linux.dev> wrote:
>
> kvm_vcpu_check_block() calls kvm_arch_vcpu_runnable() before
> checking whether a timer is pending. On RISC-V, kvm_arch_vcpu_runnable()
> already checks all pending guest interrupts through
> kvm_riscv_vcpu_has_interrupts(vcpu, -1UL), including IRQ_VS_TIMER.
>
> Drop the repeated IRQ_VS_TIMER pending-interrupt check from
> kvm_riscv_vcpu_timer_pending() and keep the helper focused on the timer
> deadline state. If the timer becomes pending after the runnable check,
> the timer path still injects IRQ_VS_TIMER and kicks the vCPU through the
> normal wakeup path.
>
> Signed-off-by: Jinyu Tang <jinyu.tang@linux.dev>
LGTM.
Reviewed-by: Anup Patel <anup@brainfault.org>
Queued this patch for Linux-7.4
Thanks,
Anup
> ---
> arch/riscv/kvm/vcpu_timer.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/arch/riscv/kvm/vcpu_timer.c b/arch/riscv/kvm/vcpu_timer.c
> index ae53133c7ab0..0e01bd793772 100644
> --- a/arch/riscv/kvm/vcpu_timer.c
> +++ b/arch/riscv/kvm/vcpu_timer.c
> @@ -132,11 +132,7 @@ bool kvm_riscv_vcpu_timer_pending(struct kvm_vcpu *vcpu)
> struct kvm_vcpu_timer *t = &vcpu->arch.timer;
> struct kvm_guest_timer *gt = &vcpu->kvm->arch.timer;
>
> - if (!kvm_riscv_delta_cycles2ns(t->next_cycles, gt, t) ||
> - kvm_riscv_vcpu_has_interrupts(vcpu, 1UL << IRQ_VS_TIMER))
> - return true;
> - else
> - return false;
> + return !kvm_riscv_delta_cycles2ns(t->next_cycles, gt, t);
> }
>
> static void kvm_riscv_vcpu_timer_blocking(struct kvm_vcpu *vcpu)
> --
> 2.43.0
>
--
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-03 9:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-14 12:35 [PATCH] KVM: riscv: Avoid redundant interrupt check for pending timers Jinyu Tang
2026-08-25 9:58 ` Nutty.Liu
2026-10-03 9:19 ` Anup Patel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox