Skip to content

Commit c4cc0b9

Browse files
committed
Merge branch 'net-smc-updates-2020-10-07'
Karsten Graul says: ==================== net/smc: updates 2020-10-07 Patch 1 and 2 address warnings from static code checkers, and patch 3 handles a case when all proposed ISM V2 devices fail to init and no V1 devices are tried afterwards. ==================== Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 8f5e71b + f29fa00 commit c4cc0b9

File tree

1 file changed

+48
-44
lines changed

1 file changed

+48
-44
lines changed

net/smc/af_smc.c

+48-44
Original file line numberDiff line numberDiff line change
@@ -553,23 +553,12 @@ static int smc_connect_decline_fallback(struct smc_sock *smc, int reason_code,
553553
}
554554

555555
/* abort connecting */
556-
static int smc_connect_abort(struct smc_sock *smc, int reason_code,
557-
int local_first)
556+
static void smc_connect_abort(struct smc_sock *smc, int local_first)
558557
{
559-
bool is_smcd = smc->conn.lgr->is_smcd;
560-
561558
if (local_first)
562559
smc_lgr_cleanup_early(&smc->conn);
563560
else
564561
smc_conn_free(&smc->conn);
565-
if (is_smcd)
566-
/* there is only one lgr role for SMC-D; use server lock */
567-
mutex_unlock(&smc_server_lgr_pending);
568-
else
569-
mutex_unlock(&smc_client_lgr_pending);
570-
571-
smc->connect_nonblock = 0;
572-
return reason_code;
573562
}
574563

575564
/* check if there is a rdma device available for this connection. */
@@ -764,43 +753,47 @@ static int smc_connect_rdma(struct smc_sock *smc,
764753
break;
765754
}
766755
}
767-
if (!link)
768-
return smc_connect_abort(smc, SMC_CLC_DECL_NOSRVLINK,
769-
ini->first_contact_local);
756+
if (!link) {
757+
reason_code = SMC_CLC_DECL_NOSRVLINK;
758+
goto connect_abort;
759+
}
770760
smc->conn.lnk = link;
771761
}
772762

773763
/* create send buffer and rmb */
774-
if (smc_buf_create(smc, false))
775-
return smc_connect_abort(smc, SMC_CLC_DECL_MEM,
776-
ini->first_contact_local);
764+
if (smc_buf_create(smc, false)) {
765+
reason_code = SMC_CLC_DECL_MEM;
766+
goto connect_abort;
767+
}
777768

778769
if (ini->first_contact_local)
779770
smc_link_save_peer_info(link, aclc);
780771

781-
if (smc_rmb_rtoken_handling(&smc->conn, link, aclc))
782-
return smc_connect_abort(smc, SMC_CLC_DECL_ERR_RTOK,
783-
ini->first_contact_local);
772+
if (smc_rmb_rtoken_handling(&smc->conn, link, aclc)) {
773+
reason_code = SMC_CLC_DECL_ERR_RTOK;
774+
goto connect_abort;
775+
}
784776

785777
smc_close_init(smc);
786778
smc_rx_init(smc);
787779

788780
if (ini->first_contact_local) {
789-
if (smc_ib_ready_link(link))
790-
return smc_connect_abort(smc, SMC_CLC_DECL_ERR_RDYLNK,
791-
ini->first_contact_local);
781+
if (smc_ib_ready_link(link)) {
782+
reason_code = SMC_CLC_DECL_ERR_RDYLNK;
783+
goto connect_abort;
784+
}
792785
} else {
793-
if (smcr_lgr_reg_rmbs(link, smc->conn.rmb_desc))
794-
return smc_connect_abort(smc, SMC_CLC_DECL_ERR_REGRMB,
795-
ini->first_contact_local);
786+
if (smcr_lgr_reg_rmbs(link, smc->conn.rmb_desc)) {
787+
reason_code = SMC_CLC_DECL_ERR_REGRMB;
788+
goto connect_abort;
789+
}
796790
}
797791
smc_rmb_sync_sg_for_device(&smc->conn);
798792

799793
reason_code = smc_clc_send_confirm(smc, ini->first_contact_local,
800794
SMC_V1);
801795
if (reason_code)
802-
return smc_connect_abort(smc, reason_code,
803-
ini->first_contact_local);
796+
goto connect_abort;
804797

805798
smc_tx_init(smc);
806799

@@ -810,8 +803,7 @@ static int smc_connect_rdma(struct smc_sock *smc,
810803
reason_code = smcr_clnt_conf_first_link(smc);
811804
smc_llc_flow_stop(link->lgr, &link->lgr->llc_flow_lcl);
812805
if (reason_code)
813-
return smc_connect_abort(smc, reason_code,
814-
ini->first_contact_local);
806+
goto connect_abort;
815807
}
816808
mutex_unlock(&smc_client_lgr_pending);
817809

@@ -821,6 +813,12 @@ static int smc_connect_rdma(struct smc_sock *smc,
821813
smc->sk.sk_state = SMC_ACTIVE;
822814

823815
return 0;
816+
connect_abort:
817+
smc_connect_abort(smc, ini->first_contact_local);
818+
mutex_unlock(&smc_client_lgr_pending);
819+
smc->connect_nonblock = 0;
820+
821+
return reason_code;
824822
}
825823

