Skip to contentSkip to conversation

NFS: add nfs_sb_deactive_async to avoid deadlock

PATCH New Weston Andros Adamson 1 participant 2 messages Oct 30, 2012

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

PATCH 1/2 NFS: add nfs_sb_deactive_async to avoid deadlock

Use nfs_sb_deactive_async instead of nfs_sb_deactive when in a workqueue context. This avoids a deadlock where rpc_shutdown_client loops forever in a workqueue kworker context, trying to kill all RPC tasks associated with the client, while one or more of these tasks have already been assigned to the same kworker (and will never run rpc_exit_task).

This approach is needed because RPC tasks that have already been assigned to a kworker by queue_work cannot be canceled, as explained in the comment for workqueue.c:insert_wq_barrier.

---

This version calls kthread_run *only* when deactivate_super will result in an umount -- the previous version could cause many unneeded kthread_runs with certain workloads.

 fs/nfs/inode.c    |    5 ++++-
 fs/nfs/internal.h |    1 +
 fs/nfs/nfs4proc.c |    2 +-
 fs/nfs/super.c    |   45 +++++++++++++++++++++++++++++++++++++++++++++
 fs/nfs/unlink.c   |    2 +-
 5 files changed, 52 insertions(+), 3 deletions(-)
fs/nfs/inode.c +4 -1
index 3967be2..117183b 100644
@@ -685,7 +685,10 @@ static void __put_nfs_open_context(struct nfs_open_context *ctx, int is_sync)
 	if (ctx->cred != NULL)
 		put_rpccred(ctx->cred);
 	dput(ctx->dentry);
-	nfs_sb_deactive(sb);
+	if (is_sync)
+		nfs_sb_deactive(sb);
+	else
+		nfs_sb_deactive_async(sb);
 	kfree(ctx->mdsthreshold);
 	kfree(ctx);
 }
fs/nfs/internal.h +1 -0
index 59b133c..12b8d69 100644
@@ -351,6 +351,7 @@ extern int __init register_nfs_fs(void);
 extern void __exit unregister_nfs_fs(void);
 extern void nfs_sb_active(struct super_block *sb);
 extern void nfs_sb_deactive(struct super_block *sb);
+extern void nfs_sb_deactive_async(struct super_block *sb);
 
 /* namespace.c */
 extern char *nfs_path(char **p, struct dentry *dentry,
fs/nfs/nfs4proc.c +1 -1
index 8b04d14..33a36e0 100644
@@ -2193,7 +2193,7 @@ static void nfs4_free_closedata(void *data)
 	nfs4_put_open_state(calldata->state);
 	nfs_free_seqid(calldata->arg.seqid);
 	nfs4_put_state_owner(sp);
-	nfs_sb_deactive(sb);
+	nfs_sb_deactive_async(sb);
 	kfree(calldata);
 }
 
fs/nfs/super.c +45 -0

57 lines not on this page · raw message

fs/nfs/unlink.c +1 -1
index 13cea63..3f79c77 100644
@@ -95,7 +95,7 @@ static void nfs_async_unlink_release(void *calldata)
 
 	nfs_dec_sillycount(data->dir);
 	nfs_free_unlinkdata(data);
-	nfs_sb_deactive(sb);
+	nfs_sb_deactive_async(sb);
 }
 
 static void nfs_unlink_prepare(struct rpc_task *task, void *calldata)
Signature · 1 line
1.7.9.6 (Apple Git-31.1)
#1 lore raw

PATCH 2/2 SUNRPC: add WARN_ON_ONCE for potential deadlock

rpc_shutdown_client should never be called from a workqueue context. If it is, it could deadlock looping forever trying to kill tasks that are assigned to the same kworker thread (and will never run rpc_exit_task).

---
 net/sunrpc/clnt.c |    6 ++++++
 1 file changed, 6 insertions(+)
net/sunrpc/clnt.c +6 -0
index cdc7564..d2737c2 100644
@@ -607,6 +607,12 @@ EXPORT_SYMBOL_GPL(rpc_killall_tasks);
  */
 void rpc_shutdown_client(struct rpc_clnt *clnt)
 {
+	/*
+	 * To avoid deadlock, never call rpc_shutdown_client from a
+	 * workqueue context!
+	 */
+	WARN_ON_ONCE(current->flags & PF_WQ_WORKER);
+
 	dprintk_rcu("RPC:       shutting down %s client for %s\n",
 			clnt->cl_protname,
 			rcu_dereference(clnt->cl_xprt)->servername);
Signature · 1 line
1.7.9.6 (Apple Git-31.1)