Skip to contentSkip to conversation

net/rds: RDS-TCP robustness fixes

PATCH Superseded Sowmini Varadhan 2 participants 7 messages May 2, 2015 – May 5, 2015

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover net/rds: RDS-TCP robustness fixes

This patch-set contains bug fixes for state-recovery at the RDS layer when the underlying transport is TCP and the TCP state at one of the endpoints is reset, e.g., due to a "modprobe -r rds_tcp" or a reboot.

When that situation happens, the existing code does not correctly clean up RDS socket state for stale connections, resulting in some unstable, timing-dependant behavior on the wire, including an infinite exchange of 3WHs back-and-forth, and a resulting potential to never converge RDS state.

Test cases used to verify the changes in this set are:

1. Start rds client/server applications on two participating nodes, node1 and node1. After at least one packet has been sent (to establish the TCP connection), restart the rds_tcp module on the client, and now resend packets. Tcpdump should show server sending a FIN for the "old" client port, and clean connection establishment/exchange for the new client port.

2. At the end of step 1, restart rds srever on node2, and start client on node1, make sure using tcpdump, 'netstat -an|grep 16385' that packets flow correctly.

Sowmini Varadhan (2):
RDS-TCP: Always create a new rds_sock for an incoming connection.
RDS-TCP: only initiate reconnect attempt on outgoing TCP socket.

 net/rds/connection.c  |   17 ++++++++++++++-
 net/rds/tcp.c         |   51 ++++++++++++++++++++++++++++++++++++++++++++++++-
 net/rds/tcp.h         |    5 +++-
 net/rds/tcp_connect.c |    2 +-
 net/rds/tcp_listen.c  |   13 +++++++++++-
 5 files changed, 82 insertions(+), 6 deletions(-)
#6 lore raw

PATCH 2/2 net/rds: RDS-TCP: only initiate reconnect attempt on outgoing TCP socket.

When the peer of an RDS-TCP connection restarts, a reconnect attempt should only be made from the active side of the TCP connection, i.e. the side that has a transient TCP port number, else the 2 nodes will have an endless exchange of 3WHs followed by RSTs. Do not add the passive side of the TCP connection to the c_hash_node and thus avoid triggering rds_queue_reconnect() for passive rds connections. Passive side cleanup/recovery is handled in the rds_tcp module.

---
 net/rds/connection.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
