Re: [PATCH v5 9/9] KVM: s390: Return failure in case of failure in kvm_s390_set_cmma_bits()

From: Claudio Imbrenda

Date: Tue Jun 23 2026 - 06:34:27 EST


On Tue, 23 Jun 2026 11:30:24 +0200
Christian Borntraeger <borntraeger@xxxxxxxxxx> wrote:

> Am 22.06.26 um 18:07 schrieb Claudio Imbrenda:
> > If the allocation of the bits array failed, kvm_s390_set_cmma_bits()
> > would return 0 instead of an error code.
> >
> > Rework the function to use the __free() macros and thus simplify the
> > code flow; when the above mentioned allocation fails, simply return
> > -ENOMEM.
> >
> > Fixes: e38c884df921 ("KVM: s390: Switch to new gmap")
> > Signed-off-by: Claudio Imbrenda <imbrenda@xxxxxxxxxxxxx>
> > ---
> > arch/s390/kvm/kvm-s390.c | 18 +++++++-----------
> > 1 file changed, 7 insertions(+), 11 deletions(-)
> >
> > diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
> > index cdd8b41d24ed..27d6004132d2 100644
> > --- a/arch/s390/kvm/kvm-s390.c
> > +++ b/arch/s390/kvm/kvm-s390.c
> > @@ -2282,8 +2282,8 @@ static int kvm_s390_get_cmma_bits(struct kvm *kvm,
> > static int kvm_s390_set_cmma_bits(struct kvm *kvm,
> > const struct kvm_s390_cmma_log *args)
> > {
> > - struct kvm_s390_mmu_cache *mc;
> > - u8 *bits = NULL;
> > + struct kvm_s390_mmu_cache *mc __free(kvm_s390_mmu_cache) = NULL;
> > + u8 *bits __free(kvfree) = NULL;
>
> why kvfree and not vfree?

because vfree does not exist as cleanup macro: __free(vfree) would not
compile

adding vfree would be outside the scope of this patch

>
> > int r = 0;
> >
> > if (!kvm->arch.use_cmma)
> > @@ -2303,18 +2303,16 @@ static int kvm_s390_set_cmma_bits(struct kvm *kvm,
> > return -ENOMEM;
> > bits = vmalloc(array_size(sizeof(*bits), args->count));
> > if (!bits)
> > - goto out;
> > + return -ENOMEM;
> >
> > r = copy_from_user(bits, (void __user *)args->values, args->count);
> > - if (r) {
> > - r = -EFAULT;
> > - goto out;
> > - }
> > + if (r)
> > + return -EFAULT;
> >
> > do {
> > r = kvm_s390_mmu_cache_topup(mc);
> > if (r)
> > - break;
> > + return r;
> > scoped_guard(read_lock, &kvm->mmu_lock) {
> > r = dat_set_cmma_bits(mc, kvm->arch.gmap->asce, args->start_gfn,
> > args->count, args->mask, bits);
> > @@ -2322,9 +2320,7 @@ static int kvm_s390_set_cmma_bits(struct kvm *kvm,
> > } while (r == -ENOMEM);
> >
> > set_bit(GMAP_FLAG_USES_CMM, &kvm->arch.gmap->flags);
> > -out:
> > - kvm_s390_free_mmu_cache(mc);
> > - vfree(bits);
> > +
> > return r;
> > }
> >
>