]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
Fix SUNRPC wakeup/execute race condition
authorChristophe Saout <christophe@saout.de>
Fri, 15 Dec 2006 00:20:35 +0000 (01:20 +0100)
committerAdrian Bunk <bunk@stusta.de>
Fri, 15 Dec 2006 00:20:35 +0000 (01:20 +0100)
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.

Signed-off-by: Christophe Saout <christophe@saout.de>
Acked-by: Trond Myklebust <trond.myklebust@fys.uio.no>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
net/sunrpc/sched.c

index e838d042f7f51e2f0ded4852ddc08441ba8ff687..d1c8b47f0d0946bc9a3c7e1bd3e38cb065e7a13f 100644 (file)
@@ -299,13 +299,15 @@ EXPORT_SYMBOL(__rpc_wait_for_completion_task);
  */
 static void rpc_make_runnable(struct rpc_task *task)
 {
-       int do_ret;
-
        BUG_ON(task->tk_timeout_fn);
-       do_ret = rpc_test_and_set_running(task);
        rpc_clear_queued(task);
-       if (do_ret)
+       if (rpc_test_and_set_running(task))
+               return;
+       /* We might have raced */
+       if (RPC_IS_QUEUED(task)) {
+               rpc_clear_running(task);
                return;
+       }
        if (RPC_IS_ASYNC(task)) {
                int status;