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=1796487011; b=GJWL/Zzxdmtw/uE1qKBXVyY6zhTRkpP4FR23CN5PAvFEprrtixsQMlzC9QXtfiosERTu KD03hRFmjCTifj0WOkEwTJNq38Z8x2Q2C90iByD23n1sXDCvaS9oa/uH6rr+fdccAtfVw PeEUMJsxIkK4TG0FxNC2nNusiK80jgF/8kD53fwUPztCHABCne5vEkXs0YC7mdgP5RZkn /Nv6nX4163eh4u/pViYS1EQdIMRrKsJJsgyxYhjIvJwuvCvyS8GS6EiHVe4gzq3nLAYHv efCDguvijFRlr2ZK+Zl80XbCk+gqpBYimfFm8WoskEdBQLkUqhI+uawmW17WtQ2xl8g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796487011; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=lXcVc8HQAnR5UEPupabsDLl2D9pT30ujenJaFmWg4nA=; b=4W7bbM1kltW8RxaEgA8j5h9OfoNNJ96r1X6M72cnzjq2JK3SOgh3itE+sNyb081jrSRg 0MTZX2emXXjmInzpoAabbBVMcst98MCniOVkwnWXFwpETZjBwY25a0iEZ497mAohIglqB e9/BK+Qa/C+PasfS0mhfxewrz549M0fmeMPHvvirQbfnWpgxet/zhXaA3PjJE7K8Fg2Lk QS8X1FTxqL0KNljCmzCDWMFMeEdDdJoHcYn1g5jo7jjFIciJYKXp9GBFhZs4XeVzAp/cj v19iau+dy2N1hbA7yips3rW8xQQJ7XK5adLKqm77kHSQMxjelv/ty7uCuPQT4xkUvJg== 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=T5R+jTfH; 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 E3B80606A337 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=T5R+jTfH Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EA0A1F00A12; 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=lXcVc8HQAnR5UEPupabsDLl2D9pT30ujenJaFmWg4nA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=T5R+jTfHafvrHvU7tBMfkP8YOCFpAmaguoN3X1aSn+vHwfY5R8DFiL4wiTaVB/bR0 NBTJy46mTIW9pgIjw1qrfpzPFLfW0wcWkucgnHuMjazzr2NiLUcozNwGiHr71pPz7r EtEfveQipv8NR8XPIfXlAvN8t2ry0y4NXrVggOlS1H4KzR+j47pfe8lCu1mIGzYyMJ 8EkKL5AhM87VQA0vgVGWhFeutF8O80l9awVjmXP4qKGxpX5wZh5lm8qQn/iKKt1IWy xdoWgw8e/JoHPruYprZW/UzPU0p3hJ/YoYQ9hw42QzwYEx5LwhUKACBoEi3ORHpmoj 1h+CUqx7nWeHQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RDMA v2 08/13] RDMA/bng_re: Add CQ verbs Reply-To: sashiko-reviews@lists.linux.dev To: "Siva Reddy Kallam" Cc: linux-rdma@vger.kernel.org In-Reply-To: <20261204155249.1002019-9-siva.kallam@broadcom.com> References: <20261204155249.1002019-1-siva.kallam@broadcom.com> <20261204155249.1002019-9-siva.kallam@broadcom.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 16:10:10 +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 13 potential issues to consider: - [Critical] RDMA/bng_re: bng_re_base_pg_size() misprograms CQ page size for DMA - [High] RDMA/bng_re: NQ page size mismatch in bng_fp_alloc_nq() on 16KB kernels - [High] RDMA/bng_re: premature CQ publication and arming in bng_sp_create_cq() - [High] RDMA/bng_re: unbounded user CQ umem length in bng_re_create_user_cq() - [Medium] RDMA/bng_re: unconditional wake_up_var() in bng_fp_process_cqn() - [Medium] RDMA/bng_re: cross-CPU false sharing between adjacent struct bng_re_nq - [Medium] RDMA/bng_re: TOCTOU on bng_re_fw_may_own() leaks CQ HWQ on timeout - [Medium] RDMA/bng_re: unused req.cq_handle not checked for zero in bng_re_create_user_cq() - [Medium] RDMA/bng_re: bng_re_destroy_cq() permanently detaches NQ before DESTROY_CQ - [Low] RDMA/bng_re: incomplete commit message omits poll_cq, NQ, and DPI changes - [Low] RDMA/bng_re: unlocked data race on cq->umem in poll_cq and req_notify_cq - [Low] RDMA/bng_re: signed %d format used for unsigned cqe and max_cq_wqes - [Low] RDMA/bng_re: bng_re_resize_cq() maps CQ umem DMA_BIDIRECTIONAL -- commit 6d7c1df66e446f6918ce1708b4653963d65c8476 Author: Siva Reddy Kallam > RDMA/bng_re: Add CQ verbs > > This patch adds below verbs. > - bng_re_create_cq > - bng_re_create_user_cq > - bng_re_resize_cq > - bng_re_req_notify_cq > - bng_re_destroy_cq > > Signed-off-by: Siva Reddy Kallam [Severity: Low] This isn't a bug, but the commit message omits several major additions in this patch: bng_re_pre_destroy_cq and bng_re_poll_cq (including that kernel CQE polling is deferred), the fast-path NQ allocation and IRQ servicing in bng_fp.c/bng_fp.h, privileged DPI allocation in bng_re_dev_init() and bng_re_dev_uninit(), and the max_cq_wqes clamping in bng_re_get_dev_attr(). [ ... ] > diff --git a/drivers/infiniband/hw/bng_re/bng_fp.c b/drivers/infiniband/h= w/bng_re/bng_fp.c > new file mode 100644 > index 0000000000000..73b3595940dce > --- /dev/null > +++ b/drivers/infiniband/hw/bng_re/bng_fp.c [ ... ] > + /* Call the ULP unlocked; nq_users makes untrack wait for it */ > + atomic_inc(&sp_cq->nq_users); > + spin_unlock_bh(&nq->hwq.lock); > + cq->ib_cq.comp_handler(&cq->ib_cq, cq->ib_cq.cq_context); > + if (atomic_dec_and_test(&sp_cq->nq_users)) > + wake_up_var(&sp_cq->nq_users); > + spin_lock_bh(&nq->hwq.lock); > +} [Severity: Medium] Does this invoke wake_up_var() on every CQ completion notification? sp_cq->nq_users starts at 0 and has no 1-bias while the CQ is tracked, so atomic_dec_and_test() transitions 1 -> 0 and calls wake_up_var() on every notification, hashing into the global bit_wait_table and touching a shared cacheline (and bucket spinlock on collisions). Initializing nq_users to 1 when tracking the CQ and dropping that bias once in bng_sp_cq_untrack() after xa_erase_bh() keeps wake_up_var() off the hot path. [ ... ] > + sginfo.pgsize =3D PAGE_SIZE; > + sginfo.pgshft =3D PAGE_SHIFT; > + hwq_attr.res =3D res; > + hwq_attr.sginfo =3D &sginfo; > + hwq_attr.depth =3D nq->hwq.max_elements; > + hwq_attr.stride =3D sizeof(struct nq_base); > + hwq_attr.type =3D BNG_HWQ_TYPE_QUEUE; > + if (bng_re_alloc_init_hwq(&nq->hwq, &hwq_attr)) { [Severity: High] Can this mismatch the NQ page size programmed into firmware on 16KB PAGE_SIZE kernels? bng_fp_alloc_nq_res() registers the ring with bng_re_net_ring_alloc(), which programs req.page_size =3D BNGE_PAGE_SHIFT. On 16KB kernels (PAGE_SHIFT = =3D=3D 14), drivers/net/ethernet/broadcom/bnge/bnge_rmem.h defines BNGE_PAGE_SHIFT as 13 (8KB): drivers/net/ethernet/broadcom/bnge/bnge_rmem.h: #elif (PAGE_SHIFT < 16) #define BNGE_PAGE_SHIFT 13 For a 128K-entry NQ, bng_re_alloc_init_hwq() allocates 128 16KB pages (qe_ppg =3D 1024), while hardware expects 256 8KB pages (512 NQEs per page). CQ notifications stall after 512 NQEs, and once hardware advances past 65,536 NQEs it walks unpopulated zeroed PBL entries. [ ... ] > diff --git a/drivers/infiniband/hw/bng_re/bng_re.h b/drivers/infiniband/h= w/bng_re/bng_re.h > index b55658f3ab8ea..c290f015c82d5 100644 > --- a/drivers/infiniband/hw/bng_re/bng_re.h > +++ b/drivers/infiniband/hw/bng_re/bng_re.h [ ... ] > @@ -224,12 +228,14 @@ struct bng_re_nq { > u16 ring_id; > int msix_vec; > cpumask_t mask; > - struct tasklet_struct nq_tasklet; > + /* Services the NQ in softirq context, on system_bh_wq */ > + struct work_struct nq_work; > bool requested; > int budget; > u32 load; > - > - struct workqueue_struct *cqn_wq; > + /* CQ notification handle -> struct bng_sp_cq */ > + struct xarray cq_xa; > + u32 cq_xa_next; > }; [Severity: Medium] Can adjacent elements of rdev->nqr->nq[] suffer cross-CPU false sharing? struct bng_re_nq is embedded back-to-back in struct bng_re_nq_record::nq[] without ____cacheline_aligned_in_smp. With hwq.lock now at the start of struct bng_re_hwq (offset 24 in struct bng_re_nq), common CONFIG_NR_CPUS values make sizeof(struct bng_re_nq) a non-multiple of the cacheline size, putting nq[i].nq_work and nq[i].cq_xa on the same cacheline as nq[i + 1].hwq.lock and causing cacheline ping-pong when adjacent NQs are serviced concurrently. [ ... ] > diff --git a/drivers/infiniband/hw/bng_re/bng_res.h b/drivers/infiniband/= hw/bng_re/bng_res.h > index d7643a8472040..93df8af08a54f 100644 > --- a/drivers/infiniband/hw/bng_re/bng_res.h > +++ b/drivers/infiniband/hw/bng_re/bng_res.h [ ... ] > +static inline u8 bng_re_base_pg_size(struct bng_re_hwq *hwq) > +{ > + u8 pg_size =3D BNG_RE_HWRM_PG_SIZE_4K; > + struct bng_re_pbl *pbl; > + > + pbl =3D &hwq->pbl[BNG_PBL_LVL_0]; > + switch (pbl->pg_size) { [Severity: Critical] Does bng_re_base_pg_size() program the wrong CQ leaf page size into firmware, allowing out-of-bounds DMA past 4KB CQ buffers? Both bng_re_setup_sginfo() and bng_re_create_cq() allocate 4KB leaf pages (SZ_4K), so for any CQ with more than one 4KB leaf page (cqe >=3D 128), bng_re_alloc_init_hwq() sets hwq->pbl[BNG_PBL_LVL_0].pg_size to PAGE_SIZE (for 1-level) or npde * PAGE_SIZE (for 2-level) while the leaf level hwq->pbl[hwq->level] stays 4KB. Reading BNG_PBL_LVL_0 instead of hwq->level causes bng_sp_create_cq() and bng_sp_resize_cq() to program BNG_RE_HWRM_PG_SIZE_64K on 64KB PAGE_SIZE hosts (or BNG_RE_HWRM_PG_SIZE_8K on 4KB hosts if a user passes a > 1 GiB CQ umem so npde =3D=3D 2), letting = the NIC DMA past each 4KB leaf page into adjacent physical memory. Neither bng_sp_create_cq() nor bng_sp_resize_cq() sets req.pbl_pg_size or the PBL_PG_SIZE_VALID flag either, which breaks 2-level PBL traversal on 16KB and 64KB hosts where PBL pages are PAGE_SIZE. [ ... ] > diff --git a/drivers/infiniband/hw/bng_re/bng_sp.c b/drivers/infiniband/h= w/bng_re/bng_sp.c > index caa5ff44d99c6..a4e6692a48baa 100644 > --- a/drivers/infiniband/hw/bng_re/bng_sp.c > +++ b/drivers/infiniband/hw/bng_re/bng_sp.c [ ... ] > + /* Cyclic, so a stale NQE of a destroyed CQ doesn't match a new one */ > + rc =3D xa_alloc_cyclic_bh(&cq->nq->cq_xa, &handle, cq, xa_limit_32b, > + &cq->nq->cq_xa_next, GFP_KERNEL); > + if (rc < 0) > + return rc; > + cq->cq_handle =3D handle; > + > + cq->dbinfo.flags =3D 0; [ ... ] > + cq->dbinfo.priv_db =3D res->dpi_tbl.priv_db; > + cq->dbinfo.flags =3D 0; > + cq->dbinfo.toggle =3D 0; > + cq->dbinfo.seed =3D 0; > + spin_lock_init(&cq->dbinfo.lock); > + cq->dbinfo.res =3D res; > + cq->dbinfo.is_l2 =3D false; > + > + bng_re_armen_db(&cq->dbinfo, DBC_DBC_TYPE_CQ_ARMENA); [Severity: High] Can publishing cq in nq->cq_xa before cq->dbinfo is initialized cause a softirq NULL pointer dereference in bng_re_armen_db()? Because the NQ IRQ and system_bh_wq worker are already active, an NQE carrying handle can reach bng_fp_process_cqn() before cq->dbinfo.priv_db is assigned: CPU0 CPU1 (softirq) bng_sp_create_cq() xa_alloc_cyclic_bh(..., cq, ...) ... bng_fp_process_cqn() sp_cq =3D xa_load(&nq->cq_xa, ...) bng_re_armen_db(&sp_cq->dbinfo, ...) writeq(key, NULL) <-- NULL deref cq->dbinfo.priv_db =3D ... In addition, cq->dbinfo and toggle are initialized and CQ_ARMENA is rung without cq->cq_lock while bng_fp_process_cqn() updates them under cq->cq_lock. For user CQs, arming before ib_respond_udata() also allows an NQE to queue an event in ib_uverbs_comp_handler() before a user-triggerable -EFAULT aborts UVERBS_METHOD_CQ_CREATE without calling ib_uverbs_release_ucq(), leaving a use-after-free on struct ib_ucq_object in ib_uverbs_event_read(). Reserving the handle with NULL (XA_ZERO_ENTRY) and storing cq via xa_store_bh() plus ringing CQ_ARMENA only after CREATE_CQ, dbinfo setup, and ib_respond_udata() succeed avoids these races. [ ... ] > diff --git a/drivers/infiniband/hw/bng_re/bng_verbs.c b/drivers/infiniban= d/hw/bng_re/bng_verbs.c > index 4eb69c1bd8737..8ec0a19867b5f 100644 > --- a/drivers/infiniband/hw/bng_re/bng_verbs.c > +++ b/drivers/infiniband/hw/bng_re/bng_verbs.c [ ... ] > + /* Check for valid CQ entries */ > + if (attr->cqe > dev_attr->max_cq_wqes) { > + ibdev_dbg(&rdev->ibdev, > + "Failed to create CQ, cqe:%d max_cq_wqes:%d", > + attr->cqe, dev_attr->max_cq_wqes); > + return -EINVAL; > + } [Severity: Low] Should these format specifiers be %u instead of %d since attr->cqe and dev_attr->max_cq_wqes are unsigned? The same %d mismatch appears in bng_re_create_cq() and bng_re_resize_cq(). [ ... ] > + /* Honors the core CQ buffer attributes (VA/FD/UMEM) and falls back to > + * the VA passed in the driver udata. > + */ > + cq->umem =3D ib_umem_get_cq_buf_or_va(&rdev->ibdev, attrs, req.cq_va, > + entries * sizeof(struct cq_base), > + IB_ACCESS_LOCAL_WRITE); [Severity: High] Can an unprivileged user pass an oversized attribute-supplied CQ buffer here and trigger a vmalloc out-of-bounds write in bng_fill_user_dma_pages()? ib_umem_get_cq_buf_or_va() only checks umem->length >=3D min_size with no upper bound. bng_re_setup_sginfo() forces SZ_4K, and both bng_re_alloc_init_hwq() and bng_alloc_pbl() truncate ib_umem_num_dma_blocks(umem, SZ_4K) to u32 before allocating pg_map_arr with vmalloc_array(), whereas bng_fill_user_dma_pages() iterates over all size_t blocks returned by rdma_umem_for_each_dma_block() using int i, overflowing pg_map_arr for a >=3D 16 TiB umem or dmabuf. Even for a > 1 GiB umem, bng_re_alloc_init_hwq() allocates PBLs for the entire umem with npde >=3D 2 (breaking bng_re_base_pg_size()) and places PTU_PTE_LAST at the end of the umem rather than the CQ ring. Validating the umem size against the expected CQ ring size and avoiding u32/int truncation of the DMA block count would prevent this. [ ... ] > + cq->resize_umem =3D ib_umem_get_va(&rdev->ibdev, req.cq_va, > + entries * sizeof(struct cq_base), > + IB_ACCESS_LOCAL_WRITE); [Severity: Low] Should bng_re_resize_cq() use ib_umem_get_cq_buf_or_va(&rdev->ibdev, NULL, ...) instead of ib_umem_get_va()? ib_umem_get_va() maps the resized CQ umem DMA_BIDIRECTIONAL, whereas bng_re_create_user_cq() maps the CQ buffer DMA_FROM_DEVICE. [ ... ] > + rc =3D bng_sp_resize_cq(&rdev->bng_res, &cq->sp_cq, entries); > + if (bng_re_fw_may_own(&rdev->rcfw, rc)) { > + /* > + * FW may still switch rings: keep the new one pending until > + * destroy_cq frees it. > + */ > + ibdev_err_ratelimited(&rdev->ibdev, "Resize HW CQ %#x timed out", > + cq->sp_cq.id); > + cq->resize_timedout =3D true; [Severity: Medium] Can evaluating bng_re_fw_may_own() separately in bng_sp_resize_cq() and bng_re_resize_cq() leak cq->sp_cq.resize_hwq? If pci_channel_offline() flips from false to true between the check in bng_sp_resize_cq() and the check here after -ETIMEDOUT, bng_sp_resize_cq() keeps cq->sp_cq.resize_hwq allocated while bng_re_resize_cq() jumps to udata_fail and clears cq->resize_umem without freeing resize_hwq. Because bng_re_destroy_cq() only frees resize_hwq when cq->resize_umem is non-NULL, the HWQ PBL memory is permanently leaked. The same double-check between bng_sp_create_cq() and bng_re_create_user_cq() can leak cq->sp_cq.hwq. [ ... ] > + /* ib_free_cq() did this in pre_destroy_cq(); other destroy paths didn'= t */ > + bng_re_cq_detach_nq(cq); > + > + /* On failure FW may still DMA into the CQ memory: don't free it */ > + rc =3D bng_sp_destroy_cq(&rdev->bng_res, &cq->sp_cq); > + if (rc) { > + ibdev_err(&rdev->ibdev, "Failed to destroy HW CQ %#x rc %d", > + cq->sp_cq.id, rc); > + return rc; > + } [Severity: Medium] If bng_sp_destroy_cq() fails transiently on a user CQ, does calling bng_re_cq_detach_nq() beforehand permanently break completion notifications for the surviving CQ? bng_re_rcfw_send_message() can return -EAGAIN when CMDQ is full (or -EIO on firmware error), in which case uverbs_destroy_uobject() aborts destruction and leaves the user CQ alive. Because bng_re_cq_detach_nq() has already erased cq_handle from nq->cq_xa and decremented nq->load, all subsequent NQEs for that CQ are dropped in bng_fp_process_cqn() and nq->load stays undercounted. [ ... ] > + if (cq->umem) { > + /* > + * Safe to sleep here: this path only runs for user > + * (umem-backed) CQs, whose poll_cq always runs in process > + * context via ib_uverbs_poll_cq(). A future kernel CQ poll > + * path must stay atomic-context safe - don't block there. > + */ > + mutex_lock(&cq->resize_lock); [Severity: Low] Is this unlocked read of cq->umem a data race with bng_re_resize_cq_complete()? Multiple userspace threads can enter ib_uverbs_poll_cq() and ib_uverbs_req_notify_cq() concurrently (both take UVERBS_LOOKUP_READ), so one thread can read cq->umem here or in bng_re_req_notify_cq() while another updates cq->umem =3D cq->resize_umem under cq->resize_lock. Testing the immutable ibcq->uobject instead of cq->umem avoids the race. [ ... ] > diff --git a/include/uapi/rdma/bng_re-abi.h b/include/uapi/rdma/bng_re-ab= i.h > index 3f571fd35a23d..ebf2ff965fc93 100644 > --- a/include/uapi/rdma/bng_re-abi.h > +++ b/include/uapi/rdma/bng_re-abi.h [ ... ] > +struct bng_re_cq_req { > + __aligned_u64 cq_va; > + /* Not used yet; will be used in a future series */ > + __aligned_u64 cq_handle; > +}; [Severity: Medium] Should bng_re_create_user_cq() reject a non-zero req.cq_handle (or omit cq_handle from struct bng_re_cq_req until it is used)? ib_copy_validate_udata_in(udata, req, cq_va) copies all 16 bytes of struct bng_re_cq_req and only checks trailing bytes beyond sizeof(req) for zero, so non-zero values in the unused cq_handle field are currently silently accepted, which can break forward compatibility when cq_handle is given meaning later. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204155249.1002= 019-1-siva.kallam@broadcom.com?part=3D8