aboutsummaryrefslogtreecommitdiffstats
path: root/net/sunrpc/sched.c
diff options
context:
space:
mode:
authorChristophe Saout <christophe@saout.de>2006-11-05 12:42:48 -0500
committerTrond Myklebust <Trond.Myklebust@netapp.com>2006-12-06 10:46:24 -0500
commitcc4dc59e5580d6c0de1685a25b74d32175f43434 (patch)
tree61de2e40ba38b93027124d691308fc4405ef35d2 /net/sunrpc/sched.c
parentec0bf39a471bf6fcd01def2bd677128cea940b73 (diff)
Subject: Re: [PATCH] Fix SUNRPC wakeup/execute race condition
The sunrpc scheduler contains a race condition that can let an RPC task end up being neither running nor on any wait queue. The race takes place between rpc_make_runnable (called from rpc_wake_up_task) and __rpc_execute under the following condition: First __rpc_execute calls tk_action which puts the task on some wait queue. The task is dequeued by another process before __rpc_execute continues its execution. While executing rpc_make_runnable exactly after setting the task `running' bit and before clearing the `queued' bit __rpc_execute picks up execution, clears `running' and subsequently both functions fall through, both under the false assumption somebody else took the job. Swapping rpc_test_and_set_running with rpc_clear_queued in rpc_make_runnable fixes that hole. This introduces another possible race condition that can be handled by checking for `queued' after setting the `running' bit. Bug noticed on a 4-way x86_64 system under XEN with an NFSv4 server on the same physical machine, apparently one of the few ways to hit this race condition at all. Cc: Trond Myklebust <trond.myklebust@fys.uio.no> Cc: J. Bruce Fields <bfields@citi.umich.edu> Signed-off-by: Christophe Saout <christophe@saout.de> Signed-off-by: Trond Myklebust <trond.myklebust@fys.uio.no>
Diffstat (limited to 'net/sunrpc/sched.c')
-rw-r--r--net/sunrpc/sched.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
index a1ab4eed41f4..b57d4062d429 100644
--- a/net/sunrpc/sched.c
+++ b/net/sunrpc/sched.c
@@ -295,13 +295,15 @@ EXPORT_SYMBOL(__rpc_wait_for_completion_task);
295 */ 295 */
296static void rpc_make_runnable(struct rpc_task *task) 296static void rpc_make_runnable(struct rpc_task *task)
297{ 297{
298 int do_ret;
299
300 BUG_ON(task->tk_timeout_fn); 298 BUG_ON(task->tk_timeout_fn);
301 do_ret = rpc_test_and_set_running(task);
302 rpc_clear_queued(task); 299 rpc_clear_queued(task);
303 if (do_ret) 300 if (rpc_test_and_set_running(task))
301 return;
302 /* We might have raced */
303 if (RPC_IS_QUEUED(task)) {
304 rpc_clear_running(task);
304 return; 305 return;
306 }
305 if (RPC_IS_ASYNC(task)) { 307 if (RPC_IS_ASYNC(task)) {
306 int status; 308 int status;
307 309