Commit 605bb443 authored by David S. Miller's avatar David S. Miller

Merge branch 'smc-fixes'

Guvenc Gulce says:

====================
net/smc: fixes 2021-08-09

please apply the following patch series for smc to netdev's net tree.
One patch fixes invalid connection counting for links and the other
one fixes an access to an already cleared link.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents acc68b8d 64513d26
...@@ -795,7 +795,7 @@ static int smc_connect_rdma(struct smc_sock *smc, ...@@ -795,7 +795,7 @@ static int smc_connect_rdma(struct smc_sock *smc,
reason_code = SMC_CLC_DECL_NOSRVLINK; reason_code = SMC_CLC_DECL_NOSRVLINK;
goto connect_abort; goto connect_abort;
} }
smc->conn.lnk = link; smc_switch_link_and_count(&smc->conn, link);
} }
/* create send buffer and rmb */ /* create send buffer and rmb */
......
...@@ -917,8 +917,8 @@ static int smc_switch_cursor(struct smc_sock *smc, struct smc_cdc_tx_pend *pend, ...@@ -917,8 +917,8 @@ static int smc_switch_cursor(struct smc_sock *smc, struct smc_cdc_tx_pend *pend,
return rc; return rc;
} }
static void smc_switch_link_and_count(struct smc_connection *conn, void smc_switch_link_and_count(struct smc_connection *conn,
struct smc_link *to_lnk) struct smc_link *to_lnk)
{ {
atomic_dec(&conn->lnk->conn_cnt); atomic_dec(&conn->lnk->conn_cnt);
conn->lnk = to_lnk; conn->lnk = to_lnk;
......
...@@ -97,6 +97,7 @@ struct smc_link { ...@@ -97,6 +97,7 @@ struct smc_link {
unsigned long *wr_tx_mask; /* bit mask of used indexes */ unsigned long *wr_tx_mask; /* bit mask of used indexes */
u32 wr_tx_cnt; /* number of WR send buffers */ u32 wr_tx_cnt; /* number of WR send buffers */
wait_queue_head_t wr_tx_wait; /* wait for free WR send buf */ wait_queue_head_t wr_tx_wait; /* wait for free WR send buf */
atomic_t wr_tx_refcnt; /* tx refs to link */
struct smc_wr_buf *wr_rx_bufs; /* WR recv payload buffers */ struct smc_wr_buf *wr_rx_bufs; /* WR recv payload buffers */
struct ib_recv_wr *wr_rx_ibs; /* WR recv meta data */ struct ib_recv_wr *wr_rx_ibs; /* WR recv meta data */
...@@ -109,6 +110,7 @@ struct smc_link { ...@@ -109,6 +110,7 @@ struct smc_link {
struct ib_reg_wr wr_reg; /* WR register memory region */ struct ib_reg_wr wr_reg; /* WR register memory region */
wait_queue_head_t wr_reg_wait; /* wait for wr_reg result */ wait_queue_head_t wr_reg_wait; /* wait for wr_reg result */
atomic_t wr_reg_refcnt; /* reg refs to link */
enum smc_wr_reg_state wr_reg_state; /* state of wr_reg request */ enum smc_wr_reg_state wr_reg_state; /* state of wr_reg request */
u8 gid[SMC_GID_SIZE];/* gid matching used vlan id*/ u8 gid[SMC_GID_SIZE];/* gid matching used vlan id*/
...@@ -444,6 +446,8 @@ void smc_core_exit(void); ...@@ -444,6 +446,8 @@ void smc_core_exit(void);
int smcr_link_init(struct smc_link_group *lgr, struct smc_link *lnk, int smcr_link_init(struct smc_link_group *lgr, struct smc_link *lnk,
u8 link_idx, struct smc_init_info *ini); u8 link_idx, struct smc_init_info *ini);
void smcr_link_clear(struct smc_link *lnk, bool log); void smcr_link_clear(struct smc_link *lnk, bool log);
void smc_switch_link_and_count(struct smc_connection *conn,
struct smc_link *to_lnk);
int smcr_buf_map_lgr(struct smc_link *lnk); int smcr_buf_map_lgr(struct smc_link *lnk);
int smcr_buf_reg_lgr(struct smc_link *lnk); int smcr_buf_reg_lgr(struct smc_link *lnk);
void smcr_lgr_set_type(struct smc_link_group *lgr, enum smc_lgr_type new_type); void smcr_lgr_set_type(struct smc_link_group *lgr, enum smc_lgr_type new_type);
......
...@@ -888,6 +888,7 @@ int smc_llc_cli_add_link(struct smc_link *link, struct smc_llc_qentry *qentry) ...@@ -888,6 +888,7 @@ int smc_llc_cli_add_link(struct smc_link *link, struct smc_llc_qentry *qentry)
if (!rc) if (!rc)
goto out; goto out;
out_clear_lnk: out_clear_lnk:
lnk_new->state = SMC_LNK_INACTIVE;
smcr_link_clear(lnk_new, false); smcr_link_clear(lnk_new, false);
out_reject: out_reject:
smc_llc_cli_add_link_reject(qentry); smc_llc_cli_add_link_reject(qentry);
...@@ -1184,6 +1185,7 @@ int smc_llc_srv_add_link(struct smc_link *link) ...@@ -1184,6 +1185,7 @@ int smc_llc_srv_add_link(struct smc_link *link)
goto out_err; goto out_err;
return 0; return 0;
out_err: out_err:
link_new->state = SMC_LNK_INACTIVE;
smcr_link_clear(link_new, false); smcr_link_clear(link_new, false);
return rc; return rc;
} }
...@@ -1286,10 +1288,8 @@ static void smc_llc_process_cli_delete_link(struct smc_link_group *lgr) ...@@ -1286,10 +1288,8 @@ static void smc_llc_process_cli_delete_link(struct smc_link_group *lgr)
del_llc->reason = 0; del_llc->reason = 0;
smc_llc_send_message(lnk, &qentry->msg); /* response */ smc_llc_send_message(lnk, &qentry->msg); /* response */
if (smc_link_downing(&lnk_del->state)) { if (smc_link_downing(&lnk_del->state))
if (smc_switch_conns(lgr, lnk_del, false)) smc_switch_conns(lgr, lnk_del, false);
smc_wr_tx_wait_no_pending_sends(lnk_del);
}
smcr_link_clear(lnk_del, true); smcr_link_clear(lnk_del, true);
active_links = smc_llc_active_link_count(lgr); active_links = smc_llc_active_link_count(lgr);
...@@ -1805,8 +1805,6 @@ void smc_llc_link_clear(struct smc_link *link, bool log) ...@@ -1805,8 +1805,6 @@ void smc_llc_link_clear(struct smc_link *link, bool log)
link->smcibdev->ibdev->name, link->ibport); link->smcibdev->ibdev->name, link->ibport);
complete(&link->llc_testlink_resp); complete(&link->llc_testlink_resp);
cancel_delayed_work_sync(&link->llc_testlink_wrk); cancel_delayed_work_sync(&link->llc_testlink_wrk);
smc_wr_wakeup_reg_wait(link);
smc_wr_wakeup_tx_wait(link);
} }
/* register a new rtoken at the remote peer (for all links) */ /* register a new rtoken at the remote peer (for all links) */
......
...@@ -496,7 +496,7 @@ static int smc_tx_rdma_writes(struct smc_connection *conn, ...@@ -496,7 +496,7 @@ static int smc_tx_rdma_writes(struct smc_connection *conn,
/* Wakeup sndbuf consumers from any context (IRQ or process) /* Wakeup sndbuf consumers from any context (IRQ or process)
* since there is more data to transmit; usable snd_wnd as max transmit * since there is more data to transmit; usable snd_wnd as max transmit
*/ */
static int smcr_tx_sndbuf_nonempty(struct smc_connection *conn) static int _smcr_tx_sndbuf_nonempty(struct smc_connection *conn)
{ {
struct smc_cdc_producer_flags *pflags = &conn->local_tx_ctrl.prod_flags; struct smc_cdc_producer_flags *pflags = &conn->local_tx_ctrl.prod_flags;
struct smc_link *link = conn->lnk; struct smc_link *link = conn->lnk;
...@@ -550,6 +550,22 @@ static int smcr_tx_sndbuf_nonempty(struct smc_connection *conn) ...@@ -550,6 +550,22 @@ static int smcr_tx_sndbuf_nonempty(struct smc_connection *conn)
return rc; return rc;
} }
static int smcr_tx_sndbuf_nonempty(struct smc_connection *conn)
{
struct smc_link *link = conn->lnk;
int rc = -ENOLINK;
if (!link)
return rc;
atomic_inc(&link->wr_tx_refcnt);
if (smc_link_usable(link))
rc = _smcr_tx_sndbuf_nonempty(conn);
if (atomic_dec_and_test(&link->wr_tx_refcnt))
wake_up_all(&link->wr_tx_wait);
return rc;
}
static int smcd_tx_sndbuf_nonempty(struct smc_connection *conn) static int smcd_tx_sndbuf_nonempty(struct smc_connection *conn)
{ {
struct smc_cdc_producer_flags *pflags = &conn->local_tx_ctrl.prod_flags; struct smc_cdc_producer_flags *pflags = &conn->local_tx_ctrl.prod_flags;
......
...@@ -322,9 +322,12 @@ int smc_wr_reg_send(struct smc_link *link, struct ib_mr *mr) ...@@ -322,9 +322,12 @@ int smc_wr_reg_send(struct smc_link *link, struct ib_mr *mr)
if (rc) if (rc)
return rc; return rc;
atomic_inc(&link->wr_reg_refcnt);
rc = wait_event_interruptible_timeout(link->wr_reg_wait, rc = wait_event_interruptible_timeout(link->wr_reg_wait,
(link->wr_reg_state != POSTED), (link->wr_reg_state != POSTED),
SMC_WR_REG_MR_WAIT_TIME); SMC_WR_REG_MR_WAIT_TIME);
if (atomic_dec_and_test(&link->wr_reg_refcnt))
wake_up_all(&link->wr_reg_wait);
if (!rc) { if (!rc) {
/* timeout - terminate link */ /* timeout - terminate link */
smcr_link_down_cond_sched(link); smcr_link_down_cond_sched(link);
...@@ -566,10 +569,15 @@ void smc_wr_free_link(struct smc_link *lnk) ...@@ -566,10 +569,15 @@ void smc_wr_free_link(struct smc_link *lnk)
return; return;
ibdev = lnk->smcibdev->ibdev; ibdev = lnk->smcibdev->ibdev;
smc_wr_wakeup_reg_wait(lnk);
smc_wr_wakeup_tx_wait(lnk);
if (smc_wr_tx_wait_no_pending_sends(lnk)) if (smc_wr_tx_wait_no_pending_sends(lnk))
memset(lnk->wr_tx_mask, 0, memset(lnk->wr_tx_mask, 0,
BITS_TO_LONGS(SMC_WR_BUF_CNT) * BITS_TO_LONGS(SMC_WR_BUF_CNT) *
sizeof(*lnk->wr_tx_mask)); sizeof(*lnk->wr_tx_mask));
wait_event(lnk->wr_reg_wait, (!atomic_read(&lnk->wr_reg_refcnt)));
wait_event(lnk->wr_tx_wait, (!atomic_read(&lnk->wr_tx_refcnt)));
if (lnk->wr_rx_dma_addr) { if (lnk->wr_rx_dma_addr) {
ib_dma_unmap_single(ibdev, lnk->wr_rx_dma_addr, ib_dma_unmap_single(ibdev, lnk->wr_rx_dma_addr,
...@@ -728,7 +736,9 @@ int smc_wr_create_link(struct smc_link *lnk) ...@@ -728,7 +736,9 @@ int smc_wr_create_link(struct smc_link *lnk)
memset(lnk->wr_tx_mask, 0, memset(lnk->wr_tx_mask, 0,
BITS_TO_LONGS(SMC_WR_BUF_CNT) * sizeof(*lnk->wr_tx_mask)); BITS_TO_LONGS(SMC_WR_BUF_CNT) * sizeof(*lnk->wr_tx_mask));
init_waitqueue_head(&lnk->wr_tx_wait); init_waitqueue_head(&lnk->wr_tx_wait);
atomic_set(&lnk->wr_tx_refcnt, 0);
init_waitqueue_head(&lnk->wr_reg_wait); init_waitqueue_head(&lnk->wr_reg_wait);
atomic_set(&lnk->wr_reg_refcnt, 0);
return rc; return rc;
dma_unmap: dma_unmap:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment