net/rds: RDS-TCP protocol and extension improvements
Subsystems (5)
Allison Henderson
maintainerv2 cover net/rds: RDS-TCP protocol and extension improvements
From: Allison Henderson <[email protected]>
Hi all,
This is subset 3 of the larger RDS-TCP patch series I posted last Oct. The greater series aims to correct multiple rds-tcp issues that can cause dropped or out of sequence messages. I've broken it down into smaller sets to make reviews more manageable.
In this set, we introduce extension headers for byte accounting and fix several RDS/TCP protocol issues including message preservation during connection transitions and multipath lane handling.
The entire set can be viewed in the rfc here:
https://lore.kernel.org/netdev/[email protected]/
Questions, comments, flames appreciated!
Thanks!
Allison
Change Log:
v2:
[PATCH net-next v2 1/7] net/rds: new extension header: rdma bytes
- Fixed AI complaints for uninitalized structs
[PATCH net-next v2 2/7] net/rds: Encode cp_index in TCP source port
- Fixed line length checkpatch complaints
[PATCH net-next v2 3/7] net/rds: rds_tcp_conn_path_shutdown must not discard messages
- Added sk convenience variable to reduce dereferencing and line wrapping
- Fixed line length checkpatch complaints
[PATCH net-next v2 6/7] net/rds: Use the first lane until
- Added rds_mprds_cp0_catchup helper to de-nest rds_send_xmit
- Fixed line length checkpatch complaints
[PATCH net-next v2 7/7] net/rds: Trigger rds_send_ping() more than once
- Fixed ai complaints for comment clarification
Gerd Rausch (5):
net/rds: Encode cp_index in TCP source port net/rds: rds_tcp_conn_path_shutdown must not discard messages net/rds: Kick-start TCP receiver after accept net/rds: Use the first lane until RDS_EXTHDR_NPATHS arrives net/rds: Trigger rds_send_ping() more than once
Håkon Bugge (1):
net/rds: Clear reconnect pending bit
Shamir Rabinovitch (1):
net/rds: new extension header: rdma bytes
net/rds/connection.c | 7 ++- net/rds/ib_send.c | 22 ++++++- net/rds/message.c | 66 ++++++++++++++++----- net/rds/rds.h | 32 +++++++++-- net/rds/recv.c | 37 ++++++++++-- net/rds/send.c | 130 +++++++++++++++++++++++++++++------------- net/rds/stats.c | 1 + net/rds/tcp.c | 1 + net/rds/tcp.h | 7 ++- net/rds/tcp_connect.c | 79 +++++++++++++++++++++++-- net/rds/tcp_listen.c | 92 +++++++++++++++++++++++++++--- net/rds/tcp_recv.c | 4 ++ net/rds/tcp_send.c | 2 +- 13 files changed, 400 insertions(+), 80 deletions(-)
Signature · 1 line
2.43.0
Allison Henderson
maintainerPATCH v2 1/7 net/rds: new extension header: rdma bytes
From: Shamir Rabinovitch <[email protected]>
Introduce a new extension header type RDSV3_EXTHDR_RDMA_BYTES for an RDMA initiator to exchange rdma byte counts to its target. Currently, RDMA operations cannot precisely account how many bytes a peer just transferred via RDMA, which limits per-connection statistics and future policy (e.g., monitoring or rate/cgroup accounting of RDMA traffic).
In this patch we expand rds_message_add_extension to accept multiple extensions, and add new flag to RDS header: RDS_FLAG_EXTHDR_EXTENSION, along with a new extension to RDS header: rds_ext_header_rdma_bytes.
--- net/rds/ib_send.c | 22 ++++++++++++++-- net/rds/message.c | 65 +++++++++++++++++++++++++++++++++++++---------- net/rds/rds.h | 24 +++++++++++++---- net/rds/send.c | 6 ++--- 4 files changed, 93 insertions(+), 24 deletions(-)
net/rds/ib_send.c +20 -2
@@ -577,11 +577,29 @@ int rds_ib_xmit(struct rds_connection *conn, struct rds_message *rm,/* If it has a RDMA op, tell the peer we did it. This is * used by the peer to release use-once RDMA MRs. */ if (rm->rdma.op_active) { -struct rds_ext_header_rdma ext_hdr; +struct rds_ext_header_rdma ext_hdr = {}; +struct rds_ext_header_rdma_bytes + rdma_bytes_ext_hdr = {}; ext_hdr.h_rdma_rkey =cpu_to_be32 (rm->rdma.op_rkey);rds_message_add_extension (&rm->m_inc.i_hdr, -RDS_EXTHDR_RDMA , &ext_hdr,sizeof (ext_hdr)); +RDS_EXTHDR_RDMA , &ext_hdr); + +/* prepare the rdma bytes ext header */ + rdma_bytes_ext_hdr.h_rflags = rm->rdma.op_write ? +RDS_FLAG_RDMA_WR_BYTES :RDS_FLAG_RDMA_RD_BYTES ; + rdma_bytes_ext_hdr.h_rdma_bytes = +cpu_to_be32 (rm->rdma.op_bytes); + +if (rds_message_add_extension (&rm->m_inc.i_hdr, +RDS_EXTHDR_RDMA_BYTES , + &rdma_bytes_ext_hdr)) { +/* rdma bytes ext header was added successfully, +* notify the remote side via flag in header +*/ + rm->m_inc.i_hdr.h_flags |= +RDS_FLAG_EXTHDR_EXTENSION ; + } }if (rm->m_rdma_cookie) { rds_message_add_rdma_dest_extension(&rm->m_inc.i_hdr,
net/rds/message.c +52 -13
96 lines not on this page · raw message
net/rds/rds.h +19 -5
@@ -183,10 +183,11 @@ void rds_conn_net_set(struct rds_connection *conn, struct net *net)write_pnet (&conn->c_net, net); } -#define RDS_FLAG_CONG_BITMAP 0x01 -#define RDS_FLAG_ACK_REQUIRED 0x02 -#define RDS_FLAG_RETRANSMITTED 0x04 -#define RDS_MAX_ADV_CREDIT 255 +#define RDS_FLAG_CONG_BITMAP 0x01 +#define RDS_FLAG_ACK_REQUIRED 0x02 +#define RDS_FLAG_RETRANSMITTED 0x04 +#define RDS_FLAG_EXTHDR_EXTENSION 0x20 +#define RDS_MAX_ADV_CREDIT 255/* RDS_FLAG_PROBE_PORT is the reserved sport used for sending a ping * probe to exchange control information before establishing a connection.
@@ -258,6 +259,19 @@ struct rds_ext_header_rdma_dest {__be32 h_rdma_offset; }; +/* +* This extension header tells the peer about delivered RDMA byte count. +*/ +#define RDS_EXTHDR_RDMA_BYTES 4 + +struct rds_ext_header_rdma_bytes { +__be32 h_rdma_bytes;/* byte count */ +u8 h_rflags;/* direction of RDMA, write or read */ +}; + +#define RDS_FLAG_RDMA_WR_BYTES 0x01 +#define RDS_FLAG_RDMA_RD_BYTES 0x02 +/* Extension header announcing number of paths. * Implicit length = 2 bytes. */
@@ -871,7 +885,7 @@ struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned invoid rds_message_populate_header (struct rds_header *hdr,__be16 sport,__be16 dport,u64 seq);int rds_message_add_extension (struct rds_header *hdr, -unsigned int type,const void *data,unsigned int len); +unsigned int type,const void *data);int rds_message_next_extension (struct rds_header *hdr,unsigned int *pos,void *buf,unsigned int *buflen);int rds_message_add_rdma_dest_extension (struct rds_header *hdr,u32 r_key,u32 offset);
net/rds/send.c +2 -4
@@ -1459,12 +1459,10 @@ rds_send_probe(struct rds_conn_path *cp, __be16 sport,__be32 my_gen_num =cpu_to_be32 (cp->cp_conn->c_my_gen_num);rds_message_add_extension (&rm->m_inc.i_hdr, -RDS_EXTHDR_NPATHS , &npaths, -sizeof (npaths)); +RDS_EXTHDR_NPATHS , &npaths);rds_message_add_extension (&rm->m_inc.i_hdr,RDS_EXTHDR_GEN_NUM , - &my_gen_num, -sizeof (u32)); + &my_gen_num); }spin_unlock_irqrestore (&cp->cp_lock, flags);
Signature · 1 line
2.43.0
Allison Henderson
maintainerPATCH v2 2/7 net/rds: Encode cp_index in TCP source port
In reply to Allison HendersonFrom: Gerd Rausch <[email protected]>
Upon "sendmsg", RDS/TCP selects a backend connection based on a hash calculated from the source-port ("RDS_MPATH_HASH").
However, "rds_tcp_accept_one" accepts connections in the order they arrive, which is non-deterministic.
Therefore the mapping of the sender's "cp->cp_index" to that of the receiver changes if the backend connections are dropped and reconnected.
However, connection state that's preserved across reconnects (e.g. "cp_next_rx_seq") relies on that sender<->receiver mapping to never change.
So we make sure that client and server of the TCP connection have the exact same "cp->cp_index" across reconnects by encoding "cp->cp_index" in the lower three bits of the client's TCP source port.
A new extension "RDS_EXTHDR_SPORT_IDX" is introduced, that allows the server to tell the difference between clients that do the "cp->cp_index" encoding, and legacy clients that pick source ports randomly.
--- net/rds/message.c | 1 + net/rds/rds.h | 3 +++ net/rds/recv.c | 7 +++++++ net/rds/send.c | 4 ++++ net/rds/tcp.h | 1 + net/rds/tcp_connect.c | 23 +++++++++++++++++++++- net/rds/tcp_listen.c | 45 +++++++++++++++++++++++++++++++++++++------ 7 files changed, 77 insertions(+), 7 deletions(-)
net/rds/message.c +1 -0
@@ -47,6 +47,7 @@ static unsigned int rds_exthdr_size[__RDS_EXTHDR_MAX] = { [RDS_EXTHDR_RDMA_BYTES] = sizeof(struct rds_ext_header_rdma_bytes), [RDS_EXTHDR_NPATHS] = sizeof(__be16), [RDS_EXTHDR_GEN_NUM] = sizeof(__be32), +[RDS_EXTHDR_SPORT_IDX] = 1, };void rds_message_addref (struct rds_message *rm)
net/rds/rds.h +3 -0
@@ -147,6 +147,7 @@ struct rds_connection { c_ping_triggered:1 , c_pad_to_32:29;int c_npaths; +bool c_with_sport_idx;struct rds_connection *c_passive;struct rds_transport *c_trans;
@@ -277,8 +278,10 @@ struct rds_ext_header_rdma_bytes {*/ #define RDS_EXTHDR_NPATHS 5#define RDS_EXTHDR_GEN_NUM 6 +#define RDS_EXTHDR_SPORT_IDX 8#define __RDS_EXTHDR_MAX 16/* for now */ +#define RDS_RX_MAX_TRACES (RDS_MSG_RX_DGRAM_TRACE_MAX + 1)#define RDS_MSG_RX_HDR 0#define RDS_MSG_RX_START 1
net/rds/recv.c +7 -0
@@ -204,7 +204,9 @@ static void rds_recv_hs_exthdrs(struct rds_header *hdr,struct rds_ext_header_version version;__be16 rds_npaths;__be32 rds_gen_num; +u8 dummy; } buffer; +bool new_with_sport_idx = false;u32 new_peer_gen_num =0 ;while (1 ) {
@@ -221,11 +223,16 @@ static void rds_recv_hs_exthdrs(struct rds_header *hdr,case RDS_EXTHDR_GEN_NUM : new_peer_gen_num =be32_to_cpu (buffer.rds_gen_num);break ; +case RDS_EXTHDR_SPORT_IDX : + new_with_sport_idx = true; +break ;default :pr_warn_ratelimited ("ignoring unknown exthdr type " "0x%x\n" , type); } } + + conn->c_with_sport_idx = new_with_sport_idx;/* if RDS_EXTHDR_NPATHS was not found, default to a single-path */ conn->c_npaths =max_t (int, conn->c_npaths,1 ); conn->c_ping_triggered =0 ;
net/rds/send.c +4 -0
@@ -1457,12 +1457,16 @@ rds_send_probe(struct rds_conn_path *cp, __be16 sport, cp->cp_conn->c_trans->t_mp_capable) {__be16 npaths =cpu_to_be16 (RDS_MPATH_WORKERS );__be32 my_gen_num =cpu_to_be32 (cp->cp_conn->c_my_gen_num); +u8 dummy =0 ;rds_message_add_extension (&rm->m_inc.i_hdr,RDS_EXTHDR_NPATHS , &npaths);rds_message_add_extension (&rm->m_inc.i_hdr,RDS_EXTHDR_GEN_NUM , &my_gen_num); +rds_message_add_extension (&rm->m_inc.i_hdr, +RDS_EXTHDR_SPORT_IDX , + &dummy); }spin_unlock_irqrestore (&cp->cp_lock, flags);
net/rds/tcp.h +1 -0
@@ -34,6 +34,7 @@ struct rds_tcp_connection {*/ struct mutex t_conn_path_lock;struct socket *t_sock; +u32 t_client_port_group;struct rds_tcp_net *t_rtn;void *t_orig_write_space;void *t_orig_data_ready;
net/rds/tcp_connect.c +22 -1
@@ -93,6 +93,8 @@ int rds_tcp_conn_path_connect(struct rds_conn_path *cp)struct sockaddr_in6 sin6;struct sockaddr_in sin;struct sockaddr *addr; +int port_low, port_high, port; +int port_groups, groups_left;int addrlen;bool isv6;int ret;
@@ -145,7 +147,26 @@ int rds_tcp_conn_path_connect(struct rds_conn_path *cp) addrlen =sizeof (sin); } - ret =kernel_bind (sock, (struct sockaddr_unsized *)addr, addrlen); +/* encode cp->cp_index in lowest bits of source-port */ +inet_get_local_port_range (rds_conn_net (conn), &port_low, &port_high); + port_low =ALIGN (port_low,RDS_MPATH_WORKERS ); + port_groups = (port_high - port_low +1 ) /RDS_MPATH_WORKERS ; + ret = -EADDRINUSE ; + groups_left = port_groups; +while (groups_left-- >0 && ret) { +if (++tc->t_client_port_group >= port_groups) + tc->t_client_port_group =0 ; + port = port_low + + tc->t_client_port_group *RDS_MPATH_WORKERS + + cp->cp_index; + +if (isv6) + sin6.sin6_port =htons (port); +else + sin.sin_port =htons (port); + ret =kernel_bind (sock, (struct sockaddr_unsized *)addr, + addrlen); + }if (ret) {rdsdebug ("bind failed with %d at address %pI6c\n" , ret, &conn->c_laddr);
net/rds/tcp_listen.c +39 -6
65 lines not on this page · raw message
Signature · 1 line
2.43.0
Allison Henderson
maintainerPATCH v2 3/7 net/rds: rds_tcp_conn_path_shutdown must not discard messages
In reply to Allison HendersonFrom: Gerd Rausch <[email protected]>
RDS/TCP differs from RDS/RDMA in that message acknowledgment is done based on TCP sequence numbers:
As soon as the last byte of a message has been acknowledged by the TCP stack of a peer, rds_tcp_write_space() goes on to discard prior messages from the send queue.
Which is fine, for as long as the receiver never throws any messages away.
The dequeuing of messages in RDS/TCP is done either from the "sk_data_ready" callback pointing to rds_tcp_data_ready() (the most common case), or from the receive worker pointing to rds_tcp_recv_path() which is called for as long as the connection is "RDS_CONN_UP".
However, as soon as rds_conn_path_drop() is called for whatever reason, including "DR_USER_RESET", "cp_state" transitions to "RDS_CONN_ERROR", and rds_tcp_restore_callbacks() ends up restoring the callbacks and thereby disabling message receipt.
So messages already acknowledged to the sender were dropped.
Furthermore, the "->shutdown" callback was always called with an invalid parameter ("RCV_SHUTDOWN | SEND_SHUTDOWN == 3"), instead of the correct pre-increment value ("SHUT_RDWR == 2"). inet_shutdown() returns "-EINVAL" in such cases, rendering this call a NOOP.
So we change rds_tcp_conn_path_shutdown() to do the proper "->shutdown(SHUT_WR)" call in order to signal EOF to the peer and make it transition to "TCP_CLOSE_WAIT" (RFC 793).
This should make the peer also enter rds_tcp_conn_path_shutdown() and do the same.
This allows us to dequeue all messages already received and acknowledged to the peer.
We do so, until we know that the receive queue no longer has data (skb_queue_empty()) and that we couldn't have any data in flight anymore, because the socket transitioned to any of the states "CLOSING", "TIME_WAIT", "CLOSE_WAIT", "LAST_ACK", or "CLOSE" (RFC 793).
However, if we do just that, we suddenly see duplicate RDS messages being delivered to the application.
So what gives?
Turns out that with MPRDS and its multitude of backend connections, retransmitted messages ("RDS_FLAG_RETRANSMITTED") can outrace the dequeuing of their original counterparts.
And the duplicate check implemented in rds_recv_local() only discards duplicates if flag "RDS_FLAG_RETRANSMITTED" is set.
Rather curious, because a duplicate is a duplicate; it shouldn't matter which copy is looked at and delivered first.
To avoid this entire situation, we simply make the sender discard messages from the send-queue right from within rds_tcp_conn_path_shutdown(). Just like rds_tcp_write_space() would have done, were it called in time or still called.
This makes sure that we no longer have messages that we know the receiver already dequeued sitting in our send-queue, and therefore avoid the entire "RDS_FLAG_RETRANSMITTED" fiasco.
Now we got rid of the duplicate RDS message delivery, but we still run into cases where RDS messages are dropped.
This time it is due to the delayed setting of the socket-callbacks in rds_tcp_accept_one() via either rds_tcp_reset_callbacks() or rds_tcp_set_callbacks().
By the time rds_tcp_accept_one() gets there, the socket may already have transitioned into state "TCP_CLOSE_WAIT", but rds_tcp_state_change() was never called.
Subsequently, "->shutdown(SHUT_WR)" did not happen either. So the peer ends up getting stuck in state "TCP_FIN_WAIT2".
We fix that by checking for states "TCP_CLOSE_WAIT", "TCP_LAST_ACK", or "TCP_CLOSE" and drop the freshly accepted socket in that case.
This problem is observable by running "rds-stress --reset" frequently on either of the two sides of a RDS connection, or both while other "rds-stress" processes are exchanging data. Those "rds-stress" processes reported out-of-sequence errors, with the expected sequence number being smaller than the one actually received (due to the dropped messages).
--- net/rds/tcp.c | 1 + net/rds/tcp.h | 4 ++++ net/rds/tcp_connect.c | 56 +++++++++++++++++++++++++++++++++++++++---- net/rds/tcp_listen.c | 14 +++++++++++ net/rds/tcp_recv.c | 4 ++++ net/rds/tcp_send.c | 2 +- 6 files changed, 76 insertions(+), 5 deletions(-)
net/rds/tcp.c +1 -0
@@ -384,6 +384,7 @@ static int rds_tcp_conn_alloc(struct rds_connection *conn, gfp_t gfp) tc->t_tinc =NULL ; tc->t_tinc_hdr_rem =sizeof (struct rds_header ); tc->t_tinc_data_rem =0 ; +init_waitqueue_head (&tc->t_recv_done_waitq); conn->c_path[i].cp_transport_data = tc; tc->t_cpath = &conn->c_path[i];
net/rds/tcp.h +4 -0
@@ -55,6 +55,9 @@ struct rds_tcp_connection {u32 t_last_sent_nxt;u32 t_last_expected_una;u32 t_last_seen_una; + +/* for rds_tcp_conn_path_shutdown */ +wait_queue_head_t t_recv_done_waitq; };struct rds_tcp_statistics {
@@ -105,6 +108,7 @@ void rds_tcp_xmit_path_prepare(struct rds_conn_path *cp);void rds_tcp_xmit_path_complete (struct rds_conn_path *cp);int rds_tcp_xmit (struct rds_connection *conn,struct rds_message *rm,unsigned int hdr_off,unsigned int sg,unsigned int off); +int rds_tcp_is_acked (struct rds_message *rm,uint64_t ack);void rds_tcp_write_space (struct sock *sk);/* tcp_stats.c */
net/rds/tcp_connect.c +52 -4
78 lines not on this page · raw message
net/rds/tcp_listen.c +14 -0
@@ -278,6 +278,20 @@ int rds_tcp_accept_one(struct rds_tcp_net *rtn)rds_tcp_set_callbacks (new_sock, cp);rds_connect_path_complete (cp,RDS_CONN_CONNECTING ); } + +/* Since "rds_tcp_set_callbacks" happens this late +* the connection may already have been closed without +* "rds_tcp_state_change" doing its due diligence. +* +* If that's the case, we simply drop the path, +* knowing that "rds_tcp_conn_path_shutdown" will +* dequeue pending messages. +*/ +if (new_sock->sk->sk_state ==TCP_CLOSE_WAIT || + new_sock->sk->sk_state ==TCP_LAST_ACK || + new_sock->sk->sk_state ==TCP_CLOSE ) +rds_conn_path_drop (cp,0 ); + new_sock =NULL ; ret =0 ;if (conn->c_npaths ==0 )
net/rds/tcp_recv.c +4 -0
@@ -278,6 +278,10 @@ static int rds_tcp_read_sock(struct rds_conn_path *cp, gfp_t gfp)rdsdebug ("tcp_read_sock for tc %p gfp 0x%x returned %d\n" , tc, gfp, desc.error); +if (skb_queue_empty_lockless (&sock->sk->sk_receive_queue) && +wq_has_sleeper (&tc->t_recv_done_waitq)) +wake_up (&tc->t_recv_done_waitq); +return desc.error; }
net/rds/tcp_send.c +1 -1
@@ -169,7 +169,7 @@ int rds_tcp_xmit(struct rds_connection *conn, struct rds_message *rm,* unacked byte of the TCP sequence space. We have to do very careful * wrapping 32bit comparisons here. */ -static int rds_tcp_is_acked (struct rds_message *rm,uint64_t ack) +int rds_tcp_is_acked (struct rds_message *rm,uint64_t ack) {if (!test_bit (RDS_MSG_HAS_ACK_SEQ , &rm->m_flags))return 0 ;
Signature · 1 line
2.43.0
Allison Henderson
maintainerPATCH v2 4/7 net/rds: Kick-start TCP receiver after accept
In reply to Allison HendersonFrom: Gerd Rausch <[email protected]>
In cases where the server (the node with the higher IP-address) in an RDS/TCP connection is overwhelmed it is possible that the socket that was just accepted is chock-full of messages, up to the limit of what the socket receive buffer permits.
Subsequently, "rds_tcp_data_ready" won't be called anymore, because there is no more space to receive additional messages.
Nor was it called prior to the point of calling "rds_tcp_set_callbacks", because the "sk_data_ready" pointer didn't even point to "rds_tcp_data_ready" yet.
We fix this by simply kick-starting the receive-worker for all cases where the socket state is neither "TCP_CLOSE_WAIT" nor "TCP_CLOSE".
--- net/rds/tcp_listen.c | 2 ++ 1 file changed, 2 insertions(+)
net/rds/tcp_listen.c +2 -0
@@ -291,6 +291,8 @@ int rds_tcp_accept_one(struct rds_tcp_net *rtn) new_sock->sk->sk_state == TCP_LAST_ACK || new_sock->sk->sk_state == TCP_CLOSE)rds_conn_path_drop (cp,0 ); + else + queue_delayed_work(cp->cp_wq, &cp->cp_recv_w, 0); new_sock =NULL ; ret =0 ;
Signature · 1 line
2.43.0
Allison Henderson
maintainerPATCH v2 5/7 net/rds: Clear reconnect pending bit
In reply to Allison HendersonFrom: Håkon Bugge <[email protected]>
When canceling the reconnect worker, care must be taken to reset the reconnect-pending bit. If the reconnect worker has not yet been scheduled before it is canceled, the reconnect-pending bit will stay on forever.
--- net/rds/connection.c | 2 ++ 1 file changed, 2 insertions(+)
net/rds/connection.c +2 -0
@@ -442,6 +442,8 @@ void rds_conn_shutdown(struct rds_conn_path *cp)* to the conn hash, so we never trigger a reconnect on this * conn - the reconnect is always triggered by the active peer. */ cancel_delayed_work_sync (&cp->cp_conn_w); + +clear_bit (RDS_RECONNECT_PENDING , &cp->cp_flags);rcu_read_lock ();if (!hlist_unhashed (&conn->c_hash_node)) {rcu_read_unlock ();
Signature · 1 line
2.43.0
Allison Henderson
maintainerPATCH v2 6/7 net/rds: Use the first lane until RDS_EXTHDR_NPATHS arrives
In reply to Allison HendersonFrom: Gerd Rausch <[email protected]>
Instead of just blocking the sender until "c_npaths" is known (it gets updated upon the receipt of a MPRDS PONG message), simply use the first lane (cp_index#0).
But just using the first lane isn't enough.
As soon as we enqueue messages on a different lane, we'd run the risk of out-of-order delivery of RDS messages.
Earlier messages enqueued on "cp_index == 0" could be delivered later than more recent messages enqueued on "cp_index > 0", mostly because of possible head of line blocking issues causing the first lane to be slower.
To avoid that, we simply take a snapshot of "cp_next_tx_seq" at the time we're about to fan-out to more lanes.
Then we delay the transmission of messages enqueued on other lanes with "cp_index > 0" until cp_index#0 caught up with the delivery of new messages (from "cp_send_queue") as well as in-flight messages (from "cp_retrans") that haven't been acknowledged yet by the receiver.
We also add a new counter "mprds_catchup_tx0_retries" to keep track of how many times "rds_send_xmit" had to suspend activities, because it was waiting for the first lane to catch up.
--- net/rds/rds.h | 3 ++ net/rds/recv.c | 23 +++++++++-- net/rds/send.c | 102 +++++++++++++++++++++++++++++++----------------- net/rds/stats.c | 1 + 4 files changed, 90 insertions(+), 39 deletions(-)
net/rds/rds.h +3 -0
@@ -170,6 +170,8 @@ struct rds_connection {u32 c_my_gen_num;u32 c_peer_gen_num; + +u64 c_cp0_mprds_catchup_tx_seq; }; static inline
@@ -748,6 +750,7 @@ struct rds_statistics {uint64_t s_recv_bytes_added_to_socket;uint64_t s_recv_bytes_removed_from_socket;uint64_t s_send_stuck_rm; +uint64_t s_mprds_catchup_tx0_retries; };/* af_rds.c */
net/rds/recv.c +20 -3
@@ -208,6 +208,9 @@ static void rds_recv_hs_exthdrs(struct rds_header *hdr, } buffer;bool new_with_sport_idx = false;u32 new_peer_gen_num =0 ; +int new_npaths; + + new_npaths = conn->c_npaths;while (1 ) { len =sizeof (buffer);
@@ -217,8 +220,8 @@ static void rds_recv_hs_exthdrs(struct rds_header *hdr,/* Process extension header here */ switch (type) {case RDS_EXTHDR_NPATHS : - conn->c_npaths =min_t (int,RDS_MPATH_WORKERS , -be16_to_cpu (buffer.rds_npaths)); + new_npaths =min_t (int,RDS_MPATH_WORKERS , +be16_to_cpu (buffer.rds_npaths));break ;case RDS_EXTHDR_GEN_NUM : new_peer_gen_num =be32_to_cpu (buffer.rds_gen_num);
@@ -233,8 +236,22 @@ static void rds_recv_hs_exthdrs(struct rds_header *hdr, } conn->c_with_sport_idx = new_with_sport_idx; + +if (new_npaths >1 && new_npaths != conn->c_npaths) { +/* We're about to fan-out. +* Make sure that messages from cp_index#0 +* are sent prior to handling other lanes. +*/ +struct rds_conn_path *cp0 = conn->c_path; +unsigned long flags; + +spin_lock_irqsave (&cp0->cp_lock, flags); + conn->c_cp0_mprds_catchup_tx_seq = cp0->cp_next_tx_seq; +spin_unlock_irqrestore (&cp0->cp_lock, flags); + }/* if RDS_EXTHDR_NPATHS was not found, default to a single-path */ - conn->c_npaths =max_t (int, conn->c_npaths,1 ); + conn->c_npaths =max_t (int, new_npaths,1 ); + conn->c_ping_triggered =0 ;rds_conn_peer_gen_update (conn, new_peer_gen_num);
net/rds/send.c +66 -36
127 lines not on this page · raw message
net/rds/stats.c +1 -0
@@ -79,6 +79,7 @@ static const char *const rds_stat_names[] = {"recv_bytes_added_to_sock" ,"recv_bytes_freed_fromsock" ,"send_stuck_rm" , + "mprds_catchup_tx0_retries", }; void rds_stats_info_copy(struct rds_info_iterator *iter,
Signature · 1 line
2.43.0
Allison Henderson
maintainerPATCH v2 7/7 net/rds: Trigger rds_send_ping() more than once
In reply to Allison HendersonFrom: Gerd Rausch <[email protected]>
Even though a peer may have already received a non-zero value for "RDS_EXTHDR_NPATHS" from a node in the past, the current peer may not.
Therefore it is important to initiate another rds_send_ping() after a re-connect to any peer:
It is unknown at that time if we're still talking to the same instance of RDS kernel modules on the other side.
Otherwise, the peer may just operate on a single lane ("c_npaths == 0"), not knowing that more lanes are available.
However, if "c_with_sport_idx" is supported,
we also need to check that the connection we accepted on lane#0 meets the proper source port modulo requirement, as we fan out:
Since the exchange of "RDS_EXTHDR_NPATHS" and "RDS_EXTHDR_SPORT_IDX" is asynchronous, initially we have no choice but to accept an incoming connection (via "accept") in the first slot ("cp_index == 0") for backwards compatibility.
But that very connection may have come from a different lane with "cp_index != 0", since the peer thought that we already understood and handled "c_with_sport_idx" properly, as indicated by a previous exchange before a module was reloaded.
In short:
If a module gets reloaded, we recover from that, but do *not* allow a downgrade to support fewer lanes.
Downgrades would require us to merge messages from separate lanes, which is rather tricky with the current RDS design. Each lane has its own sequence number space and all messages would need to be re-sequenced as we merge, all while handling "RDS_FLAG_RETRANSMITTED" and "cp_retrans" properly.
--- net/rds/connection.c | 5 +++- net/rds/rds.h | 2 +- net/rds/recv.c | 7 +++++- net/rds/send.c | 18 +++++++++++++++ net/rds/tcp.h | 2 +- net/rds/tcp_listen.c | 55 +++++++++++++++++++++++++++++++++----------- 6 files changed, 72 insertions(+), 17 deletions(-)
net/rds/connection.c +4 -1
@@ -447,13 +447,16 @@ void rds_conn_shutdown(struct rds_conn_path *cp)rcu_read_lock ();if (!hlist_unhashed (&conn->c_hash_node)) {rcu_read_unlock (); +if (conn->c_trans->t_mp_capable && + cp->cp_index ==0 ) +rds_send_ping (conn,0 );rds_queue_reconnect (cp); }else {rcu_read_unlock (); }if (conn->c_trans->conn_slots_available) - conn->c_trans->conn_slots_available (conn); + conn->c_trans->conn_slots_available (conn, false); }/* destroy a single rds_conn_path. rds_conn_destroy() iterates over
net/rds/rds.h +1 -1
@@ -548,7 +548,7 @@ struct rds_transport {* messages received on the new socket are not discarded when no * connection path was available at the time. */ -void (*conn_slots_available)(struct rds_connection *conn); +void (*conn_slots_available)(struct rds_connection *conn,bool fan_out);int (*conn_path_connect)(struct rds_conn_path *cp);/*
net/rds/recv.c +6 -1
@@ -209,6 +209,7 @@ static void rds_recv_hs_exthdrs(struct rds_header *hdr,bool new_with_sport_idx = false;u32 new_peer_gen_num =0 ;int new_npaths; +bool fan_out; new_npaths = conn->c_npaths;
@@ -248,7 +249,11 @@ static void rds_recv_hs_exthdrs(struct rds_header *hdr,spin_lock_irqsave (&cp0->cp_lock, flags); conn->c_cp0_mprds_catchup_tx_seq = cp0->cp_next_tx_seq;spin_unlock_irqrestore (&cp0->cp_lock, flags); + fan_out = true; + }else { + fan_out = false; } +/* if RDS_EXTHDR_NPATHS was not found, default to a single-path */ conn->c_npaths =max_t (int, new_npaths,1 );
@@ -257,7 +262,7 @@ static void rds_recv_hs_exthdrs(struct rds_header *hdr,if (conn->c_npaths >1 && conn->c_trans->conn_slots_available) - conn->c_trans->conn_slots_available (conn); + conn->c_trans->conn_slots_available (conn, fan_out); }/* rds_start_mprds() will synchronously start multiple paths when appropriate.
net/rds/send.c +18 -0
@@ -1339,6 +1339,24 @@ int rds_sendmsg(struct socket *sock, struct msghdr *msg, size_t payload_len) cpath = &conn->c_path[0 ]; } +/* Check to see if we have talked to this peer before. +* If not, this means conn->c_npaths will be zero, +* and we should initiate a connection request to the +* peer right away. +*/ +if (conn->c_trans->t_mp_capable && + !rds_conn_path_up (&conn->c_path[0 ])) { +/* Ensures that only one request is queued. And +* rds_send_ping() ensures that only one ping is +* outstanding. +*/ +if (!test_and_set_bit (RDS_RECONNECT_PENDING , + &conn->c_path[0 ].cp_flags)) +queue_delayed_work (conn->c_path[0 ].cp_wq, + &conn->c_path[0 ].cp_conn_w,0 ); +rds_send_ping (conn,0 ); + } + rm->m_conn_path = cpath;/* Parse any control messages the user may have included. */
net/rds/tcp.h +1 -1
@@ -90,7 +90,7 @@ void rds_tcp_state_change(struct sock *sk);struct socket *rds_tcp_listen_init (struct net *net,bool isv6);void rds_tcp_listen_stop (struct socket *sock,struct work_struct *acceptor);void rds_tcp_listen_data_ready (struct sock *sk); -void rds_tcp_conn_slots_available (struct rds_connection *conn); +void rds_tcp_conn_slots_available (struct rds_connection *conn,bool fan_out);int rds_tcp_accept_one (struct rds_tcp_net *rtn);void rds_tcp_keepalive (struct socket *sock);void *rds_tcp_listen_sock_def_readable (struct net *net);
net/rds/tcp_listen.c +42 -13
89 lines not on this page · raw message
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerRe: [net-next,v2,1/7] net/rds: new extension header: rdma bytes
In reply to Allison HendersonThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
net/rds: new extension header: rdma bytes
This patch introduces a new RDS extension header RDS_EXTHDR_RDMA_BYTES for RDMA byte accounting and refactors rds_message_add_extension() to support multiple extensions per message instead of just one.
Quoted 17 lines
net/rds/ib_send.c +4
-2@@ -577,11 +577,29 @@ int rds_ib_xmit(struct rds_connection *conn, struct rds_message *rm,/* If it has a RDMA op, tell the peer we did it. This is * used by the peer to release use-once RDMA MRs. */ if (rm->rdma.op_active) { -struct rds_ext_header_rdma ext_hdr; +struct rds_ext_header_rdma ext_hdr = {}; +struct rds_ext_header_rdma_bytes + rdma_bytes_ext_hdr = {}; ext_hdr.h_rdma_rkey =cpu_to_be32 (rm->rdma.op_rkey);rds_message_add_extension (&rm->m_inc.i_hdr, -RDS_EXTHDR_RDMA , &ext_hdr,sizeof (ext_hdr)); +RDS_EXTHDR_RDMA , &ext_hdr);
net/rds/ib_send.c int rds_ib_xmit(struct rds_connection *conn, struct rds_message *rm, · line 596
Quoted 10 lines
net/rds/ib_send.c +10
-0+ +/* prepare the rdma bytes ext header */ + rdma_bytes_ext_hdr.h_rflags = rm->rdma.op_write ? +RDS_FLAG_RDMA_WR_BYTES :RDS_FLAG_RDMA_RD_BYTES ; + rdma_bytes_ext_hdr.h_rdma_bytes = +cpu_to_be32 (rm->rdma.op_bytes); + +if (rds_message_add_extension (&rm->m_inc.i_hdr, +RDS_EXTHDR_RDMA_BYTES , + &rdma_bytes_ext_hdr)) {
The new rds_ext_header_rdma_bytes struct contains __be32 + u8 = 5 bytes of data, but without __packed it will be padded to 8 bytes. This means sizeof(struct rds_ext_header_rdma_bytes) returns 8, not 5.
With the h_exthdr space limited to 16 bytes, adding RDS_EXTHDR_RDMA (1+4=5 bytes) plus RDS_EXTHDR_RDMA_BYTES (1+8=9 bytes) consumes 14 bytes, leaving only 2 bytes available.
net/rds/ib_send.c
Quoted 12 lines
net/rds/ib_send.c +6
-0+/* rdma bytes ext header was added successfully, +* notify the remote side via flag in header +*/ + rm->m_inc.i_hdr.h_flags |= +RDS_FLAG_EXTHDR_EXTENSION ; + } }if (rm->m_rdma_cookie) { rds_message_add_rdma_dest_extension(&rm->m_inc.i_hdr,net/rds/ib_send.c +0
-0rds_rdma_cookie_key (rm->m_rdma_cookie), rds_rdma_cookie_offset(rm->m_rdma_cookie)); }
When rm->rdma.op_active and rm->m_rdma_cookie are both set, could this cause rds_message_add_rdma_dest_extension() to silently fail? The RDS_EXTHDR_RDMA_DEST extension requires 9 bytes (1+8), but only 2 bytes remain after the RDMA and RDMA_BYTES extensions are added.
The return value of rds_message_add_rdma_dest_extension() is not checked here. If both conditions are true, the RDMA destination cookie would be silently dropped without any indication to the caller.
Should the struct be marked __packed to use only 5 bytes on the wire, or should there be handling for the case when extension space runs out?
Quoted 4 lines
net/rds/rds.h +0
-0
[ ... ]
net/rds/rds.h struct rds_ext_header_rdma_dest { · line 270
Quoted 13 lines
net/rds/rds.h +9
-0@@ -258,6 +259,19 @@ struct rds_ext_header_rdma_dest {__be32 h_rdma_offset; }; +/* +* This extension header tells the peer about delivered RDMA byte count. +*/ +#define RDS_EXTHDR_RDMA_BYTES 4 + +struct rds_ext_header_rdma_bytes { +__be32 h_rdma_bytes;/* byte count */ +u8 h_rflags;/* direction of RDMA, write or read */ +};
Without __packed, this struct will be 8 bytes due to padding after h_rflags. The other extension header structs (rds_ext_header_rdma, rds_ext_header_rdma_dest) use only __be32 fields so they have no padding concerns.
Jakub Kicinski
maintainerRe: [net-next,v2,7/7] net/rds: Trigger rds_send_ping() more than once
In reply to Allison HendersonThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
net/rds: Trigger rds_send_ping() more than once
This commit ensures rds_send_ping() is triggered after reconnect to properly communicate multipath capabilities, especially after an RDS module reload. It also validates source port modulo during fan-out.
Quoted 5 lines
net/rds/send.c +0
-0
net/rds/send.c int rds_sendmsg(struct socket *sock, struct msghdr *msg, size_t payload_len) · line 1348
Quoted 10 lines
net/rds/send.c +7
-0@@ -1339,6 +1339,24 @@ int rds_sendmsg(struct socket *sock, struct msghdr *msg, size_t payload_len) cpath = &conn->c_path[0 ]; } +/* Check to see if we have talked to this peer before. +* If not, this means conn->c_npaths will be zero, +* and we should initiate a connection request to the +* peer right away. +*/ +if (conn->c_trans->t_mp_capable && + !rds_conn_path_up (&conn->c_path[0 ])) {
This isn't a bug, but the comment says "c_npaths will be zero" while the code checks "!rds_conn_path_up()". These conditions are different:c_npaths == 0 means no paths negotiated yet, while !rds_conn_path_up() is true for any state other than RDS_CONN_UP (DOWN, CONNECTING, DISCONNECTING, ERROR, RESETTING).
The commit message mentions "after a re-connect to any peer" which aligns with the code, but the comment specifically mentions c_npaths. Should the comment be updated to reflect the actual logic?
This was flagged in v1 review:
https://lore.kernel.org/netdev/[email protected]/
[ ... ]