From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796487010; b=kryyewE+KAshEPLZc5ct3sJAlEJav3Axp3wxRpboUDx2AS0Dnmxj/BIGv5CeJ+Lr26wE n1bjsbVPM8cW1U2yqkxMv/WYqPi3Ejaemw2TMTHpwAFqwoQgyL7IT1CZpnqaAEc27HDz+ 9bfVX6ZV4XiX9K3A4IxOflVLe9JHg2hOpOlRPZRmQKrbmWztBDi98fQZl0XTfzzTcRoC1 xZssCT+01uH6EpdVlH/yROgqxqHpNL8CHCH3hY5B+/mkrMgAcItwW7fLhiuwLo7M6gynC kYZNKZmtRt41S1p35Xa0Ukkp+sD+VK6c5vcsHVJ7rN718AHZ0T0G3s6SRj1ZKt4y/4Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796487010; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=tFOGnCn+E6gNqKXuis7+D9Pghzs/Nfhxh581NweaEGg=; b=nuaSvSUUVYF4i0+rz7rP/psdiycxOi0CEWItJv5P0wsduIGkIQMvTfAMPM5b3gGNXNak gweQzUlIWz9E0FqHQUO1C6/rAi2rKjCaX6RTLMkqVihxby7LHcTd7yzDWeALxTcYReh8p la/BT1tWek44ok54P4SL5wqxSx9bUw8pbBhzF8GuU4bN+67di5QGRaMIzeabCUgCwkpKL pwHezNtu16Rkis1fuoEUAIOqdpP2kzO60NT+TG3QeytkopGv2hYCkb3m54ZAPCRs4aze8 qK0ogLrFjYrkvEaFiPROqcYZ80wb4//EmDUbGVawZqV9jHkdnazoUaSh/2QWWOIrycg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cUzUg65Z; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D53A606A681 for ; Sat, 5 Dec 2026 16:10:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cUzUg65Z Received: by smtp.kernel.org (Postfix) with ESMTPSA id 168901F00A13; Sat, 5 Dec 2026 16:10:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796487010; bh=tFOGnCn+E6gNqKXuis7+D9Pghzs/Nfhxh581NweaEGg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=cUzUg65ZQEld/0Mj49CMCXph9ULrH6k1b9LCAod656Ahdl7MBxzgzmQJ5U+HI8KgE Ag01NMU6IwxnK4dBuyF2NDux30OtsSq9PR1/0H8/L4tk+VelNK+AIBQ7VwO81W2dcd /ShUas8IX6AXKzClJD0/pk4H33NxV0qnXZZndIbCRGip3AuVRIri53rl4o2gxWw4+B jc4rIEF4EBspFjsJAodjsC6JO8RJqocTr/mEljVNhSHRP8uxMkk2TGlUY8X4mc7Vzu 5ug90ACiheIDVEr/jQrpUz72wlqyw8HL4A3TIIXdDB62j4e+n0OLrT2zzpTvLgPkQ2 6SVOKiueQomyw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RDMA v2 07/13] RDMA/bng_re: Add MR verbs Reply-To: sashiko-reviews@lists.linux.dev To: "Siva Reddy Kallam" Cc: linux-rdma@vger.kernel.org In-Reply-To: <20261204155249.1002019-8-siva.kallam@broadcom.com> References: <20261204155249.1002019-1-siva.kallam@broadcom.com> <20261204155249.1002019-8-siva.kallam@broadcom.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 16:10:09 +0000 X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 > 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 > Signed-off-by: Siva Reddy Kallam [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; > } > =20 > -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 =3D res->pdev; > int i; > =20 > - for (i =3D 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] =3D NULL; > + /* User-memory leaf pages belong to the umem, only coherent pages > + * allocated here are freed. > + */ > + if (!is_umem) { > + for (i =3D 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] =3D 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, str= uct bng_re_pbl *pbl) > pbl->pg_size =3D 0; > } > =20 > +/* 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 =3D 0; > + > + rdma_umem_for_each_dma_block(sginfo->umem, &biter, sginfo->pgsize) { > + pbl->pg_map_arr[i] =3D 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 =3D vmalloc_array(pages, sizeof(dma_addr_t)); > if (!pbl->pg_map_arr) { > vfree(pbl->pg_arr); > pbl->pg_arr =3D NULL; > return -ENOMEM; > } > pbl->pg_count =3D 0; > pbl->pg_size =3D sginfo->pgsize; > =20 > - for (i =3D 0; i < pages; i++) { > - pbl->pg_arr[i] =3D 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 =3D 0; i < pages; i++) { > + pbl->pg_arr[i] =3D 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 =3D 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 =3D npbl >> MAX_PDL_LVL_SHIFT; > if (npbl % BIT(MAX_PDL_LVL_SHIFT)) > npde++; > - /* Alloc PDE pages */ > - sginfo.pgsize =3D 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 =3D npde * PAGE_SIZE; > sginfo.npages =3D 1; > rc =3D 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/h= w/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 =3D {}; > + struct bng_re_sg_info sginfo =3D {}; > + struct bng_re_hwq *hwq; > + int pg_ptrs, rc; > + > + pg_ptrs =3D roundup_pow_of_two(max_pg_ptrs); > + > + sginfo.pgsize =3D PAGE_SIZE; > + sginfo.nopte =3D true; > + > + hwq_attr.res =3D res; > + hwq_attr.depth =3D pg_ptrs; > + hwq_attr.stride =3D PAGE_SIZE; [Severity: Low] Does passing hwq_attr.stride =3D 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/infiniban= d/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 =3D mr->sp_mr.lkey; > + mr->ib_mr.rkey =3D 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 len= gth, > + u64 virt_addr, int mr_access_flags, > + struct ib_dmah *dmah, > + struct ib_udata *udata) > +{ > + struct bng_re_pd *pd =3D container_of(ib_pd, struct bng_re_pd, ib_pd); > + struct bng_re_dev *rdev =3D pd->rdev; > + struct ib_umem *umem; > + struct ib_mr *ib_mr; > + int rc; > + > + rc =3D ib_is_udata_in_empty(udata); > + if (rc) > + return ERR_PTR(rc); > + > + umem =3D ib_umem_get_va(&rdev->ibdev, start, length, mr_access_flags); > + if (IS_ERR(umem)) > + return ERR_CAST(umem); > + > + ib_mr =3D __bng_re_user_reg_mr(ib_pd, length, virt_addr, mr_access_flag= s, 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 =3D container_of(ib_pd, struct bng_re_pd, ib_pd); > + struct bng_re_dev *rdev =3D 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 =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204155249.1002= 019-1-siva.kallam@broadcom.com?part=3D7