Skip to content

Commit c2f94da

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: KVM: Check VM msgint feature during interrupt handling
During message interrupt handling and relative CSR registers saving and restore, it is better to check VM msgint feature rather than host msgint feature, because VM may disable this feature even if host supports this. Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 31966ed commit c2f94da

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

arch/loongarch/include/asm/kvm_host.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ static inline void writel_sw_gcsr(struct loongarch_csrs *csr, int reg, unsigned
265265
csr->csrs[reg] = val;
266266
}
267267

268+
static inline bool kvm_guest_has_msgint(struct kvm_vcpu_arch *arch)
269+
{
270+
return arch->cpucfg[1] & CPUCFG1_MSGINT;
271+
}
272+
268273
static inline bool kvm_guest_has_fpu(struct kvm_vcpu_arch *arch)
269274
{
270275
return arch->cpucfg[2] & CPUCFG2_FP;

arch/loongarch/kvm/interrupt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static int kvm_irq_deliver(struct kvm_vcpu *vcpu, unsigned int priority)
3232
if (priority < EXCCODE_INT_NUM)
3333
irq = priority_to_irq[priority];
3434

35-
if (cpu_has_msgint && (priority == INT_AVEC)) {
35+
if (kvm_guest_has_msgint(&vcpu->arch) && (priority == INT_AVEC)) {
3636
set_gcsr_estat(irq);
3737
return 1;
3838
}
@@ -64,7 +64,7 @@ static int kvm_irq_clear(struct kvm_vcpu *vcpu, unsigned int priority)
6464
if (priority < EXCCODE_INT_NUM)
6565
irq = priority_to_irq[priority];
6666

67-
if (cpu_has_msgint && (priority == INT_AVEC)) {
67+
if (kvm_guest_has_msgint(&vcpu->arch) && (priority == INT_AVEC)) {
6868
clear_gcsr_estat(irq);
6969
return 1;
7070
}

arch/loongarch/kvm/vcpu.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,7 +1679,8 @@ static int _kvm_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
16791679
kvm_restore_hw_gcsr(csr, LOONGARCH_CSR_DMWIN2);
16801680
kvm_restore_hw_gcsr(csr, LOONGARCH_CSR_DMWIN3);
16811681
kvm_restore_hw_gcsr(csr, LOONGARCH_CSR_LLBCTL);
1682-
if (cpu_has_msgint) {
1682+
1683+
if (kvm_guest_has_msgint(&vcpu->arch)) {
16831684
kvm_restore_hw_gcsr(csr, LOONGARCH_CSR_ISR0);
16841685
kvm_restore_hw_gcsr(csr, LOONGARCH_CSR_ISR1);
16851686
kvm_restore_hw_gcsr(csr, LOONGARCH_CSR_ISR2);
@@ -1774,7 +1775,8 @@ static int _kvm_vcpu_put(struct kvm_vcpu *vcpu, int cpu)
17741775
kvm_save_hw_gcsr(csr, LOONGARCH_CSR_DMWIN1);
17751776
kvm_save_hw_gcsr(csr, LOONGARCH_CSR_DMWIN2);
17761777
kvm_save_hw_gcsr(csr, LOONGARCH_CSR_DMWIN3);
1777-
if (cpu_has_msgint) {
1778+
1779+
if (kvm_guest_has_msgint(&vcpu->arch)) {
17781780
kvm_save_hw_gcsr(csr, LOONGARCH_CSR_ISR0);
17791781
kvm_save_hw_gcsr(csr, LOONGARCH_CSR_ISR1);
17801782
kvm_save_hw_gcsr(csr, LOONGARCH_CSR_ISR2);

0 commit comments

Comments
 (0)