From patchwork Mon Oct 17 03:06:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Wenlong X-Patchwork-Id: 3194 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1244294wrs; Sun, 16 Oct 2022 20:08:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5PCqMMblEgvJhyzGJhHAId9wraBUKmufNs3h5XWklkjYRBiz8xopTfdxKZf6s+eJ2W0OvP X-Received: by 2002:a63:145d:0:b0:44b:f115:f90f with SMTP id 29-20020a63145d000000b0044bf115f90fmr8870413pgu.157.1665976082964; Sun, 16 Oct 2022 20:08:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665976082; cv=none; d=google.com; s=arc-20160816; b=0o1M+T0d0hIlGFJZpHpF8J6TbYgewPFaXVRCFk94a2RiOneO3ugit04B5LD2aGe49i TFVc7bYKUjVqqVSbsiYPCWD2OXVLHFAhYtWB5q8VS9jbBZ9aEDkn6cgq2gxiHxhRqv2y 9jM/tccrY6LV1CQUMbP2MA42jysjXhvqUvD9v+15VUf4SoC3z9eUtjAEwVO6R3b99OTM 57jI8Wmmknfidr55zFEjDQZdOxwE17/qT/fM1mp/KxFFFGeTvfQkcrMup7M9VNWxg2YM H8r/GKfbmgd75Q2oRbcIMhrTJMO5/p4Zx+yMSS1d80kIT2nwxWt8oiA05Bvtxr0g85rJ MEuQ== 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=RrV334p+GC/wydUJnW2RZu/G1x62pV3mFDw3m8AMPlA=; b=u8U3+2iGghaF6dVcgXeEtwDt5Uxq+ZHEDboKnVW+P0DSDw7Wk8gkx9sGzimawzcPIy 5gLikzrYT1/FQzA3pdTubxJ2zzjhu7URP5lRS11vVKXrYQeEwgZhVfykd3ERq9hW6VFL AUCwz+Bckk5F7fUfaVJZI072cxFU4Gx5eDB0r7kBoPTqQV59qyDBBJntulV/ktj8Sk+D VxMChJl7dbanYG7vvmsyTEfSykx72m9dxaMyW6d6++j7sN84sshzgjJ1gm20hbLAnCQ2 Zf0YS6LhnwBErvhwNT0zEt64ZCDH6Q5ebpOiSo2r2QXSNZteb2+Cexn/EdL3iGYTDyOg h5TQ== 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 s14-20020a17090302ce00b0016c44b7c8c5si10043361plk.11.2022.10.16.20.07.50; Sun, 16 Oct 2022 20:08:02 -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 S231893AbiJQDHZ (ORCPT + 99 others); Sun, 16 Oct 2022 23:07:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231852AbiJQDG5 (ORCPT ); Sun, 16 Oct 2022 23:06:57 -0400 Received: from out0-150.mail.aliyun.com (out0-150.mail.aliyun.com [140.205.0.150]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D4F54B4BA; Sun, 16 Oct 2022 20:06:44 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047202;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---.PeP-vlI_1665975970; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.PeP-vlI_1665975970) by smtp.aliyun-inc.com; Mon, 17 Oct 2022 11:06:11 +0800 From: "Hou Wenlong" To: kvm@vger.kernel.org Cc: Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Xu , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] KVM: x86: Reduce refcount if single_open() fails in kvm_mmu_rmaps_stat_open() Date: Mon, 17 Oct 2022 11:06:09 +0800 Message-Id: <5ddb7c97d2f1edbd000020aa842b0619374e6951.1665975828.git.houwenlong.hwl@antgroup.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, 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: 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?1746902537435187707?= 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 Reviewed-by: Peter Xu --- 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..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) From patchwork Mon Oct 17 03:06:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Wenlong X-Patchwork-Id: 3193 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1244030wrs; Sun, 16 Oct 2022 20:07:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4QAr9Xdm7KFnWQKHjElR0BmnNiBEmFvGO1BwOrJOYCVOWjQIgAHKCGXXTP0U4aLBwgocHf X-Received: by 2002:a17:90a:f2c3:b0:20b:b75f:2f9e with SMTP id gt3-20020a17090af2c300b0020bb75f2f9emr31123181pjb.43.1665976030129; Sun, 16 Oct 2022 20:07:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665976030; cv=none; d=google.com; s=arc-20160816; b=j/NzaCrY29zzQRADSMx0/uiUxPrys0dnevn//hg8ZxidBZPCz5kZ3qr1wgg50m9SpX B8RDdINICOXxNAKaEhjQkJsZZDuGZSdTpiwNkri2JU7XnHKbCQxKO5v0B+0KkHNml9eO aurvjQN+yZRz3ALLsnUdQ4uWSFFGl6FHAfRyL2oTl14YvSRhLRITbs8vBjjXXpbB3W4c DtiYAzzfU/+/mEyfqzZBIMHKfUv6qaCeBZu7GjNcIRkEurzUjFUVI4A/Pt3vPziuYo76 TDLgv+U9qUDsdDsOwueKKvkUqDwCo1JEuTLok0bXDImSltuZKCliDZsjwb9j9pRTMInx OJvQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=7TtDfOb9/roKzKmbXp7O/nCVu3tXbWoEeUlUHTMQacs=; b=TZFV1xpuRqcBiBptOFsF1ilN9pGbX5wuGLBJW4zLrE+WT2kfy2xksg1z44NrT57Hfl MBbNYXWuNa5kY9iUj1l8dTuDQx+DYwY9d1kmWgF9KxTwzSZFvbHexf2TNWeQfU0zoXLk v/aynbZiz4gi2ktOHcSftkLDdcJnoRUEg9ucJAilcp/m8aptbkXyBV1+1iCEP0hMYsCu 6Kku7AdrIxjo3tcnO98izLhCVBn4wkvTLMcdF7NzCamYAccXkrDW/z0sUNpvJpNqQg1o wSOBD6AQAgzkIc4+yyoGxU4su7zqP1T5zUMBy38jCRC5gL3VxfK0s6KS4Kh/92F3kicT qA1Q== 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 m24-20020a63f618000000b00430b00f507dsi9407881pgh.430.2022.10.16.20.06.57; Sun, 16 Oct 2022 20:07:10 -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 S231789AbiJQDG3 (ORCPT + 99 others); Sun, 16 Oct 2022 23:06:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231784AbiJQDGY (ORCPT ); Sun, 16 Oct 2022 23:06:24 -0400 Received: from out0-149.mail.aliyun.com (out0-149.mail.aliyun.com [140.205.0.149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02FDA4B0E2; Sun, 16 Oct 2022 20:06:14 -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=ay29a033018047204;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=3;SR=0;TI=SMTPD_---.PeQJoS4_1665975971; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.PeQJoS4_1665975971) by smtp.aliyun-inc.com; Mon, 17 Oct 2022 11:06:12 +0800 From: "Hou Wenlong" To: kvm@vger.kernel.org Cc: Paolo Bonzini , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] KVM: debugfs: Return retval of simple_attr_open() if it fails Date: Mon, 17 Oct 2022 11:06:10 +0800 Message-Id: <69d64d93accd1f33691b8a383ae555baee80f943.1665975828.git.houwenlong.hwl@antgroup.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <5ddb7c97d2f1edbd000020aa842b0619374e6951.1665975828.git.houwenlong.hwl@antgroup.com> References: <5ddb7c97d2f1edbd000020aa842b0619374e6951.1665975828.git.houwenlong.hwl@antgroup.com> MIME-Version: 1.0 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746902481842409070?= X-GMAIL-MSGID: =?utf-8?q?1746902481842409070?= Although simple_attr_open() fails only with -ENOMEM with current code base, it would be nicer to return retval of simple_attr_open() directly in kvm_debugfs_open(). No functional change intended. Signed-off-by: Hou Wenlong --- virt/kvm/kvm_main.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index e30f1b4ecfa5..f7b06c1e8827 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -5398,6 +5398,7 @@ static int kvm_debugfs_open(struct inode *inode, struct file *file, int (*get)(void *, u64 *), int (*set)(void *, u64), const char *fmt) { + int ret; struct kvm_stat_data *stat_data = (struct kvm_stat_data *) inode->i_private; @@ -5409,15 +5410,13 @@ static int kvm_debugfs_open(struct inode *inode, struct file *file, if (!kvm_get_kvm_safe(stat_data->kvm)) return -ENOENT; - if (simple_attr_open(inode, file, get, - kvm_stats_debugfs_mode(stat_data->desc) & 0222 - ? set : NULL, - fmt)) { + ret = simple_attr_open(inode, file, get, + kvm_stats_debugfs_mode(stat_data->desc) & 0222 + ? set : NULL, fmt); + if (ret) kvm_put_kvm(stat_data->kvm); - return -ENOMEM; - } - return 0; + return ret; } static int kvm_debugfs_release(struct inode *inode, struct file *file)