Skip to content

Commit 1a0e100

Browse files
sowminivdavem330
authored andcommitted
RDS: TCP: Force every connection to be initiated by numerically smaller IP address
When 2 RDS peers initiate an RDS-TCP connection simultaneously, there is a potential for "duelling syns" on either/both sides. See commit 241b271 ("RDS-TCP: Reset tcp callbacks if re-using an outgoing socket in rds_tcp_accept_one()") for a description of this condition, and the arbitration logic which ensures that the numerically large IP address in the TCP connection is bound to the RDS_TCP_PORT ("canonical ordering"). The rds_connection should not be marked as RDS_CONN_UP until the arbitration logic has converged for the following reason. The sender may start transmitting RDS datagrams as soon as RDS_CONN_UP is set, and since the sender removes all datagrams from the rds_connection's cp_retrans queue based on TCP acks. If the TCP ack was sent from a tcp socket that got reset as part of duel aribitration (but before data was delivered to the receivers RDS socket layer), the sender may end up prematurely freeing the datagram, and the datagram is no longer reliably deliverable. This patch remedies that condition by making sure that, upon receipt of 3WH completion state change notification of TCP_ESTABLISHED in rds_tcp_state_change, we mark the rds_connection as RDS_CONN_UP if, and only if, the IP addresses and ports for the connection are canonically ordered. In all other cases, rds_tcp_state_change will force an rds_conn_path_drop(), and rds_queue_reconnect() on both peers will restart the connection to ensure canonical ordering. A side-effect of enforcing this condition in rds_tcp_state_change() is that rds_tcp_accept_one_path() can now be refactored for simplicity. It is also no longer possible to encounter an RDS_CONN_UP connection in the arbitration logic in rds_tcp_accept_one(). Signed-off-by: Sowmini Varadhan <sowmini.varadhan@oracle.com> Acked-by: Santosh Shilimkar <santosh.shilimkar@oracle.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 905dd41 commit 1a0e100

3 files changed

Lines changed: 26 additions & 18 deletions

File tree

‎net/rds/connection.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ void rds_conn_path_connect_if_down(struct rds_conn_path *cp)
683683
!test_and_set_bit(RDS_RECONNECT_PENDING, &cp->cp_flags))
684684
queue_delayed_work(rds_wq, &cp->cp_conn_w, 0);
685685
}
686+
EXPORT_SYMBOL_GPL(rds_conn_path_connect_if_down);
686687

687688
void rds_conn_connect_if_down(struct rds_connection *conn)
688689
{

‎net/rds/tcp_connect.c‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,19 @@ void rds_tcp_state_change(struct sock *sk)
6060
case TCP_SYN_RECV:
6161
break;
6262
case TCP_ESTABLISHED:
63-
rds_connect_path_complete(cp, RDS_CONN_CONNECTING);
63+
/* Force the peer to reconnect so that we have the
64+
* TCP ports going from <smaller-ip>.<transient> to
65+
* <larger-ip>.<RDS_TCP_PORT>. We avoid marking the
66+
* RDS connection as RDS_CONN_UP until the reconnect,
67+
* to avoid RDS datagram loss.
68+
*/
69+
if (cp->cp_conn->c_laddr > cp->cp_conn->c_faddr &&
70+
rds_conn_path_transition(cp, RDS_CONN_CONNECTING,
71+
RDS_CONN_ERROR)) {
72+
rds_conn_path_drop(cp);
73+
} else {
74+
rds_connect_path_complete(cp, RDS_CONN_CONNECTING);
75+
}
6476
break;
6577
case TCP_CLOSE_WAIT:
6678
case TCP_CLOSE:

‎net/rds/tcp_listen.c‎

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,20 @@ struct rds_tcp_connection *rds_tcp_accept_one_path(struct rds_connection *conn)
8383
{
8484
int i;
8585
bool peer_is_smaller = (conn->c_faddr < conn->c_laddr);
86-
int npaths = conn->c_npaths;
87-
88-
if (npaths <= 1) {
89-
struct rds_conn_path *cp = &conn->c_path[0];
90-
int ret;
91-
92-
ret = rds_conn_path_transition(cp, RDS_CONN_DOWN,
93-
RDS_CONN_CONNECTING);
94-
if (!ret)
95-
rds_conn_path_transition(cp, RDS_CONN_ERROR,
96-
RDS_CONN_CONNECTING);
97-
return cp->cp_transport_data;
98-
}
86+
int npaths = max_t(int, 1, conn->c_npaths);
9987

100-
/* for mprds, paths with cp_index > 0 MUST be initiated by the peer
88+
/* for mprds, all paths MUST be initiated by the peer
10189
* with the smaller address.
10290
*/
103-
if (!peer_is_smaller)
91+
if (!peer_is_smaller) {
92+
/* Make sure we initiate at least one path if this
93+
* has not already been done; rds_start_mprds() will
94+
* take care of additional paths, if necessary.
95+
*/
96+
if (npaths == 1)
97+
rds_conn_path_connect_if_down(&conn->c_path[0]);
10498
return NULL;
99+
}
105100

106101
for (i = 0; i < npaths; i++) {
107102
struct rds_conn_path *cp = &conn->c_path[i];
@@ -171,8 +166,8 @@ int rds_tcp_accept_one(struct socket *sock)
171166
mutex_lock(&rs_tcp->t_conn_path_lock);
172167
cp = rs_tcp->t_cpath;
173168
conn_state = rds_conn_path_state(cp);
174-
if (conn_state != RDS_CONN_CONNECTING && conn_state != RDS_CONN_UP &&
175-
conn_state != RDS_CONN_ERROR)
169+
WARN_ON(conn_state == RDS_CONN_UP);
170+
if (conn_state != RDS_CONN_CONNECTING && conn_state != RDS_CONN_ERROR)
176171
goto rst_nsk;
177172
if (rs_tcp->t_sock) {
178173
/* Need to resolve a duelling SYN between peers.

0 commit comments

Comments
 (0)