diff mbox series

[v2,1/2] KVM: x86: Reduce refcount if single_open() fails in kvm_mmu_rmaps_stat_open()

Message ID 5ddb7c97d2f1edbd000020aa842b0619374e6951.1665975828.git.houwenlong.hwl@antgroup.com (mailing list archive)
State New, archived
Headers show
Series [v2,1/2] KVM: x86: Reduce refcount if single_open() fails in kvm_mmu_rmaps_stat_open() | expand

Commit Message

Hou Wenlong Oct. 17, 2022, 3:06 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

Peter Xu Oct. 17, 2022, 6:05 p.m. UTC | #1
On Mon, Oct 17, 2022 at 11:06:09AM +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>

Reviewed-by: Peter Xu <peterx@redhat.com>

Thanks,
diff mbox series

Patch

diff --git a/arch/x86/kvm/debugfs.c b/arch/x86/kvm/debugfs.c
index cfed36aba2f7..e6efd0821c59 100644
--- a/arch/x86/kvm/debugfs.c
+++ b/arch/x86/kvm/debugfs.c
@@ -157,12 +157,17 @@  static int kvm_mmu_rmaps_stat_show(struct seq_file *m, void *v)
 
 static int kvm_mmu_rmaps_stat_open(struct inode *inode, struct file *file)
 {
+	int ret;
 	struct kvm *kvm = inode->i_private;
 
 	if (!kvm_get_kvm_safe(kvm))
 		return -ENOENT;
 
-	return single_open(file, kvm_mmu_rmaps_stat_show, kvm);
+	ret = single_open(file, kvm_mmu_rmaps_stat_show, kvm);
+	if (ret)
+		kvm_put_kvm(kvm);
+
+	return ret;
 }
 
 static int kvm_mmu_rmaps_stat_release(struct inode *inode, struct file *file)