Commit d5b39621 authored by Trond Myklebust's avatar Trond Myklebust Committed by Ben Hutchings

SUNRPC: Prevent races in xs_abort_connection()

commit 4bc1e68e upstream.

The call to xprt_disconnect_done() that is triggered by a successful
connection reset will trigger another automatic wakeup of all tasks
on the xprt->pending rpc_wait_queue. In particular it will cause an
early wake up of the task that called xprt_connect().

All we really want to do here is clear all the socket-specific state
flags, so we split that functionality out of xs_sock_mark_closed()
into a helper that can be called by xs_abort_connection()
Reported-by: default avatarChris Perl <chris.perl@gmail.com>
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
Tested-by: default avatarChris Perl <chris.perl@gmail.com>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent b6181a66
...@@ -1465,7 +1465,7 @@ static void xs_tcp_cancel_linger_timeout(struct rpc_xprt *xprt) ...@@ -1465,7 +1465,7 @@ static void xs_tcp_cancel_linger_timeout(struct rpc_xprt *xprt)
xprt_clear_connecting(xprt); xprt_clear_connecting(xprt);
} }
static void xs_sock_mark_closed(struct rpc_xprt *xprt) static void xs_sock_reset_connection_flags(struct rpc_xprt *xprt)
{ {
smp_mb__before_clear_bit(); smp_mb__before_clear_bit();
clear_bit(XPRT_CONNECTION_ABORT, &xprt->state); clear_bit(XPRT_CONNECTION_ABORT, &xprt->state);
...@@ -1473,6 +1473,11 @@ static void xs_sock_mark_closed(struct rpc_xprt *xprt) ...@@ -1473,6 +1473,11 @@ static void xs_sock_mark_closed(struct rpc_xprt *xprt)
clear_bit(XPRT_CLOSE_WAIT, &xprt->state); clear_bit(XPRT_CLOSE_WAIT, &xprt->state);
clear_bit(XPRT_CLOSING, &xprt->state); clear_bit(XPRT_CLOSING, &xprt->state);
smp_mb__after_clear_bit(); smp_mb__after_clear_bit();
}
static void xs_sock_mark_closed(struct rpc_xprt *xprt)
{
xs_sock_reset_connection_flags(xprt);
/* Mark transport as closed and wake up all pending tasks */ /* Mark transport as closed and wake up all pending tasks */
xprt_disconnect_done(xprt); xprt_disconnect_done(xprt);
} }
...@@ -2028,10 +2033,8 @@ static void xs_abort_connection(struct sock_xprt *transport) ...@@ -2028,10 +2033,8 @@ static void xs_abort_connection(struct sock_xprt *transport)
any.sa_family = AF_UNSPEC; any.sa_family = AF_UNSPEC;
result = kernel_connect(transport->sock, &any, sizeof(any), 0); result = kernel_connect(transport->sock, &any, sizeof(any), 0);
if (!result) if (!result)
xs_sock_mark_closed(&transport->xprt); xs_sock_reset_connection_flags(&transport->xprt);
else dprintk("RPC: AF_UNSPEC connect return code %d\n", result);
dprintk("RPC: AF_UNSPEC connect return code %d\n",
result);
} }
static void xs_tcp_reuse_connection(struct sock_xprt *transport) static void xs_tcp_reuse_connection(struct sock_xprt *transport)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment