Skip to contentSkip to conversation

RPC: killing RPC tasks races fixed

PATCH Superseded Stanislav Kinsbursky 2 participants 5 messages Mar 17, 2011

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RPC: killing RPC tasks races fixed

task->tk_waitqueue must be checked for NULL before trying to wake up task in rpc_killall_tasks() because it can be NULL.

Here is an example:

CPU 0 CPU 1 CPU 2
-------------------- --------------------- --------------------------
nfs4_run_open_task
rpc_run_task
rpc_execute
rpc_set_active
rpc_make_runnable
(waiting)

			rpc_async_schedule
			nfs4_open_prepare
			nfs_wait_on_sequence
						nfs_umount_begin
						rpc_killall_tasks
						rpc_wake_up_task
						rpc_wake_up_queued_task
						spin_lock(tk_waitqueue == NULL)
						BUG()
			rpc_sleep_on
			spin_lock(&q->lock)
			__rpc_sleep_on
			task->tk_waitqueue = q
---
 net/sunrpc/clnt.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
net/sunrpc/clnt.c +3 -1
index 57d344c..24039fe 100644
@@ -436,7 +436,9 @@ void rpc_killall_tasks(struct rpc_clnt *clnt)
 		if (!(rovr->tk_flags & RPC_TASK_KILLED)) {
 			rovr->tk_flags |= RPC_TASK_KILLED;
 			rpc_exit(rovr, -EIO);
-			rpc_wake_up_queued_task(rovr->tk_waitqueue, rovr);
+			if (rovr->tk_waitqueue)
+				rpc_wake_up_queued_task(rovr->tk_waitqueue, 
+							rovr);
 		}
 	}
 	spin_unlock(&clnt->cl_lock);
#1 lore raw
Quoted 38 lines · Stanislav Kinsbursky

task->tk_waitqueue must be checked for NULL before trying to wake up task in rpc_killall_tasks() because it can be NULL.

Here is an example:

CPU 0 CPU 1 CPU 2
-------------------- --------------------- --------------------------
nfs4_run_open_task
rpc_run_task
rpc_execute
rpc_set_active
rpc_make_runnable
(waiting)

			rpc_async_schedule
			nfs4_open_prepare
			nfs_wait_on_sequence
						nfs_umount_begin
						rpc_killall_tasks
						rpc_wake_up_task
						rpc_wake_up_queued_task
						spin_lock(tk_waitqueue == NULL)
						BUG()
			rpc_sleep_on
			spin_lock(&q->lock)
			__rpc_sleep_on
			task->tk_waitqueue = q
---
 net/sunrpc/clnt.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
net/sunrpc/clnt.c +0 -0
index 57d344c..24039fe 100644

net/sunrpc/clnt.c void rpc_killall_tasks(struct rpc_clnt *clnt) · line 441

Quoted 7 lines
net/sunrpc/clnt.c +3 -1
@@ -436,7 +436,9 @@ void rpc_killall_tasks(struct rpc_clnt *clnt)
 		if (!(rovr->tk_flags & RPC_TASK_KILLED)) {
 			rovr->tk_flags |= RPC_TASK_KILLED;
 			rpc_exit(rovr, -EIO);
-			rpc_wake_up_queued_task(rovr->tk_waitqueue, rovr);
+			if (rovr->tk_waitqueue)
+				rpc_wake_up_queued_task(rovr->tk_waitqueue, 
+							rovr);

Testing for RPC_IS_QUEUED(rovr) would be better, since that would optimise away the call to rpc_wake_up_queued_task() altogether for those tasks that aren't queued.

Quoted 4 lines
net/sunrpc/clnt.c +0 -0
 		}
 	}
 	spin_unlock(&clnt->cl_lock);
Signature · 11 lines
Trond Myklebust
Linux NFS client maintainer

NetApp
[email protected]
www.netapp.com

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

17.03.2011 16:01, Trond Myklebust пишет:

Quoted 34 lines · Stanislav Kinsbursky
Quoted 33 lines

task->tk_waitqueue must be checked for NULL before trying to wake up task in rpc_killall_tasks() because it can be NULL.

Here is an example:

CPU 0 CPU 1 CPU 2
-------------------- --------------------- --------------------------
nfs4_run_open_task
rpc_run_task
rpc_execute
rpc_set_active
rpc_make_runnable
(waiting)

			rpc_async_schedule
			nfs4_open_prepare
			nfs_wait_on_sequence
						nfs_umount_begin
						rpc_killall_tasks
						rpc_wake_up_task
						rpc_wake_up_queued_task
						spin_lock(tk_waitqueue == NULL)
						BUG()
			rpc_sleep_on
			spin_lock(&q->lock)
			__rpc_sleep_on
			task->tk_waitqueue = q
