public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Zhi Wang <zhi.wang.linux@gmail.com>
To: Aleksandr Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Cc: pbonzini@redhat.com, "Sean Christopherson" <seanjc@google.com>,
	"Stéphane Graber" <stgraber@ubuntu.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] KVM: SVM: free sev_*asid_bitmap init if SEV init fails
Date: Thu, 13 Apr 2023 08:07:02 +0300	[thread overview]
Message-ID: <20230413080702.0000016b.zhi.wang.linux@gmail.com> (raw)
In-Reply-To: <CAEivzxfxm9Kg-ap9QeceGgTeCd0du7FrH7Kmi2dRZH6gah-8HQ@mail.gmail.com>

On Wed, 12 Apr 2023 16:52:23 +0200
Aleksandr Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com> wrote:

> On Tue, Apr 11, 2023 at 9:47 PM Zhi Wang <zhi.wang.linux@gmail.com> wrote:
> >
> > On Tue,  4 Apr 2023 14:26:51 +0200
> > Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com> wrote:
> >
> > > If misc_cg_set_capacity() fails for some reason then we have
> > > a memleak for sev_reclaim_asid_bitmap/sev_asid_bitmap. It's
> > > not a case right now, because misc_cg_set_capacity() just can't
> > > fail and check inside it is always successful.
> > >
> > > But let's fix that for code consistency.
> > >
> > > Cc: Sean Christopherson <seanjc@google.com>
> > > Cc: Paolo Bonzini <pbonzini@redhat.com>
> > > Cc: Stéphane Graber <stgraber@ubuntu.com>
> > > Cc: kvm@vger.kernel.org
> > > Cc: linux-kernel@vger.kernel.org
> > > Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
> > > ---
> > >  arch/x86/kvm/svm/sev.c | 7 ++++++-
> > >  1 file changed, 6 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> > > index c25aeb550cd9..a42536a0681a 100644
> > > --- a/arch/x86/kvm/svm/sev.c
> > > +++ b/arch/x86/kvm/svm/sev.c
> > > @@ -2213,8 +2213,13 @@ void __init sev_hardware_setup(void)
> > >       }
> > >
> > >       sev_asid_count = max_sev_asid - min_sev_asid + 1;
> > > -     if (misc_cg_set_capacity(MISC_CG_RES_SEV, sev_asid_count))
> > > +     if (misc_cg_set_capacity(MISC_CG_RES_SEV, sev_asid_count)) {
> > > +             bitmap_free(sev_reclaim_asid_bitmap);
> > > +             sev_reclaim_asid_bitmap = NULL;
> > > +             bitmap_free(sev_asid_bitmap);
> > > +             sev_asid_bitmap = NULL;
> > >               goto out;
> > > +     }
> > >
> > >       pr_info("SEV supported: %u ASIDs\n", sev_asid_count);
> > >       sev_supported = true;
> >
> > It would be nice that another case can also be fixed:
> >
> >         sev_es_asid_count = min_sev_asid - 1;
> >         if (misc_cg_set_capacity(MISC_CG_RES_SEV_ES, sev_es_asid_count))
> >                 goto out; /* <----HERE */
> 
> Nope.
> 
> There is no leak. Because when we are at this point then sev_supported
> = true and everything is fine.
> 
Uh. You are right. Sorry that I was giving this comment based on my on-going
development branch.
> >
> > Maybe it would be a good idea to factor out an common error handling path.


  reply	other threads:[~2023-04-13  5:07 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-04 12:26 [PATCH 0/2] KVM: SVM: small tweaks for sev_hardware_setup Alexander Mikhalitsyn
2023-04-04 12:26 ` [PATCH 1/2] KVM: SVM: free sev_*asid_bitmap init if SEV init fails Alexander Mikhalitsyn
2023-04-11 19:47   ` Zhi Wang
2023-04-12 14:52     ` Aleksandr Mikhalitsyn
2023-04-13  5:07       ` Zhi Wang [this message]
2023-04-04 12:26 ` [PATCH 2/2] KVM: SVM: add some info prints to SEV init Alexander Mikhalitsyn
2023-04-11 19:43   ` Zhi Wang
2023-04-12 14:55     ` Aleksandr Mikhalitsyn
2023-05-19 18:17   ` Sean Christopherson
2023-05-19 19:03     ` Aleksandr Mikhalitsyn
2023-05-19 21:02       ` Sean Christopherson
2023-04-06  3:32 ` [PATCH 0/2] KVM: SVM: small tweaks for sev_hardware_setup Sean Christopherson
2023-04-06  7:07   ` Aleksandr Mikhalitsyn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230413080702.0000016b.zhi.wang.linux@gmail.com \
    --to=zhi.wang.linux@gmail.com \
    --cc=aleksandr.mikhalitsyn@canonical.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=stgraber@ubuntu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox