All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Meena Shanmugam <meenashanmugam@google.com>
Cc: enrico.scholz@sigma-chemnitz.de, stable@vger.kernel.org,
	trond.myklebust@hammerspace.com
Subject: Re: [PATCH 3/4] SUNRPC: Don't call connect() more than once on a TCP socket
Date: Mon, 16 May 2022 23:34:34 +0200	[thread overview]
Message-ID: <YoLDak9O1c1gu54I@kroah.com> (raw)
In-Reply-To: <20220514053453.3277330-4-meenashanmugam@google.com>

On Sat, May 14, 2022 at 05:34:52AM +0000, Meena Shanmugam wrote:
> From: Trond Myklebust <trond.myklebust@hammerspace.com>
> 
> commit 89f42494f92f448747bd8a7ab1ae8b5d5520577d upstream.
> 
> Avoid socket state races due to repeated calls to ->connect() using the
> same socket. If connect() returns 0 due to the connection having
> completed, but we are in fact in a closing state, then we may leave the
> XPRT_CONNECTING flag set on the transport.
> 
> Reported-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
> Fixes: 3be232f11a3c ("SUNRPC: Prevent immediate close+reconnect")
> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
> [meenashanmugam: Backported to 5.10: Fixed merge conflict in xs_tcp_setup_socket]
> Signed-off-by: Meena Shanmugam <meenashanmugam@google.com>
> ---
>  include/linux/sunrpc/xprtsock.h |  1 +
>  net/sunrpc/xprtsock.c           | 21 +++++++++++----------
>  2 files changed, 12 insertions(+), 10 deletions(-)
> 
> diff --git a/include/linux/sunrpc/xprtsock.h b/include/linux/sunrpc/xprtsock.h
> index 8c2a712cb242..689062afdd61 100644
> --- a/include/linux/sunrpc/xprtsock.h
> +++ b/include/linux/sunrpc/xprtsock.h
> @@ -89,5 +89,6 @@ struct sock_xprt {
>  #define XPRT_SOCK_WAKE_WRITE	(5)
>  #define XPRT_SOCK_WAKE_PENDING	(6)
>  #define XPRT_SOCK_WAKE_DISCONNECT	(7)
> +#define XPRT_SOCK_CONNECT_SENT	(8)
>  
>  #endif /* _LINUX_SUNRPC_XPRTSOCK_H */
> diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
> index 60c58eb9a456..33a81f9703b1 100644
> --- a/net/sunrpc/xprtsock.c
> +++ b/net/sunrpc/xprtsock.c
> @@ -2260,10 +2260,14 @@ static void xs_tcp_setup_socket(struct work_struct *work)
>  	struct rpc_xprt *xprt = &transport->xprt;
>  	int status = -EIO;
>  
> -	if (!sock) {
> -		sock = xs_create_sock(xprt, transport,
> -				xs_addr(xprt)->sa_family, SOCK_STREAM,
> -				IPPROTO_TCP, true);
> +	if (xprt_connected(xprt))
> +		goto out;
> +	if (test_and_clear_bit(XPRT_SOCK_CONNECT_SENT,
> +			       &transport->sock_state) ||
> +	    !sock) {
> +		xs_reset_transport(transport);
> +		sock = xs_create_sock(xprt, transport, xs_addr(xprt)->sa_family,
> +				      SOCK_STREAM, IPPROTO_TCP, true);
>  		if (IS_ERR(sock)) {
>  			status = PTR_ERR(sock);
>  			goto out;
> @@ -2294,6 +2298,7 @@ static void xs_tcp_setup_socket(struct work_struct *work)
>  		break;
>  	case 0:
>  	case -EINPROGRESS:
> +		set_bit(XPRT_SOCK_CONNECT_SENT, &transport->sock_state);
>  	case -EALREADY:
>  		xprt_unlock_connect(xprt, transport);
>  		return;
> @@ -2345,13 +2350,9 @@ static void xs_connect(struct rpc_xprt *xprt, struct rpc_task *task)
>  
>  	WARN_ON_ONCE(!xprt_lock_connect(xprt, task, transport));
>  
> -	if (transport->sock != NULL && !xprt_connecting(xprt)) {
> +	if (transport->sock != NULL) {
>  		dprintk("RPC:       xs_connect delayed xprt %p for %lu "
> -				"seconds\n",
> -				xprt, xprt->reestablish_timeout / HZ);
> -
> -		/* Start by resetting any existing state */
> -		xs_reset_transport(transport);
> +			"seconds\n", xprt, xprt->reestablish_timeout / HZ);
>  
>  		delay = xprt_reconnect_delay(xprt);
>  		xprt_reconnect_backoff(xprt, XS_TCP_INIT_REEST_TO);
> -- 
> 2.36.0.550.gb090851708-goog
> 

This commit added a build warning.  Always properly test your changes,
they can not add warnings.

I've fixed it up by hand now.

thanks,

greg k-h

  reply	other threads:[~2022-05-16 21:34 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-11  2:33 Request to cherry-pick f00432063db1 to 5.10 Meena Shanmugam
2022-05-12  6:48 ` Bagas Sanjaya
2022-05-12 16:23 ` Greg KH
2022-05-12 17:38   ` Meena Shanmugam
2022-05-13  8:25     ` Greg KH
2022-05-13 17:59       ` [PATCH] SUNRPC: Don't call connect() more than once on a TCP socket Meena Shanmugam
2022-05-14  4:56         ` Greg KH
2022-05-14  5:34           ` [PATCH 0/4] Request to cherry-pick f00432063db1 to 5.10 Meena Shanmugam
2022-05-14  5:34             ` [PATCH 1/4] SUNRPC: Clean up scheduling of autoclose Meena Shanmugam
2022-05-14  5:34             ` [PATCH 2/4] SUNRPC: Prevent immediate close+reconnect Meena Shanmugam
2022-05-14  5:34             ` [PATCH 3/4] SUNRPC: Don't call connect() more than once on a TCP socket Meena Shanmugam
2022-05-16 21:34               ` Greg KH [this message]
2022-05-17  3:56                 ` Meena Shanmugam
2022-05-14  5:34             ` [PATCH 4/4] SUNRPC: Ensure we flush any closed sockets before xs_xprt_free() Meena Shanmugam
2022-05-14  8:47             ` [PATCH 0/4] Request to cherry-pick f00432063db1 to 5.10 Bagas Sanjaya
2022-05-16 12:43               ` Greg KH
2022-05-13 18:10       ` Meena Shanmugam
2022-05-13 18:14       ` Meena Shanmugam
2022-05-16 12:42         ` Greg KH

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=YoLDak9O1c1gu54I@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=enrico.scholz@sigma-chemnitz.de \
    --cc=meenashanmugam@google.com \
    --cc=stable@vger.kernel.org \
    --cc=trond.myklebust@hammerspace.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.