Commit c93b6fba authored by Roland Dreier's avatar Roland Dreier

IB/mthca: Make all device methods truly reentrant

Documentation/infiniband/core_locking.txt says:

  All of the methods in struct ib_device exported by a low-level
  driver must be fully reentrant.  The low-level driver is required to
  perform all synchronization necessary to maintain consistency, even
  if multiple function calls using the same object are run
  simultaneously.

However, mthca's modify_qp, modify_srq and resize_cq methods are
currently not reentrant.  Add a mutex to the QP, SRQ and CQ structures
so that these calls can be properly serialized.
Signed-off-by: default avatarRoland Dreier <rolandd@cisco.com>
parent c9c5d9fe
...@@ -822,6 +822,7 @@ int mthca_init_cq(struct mthca_dev *dev, int nent, ...@@ -822,6 +822,7 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
spin_lock_init(&cq->lock); spin_lock_init(&cq->lock);
cq->refcount = 1; cq->refcount = 1;
init_waitqueue_head(&cq->wait); init_waitqueue_head(&cq->wait);
mutex_init(&cq->mutex);
memset(cq_context, 0, sizeof *cq_context); memset(cq_context, 0, sizeof *cq_context);
cq_context->flags = cpu_to_be32(MTHCA_CQ_STATUS_OK | cq_context->flags = cpu_to_be32(MTHCA_CQ_STATUS_OK |
......
...@@ -793,18 +793,24 @@ static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *uda ...@@ -793,18 +793,24 @@ static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *uda
if (entries < 1 || entries > dev->limits.max_cqes) if (entries < 1 || entries > dev->limits.max_cqes)
return -EINVAL; return -EINVAL;
mutex_lock(&cq->mutex);
entries = roundup_pow_of_two(entries + 1); entries = roundup_pow_of_two(entries + 1);
if (entries == ibcq->cqe + 1) if (entries == ibcq->cqe + 1) {
return 0; ret = 0;
goto out;
}
if (cq->is_kernel) { if (cq->is_kernel) {
ret = mthca_alloc_resize_buf(dev, cq, entries); ret = mthca_alloc_resize_buf(dev, cq, entries);
if (ret) if (ret)
return ret; goto out;
lkey = cq->resize_buf->buf.mr.ibmr.lkey; lkey = cq->resize_buf->buf.mr.ibmr.lkey;
} else { } else {
if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd)) if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd)) {
return -EFAULT; ret = -EFAULT;
goto out;
}
lkey = ucmd.lkey; lkey = ucmd.lkey;
} }
...@@ -821,7 +827,7 @@ static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *uda ...@@ -821,7 +827,7 @@ static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *uda
cq->resize_buf = NULL; cq->resize_buf = NULL;
spin_unlock_irq(&cq->lock); spin_unlock_irq(&cq->lock);
} }
return ret; goto out;
} }
if (cq->is_kernel) { if (cq->is_kernel) {
...@@ -848,7 +854,10 @@ static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *uda ...@@ -848,7 +854,10 @@ static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *uda
} else } else
ibcq->cqe = entries - 1; ibcq->cqe = entries - 1;
return 0; out:
mutex_unlock(&cq->mutex);
return ret;
} }
static int mthca_destroy_cq(struct ib_cq *cq) static int mthca_destroy_cq(struct ib_cq *cq)
......
...@@ -214,6 +214,7 @@ struct mthca_cq { ...@@ -214,6 +214,7 @@ struct mthca_cq {
int arm_sn; int arm_sn;
wait_queue_head_t wait; wait_queue_head_t wait;
struct mutex mutex;
}; };
struct mthca_srq { struct mthca_srq {
...@@ -237,6 +238,7 @@ struct mthca_srq { ...@@ -237,6 +238,7 @@ struct mthca_srq {
struct mthca_mr mr; struct mthca_mr mr;
wait_queue_head_t wait; wait_queue_head_t wait;
struct mutex mutex;
}; };
struct mthca_wq { struct mthca_wq {
...@@ -278,6 +280,7 @@ struct mthca_qp { ...@@ -278,6 +280,7 @@ struct mthca_qp {
union mthca_buf queue; union mthca_buf queue;
wait_queue_head_t wait; wait_queue_head_t wait;
struct mutex mutex;
}; };
struct mthca_sqp { struct mthca_sqp {
......
...@@ -536,6 +536,8 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask) ...@@ -536,6 +536,8 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
u8 status; u8 status;
int err = -EINVAL; int err = -EINVAL;
mutex_lock(&qp->mutex);
if (attr_mask & IB_QP_CUR_STATE) { if (attr_mask & IB_QP_CUR_STATE) {
cur_state = attr->cur_qp_state; cur_state = attr->cur_qp_state;
} else { } else {
...@@ -553,39 +555,41 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask) ...@@ -553,39 +555,41 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
"%d->%d with attr 0x%08x\n", "%d->%d with attr 0x%08x\n",
qp->transport, cur_state, new_state, qp->transport, cur_state, new_state,
attr_mask); attr_mask);
return -EINVAL; goto out;
} }
if ((attr_mask & IB_QP_PKEY_INDEX) && if ((attr_mask & IB_QP_PKEY_INDEX) &&
attr->pkey_index >= dev->limits.pkey_table_len) { attr->pkey_index >= dev->limits.pkey_table_len) {
mthca_dbg(dev, "P_Key index (%u) too large. max is %d\n", mthca_dbg(dev, "P_Key index (%u) too large. max is %d\n",
attr->pkey_index, dev->limits.pkey_table_len-1); attr->pkey_index, dev->limits.pkey_table_len-1);
return -EINVAL; goto out;
} }
if ((attr_mask & IB_QP_PORT) && if ((attr_mask & IB_QP_PORT) &&
(attr->port_num == 0 || attr->port_num > dev->limits.num_ports)) { (attr->port_num == 0 || attr->port_num > dev->limits.num_ports)) {
mthca_dbg(dev, "Port number (%u) is invalid\n", attr->port_num); mthca_dbg(dev, "Port number (%u) is invalid\n", attr->port_num);
return -EINVAL; goto out;
} }
if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC && if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC &&
attr->max_rd_atomic > dev->limits.max_qp_init_rdma) { attr->max_rd_atomic > dev->limits.max_qp_init_rdma) {
mthca_dbg(dev, "Max rdma_atomic as initiator %u too large (max is %d)\n", mthca_dbg(dev, "Max rdma_atomic as initiator %u too large (max is %d)\n",
attr->max_rd_atomic, dev->limits.max_qp_init_rdma); attr->max_rd_atomic, dev->limits.max_qp_init_rdma);
return -EINVAL; goto out;
} }
if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC && if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC &&
attr->max_dest_rd_atomic > 1 << dev->qp_table.rdb_shift) { attr->max_dest_rd_atomic > 1 << dev->qp_table.rdb_shift) {
mthca_dbg(dev, "Max rdma_atomic as responder %u too large (max %d)\n", mthca_dbg(dev, "Max rdma_atomic as responder %u too large (max %d)\n",
attr->max_dest_rd_atomic, 1 << dev->qp_table.rdb_shift); attr->max_dest_rd_atomic, 1 << dev->qp_table.rdb_shift);
return -EINVAL; goto out;
} }
mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
if (IS_ERR(mailbox)) if (IS_ERR(mailbox)) {
return PTR_ERR(mailbox); err = PTR_ERR(mailbox);
goto out;
}
qp_param = mailbox->buf; qp_param = mailbox->buf;
qp_context = &qp_param->context; qp_context = &qp_param->context;
memset(qp_param, 0, sizeof *qp_param); memset(qp_param, 0, sizeof *qp_param);
...@@ -618,7 +622,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask) ...@@ -618,7 +622,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
if (attr->path_mtu < IB_MTU_256 || attr->path_mtu > IB_MTU_2048) { if (attr->path_mtu < IB_MTU_256 || attr->path_mtu > IB_MTU_2048) {
mthca_dbg(dev, "path MTU (%u) is invalid\n", mthca_dbg(dev, "path MTU (%u) is invalid\n",
attr->path_mtu); attr->path_mtu);
goto out; goto out_mailbox;
} }
qp_context->mtu_msgmax = (attr->path_mtu << 5) | 31; qp_context->mtu_msgmax = (attr->path_mtu << 5) | 31;
} }
...@@ -672,7 +676,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask) ...@@ -672,7 +676,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
if (attr_mask & IB_QP_AV) { if (attr_mask & IB_QP_AV) {
if (mthca_path_set(dev, &attr->ah_attr, &qp_context->pri_path, if (mthca_path_set(dev, &attr->ah_attr, &qp_context->pri_path,
attr_mask & IB_QP_PORT ? attr->port_num : qp->port)) attr_mask & IB_QP_PORT ? attr->port_num : qp->port))
goto out; goto out_mailbox;
qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_PRIMARY_ADDR_PATH); qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_PRIMARY_ADDR_PATH);
} }
...@@ -686,18 +690,18 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask) ...@@ -686,18 +690,18 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
if (attr->alt_pkey_index >= dev->limits.pkey_table_len) { if (attr->alt_pkey_index >= dev->limits.pkey_table_len) {
mthca_dbg(dev, "Alternate P_Key index (%u) too large. max is %d\n", mthca_dbg(dev, "Alternate P_Key index (%u) too large. max is %d\n",
attr->alt_pkey_index, dev->limits.pkey_table_len-1); attr->alt_pkey_index, dev->limits.pkey_table_len-1);
goto out; goto out_mailbox;
} }
if (attr->alt_port_num == 0 || attr->alt_port_num > dev->limits.num_ports) { if (attr->alt_port_num == 0 || attr->alt_port_num > dev->limits.num_ports) {
mthca_dbg(dev, "Alternate port number (%u) is invalid\n", mthca_dbg(dev, "Alternate port number (%u) is invalid\n",
attr->alt_port_num); attr->alt_port_num);
goto out; goto out_mailbox;
} }
if (mthca_path_set(dev, &attr->alt_ah_attr, &qp_context->alt_path, if (mthca_path_set(dev, &attr->alt_ah_attr, &qp_context->alt_path,
attr->alt_ah_attr.port_num)) attr->alt_ah_attr.port_num))
goto out; goto out_mailbox;
qp_context->alt_path.port_pkey |= cpu_to_be32(attr->alt_pkey_index | qp_context->alt_path.port_pkey |= cpu_to_be32(attr->alt_pkey_index |
attr->alt_port_num << 24); attr->alt_port_num << 24);
...@@ -793,12 +797,12 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask) ...@@ -793,12 +797,12 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
err = mthca_MODIFY_QP(dev, cur_state, new_state, qp->qpn, 0, err = mthca_MODIFY_QP(dev, cur_state, new_state, qp->qpn, 0,
mailbox, sqd_event, &status); mailbox, sqd_event, &status);
if (err) if (err)
goto out; goto out_mailbox;
if (status) { if (status) {
mthca_warn(dev, "modify QP %d->%d returned status %02x.\n", mthca_warn(dev, "modify QP %d->%d returned status %02x.\n",
cur_state, new_state, status); cur_state, new_state, status);
err = -EINVAL; err = -EINVAL;
goto out; goto out_mailbox;
} }
qp->state = new_state; qp->state = new_state;
...@@ -853,8 +857,11 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask) ...@@ -853,8 +857,11 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
} }
} }
out: out_mailbox:
mthca_free_mailbox(dev, mailbox); mthca_free_mailbox(dev, mailbox);
out:
mutex_unlock(&qp->mutex);
return err; return err;
} }
...@@ -1100,6 +1107,7 @@ static int mthca_alloc_qp_common(struct mthca_dev *dev, ...@@ -1100,6 +1107,7 @@ static int mthca_alloc_qp_common(struct mthca_dev *dev,
qp->refcount = 1; qp->refcount = 1;
init_waitqueue_head(&qp->wait); init_waitqueue_head(&qp->wait);
mutex_init(&qp->mutex);
qp->state = IB_QPS_RESET; qp->state = IB_QPS_RESET;
qp->atomic_rd_en = 0; qp->atomic_rd_en = 0;
qp->resp_depth = 0; qp->resp_depth = 0;
......
...@@ -243,6 +243,7 @@ int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd, ...@@ -243,6 +243,7 @@ int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,
spin_lock_init(&srq->lock); spin_lock_init(&srq->lock);
srq->refcount = 1; srq->refcount = 1;
init_waitqueue_head(&srq->wait); init_waitqueue_head(&srq->wait);
mutex_init(&srq->mutex);
if (mthca_is_memfree(dev)) if (mthca_is_memfree(dev))
mthca_arbel_init_srq_context(dev, pd, srq, mailbox->buf); mthca_arbel_init_srq_context(dev, pd, srq, mailbox->buf);
...@@ -371,7 +372,11 @@ int mthca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr, ...@@ -371,7 +372,11 @@ int mthca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
if (attr_mask & IB_SRQ_LIMIT) { if (attr_mask & IB_SRQ_LIMIT) {
if (attr->srq_limit > srq->max) if (attr->srq_limit > srq->max)
return -EINVAL; return -EINVAL;
mutex_lock(&srq->mutex);
ret = mthca_ARM_SRQ(dev, srq->srqn, attr->srq_limit, &status); ret = mthca_ARM_SRQ(dev, srq->srqn, attr->srq_limit, &status);
mutex_unlock(&srq->mutex);
if (ret) if (ret)
return ret; return ret;
if (status) if (status)
......
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