Commit a463fa2c authored by David S. Miller's avatar David S. Miller

Merge branch 'net-smc-fixes'

Karsten Graul says:

====================
net/smc: fixes 2020-07-16

Please apply the following patch series for smc to netdev's net tree.

The patches address problems caused by late or unexpected link layer
control packets, dma sync calls for unmapped memory, freed buffers
that are not removed from the buffer list and a possible null pointer
access that results in a crash.

v1->v2: in patch 4, improve patch description and correct the comment
        for the new mutex
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 9b873778 1ad24058
...@@ -126,8 +126,10 @@ EXPORT_SYMBOL_GPL(smc_proto6); ...@@ -126,8 +126,10 @@ EXPORT_SYMBOL_GPL(smc_proto6);
static void smc_restore_fallback_changes(struct smc_sock *smc) static void smc_restore_fallback_changes(struct smc_sock *smc)
{ {
if (smc->clcsock->file) { /* non-accepted sockets have no file yet */
smc->clcsock->file->private_data = smc->sk.sk_socket; smc->clcsock->file->private_data = smc->sk.sk_socket;
smc->clcsock->file = NULL; smc->clcsock->file = NULL;
}
} }
static int __smc_release(struct smc_sock *smc) static int __smc_release(struct smc_sock *smc)
...@@ -352,7 +354,7 @@ static int smcr_lgr_reg_rmbs(struct smc_link *link, ...@@ -352,7 +354,7 @@ static int smcr_lgr_reg_rmbs(struct smc_link *link,
*/ */
mutex_lock(&lgr->llc_conf_mutex); mutex_lock(&lgr->llc_conf_mutex);
for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
if (lgr->lnk[i].state != SMC_LNK_ACTIVE) if (!smc_link_active(&lgr->lnk[i]))
continue; continue;
rc = smcr_link_reg_rmb(&lgr->lnk[i], rmb_desc); rc = smcr_link_reg_rmb(&lgr->lnk[i], rmb_desc);
if (rc) if (rc)
...@@ -632,7 +634,9 @@ static int smc_connect_rdma(struct smc_sock *smc, ...@@ -632,7 +634,9 @@ static int smc_connect_rdma(struct smc_sock *smc,
for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
struct smc_link *l = &smc->conn.lgr->lnk[i]; struct smc_link *l = &smc->conn.lgr->lnk[i];
if (l->peer_qpn == ntoh24(aclc->qpn)) { if (l->peer_qpn == ntoh24(aclc->qpn) &&
!memcmp(l->peer_gid, &aclc->lcl.gid, SMC_GID_SIZE) &&
!memcmp(l->peer_mac, &aclc->lcl.mac, sizeof(l->peer_mac))) {
link = l; link = l;
break; break;
} }
......
...@@ -45,18 +45,10 @@ static struct smc_lgr_list smc_lgr_list = { /* established link groups */ ...@@ -45,18 +45,10 @@ static struct smc_lgr_list smc_lgr_list = { /* established link groups */
static atomic_t lgr_cnt = ATOMIC_INIT(0); /* number of existing link groups */ static atomic_t lgr_cnt = ATOMIC_INIT(0); /* number of existing link groups */
static DECLARE_WAIT_QUEUE_HEAD(lgrs_deleted); static DECLARE_WAIT_QUEUE_HEAD(lgrs_deleted);
struct smc_ib_up_work {
struct work_struct work;
struct smc_link_group *lgr;
struct smc_ib_device *smcibdev;
u8 ibport;
};
static void smc_buf_free(struct smc_link_group *lgr, bool is_rmb, static void smc_buf_free(struct smc_link_group *lgr, bool is_rmb,
struct smc_buf_desc *buf_desc); struct smc_buf_desc *buf_desc);
static void __smc_lgr_terminate(struct smc_link_group *lgr, bool soft); static void __smc_lgr_terminate(struct smc_link_group *lgr, bool soft);
static void smc_link_up_work(struct work_struct *work);
static void smc_link_down_work(struct work_struct *work); static void smc_link_down_work(struct work_struct *work);
/* return head of link group list and its lock for a given link group */ /* return head of link group list and its lock for a given link group */
...@@ -326,7 +318,6 @@ int smcr_link_init(struct smc_link_group *lgr, struct smc_link *lnk, ...@@ -326,7 +318,6 @@ int smcr_link_init(struct smc_link_group *lgr, struct smc_link *lnk,
get_device(&ini->ib_dev->ibdev->dev); get_device(&ini->ib_dev->ibdev->dev);
atomic_inc(&ini->ib_dev->lnk_cnt); atomic_inc(&ini->ib_dev->lnk_cnt);
lnk->state = SMC_LNK_ACTIVATING;
lnk->link_id = smcr_next_link_id(lgr); lnk->link_id = smcr_next_link_id(lgr);
lnk->lgr = lgr; lnk->lgr = lgr;
lnk->link_idx = link_idx; lnk->link_idx = link_idx;
...@@ -362,6 +353,7 @@ int smcr_link_init(struct smc_link_group *lgr, struct smc_link *lnk, ...@@ -362,6 +353,7 @@ int smcr_link_init(struct smc_link_group *lgr, struct smc_link *lnk,
rc = smc_wr_create_link(lnk); rc = smc_wr_create_link(lnk);
if (rc) if (rc)
goto destroy_qp; goto destroy_qp;
lnk->state = SMC_LNK_ACTIVATING;
return 0; return 0;
destroy_qp: destroy_qp:
...@@ -550,8 +542,7 @@ struct smc_link *smc_switch_conns(struct smc_link_group *lgr, ...@@ -550,8 +542,7 @@ struct smc_link *smc_switch_conns(struct smc_link_group *lgr,
smc_wr_wakeup_tx_wait(from_lnk); smc_wr_wakeup_tx_wait(from_lnk);
for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
if (lgr->lnk[i].state != SMC_LNK_ACTIVE || if (!smc_link_active(&lgr->lnk[i]) || i == from_lnk->link_idx)
i == from_lnk->link_idx)
continue; continue;
if (is_dev_err && from_lnk->smcibdev == lgr->lnk[i].smcibdev && if (is_dev_err && from_lnk->smcibdev == lgr->lnk[i].smcibdev &&
from_lnk->ibport == lgr->lnk[i].ibport) { from_lnk->ibport == lgr->lnk[i].ibport) {
...@@ -1106,67 +1097,23 @@ static void smc_conn_abort_work(struct work_struct *work) ...@@ -1106,67 +1097,23 @@ static void smc_conn_abort_work(struct work_struct *work)
sock_put(&smc->sk); /* sock_hold done by schedulers of abort_work */ sock_put(&smc->sk); /* sock_hold done by schedulers of abort_work */
} }
/* link is up - establish alternate link if applicable */
static void smcr_link_up(struct smc_link_group *lgr,
struct smc_ib_device *smcibdev, u8 ibport)
{
struct smc_link *link = NULL;
if (list_empty(&lgr->list) ||
lgr->type == SMC_LGR_SYMMETRIC ||
lgr->type == SMC_LGR_ASYMMETRIC_PEER)
return;
if (lgr->role == SMC_SERV) {
/* trigger local add link processing */
link = smc_llc_usable_link(lgr);
if (!link)
return;
smc_llc_srv_add_link_local(link);
} else {
/* invite server to start add link processing */
u8 gid[SMC_GID_SIZE];
if (smc_ib_determine_gid(smcibdev, ibport, lgr->vlan_id, gid,
NULL))
return;
if (lgr->llc_flow_lcl.type != SMC_LLC_FLOW_NONE) {
/* some other llc task is ongoing */
wait_event_timeout(lgr->llc_flow_waiter,
(list_empty(&lgr->list) ||
lgr->llc_flow_lcl.type == SMC_LLC_FLOW_NONE),
SMC_LLC_WAIT_TIME);
}
/* lgr or device no longer active? */
if (!list_empty(&lgr->list) &&
smc_ib_port_active(smcibdev, ibport))
link = smc_llc_usable_link(lgr);
if (link)
smc_llc_send_add_link(link, smcibdev->mac[ibport - 1],
gid, NULL, SMC_LLC_REQ);
wake_up(&lgr->llc_flow_waiter); /* wake up next waiter */
}
}
void smcr_port_add(struct smc_ib_device *smcibdev, u8 ibport) void smcr_port_add(struct smc_ib_device *smcibdev, u8 ibport)
{ {
struct smc_ib_up_work *ib_work;
struct smc_link_group *lgr, *n; struct smc_link_group *lgr, *n;
list_for_each_entry_safe(lgr, n, &smc_lgr_list.list, list) { list_for_each_entry_safe(lgr, n, &smc_lgr_list.list, list) {
struct smc_link *link;
if (strncmp(smcibdev->pnetid[ibport - 1], lgr->pnet_id, if (strncmp(smcibdev->pnetid[ibport - 1], lgr->pnet_id,
SMC_MAX_PNETID_LEN) || SMC_MAX_PNETID_LEN) ||
lgr->type == SMC_LGR_SYMMETRIC || lgr->type == SMC_LGR_SYMMETRIC ||
lgr->type == SMC_LGR_ASYMMETRIC_PEER) lgr->type == SMC_LGR_ASYMMETRIC_PEER)
continue; continue;
ib_work = kmalloc(sizeof(*ib_work), GFP_KERNEL);
if (!ib_work) /* trigger local add link processing */
continue; link = smc_llc_usable_link(lgr);
INIT_WORK(&ib_work->work, smc_link_up_work); if (link)
ib_work->lgr = lgr; smc_llc_add_link_local(link);
ib_work->smcibdev = smcibdev;
ib_work->ibport = ibport;
schedule_work(&ib_work->work);
} }
} }
...@@ -1204,10 +1151,12 @@ static void smcr_link_down(struct smc_link *lnk) ...@@ -1204,10 +1151,12 @@ static void smcr_link_down(struct smc_link *lnk)
SMC_LLC_WAIT_TIME); SMC_LLC_WAIT_TIME);
mutex_lock(&lgr->llc_conf_mutex); mutex_lock(&lgr->llc_conf_mutex);
} }
if (!list_empty(&lgr->list)) if (!list_empty(&lgr->list)) {
smc_llc_send_delete_link(to_lnk, del_link_id, smc_llc_send_delete_link(to_lnk, del_link_id,
SMC_LLC_REQ, true, SMC_LLC_REQ, true,
SMC_LLC_DEL_LOST_PATH); SMC_LLC_DEL_LOST_PATH);
smcr_link_clear(lnk, true);
}
wake_up(&lgr->llc_flow_waiter); /* wake up next waiter */ wake_up(&lgr->llc_flow_waiter); /* wake up next waiter */
} }
} }
...@@ -1247,20 +1196,6 @@ void smcr_port_err(struct smc_ib_device *smcibdev, u8 ibport) ...@@ -1247,20 +1196,6 @@ void smcr_port_err(struct smc_ib_device *smcibdev, u8 ibport)
} }
} }
static void smc_link_up_work(struct work_struct *work)
{
struct smc_ib_up_work *ib_work = container_of(work,
struct smc_ib_up_work,
work);
struct smc_link_group *lgr = ib_work->lgr;
if (list_empty(&lgr->list))
goto out;
smcr_link_up(lgr, ib_work->smcibdev, ib_work->ibport);
out:
kfree(ib_work);
}
static void smc_link_down_work(struct work_struct *work) static void smc_link_down_work(struct work_struct *work)
{ {
struct smc_link *link = container_of(work, struct smc_link, struct smc_link *link = container_of(work, struct smc_link,
...@@ -1333,7 +1268,7 @@ static bool smcr_lgr_match(struct smc_link_group *lgr, ...@@ -1333,7 +1268,7 @@ static bool smcr_lgr_match(struct smc_link_group *lgr,
return false; return false;
for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
if (lgr->lnk[i].state != SMC_LNK_ACTIVE) if (!smc_link_active(&lgr->lnk[i]))
continue; continue;
if ((lgr->role == SMC_SERV || lgr->lnk[i].peer_qpn == clcqpn) && if ((lgr->role == SMC_SERV || lgr->lnk[i].peer_qpn == clcqpn) &&
!memcmp(lgr->lnk[i].peer_gid, &lcl->gid, SMC_GID_SIZE) && !memcmp(lgr->lnk[i].peer_gid, &lcl->gid, SMC_GID_SIZE) &&
...@@ -1781,14 +1716,14 @@ static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb) ...@@ -1781,14 +1716,14 @@ static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb)
void smc_sndbuf_sync_sg_for_cpu(struct smc_connection *conn) void smc_sndbuf_sync_sg_for_cpu(struct smc_connection *conn)
{ {
if (!conn->lgr || conn->lgr->is_smcd || !smc_link_usable(conn->lnk)) if (!conn->lgr || conn->lgr->is_smcd || !smc_link_active(conn->lnk))
return; return;
smc_ib_sync_sg_for_cpu(conn->lnk, conn->sndbuf_desc, DMA_TO_DEVICE); smc_ib_sync_sg_for_cpu(conn->lnk, conn->sndbuf_desc, DMA_TO_DEVICE);
} }
void smc_sndbuf_sync_sg_for_device(struct smc_connection *conn) void smc_sndbuf_sync_sg_for_device(struct smc_connection *conn)
{ {
if (!conn->lgr || conn->lgr->is_smcd || !smc_link_usable(conn->lnk)) if (!conn->lgr || conn->lgr->is_smcd || !smc_link_active(conn->lnk))
return; return;
smc_ib_sync_sg_for_device(conn->lnk, conn->sndbuf_desc, DMA_TO_DEVICE); smc_ib_sync_sg_for_device(conn->lnk, conn->sndbuf_desc, DMA_TO_DEVICE);
} }
...@@ -1800,7 +1735,7 @@ void smc_rmb_sync_sg_for_cpu(struct smc_connection *conn) ...@@ -1800,7 +1735,7 @@ void smc_rmb_sync_sg_for_cpu(struct smc_connection *conn)
if (!conn->lgr || conn->lgr->is_smcd) if (!conn->lgr || conn->lgr->is_smcd)
return; return;
for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
if (!smc_link_usable(&conn->lgr->lnk[i])) if (!smc_link_active(&conn->lgr->lnk[i]))
continue; continue;
smc_ib_sync_sg_for_cpu(&conn->lgr->lnk[i], conn->rmb_desc, smc_ib_sync_sg_for_cpu(&conn->lgr->lnk[i], conn->rmb_desc,
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
...@@ -1814,7 +1749,7 @@ void smc_rmb_sync_sg_for_device(struct smc_connection *conn) ...@@ -1814,7 +1749,7 @@ void smc_rmb_sync_sg_for_device(struct smc_connection *conn)
if (!conn->lgr || conn->lgr->is_smcd) if (!conn->lgr || conn->lgr->is_smcd)
return; return;
for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
if (!smc_link_usable(&conn->lgr->lnk[i])) if (!smc_link_active(&conn->lgr->lnk[i]))
continue; continue;
smc_ib_sync_sg_for_device(&conn->lgr->lnk[i], conn->rmb_desc, smc_ib_sync_sg_for_device(&conn->lgr->lnk[i], conn->rmb_desc,
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
...@@ -1837,8 +1772,12 @@ int smc_buf_create(struct smc_sock *smc, bool is_smcd) ...@@ -1837,8 +1772,12 @@ int smc_buf_create(struct smc_sock *smc, bool is_smcd)
return rc; return rc;
/* create rmb */ /* create rmb */
rc = __smc_buf_create(smc, is_smcd, true); rc = __smc_buf_create(smc, is_smcd, true);
if (rc) if (rc) {
mutex_lock(&smc->conn.lgr->sndbufs_lock);
list_del(&smc->conn.sndbuf_desc->list);
mutex_unlock(&smc->conn.lgr->sndbufs_lock);
smc_buf_free(smc->conn.lgr, false, smc->conn.sndbuf_desc); smc_buf_free(smc->conn.lgr, false, smc->conn.sndbuf_desc);
}
return rc; return rc;
} }
......
...@@ -349,6 +349,11 @@ static inline bool smc_link_usable(struct smc_link *lnk) ...@@ -349,6 +349,11 @@ static inline bool smc_link_usable(struct smc_link *lnk)
return true; return true;
} }
static inline bool smc_link_active(struct smc_link *lnk)
{
return lnk->state == SMC_LNK_ACTIVE;
}
struct smc_sock; struct smc_sock;
struct smc_clc_msg_accept_confirm; struct smc_clc_msg_accept_confirm;
struct smc_clc_msg_local; struct smc_clc_msg_local;
......
...@@ -506,6 +506,10 @@ long smc_ib_setup_per_ibdev(struct smc_ib_device *smcibdev) ...@@ -506,6 +506,10 @@ long smc_ib_setup_per_ibdev(struct smc_ib_device *smcibdev)
int cqe_size_order, smc_order; int cqe_size_order, smc_order;
long rc; long rc;
mutex_lock(&smcibdev->mutex);
rc = 0;
if (smcibdev->initialized)
goto out;
/* the calculated number of cq entries fits to mlx5 cq allocation */ /* the calculated number of cq entries fits to mlx5 cq allocation */
cqe_size_order = cache_line_size() == 128 ? 7 : 6; cqe_size_order = cache_line_size() == 128 ? 7 : 6;
smc_order = MAX_ORDER - cqe_size_order - 1; smc_order = MAX_ORDER - cqe_size_order - 1;
...@@ -517,7 +521,7 @@ long smc_ib_setup_per_ibdev(struct smc_ib_device *smcibdev) ...@@ -517,7 +521,7 @@ long smc_ib_setup_per_ibdev(struct smc_ib_device *smcibdev)
rc = PTR_ERR_OR_ZERO(smcibdev->roce_cq_send); rc = PTR_ERR_OR_ZERO(smcibdev->roce_cq_send);
if (IS_ERR(smcibdev->roce_cq_send)) { if (IS_ERR(smcibdev->roce_cq_send)) {
smcibdev->roce_cq_send = NULL; smcibdev->roce_cq_send = NULL;
return rc; goto out;
} }
smcibdev->roce_cq_recv = ib_create_cq(smcibdev->ibdev, smcibdev->roce_cq_recv = ib_create_cq(smcibdev->ibdev,
smc_wr_rx_cq_handler, NULL, smc_wr_rx_cq_handler, NULL,
...@@ -529,21 +533,26 @@ long smc_ib_setup_per_ibdev(struct smc_ib_device *smcibdev) ...@@ -529,21 +533,26 @@ long smc_ib_setup_per_ibdev(struct smc_ib_device *smcibdev)
} }
smc_wr_add_dev(smcibdev); smc_wr_add_dev(smcibdev);
smcibdev->initialized = 1; smcibdev->initialized = 1;
return rc; goto out;
err: err:
ib_destroy_cq(smcibdev->roce_cq_send); ib_destroy_cq(smcibdev->roce_cq_send);
out:
mutex_unlock(&smcibdev->mutex);
return rc; return rc;
} }
static void smc_ib_cleanup_per_ibdev(struct smc_ib_device *smcibdev) static void smc_ib_cleanup_per_ibdev(struct smc_ib_device *smcibdev)
{ {
mutex_lock(&smcibdev->mutex);
if (!smcibdev->initialized) if (!smcibdev->initialized)
return; goto out;
smcibdev->initialized = 0; smcibdev->initialized = 0;
ib_destroy_cq(smcibdev->roce_cq_recv); ib_destroy_cq(smcibdev->roce_cq_recv);
ib_destroy_cq(smcibdev->roce_cq_send); ib_destroy_cq(smcibdev->roce_cq_send);
smc_wr_remove_dev(smcibdev); smc_wr_remove_dev(smcibdev);
out:
mutex_unlock(&smcibdev->mutex);
} }
static struct ib_client smc_ib_client; static struct ib_client smc_ib_client;
...@@ -566,6 +575,7 @@ static int smc_ib_add_dev(struct ib_device *ibdev) ...@@ -566,6 +575,7 @@ static int smc_ib_add_dev(struct ib_device *ibdev)
INIT_WORK(&smcibdev->port_event_work, smc_ib_port_event_work); INIT_WORK(&smcibdev->port_event_work, smc_ib_port_event_work);
atomic_set(&smcibdev->lnk_cnt, 0); atomic_set(&smcibdev->lnk_cnt, 0);
init_waitqueue_head(&smcibdev->lnks_deleted); init_waitqueue_head(&smcibdev->lnks_deleted);
mutex_init(&smcibdev->mutex);
mutex_lock(&smc_ib_devices.mutex); mutex_lock(&smc_ib_devices.mutex);
list_add_tail(&smcibdev->list, &smc_ib_devices.list); list_add_tail(&smcibdev->list, &smc_ib_devices.list);
mutex_unlock(&smc_ib_devices.mutex); mutex_unlock(&smc_ib_devices.mutex);
......
...@@ -52,6 +52,7 @@ struct smc_ib_device { /* ib-device infos for smc */ ...@@ -52,6 +52,7 @@ struct smc_ib_device { /* ib-device infos for smc */
DECLARE_BITMAP(ports_going_away, SMC_MAX_PORTS); DECLARE_BITMAP(ports_going_away, SMC_MAX_PORTS);
atomic_t lnk_cnt; /* number of links on ibdev */ atomic_t lnk_cnt; /* number of links on ibdev */
wait_queue_head_t lnks_deleted; /* wait 4 removal of all links*/ wait_queue_head_t lnks_deleted; /* wait 4 removal of all links*/
struct mutex mutex; /* protect dev setup+cleanup */
}; };
struct smc_buf_desc; struct smc_buf_desc;
......
...@@ -428,7 +428,7 @@ static int smc_llc_send_confirm_rkey(struct smc_link *send_link, ...@@ -428,7 +428,7 @@ static int smc_llc_send_confirm_rkey(struct smc_link *send_link,
rtok_ix = 1; rtok_ix = 1;
for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
link = &send_link->lgr->lnk[i]; link = &send_link->lgr->lnk[i];
if (link->state == SMC_LNK_ACTIVE && link != send_link) { if (smc_link_active(link) && link != send_link) {
rkeyllc->rtoken[rtok_ix].link_id = link->link_id; rkeyllc->rtoken[rtok_ix].link_id = link->link_id;
rkeyllc->rtoken[rtok_ix].rmb_key = rkeyllc->rtoken[rtok_ix].rmb_key =
htonl(rmb_desc->mr_rx[link->link_idx]->rkey); htonl(rmb_desc->mr_rx[link->link_idx]->rkey);
...@@ -895,6 +895,36 @@ int smc_llc_cli_add_link(struct smc_link *link, struct smc_llc_qentry *qentry) ...@@ -895,6 +895,36 @@ int smc_llc_cli_add_link(struct smc_link *link, struct smc_llc_qentry *qentry)
return rc; return rc;
} }
/* as an SMC client, invite server to start the add_link processing */
static void smc_llc_cli_add_link_invite(struct smc_link *link,
struct smc_llc_qentry *qentry)
{
struct smc_link_group *lgr = smc_get_lgr(link);
struct smc_init_info ini;
if (lgr->type == SMC_LGR_SYMMETRIC ||
lgr->type == SMC_LGR_ASYMMETRIC_PEER)
goto out;
ini.vlan_id = lgr->vlan_id;
smc_pnet_find_alt_roce(lgr, &ini, link->smcibdev);
if (!ini.ib_dev)
goto out;
smc_llc_send_add_link(link, ini.ib_dev->mac[ini.ib_port - 1],
ini.ib_gid, NULL, SMC_LLC_REQ);
out:
kfree(qentry);
}
static bool smc_llc_is_local_add_link(union smc_llc_msg *llc)
{
if (llc->raw.hdr.common.type == SMC_LLC_ADD_LINK &&
!llc->add_link.qp_mtu && !llc->add_link.link_num)
return true;
return false;
}
static void smc_llc_process_cli_add_link(struct smc_link_group *lgr) static void smc_llc_process_cli_add_link(struct smc_link_group *lgr)
{ {
struct smc_llc_qentry *qentry; struct smc_llc_qentry *qentry;
...@@ -902,6 +932,9 @@ static void smc_llc_process_cli_add_link(struct smc_link_group *lgr) ...@@ -902,6 +932,9 @@ static void smc_llc_process_cli_add_link(struct smc_link_group *lgr)
qentry = smc_llc_flow_qentry_clr(&lgr->llc_flow_lcl); qentry = smc_llc_flow_qentry_clr(&lgr->llc_flow_lcl);
mutex_lock(&lgr->llc_conf_mutex); mutex_lock(&lgr->llc_conf_mutex);
if (smc_llc_is_local_add_link(&qentry->msg))
smc_llc_cli_add_link_invite(qentry->link, qentry);
else
smc_llc_cli_add_link(qentry->link, qentry); smc_llc_cli_add_link(qentry->link, qentry);
mutex_unlock(&lgr->llc_conf_mutex); mutex_unlock(&lgr->llc_conf_mutex);
} }
...@@ -911,7 +944,7 @@ static int smc_llc_active_link_count(struct smc_link_group *lgr) ...@@ -911,7 +944,7 @@ static int smc_llc_active_link_count(struct smc_link_group *lgr)
int i, link_count = 0; int i, link_count = 0;
for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
if (!smc_link_usable(&lgr->lnk[i])) if (!smc_link_active(&lgr->lnk[i]))
continue; continue;
link_count++; link_count++;
} }
...@@ -1051,12 +1084,14 @@ static int smc_llc_srv_conf_link(struct smc_link *link, ...@@ -1051,12 +1084,14 @@ static int smc_llc_srv_conf_link(struct smc_link *link,
if (rc) if (rc)
return -ENOLINK; return -ENOLINK;
/* receive CONFIRM LINK response over the RoCE fabric */ /* receive CONFIRM LINK response over the RoCE fabric */
qentry = smc_llc_wait(lgr, link, SMC_LLC_WAIT_FIRST_TIME, qentry = smc_llc_wait(lgr, link, SMC_LLC_WAIT_FIRST_TIME, 0);
SMC_LLC_CONFIRM_LINK); if (!qentry ||
if (!qentry) { qentry->msg.raw.hdr.common.type != SMC_LLC_CONFIRM_LINK) {
/* send DELETE LINK */ /* send DELETE LINK */
smc_llc_send_delete_link(link, link_new->link_id, SMC_LLC_REQ, smc_llc_send_delete_link(link, link_new->link_id, SMC_LLC_REQ,
false, SMC_LLC_DEL_LOST_PATH); false, SMC_LLC_DEL_LOST_PATH);
if (qentry)
smc_llc_flow_qentry_del(&lgr->llc_flow_lcl);
return -ENOLINK; return -ENOLINK;
} }
smc_llc_save_peer_uid(qentry); smc_llc_save_peer_uid(qentry);
...@@ -1158,14 +1193,14 @@ static void smc_llc_process_srv_add_link(struct smc_link_group *lgr) ...@@ -1158,14 +1193,14 @@ static void smc_llc_process_srv_add_link(struct smc_link_group *lgr)
mutex_unlock(&lgr->llc_conf_mutex); mutex_unlock(&lgr->llc_conf_mutex);
} }
/* enqueue a local add_link req to trigger a new add_link flow, only as SERV */ /* enqueue a local add_link req to trigger a new add_link flow */
void smc_llc_srv_add_link_local(struct smc_link *link) void smc_llc_add_link_local(struct smc_link *link)
{ {
struct smc_llc_msg_add_link add_llc = {0}; struct smc_llc_msg_add_link add_llc = {0};
add_llc.hd.length = sizeof(add_llc); add_llc.hd.length = sizeof(add_llc);
add_llc.hd.common.type = SMC_LLC_ADD_LINK; add_llc.hd.common.type = SMC_LLC_ADD_LINK;
/* no dev and port needed, we as server ignore client data anyway */ /* no dev and port needed */
smc_llc_enqueue(link, (union smc_llc_msg *)&add_llc); smc_llc_enqueue(link, (union smc_llc_msg *)&add_llc);
} }
...@@ -1345,7 +1380,7 @@ static void smc_llc_process_srv_delete_link(struct smc_link_group *lgr) ...@@ -1345,7 +1380,7 @@ static void smc_llc_process_srv_delete_link(struct smc_link_group *lgr)
if (lgr->type == SMC_LGR_SINGLE && !list_empty(&lgr->list)) { if (lgr->type == SMC_LGR_SINGLE && !list_empty(&lgr->list)) {
/* trigger setup of asymm alt link */ /* trigger setup of asymm alt link */
smc_llc_srv_add_link_local(lnk); smc_llc_add_link_local(lnk);
} }
out: out:
mutex_unlock(&lgr->llc_conf_mutex); mutex_unlock(&lgr->llc_conf_mutex);
...@@ -1474,7 +1509,18 @@ static void smc_llc_event_handler(struct smc_llc_qentry *qentry) ...@@ -1474,7 +1509,18 @@ static void smc_llc_event_handler(struct smc_llc_qentry *qentry)
if (list_empty(&lgr->list)) if (list_empty(&lgr->list))
goto out; /* lgr is terminating */ goto out; /* lgr is terminating */
if (lgr->role == SMC_CLNT) { if (lgr->role == SMC_CLNT) {
if (lgr->llc_flow_lcl.type == SMC_LLC_FLOW_ADD_LINK) { if (smc_llc_is_local_add_link(llc)) {
if (lgr->llc_flow_lcl.type ==
SMC_LLC_FLOW_ADD_LINK)
break; /* add_link in progress */
if (smc_llc_flow_start(&lgr->llc_flow_lcl,
qentry)) {
schedule_work(&lgr->llc_add_link_work);
}
return;
}
if (lgr->llc_flow_lcl.type == SMC_LLC_FLOW_ADD_LINK &&
!lgr->llc_flow_lcl.qentry) {
/* a flow is waiting for this message */ /* a flow is waiting for this message */
smc_llc_flow_qentry_set(&lgr->llc_flow_lcl, smc_llc_flow_qentry_set(&lgr->llc_flow_lcl,
qentry); qentry);
...@@ -1498,29 +1544,14 @@ static void smc_llc_event_handler(struct smc_llc_qentry *qentry) ...@@ -1498,29 +1544,14 @@ static void smc_llc_event_handler(struct smc_llc_qentry *qentry)
} }
break; break;
case SMC_LLC_DELETE_LINK: case SMC_LLC_DELETE_LINK:
if (lgr->role == SMC_CLNT) {
/* server requests to delete this link, send response */
if (lgr->llc_flow_lcl.type != SMC_LLC_FLOW_NONE) {
/* DEL LINK REQ during ADD LINK SEQ */
smc_llc_flow_qentry_set(&lgr->llc_flow_lcl,
qentry);
wake_up(&lgr->llc_msg_waiter);
} else if (smc_llc_flow_start(&lgr->llc_flow_lcl,
qentry)) {
schedule_work(&lgr->llc_del_link_work);
}
} else {
if (lgr->llc_flow_lcl.type == SMC_LLC_FLOW_ADD_LINK && if (lgr->llc_flow_lcl.type == SMC_LLC_FLOW_ADD_LINK &&
!lgr->llc_flow_lcl.qentry) { !lgr->llc_flow_lcl.qentry) {
/* DEL LINK REQ during ADD LINK SEQ */ /* DEL LINK REQ during ADD LINK SEQ */
smc_llc_flow_qentry_set(&lgr->llc_flow_lcl, smc_llc_flow_qentry_set(&lgr->llc_flow_lcl, qentry);
qentry);
wake_up(&lgr->llc_msg_waiter); wake_up(&lgr->llc_msg_waiter);
} else if (smc_llc_flow_start(&lgr->llc_flow_lcl, } else if (smc_llc_flow_start(&lgr->llc_flow_lcl, qentry)) {
qentry)) {
schedule_work(&lgr->llc_del_link_work); schedule_work(&lgr->llc_del_link_work);
} }
}
return; return;
case SMC_LLC_CONFIRM_RKEY: case SMC_LLC_CONFIRM_RKEY:
/* new request from remote, assign to remote flow */ /* new request from remote, assign to remote flow */
...@@ -1585,23 +1616,30 @@ static void smc_llc_event_work(struct work_struct *work) ...@@ -1585,23 +1616,30 @@ static void smc_llc_event_work(struct work_struct *work)
static void smc_llc_rx_response(struct smc_link *link, static void smc_llc_rx_response(struct smc_link *link,
struct smc_llc_qentry *qentry) struct smc_llc_qentry *qentry)
{ {
enum smc_llc_flowtype flowtype = link->lgr->llc_flow_lcl.type;
struct smc_llc_flow *flow = &link->lgr->llc_flow_lcl;
u8 llc_type = qentry->msg.raw.hdr.common.type; u8 llc_type = qentry->msg.raw.hdr.common.type;
switch (llc_type) { switch (llc_type) {
case SMC_LLC_TEST_LINK: case SMC_LLC_TEST_LINK:
if (link->state == SMC_LNK_ACTIVE) if (smc_link_active(link))
complete(&link->llc_testlink_resp); complete(&link->llc_testlink_resp);
break; break;
case SMC_LLC_ADD_LINK: case SMC_LLC_ADD_LINK:
case SMC_LLC_DELETE_LINK:
case SMC_LLC_CONFIRM_LINK:
case SMC_LLC_ADD_LINK_CONT: case SMC_LLC_ADD_LINK_CONT:
case SMC_LLC_CONFIRM_LINK:
if (flowtype != SMC_LLC_FLOW_ADD_LINK || flow->qentry)
break; /* drop out-of-flow response */
goto assign;
case SMC_LLC_DELETE_LINK:
if (flowtype != SMC_LLC_FLOW_DEL_LINK || flow->qentry)
break; /* drop out-of-flow response */
goto assign;
case SMC_LLC_CONFIRM_RKEY: case SMC_LLC_CONFIRM_RKEY:
case SMC_LLC_DELETE_RKEY: case SMC_LLC_DELETE_RKEY:
/* assign responses to the local flow, we requested them */ if (flowtype != SMC_LLC_FLOW_RKEY || flow->qentry)
smc_llc_flow_qentry_set(&link->lgr->llc_flow_lcl, qentry); break; /* drop out-of-flow response */
wake_up(&link->lgr->llc_msg_waiter); goto assign;
return;
case SMC_LLC_CONFIRM_RKEY_CONT: case SMC_LLC_CONFIRM_RKEY_CONT:
/* not used because max links is 3 */ /* not used because max links is 3 */
break; break;
...@@ -1610,6 +1648,11 @@ static void smc_llc_rx_response(struct smc_link *link, ...@@ -1610,6 +1648,11 @@ static void smc_llc_rx_response(struct smc_link *link,
break; break;
} }
kfree(qentry); kfree(qentry);
return;
assign:
/* assign responses to the local flow, we requested them */
smc_llc_flow_qentry_set(&link->lgr->llc_flow_lcl, qentry);
wake_up(&link->lgr->llc_msg_waiter);
} }
static void smc_llc_enqueue(struct smc_link *link, union smc_llc_msg *llc) static void smc_llc_enqueue(struct smc_link *link, union smc_llc_msg *llc)
...@@ -1663,7 +1706,7 @@ static void smc_llc_testlink_work(struct work_struct *work) ...@@ -1663,7 +1706,7 @@ static void smc_llc_testlink_work(struct work_struct *work)
u8 user_data[16] = { 0 }; u8 user_data[16] = { 0 };
int rc; int rc;
if (link->state != SMC_LNK_ACTIVE) if (!smc_link_active(link))
return; /* don't reschedule worker */ return; /* don't reschedule worker */
expire_time = link->wr_rx_tstamp + link->llc_testlink_time; expire_time = link->wr_rx_tstamp + link->llc_testlink_time;
if (time_is_after_jiffies(expire_time)) { if (time_is_after_jiffies(expire_time)) {
...@@ -1675,7 +1718,7 @@ static void smc_llc_testlink_work(struct work_struct *work) ...@@ -1675,7 +1718,7 @@ static void smc_llc_testlink_work(struct work_struct *work)
/* receive TEST LINK response over RoCE fabric */ /* receive TEST LINK response over RoCE fabric */
rc = wait_for_completion_interruptible_timeout(&link->llc_testlink_resp, rc = wait_for_completion_interruptible_timeout(&link->llc_testlink_resp,
SMC_LLC_WAIT_TIME); SMC_LLC_WAIT_TIME);
if (link->state != SMC_LNK_ACTIVE) if (!smc_link_active(link))
return; /* link state changed */ return; /* link state changed */
if (rc <= 0) { if (rc <= 0) {
smcr_link_down_cond_sched(link); smcr_link_down_cond_sched(link);
......
...@@ -103,7 +103,7 @@ void smc_llc_send_link_delete_all(struct smc_link_group *lgr, bool ord, ...@@ -103,7 +103,7 @@ void smc_llc_send_link_delete_all(struct smc_link_group *lgr, bool ord,
u32 rsn); u32 rsn);
int smc_llc_cli_add_link(struct smc_link *link, struct smc_llc_qentry *qentry); int smc_llc_cli_add_link(struct smc_link *link, struct smc_llc_qentry *qentry);
int smc_llc_srv_add_link(struct smc_link *link); int smc_llc_srv_add_link(struct smc_link *link);
void smc_llc_srv_add_link_local(struct smc_link *link); void smc_llc_add_link_local(struct smc_link *link);
int smc_llc_init(void) __init; int smc_llc_init(void) __init;
#endif /* SMC_LLC_H */ #endif /* SMC_LLC_H */
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