Skip to contentSkip to conversation

nfsd: remove long-standing revoked delegations by force

PATCH Superseded Li Lingfeng 3 participants 5 messages Sep 5, 2025 – Oct 9, 2025

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 nfsd: remove long-standing revoked delegations by force

When file access conflicts occur between clients, the server recalls delegations. If the client holding delegation fails to return it after a recall, nfs4_laundromat adds the delegation to cl_revoked list. This causes subsequent SEQUENCE operations to set the SEQ4_STATUS_RECALLABLE_STATE_REVOKED flag, forcing the client to validate all delegations and return the revoked one.

However, if the client fails to return the delegation like this:
nfs4_laundromat nfsd4_delegreturn
unhash_delegation_locked
list_add // add dp to reaplist

          // by dl_recall_lru
 list_del_init // delete dp from
               // reaplist
                                       destroy_delegation
                                        unhash_delegation_locked
                                         // do nothing but return false
 revoke_delegation
 list_add // add dp to cl_revoked
          // by dl_recall_lru

The delegation will remain in the server's cl_revoked list while the client marks it revoked and won't find it upon detecting SEQ4_STATUS_RECALLABLE_STATE_REVOKED.
This leads to a loop:
the server persistently sets SEQ4_STATUS_RECALLABLE_STATE_REVOKED, and the client repeatedly tests all delegations, severely impacting performance when numerous delegations exist.

Since abnormal delegations are removed from flc_lease via nfs4_laundromat --> revoke_delegation --> destroy_unhashed_deleg --> nfs4_unlock_deleg_lease --> kernel_setlease, and do not block new open requests indefinitely, retaining such a delegation on the server is unnecessary.

Fixes 3bd64a5ba171 ("nfsd4: implement SEQ4_STATUS_RECALLABLE_STATE_REVOKED")

---
Changes in v2:
1) Set SC_STATUS_CLOSED unconditionally in destroy_delegation();
2) Determine whether to remove the delegation based on SC_STATUS_CLOSED,

     rather than by timeout;

3) Modify the commit message.

Changes in v3:
1) Move variables used for traversal inside the if statement;
2) Add a comment to explain why we have to do this;
3) Move the second check of cl_revoked inside the if statement of the first check.

 fs/nfsd/nfs4state.c | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)
fs/nfsd/nfs4state.c +33 -2
index 88c347957da5..20fae3449af6 100644
@@ -1336,6 +1336,11 @@ static void destroy_delegation(struct nfs4_delegation *dp)
 
 	spin_lock(&state_lock);
 	unhashed = unhash_delegation_locked(dp, SC_STATUS_CLOSED);
+	/*
+	 * Unconditionally set SC_STATUS_CLOSED, regardless of whether the
+	 * delegation is hashed, to mark the current delegation as invalid.
+	 */
+	dp->dl_stid.sc_status |= SC_STATUS_CLOSED;
 	spin_unlock(&state_lock);
 	if (unhashed)
 		destroy_unhashed_deleg(dp);
@@ -4470,8 +4475,34 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 	default:
 		seq->status_flags = 0;
 	}
-	if (!list_empty(&clp->cl_revoked))
-		seq->status_flags |= SEQ4_STATUS_RECALLABLE_STATE_REVOKED;
+	if (!list_empty(&clp->cl_revoked)) {
+		struct list_head *pos, *next;
+		struct nfs4_delegation *dp;
+
+		/*
+		 * Concurrent nfs4_laundromat() and nfsd4_delegreturn()
+		 * may add a delegation to cl_revoked even after the
+		 * client has returned it, causing persistent
+		 * SEQ4_STATUS_RECALLABLE_STATE_REVOKED, disrupting normal
+		 * operations.
+		 * Remove delegations with SC_STATUS_CLOSED from cl_revoked
+		 * to resolve.
+		 */
+		spin_lock(&clp->cl_lock);
+		list_for_each_safe(pos, next, &clp->cl_revoked) {
+			dp = list_entry(pos, struct nfs4_delegation, dl_recall_lru);
+			if (dp->dl_stid.sc_status & SC_STATUS_CLOSED) {
+				list_del_init(&dp->dl_recall_lru);
+				spin_unlock(&clp->cl_lock);
+				nfs4_put_stid(&dp->dl_stid);
+				spin_lock(&clp->cl_lock);
+			}
+		}
+		spin_unlock(&clp->cl_lock);
+
+		if (!list_empty(&clp->cl_revoked))
+			seq->status_flags |= SEQ4_STATUS_RECALLABLE_STATE_REVOKED;
+	}
 	if (atomic_read(&clp->cl_admin_revoked))
 		seq->status_flags |= SEQ4_STATUS_ADMIN_STATE_REVOKED;
 	trace_nfsd_seq4_status(rqstp, seq);
