Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp19744672rwd; Wed, 28 Jun 2023 13:41:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7nB2HzKbQphfgce4XWi9QKt2ZXE5seeEHNw2mHRm7B+A4vjxxzYEIZx4aTGV0NYKsCVW9V X-Received: by 2002:a17:902:f552:b0:1b2:5689:8686 with SMTP id h18-20020a170902f55200b001b256898686mr10440258plf.63.1687984884817; Wed, 28 Jun 2023 13:41:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687984884; cv=none; d=google.com; s=arc-20160816; b=KVAOIzQ53RQ5SEvr1OWMPDbe83Pc8ORNWIzK7+DKO2COJEd5zS3QLe01qxTwG6A+gQ L8ee2Vq8l8sp8ogit2lK5CH7iLSAf46S1SYKoiIR623l78yCR63g6GgooNo1k6sqLefU lW+IE+VBv0RIq8I7cN6Icqezh/V+gN6D+JZkDdbE3M0XijR/evmXex5gDRoMfzbAvWB6 2TDZzRZ2hHIbXKuPU6O/u47cGzxElhw9xj1c3uJttjvymk66Bf6RDCf7PsA5Heim7nSd VAb+kdTVpBsVM/x7/uHnvOF3DLNvwktfcPjA5g1eUL6xo80n7Z1qbOh5NCpzDwVhJAsK CH3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=k4rTWpAfDqcdZDTILe7jmFb9qWXSX04H9q/bdDWrzoY=; fh=V5Pkf+Q4gQI64TCkPRjovR9bPVczm4VazeGaWgDqWvc=; b=W7Z6MSkBmU1KESENIPiGhuiUxGWL7jQwsK0slxxNK07wdN0cJNokaJmpq3kYtfXUxE +CJdkPEz46FzfFTEqxVBdMBrCT4uIWBuTcdz6DUejTnqAMTbHIeoUbadiTRxC6d3AzsW 4lQfaholH2Fy13QVNC70/amIRPLumpWyXAbpxggXChULoAStJlmLYejFE9oMi4raw5yP 1+wd8h9c2GI8elDQXaRpIlxjvx/XLx6Iw4yJtg/fliEyKxy4yIp4OtavBcx4NheamQ+u +ew7Gd43PuXARvUinGuJhVYZennhZIoGDK5U58siu0Sw/2zIUDWV8fxhOP0D/QC7tQCU LfPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=U4zCCdk9; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j3-20020a170903028300b001b6788a5528si10016977plr.622.2023.06.28.13.41.11; Wed, 28 Jun 2023 13:41:24 -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=@google.com header.s=20221208 header.b=U4zCCdk9; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231182AbjF1UNO (ORCPT + 99 others); Wed, 28 Jun 2023 16:13:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231967AbjF1UNB (ORCPT ); Wed, 28 Jun 2023 16:13:01 -0400 Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98829210B for ; Wed, 28 Jun 2023 13:12:38 -0700 (PDT) Received: by mail-ot1-x336.google.com with SMTP id 46e09a7af769-6b72329b63eso77508a34.0 for ; Wed, 28 Jun 2023 13:12:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687983158; x=1690575158; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=k4rTWpAfDqcdZDTILe7jmFb9qWXSX04H9q/bdDWrzoY=; b=U4zCCdk957gzYM+H+xsRYEONc6RfAPY01RFg1AsAiC76Nlrzfibh3F8apitW44iD4n RUHp1ewjwkT8/07gIW2yd2o6KWfoEsdQ1RsO1okZZ6nH2Mr5kwlGrby0vWUhM9ViRN7t 13g9BOJ5WDeL79lOybkTWaiBVxSQg1laObVGeO5NhmQS1SQYJYNB5wjLMo1HO0fK6Gz5 WdLKojwTtKjBN5QFGmMtZvkJreuEo/Brvnxn3Upo5JUokm0wI4OKMDq++dzzSY9+JFo0 YW0LvwHCBuHdnHsKhCeaX5n+BThhzuEZo0yXHZ3GfqDOIG/IIy3NqjntHu24BBKEIPsN To+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687983158; x=1690575158; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k4rTWpAfDqcdZDTILe7jmFb9qWXSX04H9q/bdDWrzoY=; b=clMRhnn3W1IoSP+7E6gN9r2r/H0h1Mz4o2XWaZarYvhiceaJftFhQPx2dkuhVA9YIj vk1NOHlD7RG0Ze6RmZXPj/Q2vrjSoPD5sfX2xCtlC/endgYE8YAOcS5t03PJosT8Ispr NN9Ltqr9RkXN9mlnD7UYqtJ42TU0SAMYYAABMbY6PCzyarTbuszZCEOWpUlMKHAHOSuk jzoxDAj0sFGgN/qyyZHNQ1zzi6K/q65da2KkthPospkJv3/rJr3rM+6HvziNWX708pgO e3t8Qu8RN86A3M1AxVVOn+eHKeLPAcJEXn2jlI+R8Sp+VOubWMlDXOqg4F3b+6AWbJp8 wURw== X-Gm-Message-State: AC+VfDxHfeTWMZhxfmj/JlEcNU0jYBAiNqttj3KR8GdHRxWJWZk5qVuW WjzGAoXX2wXigpcCIEbeqgqqx/jYQJS9XCWMZDrTmw== X-Received: by 2002:a9d:6289:0:b0:6b8:8a3b:86be with SMTP id x9-20020a9d6289000000b006b88a3b86bemr154556otk.26.1687983157754; Wed, 28 Jun 2023 13:12:37 -0700 (PDT) MIME-Version: 1.0 References: <20230628-meisennest-redlich-c09e79fde7f7@brauner> <20230628-faden-qualvoll-6c33b570f54c@brauner> <20230628-spotten-anzweifeln-e494d16de48a@brauner> <2023062845-stabilize-boogieman-1925@gregkh> In-Reply-To: <2023062845-stabilize-boogieman-1925@gregkh> From: Suren Baghdasaryan Date: Wed, 28 Jun 2023 13:12:23 -0700 Message-ID: Subject: Re: [PATCH 1/2] kernfs: add kernfs_ops.free operation to free resources tied to the file To: Greg KH Cc: Tejun Heo , Christian Brauner , 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, 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Wed, Jun 28, 2023 at 11:42=E2=80=AFAM Greg KH wrote: > > On Wed, Jun 28, 2023 at 11:18:20AM -0700, Suren Baghdasaryan wrote: > > On Wed, Jun 28, 2023 at 11:02=E2=80=AFAM Tejun Heo wrot= e: > > > > > > On Wed, Jun 28, 2023 at 07:35:20PM +0200, Christian Brauner wrote: > > > > > To summarize my understanding of your proposal, you suggest addin= g new > > > > > kernfs_ops for the case you marked (1) and change ->release() to = do > > > > > only (2). Please correct me if I misunderstood. Greg, Tejun, WDYT= ? > > > > > > > > Yes. I can't claim to know all the intricate implementation details= of > > > > kernfs ofc but this seems sane to me. > > > > > > This is going to be massively confusing for vast majority of kernfs u= sers. > > > The contract kernfs provides is that you can tell kernfs that you wan= t out > > > and then you can do so synchronously in a finite amount of time (you = still > > > have to wait for in-flight operations to finish but that's under your > > > control). Adding an operation which outlives that contract as somethi= ng > > > usual to use is guaranteed to lead to obscure future crnashes. For a > > > temporary fix, it's fine as long as it's marked clearly but please do= n't > > > make it something seemingly widely useable. > > > > > > We have a long history of modules causing crashes because of this. Th= e > > > severing semantics is not there just for fun. > > > > I'm sure there are reasons things are working as they do today. Sounds > > like we can't change the ->release() logic from what it is today... > > Then the question is how do we fix this case needing to release a > > resource which can be released only when there are no users of the > > file? My original suggestion was to add a kernfs_ops operation which > > would indicate there are no more users but that seems to be confusing. > > Are there better ways to fix this issue? > > Just make sure that you really only remove the file when all users are > done with it? Do you have control of that from the driver side? I'm a bit confused. In my case it's not a driver, it's the cgroup subsystem and the issue is not that we are removing the file while there are other users. The issue is that kernfs today has no operation which is called when the last user is gone. I need such an operation to be able to free the resources knowing that no users are left. > > But, why is this kernfs file so "special" that it must have this special > construct? Why not do what all other files that handle polling do and > just remove and get out of there when done? AFAIU all other files that handle polling rely on f_op->release() being called after all the users are gone, therefore they can safely free their resources. However kernfs can call ->release() while there are still active users of the file. I can't use that operation for resource cleanup therefore I was suggesting to add a new operation which would be called only after the last fput() and would guarantee no users. Again, I'm not an expert in this, so there might be a better way to handle it. Please advise. Thanks, Suren. > > thanks, > > greg k-h