Skip to contentSkip to conversation

sunrpc: Fix race between work-queue and rpc_killall_tasks.

RFC In review [email protected] 2 participants 16 messages Jul 6, 2011 – Jul 14, 2011

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

RFC 1/1 sunrpc: Fix race between work-queue and rpc_killall_tasks.

From: Ben Greear <[email protected]>

The rpc_killall_tasks logic is not locked against the work-queue thread, but it still directly modifies function pointers and data in the task objects.

This patch changes the killall-tasks logic to set a flag that tells the work-queue thread to terminate the task instead of directly calling the terminate logic.

---

NOTE: This needs review, as I am still struggling to understand the rpc code, and it's quite possible this patch either doesn't fully fix the problem or actually causes other issues. That said, my nfs stress test seems to run a bit more stable with this patch applied.

:100644 100644 fe2d8e6... b238944... M include/linux/sunrpc/sched.h
:100644 100644 8c91415... 6851f84... M net/sunrpc/clnt.c
:100644 100644 1cbbed5... 0fc559e... M net/sunrpc/sched.c

 include/linux/sunrpc/sched.h |   10 ++++++++++
 net/sunrpc/clnt.c            |    3 +--
 net/sunrpc/sched.c           |    6 ++++++
 3 files changed, 17 insertions(+), 2 deletions(-)
