Skip to content

Commit fcd2b0d

Browse files
committed
Merge branch 'rds-ha-failover-fixes'
Sowmini Varadhan says: ==================== RDS: TCP: HA/Failover fixes This series contains a set of fixes for bugs exposed when we ran the following in a loop between a test machine pair: while (1); do # modprobe rds-tcp on test nodes # run rds-stress in bi-dir mode between test machine pair # modprobe -r rds-tcp on test nodes done rds-stress in bi-dir mode will cause both nodes to initiate RDS-TCP connections at almost the same instant, exposing the bugs fixed in this series. Without the fixes, rds-stress reports sporadic packet drops, and packets arriving out of sequence. After the fixes,we have been able to run the test overnight, without any issues. Each patch has a detailed description of the root-cause fixed by the patch. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents b3e5106 + 1a0e100 commit fcd2b0d

9 files changed

Lines changed: 86 additions & 21 deletions

File tree

‎net/rds/af_rds.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,10 +605,14 @@ static void rds_exit(void)
605605
}
606606
module_exit(rds_exit);
607607

608+
u32 rds_gen_num;
609+
608610
static int rds_init(void)
609611
{
610612
int ret;
611613

614+
net_get_random_once(&rds_gen_num, sizeof(rds_gen_num));
615+
612616
ret = rds_bind_lock_init();
613617
if (ret)
614618
goto out;

‎net/rds/connection.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ static struct rds_connection *__rds_conn_create(struct net *net,
269269
kmem_cache_free(rds_conn_slab, conn);
270270
conn = found;
271271
} else {
272+
conn->c_my_gen_num = rds_gen_num;
273+
conn->c_peer_gen_num = 0;
272274
hlist_add_head_rcu(&conn->c_hash_node, head);
273275
rds_cong_add_conn(conn);
274276
rds_conn_count++;
@@ -681,6 +683,7 @@ void rds_conn_path_connect_if_down(struct rds_conn_path *cp)
681683
!test_and_set_bit(RDS_RECONNECT_PENDING, &cp->cp_flags))
682684
queue_delayed_work(rds_wq, &cp->cp_conn_w, 0);
683685
}
686+
EXPORT_SYMBOL_GPL(rds_conn_path_connect_if_down);
684687

