Skip to content

Commit f771c0a

Browse files
gaosong-loongsongregkh
authored andcommitted
LoongArch: KVM: Use kvm_get_vcpu_by_id() instead of kvm_get_vcpu()
[ Upstream commit 0dfd9ea ] 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 <siyanteng@cqsoftware.com.cm> Signed-off-by: Song Gao <gaosong@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 8bb4dfc commit f771c0a

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
@@ -318,7 +318,7 @@ static int kvm_ipi_regs_access(struct kvm_device *dev,
318318
cpu = (attr->attr >> 16) & 0x3ff;
319319
addr = attr->attr & 0xff;
320320

321-
vcpu = kvm_get_vcpu(dev->kvm, cpu);
321+
vcpu = kvm_get_vcpu_by_id(dev->kvm, cpu);
322322
if (unlikely(vcpu == NULL)) {
323323
kvm_err("%s: invalid target cpu: %d\n", __func__, cpu);
324324
return -EINVAL;

0 commit comments

Comments
 (0)