mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Hou Wenlong" <houwenlong.hwl@antgroup.com>
To: Peter Xu <peterx@redhat.com>
Cc: kvm@vger.kernel.org, Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: x86: Reduce refcount if single_open() fails in kvm_mmu_rmaps_stat_open()
Date: Mon, 17 Oct 2022 10:54:23 +0800	[thread overview]
Message-ID: <20221017025423.GA117575@k08j02272.eu95sqa> (raw)
In-Reply-To: <Y0lts0nU6fO7rrSK@x1n>

On Fri, Oct 14, 2022 at 10:09:55PM +0800, Peter Xu wrote:
> On Fri, Oct 14, 2022 at 03:55:11PM +0800, Hou Wenlong wrote:
> > Refcount is increased before calling single_open() in
> > kvm_mmu_rmaps_stat_open(), If single_open() fails, refcount should be
> > restored, otherwise the vm couldn't be destroyed.
> > 
> > Fixes: 3bcd0662d66fd ("KVM: X86: Introduce mmu_rmaps_stat per-vm debugfs file")
> > Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com>
> > ---
> >  arch/x86/kvm/debugfs.c | 7 ++++++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> > 
> > diff --git a/arch/x86/kvm/debugfs.c b/arch/x86/kvm/debugfs.c
> > index cfed36aba2f7..412ed1b341fa 100644
> > --- a/arch/x86/kvm/debugfs.c
> > +++ b/arch/x86/kvm/debugfs.c
> > @@ -162,7 +162,12 @@ static int kvm_mmu_rmaps_stat_open(struct inode *inode, struct file *file)
> >  	if (!kvm_get_kvm_safe(kvm))
> >  		return -ENOENT;
> >  
> > -	return single_open(file, kvm_mmu_rmaps_stat_show, kvm);
> > +	if (single_open(file, kvm_mmu_rmaps_stat_show, kvm)) {
> > +		kvm_put_kvm(kvm);
> > +		return -ENOMEM;
> > +	}
> 
> Thanks for fixing this.  Would it be nicer to wire the single_open retval
> (even though it'll only fail with -ENOMEM with current code base)?
> 
I agree, it would be nicer to return the single_open() retval directly.
I just follow how failure of simple_attr_open() is handled in kvm_debugfs_open(),
but I think it should be changed too. 

> -- 
> Peter Xu

      reply	other threads:[~2022-10-17  2:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-14  7:55 Hou Wenlong
2022-10-14 14:09 ` Peter Xu
2022-10-17  2:54   ` Hou Wenlong [this message]

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=20221017025423.GA117575@k08j02272.eu95sqa \
    --to=houwenlong.hwl@antgroup.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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

all inboxes | Powered by JetHome®