Re: [PATCH] LoongArch: KVM: Return the actual error code in kvm_ipi_create()
From: Huacai Chen
Date: Wed Sep 23 2026 - 00:21:21 EST
Hi, Chaithanya
On Tue, Sep 22, 2026 at 6:39 PM Chaithanya Lagisetty
<nagachaithanya9911@xxxxxxxxx> wrote:
>
> kvm_ipi_create() registers the IPI device on the IOCSR bus and jumps to
> the error label when that fails. The error path then discards the error
> code that kvm_io_bus_register_dev() reported and returns -EFAULT
> instead:
>
> ret = kvm_io_bus_register_dev(kvm, KVM_IOCSR_BUS, IOCSR_IPI_BASE,
> IOCSR_IPI_SIZE, device);
> mutex_unlock(&kvm->slots_lock);
> if (ret < 0) {
> kvm_pr_unimpl("%s: Initialize IOCSR dev failed, ret = %d\n",
> __func__, ret);
> goto err;
> }
> ...
> err:
> kfree(s);
> return -EFAULT;
>
> kvm_io_bus_register_dev() fails with -ENOMEM or -ENOSPC, so userspace
> creating a KVM_DEV_TYPE_LOONGARCH_IPI device is told that it passed a
> bad address when the real problem is that the host is out of memory or
> out of IOCSR bus slots. -EFAULT is reserved for faulting user addresses,
> and the remaining -EFAULT returns in this file are get_user() failures,
> where it is correct.
>
> Return ret instead. It is guaranteed to hold a valid negative errno
> because the ret < 0 branch above is the only path that reaches the error
> label. This also matches kvm_eiointc_create(), which already propagates
> the kvm_io_bus_register_dev() error code unchanged.
>
> Only compile-tested; the fix is a straight propagation of an error code
> that the adjacent kvm_pr_unimpl() already logs.
>
> Fixes: c532de5a67a7 ("LoongArch: KVM: Add IPI device support")
> Assisted-by: Cursor:claude-opus-5
> Signed-off-by: Chaithanya Lagisetty <nagachaithanya9911@xxxxxxxxx>
> ---
> arch/loongarch/kvm/intc/ipi.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/loongarch/kvm/intc/ipi.c b/arch/loongarch/kvm/intc/ipi.c
> index 7b333a4a0430..672ec053a997 100644
> --- a/arch/loongarch/kvm/intc/ipi.c
> +++ b/arch/loongarch/kvm/intc/ipi.c
> @@ -431,7 +431,7 @@ static int kvm_ipi_create(struct kvm_device *dev, u32 type)
>
> err:
> kfree(s);
> - return -EFAULT;
> + return ret;
Why not remove the "err" label and return at the "goto" statement?
Huacai
> }
>
> static void kvm_ipi_destroy(struct kvm_device *dev)
> --
> 2.43.0
>