Signature · 1 line
2.46.1
maintainer
#1 lore raw

From: Chuck Lever <[email protected]>

Quoted 8 lines · Li Lingfeng

When file access conflicts occur between clients, the server recalls delegations. If the client holding delegation fails to return it after a recall, nfs4_laundromat adds the delegation to cl_revoked list. This causes subsequent SEQUENCE operations to set the SEQ4_STATUS_RECALLABLE_STATE_REVOKED flag, forcing the client to validate all delegations and return the revoked one.

[...]

Applied to nfsd-testing, thanks!

[1/1] nfsd: remove long-standing revoked delegations by force

      commit: 5f5838c5e1b399371e3e4f45a79ce822eb6ee4cc

--
Chuck Lever

#2 lore raw
In reply to Li Lingfeng
Quoted 86 lines · Li Lingfeng

When file access conflicts occur between clients, the server recalls delegations. If the client holding delegation fails to return it after a recall, nfs4_laundromat adds the delegation to cl_revoked list. This causes subsequent SEQUENCE operations to set the SEQ4_STATUS_RECALLABLE_STATE_REVOKED flag, forcing the client to validate all delegations and return the revoked one.

However, if the client fails to return the delegation like this:
nfs4_laundromat nfsd4_delegreturn
unhash_delegation_locked
list_add // add dp to reaplist

          // by dl_recall_lru
 list_del_init // delete dp from
               // reaplist
                                       destroy_delegation
                                        unhash_delegation_locked
                                         // do nothing but return false
 revoke_delegation
 list_add // add dp to cl_revoked
          // by dl_recall_lru

The delegation will remain in the server's cl_revoked list while the client marks it revoked and won't find it upon detecting SEQ4_STATUS_RECALLABLE_STATE_REVOKED.
This leads to a loop:
the server persistently sets SEQ4_STATUS_RECALLABLE_STATE_REVOKED, and the client repeatedly tests all delegations, severely impacting performance when numerous delegations exist.

Since abnormal delegations are removed from flc_lease via nfs4_laundromat --> revoke_delegation --> destroy_unhashed_deleg --> nfs4_unlock_deleg_lease --> kernel_setlease, and do not block new open requests indefinitely, retaining such a delegation on the server is unnecessary.

Fixes 3bd64a5ba171 ("nfsd4: implement SEQ4_STATUS_RECALLABLE_STATE_REVOKED")

---
Changes in v2:
1) Set SC_STATUS_CLOSED unconditionally in destroy_delegation();
2) Determine whether to remove the delegation based on SC_STATUS_CLOSED,

     rather than by timeout;

3) Modify the commit message.

Changes in v3:
1) Move variables used for traversal inside the if statement;
2) Add a comment to explain why we have to do this;
3) Move the second check of cl_revoked inside the if statement of the first check.

 fs/nfsd/nfs4state.c | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)
fs/nfsd/nfs4state.c +14 -2
index 88c347957da5..20fae3449af6 100644
@@ -1336,6 +1336,11 @@ static void destroy_delegation(struct nfs4_delegation *dp)
 
 	spin_lock(&state_lock);
 	unhashed = unhash_delegation_locked(dp, SC_STATUS_CLOSED);
+	/*
+	 * Unconditionally set SC_STATUS_CLOSED, regardless of whether the
+	 * delegation is hashed, to mark the current delegation as invalid.
+	 */
+	dp->dl_stid.sc_status |= SC_STATUS_CLOSED;
 	spin_unlock(&state_lock);
 	if (unhashed)
 		destroy_unhashed_deleg(dp);
@@ -4470,8 +4475,34 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 	default:
 		seq->status_flags = 0;
 	}
