Re: [PATCH 4/4] sunrpc: lock xprt before trying to set memalloc on the sockets

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 30 May 2015 08:03:13 -0400
Jeff Layton <jlayton@xxxxxxxxxxxxxxx> wrote:

> It's possible that we could race with a call to xs_reset_transport, in
> which case the xprt->inet pointer could be zeroed out while we're
> accessing it. Lock the xprt before we try to set memalloc on it.
> 
> Cc: Mel Gorman <mgorman@xxxxxxx>
> Signed-off-by: Jeff Layton <jeff.layton@xxxxxxxxxxxxxxx>
> ---
>  net/sunrpc/xprtsock.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
> index 359446442112..91770ccab608 100644
> --- a/net/sunrpc/xprtsock.c
> +++ b/net/sunrpc/xprtsock.c
> @@ -1964,11 +1964,22 @@ static void xs_local_connect(struct rpc_xprt *xprt, struct rpc_task *task)
>  }
>  
>  #ifdef CONFIG_SUNRPC_SWAP
> +/*
> + * Note that this should be called with XPRT_LOCKED held (or when we otherwise
> + * know that we have exclusive access to the socket), to guard against
> + * races with xs_reset_transport.
> + */
>  static void xs_set_memalloc(struct rpc_xprt *xprt)
>  {
>  	struct sock_xprt *transport = container_of(xprt, struct sock_xprt,
>  			xprt);
>  
> +	/*
> +	 * If there's no sock, then we have nothing to set. The
> +	 * reconnecting process will get it for us.
> +	 */
> +	if (!transport->inet)
> +		return;
>  	if (atomic_read(&xprt->swapper))
>  		sk_set_memalloc(transport->inet);
>  }
> @@ -1986,8 +1997,11 @@ xs_swapper_enable(struct rpc_xprt *xprt)
>  	struct sock_xprt *transport = container_of(xprt, struct sock_xprt,
>  			xprt);
>  
> +	if (wait_on_bit_lock(&xprt->state, XPRT_LOCKED, TASK_KILLABLE))
> +		return -ERESTARTSYS;
>  	if (atomic_inc_return(&xprt->swapper) == 1)
>  		sk_set_memalloc(transport->inet);

Oh, we need to check that transport->inet is not NULL before we call
sk_set/clear_memalloc on it. I'll respin with that fix once I give
everyone a chance to comment on the rest...

> +	xprt_release_xprt(xprt, NULL);
>  	return 0;
>  }
>  
> @@ -2004,8 +2018,11 @@ xs_swapper_disable(struct rpc_xprt *xprt)
>  	struct sock_xprt *transport = container_of(xprt, struct sock_xprt,
>  			xprt);
>  
> +	if (wait_on_bit_lock(&xprt->state, XPRT_LOCKED, TASK_UNINTERRUPTIBLE))
> +		return;
>  	if (atomic_dec_and_test(&xprt->swapper))
>  		sk_clear_memalloc(transport->inet);
> +	xprt_release_xprt(xprt, NULL);
>  }
>  #else
>  static void xs_set_memalloc(struct rpc_xprt *xprt)


-- 
Jeff Layton <jlayton@xxxxxxxxxxxxxxx>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]