Skip to content

Commit 99f1956

Browse files
karstengrgregkh
authored andcommitted
net/smc: improved fix wait on already cleared link
[ Upstream commit 95f7f3e ] Commit 8f3d65c ("net/smc: fix wait on already cleared link") introduced link refcounting to avoid waits on already cleared links. This patch extents and improves the refcounting to cover all remaining possible cases for this kind of error situation. Fixes: 15e1b99 ("net/smc: no WR buffer wait for terminating link group") Signed-off-by: Karsten Graul <kgraul@linux.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent e553265 commit 99f1956

5 files changed

Lines changed: 85 additions & 41 deletions

File tree

‎net/smc/smc_cdc.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,23 +150,28 @@ static int smcr_cdc_get_slot_and_msg_send(struct smc_connection *conn)
150150

151151
again:
152152
link = conn->lnk;
153+
if (!smc_wr_tx_link_hold(link))
154+
return -ENOLINK;
153155
rc = smc_cdc_get_free_slot(conn, link, &wr_buf, NULL, &pend);
154156
if (rc)
155-
return rc;
157+
goto put_out;
156158

157159
spin_lock_bh(&conn->send_lock);
158160
if (link != conn->lnk) {
159161
/* link of connection changed, try again one time*/
160162
spin_unlock_bh(&conn->send_lock);
161163
smc_wr_tx_put_slot(link,
162164
(struct smc_wr_tx_pend_priv *)pend);
165+
smc_wr_tx_link_put(link);
163166
if (again)
164167
return -ENOLINK;
165168
again = true;
166169
goto again;
167170
}
168171
rc = smc_cdc_msg_send(conn, wr_buf, pend);
169172
spin_unlock_bh(&conn->send_lock);
173+
put_out:
174+
smc_wr_tx_link_put(link);
170175
return rc;
171176
}
172177

‎net/smc/smc_core.c‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ struct smc_link *smc_switch_conns(struct smc_link_group *lgr,
550550
to_lnk = &lgr->lnk[i];
551551
break;
552552
}
553-
if (!to_lnk) {
553+
if (!to_lnk || !smc_wr_tx_link_hold(to_lnk)) {
554554
smc_lgr_terminate_sched(lgr);
555555
return NULL;
556556
}
@@ -582,24 +582,26 @@ struct smc_link *smc_switch_conns(struct smc_link_group *lgr,
582582
read_unlock_bh(&lgr->conns_lock);
583583
/* pre-fetch buffer outside of send_lock, might sleep */
584584
rc = smc_cdc_get_free_slot(conn, to_lnk, &wr_buf, NULL, &pend);
585-
if (rc) {
586-
smcr_link_down_cond_sched(to_lnk);
587-
return NULL;
588-
}
585+
if (rc)
586+
goto err_out;
589587
/* avoid race with smcr_tx_sndbuf_nonempty() */
590588
spin_lock_bh(&conn->send_lock);
591589
conn->lnk = to_lnk;
592590
rc = smc_switch_cursor(smc, pend, wr_buf);
593591
spin_unlock_bh(&conn->send_lock);
594592
sock_put(&smc->sk);
595-
if (rc) {
596-
smcr_link_down_cond_sched(to_lnk);
597-
return NULL;
598-
}
593+
if (rc)
594+
goto err_out;
599595
goto again;
600596
}
601597
read_unlock_bh(&lgr->conns_lock);
598+
smc_wr_tx_link_put(to_lnk);
602599
return to_lnk;
600+
601+
err_out:
602+
smcr_link_down_cond_sched(to_lnk);
603+
smc_wr_tx_link_put(to_lnk);
604+
return NULL;
603605
}
604606

