Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796411323; b=f+zhVzEKOHLjf2dE6RdJHUPsTSYzR7nGbFWeEKXhH/7G1z5W8AqUG6Blo70VrebvbaHB RVsiFDXPUITNIc9FX6tr1lE2zoAhdk8qFPDufCN2Ui8QOylAnyBd497Vvo5Mel2wVgLae 7xPccSxILqnc3axweK45rrHblTBTyjN0ipcR20vFckNXLIPAt2hmCZpaca1/MaMJA7dW0 ro+WazgIkwqcWyjaSuYcVEqESMqQamp6UxPdRjCRw1Mcy7ZZ/JYwgskEu2e0aQcCW+vyr GhgP27HoE1ct9P8vm7+boGklcVaQwqWkKpvftk+HXK0kfiUMjKLzHN1alC1XRYQV5wg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796411323; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=mnxjakLAsjLPZTWWFzdXtQdu6gGLJoUgTUMUUl7xC8Q=; b=cn0s0gr3fLceoeddrN9cizqnyCVDKbzW8avHLRxGFvK70Qn/od+AQ5JuMeVCIK+dAt3t Vjlh2UPLF//ArOM50JYBuh0kayEe8qL6YW5yKdj/yTR7haeuB8dT5vfBtQ6rvJmAAGkOz xnEoXuWI2lKHGgb7BMjz3MkPfRY+1QnW9ibJStOoKuNlU+g3srs0FPMmhm3HfUgUcOwam D8eIOKkivpHUIhPE+GUFlqLm0HbKslFuaOQ7N6R7Oed0PxqGgu46cNb0AzZeD8agDWNBg iJaVUIXH2zZy/nCAdxi0BBPMJZftETg4inobORNjZtKUk9p1twi69YOG2XdIMb3yxAw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=B4KixMTX; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35228606A322 for ; Fri, 4 Dec 2026 19:08:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=B4KixMTX Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED6FD1F00A07; Fri, 4 Dec 2026 19:08:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796411322; bh=mnxjakLAsjLPZTWWFzdXtQdu6gGLJoUgTUMUUl7xC8Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=B4KixMTXHOs2p0f2uHuNBU4+lG7f8zr7SFeAIM/vutbq82QNjm1rs+QFRhkN5s9BU 6qY0AYTkFr44DwnWQa7mQDVACnR9pVBqYXFON0tNmVfKKqEPttAwNkWII5BCyaf8dK JAuQ9gTeD3l9xsoywjyNzewIokKJf3XcP+PLQ7T3wH58oQPa+xFEWVFec2FxsfUhgW MJyIZfAIF7+fjuVU7VlgAgmrFYnyghqZ1xCG5Y6RGUNGwoIDhVZrg+LtGVaqxruVQ5 21D7v7yWdYjsRup1nymhiUa9GeYmhO6wkMf1Hgdx4B4oXVY1QflEyymVH0vUjfQuPD mzQAEPK0KrBHw== From: Jeff Layton Date: Fri, 04 Dec 2026 14:08:25 -0500 Subject: [PATCH 1/3] NFSD: don't recall a LOCALIO client's own delegations X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261204-localio-deleg-v1-1-9dcb7d24e425@kernel.org> References: <20261204-localio-deleg-v1-0-9dcb7d24e425@kernel.org> In-Reply-To: <20261204-localio-deleg-v1-0-9dcb7d24e425@kernel.org> To: Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Weston Andros Adamson , Mike Snitzer Cc: Anna Schumaker , linux-nfs@vger.kernel.org, Trond Myklebust , Jeff Layton X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=11804; i=jlayton@kernel.org; h=from:subject:message-id; bh=MQsPyQuxQFOLkeTchj+FWLveyzRzY4IyVMgZqYkXoCM=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBrEw+4AbxFJUF9ocp/XxPEUyyVJ++2W0IfUkeRJ vq/tgNu+X6JAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCaxMPuAAKCRAADmhBGVaC FdqxD/kB83SQ4yU6Gk3HO8113Imbb4EYPU1ik+4ks4pBsmYsACxbPws6WbwmzovewyToW9rY1AR HQLNWjltTOkimZ8+zJe7sUt0LE0PN/zaRx+L7fC6S68wtREgy1I4J0QOw5ZdfTFlkNrJ1kWYZhE QlNiovlHxkmVIgUGp9Q9UepGGwQmuZhK2PnHEo6tPnj0Q+I42botvAi1EhZRB6UZ2Hpmcvy2Qki iR93E5xhsLFtMETh6+KLDpsxbKaOYfeo9VVX9pUhUoDaYXG8TXjEg6sa8/plwIpE7I0CyX84Vt8 X6R+Y48Gwsh9l3ZZYyDoRIuD83SV35N1iK05Te1dUA8WTCpGrH8tNRfBueWsZVl+4RHwjq9nDqo Tl9H44c7eOd9KUB18/G+xv4aSUQgYUNfsDEg2NohROY5l5fCqiDZkBhYHa54L5562nhGQb7dXWt QiaubyVyyzcoYLoKdk5UNaLplYEmS3bhyDksQxUW4koeOno7KTU22LK9DDJNaigRlgIwzZM7ju/ h8qa5uYhZlyLKUqDd8wGHFS7Ey9SpCVe89yPVkShA7ZyAyF361yYr4KjjFLyxVopt7cOS8U2OYj ckMUgRPDplF3yRg7UCtyYfe+JBa+sqlHB/IoM7CSjzZcpNJno2EmiEIyuyKkvsCS4e0K6jMWnff 6KpRC4TCQO7k6LQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Opening a file for LOCALIO breaks leases like any other nfsd open, but it runs in the NFS client's task, not in an nfsd thread. nfsd_breaker_owns_lease() identifies the breaker through the svc_rqst of the current nfsd thread, finds none, and treats the client's own delegation as a conflict. So the client's first LOCALIO read or write recalls its own delegation: nfsd_cb_recall <- nfsd_break_deleg_cb <- __break_lease <- nfsd_file_do_acquire <- nfsd_file_acquire_local <- nfsd_open_local_fh <- nfs_open_local_fh <- nfs_local_open_fh The open fails with NFS4ERR_DELAY, that I/O goes over the wire, and the client returns the delegation. A LOCALIO client never keeps a write delegation past its first I/O. When the open misses the nfsd_file cache, do_dentry_open() breaks leases again, and since that break can block, the open would also wait for the recall to complete. Let the caller of nfsd_open_local_fh() pass the NFSv4 client ID of the client whose open state covers the I/O. While nfsd opens the file, it records that client ID against the current task, on a list in the server's network namespace. When there is no svc_rqst, nfsd_breaker_owns_lease() looks the task up on the list of the namespace of the client holding the delegation, and compares the ID with that client's. This covers nfsd's own lease break and the one in do_dentry_open(). Other clients' delegations are still recalled, and so is every delegation when the client ID is 0 or doesn't name the client holding it. The client itself isn't looked up or pinned. nfsd shutdown destroys clients and frees the client tables without waiting for LOCALIO opens in progress, and the delegation being broken pins its client anyway. The client ID can't be inferred from the LOCALIO handshake: the I/O may come from an NFSv3 nfs_client, as with flexfiles data servers, while the delegation belongs to the NFSv4 client of the metadata server. Nothing passes a client ID yet. Fixes: fa4983862e50 ("nfsd: add LOCALIO support") Signed-off-by: Jeff Layton --- fs/nfs_common/nfslocalio.c | 2 +- fs/nfsd/localio.c | 14 ++++++++- fs/nfsd/netns.h | 3 ++ fs/nfsd/nfs4state.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/nfsctl.c | 2 ++ fs/nfsd/state.h | 22 +++++++++++++ include/linux/nfslocalio.h | 2 +- 7 files changed, 120 insertions(+), 3 deletions(-) diff --git a/fs/nfs_common/nfslocalio.c b/fs/nfs_common/nfslocalio.c index b2b8d7c3d93e..e77e42c2d567 100644 --- a/fs/nfs_common/nfslocalio.c +++ b/fs/nfs_common/nfslocalio.c @@ -365,7 +365,7 @@ struct nfsd_file *nfs_open_local_fh(nfs_uuid_t *uuid, rcu_read_unlock(); /* We have an implied reference to net thanks to nfsd_net_try_get */ localio = nfs_to->nfsd_open_local_fh(net, dom, rpc_clnt, cred, - nfs_fh, pnf, fmode); + nfs_fh, pnf, fmode, 0); if (!IS_ERR(localio) && nfs_uuid_add_file(uuid, nfl) < 0) { /* * Delete the cached file when racing with nfs_uuid_put(). diff --git a/fs/nfsd/localio.c b/fs/nfsd/localio.c index 33b56d1b3f44..c735f1f4e9eb 100644 --- a/fs/nfsd/localio.c +++ b/fs/nfsd/localio.c @@ -21,6 +21,7 @@ #include "netns.h" #include "filecache.h" #include "cache.h" +#include "state.h" /** * nfsd_open_local_fh - lookup a local filehandle @nfs_fh and map to nfsd_file @@ -32,6 +33,8 @@ * @nfs_fh: filehandle to lookup * @pnf: place to find the nfsd_file, or store it if it was non-NULL * @fmode: fmode_t to use for open + * @clientid: NFSv4 client ID of the NFS client whose open state covers the + * I/O, or 0. Its delegations aren't recalled by this open. * * This function maps a local fh to a path on a local filesystem. * This is useful when the nfs client has the local server mounted - it can @@ -45,9 +48,10 @@ static struct nfsd_file * nfsd_open_local_fh(struct net *net, struct auth_domain *dom, struct rpc_clnt *rpc_clnt, const struct cred *cred, const struct nfs_fh *nfs_fh, struct nfsd_file __rcu **pnf, - const fmode_t fmode) + const fmode_t fmode, u64 clientid) { int mayflags = NFSD_MAY_LOCALIO; + struct nfsd_localio_breaker breaker; struct svc_cred rq_cred; struct svc_fh fh; struct nfsd_file *localio; @@ -77,8 +81,16 @@ nfsd_open_local_fh(struct net *net, struct auth_domain *dom, svcauth_map_clnt_to_svc_cred_local(rpc_clnt, cred, &rq_cred); + /* + * Opening the file breaks leases, both in nfsd and in the VFS, from + * this task. Tell nfsd_breaker_owns_lease() which client that is. + */ + if (clientid) + nfsd4_localio_breaker_begin(net, clientid, &breaker); beres = nfsd_file_acquire_local(net, &rq_cred, dom, &fh, mayflags, &localio); + if (clientid) + nfsd4_localio_breaker_end(net, &breaker); if (beres) localio = ERR_PTR(nfs_stat_to_errno(be32_to_cpu(beres))); diff --git a/fs/nfsd/netns.h b/fs/nfsd/netns.h index 16be473f2c04..8ab306111251 100644 --- a/fs/nfsd/netns.h +++ b/fs/nfsd/netns.h @@ -277,6 +277,9 @@ struct nfsd_net { /* Local clients to be invalidated when net is shut down */ spinlock_t local_clients_lock; struct list_head local_clients; + /* LOCALIO opens in progress: struct nfsd_localio_breaker */ + spinlock_t localio_breakers_lock; + struct list_head localio_breakers; #endif siphash_key_t *fh_key; diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 45c105a1fd2b..ff1e3d749a31 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4150,6 +4150,81 @@ find_confirmed_client(clientid_t *clid, bool sessions, struct nfsd_net *nn) return find_client_in_id_table(tbl, clid, sessions); } +#if IS_ENABLED(CONFIG_NFS_LOCALIO) +/** + * nfsd4_localio_breaker_begin - say which client a LOCALIO open is for + * @net: network namespace of the server + * @clientid: client ID as the NFS client decoded it, as a big-endian hyper + * @b: record to fill in, valid until nfsd4_localio_breaker_end() + * + * The NFS client passes the client ID that SETCLIENTID or EXCHANGE_ID gave + * it. Until nfsd4_localio_breaker_end(), lease breaks from the current task + * spare that client's delegations, as they would for its own requests. An + * ID that names no client of @net spares nothing. @b goes on a list in @net, + * which is only looked up when a lease is broken outside an nfsd thread. + * + * Only the ID is recorded. The client isn't looked up or pinned: nfsd + * shutdown destroys clients while LOCALIO opens may still be in progress. + * A delegation pins its client, so nfsd4_localio_breaker_is() compares the + * ID with the client of the delegation being broken instead. + */ +void nfsd4_localio_breaker_begin(struct net *net, u64 clientid, + struct nfsd_localio_breaker *b) +{ + struct nfsd_net *nn = net_generic(net, nfsd_net_id); + __be64 raw = cpu_to_be64(clientid); + + BUILD_BUG_ON(sizeof(b->clid) != sizeof(raw)); + /* The clientid4 goes on the wire as the raw bytes of a clientid_t */ + memcpy(&b->clid, &raw, sizeof(b->clid)); + b->task = current; + spin_lock(&nn->localio_breakers_lock); + list_add(&b->list, &nn->localio_breakers); + spin_unlock(&nn->localio_breakers_lock); +} + +/** + * nfsd4_localio_breaker_end - end a nfsd4_localio_breaker_begin() section + * @net: network namespace passed to nfsd4_localio_breaker_begin() + * @b: record set up by nfsd4_localio_breaker_begin() + */ +void nfsd4_localio_breaker_end(struct net *net, struct nfsd_localio_breaker *b) +{ + struct nfsd_net *nn = net_generic(net, nfsd_net_id); + + spin_lock(&nn->localio_breakers_lock); + list_del(&b->list); + spin_unlock(&nn->localio_breakers_lock); +} + +/* Is the current task a LOCALIO open on behalf of @clp? */ +static bool nfsd4_localio_breaker_is(struct nfs4_client *clp) +{ + /* Client IDs are only unique within one server: look in @clp's net */ + struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id); + struct nfsd_localio_breaker *b; + bool ret = false; + + /* The current task's own record, if any, was added by this task */ + if (list_empty_careful(&nn->localio_breakers)) + return false; + spin_lock(&nn->localio_breakers_lock); + list_for_each_entry(b, &nn->localio_breakers, list) { + if (b->task == current) { + ret = same_clid(&b->clid, &clp->cl_clientid); + break; + } + } + spin_unlock(&nn->localio_breakers_lock); + return ret; +} +#else +static bool nfsd4_localio_breaker_is(struct nfs4_client *clp) +{ + return false; +} +#endif + static struct nfs4_client * find_unconfirmed_client(clientid_t *clid, bool sessions, struct nfsd_net *nn) { @@ -6551,6 +6626,9 @@ static bool nfsd_breaker_owns_lease(struct file_lease *fl) return false; rqst = nfsd_current_rqst(); + /* Not an nfsd thread: maybe a LOCALIO open */ + if (!rqst) + return nfsd4_localio_breaker_is(dl->dl_stid.sc_client); if (!nfsd_v4client(rqst)) return false; ntli = rqst->rq_private; diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c index b4411b253ad8..352a4c896252 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c @@ -3068,6 +3068,8 @@ static __net_init int nfsd_net_init(struct net *net) #if IS_ENABLED(CONFIG_NFS_LOCALIO) spin_lock_init(&nn->local_clients_lock); INIT_LIST_HEAD(&nn->local_clients); + spin_lock_init(&nn->localio_breakers_lock); + INIT_LIST_HEAD(&nn->localio_breakers); #endif return 0; diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index 7afdf6ef6727..8036b01e0725 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -997,12 +997,26 @@ static inline void get_nfs4_file(struct nfs4_file *fi) } struct nfsd_file *find_any_file(struct nfs4_file *f); +/* + * A LOCALIO open runs in the NFS client's task, not in an nfsd thread, so + * the lease breaks it causes can't be tied to an NFSv4 client through the + * svc_rqst. This records which client the task is opening the file for. + */ +struct nfsd_localio_breaker { + struct list_head list; + struct task_struct *task; + clientid_t clid; +}; + #ifdef CONFIG_NFSD_V4 void nfsd4_revoke_states(struct nfsd_net *nn, struct super_block *sb); void nfsd4_revoke_export_states(struct nfsd_net *nn, const struct path *path); void nfsd4_cancel_copy_by_sb(struct net *net, struct super_block *sb); int nfsd_net_cb_init(struct nfsd_net *nn); void nfsd_net_cb_shutdown(struct nfsd_net *nn); +void nfsd4_localio_breaker_begin(struct net *net, u64 clientid, + struct nfsd_localio_breaker *b); +void nfsd4_localio_breaker_end(struct net *net, struct nfsd_localio_breaker *b); #else static inline void nfsd4_revoke_states(struct nfsd_net *nn, struct super_block *sb) { @@ -1021,6 +1035,14 @@ static inline int nfsd_net_cb_init(struct nfsd_net *nn) static inline void nfsd_net_cb_shutdown(struct nfsd_net *nn) { } +static inline void nfsd4_localio_breaker_begin(struct net *net, u64 clientid, + struct nfsd_localio_breaker *b) +{ +} +static inline void nfsd4_localio_breaker_end(struct net *net, + struct nfsd_localio_breaker *b) +{ +} #endif /* grace period management */ diff --git a/include/linux/nfslocalio.h b/include/linux/nfslocalio.h index 914246e3f342..6b4746dde88a 100644 --- a/include/linux/nfslocalio.h +++ b/include/linux/nfslocalio.h @@ -78,7 +78,7 @@ struct nfsd_localio_operations { const struct cred *, const struct nfs_fh *, struct nfsd_file __rcu **pnf, - const fmode_t); + const fmode_t, u64 clientid); struct net *(*nfsd_file_put_local)(struct nfsd_file __rcu **); struct file *(*nfsd_file_file)(struct nfsd_file *); void (*nfsd_file_dio_alignment)(struct nfsd_file *, -- 2.56.1