Skip to content

Commit b715ceb

Browse files
bibo-maogregkh
authored andcommitted
LoongArch: KVM: Fix HW timer interrupt lost when inject interrupt by software
commit 2433f3f upstream. With passthrough HW timer, timer interrupt is injected by HW. When inject emulated CPU interrupt by software such SIP0/SIP1/IPI, HW timer interrupt may be lost. Here check whether there is timer tick value inversion before and after injecting emulated CPU interrupt by software, timer enabling by reading timer cfg register is skipped. If the timer tick value is detected with changing, then timer should be enabled. And inject a timer interrupt by software if there is. Cc: <stable@vger.kernel.org> Fixes: f45ad5b ("LoongArch: KVM: Implement vcpu interrupt operations"). 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 1c32824 commit b715ceb

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

arch/loongarch/kvm/interrupt.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static unsigned int priority_to_irq[EXCCODE_INT_NUM] = {
2626
static int kvm_irq_deliver(struct kvm_vcpu *vcpu, unsigned int priority)
2727
{
2828
unsigned int irq = 0;
29+
unsigned long old, new;
2930

3031
clear_bit(priority, &vcpu->arch.irq_pending);
3132
if (priority < EXCCODE_INT_NUM)
@@ -36,7 +37,13 @@ static int kvm_irq_deliver(struct kvm_vcpu *vcpu, unsigned int priority)
3637
case INT_IPI:
3738
case INT_SWI0:
3839
case INT_SWI1:
40+
old = kvm_read_hw_gcsr(LOONGARCH_CSR_TVAL);
3941
set_gcsr_estat(irq);
42+
new = kvm_read_hw_gcsr(LOONGARCH_CSR_TVAL);
43+
44+
/* Inject TI if TVAL inverted */
45+
if (new > old)
46+
set_gcsr_estat(CPU_TIMER);
4047
break;
4148

4249
case INT_HWI0 ... INT_HWI7:
@@ -53,6 +60,7 @@ static int kvm_irq_deliver(struct kvm_vcpu *vcpu, unsigned int priority)
5360
static int kvm_irq_clear(struct kvm_vcpu *vcpu, unsigned int priority)
5461
{
5562
unsigned int irq = 0;
63+
unsigned long old, new;
5664

5765
clear_bit(priority, &vcpu->arch.irq_clear);
5866
if (priority < EXCCODE_INT_NUM)
@@ -63,7 +71,13 @@ static int kvm_irq_clear(struct kvm_vcpu *vcpu, unsigned int priority)
6371
case INT_IPI:
6472
case INT_SWI0:
6573
case INT_SWI1:
74+
old = kvm_read_hw_gcsr(LOONGARCH_CSR_TVAL);
6675
clear_gcsr_estat(irq);
76+
new = kvm_read_hw_gcsr(LOONGARCH_CSR_TVAL);
77+
78+
/* Inject TI if TVAL inverted */
79+
if (new > old)
80+
set_gcsr_estat(CPU_TIMER);
6781
break;
6882

6983
case INT_HWI0 ... INT_HWI7:

0 commit comments

Comments
 (0)