Skip to content

Commit 7b97357

Browse files
bibo-maoopsiff
authored andcommitted
LoongArch: KVM: Add delay until timer interrupt injected
commit d3c9515 upstream. When timer is fired in oneshot mode, CSR.TVAL will stop with value -1 rather than 0. However when the register CSR.TVAL is restored, it will continue to count down rather than stop there. Now the method is to write 0 to CSR.TVAL, wait to count down for 1 cycle at least, which is 10ns with a timer freq 100MHz, and then retore timer interrupt status. Here add 2 cycles delay to assure that timer interrupt is injected. With this patch, timer selftest case passes to run always. 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> (cherry picked from commit 4d9b0ea62972ecef25442c69a9404947351bc3bd) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent ef0d606 commit 7b97357

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

arch/loongarch/kvm/timer.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include <linux/kvm_host.h>
7+
#include <asm/delay.h>
78
#include <asm/kvm_csr.h>
89
#include <asm/kvm_vcpu.h>
910

@@ -95,6 +96,7 @@ void kvm_restore_timer(struct kvm_vcpu *vcpu)
9596
* and set CSR TVAL with -1
9697
*/
9798
write_gcsr_timertick(0);
99+
__delay(2); /* Wait cycles until timer interrupt injected */
98100

99101
/*
100102
* Writing CSR_TINTCLR_TI to LOONGARCH_CSR_TINTCLR will clear

0 commit comments

Comments
 (0)