Skip to content

Commit 45515c6

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: KVM: Check interrupt route from physical CPU
With EIOINTC interrupt controller, physical CPU ID is set for irq route. However the function kvm_get_vcpu() is used to get destination vCPU when delivering irq. With API kvm_get_vcpu(), the logical CPU ID is used. With API kvm_get_vcpu_by_cpuid(), vCPU ID can be searched from physical CPU ID. Cc: [email protected] Fixes: 3956a52 ("LoongArch: KVM: Add EIOINTC read and write functions") Signed-off-by: Bibo Mao <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent c34bbc2 commit 45515c6

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

arch/loongarch/kvm/intc/eiointc.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
static void eiointc_set_sw_coreisr(struct loongarch_eiointc *s)
1111
{
12-
int ipnum, cpu, irq_index, irq_mask, irq;
12+
int ipnum, cpu, cpuid, irq_index, irq_mask, irq;
13+
struct kvm_vcpu *vcpu;
1314

1415
for (irq = 0; irq < EIOINTC_IRQS; irq++) {
1516
ipnum = s->ipmap.reg_u8[irq / 32];
@@ -20,7 +21,12 @@ static void eiointc_set_sw_coreisr(struct loongarch_eiointc *s)
2021
irq_index = irq / 32;
2122
irq_mask = BIT(irq & 0x1f);
2223

23-
cpu = s->coremap.reg_u8[irq];
24+
cpuid = s->coremap.reg_u8[irq];
25+
vcpu = kvm_get_vcpu_by_cpuid(s->kvm, cpuid);
26+
if (!vcpu)
27+
continue;
28+
29+
cpu = vcpu->vcpu_id;
2430
if (!!(s->coreisr.reg_u32[cpu][irq_index] & irq_mask))
2531
set_bit(irq, s->sw_coreisr[cpu][ipnum]);
2632
else
@@ -68,17 +74,23 @@ static void eiointc_update_irq(struct loongarch_eiointc *s, int irq, int level)
6874
static inline void eiointc_update_sw_coremap(struct loongarch_eiointc *s,
6975
int irq, u64 val, u32 len, bool notify)
7076
{
71-
int i, cpu;
77+
int i, cpu, cpuid;
78+
struct kvm_vcpu *vcpu;
7279

7380
for (i = 0; i < len; i++) {
74-
cpu = val & 0xff;
81+
cpuid = val & 0xff;
7582
val = val >> 8;
7683

7784
if (!(s->status & BIT(EIOINTC_ENABLE_CPU_ENCODE))) {
78-
cpu = ffs(cpu) - 1;
79-
cpu = (cpu >= 4) ? 0 : cpu;
85+
cpuid = ffs(cpuid) - 1;
86+
cpuid = (cpuid >= 4) ? 0 : cpuid;
8087
}
8188

89+
vcpu = kvm_get_vcpu_by_cpuid(s->kvm, cpuid);
90+
if (!vcpu)
91+
continue;
92+
93+
cpu = vcpu->vcpu_id;
8294
if (s->sw_coremap[irq + i] == cpu)
8395
continue;
8496

0 commit comments

Comments
 (0)