Skip to content

Commit e306e51

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: KVM: Sync pending interrupt when getting ESTAT from user mode
Currently interrupts are posted and cleared with the asynchronous mode, meanwhile they are saved in SW state vcpu::arch::irq_pending and vcpu:: arch::irq_clear. When vcpu is ready to run, pending interrupt is written back to CSR.ESTAT register from SW state vcpu::arch::irq_pending at the guest entrance. During VM migration stage, vcpu is put into stopped state, however pending interrupts are not synced to CSR.ESTAT register. So there will be interrupt lost when VCPU is migrated to another host machines. Here in this patch when ESTAT CSR register is read from VMM user mode, pending interrupts are synchronized to ESTAT also. So that VMM can get correct pending interrupts. Signed-off-by: Bibo Mao <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 256abd8 commit e306e51

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

arch/loongarch/kvm/vcpu.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,17 @@ static int _kvm_getcsr(struct kvm_vcpu *vcpu, unsigned int id, u64 *val)
354354
return -EINVAL;
355355

356356
if (id == LOONGARCH_CSR_ESTAT) {
357+
preempt_disable();
358+
vcpu_load(vcpu);
359+
/*
360+
* Sync pending interrupts into ESTAT so that interrupt
361+
* remains during VM migration stage
362+
*/
363+
kvm_deliver_intr(vcpu);
364+
vcpu->arch.aux_inuse &= ~KVM_LARCH_SWCSR_LATEST;
365+
vcpu_put(vcpu);
366+
preempt_enable();
367+
357368
/* ESTAT IP0~IP7 get from GINTC */
358369
gintc = kvm_read_sw_gcsr(csr, LOONGARCH_CSR_GINTC) & 0xff;
359370
*val = kvm_read_sw_gcsr(csr, LOONGARCH_CSR_ESTAT) | (gintc << 2);

0 commit comments

Comments
 (0)