ib_srpt: Fix possible race with srp_sq_size in srpt_create_ch_ib
Subsystems (3)
PATCH 1/2 ib_srpt: Fix possible race with srp_sq_size in srpt_create_ch_ib
From: Nicholas Bellinger <[email protected]>
This patch fixes a possible race with srp_sq_size in srpt_create_ch_ib() where changing sport->port_attrib.srp_sq_size via configfs could have unintended consequences. It uses a local assignment for srp_sq_size to ensure the values for ib_create_cq() and qp_init->cap.max_send_wr are consistent.
--- drivers/infiniband/ulp/srpt/ib_srpt.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)
drivers/infiniband/ulp/srpt/ib_srpt.c +4 -3
@@ -2130,6 +2130,7 @@ static int srpt_create_ch_ib(struct srpt_rdma_ch *ch)struct ib_qp_init_attr *qp_init;struct srpt_port *sport = ch->sport;struct srpt_device *sdev = sport->sdev; +u32 srp_sq_size = sport->port_attrib.srp_sq_size;int ret;WARN_ON (ch->rq_size <1 );
@@ -2140,11 +2141,11 @@ static int srpt_create_ch_ib(struct srpt_rdma_ch *ch) goto out; ch->cq =ib_create_cq (sdev->device, srpt_completion,NULL , ch, - ch->rq_size + sport->port_attrib.srp_sq_size,0 ); + ch->rq_size + srp_sq_size,0 );if (IS_ERR (ch->cq)) { ret =PTR_ERR (ch->cq);printk (KERN_ERR "failed to create CQ cqe= %d ret= %d\n" , - ch->rq_size + sport->port_attrib.srp_sq_size, ret); + ch->rq_size + srp_sq_size, ret); goto out; }
@@ -2156,7 +2157,7 @@ static int srpt_create_ch_ib(struct srpt_rdma_ch *ch) qp_init->srq = sdev->srq; qp_init->sq_sig_type =IB_SIGNAL_REQ_WR ; qp_init->qp_type =IB_QPT_RC ; - qp_init->cap.max_send_wr = sport->port_attrib.srp_sq_size; + qp_init->cap.max_send_wr = srp_sq_size; qp_init->cap.max_send_sge =SRPT_DEF_SG_PER_WQE ; ch->qp =ib_create_qp (sdev->pd, qp_init);
Signature · 6 lines
1.7.2.5 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/2 ib_srpt: Fix possible race with srp_max_rsp_size in srpt_release_channel_work
From: Nicholas Bellinger <[email protected]>
This patch fixes a possible race with srp_max_rsp_size in srpt_release_channel_work() when changing sport->port_attrib.srp_max_rsp_size via configfs could have unintended consequences. It uses a new srpt_rdma_ch->rsp_size and assign the value during srpt_cm_req_recv(), which is used in subsequent calls to srpt_free_ioctx_ring() to ensure consistency with the original srpt_alloc_ioctx_ring().
--- drivers/infiniband/ulp/srpt/ib_srpt.c | 10 ++++------ drivers/infiniband/ulp/srpt/ib_srpt.h | 2 ++ 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/infiniband/ulp/srpt/ib_srpt.c +4 -6
@@ -2373,8 +2373,7 @@ static void srpt_release_channel_work(struct work_struct *w)srpt_free_ioctx_ring ((struct srpt_ioctx **)ch->ioctx_ring, ch->sport->sdev, ch->rq_size, - ch->sport->port_attrib.srp_max_rsp_size, -DMA_TO_DEVICE ); + ch->rsp_size,DMA_TO_DEVICE );spin_lock_irq (&sdev->spinlock);list_del (&ch->list);
@@ -2554,12 +2553,12 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,spin_lock_init (&ch->spinlock); ch->state =CH_CONNECTING ;INIT_LIST_HEAD (&ch->cmd_wait_list); + ch->rsp_size = ch->sport->port_attrib.srp_max_rsp_size; ch->ioctx_ring = (struct srpt_send_ioctx **)srpt_alloc_ioctx_ring (ch->sport->sdev, ch->rq_size,sizeof (*ch->ioctx_ring[0 ]), - ch->sport->port_attrib.srp_max_rsp_size, -DMA_TO_DEVICE ); + ch->rsp_size,DMA_TO_DEVICE );if (!ch->ioctx_ring) goto free_ch;
@@ -2667,8 +2666,7 @@ destroy_ib: free_ring:srpt_free_ioctx_ring ((struct srpt_ioctx **)ch->ioctx_ring, ch->sport->sdev, ch->rq_size, - ch->sport->port_attrib.srp_max_rsp_size, -DMA_TO_DEVICE ); + ch->rsp_size,DMA_TO_DEVICE ); free_ch:kfree (ch);
drivers/infiniband/ulp/srpt/ib_srpt.h +2 -0
@@ -277,6 +277,7 @@ enum rdma_ch_state {* @qp: IB queue pair used for communicating over this channel. * @cq: IB completion queue for this channel. * @rq_size: IB receive queue size. +* @rsp_size IB response message size in bytes. * @sq_wr_avail: number of work requests available in the send queue. * @sport: pointer to the information of the HCA port used by this * channel.
@@ -307,6 +308,7 @@ struct srpt_rdma_ch {struct ib_qp *qp;struct ib_cq *cq;int rq_size; +u32 rsp_size;atomic_t sq_wr_avail;struct srpt_port *sport;u8 i_port_id[16 ];
Signature · 1 line
1.7.2.5