net/smc: fixes 2018-11-12
v3 cover net/smc: fixes 2018-11-12
Dave,
here is V3 of some net/smc fixes in different areas for the net tree.
v1->v2:
do not define 8-byte alignment for union smcd_cdc_cursor in patch 4/5 "net/smc: atomic SMCD cursor handling"v2->v3:
stay with 8-byte alignment for union smcd_cdc_cursor in patch 4/5 "net/smc: atomic SMCD cursor handling", but get rid of __packed for struct smcd_cdc_msg
Thanks, Ursula
Hans Wippel (2):
net/smc: abort CLC connection in smc_release
net/smc: add SMC-D shutdown signal
Karsten Graul (1):
net/smc: use queue pair number when matching link group
Ursula Braun (2):
net/smc: atomic SMCD cursor handling net/smc: use after free fix in smc_wr_tx_put_slot()
net/smc/af_smc.c | 11 +++++++---- net/smc/smc_cdc.c | 24 ++++++++++++---------- net/smc/smc_cdc.h | 58 +++++++++++++++++++++++++++++++++++++++++------------- net/smc/smc_core.c | 20 +++++++++++++------ net/smc/smc_core.h | 5 +++-- net/smc/smc_ism.c | 43 +++++++++++++++++++++++++++++----------- net/smc/smc_ism.h | 1 + net/smc/smc_wr.c | 4 +++- 8 files changed, 118 insertions(+), 48 deletions(-)
Signature · 1 line
2.16.4
PATCH v3 1/5 net/smc: abort CLC connection in smc_release
From: Hans Wippel <[email protected]>
In case of a non-blocking SMC socket, the initial CLC handshake is performed over a blocking TCP connection in a worker. If the SMC socket is released, smc_release has to wait for the blocking CLC socket operations (e.g., kernel_connect) inside the worker.
This patch aborts a CLC connection when the respective non-blocking SMC socket is released to avoid waiting on socket operations or timeouts.
--- net/smc/af_smc.c | 2 ++ 1 file changed, 2 insertions(+)
net/smc/af_smc.c +2 -0
@@ -127,6 +127,8 @@ static int smc_release(struct socket *sock) smc =smc_sk (sk);/* cleanup for a dangling non-blocking connect */ +if (smc->connect_info && sk->sk_state ==SMC_INIT ) +tcp_abort (smc->clcsock->sk,ECONNABORTED );flush_work (&smc->connect_work);kfree (smc->connect_info); smc->connect_info =NULL ;
Signature · 1 line
2.16.4
PATCH v3 2/5 net/smc: use queue pair number when matching link group
In reply to Ursula BraunFrom: Karsten Graul <[email protected]>
When searching for an existing link group the queue pair number is also to be taken into consideration. When the SMC server sends a new number in a CLC packet (keeping all other values equal) then a new link group is to be created on the SMC client side.
--- net/smc/af_smc.c | 9 +++++---- net/smc/smc_core.c | 10 ++++++---- net/smc/smc_core.h | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-)
net/smc/af_smc.c +5 -4
@@ -549,7 +549,8 @@ static int smc_connect_rdma(struct smc_sock *smc,mutex_lock (&smc_create_lgr_pending); local_contact =smc_conn_create (smc, false, aclc->hdr.flag, ibdev, - ibport, &aclc->lcl,NULL ,0 ); + ibport,ntoh24 (aclc->qpn), &aclc->lcl, +NULL ,0 );if (local_contact <0 ) {if (local_contact == -ENOMEM ) reason_code =SMC_CLC_DECL_MEM ;/* insufficient memory*/
@@ -620,7 +621,7 @@ static int smc_connect_ism(struct smc_sock *smc,int rc =0 ;mutex_lock (&smc_create_lgr_pending); - local_contact =smc_conn_create (smc, true, aclc->hdr.flag,NULL ,0 , + local_contact =smc_conn_create (smc, true, aclc->hdr.flag,NULL ,0 ,0 ,NULL , ismdev, aclc->gid);if (local_contact <0 )return smc_connect_abort (smc,SMC_CLC_DECL_MEM ,0 );
@@ -1085,7 +1086,7 @@ static int smc_listen_rdma_init(struct smc_sock *new_smc, int *local_contact) {/* allocate connection / link group */ - *local_contact =smc_conn_create (new_smc, false,0 , ibdev, ibport, + *local_contact =smc_conn_create (new_smc, false,0 , ibdev, ibport,0 , &pclc->lcl,NULL ,0 );if (*local_contact <0 ) {if (*local_contact == -ENOMEM )
@@ -1109,7 +1110,7 @@ static int smc_listen_ism_init(struct smc_sock *new_smc,struct smc_clc_msg_smcd *pclc_smcd; pclc_smcd =smc_get_clc_msg_smcd (pclc); - *local_contact =smc_conn_create (new_smc, true,0 ,NULL ,0 ,NULL , + *local_contact =smc_conn_create (new_smc, true,0 ,NULL ,0 ,0 ,NULL , ismdev, pclc_smcd->gid);if (*local_contact <0 ) {if (*local_contact == -ENOMEM )
net/smc/smc_core.c +6 -4
@@ -559,7 +559,7 @@ int smc_vlan_by_tcpsk(struct socket *clcsock, unsigned short *vlan_id)static bool smcr_lgr_match (struct smc_link_group *lgr,struct smc_clc_msg_local *lcl, -enum smc_lgr_role role) +enum smc_lgr_role role,u32 clcqpn) {return !memcmp (lgr->peer_systemid, lcl->id_for_peer, SMC_SYSTEMID_LEN) &&
@@ -567,7 +567,9 @@ static bool smcr_lgr_match(struct smc_link_group *lgr, SMC_GID_SIZE) && !memcmp (lgr->lnk[SMC_SINGLE_LINK ].peer_mac, lcl->mac,sizeof (lcl->mac)) && - lgr->role == role; + lgr->role == role && + (lgr->role ==SMC_SERV || + lgr->lnk[SMC_SINGLE_LINK ].peer_qpn == clcqpn); } static bool smcd_lgr_match(struct smc_link_group *lgr,
@@ -578,7 +580,7 @@ static bool smcd_lgr_match(struct smc_link_group *lgr,/* create a new SMC connection (and a new link group if necessary) */ int smc_conn_create (struct smc_sock *smc,bool is_smcd,int srv_first_contact, -struct smc_ib_device *smcibdev,u8 ibport, +struct smc_ib_device *smcibdev,u8 ibport,u32 clcqpn,struct smc_clc_msg_local *lcl,struct smcd_dev *smcd,u64 peer_gid) {
@@ -603,7 +605,7 @@ int smc_conn_create(struct smc_sock *smc, bool is_smcd, int srv_first_contact,list_for_each_entry (lgr, &smc_lgr_list.list, list) {write_lock_bh (&lgr->conns_lock); if ((is_smcd ? smcd_lgr_match(lgr, smcd, peer_gid) : - smcr_lgr_match(lgr, lcl, role)) && + smcr_lgr_match(lgr, lcl, role, clcqpn)) && !lgr->sync_err && lgr->vlan_id == vlan_id && (role == SMC_CLNT ||
net/smc/smc_core.h +1 -1
@@ -262,7 +262,7 @@ int smc_vlan_by_tcpsk(struct socket *clcsock, unsigned short *vlan_id);void smc_conn_free (struct smc_connection *conn);int smc_conn_create (struct smc_sock *smc,bool is_smcd,int srv_first_contact, -struct smc_ib_device *smcibdev,u8 ibport, +struct smc_ib_device *smcibdev,u8 ibport,u32 clcqpn,struct smc_clc_msg_local *lcl,struct smcd_dev *smcd,u64 peer_gid);void smcd_conn_free (struct smc_connection *conn);
Signature · 1 line
2.16.4
PATCH v3 3/5 net/smc: add SMC-D shutdown signal
In reply to Ursula BraunFrom: Hans Wippel <[email protected]>
When a SMC-D link group is freed, a shutdown signal should be sent to the peer to indicate that the link group is invalid. This patch adds the shutdown signal to the SMC code.
--- net/smc/smc_core.c | 10 ++++++++-- net/smc/smc_core.h | 3 ++- net/smc/smc_ism.c | 43 ++++++++++++++++++++++++++++++++----------- net/smc/smc_ism.h | 1 + 4 files changed, 43 insertions(+), 14 deletions(-)
net/smc/smc_core.c +8 -2
@@ -184,6 +184,8 @@ static void smc_lgr_free_work(struct work_struct *work)if (!lgr->is_smcd && lnk->state !=SMC_LNK_INACTIVE )smc_llc_link_inactive (lnk); +if (lgr->is_smcd) +smc_ism_signal_shutdown (lgr);smc_lgr_free (lgr); } }
@@ -485,7 +487,7 @@ void smc_port_terminate(struct smc_ib_device *smcibdev, u8 ibport) }/* Called when SMC-D device is terminated or peer is lost */ -void smc_smcd_terminate (struct smcd_dev *dev,u64 peer_gid) +void smc_smcd_terminate (struct smcd_dev *dev,u64 peer_gid,unsigned short vlan) {struct smc_link_group *lgr, *l;LIST_HEAD (lgr_free_list);
@@ -495,7 +497,7 @@ void smc_smcd_terminate(struct smcd_dev *dev, u64 peer_gid)list_for_each_entry_safe (lgr, l, &smc_lgr_list.list, list) {if (lgr->is_smcd && lgr->smcd == dev && (!peer_gid || lgr->peer_gid == peer_gid) && - !list_empty (&lgr->list)) { + (vlan ==VLAN_VID_MASK || lgr->vlan_id == vlan)) {__smc_lgr_terminate (lgr);list_move (&lgr->list, &lgr_free_list); }
@@ -506,6 +508,8 @@ void smc_smcd_terminate(struct smcd_dev *dev, u64 peer_gid)list_for_each_entry_safe (lgr, l, &lgr_free_list, list) {list_del_init (&lgr->list);cancel_delayed_work_sync (&lgr->free_work); +if (!peer_gid && vlan ==VLAN_VID_MASK )/* dev terminated? */ +smc_ism_signal_shutdown (lgr);smc_lgr_free (lgr); } }
@@ -1026,6 +1030,8 @@ void smc_core_exit(void)smc_llc_link_inactive (lnk); }cancel_delayed_work_sync (&lgr->free_work); +if (lgr->is_smcd) +smc_ism_signal_shutdown (lgr);smc_lgr_free (lgr);/* free link group */ } }
net/smc/smc_core.h +2 -1
@@ -247,7 +247,8 @@ void smc_lgr_free(struct smc_link_group *lgr);void smc_lgr_forget (struct smc_link_group *lgr);void smc_lgr_terminate (struct smc_link_group *lgr);void smc_port_terminate (struct smc_ib_device *smcibdev,u8 ibport); -void smc_smcd_terminate (struct smcd_dev *dev,u64 peer_gid); +void smc_smcd_terminate (struct smcd_dev *dev,u64 peer_gid, +unsigned short vlan);int smc_buf_create (struct smc_sock *smc,bool is_smcd);int smc_uncompress_bufsize (u8 compressed); int smc_rmb_rtoken_handling(struct smc_connection *conn,
net/smc/smc_ism.c +32 -11
74 lines not on this page · raw message
net/smc/smc_ism.h +1 -0
@@ -45,4 +45,5 @@ int smc_ism_register_dmb(struct smc_link_group *lgr, int buf_size,int smc_ism_unregister_dmb (struct smcd_dev *dev,struct smc_buf_desc *dmb_desc);int smc_ism_write (struct smcd_dev *dev,const struct smc_ism_position *pos,void *data,size_t len); +int smc_ism_signal_shutdown (struct smc_link_group *lgr);#endif
Signature · 1 line
2.16.4
PATCH v3 4/5 net/smc: atomic SMCD cursor handling
In reply to Ursula BraunRunning uperf tests with SMCD on LPARs results in corrupted cursors. SMCD cursors should be treated atomically to fix cursor corruption.
--- net/smc/smc_cdc.c | 24 +++++++++++++---------- net/smc/smc_cdc.h | 58 +++++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 58 insertions(+), 24 deletions(-)
net/smc/smc_cdc.c +14 -10
@@ -177,23 +177,24 @@ void smc_cdc_tx_dismiss_slots(struct smc_connection *conn)int smcd_cdc_msg_send (struct smc_connection *conn) { struct smc_sock *smc = container_of(conn, struct smc_sock, conn); +union smc_host_cursor curs;struct smcd_cdc_msg cdc;int rc, diff;memset (&cdc,0 ,sizeof (cdc)); cdc.common.type =SMC_CDC_MSG_TYPE ; - cdc.prod_wrap = conn->local_tx_ctrl.prod.wrap; - cdc.prod_count = conn->local_tx_ctrl.prod.count; - - cdc.cons_wrap = conn->local_tx_ctrl.cons.wrap; - cdc.cons_count = conn->local_tx_ctrl.cons.count; - cdc.prod_flags = conn->local_tx_ctrl.prod_flags; - cdc.conn_state_flags = conn->local_tx_ctrl.conn_state_flags; + curs.acurs.counter =atomic64_read (&conn->local_tx_ctrl.prod.acurs); + cdc.prod.wrap = curs.wrap; + cdc.prod.count = curs.count; + curs.acurs.counter =atomic64_read (&conn->local_tx_ctrl.cons.acurs); + cdc.cons.wrap = curs.wrap; + cdc.cons.count = curs.count; + cdc.cons.prod_flags = conn->local_tx_ctrl.prod_flags; + cdc.cons.conn_state_flags = conn->local_tx_ctrl.conn_state_flags; rc =smcd_tx_ism_write (conn, &cdc,sizeof (cdc),0 ,1 );if (rc)return rc; -smc_curs_copy (&conn->rx_curs_confirmed, &conn->local_tx_ctrl.cons, - conn); +smc_curs_copy (&conn->rx_curs_confirmed, &curs, conn);/* Calculate transmitted data and increment free send buffer space */ diff =smc_curs_diff (conn->sndbuf_desc->len, &conn->tx_curs_fin, &conn->tx_curs_sent);
@@ -331,13 +332,16 @@ static void smc_cdc_msg_recv(struct smc_sock *smc, struct smc_cdc_msg *cdc)static void smcd_cdc_rx_tsklet (unsigned long data) {struct smc_connection *conn = (struct smc_connection *)data; +struct smcd_cdc_msg *data_cdc;struct smcd_cdc_msg cdc;struct smc_sock *smc;if (!conn)return ; -memcpy (&cdc, conn->rmb_desc->cpu_addr,sizeof (cdc)); + data_cdc = (struct smcd_cdc_msg *)conn->rmb_desc->cpu_addr; +smcd_curs_copy (&cdc.prod, &data_cdc->prod, conn); +smcd_curs_copy (&cdc.cons, &data_cdc->cons, conn); smc = container_of(conn, struct smc_sock, conn);smc_cdc_msg_recv (smc, (struct smc_cdc_msg *)&cdc); }
net/smc/smc_cdc.h +44 -14
81 lines not on this page · raw message
Signature · 1 line
2.16.4
PATCH v3 5/5 net/smc: use after free fix in smc_wr_tx_put_slot()
In reply to Ursula BraunFrom: Ursula Braun <[email protected]>
In smc_wr_tx_put_slot() field pend->idx is used after being cleared. That means always idx 0 is cleared in the wr_tx_mask. This results in a broken administration of available WR send payload buffers.
--- net/smc/smc_wr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/smc/smc_wr.c +3 -1
@@ -215,12 +215,14 @@ int smc_wr_tx_put_slot(struct smc_link *link, pend = container_of(wr_pend_priv, struct smc_wr_tx_pend, priv);if (pend->idx < link->wr_tx_cnt) { +u32 idx = pend->idx; +/* clear the full struct smc_wr_tx_pend including .priv */ memset (&link->wr_tx_pends[pend->idx],0 ,sizeof (link->wr_tx_pends[pend->idx]));memset (&link->wr_tx_bufs[pend->idx],0 ,sizeof (link->wr_tx_bufs[pend->idx])); -test_and_clear_bit (pend->idx, link->wr_tx_mask); +test_and_clear_bit (idx, link->wr_tx_mask);return 1 ; }
Signature · 1 line
2.16.4
David Miller
maintainerFrom: Ursula Braun <[email protected]>
Date: Fri, 16 Nov 2018 13:36:12 +0100
Quoted 4 lines
v2->v3:
stay with 8-byte alignment for unionsmcd_cdc_cursorin patch 4/5 "net/smc: atomic SMCD cursor handling", but get rid of__packedfor structsmcd_cdc_msg
This SMC-D message is defined in some standard somewhere, right? So if this __packed removal changes the layout it will break things.
I see smc_cdc_msg has the same issue, and it's layout is defined in RFC7609.
If the __packed removal doesn't change the layout, you should remove it from smc_cdc_msg too for consistency.
This is why I tell people to never use __packed.