]> git.ipfire.org Git - thirdparty/kernel/stable.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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Aug 2025 14:34:49 +0000 (16:34 +0200)
[ Upstream commit 0dfd9ea7bf80fabe11f5b775d762a5cd168cdf41 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/loongarch/kvm/intc/eiointc.c
arch/loongarch/kvm/intc/ipi.c

index 3cf9894999da437e863976d5fe6f2ec5596639af..0207cfe1dbd6c774f5e26708fc96bf9f2d2ff54c 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 6a13d2f445757f1fe270fe06ec79d5540d0673c0..4859e320e3a1661ebd136d472662ed1fd365e6be 100644 (file)
@@ -318,7 +318,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;