Skip to contentSkip to conversation

NFSv4 callback service ate my homework

PATCH In review Benjamin Coddington 3 participants 5 messages Mar 3, 2023 – Mar 8, 2023

Subsystems (3)
lore
Share & tools
lore
#1 lore raw

PATCH 1/1 SUNRPC: Fix a server shutdown leak

In reply to Benjamin Coddington

Fix a race where kthread_stop() may prevent the threadfn from ever getting called. If that happens the svc_rqst will not be cleaned up.

Fixes ed6473ddc704 ("NFSv4: Fix callback server shutdown")
---
 net/sunrpc/svc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
net/sunrpc/svc.c +5 -1
index 1fd3f5e57285..fea7ce8fba14 100644
@@ -798,6 +798,7 @@ svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
 static int
 svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
 {
+	struct svc_rqst	*rqstp;
 	struct task_struct *task;
 	unsigned int state = serv->sv_nrthreads-1;
 
@@ -806,7 +807,10 @@ svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
 		task = choose_victim(serv, pool, &state);
 		if (task == NULL)
 			break;
-		kthread_stop(task);
+		rqstp = kthread_data(task);
+		/* Did we lose a race to svo_function threadfn? */
+		if (kthread_stop(task) == -EINTR)
+			svc_exit_thread(rqstp);
 		nrservs++;
 	} while (nrservs < 0);
 	return 0;
Signature · 1 line
2.31.1
#0 lore raw

cover NFSv4 callback service ate my homework

A system with very low autofs timeouts for many mounts of v4.0 exports, while attempting to mount with the non-specific vers=4 option would run out of memory every few days. Each mount was doing the v4.2, v4.1, v4.0 negotiation and constantly setting up and tearing down the backchannel service for positive minorversions. We found a probable cause:
wake_up_process() isn't guarunteed to execute the threadfn; kthread_stop() can race in and prevent it.

Benjamin Coddington (1):
SUNRPC: Fix a server shutdown leak

 net/sunrpc/svc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
2.31.1
#2 lore raw

Re: [PATCH 1/1] SUNRPC: Fix a server shutdown leak

In reply to Benjamin Coddington
Quoted 40 lines · Benjamin Coddington

Fix a race where kthread_stop() may prevent the threadfn from ever getting called. If that happens the svc_rqst will not be cleaned up.

Fixes ed6473ddc704 ("NFSv4: Fix callback server shutdown")

---
net/sunrpc/svc.c | 6 +++++-

1 file changed, 5 insertions(+), 1 deletion(-)
net/sunrpc/svc.c +0 -0
index 1fd3f5e57285..fea7ce8fba14 100644
@@ -798,6 +798,7 @@ svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)

static int
svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs) {
+ struct svc_rqst *rqstp;
struct task_struct *task;
unsigned int state = serv->sv_nrthreads-1;

net/sunrpc/svc.c +4 -1
@@ -806,7 +807,10 @@ svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
 task = choose_victim(serv, pool, &state);
 if (task == NULL)
 break;
- kthread_stop(task);
+ rqstp = kthread_data(task);
+ /* Did we lose a race to svo_function threadfn? */
+ if (kthread_stop(task) == -EINTR)
+ svc_exit_thread(rqstp);
 nrservs++;
 } while (nrservs < 0);
 return 0;
Signature · 1 line
2.31.1

Seems sensible, applied. Is there a bugzilla link that should be included?

--
Chuck Lever

#3 lore raw

Re: [PATCH 1/1] SUNRPC: Fix a server shutdown leak

Quoted 32 lines · Chuck Lever III
Quoted 32 lines · Benjamin Coddington

Fix a race where kthread_stop() may prevent the threadfn from ever getting called. If that happens the svc_rqst will not be cleaned up.

Fixes ed6473ddc704 ("NFSv4: Fix callback server shutdown")

---
net/sunrpc/svc.c | 6 +++++-

1 file changed, 5 insertions(+), 1 deletion(-)
net/sunrpc/svc.c +0 -0
index 1fd3f5e57285..fea7ce8fba14 100644
@@ -798,6 +798,7 @@ svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)

static int
svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs) {
+ struct svc_rqst *rqstp;
struct task_struct *task;
unsigned int state = serv->sv_nrthreads-1;

net/sunrpc/svc.c +4 -1
@@ -806,7 +807,10 @@ svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
 task = choose_victim(serv, pool, &state);
 if (task == NULL)
 break;
- kthread_stop(task);
+ rqstp = kthread_data(task);
+ /* Did we lose a race to svo_function threadfn? */
+ if (kthread_stop(task) == -EINTR)
+ svc_exit_thread(rqstp);
Quoted 8 lines
Quoted 6 lines
net/sunrpc/svc.c +0 -0
 nrservs++;
 } while (nrservs < 0);
 return 0;
Signature · 1 line
2.31.1

Seems sensible, applied. Is there a bugzilla link that should be included?

No, the issue was found in a private environment.

Ben

maintainer Reviewed-by on v1 1/1
#4 lore raw

Re: [PATCH 1/1] SUNRPC: Fix a server shutdown leak

In reply to Benjamin Coddington
Quoted 23 lines · Benjamin Coddington

Fix a race where kthread_stop() may prevent the threadfn from ever getting called. If that happens the svc_rqst will not be cleaned up.

Fixes ed6473ddc704 ("NFSv4: Fix callback server shutdown")
---
 net/sunrpc/svc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
net/sunrpc/svc.c +1 -0
index 1fd3f5e57285..fea7ce8fba14 100644
@@ -798,6 +798,7 @@ svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
 static int
 svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
 {
+	struct svc_rqst	*rqstp;
 	struct task_struct *task;
 	unsigned int state = serv->sv_nrthreads-1;
 
@@ -806,7 +807,10 @@ svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
 		task = choose_victim(serv, pool, &state);

net/sunrpc/svc.c svc_stop_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs) · line 816

Quoted 10 lines
net/sunrpc/svc.c +4 -1
 		if (task == NULL)
 			break;
-		kthread_stop(task);
+		rqstp = kthread_data(task);
+		/* Did we lose a race to svo_function threadfn? */
+		if (kthread_stop(task) == -EINTR)
+			svc_exit_thread(rqstp);
 		nrservs++;
 	} while (nrservs < 0);
 	return 0;