605607
static void smcr_buf_unuse(struct smc_buf_desc *rmb_desc,

‎net/smc/smc_llc.c‎

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,11 @@ int smc_llc_send_confirm_link(struct smc_link *link,
383383
struct smc_wr_buf *wr_buf;
384384
int rc;
385385

386+
if (!smc_wr_tx_link_hold(link))
387+
return -ENOLINK;
386388
rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
387389
if (rc)
388-
return rc;
390+
goto put_out;
389391
confllc = (struct smc_llc_msg_confirm_link *)wr_buf;
390392
memset(confllc, 0, sizeof(*confllc));
391393
confllc->hd.common.type = SMC_LLC_CONFIRM_LINK;
@@ -402,6 +404,8 @@ int smc_llc_send_confirm_link(struct smc_link *link,
402404
confllc->max_links = SMC_LLC_ADD_LNK_MAX_LINKS;
403405
/* send llc message */
404406
rc = smc_wr_tx_send(link, pend);
407+
put_out:
408+
smc_wr_tx_link_put(link);
405409
return rc;
406410
}
407411

@@ -415,9 +419,11 @@ static int smc_llc_send_confirm_rkey(struct smc_link *send_link,
415419
struct smc_link *link;
416420
int i, rc, rtok_ix;
417421

422+
if (!smc_wr_tx_link_hold(send_link))
423+
return -ENOLINK;
418424
rc = smc_llc_add_pending_send(send_link, &wr_buf, &pend);
419425
if (rc)
420-
return rc;
426+
goto put_out;
421427
rkeyllc = (struct smc_llc_msg_confirm_rkey *)wr_buf;
422428
memset(rkeyllc, 0, sizeof(*rkeyllc));
423429
rkeyllc->hd.common.type = SMC_LLC_CONFIRM_RKEY;
@@ -444,6 +450,8 @@ static int smc_llc_send_confirm_rkey(struct smc_link *send_link,
444450
(u64)sg_dma_address(rmb_desc->sgt[send_link->link_idx].sgl));
445451
/* send llc message */
446452
rc = smc_wr_tx_send(send_link, pend);
453+
put_out:
454+
smc_wr_tx_link_put(send_link);
447455
return rc;
448456
}
449457

@@ -456,9 +464,11 @@ static int smc_llc_send_delete_rkey(struct smc_link *link,
456464
struct smc_wr_buf *wr_buf;
457465
int rc;
458466

467+
if (!smc_wr_tx_link_hold(link))
468+
return -ENOLINK;
459469
rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
460470
if (rc)
461-
return rc;
471+
goto put_out;
462472
rkeyllc = (struct smc_llc_msg_delete_rkey *)wr_buf;
463473
memset(rkeyllc, 0, sizeof(*rkeyllc));
464474
rkeyllc->hd.common.type = SMC_LLC_DELETE_RKEY;
@@ -467,6 +477,8 @@ static int smc_llc_send_delete_rkey(struct smc_link *link,
467477
rkeyllc->rkey[0] = htonl(rmb_desc->mr_rx[link->link_idx]->rkey);
468478
/* send llc message */
469479
rc = smc_wr_tx_send(link, pend);
480+
put_out:
481+
smc_wr_tx_link_put(link);
470482
return rc;
471483
}
472484

@@ -480,9 +492,11 @@ int smc_llc_send_add_link(struct smc_link *link, u8 mac[], u8 gid[],
480492
struct smc_wr_buf *wr_buf;
481493
int rc;
482494

495+
if (!smc_wr_tx_link_hold(link))
496+
return -ENOLINK;
483497
rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
484498
if (rc)
485-
return rc;
499+
goto put_out;
486500
addllc = (struct smc_llc_msg_add_link *)wr_buf;
487501

488502
memset(addllc, 0, sizeof(*addllc));
@@ -504,6 +518,8 @@ int smc_llc_send_add_link(struct smc_link *link, u8 mac[], u8 gid[],
504518
}
505519
/* send llc message */
506520
rc = smc_wr_tx_send(link, pend);
521+
put_out:
522+
smc_wr_tx_link_put(link);
507523
return rc;
508524
}
509525

@@ -517,9 +533,11 @@ int smc_llc_send_delete_link(struct smc_link *link, u8 link_del_id,
517533
struct smc_wr_buf *wr_buf;
518534
int rc;
519535

536+
if (!smc_wr_tx_link_hold(link))
537+
return -ENOLINK;
520538
rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
521539
if (rc)
522-
return rc;
540+
goto put_out;
523541
delllc = (struct smc_llc_msg_del_link *)wr_buf;
524542

525543
memset(delllc, 0, sizeof(*delllc));
@@ -536,6 +554,8 @@ int smc_llc_send_delete_link(struct smc_link *link, u8 link_del_id,
536554
delllc->reason = htonl(reason);
537555
/* send llc message */
538556
rc = smc_wr_tx_send(link, pend);
557+
put_out:
558+
smc_wr_tx_link_put(link);
539559
return rc;
540560
}
541561

@@ -547,16 +567,20 @@ static int smc_llc_send_test_link(struct smc_link *link, u8 user_data[16])
547567
struct smc_wr_buf *wr_buf;
548568
int rc;
549569

570+
if (!smc_wr_tx_link_hold(link))
571+
return -ENOLINK;
550572
rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
551573
if (rc)
552-
return rc;
574+
goto put_out;
553575
testllc = (struct smc_llc_msg_test_link *)wr_buf;
554576
memset(testllc, 0, sizeof(*testllc));
555577
testllc->hd.common.type = SMC_LLC_TEST_LINK;
556578
testllc->hd.length = sizeof(struct smc_llc_msg_test_link);
557579
memcpy(testllc->user_data, user_data, sizeof(testllc->user_data));
558580
/* send llc message */
559581
rc = smc_wr_tx_send(link, pend);
582+
put_out:
583+
smc_wr_tx_link_put(link);
560584
return rc;
561585
}
562586

@@ -567,13 +591,16 @@ static int smc_llc_send_message(struct smc_link *link, void *llcbuf)
567591
struct smc_wr_buf *wr_buf;
568592
int rc;
569593

570-
if (!smc_link_usable(link))
594+
if (!smc_wr_tx_link_hold(link))
571595
return -ENOLINK;
572596
rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
573597
if (rc)
574-
return rc;
598+
goto put_out;
575599
memcpy(wr_buf, llcbuf, sizeof(union smc_llc_msg));
576-
return smc_wr_tx_send(link, pend);
600+
rc = smc_wr_tx_send(link, pend);
601+
put_out:
602+
smc_wr_tx_link_put(link);
603+
return rc;
577604
}
578605

579606
/* schedule an llc send on link, may wait for buffers,
@@ -586,13 +613,16 @@ static int smc_llc_send_message_wait(struct smc_link *link, void *llcbuf)
586613
struct smc_wr_buf *wr_buf;
587614
int rc;
588615

589-
if (!smc_link_usable(link))
616+
if (!smc_wr_tx_link_hold(link))
590617
return -ENOLINK;
591618
rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
592619
if (rc)
593-
return rc;
620+
goto put_out;
594621
memcpy(wr_buf, llcbuf, sizeof(union smc_llc_msg));
595-
return smc_wr_tx_send_wait(link, pend, SMC_LLC_WAIT_TIME);
622+
rc = smc_wr_tx_send_wait(link, pend, SMC_LLC_WAIT_TIME);
623+
put_out:
624+
smc_wr_tx_link_put(link);
625+
return rc;
596626
}
597627

598628
/********************************* receive ***********************************/
@@ -672,9 +702,11 @@ static int smc_llc_add_link_cont(struct smc_link *link,
672702
struct smc_buf_desc *rmb;
673703
u8 n;
674704

705+
if (!smc_wr_tx_link_hold(link))
706+
return -ENOLINK;
675707
rc = smc_llc_add_pending_send(link, &wr_buf, &pend);
676708
if (rc)
677-
return rc;
709+
goto put_out;
678710
addc_llc = (struct smc_llc_msg_add_link_cont *)wr_buf;
679711
memset(addc_llc, 0, sizeof(*addc_llc));
680712

@@ -706,7 +738,10 @@ static int smc_llc_add_link_cont(struct smc_link *link,
706738
addc_llc->hd.length = sizeof(struct smc_llc_msg_add_link_cont);
707739
if (lgr->role == SMC_CLNT)
708740
addc_llc->hd.flags |= SMC_LLC_FLAG_RESP;
709-
return smc_wr_tx_send(link, pend);
741+
rc = smc_wr_tx_send(link, pend);
742+
put_out:
743+
smc_wr_tx_link_put(link);
744+
return rc;
710745
}
711746

712747
static int smc_llc_cli_rkey_exchange(struct smc_link *link,

‎net/smc/smc_tx.c‎

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ static int smc_tx_rdma_writes(struct smc_connection *conn,
479479
/* Wakeup sndbuf consumers from any context (IRQ or process)
480480
* since there is more data to transmit; usable snd_wnd as max transmit
481481
*/
482-
static int _smcr_tx_sndbuf_nonempty(struct smc_connection *conn)
482+
static int smcr_tx_sndbuf_nonempty(struct smc_connection *conn)
483483
{
484484
struct smc_cdc_producer_flags *pflags = &conn->local_tx_ctrl.prod_flags;
485485
struct smc_link *link = conn->lnk;
@@ -488,8 +488,11 @@ static int _smcr_tx_sndbuf_nonempty(struct smc_connection *conn)
488488
struct smc_wr_buf *wr_buf;
489489
int rc;
490490

491+
if (!link || !smc_wr_tx_link_hold(link))
492+
return -ENOLINK;
491493
rc = smc_cdc_get_free_slot(conn, link, &wr_buf, &wr_rdma_buf, &pend);
492494
if (rc < 0) {
495+
smc_wr_tx_link_put(link);
493496
if (rc == -EBUSY) {
494497
struct smc_sock *smc =
495498
container_of(conn, struct smc_sock, conn);
@@ -530,22 +533,7 @@ static int _smcr_tx_sndbuf_nonempty(struct smc_connection *conn)
530533

531534
out_unlock:
532535
spin_unlock_bh(&conn->send_lock);
533-
return rc;
534-
}
535-
536-
static int smcr_tx_sndbuf_nonempty(struct smc_connection *conn)
537-
{
538-
struct smc_link *link = conn->lnk;
539-
int rc = -ENOLINK;
540-
541-
if (!link)
542-
return rc;
543-
544-
atomic_inc(&link->wr_tx_refcnt);
545-
if (smc_link_usable(link))
546-
rc = _smcr_tx_sndbuf_nonempty(conn);
547-
if (atomic_dec_and_test(&link->wr_tx_refcnt))
548-
wake_up_all(&link->wr_tx_wait);
536+
smc_wr_tx_link_put(link);
549537
return rc;
550538
}
551539

‎net/smc/smc_wr.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ static inline void smc_wr_tx_set_wr_id(atomic_long_t *wr_tx_id, long val)
6060
atomic_long_set(wr_tx_id, val);
6161
}
6262

63+
static inline bool smc_wr_tx_link_hold(struct smc_link *link)
64+
{
65+
if (!smc_link_usable(link))
66+
return false;
67+
atomic_inc(&link->wr_tx_refcnt);
68+
return true;
69+
}
70+
71+
static inline void smc_wr_tx_link_put(struct smc_link *link)
72+
{
73+
if (atomic_dec_and_test(&link->wr_tx_refcnt))
74+
wake_up_all(&link->wr_tx_wait);
75+
}
76+
6377
static inline void smc_wr_wakeup_tx_wait(struct smc_link *lnk)
6478
{
6579
wake_up_all(&lnk->wr_tx_wait);

0 commit comments

Comments
 (0)