Skip to contentSkip to conversation

nfsd: fix net-namespace logic in __nfsd_file_cache_purge

PATCH Superseded Jeff Layton 2 participants 2 messages Oct 31, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jeff Layton

author maintainer
#0 lore raw

PATCH 1/1 nfsd: fix net-namespace logic in __nfsd_file_cache_purge

If the namespace doesn't match the one in "net", then we'll continue, but that doesn't cause another rhashtable_walk_next call, so it will loop infinitely.

Fixes ce502f81ba88 ("NFSD: Convert the filecache to use rhashtable")
---
 fs/nfsd/filecache.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

This should probably go to stable too.

fs/nfsd/filecache.c +9 -11
index eeed4ae5b4ad..f9ea89057ae8 100644
@@ -908,19 +908,17 @@ __nfsd_file_cache_purge(struct net *net)
 
 		nf = rhashtable_walk_next(&iter);
 		while (!IS_ERR_OR_NULL(nf)) {
-			if (net && nf->nf_net != net)
-				continue;
-			del = nfsd_file_unhash_and_dispose(nf, &dispose);
-
-			/*
-			 * Deadlock detected! Something marked this entry as
-			 * unhased, but hasn't removed it from the hash list.
-			 */
-			WARN_ON_ONCE(!del);
-
+			if (!net || nf->nf_net == net) {
+				del = nfsd_file_unhash_and_dispose(nf, &dispose);
+
+				/*
+				 * Deadlock detected! Something marked this entry as
+				 * unhased, but hasn't removed it from the hash list.
+				 */
+				WARN_ON_ONCE(!del);
+			}
 			nf = rhashtable_walk_next(&iter);
 		}
-
 		rhashtable_walk_stop(&iter);
 	} while (nf == ERR_PTR(-EAGAIN));
 	rhashtable_walk_exit(&iter);
Signature · 1 line
2.38.1
#1 lore raw
Quoted 8 lines · Jeff Layton

If the namespace doesn't match the one in "net", then we'll continue, but that doesn't cause another rhashtable_walk_next call, so it will loop infinitely.

Quoted 8 lines
Fixes ce502f81ba88 ("NFSD: Convert the filecache to use rhashtable")

---
fs/nfsd/filecache.c | 20 +++++++++-----------

1 file changed, 9 insertions(+), 11 deletions(-)

This should probably go to stable too.

I tried to apply this to for-rc, but the WARN_ON_ONCE logic has already been removed there. Can you rebase and resend?

Quoted 36 lines
fs/nfsd/filecache.c +9 -11
index eeed4ae5b4ad..f9ea89057ae8 100644
@@ -908,19 +908,17 @@ __nfsd_file_cache_purge(struct net *net)
 
 		nf = rhashtable_walk_next(&iter);
 		while (!IS_ERR_OR_NULL(nf)) {
-			if (net && nf->nf_net != net)
-				continue;
-			del = nfsd_file_unhash_and_dispose(nf, &dispose);
-
-			/*
-			 * Deadlock detected! Something marked this entry as
-			 * unhased, but hasn't removed it from the hash list.
-			 */
-			WARN_ON_ONCE(!del);
-
+			if (!net || nf->nf_net == net) {
+				del = nfsd_file_unhash_and_dispose(nf, &dispose);
+
+				/*
+				 * Deadlock detected! Something marked this entry as
+				 * unhased, but hasn't removed it from the hash list.
+				 */
+				WARN_ON_ONCE(!del);
+			}
 			nf = rhashtable_walk_next(&iter);
 		}
-
 		rhashtable_walk_stop(&iter);
 	} while (nf == ERR_PTR(-EAGAIN));
 	rhashtable_walk_exit(&iter);
Signature · 1 line
2.38.1

--
Chuck Lever