Commit 083bfdbf authored by Jason Gunthorpe's avatar Jason Gunthorpe

RDMA/cm: Make it clear that there is no concurrency in cm_sidr_req_handler()

ib_create_cm_id() immediately places the id in the xarray, so it is visible
to network traffic.

The state is initially set to IB_CM_IDLE and all the MAD handlers will
test this state under lock and refuse to advance from IDLE, so adding to
the xarray is harmless.

Further, the set to IB_CM_SIDR_REQ_RCVD also excludes all MAD handlers.

However, the local_id isn't even used for SIDR mode, and there will be no
input MADs related to the newly created ID.

So, make the whole flow simpler so it can be understood:
 - Do not put the SIDR cm_id in the xarray. This directly shows that there
   is no concurrency
 - Delete the confusing work_count and pending_list manipulations. This
   mechanism is only used by MAD handlers and timewait, neither of which
   apply to SIDR.
 - Add a few comments and rename 'cur_cm_id_priv' to 'listen_cm_id_priv'
 - Move other loose sets up to immediately after cm_id creation so that
   the cm_id is fully configured right away. This fixes an oversight where
   the service_id will not be returned back on a IB_SIDR_UNSUPPORTED
   reject.

Link: https://lore.kernel.org/r/20200310092545.251365-8-leon@kernel.orgSigned-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 153a2e43
...@@ -3535,20 +3535,27 @@ static void cm_format_sidr_req_event(struct cm_work *work, ...@@ -3535,20 +3535,27 @@ static void cm_format_sidr_req_event(struct cm_work *work,
static int cm_sidr_req_handler(struct cm_work *work) static int cm_sidr_req_handler(struct cm_work *work)
{ {
struct ib_cm_id *cm_id; struct cm_id_private *cm_id_priv, *listen_cm_id_priv;
struct cm_id_private *cm_id_priv, *cur_cm_id_priv;
struct cm_sidr_req_msg *sidr_req_msg; struct cm_sidr_req_msg *sidr_req_msg;
struct ib_wc *wc; struct ib_wc *wc;
int ret; int ret;
cm_id = ib_create_cm_id(work->port->cm_dev->ib_device, NULL, NULL); cm_id_priv =
if (IS_ERR(cm_id)) cm_alloc_id_priv(work->port->cm_dev->ib_device, NULL, NULL);
return PTR_ERR(cm_id); if (IS_ERR(cm_id_priv))
cm_id_priv = container_of(cm_id, struct cm_id_private, id); return PTR_ERR(cm_id_priv);
/* Record SGID/SLID and request ID for lookup. */ /* Record SGID/SLID and request ID for lookup. */
sidr_req_msg = (struct cm_sidr_req_msg *) sidr_req_msg = (struct cm_sidr_req_msg *)
work->mad_recv_wc->recv_buf.mad; work->mad_recv_wc->recv_buf.mad;
cm_id_priv->id.remote_id =
cpu_to_be32(IBA_GET(CM_SIDR_REQ_REQUESTID, sidr_req_msg));
cm_id_priv->id.service_id =
cpu_to_be64(IBA_GET(CM_SIDR_REQ_SERVICEID, sidr_req_msg));
cm_id_priv->id.service_mask = ~cpu_to_be64(0);
cm_id_priv->tid = sidr_req_msg->hdr.tid;
wc = work->mad_recv_wc->wc; wc = work->mad_recv_wc->wc;
cm_id_priv->av.dgid.global.subnet_prefix = cpu_to_be64(wc->slid); cm_id_priv->av.dgid.global.subnet_prefix = cpu_to_be64(wc->slid);
cm_id_priv->av.dgid.global.interface_id = 0; cm_id_priv->av.dgid.global.interface_id = 0;
...@@ -3558,41 +3565,44 @@ static int cm_sidr_req_handler(struct cm_work *work) ...@@ -3558,41 +3565,44 @@ static int cm_sidr_req_handler(struct cm_work *work)
if (ret) if (ret)
goto out; goto out;
cm_id_priv->id.remote_id =
cpu_to_be32(IBA_GET(CM_SIDR_REQ_REQUESTID, sidr_req_msg));
cm_id_priv->tid = sidr_req_msg->hdr.tid;
atomic_inc(&cm_id_priv->work_count);
spin_lock_irq(&cm.lock); spin_lock_irq(&cm.lock);
cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv); listen_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
if (cur_cm_id_priv) { if (listen_cm_id_priv) {
spin_unlock_irq(&cm.lock); spin_unlock_irq(&cm.lock);
atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES]. atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
counter[CM_SIDR_REQ_COUNTER]); counter[CM_SIDR_REQ_COUNTER]);
goto out; /* Duplicate message. */ goto out; /* Duplicate message. */
} }
cm_id_priv->id.state = IB_CM_SIDR_REQ_RCVD; cm_id_priv->id.state = IB_CM_SIDR_REQ_RCVD;
cur_cm_id_priv = cm_find_listen( listen_cm_id_priv = cm_find_listen(cm_id_priv->id.device,
cm_id->device, cm_id_priv->id.service_id);
cpu_to_be64(IBA_GET(CM_SIDR_REQ_SERVICEID, sidr_req_msg))); if (!listen_cm_id_priv) {
if (!cur_cm_id_priv) {
spin_unlock_irq(&cm.lock); spin_unlock_irq(&cm.lock);
cm_reject_sidr_req(cm_id_priv, IB_SIDR_UNSUPPORTED); cm_reject_sidr_req(cm_id_priv, IB_SIDR_UNSUPPORTED);
goto out; /* No match. */ goto out; /* No match. */
} }
refcount_inc(&cur_cm_id_priv->refcount); refcount_inc(&listen_cm_id_priv->refcount);
refcount_inc(&cm_id_priv->refcount);
spin_unlock_irq(&cm.lock); spin_unlock_irq(&cm.lock);
cm_id_priv->id.cm_handler = cur_cm_id_priv->id.cm_handler; cm_id_priv->id.cm_handler = listen_cm_id_priv->id.cm_handler;
cm_id_priv->id.context = cur_cm_id_priv->id.context; cm_id_priv->id.context = listen_cm_id_priv->id.context;
cm_id_priv->id.service_id =
cpu_to_be64(IBA_GET(CM_SIDR_REQ_SERVICEID, sidr_req_msg));
cm_id_priv->id.service_mask = ~cpu_to_be64(0);
cm_format_sidr_req_event(work, cm_id_priv, &cur_cm_id_priv->id); /*
cm_process_work(cm_id_priv, work); * A SIDR ID does not need to be in the xarray since it does not receive
cm_deref_id(cur_cm_id_priv); * mads, is not placed in the remote_id or remote_qpn rbtree, and does
* not enter timewait.
*/
cm_format_sidr_req_event(work, cm_id_priv, &listen_cm_id_priv->id);
ret = cm_id_priv->id.cm_handler(&cm_id_priv->id, &work->cm_event);
cm_free_work(work);
/*
* A pointer to the listen_cm_id is held in the event, so this deref
* must be after the event is delivered above.
*/
cm_deref_id(listen_cm_id_priv);
if (ret)
cm_destroy_id(&cm_id_priv->id, ret);
return 0; return 0;
out: out:
ib_destroy_cm_id(&cm_id_priv->id); ib_destroy_cm_id(&cm_id_priv->id);
......
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