-	if (!list_empty(&clp->cl_revoked))
-		seq->status_flags |= SEQ4_STATUS_RECALLABLE_STATE_REVOKED;
+	if (!list_empty(&clp->cl_revoked)) {
+		struct list_head *pos, *next;
+		struct nfs4_delegation *dp;
+
+		/*
+		 * Concurrent nfs4_laundromat() and nfsd4_delegreturn()
+		 * may add a delegation to cl_revoked even after the
+		 * client has returned it, causing persistent
+		 * SEQ4_STATUS_RECALLABLE_STATE_REVOKED, disrupting normal

fs/nfsd/nfs4state.c nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 4496

Quoted 10 lines
fs/nfsd/nfs4state.c +10 -0
+		 * operations.
+		 * Remove delegations with SC_STATUS_CLOSED from cl_revoked
+		 * to resolve.
+		 */
+		spin_lock(&clp->cl_lock);
+		list_for_each_safe(pos, next, &clp->cl_revoked) {
+			dp = list_entry(pos, struct nfs4_delegation, dl_recall_lru);
+			if (dp->dl_stid.sc_status & SC_STATUS_CLOSED) {
+				list_del_init(&dp->dl_recall_lru);
+				spin_unlock(&clp->cl_lock);

Does unlocking cl_lock here allow another CPU to free the object that @next is pointing to? That pointer address would then be dereferenced on the next loop iteration.

Might be better to stuff dp onto a local list, then "put" all the items on that list once this loop has terminated and cl_lock has been released.

Quoted 12 lines
fs/nfsd/nfs4state.c +9 -0
+				nfs4_put_stid(&dp->dl_stid);
+				spin_lock(&clp->cl_lock);
+			}
+		}
+		spin_unlock(&clp->cl_lock);
+
+		if (!list_empty(&clp->cl_revoked))
+			seq->status_flags |= SEQ4_STATUS_RECALLABLE_STATE_REVOKED;
+	}
 	if (atomic_read(&clp->cl_admin_revoked))
 		seq->status_flags |= SEQ4_STATUS_ADMIN_STATE_REVOKED;
 	trace_nfsd_seq4_status(rqstp, seq);
Signature · 1 line
Chuck Lever
#3 lore raw
Quoted 102 lines · Chuck Lever
Quoted 86 lines · Li Lingfeng

When file access conflicts occur between clients, the server recalls delegations. If the client holding delegation fails to return it after a recall, nfs4_laundromat adds the delegation to cl_revoked list. This causes subsequent SEQUENCE operations to set the SEQ4_STATUS_RECALLABLE_STATE_REVOKED flag, forcing the client to validate all delegations and return the revoked one.

However, if the client fails to return the delegation like this:
nfs4_laundromat nfsd4_delegreturn
unhash_delegation_locked
list_add // add dp to reaplist

          // by dl_recall_lru
 list_del_init // delete dp from
               // reaplist
                                       destroy_delegation
                                        unhash_delegation_locked
                                         // do nothing but return false
 revoke_delegation
 list_add // add dp to cl_revoked
          // by dl_recall_lru

The delegation will remain in the server's cl_revoked list while the client marks it revoked and won't find it upon detecting SEQ4_STATUS_RECALLABLE_STATE_REVOKED.
This leads to a loop:
the server persistently sets SEQ4_STATUS_RECALLABLE_STATE_REVOKED, and the client repeatedly tests all delegations, severely impacting performance when numerous delegations exist.

Since abnormal delegations are removed from flc_lease via nfs4_laundromat --> revoke_delegation --> destroy_unhashed_deleg --> nfs4_unlock_deleg_lease --> kernel_setlease, and do not block new open requests indefinitely, retaining such a delegation on the server is unnecessary.

Fixes 3bd64a5ba171 ("nfsd4: implement SEQ4_STATUS_RECALLABLE_STATE_REVOKED")

---
Changes in v2:
1) Set SC_STATUS_CLOSED unconditionally in destroy_delegation();
2) Determine whether to remove the delegation based on SC_STATUS_CLOSED,

     rather than by timeout;

3) Modify the commit message.

Changes in v3:
1) Move variables used for traversal inside the if statement;
2) Add a comment to explain why we have to do this;
3) Move the second check of cl_revoked inside the if statement of the first check.

 fs/nfsd/nfs4state.c | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)
fs/nfsd/nfs4state.c +14 -2
index 88c347957da5..20fae3449af6 100644
@@ -1336,6 +1336,11 @@ static void destroy_delegation(struct nfs4_delegation *dp)
 
 	spin_lock(&state_lock);
 	unhashed = unhash_delegation_locked(dp, SC_STATUS_CLOSED);
+	/*
+	 * Unconditionally set SC_STATUS_CLOSED, regardless of whether the
+	 * delegation is hashed, to mark the current delegation as invalid.
+	 */
+	dp->dl_stid.sc_status |= SC_STATUS_CLOSED;
 	spin_unlock(&state_lock);
 	if (unhashed)
 		destroy_unhashed_deleg(dp);
