All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: lirongqing <lirongqing@baidu.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>, linux-rdma@vger.kernel.org
Subject: Re: [PATCH] RDMA/mlx5: Fix CQ resize destination index mask
Date: Mon, 28 Sep 2026 21:34:03 +0300	[thread overview]
Message-ID: <20260928183403.GY563127@unreal> (raw)
In-Reply-To: <20260919100716.2221-1-lirongqing@baidu.com>

On Sat, Sep 19, 2026 at 06:07:16PM +0800, lirongqing wrote:
> From: Li RongQing <lirongqing@baidu.com>
> 
> In copy_resize_cqes, the destination CQE index is computed as
> (i + 1) & cq->resize_buf->nent, but resize_buf->nent is the power-of-two
> entry count, so the mask only yields 0 or nent -- and nent is one past the
> last valid slot. The following memcpy then writes out of bounds.
> 
> Use (nent - 1) as the wrap mask, consistent with get_sw_cqe which masks
> against cq->ibcq.cqe (the nent - 1 value).
> 
> Fixes: bde51583f49b ("IB/mlx5: Add support for resize CQ")
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
>  drivers/infiniband/hw/mlx5/cq.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/infiniband/hw/mlx5/cq.c b/drivers/infiniband/hw/mlx5/cq.c
> index b0b1177..5bd5227 100644
> --- a/drivers/infiniband/hw/mlx5/cq.c
> +++ b/drivers/infiniband/hw/mlx5/cq.c
> @@ -1319,7 +1319,7 @@ static int copy_resize_cqes(struct mlx5_ib_cq *cq)
>  
>  	while (get_cqe_opcode(scqe64) != MLX5_CQE_RESIZE_CQ) {
>  		dcqe = mlx5_frag_buf_get_wqe(&cq->resize_buf->fbc,
> -					     (i + 1) & cq->resize_buf->nent);
> +					     (i + 1) & (cq->resize_buf->nent - 1));

I think the original intent was to use `(i + 1) % cq->resize_buf->nent`.

Thanks

>  		dcqe64 = dsize == 64 ? dcqe : dcqe + 64;
>  		sw_own = sw_ownership_bit(i + 1, cq->resize_buf->nent);
>  		memcpy(dcqe, scqe, dsize);
> -- 
> 2.9.4
> 

  parent reply	other threads:[~2026-09-28 18:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-19 10:07 [PATCH] RDMA/mlx5: Fix CQ resize destination index mask lirongqing
2026-09-19 10:14 ` sashiko-bot
2026-09-28 18:34 ` Leon Romanovsky [this message]
2026-09-29  1:06   ` 答复: [????] " Li,Rongqing
2026-09-30 12:24     ` Leon Romanovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260928183403.GY563127@unreal \
    --to=leon@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=linux-rdma@vger.kernel.org \
    --cc=lirongqing@baidu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.