From: Jeff Layton <jlayton@poochiereds.net>
To: trond.myklebust@primarydata.com
Cc: linux-nfs@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, Mel Gorman <mgorman@suse.de>,
Jerome Marchand <jmarchan@redhat.com>
Subject: Re: [PATCH 4/4] sunrpc: lock xprt before trying to set memalloc on the sockets
Date: Sat, 30 May 2015 08:57:10 -0400 [thread overview]
Message-ID: <20150530085710.34035d84@tlielax.poochiereds.net> (raw)
In-Reply-To: <1432987393-15604-5-git-send-email-jeff.layton@primarydata.com>
On Sat, 30 May 2015 08:03:13 -0400
Jeff Layton <jlayton@poochiereds.net> 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@suse.de>
> Signed-off-by: Jeff Layton <jeff.layton@primarydata.com>
> ---
> 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@poochiereds.net>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
prev parent reply other threads:[~2015-05-30 12:57 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-30 12:03 [PATCH 0/4] sunrpc: clean up "swapper" xprt handling Jeff Layton
2015-05-30 12:03 ` [PATCH 1/4] sunrpc: keep a count of swapfiles associated with the rpc_clnt Jeff Layton
2015-06-02 12:36 ` Mel Gorman
2015-05-30 12:03 ` [PATCH 2/4] sunrpc: make xprt->swapper an atomic_t Jeff Layton
2015-05-30 17:55 ` Chuck Lever
2015-05-30 19:38 ` Jeff Layton
2015-05-30 12:03 ` [PATCH 3/4] sunrpc: if we're closing down a socket, clear memalloc on it first Jeff Layton
2015-06-02 12:38 ` Mel Gorman
2015-06-02 12:40 ` Mel Gorman
2015-06-03 14:32 ` Jeff Layton
2015-06-04 13:08 ` Mel Gorman
2015-06-04 14:25 ` Jeff Layton
2015-05-30 12:03 ` [PATCH 4/4] sunrpc: lock xprt before trying to set memalloc on the sockets Jeff Layton
2015-05-30 12:57 ` Jeff Layton [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150530085710.34035d84@tlielax.poochiereds.net \
--to=jlayton@poochiereds.net \
--cc=jmarchan@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-nfs@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=trond.myklebust@primarydata.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).