826824
/* The server has chosen one of the proposed ISM devices for the communication.
@@ -872,11 +870,10 @@ static int smc_connect_ism(struct smc_sock *smc,
872870

873871
/* Create send and receive buffers */
874872
rc = smc_buf_create(smc, true);
875-
if (rc)
876-
return smc_connect_abort(smc, (rc == -ENOSPC) ?
877-
SMC_CLC_DECL_MAX_DMB :
878-
SMC_CLC_DECL_MEM,
879-
ini->first_contact_local);
873+
if (rc) {
874+
rc = (rc == -ENOSPC) ? SMC_CLC_DECL_MAX_DMB : SMC_CLC_DECL_MEM;
875+
goto connect_abort;
876+
}
880877

881878
smc_conn_save_peer_info(smc, aclc);
882879
smc_close_init(smc);
@@ -886,7 +883,7 @@ static int smc_connect_ism(struct smc_sock *smc,
886883
rc = smc_clc_send_confirm(smc, ini->first_contact_local,
887884
aclc->hdr.version);
888885
if (rc)
889-
return smc_connect_abort(smc, rc, ini->first_contact_local);
886+
goto connect_abort;
890887
mutex_unlock(&smc_server_lgr_pending);
891888

892889
smc_copy_sock_settings_to_clc(smc);
@@ -895,6 +892,12 @@ static int smc_connect_ism(struct smc_sock *smc,
895892
smc->sk.sk_state = SMC_ACTIVE;
896893

897894
return 0;
895+
connect_abort:
896+
smc_connect_abort(smc, ini->first_contact_local);
897+
mutex_unlock(&smc_server_lgr_pending);
898+
smc->connect_nonblock = 0;
899+
900+
return rc;
898901
}
899902

900903
/* check if received accept type and version matches a proposed one */
@@ -1478,11 +1481,12 @@ static void smc_find_ism_v2_device_serv(struct smc_sock *new_smc,
14781481
struct smc_clc_v2_extension *smc_v2_ext;
14791482
struct smc_clc_msg_smcd *pclc_smcd;
14801483
unsigned int matches = 0;
1484+
u8 smcd_version;
14811485
u8 *eid = NULL;
14821486
int i;
14831487

14841488
if (!(ini->smcd_version & SMC_V2) || !smcd_indicated(ini->smc_type_v2))
1485-
return;
1489+
goto not_found;
14861490

14871491
pclc_smcd = smc_get_clc_msg_smcd(pclc);
14881492
smc_v2_ext = smc_get_clc_v2_ext(pclc);
@@ -1516,6 +1520,7 @@ static void smc_find_ism_v2_device_serv(struct smc_sock *new_smc,
15161520
}
15171521

15181522
/* separate - outside the smcd_dev_list.lock */
1523+
smcd_version = ini->smcd_version;
15191524
for (i = 0; i < matches; i++) {
15201525
ini->smcd_version = SMC_V2;
15211526
ini->is_smcd = true;
@@ -1525,6 +1530,8 @@ static void smc_find_ism_v2_device_serv(struct smc_sock *new_smc,
15251530
continue;
15261531
return; /* matching and usable V2 ISM device found */
15271532
}
1533+
/* no V2 ISM device could be initialized */
1534+
ini->smcd_version = smcd_version; /* restore original value */
15281535

15291536
not_found:
15301537
ini->smcd_version &= ~SMC_V2;
@@ -1661,7 +1668,6 @@ static void smc_listen_work(struct work_struct *work)
16611668
smc_listen_work);
16621669
u8 version = smc_ism_v2_capable ? SMC_V2 : SMC_V1;
16631670
struct socket *newclcsock = new_smc->clcsock;
1664-
struct smc_clc_msg_accept_confirm_v2 *cclc2;
16651671
struct smc_clc_msg_accept_confirm *cclc;
16661672
struct smc_clc_msg_proposal_area *buf;
16671673
struct smc_clc_msg_proposal *pclc;
@@ -1737,11 +1743,9 @@ static void smc_listen_work(struct work_struct *work)
17371743
mutex_unlock(&smc_server_lgr_pending);
17381744

17391745
/* receive SMC Confirm CLC message */
1740-
cclc2 = (struct smc_clc_msg_accept_confirm_v2 *)buf;
1741-
cclc = (struct smc_clc_msg_accept_confirm *)cclc2;
1742-
memset(buf, 0, sizeof(struct smc_clc_msg_proposal_area));
1743-
rc = smc_clc_wait_msg(new_smc, cclc2,
1744-
sizeof(struct smc_clc_msg_proposal_area),
1746+
memset(buf, 0, sizeof(*buf));
1747+
cclc = (struct smc_clc_msg_accept_confirm *)buf;
1748+
rc = smc_clc_wait_msg(new_smc, cclc, sizeof(*buf),
17451749
SMC_CLC_CONFIRM, CLC_WAIT_TIME);
17461750
if (rc) {
17471751
if (!ini->is_smcd)

0 commit comments

Comments
 (0)