All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Siva Reddy Kallam" <siva.kallam@broadcom.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [RDMA v2 07/13] RDMA/bng_re: Add MR verbs
Date: Sat, 05 Dec 2026 16:10:09 +0000	[thread overview]
Message-ID: <sashiko-outbox-251731@kernel.org> (raw)
In-Reply-To: <20261204155249.1002019-8-siva.kallam@broadcom.com>

Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [Medium] RDMA/bng_re: hardcoded 4 KiB PBL sizing mismatches PAGE_SIZE
  allocations
- [Medium] RDMA/bng_re: user MR retains unused leaf pg_map_arr vmalloc
  array for lifetime
- [Medium] RDMA/bng_re: __bng_re_user_reg_mr() leaves ib_mr.iova and
  length zero
- [Medium] RDMA/bng_re: incomplete udata validation in user MR
  registration verbs
- [Medium] RDMA/bng_re: missing cond_resched() in large user MR PBL/PTE
  loops
- [Low] RDMA/bng_re: omit pci_channel_offline() RCFW change from commit
  message
- [Low] RDMA/bng_re: PAGE_SIZE stride truncates u16 hwq->element_size on
  64K pages
--

commit 10686ef14670168e01b111081ed6413724fe2f59
Author: Suresh Rupanagudi <suresh.rupanagudi@broadcom.com>

> RDMA/bng_re: Add MR verbs
>
> This patch adds below verbs.
> - bng_re_get_dma_mr
> - bng_re_alloc_mr
> - bng_re_map_mr_sg
> - bng_re_reg_user_mr
> - bng_re_reg_user_mr_dmabuf
> - bng_re_dereg_mr
>
> Signed-off-by: Suresh Rupanagudi <suresh.rupanagudi@broadcom.com>
> Signed-off-by: Siva Reddy Kallam <siva.kallam@broadcom.com>

[Severity: Low]
Should the commit message mention the bng_fw.c change, or should it be
split into a separate patch?

In addition to adding the MR verbs, this patch adds a
pci_channel_offline() check returning -ENXIO in
__send_message_basic_sanity().  In bng_re_rcfw_send_message(), that
activates bng_re_map_rc(opcode), changing offline error handling across
all firmware opcodes so teardown commands return 0 immediately and other
commands fail fast with -ETIMEDOUT.

[ ... ]

> diff --git a/drivers/infiniband/hw/bng_re/bng_res.c b/drivers/infiniband/hw/bng_re/bng_res.c
> index 471f3bfb71f73..47cea41150ba2 100644
> --- a/drivers/infiniband/hw/bng_re/bng_res.c
> +++ b/drivers/infiniband/hw/bng_re/bng_res.c

[ ... ]

