From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23693C4332F for ; Mon, 17 Oct 2022 02:54:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231528AbiJQCyd (ORCPT ); Sun, 16 Oct 2022 22:54:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231516AbiJQCy3 (ORCPT ); Sun, 16 Oct 2022 22:54:29 -0400 Received: from out0-153.mail.aliyun.com (out0-153.mail.aliyun.com [140.205.0.153]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5007B0; Sun, 16 Oct 2022 19:54:26 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R791e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047207;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---.PeOkqYT_1665975263; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.PeOkqYT_1665975263) by smtp.aliyun-inc.com; Mon, 17 Oct 2022 10:54:24 +0800 Date: Mon, 17 Oct 2022 10:54:23 +0800 From: "Hou Wenlong" To: Peter Xu Cc: kvm@vger.kernel.org, Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org Subject: Re: [PATCH] KVM: x86: Reduce refcount if single_open() fails in kvm_mmu_rmaps_stat_open() Message-ID: <20221017025423.GA117575@k08j02272.eu95sqa> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > > --- > > 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