Message ID | a75900413bb8b1e556be690e9588a0f92e946a30.1665733883.git.houwenlong.hwl@antgroup.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp57150wrs; Fri, 14 Oct 2022 01:04:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Zm7Wb9z82k7RQx7kwMpigSEetTL6yWpokKuAQtcIcZqIPii8Gz19QKlJv5bWGjzrX+5Xw X-Received: by 2002:a50:fc85:0:b0:458:e7c6:1cfa with SMTP id f5-20020a50fc85000000b00458e7c61cfamr3327862edq.256.1665734696683; Fri, 14 Oct 2022 01:04:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665734696; cv=none; d=google.com; s=arc-20160816; b=dcYEsJ8M68OBeY7S3ljTQW2cnjFc8uvSKlnPpbR5i5VB5oA0wKK/FuFjzitJJWNoCU rK1vIf8ZCasdXsjNlmgyt3KU653vOarRw8LnfVZvlW27nghJEzDCysKQR5YpQqJx0Otz Yc2vEHiHhNvil10li9bPQoNeIy0ma3vM/rmlt6hGwQoBkTFkprmKEsla4tujy2SVRtc/ P3QffXpXPPPbxA+W6DjrzbrT9719vRsGq0mDunpV42ASKqxQNA9nTmgdrWxaEFe21bsc bkUnavvpjhKAX4ktCwMLnqoijCbEOqBFuGp7g3/uxAG5WqSrnBFHn3WYkVDqCbdlrw79 jQGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=CytTevFXRR6jZGLMvaxcxqlMQSmmxmvFfQrntBkBgkk=; b=P8dfJEXqLEgwF/PUh/Zk0F4pLgaf5IboJivvus85918eFaUFt5OHciiCyy1yx62gU5 10L3qch8bH4LIks4jpQNpLNPPxb6RkpFN5DKSXTFhqVTebwz2HcN9+TrhIWvu1jmBTxC Nf5/GFfkfSmsm07OLCWSIrqwzsGbdTZucTWgrSDlVOMv1GcL6la6YMSHO+JnZ/uYxfx+ nj4nhHriZlSSERdq2m8jRTJ584ehEq5oDzA5aNhqXWS68b76XT7A3QJbdJHeGmViMctb fXaRyPq+4XhY1qyd565xU9RXevl7qU0OYyrXH/g5QezblcgxcgllIofsgzaCyFWj/rgp LrWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=antgroup.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g14-20020a056402180e00b0045102ae16dasi1536830edy.198.2022.10.14.01.04.31; Fri, 14 Oct 2022 01:04:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=antgroup.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229595AbiJNHzv (ORCPT <rfc822;ouuuleilei@gmail.com> + 99 others); Fri, 14 Oct 2022 03:55:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229733AbiJNHzs (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 14 Oct 2022 03:55:48 -0400 Received: from out0-140.mail.aliyun.com (out0-140.mail.aliyun.com [140.205.0.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37B2617FD51; Fri, 14 Oct 2022 00:55:46 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047209;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---.Pc1XjxL_1665734112; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.Pc1XjxL_1665734112) by smtp.aliyun-inc.com; Fri, 14 Oct 2022 15:55:12 +0800 From: "Hou Wenlong" <houwenlong.hwl@antgroup.com> To: kvm@vger.kernel.org Cc: 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>, Peter Xu <peterx@redhat.com>, linux-kernel@vger.kernel.org Subject: [PATCH] KVM: x86: Reduce refcount if single_open() fails in kvm_mmu_rmaps_stat_open() Date: Fri, 14 Oct 2022 15:55:11 +0800 Message-Id: <a75900413bb8b1e556be690e9588a0f92e946a30.1665733883.git.houwenlong.hwl@antgroup.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746649425577746657?= X-GMAIL-MSGID: =?utf-8?q?1746649425577746657?= |
Series |
KVM: x86: Reduce refcount if single_open() fails in kvm_mmu_rmaps_stat_open()
|
|
Commit Message
Hou Wenlong
Oct. 14, 2022, 7:55 a.m. UTC
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(-)
Comments
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)?
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
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; + } + + return 0; } static int kvm_mmu_rmaps_stat_release(struct inode *inode, struct file *file)