diff mbox

[05/10] SUNRPC: lock the socket while detaching it

Message ID 1466780152-7154-5-git-send-email-trond.myklebust@primarydata.com (mailing list archive)
State New, archived
Headers show

Commit Message

Trond Myklebust June 24, 2016, 2:55 p.m. UTC
Prevent callbacks from triggering while we're detaching the socket.

Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
---
 net/sunrpc/svcsock.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

J. Bruce Fields June 24, 2016, 9:06 p.m. UTC | #1
On Fri, Jun 24, 2016 at 10:55:47AM -0400, Trond Myklebust wrote:
> Prevent callbacks from triggering while we're detaching the socket.

What motivated this?  Do we have a bug without it?

--b.

> 
> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
> ---
>  net/sunrpc/svcsock.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
> index dadfec66dbd8..abe2da602fb8 100644
> --- a/net/sunrpc/svcsock.c
> +++ b/net/sunrpc/svcsock.c
> @@ -1611,9 +1611,12 @@ static void svc_sock_detach(struct svc_xprt *xprt)
>  	dprintk("svc: svc_sock_detach(%p)\n", svsk);
>  
>  	/* put back the old socket callbacks */
> +	lock_sock(sk);
>  	sk->sk_state_change = svsk->sk_ostate;
>  	sk->sk_data_ready = svsk->sk_odata;
>  	sk->sk_write_space = svsk->sk_owspace;
> +	sk->sk_user_data = NULL;
> +	release_sock(sk);
>  
>  	wq = sk_sleep(sk);
>  	if (sunrpc_waitqueue_active(wq))
> -- 
> 2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Trond Myklebust June 24, 2016, 9:21 p.m. UTC | #2
> On Jun 24, 2016, at 17:06, J. Bruce Fields <bfields@fieldses.org> wrote:
> 
> On Fri, Jun 24, 2016 at 10:55:47AM -0400, Trond Myklebust wrote:
>> Prevent callbacks from triggering while we're detaching the socket.
> 
> What motivated this?  Do we have a bug without it?

Code inspection. Without locking, what ensures that you don’t have another processor calling into, say, svc_tcp_state_change() while this processor is tearing down your svc_sock.

> 
> --b.
> 
>> 
>> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
>> ---
>> net/sunrpc/svcsock.c | 3 +++
>> 1 file changed, 3 insertions(+)
>> 
>> diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
>> index dadfec66dbd8..abe2da602fb8 100644
>> --- a/net/sunrpc/svcsock.c
>> +++ b/net/sunrpc/svcsock.c
>> @@ -1611,9 +1611,12 @@ static void svc_sock_detach(struct svc_xprt *xprt)
>> 	dprintk("svc: svc_sock_detach(%p)\n", svsk);
>> 
>> 	/* put back the old socket callbacks */
>> +	lock_sock(sk);
>> 	sk->sk_state_change = svsk->sk_ostate;
>> 	sk->sk_data_ready = svsk->sk_odata;
>> 	sk->sk_write_space = svsk->sk_owspace;
>> +	sk->sk_user_data = NULL;
>> +	release_sock(sk);
>> 
>> 	wq = sk_sleep(sk);
>> 	if (sunrpc_waitqueue_active(wq))
>> -- 
>> 2.7.4
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index dadfec66dbd8..abe2da602fb8 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -1611,9 +1611,12 @@  static void svc_sock_detach(struct svc_xprt *xprt)
 	dprintk("svc: svc_sock_detach(%p)\n", svsk);
 
 	/* put back the old socket callbacks */
+	lock_sock(sk);
 	sk->sk_state_change = svsk->sk_ostate;
 	sk->sk_data_ready = svsk->sk_odata;
 	sk->sk_write_space = svsk->sk_owspace;
+	sk->sk_user_data = NULL;
+	release_sock(sk);
 
 	wq = sk_sleep(sk);
 	if (sunrpc_waitqueue_active(wq))