[PATCH] LoongArch: KVM: Reload one-shot TVAL on migration destination

From: Tao Cui

Date: Tue Jul 14 2026 - 23:29:21 EST


From: Tao Cui <cuitao@xxxxxxxxxx>

kvm_restore_timer() rebuilds the remaining timer countdown from
vcpu->arch.expire, which is host-internal and is not part of the migrated
vCPU state. On the migration destination it is still 0, so for a one-shot
timer that has not expired yet the computed delta is 0 and
write_gcsr_timertick(0) injects the timer interrupt immediately instead of
after the remaining time. The guest observes a premature timer event right
after migration.

The expired one-shot case (TVAL = -1) is already handled earlier, so only
the non-expired one-shot path is affected. When expire has not been set
(i.e. on the destination), reload the remaining countdown from the
migrated TVAL. The regular preempt/resume path on the source, where
expire is valid, is unchanged.

Fixes: a5857b9ff6e0 ("LoongArch: KVM: Implement vcpu timer operations")
Signed-off-by: Tao Cui <cuitao@xxxxxxxxxx>
---
arch/loongarch/kvm/timer.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/arch/loongarch/kvm/timer.c b/arch/loongarch/kvm/timer.c
index 3829f35a4070..57f53d19a00a 100644
--- a/arch/loongarch/kvm/timer.c
+++ b/arch/loongarch/kvm/timer.c
@@ -132,6 +132,14 @@ void kvm_restore_timer(struct kvm_vcpu *vcpu)
* during injecting intr async
*/
kvm_queue_irq(vcpu, INT_TI);
+ } else if (!expire) {
+ /*
+ * One-shot timer on the migration destination: vcpu->arch.expire
+ * is host-internal and is not migrated, so it is still 0 here.
+ * Reload the remaining countdown from the migrated TVAL instead
+ * of firing the timer immediately.
+ */
+ delta = ticks;
}

write_gcsr_timertick(delta);
--
2.43.0