]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
LoongArch: KVM: Use kvm_get_vcpu_by_id() instead of kvm_get_vcpu()
authorSong Gao <gaosong@loongson.cn>
Wed, 20 Aug 2025 14:51:15 +0000 (22:51 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Wed, 20 Aug 2025 14:51:15 +0000 (22:51 +0800)
Since using kvm_get_vcpu() may fail to retrieve the vCPU context,
kvm_get_vcpu_by_id() should be used instead.

Fixes: 8e3054261bc3 ("LoongArch: KVM: Add IPI user mode read and write function")
Fixes: 3956a52bc05b ("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>
arch/loongarch/kvm/intc/eiointc.c
arch/loongarch/kvm/intc/ipi.c

index a3a12af9ecbff8ecaf3507a6cdf54c0235a0e3f7..026b139dcff2de431e53a593bbe429fcbd43e166 100644 (file)
@@ -45,7 +45,12 @@ static void eiointc_update_irq(struct loongarch_eiointc *s, int irq, int level)
        }
 
        cpu = s->sw_coremap[irq];
-       vcpu = kvm_get_vcpu(s->kvm, cpu);
+       vcpu = kvm_get_vcpu_by_id(s->kvm, cpu);
+       if (unlikely(vcpu == NULL)) {
+               kvm_err("%s: invalid target cpu: %d\n", __func__, cpu);
+               return;
+       }
+
        if (level) {
                /* if not enable return false */
                if (!test_bit(irq, (unsigned long *)s->enable.reg_u32))
index 7925651d2ccf1ec6202fb1c47478caef6923ddb9..5a8481dda052e6b493e1c873225625809489a1a8 100644 (file)
@@ -298,7 +298,7 @@ static int kvm_ipi_regs_access(struct kvm_device *dev,
        cpu = (attr->attr >> 16) & 0x3ff;
        addr = attr->attr & 0xff;
 
-       vcpu = kvm_get_vcpu(dev->kvm, cpu);
+       vcpu = kvm_get_vcpu_by_id(dev->kvm, cpu);
        if (unlikely(vcpu == NULL)) {
                kvm_err("%s: invalid target cpu: %d\n", __func__, cpu);
                return -EINVAL;