@@ -4470,8 +4475,34 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 	default:
 		seq->status_flags = 0;
 	}
-	if (!list_empty(&clp->cl_revoked))
-		seq->status_flags |= SEQ4_STATUS_RECALLABLE_STATE_REVOKED;
+	if (!list_empty(&clp->cl_revoked)) {
+		struct list_head *pos, *next;
+		struct nfs4_delegation *dp;
+
+		/*
+		 * Concurrent nfs4_laundromat() and nfsd4_delegreturn()
+		 * may add a delegation to cl_revoked even after the
+		 * client has returned it, causing persistent
+		 * SEQ4_STATUS_RECALLABLE_STATE_REVOKED, disrupting normal

fs/nfsd/nfs4state.c nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 4496

Quoted 10 lines
fs/nfsd/nfs4state.c +10 -0
+		 * operations.
+		 * Remove delegations with SC_STATUS_CLOSED from cl_revoked
+		 * to resolve.
+		 */
+		spin_lock(&clp->cl_lock);
+		list_for_each_safe(pos, next, &clp->cl_revoked) {
+			dp = list_entry(pos, struct nfs4_delegation, dl_recall_lru);
+			if (dp->dl_stid.sc_status & SC_STATUS_CLOSED) {
+				list_del_init(&dp->dl_recall_lru);
+				spin_unlock(&clp->cl_lock);

Does unlocking cl_lock here allow another CPU to free the object that @next is pointing to? That pointer address would then be dereferenced on the next loop iteration.

Quoted 3 lines

Might be better to stuff dp onto a local list, then "put" all the items on that list once this loop has terminated and cl_lock has been released.

I intended to include this patch in nfsd-next for v6.18, but since I haven't gotten a response, I have dropped it for now.

When we get closure on my question above, I am happy to requeue it for a later merge window.

Quoted 14 lines
Quoted 12 lines
fs/nfsd/nfs4state.c +9 -0
+				nfs4_put_stid(&dp->dl_stid);
+				spin_lock(&clp->cl_lock);
+			}
+		}
+		spin_unlock(&clp->cl_lock);
+
+		if (!list_empty(&clp->cl_revoked))
+			seq->status_flags |= SEQ4_STATUS_RECALLABLE_STATE_REVOKED;
+	}
 	if (atomic_read(&clp->cl_admin_revoked))
 		seq->status_flags |= SEQ4_STATUS_ADMIN_STATE_REVOKED;
 	trace_nfsd_seq4_status(rqstp, seq);
Signature · 1 line
Chuck Lever
#4 lore raw

Hi,

Quoted 93 lines · Chuck Lever
Quoted 92 lines · Chuck Lever
Quoted 91 lines · Li Lingfeng

When file access conflicts occur between clients, the server recalls delegations. If the client holding delegation fails to return it after a recall, nfs4_laundromat adds the delegation to cl_revoked list. This causes subsequent SEQUENCE operations to set the SEQ4_STATUS_RECALLABLE_STATE_REVOKED flag, forcing the client to validate all delegations and return the revoked one.

However, if the client fails to return the delegation like this:
nfs4_laundromat nfsd4_delegreturn
unhash_delegation_locked
list_add // add dp to reaplist

           // by dl_recall_lru
  list_del_init // delete dp from
                // reaplist
                                        destroy_delegation
                                         unhash_delegation_locked
                                          // do nothing but return false
  revoke_delegation
  list_add // add dp to cl_revoked
           // by dl_recall_lru

The delegation will remain in the server's cl_revoked list while the client marks it revoked and won't find it upon detecting SEQ4_STATUS_RECALLABLE_STATE_REVOKED.
This leads to a loop:
the server persistently sets SEQ4_STATUS_RECALLABLE_STATE_REVOKED, and the client repeatedly tests all delegations, severely impacting performance when numerous delegations exist.

Since abnormal delegations are removed from flc_lease via nfs4_laundromat --> revoke_delegation --> destroy_unhashed_deleg --> nfs4_unlock_deleg_lease --> kernel_setlease, and do not block new open requests indefinitely, retaining such a delegation on the server is unnecessary.

Fixes 3bd64a5ba171 ("nfsd4: implement SEQ4_STATUS_RECALLABLE_STATE_REVOKED")

---
Changes in v2:
1) Set SC_STATUS_CLOSED unconditionally in destroy_delegation();
2) Determine whether to remove the delegation based on SC_STATUS_CLOSED,

      rather than by timeout;

