Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp689656rwi; Fri, 14 Oct 2022 07:26:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6+DAPEcJMDZW35L1xrz+t4s8jXcgwy8g6cZ4TNLYrTX4moCHpY9qcb4nWzcywzwtDa93wJ X-Received: by 2002:a17:907:7b95:b0:72f:9c64:4061 with SMTP id ne21-20020a1709077b9500b0072f9c644061mr3648445ejc.351.1665757571364; Fri, 14 Oct 2022 07:26:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665757571; cv=none; d=google.com; s=arc-20160816; b=jnqDRApW2UNq6pfGMpprT+ivlRsA/M98tljEW/TvGhQGvP/cgW41Bt/2c4YmCfZ6Be oQ3mk6XgtO17oe/65EKjm4T5Gg7xCiMN/G8amjW28eldKU93ur5dmMjoGAPqBWQlOJ4u SOop9KZGKVkHD5ETVxtE63DVa7HBsIRpxXy0PVr6Ctc8fGqck2/Ls07HU5tmssUb9mSY QwBgS1lJ7tvRNxjyc7DT7IORFDfmwYjR7E/K44wz/LL1/IwXW45zOrgltV90N/eJb9fh IS4kCgfTPVgUFu3J+Ps7aNP1HT2XkGc/qGvFIweB38/YeQ7K1zNt928BFOUEvO/IFDZR ETtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=BrQ5y1JLetbsFHwRysDZJqLCG1uMk5W5RNBPwooSzyA=; b=oLQknjXMnECfkdJnzaDAqszG3PrLJ0GaDcxNhw4/LhLEXELt7J2rNqfEQ6eCwPu6uy X0Ya5kqP16CovoMBiPC4O+UowTmJapdVHFxFAi3AT03TFcjFimpDJTQxDot8MthCLlQZ FjwPqPAhVxa3wvjGTThJtxj1VstKtrNxlqGsGYFMFkJ2OsLjRbiH4AujK8+EaRXdlWjs YiyQwZPTL/idT2OjHEUwlHeYRXmy8GaxHbWtZsKuXSKaDgznghm5SKaU45JIHwGgi6wK nNykryru5RUl0YS245X4PwmsSddLIFsT8m1zw3NLIBK56ddXtx92FlDzvZQuPakTWYSI pZdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EJ0LTQ8m; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kx24-20020a170907775800b0078266dc4b8csi2154406ejc.719.2022.10.14.07.25.45; Fri, 14 Oct 2022 07:26:11 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EJ0LTQ8m; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230024AbiJNOLf (ORCPT + 99 others); Fri, 14 Oct 2022 10:11:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229971AbiJNOLc (ORCPT ); Fri, 14 Oct 2022 10:11:32 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C95B41D5577 for ; Fri, 14 Oct 2022 07:11:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665756687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=BrQ5y1JLetbsFHwRysDZJqLCG1uMk5W5RNBPwooSzyA=; b=EJ0LTQ8mnEdqT/4HlfBXxmahQ/R/Wvi0uz6I4G303eR+VYf2DF1aHxuXt1CWNTZrqszxGH pYVxOpzg4GOHb0N8+FdPoC5m7nPtZSQWrEdUEtJZgiGLn6aLoLCEZjK1Nfm4/aWS79tcYd OgC7wxEEaHneEQB6saHNimQJTlUlTEE= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-2-gTKKE8MKOgmvKYfTbIjDNg-1; Fri, 14 Oct 2022 10:09:58 -0400 X-MC-Unique: gTKKE8MKOgmvKYfTbIjDNg-1 Received: by mail-qk1-f200.google.com with SMTP id n13-20020a05620a294d00b006cf933c40feso3550268qkp.20 for ; Fri, 14 Oct 2022 07:09:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=BrQ5y1JLetbsFHwRysDZJqLCG1uMk5W5RNBPwooSzyA=; b=S9/QXyhlg+26JryDr2LaCUr5nHlnjfMGWdqRVE7D3s4ai/9bNCw2fV4a8oNwWDu4Ts azUYgGA3Zzr3rKqdD60sGq79ErkD2KcP63/4XjbUMxhNcmEXVwWic1d3kHFLvld0rbJL bnY+wdgUTppoIcSZ0JcIoZjqqwCANIQXQDrToRRTohbxss80Qdmn55ULvFs+Ctk14B9J +wWwr7hguxJn0Uy+2HrXzUp0tus9OZrfKdMgmuSdeCUCfxHXFKxIRy+CPOEwI2HWrv7I bJbkFYMIRBqKHK/GVmdOJs2tU+z08THT0Qhlcb3SJAN2YJntMcf3h4puWrvDbWyVygIP GOpA== X-Gm-Message-State: ACrzQf3+303LfAjJC3VsVkpdhcCXhSK5eG+s1zUibyGv5HPWV1F9xQkt fKdedvfp3cKXKbrs8oQ6Q4eHzhKfd4fACUXdGRlrsIaww6cxYZCUkIbmILGNNVYYzIQ34p2uZ6O bQFloceDQC74eO2qy4xV8tqyc X-Received: by 2002:a05:620a:4310:b0:6ac:f9df:178d with SMTP id u16-20020a05620a431000b006acf9df178dmr3912612qko.773.1665756597735; Fri, 14 Oct 2022 07:09:57 -0700 (PDT) X-Received: by 2002:a05:620a:4310:b0:6ac:f9df:178d with SMTP id u16-20020a05620a431000b006acf9df178dmr3912564qko.773.1665756597250; Fri, 14 Oct 2022 07:09:57 -0700 (PDT) Received: from x1n (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id u6-20020a05620a430600b006e16dcf99c8sm2527098qko.71.2022.10.14.07.09.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 07:09:56 -0700 (PDT) Date: Fri, 14 Oct 2022 10:09:55 -0400 From: Peter Xu To: Hou Wenlong 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: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 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)? -- Peter Xu