Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp592168rdb; Tue, 5 Dec 2023 14:04:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IEHw9Jl/jYKp2ziGpaXSpnwbZwB2756PVtOvtT6HNlT0jwfenWPePkZ+Xvuf8AS+hFhftsn X-Received: by 2002:a17:90b:143:b0:286:6cc0:b927 with SMTP id em3-20020a17090b014300b002866cc0b927mr1564702pjb.94.1701813845016; Tue, 05 Dec 2023 14:04:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701813845; cv=none; d=google.com; s=arc-20160816; b=aZ3I65Zl/SsYasEX62Peuah5k4f3UeCJKuhA3WVgdX7aVcp6qaDm8fTFcs6z4ijSMJ /j3ZI6x3cNGpdYMQtmFb7fTusErRvCsvnOOxMjiFkw4xzf1nveuDMY4uGx7I3GoBdHxd 5Vym2qgSbWfuTjEau0f0CFad0IQi/779nueuUu1ieqg9Q3kv0gtrndi/5AHzph83wVY5 k3Z5oDg/+dr5DKiY8yEdX18dpFCAF1OOkGx4zeOcanPrSBb4hRo6sJWMAk3dkn3jnW35 zJEvPlEdZ0LnGBA1qJ94GPr6dTuooKRcu6J0ms0w0r3ytLpfTh/oMHUxpDJf1DVm9+Dk 02FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=wzBUASs8pPfv/I/aupn6RulJurEpXssH14Jo91yxznE=; fh=PVdaGWcqEoX6wb3PzqwzAIxAuXOZAjDtXgiiWX5iWqg=; b=d7652Pfc9btkQQzkAJnmJiBNU+dTbQbUVT4DPLqlCAkx5B3xFdUw1Tt5UfKt+AZ2q1 VZWMarwcCXpfrTnqwJQ0XfYB41LxLVa5viz+Cp6DH7wRIuZxJVL1I88/ZGOiD7ZFFI7V tH/Y2wVe28WW+HFeg+VfJdmkwbapjc/atf90uS+hRYKFraFUE1Ci+bvIER3okoxJ2v60 6kBjvRybFm5Nne7/b72m3VaoWto2SVG1WZ5dfMXIplLz1JG2xyXeEZ56No5mfYeBDuH4 MDeKWXEtOCY6nA9eoLANHCtgs6fbJqxTiUKLbHYnP4ABuux/kel/ZqJvTobpGe85Rvmy FxUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=Y49si3Z7; spf=pass (google.com: domain of linux-nfs+bounces-347-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-347-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id o11-20020a17090a744b00b00286a2a7a67asi4328293pjk.64.2023.12.05.14.04.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 14:04:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-347-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=Y49si3Z7; spf=pass (google.com: domain of linux-nfs+bounces-347-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-347-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 10035B21200 for ; Tue, 5 Dec 2023 22:04:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EDDA46FCDA; Tue, 5 Dec 2023 22:03:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="Y49si3Z7" X-Original-To: linux-nfs@vger.kernel.org Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AC94183 for ; Tue, 5 Dec 2023 14:03:49 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1d03f90b0cbso11664975ad.1 for ; Tue, 05 Dec 2023 14:03:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1701813828; x=1702418628; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=wzBUASs8pPfv/I/aupn6RulJurEpXssH14Jo91yxznE=; b=Y49si3Z7ejmZaeBTbG9/v3b/cPyXwdYt0UiG8aX94+NPqpxaT8VoVErfm+PrgRSZsH w2cu97G/plmUiFCzm4/kdnUSKoaad8kXZ5CyqHebLabGVO/XWyyP6/79O+KyocVlvDXH W0q9EomiP9Wnx/EpqJVonxzI2Cz2JdJQGGJ8Viou42ryz1BokkpMBnxxPGzaePyIoUEv ST9ayZp/M/0lgBj31VPSa1Fco+cGkVXxOVBrWWYOTRuoKjdCwajPbh8Ltl727IjBceiU u14xvr0qMZO+UPwL6uS4sVHPlBMjk7FRlgurcZv4CpmS3l2Pffxtyd1IQM8qibn4YIsG dsiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701813828; x=1702418628; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wzBUASs8pPfv/I/aupn6RulJurEpXssH14Jo91yxznE=; b=rmsepLqE1vsdGnPmd6kH6sgg18khOubFovyncvQXf6hhoaD1V3DMsFzdLVrIzKymg5 of/Z7o5sqrS7hatKDHSIW65rinDqRMJULT08NLTFcv1G1xhMVjWLLo6217LwYlRvItTl Kd+vYebYCWZboWS7QxmNmS9NNGoUvtKukWTjkyL/f3M4xGSpPyhtLSUwOGWGUFxEXQ3P KDb3nW1mJuiQoAd0F8K5P/PFw7VktygYxcwrzSchPo/MGoTO6ImhT2ktQeokZsqfxYYS 7RheugdCYDh3DZ6G4xFJpbOYcuEspAr+gnlowYnmQpEOizEaIr5OiQf8RX0MHEYxZ/dX UZ5A== X-Gm-Message-State: AOJu0YwO1hINugvlSggpvwGfkR44EdR/DbK4pnRugg1E3jUrzeb9koPV xhMOPcQ3RTTmfw1C7+jUuh4KZw== X-Received: by 2002:a17:90a:4bc7:b0:286:f169:79f1 with SMTP id u7-20020a17090a4bc700b00286f16979f1mr1945090pjl.2.1701813828561; Tue, 05 Dec 2023 14:03:48 -0800 (PST) Received: from [192.168.1.150] ([198.8.77.194]) by smtp.gmail.com with ESMTPSA id q24-20020a170902bd9800b001d1c96a0c63sm190278pls.274.2023.12.05.14.03.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Dec 2023 14:03:48 -0800 (PST) Message-ID: <3609267c-3fcd-43d6-9b43-9f84bef029a2@kernel.dk> Date: Tue, 5 Dec 2023 15:03:46 -0700 Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] Allow a kthread to declare that it calls task_work_run() Content-Language: en-US From: Jens Axboe To: NeilBrown , Christian Brauner Cc: Al Viro , Oleg Nesterov , Chuck Lever , Jeff Layton , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org References: <20231204014042.6754-1-neilb@suse.de> <20231204014042.6754-2-neilb@suse.de> <170172377302.7109.11739406555273171485@noble.neil.brown.name> <20231205-altbacken-umbesetzen-e5c0c021ab98@brauner> <170181169515.7109.11121482729257102758@noble.neil.brown.name> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/5/23 2:58 PM, Jens Axboe wrote: > On 12/5/23 2:28 PM, NeilBrown wrote: >> On Tue, 05 Dec 2023, Christian Brauner wrote: >>> On Mon, Dec 04, 2023 at 03:09:44PM -0700, Jens Axboe wrote: >>>> On 12/4/23 2:02 PM, NeilBrown wrote: >>>>> It isn't clear to me what _GPL is appropriate, but maybe the rules >>>>> changed since last I looked..... are there rules? >>>>> >>>>> My reasoning was that the call is effectively part of the user-space >>>>> ABI. A user-space process can call this trivially by invoking any >>>>> system call. The user-space ABI is explicitly a boundary which the GPL >>>>> does not cross. So it doesn't seem appropriate to prevent non-GPL >>>>> kernel code from doing something that non-GPL user-space code can >>>>> trivially do. >>>> >>>> By that reasoning, basically everything in the kernel should be non-GPL >>>> marked. And while task_work can get used by the application, it happens >>>> only indirectly or implicitly. So I don't think this reasoning is sound >>>> at all, it's not an exported ABI or API by itself. >>>> >>>> For me, the more core of an export it is, the stronger the reason it >>>> should be GPL. FWIW, I don't think exporting task_work functionality is > >>> >>> Yeah, I'm not too fond of that part as well. I don't think we want to >>> give modules the ability to mess with task work. This is just asking for >>> trouble. >>> >> >> Ok, maybe we need to reframe the problem then. >> >> Currently fput(), and hence filp_close(), take control away from kernel >> threads in that they cannot be sure that a "close" has actually >> completed. >> >> This is already a problem for nfsd. When renaming a file, nfsd needs to >> ensure any cached "open" that it has on the file is closed (else when >> re-exporting an NFS filesystem it can result in a silly-rename). >> >> nfsd currently handles this case by calling flush_delayed_fput(). I >> suspect you are no more happy about exporting that than you are about >> exporting task_work_run(), but this solution isn't actually 100% >> reliable. If some other thread calls flush_delayed_fput() between nfsd >> calling filp_close() and that same nfsd calling flush_delayed_fput(), >> then the second flush can return before the first flush (in the other >> thread) completes all the work it took on. >> >> What we really need - both for handling renames and for avoiding >> possible memory exhaustion - is for nfsd to be able to reliably wait for >> any fput() that it initiated to complete. >> >> How would you like the VFS to provide that service? > > Since task_work happens in the context of your task already, why not > just have a way to get it stashed into a list when final fput is done? > This avoids all of this "let's expose task_work" and using the task list > for that, which seems kind of pointless as you're just going to run it > later on manually anyway. > > In semi pseudo code: > > bool fput_put_ref(struct file *file) > { > return atomic_dec_and_test(&file->f_count); > } > > void fput(struct file *file) > { > if (fput_put_ref(file)) { > ... > } > } > > and then your nfsd_file_free() could do: > > ret = filp_flush(file, id); > if (fput_put_ref(file)) > llist_add(&file->f_llist, &l->to_free_llist); > > or something like that, where l->to_free_llist is where ever you'd > otherwise punt the actual freeing to. Should probably have the put_ref or whatever helper also init the task_work, and then reuse the list in the callback_head there. Then whoever flushes it has to call ->func() and avoid exposing ____fput() to random users. But you get the idea. -- Jens Axboe