include/linux/sunrpc/sched.h +10 -0
index fe2d8e6..b238944 100644
@@ -76,6 +76,7 @@ struct rpc_task {
 
 	pid_t			tk_owner;	/* Process id for batching tasks */
 	int			tk_status;	/* result of last operation */
+	int			tk_killme_errno;/* For RPC_TASK_KILLME */
 	unsigned short		tk_flags;	/* misc flags */
 	unsigned short		tk_timeouts;	/* maj timeouts */
 
@@ -130,6 +131,7 @@ struct rpc_task_setup {
 #define RPC_TASK_SOFTCONN	0x0400		/* Fail if can't connect */
 #define RPC_TASK_SENT		0x0800		/* message was sent */
 #define RPC_TASK_TIMEOUT	0x1000		/* fail with ETIMEDOUT on timeout */
+#define RPC_TASK_KILLME		0x2000		/* Need to die ASAP. */
 
 #define RPC_IS_ASYNC(t)		((t)->tk_flags & RPC_TASK_ASYNC)
 #define RPC_IS_SWAPPER(t)	((t)->tk_flags & RPC_TASK_SWAPPER)
@@ -138,6 +140,7 @@ struct rpc_task_setup {
 #define RPC_IS_SOFT(t)		((t)->tk_flags & (RPC_TASK_SOFT|RPC_TASK_TIMEOUT))
 #define RPC_IS_SOFTCONN(t)	((t)->tk_flags & RPC_TASK_SOFTCONN)
 #define RPC_WAS_SENT(t)		((t)->tk_flags & RPC_TASK_SENT)
+#define RPC_SHOULD_KILLME(t)	((t)->tk_flags & RPC_TASK_KILLME)
 
 #define RPC_TASK_RUNNING	0
 #define RPC_TASK_QUEUED		1
@@ -269,4 +272,11 @@ static inline const char * rpc_qname(struct rpc_wait_queue *q)
 }
 #endif
 
+static inline void rpc_task_killme(struct rpc_task *task, int exit_errno)
+{
+	task->tk_killme_errno = exit_errno;
+	task->tk_flags |= RPC_TASK_KILLME;
+}
+
+
 #endif /* _LINUX_SUNRPC_SCHED_H_ */
net/sunrpc/clnt.c +1 -2
index 8c91415..6851f84 100644
@@ -437,8 +437,7 @@ void rpc_killall_tasks(struct rpc_clnt *clnt)
 		if (!RPC_IS_ACTIVATED(rovr))
 			continue;
 		if (!(rovr->tk_flags & RPC_TASK_KILLED)) {
-			rovr->tk_flags |= RPC_TASK_KILLED;
-			rpc_exit(rovr, -EIO);
+			rpc_task_killme(rovr, -EIO);
 			if (RPC_IS_QUEUED(rovr))
 				rpc_wake_up_queued_task(rovr->tk_waitqueue,
 							rovr);
net/sunrpc/sched.c +6 -0
index 1cbbed5..0fc559e 100644
@@ -646,6 +646,12 @@ static void __rpc_execute(struct rpc_task *task)
 			task->tk_action(task);
 		}
 
+		/* If we should die, do it now. */
+		if (RPC_SHOULD_KILLME(task)) {
+			task->tk_flags |= RPC_TASK_KILLED;
+			rpc_exit(task, task->tk_killme_errno);
+		}
+
 		/*
 		 * Lockless check for whether task is sleeping or not.
 		 */
Signature · 1 line
1.7.3.4
#1 lore raw
Quoted 10 lines · On Wed, 2011-07-06 at 15:49 -0700, [email protected] wrote:

From: Ben Greear <[email protected]>

The rpc_killall_tasks logic is not locked against the work-queue thread, but it still directly modifies function pointers and data in the task objects.

This patch changes the killall-tasks logic to set a flag that tells the work-queue thread to terminate the task instead of directly calling the terminate logic.

Quoted 7 lines

---

NOTE: This needs review, as I am still struggling to understand the rpc code, and it's quite possible this patch either doesn't fully fix the problem or actually causes other issues. That said, my nfs stress test seems to run a bit more stable with this patch applied.

Yes, but I don't see why you are adding a new flag, nor do I see why we want to keep checking for that flag in the rpc_execute() loop. rpc_killall_tasks() is not a frequent operation that we want to optimise for.

How about the following instead?

8<----------------------------------------------------------------------------------

author
#2 lore raw
Quoted 19 lines · Trond Myklebust
Quoted 10 lines · On Wed, 2011-07-06 at 15:49 -0700, [email protected] wrote:

From: Ben Greear<[email protected]>

The rpc_killall_tasks logic is not locked against the work-queue thread, but it still directly modifies function pointers and data in the task objects.

This patch changes the killall-tasks logic to set a flag that tells the work-queue thread to terminate the task instead of directly calling the terminate logic.

Quoted 7 lines

---

NOTE: This needs review, as I am still struggling to understand the rpc code, and it's quite possible this patch either doesn't fully fix the problem or actually causes other issues. That said, my nfs stress test seems to run a bit more stable with this patch applied.

Quoted 4 lines

Yes, but I don't see why you are adding a new flag, nor do I see why we want to keep checking for that flag in the rpc_execute() loop. rpc_killall_tasks() is not a frequent operation that we want to optimise for.

I was hoping that if the killall logic never set anything that was also set by the work-queue thread it would be lock-safe without needing explicit locking.

I was a bit concerned that my flags |= KILLME logic would potentially over-write flags that were being simultaneously written elsewhere (so maybe I'd have to add a completely new variable for that KILLME flag to really be safe.)

Quoted 2 lines

How about the following instead?

I think it still races..more comments below.

Review

Quoted 13 lines

8<----------------------------------------------------------------------------------
From ecb7244b661c3f9d2008ef6048733e5cea2f98ab Mon Sep 17 00:00:00 2001
From: Trond Myklebust<[email protected]>
Date: Wed, 6 Jul 2011 19:44:52 -0400
Subject: [PATCH] SUNRPC: Fix a race between work-queue and rpc_killall_tasks

Since rpc_killall_tasks may modify the rpc_task's tk_action field without any locking, we need to be careful when dereferencing it.

(quoted diff) +3 -0
+		do_action = task->tk_callback;
+		task->tk_callback = NULL;
+		if (do_action == NULL) {

I think the race still exists, though it would be harder to hit.
What if the killall logic sets task->tk_callback right after you assign do_action, but before you set tk_callback to NULL? Or after you set tk_callback to NULL for
that matter.

Quoted 8 lines

/*
* Perform the next FSM step.

(quoted diff) +3 -2
-			 * tk_action may be NULL when the task has been killed
-			 * by someone else.
+			 * tk_action may be NULL if the task has been killed.
+			 * In particular, note that rpc_killall_tasks may
+			 * do this at any time, so beware when dereferencing.
  			 */

Review

Quoted 10 lines
(quoted diff) +3 -2
-			if (task->tk_action == NULL)
+			do_action = task->tk_action;
+			if (do_action == NULL)
  				break;
-			task->tk_action(task);
  		}
+		do_action(task);
 
  		/*
  		 * Lockless check for whether task is sleeping or not.

Thanks,
Ben

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
#3 lore raw
Quoted 49 lines · Ben Greear
Quoted 19 lines · Trond Myklebust
Quoted 10 lines · On Wed, 2011-07-06 at 15:49 -0700, [email protected] wrote:

From: Ben Greear<[email protected]>

The rpc_killall_tasks logic is not locked against the work-queue thread, but it still directly modifies function pointers and data in the task objects.

This patch changes the killall-tasks logic to set a flag that tells the work-queue thread to terminate the task instead of directly calling the terminate logic.

Quoted 7 lines

---

NOTE: This needs review, as I am still struggling to understand the rpc code, and it's quite possible this patch either doesn't fully fix the problem or actually causes other issues. That said, my nfs stress test seems to run a bit more stable with this patch applied.

Quoted 4 lines

Yes, but I don't see why you are adding a new flag, nor do I see why we want to keep checking for that flag in the rpc_execute() loop. rpc_killall_tasks() is not a frequent operation that we want to optimise for.

I was hoping that if the killall logic never set anything that was also set by the work-queue thread it would be lock-safe without needing explicit locking.

I was a bit concerned that my flags |= KILLME logic would potentially over-write flags that were being simultaneously written elsewhere (so maybe I'd have to add a completely new variable for that KILLME flag to really be safe.)

Quoted 2 lines

How about the following instead?

I think it still races..more comments below.

Quoted 9 lines

8<----------------------------------------------------------------------------------
From ecb7244b661c3f9d2008ef6048733e5cea2f98ab Mon Sep 17 00:00:00 2001
From: Trond Myklebust<[email protected]>
Date: Wed, 6 Jul 2011 19:44:52 -0400
Subject: [PATCH] SUNRPC: Fix a race between work-queue and rpc_killall_tasks

Since rpc_killall_tasks may modify the rpc_task's tk_action field without any locking, we need to be careful when dereferencing it.

Quoted 8 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+		do_action = task->tk_callback;
+		task->tk_callback = NULL;
+		if (do_action == NULL) {

I think the race still exists, though it would be harder to hit.
What if the killall logic sets task->tk_callback right after you assign do_action, but before you set tk_callback to NULL? Or after you set tk_callback to NULL for
that matter.

What if it does? The rpc call will continue to execute until it completes.

rpc_killall_tasks is really only useful for signalling to tasks that are hanging on a completely unresponsive server that we want them to stop. The only case where we really care is in rpc_shutdown_client(), where we sleep and loop anyway.

IOW: I really don't care about 'fixing' rpc_killall_tasks to perfection. All I care about is that it doesn't Oops.

Signature · 6 lines
Trond Myklebust
Linux NFS client maintainer

NetApp
[email protected]
www.netapp.com
author
#4 lore raw
Quoted 62 lines · Trond Myklebust
Quoted 49 lines · Ben Greear
Quoted 19 lines · Trond Myklebust
Quoted 10 lines · On Wed, 2011-07-06 at 15:49 -0700, [email protected] wrote:

From: Ben Greear<[email protected]>

The rpc_killall_tasks logic is not locked against the work-queue thread, but it still directly modifies function pointers and data in the task objects.

This patch changes the killall-tasks logic to set a flag that tells the work-queue thread to terminate the task instead of directly calling the terminate logic.

Quoted 7 lines

---

NOTE: This needs review, as I am still struggling to understand the rpc code, and it's quite possible this patch either doesn't fully fix the problem or actually causes other issues. That said, my nfs stress test seems to run a bit more stable with this patch applied.

Quoted 4 lines

Yes, but I don't see why you are adding a new flag, nor do I see why we want to keep checking for that flag in the rpc_execute() loop. rpc_killall_tasks() is not a frequent operation that we want to optimise for.

I was hoping that if the killall logic never set anything that was also set by the work-queue thread it would be lock-safe without needing explicit locking.

I was a bit concerned that my flags |= KILLME logic would potentially over-write flags that were being simultaneously written elsewhere (so maybe I'd have to add a completely new variable for that KILLME flag to really be safe.)

Quoted 2 lines

How about the following instead?

I think it still races..more comments below.

Quoted 9 lines

8<----------------------------------------------------------------------------------
From ecb7244b661c3f9d2008ef6048733e5cea2f98ab Mon Sep 17 00:00:00 2001
From: Trond Myklebust<[email protected]>
Date: Wed, 6 Jul 2011 19:44:52 -0400
Subject: [PATCH] SUNRPC: Fix a race between work-queue and rpc_killall_tasks

Since rpc_killall_tasks may modify the rpc_task's tk_action field without any locking, we need to be careful when dereferencing it.

Quoted 8 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+		do_action = task->tk_callback;
+		task->tk_callback = NULL;
+		if (do_action == NULL) {

I think the race still exists, though it would be harder to hit.
What if the killall logic sets task->tk_callback right after you assign do_action, but before you set tk_callback to NULL? Or after you set tk_callback to NULL for
that matter.

What if it does? The rpc call will continue to execute until it completes.

Quoted 7 lines

rpc_killall_tasks is really only useful for signalling to tasks that are hanging on a completely unresponsive server that we want them to stop. The only case where we really care is in rpc_shutdown_client(), where we sleep and loop anyway.

IOW: I really don't care about 'fixing' rpc_killall_tasks to perfection. All I care about is that it doesn't Oops.

That is my concern as well. I'll try your patch and see if it fixes the crashes I'm seeing in this area.

Thanks,
Ben

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
author
#5 lore raw
In reply to Trond Myklebust
Quoted 32 lines · Trond Myklebust
Quoted 10 lines · On Wed, 2011-07-06 at 15:49 -0700, [email protected] wrote:

From: Ben Greear<[email protected]>

The rpc_killall_tasks logic is not locked against the work-queue thread, but it still directly modifies function pointers and data in the task objects.

This patch changes the killall-tasks logic to set a flag that tells the work-queue thread to terminate the task instead of directly calling the terminate logic.

Quoted 7 lines

---

NOTE: This needs review, as I am still struggling to understand the rpc code, and it's quite possible this patch either doesn't fully fix the problem or actually causes other issues. That said, my nfs stress test seems to run a bit more stable with this patch applied.

Yes, but I don't see why you are adding a new flag, nor do I see why we want to keep checking for that flag in the rpc_execute() loop. rpc_killall_tasks() is not a frequent operation that we want to optimise for.

How about the following instead?

8<----------------------------------------------------------------------------------
From ecb7244b661c3f9d2008ef6048733e5cea2f98ab Mon Sep 17 00:00:00 2001
From: Trond Myklebust<[email protected]>
Date: Wed, 6 Jul 2011 19:44:52 -0400
Subject: [PATCH] SUNRPC: Fix a race between work-queue and rpc_killall_tasks

Quoted 5 lines

Since rpc_killall_tasks may modify the rpc_task's tk_action field without any locking, we need to be careful when dereferencing it.

I've been testing this for 4+ hours, and it seems to fix the problem. We'll continue to burn on it for a day or two just in case we're getting (un)lucky in our testing.

Thanks,
Ben

Quoted 50 lines
---
  net/sunrpc/sched.c |   27 +++++++++++----------------
  1 files changed, 11 insertions(+), 16 deletions(-)
net/sunrpc/sched.c +11 -16
index a27406b..4814e24 100644
@@ -616,30 +616,25 @@ static void __rpc_execute(struct rpc_task *task)
  	BUG_ON(RPC_IS_QUEUED(task));
 
  	for (;;) {
+		void (*do_action)(struct rpc_task *);
 
  		/*
-		 * Execute any pending callback.
+		 * Execute any pending callback first.
  		 */
-		if (task->tk_callback) {
-			void (*save_callback)(struct rpc_task *);
-
-			/*
-			 * We set tk_callback to NULL before calling it,
-			 * in case it sets the tk_callback field itself:
-			 */
-			save_callback = task->tk_callback;
-			task->tk_callback = NULL;
-			save_callback(task);
-		} else {
+		do_action = task->tk_callback;
+		task->tk_callback = NULL;
+		if (do_action == NULL) {
  			/*
  			 * Perform the next FSM step.
-			 * tk_action may be NULL when the task has been killed
-			 * by someone else.
+			 * tk_action may be NULL if the task has been killed.
+			 * In particular, note that rpc_killall_tasks may
+			 * do this at any time, so beware when dereferencing.
  			 */
-			if (task->tk_action == NULL)
+			do_action = task->tk_action;
+			if (do_action == NULL)
  				break;
-			task->tk_action(task);
  		}
+		do_action(task);
 
  		/*
  		 * Lockless check for whether task is sleeping or not.
Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
author
#6 lore raw
Quoted 39 lines · Ben Greear
Quoted 32 lines · Trond Myklebust
Quoted 10 lines · On Wed, 2011-07-06 at 15:49 -0700, [email protected] wrote:

From: Ben Greear<[email protected]>

The rpc_killall_tasks logic is not locked against the work-queue thread, but it still directly modifies function pointers and data in the task objects.

This patch changes the killall-tasks logic to set a flag that tells the work-queue thread to terminate the task instead of directly calling the terminate logic.

Quoted 7 lines

---

NOTE: This needs review, as I am still struggling to understand the rpc code, and it's quite possible this patch either doesn't fully fix the problem or actually causes other issues. That said, my nfs stress test seems to run a bit more stable with this patch applied.

Yes, but I don't see why you are adding a new flag, nor do I see why we want to keep checking for that flag in the rpc_execute() loop. rpc_killall_tasks() is not a frequent operation that we want to optimise for.

How about the following instead?

8<---------------------------------------------------------------------------------- From ecb7244b661c3f9d2008ef6048733e5cea2f98ab Mon Sep 17 00:00:00 2001
From: Trond Myklebust<[email protected]>
Date: Wed, 6 Jul 2011 19:44:52 -0400
Subject: [PATCH] SUNRPC: Fix a race between work-queue and rpc_killall_tasks

Quoted 5 lines

Since rpc_killall_tasks may modify the rpc_task's tk_action field without any locking, we need to be careful when dereferencing it.

Quoted 6 lines

I've been testing this for 4+ hours, and it seems to fix the problem. We'll continue to burn on it for a day or two just in case we're getting (un)lucky in our testing.

Thanks,
Ben

Well, we still hit the bug in over-night testing. Maybe there are other races...

=============================================================================
BUG kmalloc-64: Object is on free-list
-----------------------------------------------------------------------------

INFO: Allocated in rpcb_getport_async+0x39c/0x5a5 [sunrpc] age=52 cpu=6 pid=18908

        __slab_alloc+0x348/0x3ba
        kmem_cache_alloc_trace+0x67/0xe7
        rpcb_getport_async+0x39c/0x5a5 [sunrpc]
        call_bind+0x70/0x75 [sunrpc]
        __rpc_execute+0x80/0x253 [sunrpc]
        rpc_execute+0x3d/0x42 [sunrpc]
        rpc_run_task+0x79/0x81 [sunrpc]
        rpc_call_sync+0x3f/0x60 [sunrpc]
        rpc_ping+0x42/0x58 [sunrpc]
        rpc_create+0x4aa/0x527 [sunrpc]
        nfs_create_rpc_client+0xb1/0xf6 [nfs]
        nfs_init_client+0x3b/0x7d [nfs]
        nfs_get_client+0x453/0x5ab [nfs]
        nfs_create_server+0x10b/0x437 [nfs]
        nfs_fs_mount+0x4ca/0x708 [nfs]
        mount_fs+0x6b/0x152
INFO: Freed in rpcb_map_release+0x3f/0x44 [sunrpc] age=119 cpu=5 pid=13934
        __slab_free+0x57/0x150
        kfree+0x107/0x13a
        rpcb_map_release+0x3f/0x44 [sunrpc]
        rpc_release_calldata+0x12/0x14 [sunrpc]
        rpc_free_task+0x72/0x7a [sunrpc]
        rpc_final_put_task+0x82/0x8a [sunrpc]
        __rpc_execute+0x244/0x253 [sunrpc]
        rpc_async_schedule+0x10/0x12 [sunrpc]
        process_one_work+0x230/0x41d
        worker_thread+0x133/0x217
        kthread+0x7d/0x85
        kernel_thread_helper+0x4/0x10
INFO: Slab 0xffffea0002c38b90 objects=20 used=13 fp=0xffff8800ca27e620 flags=0x20000000004081
INFO: Object 0xffff8800ca27e620 @offset=1568 fp=0xffff8800ca27f880
Bytes b4 0xffff8800ca27e610:  d0 c4 1a 02 01 00 00 00 5a 5a 5a 5a 5a 5a 5a 5a ÐÄ......ZZZZZZZZ
  Object 0xffff8800ca27e620:  6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk
  Object 0xffff8800ca27e630:  6b 6b 6b 6b 00 00 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkk..kkkkkkkkkk
  Object 0xffff8800ca27e640:  6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk
  Object 0xffff8800ca27e650:  6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b a5 kkkkkkkkkkkkkkk¥
 Redzone 0xffff8800ca27e660:  bb bb bb bb bb bb bb bb                         »»»»»»»»
 Padding 0xffff8800ca27e7a0:  5a 5a 5a 5a 5a 5a 5a 5a                         ZZZZZZZZ
Pid: 13035, comm: kworker/0:1 Not tainted 3.0.0-rc6+ #13
Call Trace:
 [<ffffffff81105907>] print_trailer+0x131/0x13a
 [<ffffffff81105945>] object_err+0x35/0x3e
 [<ffffffff811077b3>] verify_mem_not_deleted+0x7a/0xb7
 [<ffffffffa02891e5>] rpcb_getport_done+0x23/0x126 [sunrpc]
 [<ffffffffa02810df>] rpc_exit_task+0x3f/0x6d [sunrpc]
 [<ffffffffa02814d8>] __rpc_execute+0x80/0x253 [sunrpc]
 [<ffffffffa02816ed>] ? rpc_execute+0x42/0x42 [sunrpc]
 [<ffffffffa02816fd>] rpc_async_schedule+0x10/0x12 [sunrpc]
 [<ffffffff81061343>] process_one_work+0x230/0x41d
 [<ffffffff8106128e>] ? process_one_work+0x17b/0x41d
 [<ffffffff8106379f>] worker_thread+0x133/0x217
 [<ffffffff8106366c>] ? manage_workers+0x191/0x191
 [<ffffffff81066f9c>] kthread+0x7d/0x85
 [<ffffffff81485ee4>] kernel_thread_helper+0x4/0x10
 [<ffffffff8147f0d8>] ? retint_restore_args+0x13/0x13
 [<ffffffff81066f1f>] ? __init_kthread_worker+0x56/0x56
 [<ffffffff81485ee0>] ? gs_change+0x13/0x13

Thanks,
Ben

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
author
#7 lore raw
In reply to Trond Myklebust
Quoted 19 lines · Trond Myklebust
Quoted 10 lines · On Wed, 2011-07-06 at 15:49 -0700, [email protected] wrote:

From: Ben Greear<[email protected]>

The rpc_killall_tasks logic is not locked against the work-queue thread, but it still directly modifies function pointers and data in the task objects.

This patch changes the killall-tasks logic to set a flag that tells the work-queue thread to terminate the task instead of directly calling the terminate logic.

Quoted 7 lines

---

NOTE: This needs review, as I am still struggling to understand the rpc code, and it's quite possible this patch either doesn't fully fix the problem or actually causes other issues. That said, my nfs stress test seems to run a bit more stable with this patch applied.

Quoted 6 lines

Yes, but I don't see why you are adding a new flag, nor do I see why we want to keep checking for that flag in the rpc_execute() loop. rpc_killall_tasks() is not a frequent operation that we want to optimise for.

How about the following instead?

Ok, I looked at your patch closer. I think it can still cause bad race conditions.

For instance:

Assume that tk_callback is NULL at beginning of while loop in __rpc_execute, and tk_action is rpc_exit_task.

While do_action(task) is being called, tk_action is set to NULL in rpc_exit_task.

But, right after tk_action is set to NULL in rpc_exit_task, the rpc_killall_tasks method calls rpc_exit, which sets tk_action back to rpc_exit_task.

I believe this could cause the xprt_release(task) logic to be called in the work-queue's execution of rpc_exit_task due to tk_action != NULL when it should not be.

I have no hard evidence this exact scenario is happening in my case, but I believe the code is still racy with your patch.

For that matter, is it safe to modify the flags in rpc_killall_tasks:

rovr->tk_flags |= RPC_TASK_KILLED;

Is that guaranteed to be atomic with any other modification of flags?

Thanks,
Ben

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
#8 lore raw

PiAtLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLQ0KPiBGcm9tOiBCZW4gR3JlZWFyIFttYWlsdG86 Z3JlZWFyYkBjYW5kZWxhdGVjaC5jb21dDQo+IFNlbnQ6IEZyaWRheSwgSnVseSAwOCwgMjAxMSAx OjE5IFBNDQo+IFRvOiBNeWtsZWJ1c3QsIFRyb25kDQo+IENjOiBsaW51eC1uZnNAdmdlci5rZXJu ZWwub3JnOyBsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnDQo+IFN1YmplY3Q6IFJlOiBbUkZD XSBzdW5ycGM6IEZpeCByYWNlIGJldHdlZW4gd29yay1xdWV1ZSBhbmQNCj4gcnBjX2tpbGxhbGxf dGFza3MuDQo+IA0KPiBPbiAwNy8wNi8yMDExIDA0OjQ1IFBNLCBUcm9uZCBNeWtsZWJ1c3Qgd3Jv dGU6DQo+ID4gT24gV2VkLCAyMDExLTA3LTA2IGF0IDE1OjQ5IC0wNzAwLCBncmVlYXJiQGNhbmRl bGF0ZWNoLmNvbSB3cm90ZToNCj4gPj4gRnJvbTogQmVuIEdyZWVhcjxncmVlYXJiQGNhbmRlbGF0 ZWNoLmNvbT4NCj4gPj4NCj4gPj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yBzZXQgdXAuIFRoZSBv bmx5IGFsbG93ZWQgY2hhbmdlIGlzIHRoZSBSUENfVEFTS19LSUxMRUQuIFdlIGNvdWxkIGNvbnZl cnQgdGhhdCBpbnRvIGFuIGF0b21pYyBiaXQgaW4gdGFzay0+dGtfcnVuc3RhdGUsIGJ1dCBhZ2Fp biwgdGhpcyBpc24ndCBzb21ldGhpbmcgdGhhdCBpcyBsaWtlbHkgdG8gYmUgcmVzcG9uc2libGUg Zm9yIHRoZSBwcm9ibGVtIHlvdSBhcmUgc2VlaW5nLg0KDQoT77+977+97Lm7HO+/vSbvv71+77+9 Ju+/vRjvv73vv70rLe+/ve+/vd22F++/ve+/vXfvv73vv73Lm++/ve+/ve+/vW3vv71i77+977+9 Z37Ip++/vRfvv73vv73cqH3vv73vv73vv73GoHrvv70majordu+/ve+/ve+/vQfvv73vv73vv73v v716Wivvv73vv70rembvv73vv73vv71o77+977+977+9fu+/ve+/ve+/ve+/vWnvv73vv73vv716 77+9Hu+/vXfvv73vv73vv70/77+977+977+977+9Ju+/vSnfohtm

author
#9 lore raw
Quoted 54 lines · Trond
Quoted 54 lines

-----Original Message-----
From: Ben Greear [mailto:[email protected]]
Sent: Friday, July 08, 2011 1:19 PM
To: Myklebust, Trond
Cc: [email protected]; [email protected]
Subject: Re: [RFC] sunrpc: Fix race between work-queue and rpc_killall_tasks.

Quoted 11 lines · Trond Myklebust
Quoted 10 lines · On Wed, 2011-07-06 at 15:49 -0700, [email protected] wrote:

From: Ben Greear<[email protected]>

The rpc_killall_tasks logic is not locked against the work-queue thread, but it still directly modifies function pointers and data in the task objects.

This patch changes the killall-tasks logic to set a flag that tells the work-queue thread to terminate the task instead of directly calling the terminate logic.

Quoted 7 lines
Quoted 7 lines

---

NOTE: This needs review, as I am still struggling to understand the rpc code, and it's quite possible this patch either doesn't fully fix the problem or actually causes other issues. That said, my nfs stress test seems to run a bit more stable with this patch

applied.

Quoted 2 lines

Yes, but I don't see why you are adding a new flag, nor do I see why

we

Quoted 2 lines

want to keep checking for that flag in the rpc_execute() loop. rpc_killall_tasks() is not a frequent operation that we want to

optimise

Quoted 3 lines

for.

How about the following instead?

Ok, I looked at your patch closer. I think it can still cause bad race conditions.

For instance:

Assume that tk_callback is NULL at beginning of while loop in __rpc_execute,
and tk_action is rpc_exit_task.

While do_action(task) is being called, tk_action is set to NULL in rpc_exit_task.

But, right after tk_action is set to NULL in rpc_exit_task, the rpc_killall_tasks
method calls rpc_exit, which sets tk_action back to rpc_exit_task.

Quoted 8 lines
Quoted 4 lines

I believe this could cause the xprt_release(task) logic to be called in the
work-queue's execution of rpc_exit_task due to tk_action != NULL when it should not be.

Why would this be a problem? xprt_release() can certainly be called multiple times on an rpc_task. Ditto rpbc_getport_done.

The only thing that is not re-entrant there is rpcb_map_release, which should only ever be called once whether or not something calls rpc_killall_tasks.

From the trace I posted, this stack trace below is being called with the void *data object already freed.

One way for this to happen would be to have rpc_exit_task call task->tk_ops->rpc_call_done more than once (I believe). Two calls to rpc_exit_task could do that, and since the rpc_exit_task method is assigned to tk_action, I *think* the race I mention above could cause rpc_exit_task to be called twice.

 [<ffffffff81105907>] print_trailer+0x131/0x13a
 [<ffffffff81105945>] object_err+0x35/0x3e
 [<ffffffff811077b3>] verify_mem_not_deleted+0x7a/0xb7
 [<ffffffffa02891e5>] rpcb_getport_done+0x23/0x126 [sunrpc]
 [<ffffffffa02810df>] rpc_exit_task+0x3f/0x6d [sunrpc]
 [<ffffffffa02814d8>] __rpc_execute+0x80/0x253 [sunrpc]
 [<ffffffffa02816ed>] ? rpc_execute+0x42/0x42 [sunrpc]
 [<ffffffffa02816fd>] rpc_async_schedule+0x10/0x12 [sunrpc]
 [<ffffffff81061343>] process_one_work+0x230/0x41d
 [<ffffffff8106128e>] ? process_one_work+0x17b/0x41d
 [<ffffffff8106379f>] worker_thread+0x133/0x217
 [<ffffffff8106366c>] ? manage_workers+0x191/0x191
 [<ffffffff81066f9c>] kthread+0x7d/0x85
 [<ffffffff81485ee4>] kernel_thread_helper+0x4/0x10
 [<ffffffff8147f0d8>] ? retint_restore_args+0x13/0x13
 [<ffffffff81066f1f>] ? __init_kthread_worker+0x56/0x56
 [<ffffffff81485ee0>] ? gs_change+0x13/0x13

Thanks,
Ben

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
#10 lore raw

PiAtLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLQ0KPiBGcm9tOiBCZW4gR3JlZWFyIFttYWlsdG86 Z3JlZWFyYkBjYW5kZWxhdGVjaC5jb21dDQo+IFNlbnQ6IEZyaWRheSwgSnVseSAwOCwgMjAxMSA2 OjAzIFBNDQo+IFRvOiBNeWtsZWJ1c3QsIFRyb25kDQo+IENjOiBsaW51eC1uZnNAdmdlci5rZXJu ZWwub3JnOyBsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnDQo+IFN1YmplY3Q6IFJlOiBbUkZD XSBzdW5ycGM6IEZpeCByYWNlIGJldHdlZW4gd29yay1xdWV1ZSBhbmQNCj4gcnBjX2tpbGxhbGxf dGFza3MuDQo+IA0KPiBPbiAwNy8wOC8yMDExIDExOjExIEFNLCBNeWtsZWJ1c3QsIFRyb25kIHdy b3RlOg0KPiA+PiAtLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLQ0KPiA+PiBGcm9tOiBCZW4gR3Jl ZWFyIFttYWlsdG86Z3JlZWFyYkBjYW5kZWxhdGVjaC5jb21dDQo+ID4+IFNlbnQ6IEZyaWRheSwg SnVseSAwOCwgMjAxMSAxOjE5IFBNDQo+ID4+IFRvOiBNeWtsZWJ1c3QsIFRyb25kDQo+ID4+IENj OiBsaW51eC1uZnNAdmdlci5rZXJuZWwub3JnOyBsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3Jn DQo+ID4+IFN1YmplY3Q6IFJlOiBbUkZDXSBzdW5ycGM6IEZpeCByYWNlIGJldHdlZW4gd29yay1x dWV1ZSBhbmQNCj4gPj4gcnBjX2tpb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GwgcnBjX2V4aXRfdGFzaygp IGFmdGVyIHJwY19maW5hbF9wdXRfdGFzaw0KTu+/ve+/ve+/ve+/ve+/vXLvv73vv71577+977+9 77+9Yu+/vVjvv73vv73Hp3bvv71e77+9Kd66ey5u77+9K++/ve+/ve+/ve+/vXvvv73vv73vv70i 77+977+9Xm7vv71y77+977+977+9eu+/vRrvv73vv71o77+977+977+977+9Ju+/ve+/vR7vv71H 77+977+977+9aO+/vQMo77+96ZqO77+93aJqIu+/ve+/vRrvv70bbe+/ve+/ve+/ve+/ve+/vXrv v73elu+/ve+/ve+/vWbvv73vv73vv71o77+977+977+9fu+/vW3vv70=

author
#11 lore raw
Quoted 1 line · Trond

The calldata gets freed in the rpc_final_put_task() which shouldn't ever be run while the task is still referenced in __rpc_execute

Ok, please go ahead and use your patch for the killall tasks race. My problem remains with or without your patch, and with or without my version. So, I'm hitting something else.

I'm real low on ideas of how exactly I am hitting the bug..but will keep poking around.

Thanks,
Ben

Quoted 3 lines

IOW: it should be impossible to call rpc_exit_task() after rpc_final_put_task N�����r��y���b�X��ǧv�^�)޺{.n�+����{���"��^n�r��z���h����&���G���h�(�階�ݢj"���m�����z�ޖ���f���h���~�mml==

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
author
#12 lore raw
In reply to Myklebust, Trond
Quoted 18 lines · Trond
Quoted 9 lines
   [<ffffffff81105907>] print_trailer+0x131/0x13a
   [<ffffffff81105945>] object_err+0x35/0x3e
   [<ffffffff811077b3>] verify_mem_not_deleted+0x7a/0xb7
   [<ffffffffa02891e5>] rpcb_getport_done+0x23/0x126 [sunrpc]
   [<ffffffffa02810df>] rpc_exit_task+0x3f/0x6d [sunrpc]
   [<ffffffffa02814d8>] __rpc_execute+0x80/0x253 [sunrpc]
   [<ffffffffa02816ed>] ? rpc_execute+0x42/0x42 [sunrpc]
   [<ffffffffa02816fd>] rpc_async_schedule+0x10/0x12 [sunrpc]
   [<ffffffff81061343>] process_one_work+0x230/0x41d
Quoted 8 lines
   [<ffffffff8106128e>] ? process_one_work+0x17b/0x41d
   [<ffffffff8106379f>] worker_thread+0x133/0x217
   [<ffffffff8106366c>] ? manage_workers+0x191/0x191
   [<ffffffff81066f9c>] kthread+0x7d/0x85
   [<ffffffff81485ee4>] kernel_thread_helper+0x4/0x10
   [<ffffffff8147f0d8>] ? retint_restore_args+0x13/0x13
   [<ffffffff81066f1f>] ? __init_kthread_worker+0x56/0x56
   [<ffffffff81485ee0>] ? gs_change+0x13/0x13
Quoted 3 lines

The calldata gets freed in the rpc_final_put_task() which shouldn't ever be run while the task is still referenced in __rpc_execute

IOW: it should be impossible to call rpc_exit_task() after rpc_final_put_task

I added lots of locking around the calldata, work-queue logic, and such, and still the problem persists w/out hitting any of the debug warnings or poisoned values I put in. It almost seems like tk_calldata is just assigned to two different tasks.

While poking through the code, I noticed that 'map' is static in rpcb_getport_async.

That would seem to cause problems if two threads called this method at the same time, possibly causing tk_calldata to be assigned to two different tasks???

Any idea why it is static?

I'm going to start another test run with this non-static to see if that resolves things...

Thanks,
Ben

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
#13 lore raw

PiAtLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLQ0KPiBGcm9tOiBCZW4gR3JlZWFyIFttYWlsdG86 Z3JlZWFyYkBjYW5kZWxhdGVjaC5jb21dDQo+IFNlbnQ6IFR1ZXNkYXksIEp1bHkgMTIsIDIwMTEg MToxNSBQTQ0KPiBUbzogTXlrbGVidXN0LCBUcm9uZA0KPiBDYzogbGludXgtbmZzQHZnZXIua2Vy bmVsLm9yZzsgbGludXgta2VybmVsQHZnZXIua2VybmVsLm9yZw0KPiBTdWJqZWN0OiBSZTogW1JG Q10gc3VucnBjOiBGaXggcmFjZSBiZXR3ZWVuIHdvcmstcXVldWUgYW5kDQo+IHJwY19raWxsYWxs X3Rhc2tzLg0KPiANCj4gT24gMDcvMDgvMjAxMSAwMzoxNCBQTSwgTX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aWxlIHBva2luZyB0aHJvdWdoIHRoZSBjb2RlLCBJIG5vdGljZWQgdGhhdCAnbWFwJyBp cyBzdGF0aWMgaW4NCj4gcnBjYl9nZXRwb3J0X2FzeW5jLg0KPiANCj4gVGhhdCB3b3VsZCBzZWVt IHRvIGNhdXNlIHByb2JsZW1zIGlmIHR3byB0aHJlYWRzIGNhbGxlZCB0aGlzIG1ldGhvZCBhdA0K PiB0aGUgc2FtZSB0aW1lLCBwb3NzaWJseSBjYXVzaW5nIHRrX2NhbGxkYXRhIHRvIGJlIGFzc2ln bmVkIHRvIHR3bw0KPiBkaWZmZXJlbnQNCj4gdGFza3M/Pz8NCj4gDQo+IEFueSBpZGVhIHdoeSBp dCBpcyBzdGF0aWM/DQoNCkRvaCEgVGhhdCBpcyBjbGVhcmx5IGEgdHlwbyBkYXRpbmcgYWxsIHRo ZSB3YXkgYmFjayB0byB3aGVuIENodWNrIHdyb3RlIHRoYXQgZnVuY3Rpb24uDQoNClllcywgdGhh dCB3b3VsZCBkZWZpbml0ZWx5IGV4cGxhaW4geW91ciBwcm9ibGVtLg0KDQpDaGVlcnMNCiAgVHJv bmQNCgTvv717Lm7vv70r77+977+977+977+977+977+977+9KyXvv73vv71sendt77+977+9Yu+/ veunsu+/ve+/vXLvv73vv716WO+/ve+/vRnfsinvv73vv73vv713Kh9qZ++/ve+/ve+/vR7vv73v v73vv73vv73vv73domov77+977+977+9eu+/vd6W77+977+9Mu+/vd6Z77+977+977+9Ju+/vSnf oe+/vWHvv73vv71/77+977+9Hu+/vUfvv73vv73vv71o77+9D++/vWo6K3bvv73vv73vv71377+9 2aU=

author
#14 lore raw
Quoted 50 lines · Trond
Quoted 50 lines

-----Original Message-----
From: Ben Greear [mailto:[email protected]]
Sent: Tuesday, July 12, 2011 1:15 PM
To: Myklebust, Trond
Cc: [email protected]; [email protected]
Subject: Re: [RFC] sunrpc: Fix race between work-queue and rpc_killall_tasks.

Quoted 18 lines · Trond
Quoted 9 lines
    [<ffffffff81105907>] print_trailer+0x131/0x13a
    [<ffffffff81105945>] object_err+0x35/0x3e
    [<ffffffff811077b3>] verify_mem_not_deleted+0x7a/0xb7
    [<ffffffffa02891e5>] rpcb_getport_done+0x23/0x126 [sunrpc]
    [<ffffffffa02810df>] rpc_exit_task+0x3f/0x6d [sunrpc]
    [<ffffffffa02814d8>] __rpc_execute+0x80/0x253 [sunrpc]
    [<ffffffffa02816ed>] ? rpc_execute+0x42/0x42 [sunrpc]
    [<ffffffffa02816fd>] rpc_async_schedule+0x10/0x12 [sunrpc]
    [<ffffffff81061343>] process_one_work+0x230/0x41d
Quoted 8 lines
    [<ffffffff8106128e>] ? process_one_work+0x17b/0x41d
    [<ffffffff8106379f>] worker_thread+0x133/0x217
    [<ffffffff8106366c>] ? manage_workers+0x191/0x191
    [<ffffffff81066f9c>] kthread+0x7d/0x85
    [<ffffffff81485ee4>] kernel_thread_helper+0x4/0x10
    [<ffffffff8147f0d8>] ? retint_restore_args+0x13/0x13
    [<ffffffff81066f1f>] ? __init_kthread_worker+0x56/0x56
    [<ffffffff81485ee0>] ? gs_change+0x13/0x13
Quoted 1 line

The calldata gets freed in the rpc_final_put_task() which shouldn't

ever be run while the task is still referenced in __rpc_execute

Quoted 2 lines

IOW: it should be impossible to call rpc_exit_task() after

rpc_final_put_task

I added lots of locking around the calldata, work-queue logic, and such, and
still the problem persists w/out hitting any of the debug warnings or poisoned
values I put in. It almost seems like tk_calldata is just assigned to two
different tasks.

While poking through the code, I noticed that 'map' is static in rpcb_getport_async.

That would seem to cause problems if two threads called this method at the same time, possibly causing tk_calldata to be assigned to two different
tasks???

Quoted 5 lines
Quoted 1 line

Any idea why it is static?

Doh! That is clearly a typo dating all the way back to when Chuck wrote that function.

Yes, that would definitely explain your problem.

Ok, patch sent. I assume someone will propagate this to stable as desired?

And assuming this fixes it, can I get some brownie points towards review of the ip-addr binding patches? :)

Thanks,
Ben

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
author
#15 lore raw
Quoted 31 lines · Ben Greear
Quoted 30 lines · Trond
Quoted 20 lines

-----Original Message-----
From: Ben Greear [mailto:[email protected]]
Sent: Tuesday, July 12, 2011 1:15 PM
To: Myklebust, Trond
Cc: [email protected]; [email protected]
Subject: Re: [RFC] sunrpc: Fix race between work-queue and rpc_killall_tasks.

I added lots of locking around the calldata, work-queue logic, and such, and
still the problem persists w/out hitting any of the debug warnings or poisoned
values I put in. It almost seems like tk_calldata is just assigned to two
different tasks.

While poking through the code, I noticed that 'map' is static in rpcb_getport_async.

Quoted 6 lines

That would seem to cause problems if two threads called this method at the same time, possibly causing tk_calldata to be assigned to two different
tasks???

Any idea why it is static?

Doh! That is clearly a typo dating all the way back to when Chuck wrote that function.

Quoted 7 lines
Quoted 1 line

Yes, that would definitely explain your problem.

Ok, patch sent. I assume someone will propagate this to stable as desired?

And assuming this fixes it, can I get some brownie points towards review of the ip-addr binding patches? :)

Just to close this issue: We ran a clean 24+ hour test mounting and unmounting 200 mounts every 30 seconds, and it ran with zero problems.

This was with 2.6.38.8+ with this fix applied.

3.0-rc7+ is still flaky in various other ways, but I see no more NFS problems at least.

So, that was the problem I was hitting, and it appears to be the last problem in this area.

Thanks,
Ben

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com