]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
IB/mthca: Make all device methods truly reentrant
authorRoland Dreier <rolandd@cisco.com>
Sun, 18 Jun 2006 03:37:41 +0000 (20:37 -0700)
committerRoland Dreier <rolandd@cisco.com>
Sun, 18 Jun 2006 03:37:41 +0000 (20:37 -0700)
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: Roland Dreier <rolandd@cisco.com>
drivers/infiniband/hw/mthca/mthca_cq.c
drivers/infiniband/hw/mthca/mthca_provider.c
drivers/infiniband/hw/mthca/mthca_provider.h
drivers/infiniband/hw/mthca/mthca_qp.c
drivers/infiniband/hw/mthca/mthca_srq.c

index 87a8f1166a3bd86c9c416a91a2c435c0cc27d67a..3e27a084257e9f23b7a4fba49561e15cfddf5b91 100644 (file)
@@ -822,6 +822,7 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
        spin_lock_init(&cq->lock);
        cq->refcount = 1;
        init_waitqueue_head(&cq->wait);
+       mutex_init(&cq->mutex);
 
        memset(cq_context, 0, sizeof *cq_context);
        cq_context->flags           = cpu_to_be32(MTHCA_CQ_STATUS_OK      |
index 8f89ba7c9147ee2c034d0db05aa940bd8f646aad..230ae21db8fd3c15a2c8664443987efec352912e 100644 (file)
@@ -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)
                return -EINVAL;
 
+       mutex_lock(&cq->mutex);
+
        entries = roundup_pow_of_two(entries + 1);
-       if (entries == ibcq->cqe + 1)
-               return 0;
+       if (entries == ibcq->cqe + 1) {
+               ret = 0;
+               goto out;
+       }
 
        if (cq->is_kernel) {
                ret = mthca_alloc_resize_buf(dev, cq, entries);
                if (ret)
-                       return ret;
+                       goto out;
                lkey = cq->resize_buf->buf.mr.ibmr.lkey;
        } else {
-               if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd))
-                       return -EFAULT;
+               if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd)) {
+                       ret = -EFAULT;
+                       goto out;
+               }
                lkey = ucmd.lkey;
        }
 
@@ -821,7 +827,7 @@ static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *uda
                        cq->resize_buf = NULL;
                        spin_unlock_irq(&cq->lock);
                }
-               return ret;
+               goto out;
        }
 
        if (cq->is_kernel) {
@@ -848,7 +854,10 @@ static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *uda
        } else
                ibcq->cqe = entries - 1;
 
-       return 0;
+out:
+       mutex_unlock(&cq->mutex);
+
+       return ret;
 }
 
 static int mthca_destroy_cq(struct ib_cq *cq)
index 179a8f610d0f00ded795bfa0b07310a9ac1fc986..8de2887ba15ce090ef9ea4297a634c5067244aaf 100644 (file)
@@ -214,6 +214,7 @@ struct mthca_cq {
        int                     arm_sn;
 
        wait_queue_head_t       wait;
+       struct mutex            mutex;
 };
 
 struct mthca_srq {
@@ -237,6 +238,7 @@ struct mthca_srq {
        struct mthca_mr         mr;
 
        wait_queue_head_t       wait;
+       struct mutex            mutex;
 };
 
 struct mthca_wq {
@@ -278,6 +280,7 @@ struct mthca_qp {
        union mthca_buf        queue;
 
        wait_queue_head_t      wait;
+       struct mutex           mutex;
 };
 
 struct mthca_sqp {
index 322bc32a93f65d1584bbd9a9b5b07b3eedc00f44..16c387d8170cc599b8b2b16aa8d0275672bbe920 100644 (file)
@@ -536,6 +536,8 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
        u8 status;
        int err = -EINVAL;
 
+       mutex_lock(&qp->mutex);
+
        if (attr_mask & IB_QP_CUR_STATE) {
                cur_state = attr->cur_qp_state;
        } else {
@@ -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",
                          qp->transport, cur_state, new_state,
                          attr_mask);
-               return -EINVAL;
+               goto out;
        }
 
        if ((attr_mask & IB_QP_PKEY_INDEX) &&
             attr->pkey_index >= dev->limits.pkey_table_len) {
                mthca_dbg(dev, "P_Key index (%u) too large. max is %d\n",
                          attr->pkey_index, dev->limits.pkey_table_len-1);
-               return -EINVAL;
+               goto out;
        }
 
        if ((attr_mask & IB_QP_PORT) &&
            (attr->port_num == 0 || attr->port_num > dev->limits.num_ports)) {
                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 &&
            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",
                          attr->max_rd_atomic, dev->limits.max_qp_init_rdma);
-               return -EINVAL;
+               goto out;
        }
 
        if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC &&
            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",
                          attr->max_dest_rd_atomic, 1 << dev->qp_table.rdb_shift);