net/rds/connection.c +11 -2
index 60f0cd6..da6da57 100644
@@ -234,13 +234,22 @@ static struct rds_connection *__rds_conn_create(__be32 laddr, __be32 faddr,
 		/* Creating normal conn */
 		struct rds_connection *found;
 
-		found = rds_conn_lookup(head, laddr, faddr, trans);
+		if (!is_outgoing && otrans->t_type == RDS_TRANS_TCP)
+			found = NULL;
+		else
+			found = rds_conn_lookup(head, laddr, faddr, trans);
 		if (found) {
 			trans->conn_free(conn->c_transport_data);
 			kmem_cache_free(rds_conn_slab, conn);
 			conn = found;
 		} else {
-			hlist_add_head_rcu(&conn->c_hash_node, head);
+			if ((is_outgoing && otrans->t_type == RDS_TRANS_TCP) ||
+			    (otrans->t_type != RDS_TRANS_TCP)) {
+				/* Only the active side should be added to
+				 * reconnect list for TCP.
+				 */
+				hlist_add_head_rcu(&conn->c_hash_node, head);
+			}
 			rds_cong_add_conn(conn);
 			rds_conn_count++;
 		}
Signature · 1 line
1.7.1
#1 lore raw

PATCH 1/2 net/rds: RDS-TCP: Always create a new rds_sock for an incoming connection.

In reply to Sowmini Varadhan

When running RDS over TCP, the active (client) side connects to the listening ("passive") side at the RDS_TCP_PORT. After the connection is established, if the client side reboots (potentially without even sending a FIN) the server still has a TCP socket in the Established state. If the server-side now gets a new SYN comes from the client with a different client port, TCP will create a new socket-pair, but the RDS layer will incorrectly pull up the old rds_connection (which is still associated with the stale t_sock and RDS socket state).

This patch corrects this behavior by having rds_tcp_accept_one() always create a new connection for an incoming TCP SYN. The rds and tcp state associated with the old socket-pair is cleaned up in rds_tcp_set_callbacks() (i.e., rds_conn_drop on the old connection)

---
 net/rds/connection.c  |    4 +++
 net/rds/tcp.c         |   51 ++++++++++++++++++++++++++++++++++++++++++++++++-
 net/rds/tcp.h         |    5 +++-
 net/rds/tcp_connect.c |    2 +-
 net/rds/tcp_listen.c  |   13 +++++++++++-
 5 files changed, 71 insertions(+), 4 deletions(-)
net/rds/connection.c +4 -0
index 14f0413..60f0cd6 100644
@@ -126,7 +126,10 @@ static struct rds_connection *__rds_conn_create(__be32 laddr, __be32 faddr,
 	struct rds_transport *loop_trans;
 	unsigned long flags;
 	int ret;
+	struct rds_transport *otrans = trans;
 
+	if (!is_outgoing && otrans->t_type == RDS_TRANS_TCP)
+		goto new_conn;
 	rcu_read_lock();
 	conn = rds_conn_lookup(head, laddr, faddr, trans);
 	if (conn && conn->c_loopback && conn->c_trans != &rds_loop_transport &&
@@ -142,6 +145,7 @@ static struct rds_connection *__rds_conn_create(__be32 laddr, __be32 faddr,
 	if (conn)
 		goto out;
 
+new_conn:
 	conn = kmem_cache_zalloc(rds_conn_slab, gfp);
 	if (!conn) {
 		conn = ERR_PTR(-ENOMEM);
net/rds/tcp.c +50 -1

74 lines not on this page · raw message

net/rds/tcp.h +4 -1
index 0dbdd37..a3b3926 100644
@@ -32,6 +32,8 @@ struct rds_tcp_connection {
 	u32			t_last_sent_nxt;
 	u32			t_last_expected_una;
 	u32			t_last_seen_una;
+
+	struct hlist_node	t_passive_conn;
 };
 
 struct rds_tcp_statistics {
@@ -45,7 +47,8 @@ struct rds_tcp_statistics {
 /* tcp.c */
 void rds_tcp_tune(struct socket *sock);
 void rds_tcp_nonagle(struct socket *sock);
-void rds_tcp_set_callbacks(struct socket *sock, struct rds_connection *conn);
+void rds_tcp_set_callbacks(struct socket *sock, struct rds_connection *conn,
+			   bool passive);
 void rds_tcp_restore_callbacks(struct socket *sock,
 			       struct rds_tcp_connection *tc);
 u32 rds_tcp_snd_nxt(struct rds_tcp_connection *tc);
net/rds/tcp_connect.c +1 -1
index f9f564a..e13facb 100644
@@ -103,7 +103,7 @@ int rds_tcp_conn_connect(struct rds_connection *conn)
 	 * once we call connect() we can start getting callbacks and they
 	 * own the socket
 	 */
-	rds_tcp_set_callbacks(sock, conn);
+	rds_tcp_set_callbacks(sock, conn, false);
 	ret = sock->ops->connect(sock, (struct sockaddr *)&dest, sizeof(dest),
 				 O_NONBLOCK);
 
net/rds/tcp_listen.c +12 -1
index 23ab4dc..6b783f1 100644
@@ -51,6 +51,7 @@ static int rds_tcp_accept_one(struct socket *sock)
 	struct rds_connection *conn;
 	int ret;
 	struct inet_sock *inet;
+	struct rds_tcp_connection *rs_tcp;
 
 	ret = sock_create_lite(sock->sk->sk_family, sock->sk->sk_type,
 			       sock->sk->sk_protocol, &new_sock);
@@ -77,6 +78,16 @@ static int rds_tcp_accept_one(struct socket *sock)
 		ret = PTR_ERR(conn);
 		goto out;
 	}
+	/* An incoming SYN request came in, and TCP just accepted it.
+	 * We always create a new conn for listen side of TCP, and do not
+	 * add it to the c_hash_list.
+	 *
+	 * If the client reboots, this conn will need to be cleaned up.
+	 * When we get a new connection request from the client,
+	 * rds_tcp_set_callbacks() will do that cleanup
+	 */
+	rs_tcp = (struct rds_tcp_connection *)conn->c_transport_data;
+	WARN_ON(!rs_tcp || rs_tcp->t_sock);
 
 	/*
 	 * see the comment above rds_queue_delayed_reconnect()
@@ -91,7 +102,7 @@ static int rds_tcp_accept_one(struct socket *sock)
 		goto out;
 	}
 
-	rds_tcp_set_callbacks(new_sock, conn);
+	rds_tcp_set_callbacks(new_sock, conn, true);
 	rds_connect_complete(conn);
 	new_sock = NULL;
 	ret = 0;
Signature · 1 line
1.7.1
maintainer
#2 lore raw

Re: [PATCH 1/2] net/rds: RDS-TCP: Always create a new rds_sock for an incoming connection.

From: Sowmini Varadhan <[email protected]>
Date: Sat, 2 May 2015 07:55:08 -0400

Quoted 9 lines

When running RDS over TCP, the active (client) side connects to the listening ("passive") side at the RDS_TCP_PORT. After the connection is established, if the client side reboots (potentially without even sending a FIN) the server still has a TCP socket in the Established state. If the server-side now gets a new SYN comes from the client with a different client port, TCP will create a new socket-pair, but the RDS layer will incorrectly pull up the old rds_connection (which is still associated with the stale t_sock and RDS socket state).

Quoted 7 lines

This patch corrects this behavior by having rds_tcp_accept_one() always create a new connection for an incoming TCP SYN. The rds and tcp state associated with the old socket-pair is cleaned up in rds_tcp_set_callbacks() (i.e., rds_conn_drop on the old connection)

I think adding 64K of data to this module just to solve this rare issue is excessive.

Furthermore I don't see any locking protecting the hash table nor the RDS socket linkage into that table.

#3 lore raw

Re: [PATCH 1/2] net/rds: RDS-TCP: Always create a new rds_sock for an incoming connection.

Quoted 3 lines · David Miller

I think adding 64K of data to this module just to solve this rare issue is excessive.

I'd based that number mostly as a heuristic based on rds_conn_hash[]. Any suggestions for what's reasonable? 8K? Less?
(BTW, I think that should be 32K, or am I mis-counting?)

Quoted 2 lines

Furthermore I don't see any locking protecting the hash table nor the RDS socket linkage into that table.

yes, I missed that, I'll fix that in v2.

--Sowmini

maintainer
#4 lore raw

Re: [PATCH 1/2] net/rds: RDS-TCP: Always create a new rds_sock for an incoming connection.

From: Sowmini Varadhan <[email protected]>
Date: Mon, 4 May 2015 15:29:08 -0400

Quoted 8 lines · David Miller
Quoted 3 lines

I think adding 64K of data to this module just to solve this rare issue is excessive.

I'd based that number mostly as a heuristic based on rds_conn_hash[]. Any suggestions for what's reasonable? 8K? Less?
(BTW, I think that should be 32K, or am I mis-counting?)

No table at all.

There has to be another way to notice this kind of situation, how for example does NFS or any other sunrpc using service handle this case?

#5 lore raw

Re: [PATCH 1/2] net/rds: RDS-TCP: Always create a new rds_sock for an incoming connection.

Quoted 6 lines · David Miller

No table at all.

There has to be another way to notice this kind of situation, how for example does NFS or any other sunrpc using service handle this case?

NFS fixes up CLOSE_WAIT connections from xs_tcp_state_change, so at the least, I can also do rds_conn_drop from rds_tcp_state_change, that will avoid all the extra baggage around the new hash list.

But there's the case of the client disappearing without even sending a FIN, and here NFS seems to recover using a notion of idle-timeout (which applies to all idle peers, not merely the dead ones?)

The closest analog of that would be to set up a so_keepalive option on the socket, but that brings in even more heuristics keepcnt, keepintvl, keepidle. Maybe I could set these to be some very generous values for now..

--Sowmini