From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF300C4320A for ; Tue, 3 Aug 2021 13:14:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2A1C6056B for ; Tue, 3 Aug 2021 13:14:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236197AbhHCNOR (ORCPT ); Tue, 3 Aug 2021 09:14:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236227AbhHCNOP (ORCPT ); Tue, 3 Aug 2021 09:14:15 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E773C06175F for ; Tue, 3 Aug 2021 06:14:03 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id e21so23670701pla.5 for ; Tue, 03 Aug 2021 06:14:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ozlabs-ru.20150623.gappssmtp.com; s=20150623; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=cD44nlfYqtKH4XtlGBmcc3+xGCi39N7kSG0uWYgAZyI=; b=KlyBn5EQFqcP6S++rF+krNoapVKRi0cFbUCjNnNLnv99HYe2sr5W/LXZTuDD/VbMN1 L6sTknsyFtEvEYrpuMrq2fPAbVNIhS4Dbs7UMXsUmU4l21oiulqjVBhULldXbbKAq4S9 i/yMsiRNqBea+akFov+0ycZYUjzcXXjIUGONK7fUa5SFzVC7PCAhn3VEEm7DDJb9mGms dhnZslm3n/pcRYkj5ZEgL/o0nQGwUpI3kJlt/cQ/JfAMAQ+G71FhqoY0RMevXII3HEMQ H38S4jpPFi2CdF+UhDp0x+v6r/pv0zv4u2VMTn1HQYKjQIFNpmdwe1QEXm59e74GVQ4n 9x0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=cD44nlfYqtKH4XtlGBmcc3+xGCi39N7kSG0uWYgAZyI=; b=NlP/MZFW21yECJiqyF6LjlL+ALUQNOdgT7JhVR7sd6zygey/NgDRHzoU8HiZYuxCq3 pcrmjD8xhk3Pn5yXaw39Vp6pIUityNAUg8SMMManFPO6fs8DSyd3G5mqQQU6+8d42BsJ Pmnp/kgalHlluIHvNo4/gK9AexEBQYLSEy6If815JLPi84O4Ts8N/9PmczK0zdBOdFvc Ue3cxUrugsz6DbuWtObQcEyNAr0a/eq1mBF1jEzVWbpmvA/Yw05I+ufTkLLOhVstEIaW KG2ybegNh/u6ihmaf4b2m+1F0yKIYPngyLkUR+B17MCm9nDG6YDtVn8Nxpqz/DhAfaMH hEWA== X-Gm-Message-State: AOAM533drrfH3P9r2cID0L+QMO8mypprxPDCildvfNnKdpeh/At76gxI 4MTfWw7J0Os+bHyAb1dTJPO27g== X-Google-Smtp-Source: ABdhPJxArDiDqJWfF+hAlpH49SYTbceqjzyGkAMccHwv5dmC+Qc2kK7ALgsBIo+uT3XMKGBETVPs1Q== X-Received: by 2002:a65:6248:: with SMTP id q8mr1584659pgv.279.1627996442817; Tue, 03 Aug 2021 06:14:02 -0700 (PDT) Received: from [192.168.10.153] (219-90-184-65.ip.adam.com.au. [219.90.184.65]) by smtp.gmail.com with UTF8SMTPSA id w18sm15193753pjg.50.2021.08.03.06.14.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 Aug 2021 06:14:02 -0700 (PDT) Message-ID: Date: Tue, 3 Aug 2021 23:13:57 +1000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:90.0) Gecko/20100101 Thunderbird/90.0 Subject: Re: [RFC PATCH kernel] KVM: Stop leaking memory in debugfs Content-Language: en-US To: Paolo Bonzini , Greg KH Cc: "Kernel Mailing List, Linux" , kvm References: <20210730043217.953384-1-aik@ozlabs.ru> From: Alexey Kardashevskiy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/08/2021 22:52, Paolo Bonzini wrote: > On Tue, Aug 3, 2021 at 1:16 PM Greg KH wrote: >> On Fri, Jul 30, 2021 at 02:32:17PM +1000, Alexey Kardashevskiy wrote: >>> snprintf(dir_name, sizeof(dir_name), "%d-%d", task_pid_nr(current), fd); >>> kvm->debugfs_dentry = debugfs_create_dir(dir_name, kvm_debugfs_dir); >>> + if (IS_ERR_OR_NULL(kvm->debugfs_dentry)) { >>> + pr_err("Failed to create %s\n", dir_name); >>> + return 0; >>> + } >> >> It should not matter if you fail a debugfs call at all. >> >> If there is a larger race at work here, please fix that root cause, do >> not paper over it by attempting to have debugfs catch the issue for you. > > I don't think it's a race, it's really just a bug that is intrinsic in how > the debugfs files are named. You can just do something like this: > > #include > #include > #include > #include > #include > #include > #include > int main() { > int kvmfd = open("/dev/kvm", O_RDONLY); > int fd = ioctl(kvmfd, KVM_CREATE_VM, 0); > if (fork() == 0) { > printf("before: %d\n", fd); > sleep(2); > } else { > close(fd); > sleep(1); > int fd = ioctl(kvmfd, KVM_CREATE_VM, 0); > printf("after: %d\n", fd); > wait(NULL); > } > } oh nice demo :) although I still think there was a race when I saw it as there was no fork() in the picture but continuous create/destroy VM in 16 threads on 16 VCPUs with no KVM_RUN in between. > > So Alexey's patch is okay and I've queued it, though with pr_warn_ratelimited > instead of pr_err. Makes sense with your reproducer. Thanks, -- Alexey