685688
void rds_conn_connect_if_down(struct rds_connection *conn)
686689
{

‎net/rds/message.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static unsigned int rds_exthdr_size[__RDS_EXTHDR_MAX] = {
4242
[RDS_EXTHDR_RDMA] = sizeof(struct rds_ext_header_rdma),
4343
[RDS_EXTHDR_RDMA_DEST] = sizeof(struct rds_ext_header_rdma_dest),
4444
[RDS_EXTHDR_NPATHS] = sizeof(u16),
45+
[RDS_EXTHDR_GEN_NUM] = sizeof(u32),
4546
};
4647

4748

‎net/rds/rds.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ struct rds_connection {
151151

152152
struct rds_conn_path c_path[RDS_MPATH_WORKERS];
153153
wait_queue_head_t c_hs_waitq; /* handshake waitq */
154+
155+
u32 c_my_gen_num;
156+
u32 c_peer_gen_num;
154157
};
155158

156159
static inline
@@ -243,7 +246,8 @@ struct rds_ext_header_rdma_dest {
243246
/* Extension header announcing number of paths.
244247
* Implicit length = 2 bytes.
245248
*/
246-
#define RDS_EXTHDR_NPATHS 4
249+
#define RDS_EXTHDR_NPATHS 5
250+
#define RDS_EXTHDR_GEN_NUM 6
247251

248252
#define __RDS_EXTHDR_MAX 16 /* for now */
249253

@@ -338,6 +342,7 @@ static inline u32 rds_rdma_cookie_offset(rds_rdma_cookie_t cookie)
338342
#define RDS_MSG_RETRANSMITTED 5
339343
#define RDS_MSG_MAPPED 6
340344
#define RDS_MSG_PAGEVEC 7
345+
#define RDS_MSG_FLUSH 8
341346

342347
struct rds_message {
343348
atomic_t m_refcount;
@@ -664,6 +669,7 @@ void rds_cong_exit(void);
664669
struct rds_message *rds_cong_update_alloc(struct rds_connection *conn);
665670

666671
/* conn.c */
672+
extern u32 rds_gen_num;
667673
int rds_conn_init(void);
668674
void rds_conn_exit(void);
669675
struct rds_connection *rds_conn_create(struct net *net,

‎net/rds/recv.c‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,36 @@ static void rds_recv_rcvbuf_delta(struct rds_sock *rs, struct sock *sk,
120120
/* do nothing if no change in cong state */
121121
}
122122

123+
static void rds_conn_peer_gen_update(struct rds_connection *conn,
124+
u32 peer_gen_num)
125+
{
126+
int i;
127+
struct rds_message *rm, *tmp;
128+
unsigned long flags;
129+
130+
WARN_ON(conn->c_trans->t_type != RDS_TRANS_TCP);
131+
if (peer_gen_num != 0) {
132+
if (conn->c_peer_gen_num != 0 &&
133+
peer_gen_num != conn->c_peer_gen_num) {
134+
for (i = 0; i < RDS_MPATH_WORKERS; i++) {
135+
struct rds_conn_path *cp;
136+
137+
cp = &conn->c_path[i];
138+
spin_lock_irqsave(&cp->cp_lock, flags);
139+
cp->cp_next_tx_seq = 1;
140+
cp->cp_next_rx_seq = 0;
141+
list_for_each_entry_safe(rm, tmp,
142+
&cp->cp_retrans,
143+
m_conn_item) {
144+
set_bit(RDS_MSG_FLUSH, &rm->m_flags);
145+
}
146+
spin_unlock_irqrestore(&cp->cp_lock, flags);
147+
}
148+
}
149+
conn->c_peer_gen_num = peer_gen_num;
150+
}
151+
}
152+
123153
/*
124154
* Process all extension headers that come with this message.
125155
*/
@@ -163,7 +193,9 @@ static void rds_recv_hs_exthdrs(struct rds_header *hdr,
163193
union {
164194
struct rds_ext_header_version version;
165195
u16 rds_npaths;
196+
u32 rds_gen_num;
166197
} buffer;
198+
u32 new_peer_gen_num = 0;
167199

168200
while (1) {
169201
len = sizeof(buffer);
@@ -176,13 +208,17 @@ static void rds_recv_hs_exthdrs(struct rds_header *hdr,
176208
conn->c_npaths = min_t(int, RDS_MPATH_WORKERS,
177209
buffer.rds_npaths);
178210
break;
211+
case RDS_EXTHDR_GEN_NUM:
212+
new_peer_gen_num = buffer.rds_gen_num;
213+
break;
179214
default:
180215
pr_warn_ratelimited("ignoring unknown exthdr type "
181216
"0x%x\n", type);
182217
}
183218
}
184219
/* if RDS_EXTHDR_NPATHS was not found, default to a single-path */
185220
conn->c_npaths = max_t(int, conn->c_npaths, 1);
221+
rds_conn_peer_gen_update(conn, new_peer_gen_num);
186222
}
187223

188224
/* rds_start_mprds() will synchronously start multiple paths when appropriate.

‎net/rds/send.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,9 @@ int rds_send_xmit(struct rds_conn_path *cp)
259259
* connection.
260260
* Therefore, we never retransmit messages with RDMA ops.
261261
*/
262-
if (rm->rdma.op_active &&
263-
test_bit(RDS_MSG_RETRANSMITTED, &rm->m_flags)) {
262+
if (test_bit(RDS_MSG_FLUSH, &rm->m_flags) ||
263+
(rm->rdma.op_active &&
264+
test_bit(RDS_MSG_RETRANSMITTED, &rm->m_flags))) {
264265
spin_lock_irqsave(&cp->cp_lock, flags);
265266
if (test_and_clear_bit(RDS_MSG_ON_CONN, &rm->m_flags))
266267
list_move(&rm->m_conn_item, &to_be_dropped);
@@ -1209,6 +1210,10 @@ rds_send_probe(struct rds_conn_path *cp, __be16 sport,
12091210
rds_message_add_extension(&rm->m_inc.i_hdr,
12101211
RDS_EXTHDR_NPATHS, &npaths,
12111212
sizeof(npaths));
1213+
rds_message_add_extension(&rm->m_inc.i_hdr,
1214+
RDS_EXTHDR_GEN_NUM,
1215+
&cp->cp_conn->c_my_gen_num,
1216+
sizeof(u32));
12121217
}
12131218
spin_unlock_irqrestore(&cp->cp_lock, flags);
12141219

‎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.

‎net/rds/tcp_send.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ int rds_tcp_xmit(struct rds_connection *conn, struct rds_message *rm,
100100
set_bit(RDS_MSG_HAS_ACK_SEQ, &rm->m_flags);
101101
tc->t_last_expected_una = rm->m_ack_seq + 1;
102102

103+
if (test_bit(RDS_MSG_RETRANSMITTED, &rm->m_flags))
104+
rm->m_inc.i_hdr.h_flags |= RDS_FLAG_RETRANSMITTED;
105+
103106
rdsdebug("rm %p tcp nxt %u ack_seq %llu\n",
104107
rm, rds_tcp_snd_nxt(tc),
105108
(unsigned long long)rm->m_ack_seq);

0 commit comments

Comments
 (0)