-               return -EINVAL;
+               goto out;
        }
 
        mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
-       if (IS_ERR(mailbox))
-               return PTR_ERR(mailbox);
+       if (IS_ERR(mailbox)) {
+               err = PTR_ERR(mailbox);
+               goto out;
+       }
        qp_param = mailbox->buf;
        qp_context = &qp_param->context;
        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)
                if (attr->path_mtu < IB_MTU_256 || attr->path_mtu > IB_MTU_2048) {
                        mthca_dbg(dev, "path MTU (%u) is invalid\n",
                                  attr->path_mtu);
-                       goto out;
+                       goto out_mailbox;
                }
                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)
        if (attr_mask & IB_QP_AV) {
                if (mthca_path_set(dev, &attr->ah_attr, &qp_context->pri_path,
                                   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);
        }
@@ -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) {
                        mthca_dbg(dev, "Alternate P_Key index (%u) too large. max is %d\n",
                                  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) {
                        mthca_dbg(dev, "Alternate port number (%u) is invalid\n",
                                attr->alt_port_num);
-                       goto out;
+                       goto out_mailbox;
                }
 
                if (mthca_path_set(dev, &attr->alt_ah_attr, &qp_context->alt_path,
                                   attr->alt_ah_attr.port_num))
-                       goto out;
+                       goto out_mailbox;
 
                qp_context->alt_path.port_pkey |= cpu_to_be32(attr->alt_pkey_index |
                                                              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)
        err = mthca_MODIFY_QP(dev, cur_state, new_state, qp->qpn, 0,
                              mailbox, sqd_event, &status);
        if (err)
-               goto out;
+               goto out_mailbox;
        if (status) {
                mthca_warn(dev, "modify QP %d->%d returned status %02x.\n",
                           cur_state, new_state, status);
                err = -EINVAL;
-               goto out;
+               goto out_mailbox;
        }
 
        qp->state = new_state;
@@ -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);
+
+out:
+       mutex_unlock(&qp->mutex);
        return err;
 }
 
@@ -1100,6 +1107,7 @@ static int mthca_alloc_qp_common(struct mthca_dev *dev,
 
        qp->refcount = 1;
        init_waitqueue_head(&qp->wait);
+       mutex_init(&qp->mutex);
        qp->state        = IB_QPS_RESET;
        qp->atomic_rd_en = 0;
        qp->resp_depth   = 0;
index b292fefa3b411924ea29d693da19f75bf5187ffd..fab417c5cf43671f329b9b8c26dddc87bd9345ad 100644 (file)
@@ -243,6 +243,7 @@ int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,
        spin_lock_init(&srq->lock);
        srq->refcount = 1;
        init_waitqueue_head(&srq->wait);
+       mutex_init(&srq->mutex);
 
        if (mthca_is_memfree(dev))
                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,
        if (attr_mask & IB_SRQ_LIMIT) {
                if (attr->srq_limit > srq->max)
                        return -EINVAL;
+
+               mutex_lock(&srq->mutex);
                ret = mthca_ARM_SRQ(dev, srq->srqn, attr->srq_limit, &status);
+               mutex_unlock(&srq->mutex);
+
                if (ret)
                        return ret;
                if (status)