Skip to contentSkip to conversation

RDMA/efa: Validate SQ depth based on WQE size

PATCH In review Yonatan Nachum 2 participants 2 messages May 17 – May 18

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 RDMA/efa: Validate SQ depth based on WQE size

Change the SQ depth validation to take into account the SQ WQE size. This is needed since when using 128-byte WQE the max SQ depth is cut in half. On create QP command, userspace provides SQ ring size which is SQ depth X WQE size so we can calculate the requested WQE size in the kernel.

Fixes 40909f664d27 ("RDMA/efa: Add EFA verbs implementation")

---
Changelog:
v2:
* Add fixes line.
v1: https://lore.kernel.org/all/[email protected]/

 drivers/infiniband/hw/efa/efa_verbs.c | 39 ++++++++++++++++++---------
 1 file changed, 27 insertions(+), 12 deletions(-)
drivers/infiniband/hw/efa/efa_verbs.c +27 -12
index 395290ab0584..9a6cbb70581b 100644
@@ -597,14 +597,27 @@ static int qp_mmap_entries_setup(struct efa_qp *qp,
 	return -ENOMEM;
 }
 
+static int efa_calc_sq_wqe_size(u32 sq_ring_size, u32 max_send_wr)
+{
+	return max_send_wr == 0 ? 0 : sq_ring_size / max_send_wr;
+}
+
+static u32 efa_calc_sq_max_depth(struct efa_dev *dev, u32 sq_wqe_size)
+{
+	return sq_wqe_size == 0 ? 0 :
+		rounddown_pow_of_two(dev->dev_attr.max_llq_size / sq_wqe_size);
+}
+
 static int efa_qp_validate_cap(struct efa_dev *dev,
-			       struct ib_qp_init_attr *init_attr)
+			       struct ib_qp_init_attr *init_attr,
+			       u32 sq_wqe_size)
 {
-	if (init_attr->cap.max_send_wr > dev->dev_attr.max_sq_depth) {
+	u32 sq_max_depth = efa_calc_sq_max_depth(dev, sq_wqe_size);
+
+	if (init_attr->cap.max_send_wr > sq_max_depth) {
 		ibdev_dbg(&dev->ibdev,
 			  "qp: requested send wr[%u] exceeds the max[%u]\n",
-			  init_attr->cap.max_send_wr,
-			  dev->dev_attr.max_sq_depth);
+			  init_attr->cap.max_send_wr, sq_max_depth);
 		return -EINVAL;
 	}
 	if (init_attr->cap.max_recv_wr > dev->dev_attr.max_rq_depth) {
@@ -671,19 +684,12 @@ int efa_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *init_attr,
 	struct efa_qp *qp = to_eqp(ibqp);
 	struct efa_ucontext *ucontext;
 	u16 supported_efa_flags = 0;
+	u32 sq_wqe_size;
 	int err;
 
 	ucontext = rdma_udata_to_drv_context(udata, struct efa_ucontext,
 					     ibucontext);
 
-	err = efa_qp_validate_cap(dev, init_attr);
-	if (err)
-		goto err_out;
-
-	err = efa_qp_validate_attr(dev, init_attr);
-	if (err)
-		goto err_out;
-
 	err = ib_copy_validate_udata_in_cm(udata, cmd, driver_qp_type, 0);
 	if (err)
 		goto err_out;
@@ -705,6 +711,15 @@ int efa_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *init_attr,
 		goto err_out;
 	}
 
+	sq_wqe_size = efa_calc_sq_wqe_size(cmd.sq_ring_size, init_attr->cap.max_send_wr);
+	err = efa_qp_validate_cap(dev, init_attr, sq_wqe_size);
+	if (err)
+		goto err_out;
+
+	err = efa_qp_validate_attr(dev, init_attr);
+	if (err)
+		goto err_out;
+
 	create_qp_params.uarn = ucontext->uarn;
 	create_qp_params.pd = to_epd(ibqp->pd)->pdn;
 
Signature · 1 line
2.50.1
#1 lore raw
Quoted 27 lines · Yonatan Nachum

Change the SQ depth validation to take into account the SQ WQE size. This is needed since when using 128-byte WQE the max SQ depth is cut in half. On create QP command, userspace provides SQ ring size which is SQ depth X WQE size so we can calculate the requested WQE size in the kernel.

Fixes 40909f664d27 ("RDMA/efa: Add EFA verbs implementation")

---
Changelog:
v2:
* Add fixes line.
v1: https://lore.kernel.org/all/[email protected]/

 drivers/infiniband/hw/efa/efa_verbs.c | 39 ++++++++++++++++++---------
 1 file changed, 27 insertions(+), 12 deletions(-)
drivers/infiniband/hw/efa/efa_verbs.c +0 -0
index 395290ab0584..9a6cbb70581b 100644
@@ -597,14 +597,27 @@ static int qp_mmap_entries_setup(struct efa_qp *qp,
 	return -ENOMEM;
 }
 

drivers/infiniband/hw/efa/efa_verbs.c static int qp_mmap_entries_setup(struct efa_qp *qp, · line 609

Quoted 10 lines
drivers/infiniband/hw/efa/efa_verbs.c +10 -0
+static int efa_calc_sq_wqe_size(u32 sq_ring_size, u32 max_send_wr)
+{
+	return max_send_wr == 0 ? 0 : sq_ring_size / max_send_wr;
+}
+
+static u32 efa_calc_sq_max_depth(struct efa_dev *dev, u32 sq_wqe_size)
+{
+	return sq_wqe_size == 0 ? 0 :
+		rounddown_pow_of_two(dev->dev_attr.max_llq_size / sq_wqe_size);
+}

Please review sashiko's findings:
https://sashiko.dev/#/patchset/[email protected]

It appears that a valid input can trigger rounddown_pow_of_two(0).

Thanks