Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH for-next] RDMA/efa: Validate SQ depth based on WQE size
@ 2026-05-07 11:21 Yonatan Nachum
  2026-05-13 17:38 ` Leon Romanovsky
  0 siblings, 1 reply; 5+ messages in thread
From: Yonatan Nachum @ 2026-05-07 11:21 UTC (permalink / raw)
  To: jgg, leon, linux-rdma
  Cc: mrgolin, sleybo, matua, gal.pressman, Daniel Kranzdorf,
	Yonatan Nachum

From: Michael Margolin <mrgolin@amazon.com>

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.

Reviewed-by: Daniel Kranzdorf <dkkranzd@amazon.com>
Reviewed-by: Michael Margolin <mrgolin@amazon.com>
Signed-off-by: Yonatan Nachum <ynachum@amazon.com>
---
 drivers/infiniband/hw/efa/efa_verbs.c | 39 ++++++++++++++++++---------
 1 file changed, 27 insertions(+), 12 deletions(-)

diff --git a/drivers/infiniband/hw/efa/efa_verbs.c b/drivers/infiniband/hw/efa/efa_verbs.c
index 7bd0838ebc99..eb95ed4e25f7 100644
--- a/drivers/infiniband/hw/efa/efa_verbs.c
+++ b/drivers/infiniband/hw/efa/efa_verbs.c
@@ -612,14 +612,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) {
@@ -686,19 +699,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;
@@ -720,6 +726,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;
 
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH for-next] RDMA/efa: Validate SQ depth based on WQE size
  2026-05-07 11:21 [PATCH for-next] RDMA/efa: Validate SQ depth based on WQE size Yonatan Nachum
@ 2026-05-13 17:38 ` Leon Romanovsky
  2026-05-13 19:24   ` Yonatan Nachum
  0 siblings, 1 reply; 5+ messages in thread
From: Leon Romanovsky @ 2026-05-13 17:38 UTC (permalink / raw)
  To: Yonatan Nachum
  Cc: jgg, linux-rdma, mrgolin, sleybo, matua, gal.pressman,
	Daniel Kranzdorf

On Thu, May 07, 2026 at 11:21:10AM +0000, Yonatan Nachum wrote:
> From: Michael Margolin <mrgolin@amazon.com>
> 
> 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.
> 
> Reviewed-by: Daniel Kranzdorf <dkkranzd@amazon.com>
> Reviewed-by: Michael Margolin <mrgolin@amazon.com>
> Signed-off-by: Yonatan Nachum <ynachum@amazon.com>
> ---
>  drivers/infiniband/hw/efa/efa_verbs.c | 39 ++++++++++++++++++---------
>  1 file changed, 27 insertions(+), 12 deletions(-)

Please add Fixes line.

Thanks

> 
> diff --git a/drivers/infiniband/hw/efa/efa_verbs.c b/drivers/infiniband/hw/efa/efa_verbs.c
> index 7bd0838ebc99..eb95ed4e25f7 100644
> --- a/drivers/infiniband/hw/efa/efa_verbs.c
> +++ b/drivers/infiniband/hw/efa/efa_verbs.c
> @@ -612,14 +612,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) {
> @@ -686,19 +699,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;
> @@ -720,6 +726,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;
>  
> -- 
> 2.50.1
> 
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH for-next] RDMA/efa: Validate SQ depth based on WQE size
  2026-05-13 17:38 ` Leon Romanovsky
@ 2026-05-13 19:24   ` Yonatan Nachum
  2026-05-14 16:28     ` Leon Romanovsky
  0 siblings, 1 reply; 5+ messages in thread
From: Yonatan Nachum @ 2026-05-13 19:24 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: jgg, linux-rdma, mrgolin, sleybo, matua, gal.pressman,
	Daniel Kranzdorf

On Wed, May 13, 2026 at 08:38:12PM +0300, Leon Romanovsky wrote:
> On Thu, May 07, 2026 at 11:21:10AM +0000, Yonatan Nachum wrote:
> > From: Michael Margolin <mrgolin@amazon.com>
> > 
> > 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.
> > 
> > Reviewed-by: Daniel Kranzdorf <dkkranzd@amazon.com>
> > Reviewed-by: Michael Margolin <mrgolin@amazon.com>
> > Signed-off-by: Yonatan Nachum <ynachum@amazon.com>
> > ---
> >  drivers/infiniband/hw/efa/efa_verbs.c | 39 ++++++++++++++++++---------
> >  1 file changed, 27 insertions(+), 12 deletions(-)
> 
> Please add Fixes line.
> 
> Thanks