> @@ -37,22 +38,28 @@ int bng_re_alloc_stats_ctx_mem(struct pci_dev *pdev,
>  	return 0;
>  }
>  
> -static void bng_free_pbl(struct bng_re_res  *res, struct bng_re_pbl *pbl)
> +static void bng_free_pbl(struct bng_re_res  *res, struct bng_re_pbl *pbl,
> +			 bool is_umem)
>  {
>  	struct pci_dev *pdev = res->pdev;
>  	int i;
>  
> -	for (i = 0; i < pbl->pg_count; i++) {
> -		if (pbl->pg_arr[i])
> -			dma_free_coherent(&pdev->dev, pbl->pg_size,
> -					  (void *)((unsigned long)
> -					     pbl->pg_arr[i] &
> -						PAGE_MASK),
> -					  pbl->pg_map_arr[i]);
> -		else
> -			dev_warn(&pdev->dev,
> -				 "PBL free pg_arr[%d] empty?!\n", i);
> -		pbl->pg_arr[i] = NULL;
> +	/* User-memory leaf pages belong to the umem, only coherent pages
> +	 * allocated here are freed.
> +	 */
> +	if (!is_umem) {
> +		for (i = 0; i < pbl->pg_count; i++) {
> +			if (pbl->pg_arr[i])
> +				dma_free_coherent(&pdev->dev, pbl->pg_size,
> +						  (void *)((unsigned long)
> +							pbl->pg_arr[i] &
> +							PAGE_MASK),
> +						  pbl->pg_map_arr[i]);
> +			else
> +				dev_warn(&pdev->dev,
> +					 "PBL free pg_arr[%d] empty?!\n", i);
> +			pbl->pg_arr[i] = NULL;
> +		}
>  	}

[Severity: Medium]
Can these PBL and PTE loops trigger soft lockups on large user MRs?

__bng_re_user_reg_mr() allows MRs up to BNG_RE_MAX_MR_SIZE (512 GiB).
When such an MR falls back to 4 KiB pages, bng_free_pbl() and
bng_alloc_pbl() iterate up to 262,144 coherent DMA allocations/frees,
while bng_fill_user_dma_pages() and the PTE copy loop in
bng_re_alloc_init_hwq() iterate up to 134,217,728 times without calling
cond_resched().

On CONFIG_PREEMPT_NONE or CONFIG_PREEMPT_VOLUNTARY kernels, those
unbounded loops can stall the CPU for seconds during registration or
deregistration.  Adding periodic cond_resched() calls in these four loops
would avoid soft lockups.

[ ... ]

> @@ -63,22 +70,46 @@ static void bng_free_pbl(struct bng_re_res  *res, struct bng_re_pbl *pbl)
>  	pbl->pg_size = 0;
>  }
>  
> +/* Use the DMA address of each pinned user block as a leaf page */
> +static void bng_fill_user_dma_pages(struct bng_re_pbl *pbl,
> +				    struct bng_re_sg_info *sginfo)
> +{
> +	struct ib_block_iter biter;
> +	int i = 0;
> +
> +	rdma_umem_for_each_dma_block(sginfo->umem, &biter, sginfo->pgsize) {
> +		pbl->pg_map_arr[i] = rdma_block_iter_dma_address(&biter);
> +		pbl->pg_count++;
> +		i++;
> +	}
> +}
> +
>  static int bng_alloc_pbl(struct bng_re_res  *res,
>  			 struct bng_re_pbl *pbl,
>  			 struct bng_re_sg_info *sginfo)
>  {

[ ... ]

>  	pbl->pg_map_arr = vmalloc_array(pages, sizeof(dma_addr_t));
>  	if (!pbl->pg_map_arr) {
>  		vfree(pbl->pg_arr);
>  		pbl->pg_arr = NULL;
>  		return -ENOMEM;
>  	}
>  	pbl->pg_count = 0;
>  	pbl->pg_size = sginfo->pgsize;
>  
> -	for (i = 0; i < pages; i++) {
> -		pbl->pg_arr[i] = dma_alloc_coherent(&pdev->dev,
> -						    pbl->pg_size,
> -						    &pbl->pg_map_arr[i],
> -						    GFP_KERNEL);
> -		if (!pbl->pg_arr[i])
> -			goto fail;
> -		pbl->pg_count++;
> +	if (!sginfo->umem) {
> +		for (i = 0; i < pages; i++) {
> +			pbl->pg_arr[i] = dma_alloc_coherent(&pdev->dev,
> +							    pbl->pg_size,
> +							    &pbl->pg_map_arr[i],
> +							    GFP_KERNEL);
> +			if (!pbl->pg_arr[i])
> +				goto fail;
> +			pbl->pg_count++;
> +		}
> +	} else {
> +		is_umem = true;
> +		bng_fill_user_dma_pages(pbl, sginfo);
>  	}

[Severity: Medium]
Does a multi-page user MR need to keep its leaf pg_map_arr allocated for
the lifetime of the MR?

For multi-page user MRs, bng_alloc_pbl() allocates an O(npages)
vmalloc_array() for the leaf level and bng_re_alloc_init_hwq() copies its
entries into the coherent PBL pages, after which only
hwq.pbl[BNG_PBL_LVL_0].pg_map_arr[0] is ever read by bng_sp_reg_mr().
Retaining the unused leaf array until bng_re_dereg_mr() doubles kernel
memory overhead (up to 1 GiB for a 512 GiB 4 KiB-paged MR) and adds an
extra linear pass plus a large vfree() on teardown.

Populating the coherent PBL pages directly while iterating
rdma_umem_for_each_dma_block() (or freeing the leaf pg_map_arr after
copying) would avoid this overhead.

[ ... ]

> @@ -171,8 +218,11 @@ int bng_re_alloc_init_hwq(struct bng_re_hwq *hwq,
>  			npde = npbl >> MAX_PDL_LVL_SHIFT;
>  			if (npbl % BIT(MAX_PDL_LVL_SHIFT))
>  				npde++;
> -			/* Alloc PDE pages */
> -			sginfo.pgsize = npde * pg_size;
> +			/* Alloc PDE pages. The PDE and PBL levels always use the
> +			 * system page size, only the leaf pages of a user MR use
> +			 * the (possibly much larger) buffer page size.
> +			 */
> +			sginfo.pgsize = npde * PAGE_SIZE;
>  			sginfo.npages = 1;
>  			rc = bng_alloc_pbl(res, &hwq->pbl[BNG_PBL_LVL_0], &sginfo);
>  			if (rc)

[Severity: Medium]
Do MAX_PBL_LVL_1_PGS, MAX_PBL_LVL_1_PGS_SHIFT, and MAX_PDL_LVL_SHIFT
mismatch the PAGE_SIZE PBL allocations on non-4 KiB page kernels?

bng_re_alloc_init_hwq() allocates PDE and PBL pages in units of PAGE_SIZE,
indexes them with PTR_CNT_PER_PG (PAGE_SIZE / sizeof(void *)), and
bng_sp_reg_mr() programs req.log2_pbl_pg_size with ilog2(PAGE_SIZE).
However, the level selection and npbl/npde calculations still use the
hardcoded 4 KiB constants (512 entries / shift 9).

On a 64 KiB PAGE_SIZE kernel, user MRs with 513 to 8192 pages are
needlessly promoted to 2-level page tables, and 2-level MRs over-allocate
coherent PBL pages by 16x and contiguous PDE buffers by up to 256x,
risking premature dma_alloc_coherent() failures.

[ ... ]

> diff --git a/drivers/infiniband/hw/bng_re/bng_sp.c b/drivers/infiniband/hw/bng_re/bng_sp.c
> index 786d591a91b3e..caa5ff44d99c6 100644
> --- a/drivers/infiniband/hw/bng_re/bng_sp.c
> +++ b/drivers/infiniband/hw/bng_re/bng_sp.c

[ ... ]

> +int bng_sp_alloc_fast_reg_page_list(struct bng_re_res *res,
> +				    struct bng_re_frpl *frpl,
> +				    int max_pg_ptrs)
> +{
> +	struct bng_re_hwq_attr hwq_attr = {};
> +	struct bng_re_sg_info sginfo = {};
> +	struct bng_re_hwq *hwq;
> +	int pg_ptrs, rc;
> +
> +	pg_ptrs = roundup_pow_of_two(max_pg_ptrs);
> +
> +	sginfo.pgsize = PAGE_SIZE;
> +	sginfo.nopte = true;
> +
> +	hwq_attr.res = res;
> +	hwq_attr.depth = pg_ptrs;
> +	hwq_attr.stride = PAGE_SIZE;

[Severity: Low]
Does passing hwq_attr.stride = PAGE_SIZE truncate hwq->element_size to 0
on 64 KiB page kernels?

bng_re_alloc_init_hwq() assigns stride to hwq->element_size, which is a
u16 in struct bng_re_hwq even though qe_ppg was widened to u32.  On
64 KiB PAGE_SIZE systems, 65536 wraps to 0; widening element_size to u32
would prevent the truncation.

[ ... ]

> diff --git a/drivers/infiniband/hw/bng_re/bng_verbs.c b/drivers/infiniband/hw/bng_re/bng_verbs.c
> index 95317907d6125..4eb69c1bd8737 100644
> --- a/drivers/infiniband/hw/bng_re/bng_verbs.c
> +++ b/drivers/infiniband/hw/bng_re/bng_verbs.c

[ ... ]

> +	mr->ib_mr.lkey = mr->sp_mr.lkey;
> +	mr->ib_mr.rkey = mr->sp_mr.lkey;
> +
> +	return &mr->ib_mr;

[Severity: Medium]
Should __bng_re_user_reg_mr() also initialize mr->ib_mr.iova and
mr->ib_mr.length?

Neither UVERBS_METHOD_REG_DMABUF_MR nor UVERBS_METHOD_REG_MR sets those
fields after calling the driver, so both stay 0 on ioctl-registered MRs.
UVERBS_METHOD_QUERY_MR then reports 0 for length and iova to userspace,
and RDMA netlink restrack exports RDMA_NLDEV_ATTR_RES_MRLEN as 0.

[ ... ]

> +struct ib_mr *bng_re_reg_user_mr(struct ib_pd *ib_pd, u64 start, u64 length,
> +				 u64 virt_addr, int mr_access_flags,
> +				 struct ib_dmah *dmah,
> +				 struct ib_udata *udata)
> +{
> +	struct bng_re_pd *pd = container_of(ib_pd, struct bng_re_pd, ib_pd);
> +	struct bng_re_dev *rdev = pd->rdev;
> +	struct ib_umem *umem;
> +	struct ib_mr *ib_mr;
> +	int rc;
> +
> +	rc = ib_is_udata_in_empty(udata);
> +	if (rc)
> +		return ERR_PTR(rc);
> +
> +	umem = ib_umem_get_va(&rdev->ibdev, start, length, mr_access_flags);
> +	if (IS_ERR(umem))
> +		return ERR_CAST(umem);
> +
> +	ib_mr = __bng_re_user_reg_mr(ib_pd, length, virt_addr, mr_access_flags, umem);
> +	if (IS_ERR(ib_mr))
> +		ib_umem_release(umem);
> +	return ib_mr;
> +}
> +
> +struct ib_mr *bng_re_reg_user_mr_dmabuf(struct ib_pd *ib_pd, u64 start,
> +					u64 length, u64 virt_addr, int fd,
> +					int mr_access_flags,
> +					struct ib_dmah *dmah,
> +					struct uverbs_attr_bundle *attrs)
> +{
> +	struct bng_re_pd *pd = container_of(ib_pd, struct bng_re_pd, ib_pd);
> +	struct bng_re_dev *rdev = pd->rdev;
> +	struct ib_umem_dmabuf *umem_dmabuf;
> +	struct ib_umem *umem;
> +	struct ib_mr *ib_mr;
> +
> +	ibdev_dbg(&rdev->ibdev, "Register user DMA-BUF MR\n");
> +
> +	umem_dmabuf = ib_umem_dmabuf_get_pinned(&rdev->ibdev, start, length,
> +						fd, mr_access_flags);
> +	if (IS_ERR(umem_dmabuf))
> +		return ERR_CAST(umem_dmabuf);

[Severity: Medium]
Should bng_re_reg_user_mr() and bng_re_reg_user_mr_dmabuf() validate and
zero driver udata with ib_no_udata_io()?

bng_re_reg_user_mr() only calls ib_is_udata_in_empty(udata), leaving
udata->outbuf unzeroed even though uverbs_ioctl.c marks UVERBS_ATTR_UHW_OUT
valid on success.  bng_re_reg_user_mr_dmabuf() does not check
&attrs->driver_udata at all, so UVERBS_METHOD_REG_MR with a DMA-BUF fd
silently accepts non-zero driver input udata instead of returning
-EOPNOTSUPP and also leaves output udata unzeroed.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204155249.1002019-1-siva.kallam@broadcom.com?part=7

  reply	other threads:[~2026-12-05 16:10 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 15:47 [RDMA v2 00/13] Add BNG_RE control path verbs Siva Reddy Kallam
2026-12-04 15:47 ` [RDMA v2 01/13] bnge: Keep the RoCE MSI-X minimum for the MPC vector Siva Reddy Kallam
2026-12-04 15:47 ` [RDMA v2 02/13] RDMA/bng_re: Add MPC, XID management, doorbell infrastructure Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-04 15:47 ` [RDMA v2 03/13] RDMA/bng_re: Add support verbs Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-04 15:47 ` [RDMA v2 04/13] RDMA/bng_re: Add ucontext/mmap verbs Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-04 15:47 ` [RDMA v2 05/13] RDMA/bng_re: Add GID verbs Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-04 15:47 ` [RDMA v2 06/13] RDMA/bng_re: Add PD verbs Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-04 15:47 ` [RDMA v2 07/13] RDMA/bng_re: Add MR verbs Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot [this message]
2026-12-04 15:48 ` [RDMA v2 08/13] RDMA/bng_re: Add CQ verbs Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-04 15:48 ` [RDMA v2 09/13] RDMA/bng_re: Add SRQ verbs Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-04 15:48 ` [RDMA v2 10/13] RDMA/bng_re: Add Stats verbs Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-04 15:48 ` [RDMA v2 11/13] RDMA/bng_re: Add AH verbs Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-04 15:48 ` [RDMA v2 12/13] RDMA/bng_re: Add QP verbs Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-04 15:48 ` [RDMA v2 13/13] RDMA/bng_re: Register with ib-core Siva Reddy Kallam
2026-12-05 16:10   ` sashiko-bot
2026-12-05 16:10 ` [RDMA v2 00/13] Add BNG_RE control path verbs sashiko-bot

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=sashiko-outbox-251731@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=siva.kallam@broadcom.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.