diff mbox series

[for-next,3/3] RDMA/rxe: Fix rxe_m-dify_srq

Message ID 20230619202110.45680-4-rpearsonhpe@gmail.com (mailing list archive)
State Superseded
Headers show
Series RDMA/rxe: Fix error path code in rxe_create_qp | expand

Commit Message

Bob Pearson June 19, 2023, 8:21 p.m. UTC
This patch corrects an error in rxe_modify_srq where if the
caller changes the srq size the actual new value is not returned
to the caller since it may be larger than what is requested.
Additionally it open codes the subroutine rcv_wqe_size() which
adds very little value. And makes some whitespace changes.

Fixes: 8700e3e7c485 ("Soft RoCE driver")
Signed-off-by: Bob Pearson <rpearsonhpe@gmail.com>
---
 drivers/infiniband/sw/rxe/rxe_loc.h |  6 ----
 drivers/infiniband/sw/rxe/rxe_srq.c | 55 ++++++++++++++++++-----------
 2 files changed, 34 insertions(+), 27 deletions(-)

Comments

kernel test robot June 20, 2023, 11:04 a.m. UTC | #1
Hi Bob,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 830f93f47068b1632cc127871fbf27e918efdf46]

url:    https://github.com/intel-lab-lkp/linux/commits/Bob-Pearson/RDMA-rxe-Move-work-queue-code-to-subroutines/20230620-042342
base:   830f93f47068b1632cc127871fbf27e918efdf46
patch link:    https://lore.kernel.org/r/20230619202110.45680-4-rpearsonhpe%40gmail.com
patch subject: [PATCH for-next 3/3] RDMA/rxe: Fix rxe_m-dify_srq
config: x86_64-randconfig-a005-20230620 (https://download.01.org/0day-ci/archive/20230620/202306201807.sCYZpuDH-lkp@intel.com/config)
compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
reproduce: (https://download.01.org/0day-ci/archive/20230620/202306201807.sCYZpuDH-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202306201807.sCYZpuDH-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/infiniband/sw/rxe/rxe_srq.c:73:18: warning: variable 'q' is uninitialized when used here [-Wuninitialized]
           srq->rq.queue = q;
                           ^
   drivers/infiniband/sw/rxe/rxe_srq.c:50:21: note: initialize the variable 'q' to silence this warning
           struct rxe_queue *q;
                              ^
                               = NULL
   1 warning generated.


vim +/q +73 drivers/infiniband/sw/rxe/rxe_srq.c

8700e3e7c4857d Moni Shoua         2016-06-16   43  
8700e3e7c4857d Moni Shoua         2016-06-16   44  int rxe_srq_from_init(struct rxe_dev *rxe, struct rxe_srq *srq,
ff23dfa134576e Shamir Rabinovitch 2019-03-31   45  		      struct ib_srq_init_attr *init, struct ib_udata *udata,
0c43ab371bcb07 Jason Gunthorpe    2018-03-13   46  		      struct rxe_create_srq_resp __user *uresp)
8700e3e7c4857d Moni Shoua         2016-06-16   47  {
8700e3e7c4857d Moni Shoua         2016-06-16   48  	int err;
06e1f13ffd8b02 Bob Pearson        2023-06-19   49  	int wqe_size;
8700e3e7c4857d Moni Shoua         2016-06-16   50  	struct rxe_queue *q;
8700e3e7c4857d Moni Shoua         2016-06-16   51  
8700e3e7c4857d Moni Shoua         2016-06-16   52  	srq->ibsrq.event_handler = init->event_handler;
8700e3e7c4857d Moni Shoua         2016-06-16   53  	srq->ibsrq.srq_context = init->srq_context;
8700e3e7c4857d Moni Shoua         2016-06-16   54  	srq->limit = init->attr.srq_limit;
02827b67085162 Bob Pearson        2021-11-03   55  	srq->srq_num = srq->elem.index;
8700e3e7c4857d Moni Shoua         2016-06-16   56  	srq->rq.max_wr = init->attr.max_wr;
8700e3e7c4857d Moni Shoua         2016-06-16   57  	srq->rq.max_sge = init->attr.max_sge;
8700e3e7c4857d Moni Shoua         2016-06-16   58  
06e1f13ffd8b02 Bob Pearson        2023-06-19   59  	wqe_size = sizeof(struct rxe_recv_wqe) +
06e1f13ffd8b02 Bob Pearson        2023-06-19   60  			srq->rq.max_sge*sizeof(struct ib_sge);
8700e3e7c4857d Moni Shoua         2016-06-16   61  
8700e3e7c4857d Moni Shoua         2016-06-16   62  	spin_lock_init(&srq->rq.producer_lock);
8700e3e7c4857d Moni Shoua         2016-06-16   63  	spin_lock_init(&srq->rq.consumer_lock);
8700e3e7c4857d Moni Shoua         2016-06-16   64  
06e1f13ffd8b02 Bob Pearson        2023-06-19   65  	srq->rq.queue = rxe_queue_init(rxe, &srq->rq.max_wr, wqe_size,
06e1f13ffd8b02 Bob Pearson        2023-06-19   66  				       QUEUE_TYPE_FROM_CLIENT);
06e1f13ffd8b02 Bob Pearson        2023-06-19   67  	if (!srq->rq.queue) {
0e6090024b3ebf Bob Pearson        2022-11-03   68  		rxe_dbg_srq(srq, "Unable to allocate queue\n");
06e1f13ffd8b02 Bob Pearson        2023-06-19   69  		err = -ENOMEM;
06e1f13ffd8b02 Bob Pearson        2023-06-19   70  		goto err_out;
8700e3e7c4857d Moni Shoua         2016-06-16   71  	}
8700e3e7c4857d Moni Shoua         2016-06-16   72  
8700e3e7c4857d Moni Shoua         2016-06-16  @73  	srq->rq.queue = q;
8700e3e7c4857d Moni Shoua         2016-06-16   74  
ff23dfa134576e Shamir Rabinovitch 2019-03-31   75  	err = do_mmap_info(rxe, uresp ? &uresp->mi : NULL, udata, q->buf,
8700e3e7c4857d Moni Shoua         2016-06-16   76  			   q->buf_size, &q->ip);
aae0484e15f062 Zhu Yanjun         2018-09-30   77  	if (err) {
06e1f13ffd8b02 Bob Pearson        2023-06-19   78  		rxe_dbg_srq(srq, "Unable to init mmap info for caller\n");
06e1f13ffd8b02 Bob Pearson        2023-06-19   79  		goto err_free;
aae0484e15f062 Zhu Yanjun         2018-09-30   80  	}
8700e3e7c4857d Moni Shoua         2016-06-16   81  
06e1f13ffd8b02 Bob Pearson        2023-06-19   82  	init->attr.max_wr = srq->rq.max_wr;
06e1f13ffd8b02 Bob Pearson        2023-06-19   83  
0c43ab371bcb07 Jason Gunthorpe    2018-03-13   84  	if (uresp) {
0c43ab371bcb07 Jason Gunthorpe    2018-03-13   85  		if (copy_to_user(&uresp->srq_num, &srq->srq_num,
aae0484e15f062 Zhu Yanjun         2018-09-30   86  				 sizeof(uresp->srq_num))) {
aae0484e15f062 Zhu Yanjun         2018-09-30   87  			rxe_queue_cleanup(q);
8700e3e7c4857d Moni Shoua         2016-06-16   88  			return -EFAULT;
8700e3e7c4857d Moni Shoua         2016-06-16   89  		}
aae0484e15f062 Zhu Yanjun         2018-09-30   90  	}
0c43ab371bcb07 Jason Gunthorpe    2018-03-13   91  
8700e3e7c4857d Moni Shoua         2016-06-16   92  	return 0;
06e1f13ffd8b02 Bob Pearson        2023-06-19   93  
06e1f13ffd8b02 Bob Pearson        2023-06-19   94  err_free:
06e1f13ffd8b02 Bob Pearson        2023-06-19   95  	vfree(q->buf);
06e1f13ffd8b02 Bob Pearson        2023-06-19   96  	kfree(q);
06e1f13ffd8b02 Bob Pearson        2023-06-19   97  err_out:
06e1f13ffd8b02 Bob Pearson        2023-06-19   98  	return err;
8700e3e7c4857d Moni Shoua         2016-06-16   99  }
8700e3e7c4857d Moni Shoua         2016-06-16  100
diff mbox series

Patch

diff --git a/drivers/infiniband/sw/rxe/rxe_loc.h b/drivers/infiniband/sw/rxe/rxe_loc.h
index 666e06a82bc9..4d2a8ef52c85 100644
--- a/drivers/infiniband/sw/rxe/rxe_loc.h
+++ b/drivers/infiniband/sw/rxe/rxe_loc.h
@@ -136,12 +136,6 @@  static inline int qp_mtu(struct rxe_qp *qp)
 		return IB_MTU_4096;
 }
 
-static inline int rcv_wqe_size(int max_sge)
-{
-	return sizeof(struct rxe_recv_wqe) +
-		max_sge * sizeof(struct ib_sge);
-}
-
 void free_rd_atomic_resource(struct resp_res *res);
 
 static inline void rxe_advance_resp_resource(struct rxe_qp *qp)
diff --git a/drivers/infiniband/sw/rxe/rxe_srq.c b/drivers/infiniband/sw/rxe/rxe_srq.c
index 27ca82ec0826..9fd37936ee5b 100644
--- a/drivers/infiniband/sw/rxe/rxe_srq.c
+++ b/drivers/infiniband/sw/rxe/rxe_srq.c
@@ -46,27 +46,28 @@  int rxe_srq_from_init(struct rxe_dev *rxe, struct rxe_srq *srq,
 		      struct rxe_create_srq_resp __user *uresp)
 {
 	int err;
-	int srq_wqe_size;
+	int wqe_size;
 	struct rxe_queue *q;
-	enum queue_type type;
 
-	srq->ibsrq.event_handler	= init->event_handler;
-	srq->ibsrq.srq_context		= init->srq_context;
-	srq->limit		= init->attr.srq_limit;
-	srq->srq_num		= srq->elem.index;
-	srq->rq.max_wr		= init->attr.max_wr;
-	srq->rq.max_sge		= init->attr.max_sge;
+	srq->ibsrq.event_handler = init->event_handler;
+	srq->ibsrq.srq_context = init->srq_context;
+	srq->limit = init->attr.srq_limit;
+	srq->srq_num = srq->elem.index;
+	srq->rq.max_wr = init->attr.max_wr;
+	srq->rq.max_sge = init->attr.max_sge;
 
-	srq_wqe_size		= rcv_wqe_size(srq->rq.max_sge);
+	wqe_size = sizeof(struct rxe_recv_wqe) +
+			srq->rq.max_sge*sizeof(struct ib_sge);
 
 	spin_lock_init(&srq->rq.producer_lock);
 	spin_lock_init(&srq->rq.consumer_lock);
 
-	type = QUEUE_TYPE_FROM_CLIENT;
-	q = rxe_queue_init(rxe, &srq->rq.max_wr, srq_wqe_size, type);
-	if (!q) {
+	srq->rq.queue = rxe_queue_init(rxe, &srq->rq.max_wr, wqe_size,
+				       QUEUE_TYPE_FROM_CLIENT);
+	if (!srq->rq.queue) {
 		rxe_dbg_srq(srq, "Unable to allocate queue\n");
-		return -ENOMEM;
+		err = -ENOMEM;
+		goto err_out;
 	}
 
 	srq->rq.queue = q;
@@ -74,11 +75,12 @@  int rxe_srq_from_init(struct rxe_dev *rxe, struct rxe_srq *srq,
 	err = do_mmap_info(rxe, uresp ? &uresp->mi : NULL, udata, q->buf,
 			   q->buf_size, &q->ip);
 	if (err) {
-		vfree(q->buf);
-		kfree(q);
-		return err;
+		rxe_dbg_srq(srq, "Unable to init mmap info for caller\n");
+		goto err_free;
 	}
 
+	init->attr.max_wr = srq->rq.max_wr;
+
 	if (uresp) {
 		if (copy_to_user(&uresp->srq_num, &srq->srq_num,
 				 sizeof(uresp->srq_num))) {
@@ -88,6 +90,12 @@  int rxe_srq_from_init(struct rxe_dev *rxe, struct rxe_srq *srq,
 	}
 
 	return 0;
+
+err_free:
+	vfree(q->buf);
+	kfree(q);
+err_out:
+	return err;
 }
 
 int rxe_srq_chk_attr(struct rxe_dev *rxe, struct rxe_srq *srq,
@@ -148,6 +156,7 @@  int rxe_srq_from_attr(struct rxe_dev *rxe, struct rxe_srq *srq,
 	int err;
 	struct rxe_queue *q = srq->rq.queue;
 	struct mminfo __user *mi = NULL;
+	int wqe_size;
 
 	if (mask & IB_SRQ_MAX_WR) {
 		/*
@@ -156,12 +165,16 @@  int rxe_srq_from_attr(struct rxe_dev *rxe, struct rxe_srq *srq,
 		 */
 		mi = u64_to_user_ptr(ucmd->mmap_info_addr);
 
-		err = rxe_queue_resize(q, &attr->max_wr,
-				       rcv_wqe_size(srq->rq.max_sge), udata, mi,
-				       &srq->rq.producer_lock,
+		wqe_size = sizeof(struct rxe_recv_wqe) +
+				srq->rq.max_sge*sizeof(struct ib_sge);
+
+		err = rxe_queue_resize(q, &attr->max_wr, wqe_size,
+				       udata, mi, &srq->rq.producer_lock,
 				       &srq->rq.consumer_lock);
 		if (err)
-			goto err2;
+			goto err_free;
+
+		srq->rq.max_wr = attr->max_wr;
 	}
 
 	if (mask & IB_SRQ_LIMIT)
@@ -169,7 +182,7 @@  int rxe_srq_from_attr(struct rxe_dev *rxe, struct rxe_srq *srq,
 
 	return 0;
 
-err2:
+err_free:
 	rxe_queue_cleanup(q);
 	srq->rq.queue = NULL;
 	return err;