Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp589143rdb; Tue, 5 Dec 2023 13:59:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IE8cn0coV8UPeXK+El/EX6d9CMYEmSaxV6duDJLaMbarhzxAzxuEY3CVol7WPNYWucM+AYW X-Received: by 2002:a17:90b:4a82:b0:286:b2ca:4bc3 with SMTP id lp2-20020a17090b4a8200b00286b2ca4bc3mr1998701pjb.32.1701813541347; Tue, 05 Dec 2023 13:59:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701813541; cv=none; d=google.com; s=arc-20160816; b=I5zwAc8jZzaa7IXygZReb20vUkFP9CUEcsTu7Lng+H2Vv4WqCC4E8qunQwnm1n1QGg RfdB+USxvueqQ7r2HAoPGVC7LbTpkri2BdtupivAo5vztUNy1nCiHe6NTXY/QcTctCzx vxuXT+/lS48SManuOW2fofnF0NJoFpyB6vSwRnpch87ezD3E7SiTGtFiOUv9r5iZR1iE b14uqFkAXbGScLV4IN3n6CcE77t7FjyJRS9T67Wr8zOs708eQsTNfkFNY2RGnFGt9Dab 99vVBEhpGjzpmEiIWoVakMj2evsFGic+KDfn7Brvli4qn9k/kCcOrY68BvqlgSoihJ7r kBcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=LGvf0v3WO1jMmuVd3YQ6/5GaYR43CazhfwAsFHfc+Ck=; fh=PVdaGWcqEoX6wb3PzqwzAIxAuXOZAjDtXgiiWX5iWqg=; b=D6ujCCSGnx4MbNWojQG7MTsoKtTDB20BFI3y4kzGqg51XpJLy6ZkLsbTtyHIILFjz9 OsWH2TB5VPysS1l3VlaJ6ucPqpfIYilno5eFBKcuOy9y1BpPeNmsML4NRX7qfzc52yef QufH3t0pYqiZ97vSDfz4JQDgAo9GL2AwOxbiLzJxTxVKDdtuL+bOjaWGGRSnXlKZnz8H 2udIJbW73XemxbOTD54ikB1I1ock5QE9dtaFRBqY2wkugYueQqT3nHmeSwYhbJjAwPuN v3u8BRtc/vI6Fc87+i67APLGdNhGTRYmMB5qcHId+OmL/L21x4qSgOZV5BQFIxi0kd0f LMMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=f4S4a9eZ; spf=pass (google.com: domain of linux-nfs+bounces-346-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-346-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id b13-20020a170903228d00b001bb8c4279f5si4010665plh.148.2023.12.05.13.59.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 13:59:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-346-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=f4S4a9eZ; spf=pass (google.com: domain of linux-nfs+bounces-346-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-346-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A4256281DCD for ; Tue, 5 Dec 2023 21:59:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D46486FCE8; Tue, 5 Dec 2023 21:58:55 +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="f4S4a9eZ" X-Original-To: linux-nfs@vger.kernel.org Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAD6C135 for ; Tue, 5 Dec 2023 13:58:49 -0800 (PST) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6ce6f4d3dafso196089b3a.0 for ; Tue, 05 Dec 2023 13:58:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1701813529; x=1702418329; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=LGvf0v3WO1jMmuVd3YQ6/5GaYR43CazhfwAsFHfc+Ck=; b=f4S4a9eZ4yRnQE+c/EYEZft+z5LwGHOMtwil4SftE9bKXVjoxszmqe0DyV3iZm1vjo tMIyEL5XRODyVrQ5kYoA6+Q2ygLf1i0UmwwNae/gUywStyqlJAmB7mwKsDVdkAwNGBD9 p0NUkvkrOj8aPkfQDXZ4eTusE987yRTOkZGDRysZAmWGP2FxbnZue0DVX/5Ey62c08Y1 dAO3AsO8Fk4FfE+nJKLLSol/XwAJr+4RIVck0p08z2QkNlF/a5SpJ1BVt5Q18JFqBZcl dchpBAwLWHqLEGn9XuI4ILb88hEANmvkNXgNg31I6eVMl6IrvruWLziC2GyL2NawVc7Z ajeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701813529; x=1702418329; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LGvf0v3WO1jMmuVd3YQ6/5GaYR43CazhfwAsFHfc+Ck=; b=A3f7YfG29deBCFqER6KqayT1WDCtAbvrGFP7Ax1cerWFabinUSyxIgIiAszKOTsXHh 1bp2hoq5d4mLWS/53KiKlByADczmrzNSbp0talKRzr2lTe21nqV7GnbRhL0hqPjb/WDt B+aL7CwItby+Poq90tYSK39RACVKS6TVhWUFP+HDDrFevYJY5JF6YYMtV+MTW+Rva/uM uq8KDfuxc/W5oU9+yDSWCvKDpOxxoMuNQoQmE6qlri/M9E/S8cUe6RRakPYIpJn9ypNM nA0K5W94gVU6XjTTRUfPxbrW/qk4uUN2DdLJBtrE7hHnNLlfO6zr6M7ezGkNFEjOKGEw M3Yg== X-Gm-Message-State: AOJu0YyDUW6E1Wddz3liDH7rgfaDq2gf6633kwNSUzf8n47U2P8sA7k9 7HIZJJ+Pyd6aFASVIOmADHsLPg== X-Received: by 2002:aa7:88c6:0:b0:6ce:4c49:58e4 with SMTP id k6-20020aa788c6000000b006ce4c4958e4mr8822580pff.0.1701813529029; Tue, 05 Dec 2023 13:58:49 -0800 (PST) Received: from [192.168.1.150] ([198.8.77.194]) by smtp.gmail.com with ESMTPSA id v14-20020aa7850e000000b006cde2889213sm1323983pfn.14.2023.12.05.13.58.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Dec 2023 13:58:48 -0800 (PST) Message-ID: Date: Tue, 5 Dec 2023 14:58: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 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> From: Jens Axboe In-Reply-To: <170181169515.7109.11121482729257102758@noble.neil.brown.name> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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. -- Jens Axboe