net/smc: fixes 2019-02-04
Subsystems (5)
cover net/smc: fixes 2019-02-04
Dave,
here are more fixes in the smc code for the net tree:
Patch 1 fixes an IB-related problem with SMCR. Patch 2 fixes a cursor problem for one-way traffic. Patch 3 fixes a problem with RMB-reusage. Patch 4 fixes a closing issue.
Thanks, Ursula
Ursula Braun (4):
net/smc: preallocated memory for rdma work requests net/smc: fix sender_free computation net/smc: delete rkey first before switching to unused net/smc: correct state change for peer closing
net/smc/smc_cdc.c | 16 ++++++---------- net/smc/smc_cdc.h | 34 ++++++++++++++++++++++++++++++++-- net/smc/smc_close.c | 9 +-------- net/smc/smc_core.c | 2 +- net/smc/smc_core.h | 20 ++++++++++++++++++++ net/smc/smc_llc.c | 3 ++- net/smc/smc_tx.c | 47 ++++++++++++++++++++++++----------------------- net/smc/smc_wr.c | 38 +++++++++++++++++++++++++++++++++++++- net/smc/smc_wr.h | 1 + 9 files changed, 124 insertions(+), 46 deletions(-)
Signature · 1 line
2.16.4
PATCH 1/4 net/smc: preallocated memory for rdma work requests
The work requests for rdma writes are built in local variables within function smc_tx_rdma_write(). This violates the rule that the work request storage has to stay till the work request is confirmed by a completion queue response.
This patch introduces preallocated memory for these work requests. The storage is allocated, once a link (and thus a queue pair) is established.
--- net/smc/smc_cdc.c | 11 +++-------- net/smc/smc_cdc.h | 8 +++++++- net/smc/smc_core.h | 20 ++++++++++++++++++++ net/smc/smc_llc.c | 3 ++- net/smc/smc_tx.c | 44 ++++++++++++++++++++++---------------------- net/smc/smc_wr.c | 38 +++++++++++++++++++++++++++++++++++++- net/smc/smc_wr.h | 1 + 7 files changed, 92 insertions(+), 33 deletions(-)
net/smc/smc_cdc.c +3 -8
@@ -21,13 +21,6 @@/********************************** send *************************************/ -struct smc_cdc_tx_pend { -struct smc_connection *conn;/* socket connection */ -union smc_host_cursor cursor;/* tx sndbuf cursor sent */ -union smc_host_cursor p_cursor;/* rx RMBE cursor produced */ -u16 ctrl_seq;/* conn. tx sequence # */ -}; -/* handler for send/transmission completion of a CDC msg */ static void smc_cdc_tx_handler(struct smc_wr_tx_pend_priv *pnd_snd, struct smc_link *link,
@@ -61,12 +54,14 @@ static void smc_cdc_tx_handler(struct smc_wr_tx_pend_priv *pnd_snd,int smc_cdc_get_free_slot (struct smc_connection *conn,struct smc_wr_buf **wr_buf, +struct smc_rdma_wr **wr_rdma_buf,struct smc_cdc_tx_pend **pend) {struct smc_link *link = &conn->lgr->lnk[SMC_SINGLE_LINK ];int rc; rc =smc_wr_tx_get_free_slot (link, smc_cdc_tx_handler, wr_buf, + wr_rdma_buf, (struct smc_wr_tx_pend_priv **)pend);if (!conn->alert_token_local)/* abnormal termination */
@@ -121,7 +116,7 @@ static int smcr_cdc_get_slot_and_msg_send(struct smc_connection *conn)struct smc_wr_buf *wr_buf;int rc; - rc =smc_cdc_get_free_slot (conn, &wr_buf, &pend); + rc =smc_cdc_get_free_slot (conn, &wr_buf,NULL , &pend);if (rc)return rc;
net/smc/smc_cdc.h +7 -1
@@ -270,10 +270,16 @@ static inline void smc_cdc_msg_to_host(struct smc_host_cdc_msg *local,smcr_cdc_msg_to_host (local, peer, conn); } -struct smc_cdc_tx_pend ; +struct smc_cdc_tx_pend { +struct smc_connection *conn;/* socket connection */ +union smc_host_cursor cursor;/* tx sndbuf cursor sent */ +union smc_host_cursor p_cursor;/* rx RMBE cursor produced */ +u16 ctrl_seq;/* conn. tx sequence # */ +};int smc_cdc_get_free_slot (struct smc_connection *conn,struct smc_wr_buf **wr_buf, +struct smc_rdma_wr **wr_rdma_buf,struct smc_cdc_tx_pend **pend);void smc_cdc_tx_dismiss_slots (struct smc_connection *conn); int smc_cdc_msg_send(struct smc_connection *conn, struct smc_wr_buf *wr_buf,
net/smc/smc_core.h +20 -0
@@ -52,6 +52,24 @@ enum smc_wr_reg_state {FAILED /* ib_wr_reg_mr response: failure */ }; +struct smc_rdma_sge {/* sges for RDMA writes */ +struct ib_sge wr_tx_rdma_sge[SMC_IB_MAX_SEND_SGE ]; +}; + +#define SMC_MAX_RDMA_WRITES 2/* max. # of RDMA writes per +* message send +*/ + +struct smc_rdma_sges {/* sges per message send */ +struct smc_rdma_sge tx_rdma_sge[SMC_MAX_RDMA_WRITES ]; +}; + +struct smc_rdma_wr {/* work requests per message +* send +*/ +struct ib_rdma_wr wr_tx_rdma[SMC_MAX_RDMA_WRITES ]; +}; +struct smc_link {struct smc_ib_device *smcibdev;/* ib-device */ u8 ibport;/* port - values 1 | 2 */
@@ -64,6 +82,8 @@ struct smc_link {struct smc_wr_buf *wr_tx_bufs;/* WR send payload buffers */ struct ib_send_wr *wr_tx_ibs;/* WR send meta data */ struct ib_sge *wr_tx_sges;/* WR send gather meta data */ +struct smc_rdma_sges *wr_tx_rdma_sges;/*RDMA WRITE gather meta data*/ +struct smc_rdma_wr *wr_tx_rdmas;/* WR RDMA WRITE */ struct smc_wr_tx_pend *wr_tx_pends;/* WR send waiting for CQE */ /* above four vectors have wr_tx_cnt elements and use the same index */ dma_addr_t wr_tx_dma_addr;/* DMA address of wr_tx_bufs */
net/smc/smc_llc.c +2 -1
@@ -166,7 +166,8 @@ static int smc_llc_add_pending_send(struct smc_link *link, {int rc; - rc =smc_wr_tx_get_free_slot (link, smc_llc_tx_handler, wr_buf, pend); + rc =smc_wr_tx_get_free_slot (link, smc_llc_tx_handler, wr_buf,NULL , + pend);if (rc <0 )return rc; BUILD_BUG_ON_MSG(
net/smc/smc_tx.c +22 -22
119 lines not on this page · raw message
net/smc/smc_wr.c +37 -1
@@ -160,6 +160,7 @@ static inline int smc_wr_tx_get_free_slot_index(struct smc_link *link, u32 *idx)* @link: Pointer to smc_link used to later send the message. * @handler: Send completion handler function pointer. * @wr_buf: Out value returns pointer to message buffer. +* @wr_rdma_buf: Out value returns pointer to rdma work request. * @wr_pend_priv: Out value returns pointer serving as handler context. * * Return: 0 on success, or -errno on error.
@@ -167,6 +168,7 @@ static inline int smc_wr_tx_get_free_slot_index(struct smc_link *link, u32 *idx)int smc_wr_tx_get_free_slot (struct smc_link *link,smc_wr_tx_handler handler,struct smc_wr_buf **wr_buf, +struct smc_rdma_wr **wr_rdma_buf,struct smc_wr_tx_pend_priv **wr_pend_priv) {struct smc_wr_tx_pend *wr_pend;
@@ -204,6 +206,8 @@ int smc_wr_tx_get_free_slot(struct smc_link *link, wr_ib = &link->wr_tx_ibs[idx]; wr_ib->wr_id = wr_id; *wr_buf = &link->wr_tx_bufs[idx]; +if (wr_rdma_buf) + *wr_rdma_buf = &link->wr_tx_rdmas[idx]; *wr_pend_priv = &wr_pend->priv;return 0 ; }
@@ -465,12 +469,26 @@ static void smc_wr_init_sge(struct smc_link *lnk) lnk->wr_tx_dma_addr + i *SMC_WR_BUF_SIZE ; lnk->wr_tx_sges[i].length =SMC_WR_TX_SIZE ; lnk->wr_tx_sges[i].lkey = lnk->roce_pd->local_dma_lkey; + lnk->wr_tx_rdma_sges[i].tx_rdma_sge[0 ].wr_tx_rdma_sge[0 ].lkey = + lnk->roce_pd->local_dma_lkey; + lnk->wr_tx_rdma_sges[i].tx_rdma_sge[0 ].wr_tx_rdma_sge[1 ].lkey = + lnk->roce_pd->local_dma_lkey; + lnk->wr_tx_rdma_sges[i].tx_rdma_sge[1 ].wr_tx_rdma_sge[0 ].lkey = + lnk->roce_pd->local_dma_lkey; + lnk->wr_tx_rdma_sges[i].tx_rdma_sge[1 ].wr_tx_rdma_sge[1 ].lkey = + lnk->roce_pd->local_dma_lkey; lnk->wr_tx_ibs[i].next =NULL ; lnk->wr_tx_ibs[i].sg_list = &lnk->wr_tx_sges[i]; lnk->wr_tx_ibs[i].num_sge =1 ; lnk->wr_tx_ibs[i].opcode =IB_WR_SEND ; lnk->wr_tx_ibs[i].send_flags =IB_SEND_SIGNALED |IB_SEND_SOLICITED ; + lnk->wr_tx_rdmas[i].wr_tx_rdma[0 ].wr.opcode =IB_WR_RDMA_WRITE ; + lnk->wr_tx_rdmas[i].wr_tx_rdma[1 ].wr.opcode =IB_WR_RDMA_WRITE ; + lnk->wr_tx_rdmas[i].wr_tx_rdma[0 ].wr.sg_list = + lnk->wr_tx_rdma_sges[i].tx_rdma_sge[0 ].wr_tx_rdma_sge; + lnk->wr_tx_rdmas[i].wr_tx_rdma[1 ].wr.sg_list = + lnk->wr_tx_rdma_sges[i].tx_rdma_sge[1 ].wr_tx_rdma_sge; }for (i =0 ; i < lnk->wr_rx_cnt; i++) { lnk->wr_rx_sges[i].addr =
@@ -521,8 +539,12 @@ void smc_wr_free_link_mem(struct smc_link *lnk) lnk->wr_tx_mask =NULL ;kfree (lnk->wr_tx_sges); lnk->wr_tx_sges =NULL ; +kfree (lnk->wr_tx_rdma_sges); + lnk->wr_tx_rdma_sges =NULL ;kfree (lnk->wr_rx_sges); lnk->wr_rx_sges =NULL ; +kfree (lnk->wr_tx_rdmas); + lnk->wr_tx_rdmas =NULL ;kfree (lnk->wr_rx_ibs); lnk->wr_rx_ibs =NULL ;kfree (lnk->wr_tx_ibs);
@@ -552,10 +574,20 @@ int smc_wr_alloc_link_mem(struct smc_link *link) GFP_KERNEL);if (!link->wr_rx_ibs) goto no_mem_wr_tx_ibs; + link->wr_tx_rdmas =kcalloc (SMC_WR_BUF_CNT , +sizeof (link->wr_tx_rdmas[0 ]), +GFP_KERNEL ); +if (!link->wr_tx_rdmas) + goto no_mem_wr_rx_ibs; + link->wr_tx_rdma_sges =kcalloc (SMC_WR_BUF_CNT , +sizeof (link->wr_tx_rdma_sges[0 ]), +GFP_KERNEL ); +if (!link->wr_tx_rdma_sges) + goto no_mem_wr_tx_rdmas; link->wr_tx_sges =kcalloc (SMC_WR_BUF_CNT ,sizeof (link->wr_tx_sges[0 ]),GFP_KERNEL );if (!link->wr_tx_sges) - goto no_mem_wr_rx_ibs; + goto no_mem_wr_tx_rdma_sges; link->wr_rx_sges =kcalloc (SMC_WR_BUF_CNT *3 ,sizeof (link->wr_rx_sges[0 ]),GFP_KERNEL );
@@ -579,6 +611,10 @@ int smc_wr_alloc_link_mem(struct smc_link *link)kfree (link->wr_rx_sges); no_mem_wr_tx_sges:kfree (link->wr_tx_sges); +no_mem_wr_tx_rdma_sges: +kfree (link->wr_tx_rdma_sges); +no_mem_wr_tx_rdmas: +kfree (link->wr_tx_rdmas); no_mem_wr_rx_ibs:kfree (link->wr_rx_ibs); no_mem_wr_tx_ibs:
net/smc/smc_wr.h +1 -0
@@ -85,6 +85,7 @@ void smc_wr_add_dev(struct smc_ib_device *smcibdev);int smc_wr_tx_get_free_slot (struct smc_link *link,smc_wr_tx_handler handler,struct smc_wr_buf **wr_buf, +struct smc_rdma_wr **wrs,struct smc_wr_tx_pend_priv **wr_pend_priv);int smc_wr_tx_put_slot (struct smc_link *link,struct smc_wr_tx_pend_priv *wr_pend_priv);
Signature · 1 line
2.16.4
PATCH 2/4 net/smc: fix sender_free computation
In reply to Ursula BraunIn some scenarios a separate consumer cursor update is necessary. The decision is made in smc_tx_consumer_cursor_update(). The sender_free computation could be wrong:
The rx confirmed cursor is always smaller than or equal to the rx producer cursor. The parameters in the smc_curs_diff() call have to be exchanged, otherwise sender_free might even be negative.
And if more data arrives local_rx_ctrl.prod might be updated, enabling a cursor difference between local_rx_ctrl.prod and rx confirmed cursor larger than the RMB size. This case is not covered by smc_curs_diff(). Thus function smc_curs_diff_large() is introduced here.
If a recvmsg() is processed in parallel, local_tx_ctrl.cons might change during smc_cdc_msg_send. Make sure rx_curs_confirmed is updated with the actually sent local_tx_ctrl.cons value.
--- net/smc/smc_cdc.c | 5 +++-- net/smc/smc_cdc.h | 26 +++++++++++++++++++++++++- net/smc/smc_tx.c | 3 ++- 3 files changed, 30 insertions(+), 4 deletions(-)
net/smc/smc_cdc.c +3 -2
@@ -91,6 +91,7 @@ int smc_cdc_msg_send(struct smc_connection *conn,struct smc_wr_buf *wr_buf, struct smc_cdc_tx_pend *pend) { + union smc_host_cursor cfed;struct smc_link *link;int rc;
@@ -102,10 +103,10 @@ int smc_cdc_msg_send(struct smc_connection *conn, conn->local_tx_ctrl.seqno = conn->tx_cdc_seq;smc_host_msg_to_cdc ((struct smc_cdc_msg *)wr_buf, &conn->local_tx_ctrl, conn); +smc_curs_copy (&cfed, &((struct smc_host_cdc_msg *)wr_buf)->cons, conn); rc =smc_wr_tx_send (link, (struct smc_wr_tx_pend_priv *)pend);if (!rc) -smc_curs_copy (&conn->rx_curs_confirmed, - &conn->local_tx_ctrl.cons, conn); +smc_curs_copy (&conn->rx_curs_confirmed, &cfed, conn);return rc; }
net/smc/smc_cdc.h +25 -1
@@ -160,7 +160,9 @@ static inline void smcd_curs_copy(union smcd_cdc_cursor *tgt,#endif } -/* calculate cursor difference between old and new, where old <= new */ +/* calculate cursor difference between old and new, where old <= new and +* difference cannot exceed size +*/ static inline int smc_curs_diff (unsigned int size,union smc_host_cursor *old,union smc_host_cursor *new)
@@ -185,6 +187,28 @@ static inline int smc_curs_comp(unsigned int size,return smc_curs_diff (size, old, new); } +/* calculate cursor difference between old and new, where old <= new and +* difference may exceed size +*/ +static inline int smc_curs_diff_large (unsigned int size, +union smc_host_cursor *old, +union smc_host_cursor *new) +{ +if (old->wrap < new->wrap) +return min_t (int, + (size - old->count) + new->count + + (new->wrap - old->wrap -1 ) * size, + size); + +if (old->wrap > new->wrap)/* wrap has switched from 0xffff to 0x0000 */ +return min_t (int, + (size - old->count) + new->count + + (new->wrap +0xffff - old->wrap) * size, + size); + +return max_t (int,0 , (new->count - old->count)); +} +static inline void smc_host_cursor_to_cdc (union smc_cdc_cursor *peer,union smc_host_cursor *local,struct smc_connection *conn)
net/smc/smc_tx.c +2 -1
@@ -595,7 +595,8 @@ void smc_tx_consumer_update(struct smc_connection *conn, bool force)if (to_confirm > conn->rmbe_update_limit) {smc_curs_copy (&prod, &conn->local_rx_ctrl.prod, conn); sender_free = conn->rmb_desc->len - -smc_curs_diff (conn->rmb_desc->len, &prod, &cfed); +smc_curs_diff_large (conn->rmb_desc->len, + &cfed, &prod); } if (conn->local_rx_ctrl.prod_flags.cons_curs_upd_req ||
Signature · 1 line
2.16.4
PATCH 3/4 net/smc: delete rkey first before switching to unused
In reply to Ursula BraunOnce RMBs are flagged as unused they are candidates for reuse. Thus the LLC DELETE RKEY operaton should be made before flagging the RMB as unused.
--- net/smc/smc_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/smc/smc_core.c +1 -1
@@ -302,13 +302,13 @@ static void smc_buf_unuse(struct smc_connection *conn, conn->sndbuf_desc->used =0 ;if (conn->rmb_desc) {if (!conn->rmb_desc->regerr) { - conn->rmb_desc->used =0 ;if (!lgr->is_smcd) {/* unregister rmb with peer */ smc_llc_do_delete_rkey ( &lgr->lnk[SMC_SINGLE_LINK ], conn->rmb_desc); } + conn->rmb_desc->used =0 ; }else {/* buf registration failed, reuse not possible */ write_lock_bh (&lgr->rmbs_lock);
Signature · 1 line
2.16.4
PATCH 4/4 net/smc: correct state change for peer closing
In reply to Ursula BraunIf some kind of closing is received from the peer while still in state SMC_INIT, it means the peer has had an active connection and closed the socket quickly before listen_work finished. This should not result in a shortcut from state SMC_INIT to state SMC_CLOSED. This patch adds the socket to the accept queue in state SMC_APPCLOSEWAIT1. The socket reaches state SMC_CLOSED once being accepted and closed with smc_release().
--- net/smc/smc_close.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
net/smc/smc_close.c +1 -8
@@ -345,14 +345,7 @@ static void smc_close_passive_work(struct work_struct *work)switch (sk->sk_state) {case SMC_INIT : -if (atomic_read (&conn->bytes_to_rcv) || - (rxflags->peer_done_writing && - !smc_cdc_rxed_any_close (conn))) { - sk->sk_state =SMC_APPCLOSEWAIT1 ; - }else { - sk->sk_state =SMC_CLOSED ; -sock_put (sk);/* passive closing */ - } + sk->sk_state =SMC_APPCLOSEWAIT1 ;break ;case SMC_ACTIVE : sk->sk_state =SMC_APPCLOSEWAIT1 ;
Signature · 1 line
2.16.4
David Miller
maintainerFrom: Ursula Braun <[email protected]>
Date: Mon, 4 Feb 2019 13:44:43 +0100
Quoted 5 lines
here are more fixes in the smc code for the net tree:
Patch 1 fixes an IB-related problem with SMCR. Patch 2 fixes a cursor problem for one-way traffic. Patch 3 fixes a problem with RMB-reusage. Patch 4 fixes a closing issue.
Series applied, thanks.