Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp18061578rwd; Tue, 27 Jun 2023 11:02:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7/LwfFo9fxm0wK3WmwNFDhozgwYCGCn84F8PR/5EmFrX9gU3oVXGBQvlHZTrf4KYrwVopi X-Received: by 2002:a17:90a:6be4:b0:25b:e85a:e9fe with SMTP id w91-20020a17090a6be400b0025be85ae9femr30459114pjj.27.1687888969930; Tue, 27 Jun 2023 11:02:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687888969; cv=none; d=google.com; s=arc-20160816; b=oZcY311edLK06Tlk6I79aDZwqZSSqGBk31tn+8ATUdGnnmKFxlpKw8cS74yD38EnC4 MsoLPqtcTKYOibor4Lc2KF3VQ/CgGlT3nsoV5/xXNrqfkaYUYftetWl0CoTCPvrNGR1m 5tXtU1KoRQvLBUgkBh0CEkgT0cxc4SZSdm2G4CkvELkshzQ3jNQac9UEp9sNoGcoGRFf Uqr9V3PNERlBwlNSCprDCt7NjVFfWB3ouDrjc9xbOjn5yzkrxK5WoLf8ledJ9Zu7YpOR eNKfrLyJFbiFsQjmr7aWceGqNDLHr2F49v0Rc2BR4EXCNbnQFG1h9ZIxxlLvRFqMDh9j LthA== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ilydTjdTS9jPS3Q531k5dt3/10xWOBh9LY6FBdmbcHw=; fh=I7NiJAVqk/vURt7O0zwAsm89xZ3uR7O04+7BELsAp8E=; b=J50BQHbrCWl7aCR19oP8o5V3i11INCG5+Tszbyd8Ve4VpegU7Wk80gadc3Vc3It/Pu 8pSlOAPNHfI4IuQa4o7/Y5oPXyXF/vLZATJzFYIWtZ8hYxymuCb0GzuNnf0E8sEbihdy vzOGUeoxX1ecjWFg2NPw97V5HS49m6H6whfpzwX4o66vudwhXBLikuQWWTEQMbKmyOtY YfvWPzmt/6JYehNadwzBffC577eTRf1KkmdAtmc2sJJR1kkpxML2Z8EyJo91dwC/v16x dassLdVuGgloXmY8f7UUQscuKlz332zFuYvJUYZarVP/J4lV4sTJ8GL5FQ4bW9CdAWBd 0FOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=cXWltV79; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f36-20020a17090a702700b0023d23393318si7386383pjk.55.2023.06.27.11.02.13; Tue, 27 Jun 2023 11:02:49 -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=@infradead.org header.s=casper.20170209 header.b=cXWltV79; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231706AbjF0RhL (ORCPT + 99 others); Tue, 27 Jun 2023 13:37:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231651AbjF0RhG (ORCPT ); Tue, 27 Jun 2023 13:37:06 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA362272D; Tue, 27 Jun 2023 10:37:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=ilydTjdTS9jPS3Q531k5dt3/10xWOBh9LY6FBdmbcHw=; b=cXWltV79wDZw6RHYQjchi8TzHq 6Kc6/NEUYJlQkKY8P9EiMBEP6KFDPdWnHxsHtPaeeFbNx0FS8iShKjqtxHxqTelUktI5TnHr5pepl iv/zfF5pzzgoIuN46eiRmCbgTu23x9Lal5BK/nU0AcHQ5m09H94J22R6OC1DvHGDn0f+whuK1lgqJ zMHN+oSdlUqf6qpoCwIT5xbTr78wbd4LR6kIBHy5d+JjeTVLKNwDyVh1NUB8tHdY/K6FJurYL1aY2 yjEivrmcWKqF3kueW64pt3BfKVrr7aaE5iqahwMe8J72Ng/sqpqzlgXPw2elPZdJkcV8oKB8fs1Pq 8tJg3p8Q==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qECc2-002wDj-7M; Tue, 27 Jun 2023 17:36:22 +0000 Date: Tue, 27 Jun 2023 18:36:22 +0100 From: Matthew Wilcox To: Suren Baghdasaryan Cc: Greg KH , tj@kernel.org, peterz@infradead.org, lujialin4@huawei.com, lizefan.x@bytedance.com, hannes@cmpxchg.org, mingo@redhat.com, ebiggers@kernel.org, oleg@redhat.com, akpm@linux-foundation.org, viro@zeniv.linux.org.uk, brauner@kernel.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH 1/2] kernfs: add kernfs_ops.free operation to free resources tied to the file Message-ID: References: <20230626201713.1204982-1-surenb@google.com> <2023062757-hardening-confusion-6f4e@gregkh> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Tue, Jun 27, 2023 at 10:03:15AM -0700, Suren Baghdasaryan wrote: > On Mon, Jun 26, 2023 at 11:25 PM Greg KH wrote: > > > > On Mon, Jun 26, 2023 at 01:17:12PM -0700, Suren Baghdasaryan wrote: > > > kernfs_ops.release operation can be called from kernfs_drain_open_files > > > which is not tied to the file's real lifecycle. Introduce a new kernfs_ops > > > free operation which is called only when the last fput() of the file is > > > performed and therefore is strictly tied to the file's lifecycle. This > > > operation will be used for freeing resources tied to the file, like > > > waitqueues used for polling the file. > > > > This is confusing, shouldn't release be the "last" time the file is > > handled and then all resources attached to it freed? Why do we need > > another callback, shouldn't release handle this? > > That is what I thought too but apparently kernfs_drain_open_files() > can also cause ops->release to be called while the file keeps on > living (see details here: > https://lore.kernel.org/all/CAJuCfpFZ3B4530TgsSHqp5F_gwfrDujwRYewKReJru==MdEHQg@mail.gmail.com/#t). If we're splitting these two functions apart, can we use the same naming as the VFS please? ``flush`` called by the close(2) system call to flush a file ``release`` called when the last reference to an open file is closed