From: sashiko-bot@kernel.org
To: "Siva Reddy Kallam" <siva.kallam@broadcom.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [RDMA v2 08/13] RDMA/bng_re: Add CQ verbs
Date: Sat, 05 Dec 2026 16:10:10 +0000 [thread overview]
Message-ID: <sashiko-outbox-251732@kernel.org> (raw)
In-Reply-To: <20261204155249.1002019-9-siva.kallam@broadcom.com>
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 <siva.kallam@broadcom.com>
> 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 <siva.kallam@broadcom.com>
[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/hw/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 = PAGE_SIZE;
> + sginfo.pgshft = PAGE_SHIFT;
> + hwq_attr.res = res;
> + hwq_attr.sginfo = &sginfo;
> + hwq_attr.depth = nq->hwq.max_elements;
> + hwq_attr.stride = sizeof(struct nq_base);
> + hwq_attr.type = 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 = BNGE_PAGE_SHIFT. On 16KB kernels (PAGE_SHIFT ==
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 = 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/hw/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 = BNG_RE_HWRM_PG_SIZE_4K;
> + struct bng_re_pbl *pbl;
> +
> + pbl = &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 >= 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 == 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/hw/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 = 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 = handle;
> +
> + cq->dbinfo.flags = 0;
[ ... ]
> + cq->dbinfo.priv_db = res->dpi_tbl.priv_db;
> + cq->dbinfo.flags = 0;
> + cq->dbinfo.toggle = 0;
> + cq->dbinfo.seed = 0;
> + spin_lock_init(&cq->dbinfo.lock);
> + cq->dbinfo.res = res;
> + cq->dbinfo.is_l2 = 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 = xa_load(&nq->cq_xa, ...)
bng_re_armen_db(&sp_cq->dbinfo, ...)
writeq(key, NULL) <-- NULL deref
cq->dbinfo.priv_db = ...
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/infiniband/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 = 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 >= 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 >= 16 TiB umem or dmabuf.
Even for a > 1 GiB umem, bng_re_alloc_init_hwq() allocates PBLs for the
entire umem with npde >= 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 = 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 = 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 = 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 = 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 = 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-abi.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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204155249.1002019-1-siva.kallam@broadcom.com?part=8
next prev parent 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
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 [this message]
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-251732@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox