Skip to content

Commit 0dfd9ea

Browse files
gaosong-loongsonchenhuacai
authored andcommitted
LoongArch: KVM: Use kvm_get_vcpu_by_id() instead of kvm_get_vcpu()
Since using kvm_get_vcpu() may fail to retrieve the vCPU context, kvm_get_vcpu_by_id() should be used instead. Fixes: 8e30542 ("LoongArch: KVM: Add IPI user mode read and write function") Fixes: 3956a52 ("LoongArch: KVM: Add EIOINTC read and write functions") Reviewed-by: Yanteng Si <[email protected]> Signed-off-by: Song Gao <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 5c68549 commit 0dfd9ea

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

arch/loongarch/kvm/intc/eiointc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ static void eiointc_update_irq(struct loongarch_eiointc *s, int irq, int level)
4545
}
4646

4747
cpu = s->sw_coremap[irq];
48-
vcpu = kvm_get_vcpu(s->kvm, cpu);
48+
vcpu = kvm_get_vcpu_by_id(s->kvm, cpu);
49+
if (unlikely(vcpu == NULL)) {
50+
kvm_err("%s: invalid target cpu: %d\n", __func__, cpu);
51+
return;
52+
}
53+
4954
if (level) {
5055
/* if not enable return false */
5156
if (!test_bit(irq, (unsigned long *)s->enable.reg_u32))

arch/loongarch/kvm/intc/ipi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ static int kvm_ipi_regs_access(struct kvm_device *dev,
298298
cpu = (attr->attr >> 16) & 0x3ff;
299299
addr = attr->attr & 0xff;
300300

301-
vcpu = kvm_get_vcpu(dev->kvm, cpu);
301+
vcpu = kvm_get_vcpu_by_id(dev->kvm, cpu);
302302
if (unlikely(vcpu == NULL)) {
303303
kvm_err("%s: invalid target cpu: %d\n", __func__, cpu);
304304
return -EINVAL;

0 commit comments

Comments
 (0)