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

From: Jeff Layton

Date: Fri Nov 20 2026 - 11:42:51 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, whose prepare,
nfsd4_cb_recall_prepare(), takes deleg_lock and queues the delegation
on del_recall_lru only if it is hashed. If the prepare runs before the
hash, the delegation is granted already recalled, and is never put on
del_recall_lru, so the laundromat never revokes it if the client
doesn't return it.

Check fi_had_conflict again under deleg_lock. The break sets it before
queueing the recall, so a prepare that ran before the hash leaves it
set, and one that runs after finds the delegation hashed.

Before 5ea9a7c5fe41, the final check was made 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 fc01ff50c8b2..ea940d8759b0 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -7427,7 +7427,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 check above has
+ * queued a recall whose prepare takes deleg_lock, and that prepare
+ * doesn't queue an unhashed delegation for revocation. Granting
+ * the delegation then would leave a recalled delegation that the
+ * laundromat never revokes.
+ */
+ 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