Skip to content

Commit 2c64a98

Browse files
bibo-maogregkh
authored andcommitted
LoongArch: KVM: Move unconditional delay into timer clear scenery
commit 5a873d7 upstream. When timer interrupt arrives in guest kernel, guest kernel clears the timer interrupt and program timer with the next incoming event. During this stage, timer tick is -1 and timer interrupt status is disabled in ESTAT register. KVM hypervisor need write zero with timer tick register and wait timer interrupt injection from HW side, and then clear timer interrupt. So there is 2 cycle delay in KVM hypervisor to emulate such scenery, and the delay is unnecessary if there is no need to clear the timer interrupt. Here move 2 cycle delay into timer clear scenery and add timer ESTAT checking after delay, and set max timer expire value if timer interrupt does not arrive still. Cc: stable@vger.kernel.org Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent de5a6e5 commit 2c64a98

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

arch/loongarch/kvm/timer.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,21 @@ void kvm_restore_timer(struct kvm_vcpu *vcpu)
9696
* and set CSR TVAL with -1
9797
*/
9898
write_gcsr_timertick(0);
99-
__delay(2); /* Wait cycles until timer interrupt injected */
10099

101100
/*
102101
* Writing CSR_TINTCLR_TI to LOONGARCH_CSR_TINTCLR will clear
103102
* timer interrupt, and CSR TVAL keeps unchanged with -1, it
104103
* avoids spurious timer interrupt
105104
*/
106-
if (!(estat & CPU_TIMER))
105+
if (!(estat & CPU_TIMER)) {
106+
__delay(2); /* Wait cycles until timer interrupt injected */
107+
108+
/* Write TVAL with max value if no TI shot */
109+
estat = kvm_read_hw_gcsr(LOONGARCH_CSR_ESTAT);
110+
if (!(estat & CPU_TIMER))
111+
write_gcsr_timertick(CSR_TCFG_VAL);
107112
gcsr_write(CSR_TINTCLR_TI, LOONGARCH_CSR_TINTCLR);
113+
}
108114
return;
109115
}
110116

0 commit comments

Comments
 (0)