[PATCH v2 10/11] nfsd: check fi_had_conflict under deleg_lock before hashing a delegation

From: Jeff Layton

Date: Mon Nov 23 2026 - 08:00:08 EST


nfs4_set_delegation() checks fi_had_conflict without a lock, then takes
deleg_lock and hashes the delegation. A lease break in between sets
fi_had_conflict and queues the recall. The recall's prepare callback,
nfsd4_cb_recall_prepare(), takes deleg_lock and puts the delegation on
del_recall_lru only if the delegation is hashed. If the prepare runs
before the hash, NFSD grants a delegation that is already recalled but
not on del_recall_lru. The laundromat then never revokes the delegation
if the client does not return it.

Check fi_had_conflict again under deleg_lock. The break sets
fi_had_conflict before queueing the recall. A prepare that ran before
the hash therefore left fi_had_conflict set, and a prepare that runs
after the hash finds the delegation hashed.

Before 5ea9a7c5fe41, nfs4_set_delegation() made the final check under
fi_lock, which nfsd_break_deleg_cb() also took.

Fixes: 5ea9a7c5fe41 ("nfsd: don't take fi_lock in nfsd_break_deleg_cb()")
Signed-off-by: Jeff Layton <jlayton@xxxxxxxxxx>
---
fs/nfsd/nfs4state.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 466416708072..9ea3b0e9b7ec 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -7428,7 +7428,17 @@ nfs4_set_delegation(struct nfsd4_open *open,
spin_lock(&nn->deleg_lock);
spin_lock(&clp->cl_lock);
spin_lock(&fp->fi_lock);
- status = hash_delegation_locked(dp, fp);
+ /*
+ * Check again under deleg_lock. A break after the unlocked check
+ * has queued a recall whose prepare takes deleg_lock. The prepare
+ * doesn't queue an unhashed delegation for revocation, so the
+ * laundromat would never revoke a delegation granted after the
+ * break.
+ */
+ if (fp->fi_had_conflict)
+ status = -EAGAIN;
+ else
+ status = hash_delegation_locked(dp, fp);
if (status == -EEXIST) {
held = nfs4_delegation_exists(clp, fp);
*held_type = held->dl_type;

--
2.56.1