3) Modify the commit message.

Changes in v3:
1) Move variables used for traversal inside the if statement;
2) Add a comment to explain why we have to do this;
3) Move the second check of cl_revoked inside the if statement of the first check.

  fs/nfsd/nfs4state.c | 35 +++++++++++++++++++++++++++++++++--
  1 file changed, 33 insertions(+), 2 deletions(-)
fs/nfsd/nfs4state.c +19 -2
index 88c347957da5..20fae3449af6 100644
@@ -1336,6 +1336,11 @@ static void destroy_delegation(struct nfs4_delegation *dp)
 
  	spin_lock(&state_lock);
  	unhashed = unhash_delegation_locked(dp, SC_STATUS_CLOSED);
+	/*
+	 * Unconditionally set SC_STATUS_CLOSED, regardless of whether the
+	 * delegation is hashed, to mark the current delegation as invalid.
+	 */
+	dp->dl_stid.sc_status |= SC_STATUS_CLOSED;
  	spin_unlock(&state_lock);
  	if (unhashed)
  		destroy_unhashed_deleg(dp);
@@ -4470,8 +4475,34 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  	default:
  		seq->status_flags = 0;
  	}
-	if (!list_empty(&clp->cl_revoked))
-		seq->status_flags |= SEQ4_STATUS_RECALLABLE_STATE_REVOKED;
+	if (!list_empty(&clp->cl_revoked)) {
+		struct list_head *pos, *next;
+		struct nfs4_delegation *dp;
+
+		/*
+		 * Concurrent nfs4_laundromat() and nfsd4_delegreturn()
+		 * may add a delegation to cl_revoked even after the
+		 * client has returned it, causing persistent
+		 * SEQ4_STATUS_RECALLABLE_STATE_REVOKED, disrupting normal
+		 * operations.
+		 * Remove delegations with SC_STATUS_CLOSED from cl_revoked
+		 * to resolve.
+		 */
+		spin_lock(&clp->cl_lock);
Quoted 8 lines
Quoted 8 lines

fs/nfsd/nfs4state.c nfsd4_sequence(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 4496

Quoted 5 lines
fs/nfsd/nfs4state.c +5 -0
+		list_for_each_safe(pos, next, &clp->cl_revoked) {
+			dp = list_entry(pos, struct nfs4_delegation, dl_recall_lru);
+			if (dp->dl_stid.sc_status & SC_STATUS_CLOSED) {
+				list_del_init(&dp->dl_recall_lru);
+				spin_unlock(&clp->cl_lock);

Does unlocking cl_lock here allow another CPU to free the object that @next is pointing to? That pointer address would then be dereferenced on the next loop iteration.

I understand the problem as follows:
    CPU1                                    CPU2
list: cl_revoked-->dp1-->dp2-->dp3-->...
spin_lock
pos = dp1
next = dp2
list: cl_revoked-->dp2-->dp3-->...
spin_unlock
                                        spin_lock
                                        // remove and free dp2
                                        list: cl_revoked-->dp3-->... spin_unlock spin_lock
pos = next = dp2
next = dp2->next // UAF

Apologies for the problem caused by my insufficient understanding of list_for_each_safe.

Quoted 3 lines
Quoted 3 lines

Might be better to stuff dp onto a local list, then "put" all the items on that list once this loop has terminated and cl_lock has been released.

Thank you for your advice, I will send v4 soon.

Quoted 5 lines

I intended to include this patch in nfsd-next for v6.18, but since I haven't gotten a response, I have dropped it for now.

When we get closure on my question above, I am happy to requeue it for a later merge window.

Please accept my apologies for the belated reply. I have been on a break for the National Day holiday and have just returned to work.

Quoted 18 lines
Quoted 14 lines
Quoted 13 lines
fs/nfsd/nfs4state.c +9 -0
+				nfs4_put_stid(&dp->dl_stid);
+				spin_lock(&clp->cl_lock);
+			}
+		}
+		spin_unlock(&clp->cl_lock);
+
+		if (!list_empty(&clp->cl_revoked))
+			seq->status_flags |= SEQ4_STATUS_RECALLABLE_STATE_REVOKED;
+	}
  	if (atomic_read(&clp->cl_admin_revoked))
  		seq->status_flags |= SEQ4_STATUS_ADMIN_STATE_REVOKED;
  	trace_nfsd_seq4_status(rqstp, seq);