[PATCH 03/13] RISC-V: KVM: Check kvm_riscv_vcpu_alloc_vector_context() return value

Anup Patel posted 13 patches 6 months, 2 weeks ago
There is a newer version of this series
[PATCH 03/13] RISC-V: KVM: Check kvm_riscv_vcpu_alloc_vector_context() return value
Posted by Anup Patel 6 months, 2 weeks ago
The kvm_riscv_vcpu_alloc_vector_context() does return an error code
upon failure so don't ignore this in kvm_arch_vcpu_create().

Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
 arch/riscv/kvm/vcpu.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c
index e0a01af426ff..6a1914b21ec3 100644
--- a/arch/riscv/kvm/vcpu.c
+++ b/arch/riscv/kvm/vcpu.c
@@ -148,8 +148,10 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
 
 	spin_lock_init(&vcpu->arch.reset_state.lock);
 
-	if (kvm_riscv_vcpu_alloc_vector_context(vcpu))
-		return -ENOMEM;
+	/* Setup VCPU vector context */
+	rc = kvm_riscv_vcpu_alloc_vector_context(vcpu);
+	if (rc)
+		return rc;
 
 	/* Setup VCPU timer */
 	kvm_riscv_vcpu_timer_init(vcpu);
-- 
2.43.0
Re: [PATCH 03/13] RISC-V: KVM: Check kvm_riscv_vcpu_alloc_vector_context() return value
Posted by Atish Patra 6 months, 2 weeks ago
On 6/4/25 11:14 PM, Anup Patel wrote:
> The kvm_riscv_vcpu_alloc_vector_context() does return an error code
> upon failure so don't ignore this in kvm_arch_vcpu_create().

currently, kvm_riscv_vcpu_alloc_vector_context returns -ENOMEM only.

Do you have some plans to return different errors in the future ?

Otherwise, the code remains same before and after.

> Signed-off-by: Anup Patel <apatel@ventanamicro.com>
> ---
>   arch/riscv/kvm/vcpu.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c
> index e0a01af426ff..6a1914b21ec3 100644
> --- a/arch/riscv/kvm/vcpu.c
> +++ b/arch/riscv/kvm/vcpu.c
> @@ -148,8 +148,10 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
>   
>   	spin_lock_init(&vcpu->arch.reset_state.lock);
>   
> -	if (kvm_riscv_vcpu_alloc_vector_context(vcpu))
> -		return -ENOMEM;
> +	/* Setup VCPU vector context */
The function name is pretty self explanatory. So no need of this comment ?
> +	rc = kvm_riscv_vcpu_alloc_vector_context(vcpu);
> +	if (rc)
> +		return rc;
>   
>   	/* Setup VCPU timer */
>   	kvm_riscv_vcpu_timer_init(vcpu);
Re: [PATCH 03/13] RISC-V: KVM: Check kvm_riscv_vcpu_alloc_vector_context() return value
Posted by Anup Patel 6 months, 1 week ago
On Fri, Jun 6, 2025 at 5:46 AM Atish Patra <atish.patra@linux.dev> wrote:
>
>
> On 6/4/25 11:14 PM, Anup Patel wrote:
> > The kvm_riscv_vcpu_alloc_vector_context() does return an error code
> > upon failure so don't ignore this in kvm_arch_vcpu_create().
>
> currently, kvm_riscv_vcpu_alloc_vector_context returns -ENOMEM only.
>
> Do you have some plans to return different errors in the future ?

Even if kvm_riscv_vcpu_alloc_vector_context() always returns -ENOMEM,
the caller should not assume anything about the return value.

>
> Otherwise, the code remains same before and after.
>
> > Signed-off-by: Anup Patel <apatel@ventanamicro.com>
> > ---
> >   arch/riscv/kvm/vcpu.c | 6 ++++--
> >   1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c
> > index e0a01af426ff..6a1914b21ec3 100644
> > --- a/arch/riscv/kvm/vcpu.c
> > +++ b/arch/riscv/kvm/vcpu.c
> > @@ -148,8 +148,10 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
> >
> >       spin_lock_init(&vcpu->arch.reset_state.lock);
> >
> > -     if (kvm_riscv_vcpu_alloc_vector_context(vcpu))
> > -             return -ENOMEM;
> > +     /* Setup VCPU vector context */
> The function name is pretty self explanatory. So no need of this comment ?

Yes, no need for this comment. I will drop it in the next revision.

> > +     rc = kvm_riscv_vcpu_alloc_vector_context(vcpu);
> > +     if (rc)
> > +             return rc;
> >
> >       /* Setup VCPU timer */
> >       kvm_riscv_vcpu_timer_init(vcpu);
>

Regards,
Anup