---
  net/sunrpc/clnt.c |    4 +++-
  1 files changed, 3 insertions(+), 1 deletions(-)
Quoted 17 lines

net/sunrpc/clnt.c void rpc_killall_tasks(struct rpc_clnt *clnt) · line 441

Quoted 12 lines
net/sunrpc/clnt.c +3 -1
index 57d344c..24039fe 100644
@@ -436,7 +436,9 @@ void rpc_killall_tasks(struct rpc_clnt *clnt)
  		if (!(rovr->tk_flags&  RPC_TASK_KILLED)) {
  			rovr->tk_flags |= RPC_TASK_KILLED;
  			rpc_exit(rovr, -EIO);
-			rpc_wake_up_queued_task(rovr->tk_waitqueue, rovr);
+			if (rovr->tk_waitqueue)
+				rpc_wake_up_queued_task(rovr->tk_waitqueue,
+							rovr);

Testing for RPC_IS_QUEUED(rovr) would be better, since that would optimise away the call to rpc_wake_up_queued_task() altogether for those tasks that aren't queued.

Yes, I agree with testing RPC_IS_QUEUED(rovr) since such approach looks clearer and in 2.6.38 tk_waitqueue is initialized prior to set RPC_TASK_QUEUED bit.
But I found this problem in 2.6.32 rhel kernel where this set sequence is inversed. Will send fixed version soon.

Quoted 5 lines
Quoted 4 lines
net/sunrpc/clnt.c +0 -0
  		}
  	}
  	spin_unlock(&clnt->cl_lock);
Signature · 2 lines
Best regards,
Stanislav Kinsbursky
#3 lore raw
Quoted 53 lines · Stanislav Kinsbursky

17.03.2011 16:01, Trond Myklebust пишет:

Quoted 34 lines · Stanislav Kinsbursky
Quoted 33 lines

task->tk_waitqueue must be checked for NULL before trying to wake up task in rpc_killall_tasks() because it can be NULL.

Here is an example:

CPU 0 CPU 1 CPU 2
-------------------- --------------------- --------------------------
nfs4_run_open_task
rpc_run_task
rpc_execute
rpc_set_active
rpc_make_runnable
(waiting)

			rpc_async_schedule
			nfs4_open_prepare
			nfs_wait_on_sequence
						nfs_umount_begin
						rpc_killall_tasks
						rpc_wake_up_task
						rpc_wake_up_queued_task
						spin_lock(tk_waitqueue == NULL)
						BUG()
			rpc_sleep_on
			spin_lock(&q->lock)
			__rpc_sleep_on
			task->tk_waitqueue = q
---
  net/sunrpc/clnt.c |    4 +++-
  1 files changed, 3 insertions(+), 1 deletions(-)
Quoted 17 lines

net/sunrpc/clnt.c void rpc_killall_tasks(struct rpc_clnt *clnt) · line 441

Quoted 12 lines
net/sunrpc/clnt.c +3 -1
index 57d344c..24039fe 100644
@@ -436,7 +436,9 @@ void rpc_killall_tasks(struct rpc_clnt *clnt)
  		if (!(rovr->tk_flags&  RPC_TASK_KILLED)) {
  			rovr->tk_flags |= RPC_TASK_KILLED;
  			rpc_exit(rovr, -EIO);
-			rpc_wake_up_queued_task(rovr->tk_waitqueue, rovr);
+			if (rovr->tk_waitqueue)
+				rpc_wake_up_queued_task(rovr->tk_waitqueue,
+							rovr);

Testing for RPC_IS_QUEUED(rovr) would be better, since that would optimise away the call to rpc_wake_up_queued_task() altogether for those tasks that aren't queued.

Quoted 5 lines

Yes, I agree with testing RPC_IS_QUEUED(rovr) since such approach looks clearer and in 2.6.38 tk_waitqueue is initialized prior to set RPC_TASK_QUEUED bit.
But I found this problem in 2.6.32 rhel kernel where this set sequence is inversed. Will send fixed version soon.

Are you sure? Why would the 2.6.32 rhel kernel differ from the mainline 2.6.32 kernel in this respect?

Signature · 11 lines
Trond Myklebust
Linux NFS client maintainer

NetApp
[email protected]
www.netapp.com

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

17.03.2011 19:44, Trond Myklebust пишет:

Quoted 4 lines

Are you sure? Why would the 2.6.32 rhel kernel differ from the mainline 2.6.32 kernel in this respect?

Checked again and realized, that was wrong.
This set sequence is the same in 2.6.32 rhel, 2.6.32 and 2.6.38 kernels.

Signature · 2 lines
Best regards,
Stanislav Kinsbursky