Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3851828rwi; Sun, 16 Oct 2022 20:04:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6waNXWjIqmobmZTR4OMrKrvtyNXiY1zbooHZZ4zJXW/5iabraIJVTUzUD2Z6L6VwYUrVUL X-Received: by 2002:a63:1308:0:b0:440:5517:c99d with SMTP id i8-20020a631308000000b004405517c99dmr8684098pgl.550.1665975872956; Sun, 16 Oct 2022 20:04:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665975872; cv=none; d=google.com; s=arc-20160816; b=UUqXCsgAWaTLQrMGzw8NdX51a36cZS0GvMbeCCsrZkF2ebB9HZxzatyJVPvUgLRTTu KC7qK5FpzLHZ8owclHc9MuVQyP/0CLZi4TPsIr2r43oLNP03WTQuVxENfkDvIKUKds3A EBytEEI9b7JUGOs9Vj0NoOp+6crdZhsugD41iByyWWadv+Co2508dwRMF5HmHaskpHcy KXn+Rh1rkj2Bh4qQE5gRNgu7SXrUwPOUsPJx/vyBVjyaX274J1/whvXew42zGW1aShZQ S7gY2BCTW3VnFoCrl51se2GOT1HX7y4OOBwDe7X8S+aBo6sGS7SMXit2FrDMcIPD8YRk i5Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=RmH5vYQSIaJXvZhPvIrShUTJD5PDlKXkNa3FcvsOnjU=; b=AiP7JC5fI0Mz9VR3n6YJoVaJ6/HNR6oU/2xVRWJl8GbexgzJfrzmlO3vvdpE8Es5ju OPjZjTVFjPRl4p5jbhqA8cDfWHxWHLTgPn7+zjKTS8oM4miWQq1t7KS3kJPX7jLLspv7 uEM1+jXlPAdnj+Oze9a3u5EPPIjdLfUy9H+0AxNQydt/E9RMJ7f+VGKolSRugyScbr4v q2YQAA9VMbb4tOgMbx0l50xhqRUnoJnTDiEq4jp3TQ7S7npFqNuVPgz2fpEFtCc9u1eP vXUHJlucfIF/uqbdvC91BMKRaDRQpUDgVLURAoPybFGU5wX9LNyZXY27L8smEaoPMT/E L9Pg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b4-20020a170902d40400b0017f5ea2e8easi9321605ple.357.2022.10.16.20.04.20; Sun, 16 Oct 2022 20:04:32 -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 S231515AbiJQCyb (ORCPT + 99 others); Sun, 16 Oct 2022 22:54:31 -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) 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 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