There is no Fixes tag as this is not a bug fix. The existing validation
works but is overly permissive — it doesn't account for WQE size when
checking max SQ depth. Without it, the device would reject the request
downstream. This patch tightens the validation to fail early in the
kernel.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH for-next] RDMA/efa: Validate SQ depth based on WQE size
  2026-05-13 19:24   ` Yonatan Nachum
@ 2026-05-14 16:28     ` Leon Romanovsky
  2026-05-14 20:45       ` Yonatan Nachum
  0 siblings, 1 reply; 5+ messages in thread
From: Leon Romanovsky @ 2026-05-14 16:28 UTC (permalink / raw)
  To: Yonatan Nachum
  Cc: jgg, linux-rdma, mrgolin, sleybo, matua, gal.pressman,
	Daniel Kranzdorf

On Wed, May 13, 2026 at 07:24:51PM +0000, Yonatan Nachum wrote:
> On Wed, May 13, 2026 at 08:38:12PM +0300, Leon Romanovsky wrote:
> > On Thu, May 07, 2026 at 11:21:10AM +0000, Yonatan Nachum wrote:
> > > From: Michael Margolin <mrgolin@amazon.com>
> > > 
> > > 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.
> > > 
> > > Reviewed-by: Daniel Kranzdorf <dkkranzd@amazon.com>
> > > Reviewed-by: Michael Margolin <mrgolin@amazon.com>
> > > Signed-off-by: Yonatan Nachum <ynachum@amazon.com>
> > > ---
> > >  drivers/infiniband/hw/efa/efa_verbs.c | 39 ++++++++++++++++++---------
> > >  1 file changed, 27 insertions(+), 12 deletions(-)
> > 
> > Please add Fixes line.
> > 
> > Thanks
> 
> There is no Fixes tag as this is not a bug fix. The existing validation
> works but is overly permissive — it doesn't account for WQE size when
> checking max SQ depth. Without it, the device would reject the request
> downstream. This patch tightens the validation to fail early in the
> kernel.

So why do we need kernel patch after all?

Thanks

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH for-next] RDMA/efa: Validate SQ depth based on WQE size
  2026-05-14 16:28     ` Leon Romanovsky
@ 2026-05-14 20:45       ` Yonatan Nachum
  0 siblings, 0 replies; 5+ messages in thread
From: Yonatan Nachum @ 2026-05-14 20:45 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: jgg, linux-rdma, mrgolin, sleybo, matua, gal.pressman,
	Daniel Kranzdorf

On Thu, May 14, 2026 at 07:28:12PM +0300, Leon Romanovsky wrote:
> On Wed, May 13, 2026 at 07:24:51PM +0000, Yonatan Nachum wrote:
> > On Wed, May 13, 2026 at 08:38:12PM +0300, Leon Romanovsky wrote:
> > > On Thu, May 07, 2026 at 11:21:10AM +0000, Yonatan Nachum wrote:
> > > > From: Michael Margolin <mrgolin@amazon.com>
> > > > 
> > > > 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.
> > > > 
> > > > Reviewed-by: Daniel Kranzdorf <dkkranzd@amazon.com>
> > > > Reviewed-by: Michael Margolin <mrgolin@amazon.com>
> > > > Signed-off-by: Yonatan Nachum <ynachum@amazon.com>
> > > > ---
> > > >  drivers/infiniband/hw/efa/efa_verbs.c | 39 ++++++++++++++++++---------
> > > >  1 file changed, 27 insertions(+), 12 deletions(-)
> > > 
> > > Please add Fixes line.
> > > 
> > > Thanks
> > 
> > There is no Fixes tag as this is not a bug fix. The existing validation
> > works but is overly permissive — it doesn't account for WQE size when
> > checking max SQ depth. Without it, the device would reject the request
> > downstream. This patch tightens the validation to fail early in the
> > kernel.
> 
> So why do we need kernel patch after all?
> 
> Thanks

The driver already validates max_send_wr against max_sq_depth — this
patch just makes that check accurate for the 128-byte WQE case. This
also gives better error reporting as opposed to device failure.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-05-14 20:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-07 11:21 [PATCH for-next] RDMA/efa: Validate SQ depth based on WQE size Yonatan Nachum
2026-05-13 17:38 ` Leon Romanovsky
2026-05-13 19:24   ` Yonatan Nachum
2026-05-14 16:28     ` Leon Romanovsky
2026-05-14 20:45       ` Yonatan Nachum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox