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=1796487007; b=ujuTWaqO0wUZe5GtQozDXTiN2bLpqsRuhMVosPeoaH0Um5iDeSgDfCMNnX/nPaDgPtuB GErsBXv3Gbjb2R2bnKMIFn286wh7n6Qd/z8abmtO9zhVeI4ZqfjaXySR+iXZjLrJyg+6k YOfL1yY2E0W6v4GEaKyGHXw5CblngDhPt4A2VaScDDI93l5MBNlI82/n0kA0TdOeQHWF0 QbPfPg3OzcuEW6B+D8GkGdN4us6+3yxLTIFyZLJrjU/AltWeOxLr8uU2kjo4xhcvtf431 2jLGJG0iRyJG8r/LJJBopCzPPxFkLgkUFFlFJT5zYLAxdRGG1BXy6aXa2lSqdb4JUKA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796487007; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=7WH/p5FG5BNWaRwtFU7UwsO5Oy/DDKXwN9Re9EFESzQ=; b=20PkkpjgnjWSrDpBtw6USfw0grHOgYjLc0Y2VllyyygsIpLfelzcfEA28hmegyGIKlO1 ua/VVvO/Hwq1vQHxOjh6iwg6mNRl13X3NjZ8ytgle4Q7olZX4H8c9nr+Jek8fzB/x4pzX ReMSX0Ye+FYsmBjcVRDDbnoPCPEuqA+ZvLZS5II43XUC67RlzMYRCdcMp0SoKDAMQZrcw 8OTPwBGmNfsB3M/qYrNtCHwO6PTC8bCi4wBtHMXDaGNTSgdYnghShjFvyi/gfXG4rIBgY RbbtZ1KzGDUm4EfgvrjIUDPSIRI3PNnPfAZxHPBW72METvVtgbbQvMyZGHfEo0tO2mQ== 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=VQhyhxHw; 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 8E4C6606A31F for ; Sat, 5 Dec 2026 16:10:07 +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=VQhyhxHw Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BB511F00A14; Sat, 5 Dec 2026 16:10:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796487007; bh=7WH/p5FG5BNWaRwtFU7UwsO5Oy/DDKXwN9Re9EFESzQ=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=VQhyhxHwzHVOiC2/Lbbn57cAIU3bO03JVFOs/M5AK9iDv63Vv6rfom3PRkhib3iIw 6CeeHH+xzixY1AkLAdI31ywbrNZegvHr4HYG87l4ABoc+e41sk0PvM4vAPkD0tkQjr PmPXP+jFmOuJ7yts0sfjwNT32nphp2OBQmJLN2Wyuc+eUO6VLRV3SP/rk7Rxsf8Gzu gsT1+Hpdh8dsDfz1a5jusn+527VQ3EbH8mYkXOEaP45dm2s2vmkUjktWxd+mag1eVk wa/VA5FrLRpPzAx5+6MYXIW7s1AGKBNpA5NqIUykW4gEUaBO5V1E/sfWmLHCQdpcPX TgJuGu7ge3Fjw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RDMA v2 02/13] RDMA/bng_re: Add MPC, XID management, doorbell infrastructure Reply-To: sashiko-reviews@lists.linux.dev To: "Siva Reddy Kallam" Cc: linux-rdma@vger.kernel.org In-Reply-To: <20261204155249.1002019-3-siva.kallam@broadcom.com> References: <20261204155249.1002019-1-siva.kallam@broadcom.com> <20261204155249.1002019-3-siva.kallam@broadcom.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 16:10:06 +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 25 potential issues to consider: - [High] RDMA/bng_re: wrong ring page_size in MPC HWQ and ring alloc on non-4KB kernels - [High] RDMA/bng_re: missing release-acquire ordering on tx_cons in MPC TX ring - [Medium] RDMA/bng_re: bng_service_mpc() ignores mpc->requested on cq_pending paths - [Medium] RDMA/bng_re: UAF and uninitialized lock on early exit in bng_re_roce_mpc_xmit() - [Medium] RDMA/bng_re: bng_re_snapdump_mpc_stats() uses snprintf() and can return > buf_len - [Medium] RDMA/bng_re: unconditional 6 MiB vmalloc for unread MPC stats and racy clear - [Medium] RDMA/bng_re: bng_re_roce_mpc_xmit() poll loop checks timeout before completion - [Medium] RDMA/bng_re: wrong CQ epoch check for slot 2 on LONG completion wrap - [Medium] RDMA/bng_re: bng_re_xm_free_tag() leaks xm_curr_active_ids quota - [Medium] RDMA/bng_re: bng_re_mpc_roce_send() leaves tx_bd_haddr stale on wrap - [Medium] RDMA/bng_re: short_timeout debugfs cap exceeds NMI hardlockup threshold - [Medium] RDMA/bng_re: hardcode fast-QP XID headroom and skip QCAPS validity checks - [Low] RDMA/bng_re: data race on mpc->requested in bng_mpc_start_irq() - [Low] RDMA/bng_re: bng_mpc_stop_irq() never increments num_irq_stopped counter - [Low] RDMA/bng_re: bng_setup_mpc_nq() allocates 128K-entry 2 MiB NQ for one CQ - [Low] RDMA/bng_re: monolithic patch with custom XID allocator, tasklets, dead code - [Low] RDMA/bng_re: bng_re_mpc_roce_deinit_free() leaves MPC doorbells unpaired - [Low] RDMA/bng_re: bng_mpc_stop_irq() never increments num_irq_stopped counter - [Low] RDMA/bng_re: bng_re_mpc_roce_add_perf_stats() misclassifies PFVF AH subtypes - [Low] RDMA/bng_re: disjoint-lock data race on tx_sw_ring handle on MPC timeout - [Low] RDMA/bng_re: unlocked debugfs and snapdump accesses race on bm_stats_info - [Low] RDMA/bng_re: unannotated concurrent accesses to MPC flags and tune params - [Low] RDMA/bng_re: invalid kernel-doc in bng_xid_allocator.c and stat format bugs - [Low] RDMA/bng_re: unnecessary GFP_ATOMIC in MPC xmit and XID allocator - [Low] RDMA/bng_re: use kvcalloc() for dpit->app_tbl in bng_res_alloc_dpi_tbl() -- commit cbc203ba778d078b7ce6510575042cb72c01d5e7 Author: Raqib Jones > RDMA/bng_re: Add MPC, XID management, doorbell infrastructure > > This patch has below changes > > New MPC channel introduced for AH/QP operations > xid management support for AH/QP > Doorbell infrastructure changes > > Signed-off-by: Raqib Jones > Signed-off-by: Siva Reddy Kallam [Severity: Low] This isn't a bug, but the patch bundles three distinct subsystems (MPC channel, XID allocator, and doorbell BAR / DPI tables) plus debugfs knobs into a single 4,551-line commit with only a brief bullet list and no explanation of why MPC or a custom XID allocator is needed. A few maintainability issues also stand out across the patch: - bng_xid_allocator.c adds 714 lines of custom RB-tree range allocation with BNG_RE_XID_AVOID_REUSE hardcoded to false, even though callers only ever allocate single IDs (which standard kernel ida handles), and xid_allocator.h omits bng_re_ prefixes on its types and enums. - bng_mpc_start_irq() introduces new usage of deprecated tasklets instead of a BH workqueue (system_bh_wq) or threaded IRQ. - Several fields, structs, and helpers are unused or stubs: bm_poll_info, struct bng_re_vf_pfvf_cmpl_work, struct bng_mpc_db, st_tag_supported, dbinfo.lock, bng_re_alloc_mpc_doorbells(), bng_re_unalloc_mpc_doorbells(), and bng_re_snapdump_mpc_stats(). The four mpctune debugfs handlers also duplicate boilerplate, and long_timeout accepts values under 100 ms even though bng_re_roce_mpc_xmit() logs an error for them. > diff --git a/drivers/infiniband/hw/bng_re/bng_debugfs.c b/drivers/infinib= and/hw/bng_re/bng_debugfs.c > index 9ec5a87852507..8d312eba987f7 100644 > --- a/drivers/infiniband/hw/bng_re/bng_debugfs.c > +++ b/drivers/infiniband/hw/bng_re/bng_debugfs.c [ ... ] > +/* > + * Limits for the MPC tunables. The short timeout is also the poll-mode > + * busy-wait budget: it is capped at 20s because longer values can trigg= er > + * soft-lockup warnings when a poll-mode caller spins in atomic context. > + */ > +#define BNG_RE_MPC_SHORT_TMO_MAX_MSECS 20000 [ ... ] > + if (!val || val > BNG_RE_MPC_SHORT_TMO_MAX_MSECS) > + return -EINVAL; > + > + rdev->mpc_roce_creq.mpc_tune_params->short_timeout =3D val; [Severity: Medium] Can setting mpctune/short_timeout above 10000 ms trip the NMI hardlockup detector when firmware stalls? bng_re_roce_mpc_xmit() in poll_cmp mode busy-waits in udelay(9) for up to short_timeout without calling touch_nmi_watchdog(). Callers such as ib_send_cm_req() -> cm_alloc_msg_agent() -> rdma_create_ah(..., 0) invoke this path with IRQs disabled, where the default NMI hardlockup threshold is 10 seconds (and 20 seconds also hits the softlockup threshold in IRQ-enabled atomic context). Either cap short_timeout below the watchdog threshold or call touch_nmi_watchdog() in the poll loop. [ ... ] > + seq_printf(s, "\t Num IRQ Started: 0x%x\n\t Num IRQ Stopped : 0x%x\n\t = Num IRQ Received : 0x%llx\n", > + mpc->stats.num_irq_started, > + mpc->stats.num_irq_stopped, > + mpc->stats.num_irq_received); [Severity: Low] Will "Num IRQ Stopped" in mpc_irq always display 0x0? Nothing in the driver ever increments mpc->stats.num_irq_stopped. > diff --git a/drivers/infiniband/hw/bng_re/bng_mpc.c b/drivers/infiniband/= hw/bng_re/bng_mpc.c > new file mode 100644 > index 0000000000000..7402f9a7156a2 > --- /dev/null > +++ b/drivers/infiniband/hw/bng_re/bng_mpc.c [ ... ] > + /*Process pending MPC completions before servicing NQ*/ > + if (mpc->cq_pending) { > + mpc->cq_pending =3D bng_re_mpc_roce_service_cne(rdev, NULL, > + BNG_MPC_MAX_MESSAGES_PER_POLL); > + if (mpc->cq_pending) { > + mpc->stats.num_cq_pending++; > + mpc->stats.num_tasklet_resched++; > + tasklet_schedule(&mpc->mpc_tasklet); > + dev_dbg(rdev_to_dev(mpc->rdev), > + "%s:%d MPC IRQ Rescheduled due to CQ pending\n", > + __func__, __LINE__); > + return; > + } > + } [ ... ] > + if (mpc->cq_pending) { > + /* Update the consumer index only and dont enable arm */ > + bng_re_ring_nq_db(&mpc->nq_db.dbinfo, res->cctx, false); > + mpc->stats.num_tasklet_resched++; > + tasklet_schedule(&mpc->mpc_tasklet); > + dev_dbg(rdev_to_dev(mpc->rdev), > + "%s:%d MPC IRQ NQ Rescheduled due to CQ pending\n", > + __func__, __LINE__); > + } else { [Severity: Medium] Can bng_service_mpc() livelock tasklet_kill() or re-arm the CQ during teardown when mpc->cq_pending is set? CPU0 CPU1 () bng_mpc_stop_irq() spin_lock_bh(&mpc->hwq.lock) mpc->requested =3D false bng_re_ring_nq_db(..., false) spin_unlock_bh(&mpc->hwq.lock) free_irq(...) tasklet_kill(&mpc->mpc_tasklet) bng_service_mpc() if (mpc->cq_pending) bng_re_mpc_roce_service_cne() tasklet_schedule(&mpc->mpc_tasklet) <-- repeats without checking reques= ted Both cq_pending branches skip the mpc->requested check that guards the non-cq_pending branches. Under sustained or stuck valid CQEs during device removal, the tasklet keeps ringing the NQ/CQ doorbells (including CQ_ARMALL) and rescheduling itself, starving tasklet_kill(). [ ... ] > + mpc->requested =3D true; > + /* > + * hwq.cons/nq_db.dbinfo.flags are also updated by the tasklet under > + * hwq.lock; take the same lock here so the doorbell is formatted > + * from a consistent (cons, epoch) pair instead of a possibly torn > + * read if an IRQ fires and schedules the tasklet concurrently. > + */ > + spin_lock_bh(&mpc->hwq.lock); > + bng_re_ring_nq_db(&mpc->nq_db.dbinfo, res->cctx, true); > + spin_unlock_bh(&mpc->hwq.lock); [Severity: Low] Does setting mpc->requested =3D true after request_irq() and outside mpc->hwq.lock create a data race with bng_service_mpc(), which reads mpc->requested under mpc->hwq.lock? Moving the assignment inside the spin_lock_bh(&mpc->hwq.lock) block avoids the race. [ ... ] > + /* Cleanup Tasklet */ > + if (kill) > + tasklet_kill(&mpc->mpc_tasklet); > + else > + tasklet_disable(&mpc->mpc_tasklet); > +} [Severity: Low] Should bng_mpc_stop_irq() increment mpc->stats.num_irq_stopped to pair with mpc->stats.num_irq_started++ in bng_mpc_start_irq()? [ ... ] > +static int bng_setup_mpc_nq(struct bng_mpc_ctx *mpc) > +{ > + struct bng_re_dev *rdev =3D mpc->rdev; > + struct bng_re_ring_attr rattr =3D {}; > + int depth; > + int rc; > + > + depth =3D BNG_NQE_MAX_CNT; > + mpc->hwq.max_elements =3D depth; > + rc =3D bng_alloc_mpc_nq_mem(mpc); [Severity: Low] Does the MPC NQ need BNG_NQE_MAX_CNT (128K) entries? This NQ only serves a single 2048-entry MPC CQ, yet sizing it to 128K entries allocates 2 MiB of DMA-coherent memory via 512 separate dma_alloc_coherent() calls per device (which scales to 128-256 MiB across 64-128 SR-IOV VFs). > diff --git a/drivers/infiniband/hw/bng_re/bng_re_mpc_roce.c b/drivers/inf= iniband/hw/bng_re/bng_re_mpc_roce.c > new file mode 100644 > index 0000000000000..d7a91eb8fb3e6 > --- /dev/null > +++ b/drivers/infiniband/hw/bng_re/bng_re_mpc_roce.c [ ... ] > +static u32 bng_re_mpc_tx_avail(struct bng_re_mpc_roce_creq_info *creq) > +{ > + u32 used =3D READ_ONCE(creq->tx_prod) - READ_ONCE(creq->tx_cons); [ ... ] > + WRITE_ONCE(creq->tx_cons, tx_cons); [Severity: High] Does publishing creq->tx_cons with plain WRITE_ONCE() and reading it with READ_ONCE() miss a release-acquire pair on weakly-ordered architectures? CPU0 (completion, mpc_ctx_lock) CPU1 (producer, tx_lock) tx_sw_ring[idx].handle =3D 0 tx_sw_ring[idx].last_cons =3D INV WRITE_ONCE(creq->tx_cons, next) bng_re_mpc_tx_avail() READ_ONCE(creq->tx_cons) bng_re_mpc_roce_send() tx_sw_ring[idx].handle =3D new_ctx tx_sw_ring[idx].last_cons =3D 0 [reordered handle=3D0 / last_cons=3DINV overwrites new_ctx] <-- data cor= ruption tx_prod uses smp_store_release() paired with smp_load_acquire(), but tx_cons does not. On ARM64 or PPC64, the consumer's slot cleanup stores can reorder past the tx_cons update and clobber a newly reused slot, causing dropped completions and MPC channel stalls. Using smp_store_release() in bng_re_mpc_adv_tx_cons() and smp_load_acquire() in bng_re_mpc_tx_avail() fixes the ordering. [ ... ] > + rc =3D bng_re_alloc_mpc_doorbells(rdev); > + if (rc) { > + dev_err(rdev_to_dev(rdev), > + "[%s:%d:%d] Error allocating mpc dbs (err : %d)\n", > + __func__, current->pid, __LINE__, rc); > + goto err_free_rings; > + } > + > + set_bit(BNG_RE_FLAG_MPC_DB_PAGE_EN, &rdev->flags); [ ... ] > +void bng_re_mpc_roce_deinit_free(struct bng_re_dev *rdev) > +{ > + struct bng_re_mpc_roce_creq_info *creq =3D &rdev->mpc_roce_creq; > + struct bng_re_res *res =3D &rdev->bng_res; > + > + dev_dbg(rdev_to_dev(rdev), "%s: %p\n", __func__, rdev); > + > + bng_re_mpc_rings_free(rdev); [Severity: Low] Should bng_re_mpc_roce_deinit_free() call bng_re_unalloc_mpc_doorbells(rdev) and clear BNG_RE_FLAG_MPC_DB_PAGE_EN? bng_re_mpc_roce_alloc_init() pairs them on setup, leaving bng_re_unalloc_mpc_doorbells() unused and the flag set after teardown. [ ... ] > + txbd->tx_bd_len_flags_type =3D > + cpu_to_le32((cmd_len << TX_BD_LEN_SHIFT) | TX_BD_TYPE_MPC_TX_BD | > + (total_bds << TX_BD_FLAGS_BD_CNT_SHIFT)); > + txbd->tx_bd_opaque =3D BNG_RE_MPC_SET_TX_OPAQUE(creq->tx_napi_idx, prod, > + total_bds, creq->tx_ring_mask); [ ... ] > + memcpy(txbd, cmd, chunk); [Severity: Medium] Should bng_re_mpc_roce_send() zero txbd->tx_bd_haddr in the header BD? Inline data BDs overwrite all 16 bytes of each slot, and because BNG_RE_MPC_TX_RING_SIZE (512) is not divisible by the 6-BD AH or 15-BD QP command sizes, former data slots are reused as header BDs after wraparound. Leaving bytes 8..15 containing stale command payload from a previous pass could cause hardware errors if TX_BD_TYPE_MPC_TX_BD expects that field to be zero. [ ... ] > + cons_next =3D cons + 1; > + if (cons_next >=3D cq_hwq->max_elements) > + cons_next =3D 0; > + > + mpcmp2 =3D bng_re_get_qe(cq_hwq, cons_next, NULL); > + if (!mpcmp2) { > + dev_err(rdev_to_dev(rdev), > + "%s: get_qe slot2 failed at cons %u\n", > + __func__, cons_next); > + break; > + } > + > + /* Same HW write as slot 1 =E2=80=94 same V polarity / consumer epoch = */ > + if (!(!!(mpcmp2->mpc_cmp_v & cpu_to_le32(MPC_CMP_V)) =3D=3D > + !cq_epoch)) { [Severity: Medium] Does validating mpcmp2->mpc_cmp_v against the unflipped !cq_epoch wedge the MPC CQ if a 2-slot LONG completion ever wraps from max_elements - 1 to 0? The unexpected-type handler above advances cons by 1 slot, which can leave cons odd. When a later LONG completion lands at max_elements - 1, slot 2 wraps to index 0 with the next-lap valid bit polarity, so comparing against the old !cq_epoch rejects slot 2 forever and stalls all subsequent MPC commands. Flipping the expected epoch when cons_next =3D=3D 0 avoids this. [ ... ] > + if (READ_ONCE(creq->bm_mpc_uninstall_pending)) { > + rc =3D -EHOSTUNREACH; > + dev_warn(rdev_to_dev(rdev), "%s QUIT(0): driver uninit in progress\n", > + __func__); > + goto exit; > + } > + > + dc =3D creq->bm_diag_counters; > + if (!creq->mpc_tune_params || !dc) { > + dev_err(rdev_to_dev(rdev), "%s: MPC channel not initialized\n", __func= __); > + rc =3D -EINVAL; > + goto exit; > + } [ ... ] > + exit: > + poll_end_time =3D jiffies; > + > + spin_lock_irqsave(&creq->mpc_ctx_lock, flags); > + /* Track available buffer space */ > + creq->avail_buffer =3D bng_re_mpc_tx_avail(creq); > + creq->min_avail_buffer =3D min(creq->avail_buffer, > + creq->min_avail_buffer); > + bng_re_mpc_roce_add_perf_stats(rdev, > + ((u8 *)cmd)[0], > + ((u8 *)cmd)[1], > + (u32)jiffies_to_msecs(poll_end_time - tx_end_time)); > + spin_unlock_irqrestore(&creq->mpc_ctx_lock, flags); [Severity: Medium] Can these early exits cause a use-after-free on bm_stats_info during teardown, or lock an uninitialized creq->mpc_ctx_lock? CPU0 CPU1 bng_deinit_mpc_creq() bm_mpc_uninstall_pending =3D 1 smp_mb() bng_re_check_mpc_pending_empty() (observes pending =3D=3D 0) bng_re_mpc_roce_deinit_free() bng_re_mpc_roce_free_stats() vfree(p->bms_lat_slab_sec) bng_re_roce_mpc_xmit() atomic_inc_return(&creq->pending) sees bm_mpc_uninstall_pending =3D=3D 1 goto exit bng_re_mpc_roce_add_perf_stats() p->bms_lat_slab_sec[...]++ <-- use-a= fter-free rdev->...bm_stats_info =3D NULL In addition, creq->mpc_ctx_lock is only initialized inside bng_re_mpc_roce_alloc_init(), so hitting the !creq->mpc_tune_params || !dc guard before channel init jumps to exit and locks an uninitialized spinlock. Both early exits should jump to a label that only decrements creq->pending and returns rc. [ ... ] > + ctx =3D kzalloc_obj(*ctx, GFP_ATOMIC); > + > + if (!ctx) { > + rc =3D -ENOMEM; > + dev_err(rdev_to_dev(rdev), "%s: ctx alloc failed\n", __func__); > + goto exit; > + } > + refcount_set(&ctx->refcnt, 1); > + ctx->poll_cmp =3D poll_cmp; > + if (!poll_cmp) { > + init_completion(&ctx->cmp); > + might_sleep(); [Severity: Low] Can ctx be allocated with poll_cmp ? GFP_ATOMIC : GFP_KERNEL? When !poll_cmp, the function immediately calls might_sleep(), so using GFP_ATOMIC unnecessarily taps emergency reserves and risks -ENOMEM on sleepable QP/AH destroy paths (which then leak the XID). Similarly, bng_re_xm_alloc_range() in bng_xid_allocator.c calls bng_re_xm_tree_info_alloc(GFP_ATOMIC) while holding spin_lock_irqsave(&xm->xm_lock, flags); pre-allocating the node before taking the lock with a caller-supplied gfp_t avoids both slab allocation under an IRQ-disabled spinlock and unnecessary GFP_ATOMIC on sleepable callers. [ ... ] > + udelay(9); > + bng_re_mpc_roce_service_creq(rdev, 32); > + if (ktime_compare(ktime_get(), deadline) >=3D 0) { > + rc =3D -ETIMEDOUT; > + goto xmit_done; > + } [Severity: Medium] Can this poll loop return -ETIMEDOUT even when bng_re_mpc_roce_service_creq= () just delivered the completion? Because ktime_compare() runs right after servicing the CQ without re-checking ctx->cmpl_available, a completion harvested on the last iteration is discarded as a timeout. For non-blocking AH destroy callers, returning -ETIMEDOUT also prevents freeing the AH XID even though hardware completed the destroy. > + if (creq->bm_mpc_stall || > + test_bit(BNG_RE_FLAG_ERR_DEVICE_DETACHED, &rdev->flags) || > + creq->bm_mpc_uninstall_pending > + ) { [Severity: Low] Do the plain accesses to creq->bm_mpc_uninstall_pending, creq->bm_mpc_stall, and mpc_tune_params fields race with concurrent writers? bm_mpc_uninstall_pending is written with WRITE_ONCE() in bng_deinit_mpc_creq() but read without READ_ONCE() in the retry, poll, and wait loops; bm_mpc_stall and the debugfs-writable mpc_tune_params fields are read and written without READ_ONCE()/WRITE_ONCE() throughout bng_re_roce_mpc_xmit() and bng_debugfs.c. [ ... ] > + spin_lock_irqsave(&creq->mpc_ctx_lock, flags); > + /* > + * The slot's last_cons is deliberately left "pending" here: > + * hardware may still own the TX BDs, so tx_cons must not > + * advance past the slot (the producer could overwrite them or > + * reuse the slot while a stale completion is in flight). A late > + * completion marks the slot done and unblocks tx_cons; if > + * firmware never completes it the ring stays blocked and needs > + * a reset (stall detection only makes the failure fast). > + * > + * Only clear the slot's handle if it still points at our own > + * ctx: if a completion for this command already arrived and > + * the slot was reused for a new post between the timeout and > + * this cleanup, pctx now belongs to that new command and > + * must not be zeroed here. > + */ > + if (pctx && *(unsigned long *)pctx =3D=3D (unsigned long)ctx) > + *(unsigned long *)pctx =3D 0; > + spin_unlock_irqrestore(&creq->mpc_ctx_lock, flags); [Severity: Low] Does reading *(unsigned long *)pctx under mpc_ctx_lock race with bng_re_mpc_roce_send() reusing that tx_sw_ring slot under tx_lock? CPU0 (timed-out xmit) CPU1 (late completion / new send) timeout detected dev_warn(...) bng_re_mpc_roce_service_creq() clears handle, advances tx_cons ... (ring wraps around) ... bng_re_mpc_roce_send() [tx_lock] tx_sw_ring[idx].handle =3D new_ctx spin_lock(&creq->mpc_ctx_lock) if (*(unsigned long *)pctx =3D=3D ctx) <-- data race on handle Because the two paths hold disjoint locks, the concurrent plain write and plain read form a KCSAN data race; using WRITE_ONCE()/READ_ONCE() or a common lock resolves it. [ ... ] > + if (cq_pages > 1) { > + req.page_size =3D BNGE_PAGE_SHIFT; > + req.page_tbl_depth =3D 1; > + } else { > + req.page_size =3D 4; > + req.page_tbl_depth =3D 0; > + } [ ... ] > + if (tx_pages > 1) { > + req.page_size =3D BNGE_PAGE_SHIFT; > + req.page_tbl_depth =3D 1; > + } else { > + req.page_size =3D 4; > + req.page_tbl_depth =3D 0; > + } [Severity: High] Does bng_re_mpc_rings_alloc() program the wrong ring page_size on non-4KB PAGE_SIZE kernels? Both bng_re_mpc_roce_alloc_hwq() and bng_alloc_mpc_nq_mem() allocate DMA pages using host PAGE_SIZE, while bng_re_mpc_rings_alloc() and bng_re_net_ring_alloc() pass BNGE_PAGE_SHIFT to HWRM_RING_ALLOC. On 16 KiB page kernels (such as CONFIG_ARM64_16K_PAGES), BNGE_PAGE_SHIFT is 13 (8 KiB): drivers/net/ethernet/broadcom/bnge/bnge_rmem.h: { ... #elif (PAGE_SHIFT < 16) #define BNGE_PAGE_SHIFT 13 ... } Hardware then steps through the CQ and NQ PBLs every 8 KiB while the driver only populated 16 KiB PTEs, causing DMA to walk past populated entries into unpopulated PTEs. In addition, when tx_pages =3D=3D 1 or cq_pages =3D=3D 1 (true on 16 KiB an= d 64 KiB kernels), the else branches set req.page_size =3D 4 (16 bytes in log2) inst= ead of leaving req.page_size =3D 0 as bng_re_net_ring_alloc() and bnge do when page_tbl_depth =3D=3D 0. [ ... ] > +int bng_re_mpc_roce_alloc_stats(struct bng_re_dev *rdev) > +{ > + struct bng_re_mpc_roce_stats_info *p; > + > + p =3D vzalloc(sizeof(*p)); > + if (!p) > + return -ENOMEM; > + > + p->bms_stats_enabled =3D false; > + p->bms_qp_modify_stats =3D vzalloc(sizeof(u64) * BNG_RE_MPC_MAX_STAT_IN= DEX); > + p->bms_ah_modify_stats =3D vzalloc(sizeof(u64) * BNG_RE_MPC_MAX_STAT_IN= DEX); > + p->bms_other_stats =3D vzalloc(sizeof(u64) * BNG_RE_MPC_MAX_STAT_INDEX); [Severity: Medium] Why does bng_re_mpc_roce_alloc_stats() unconditionally vmalloc over 6 MiB per device for three arrays that are never read? bng_re_mpc_stats_show() in bng_debugfs.c hardcodes level =3D 1 when calling bng_re_mpc_roce_perf_debugfs_show(), so the level >=3D 3 code that reads bms_qp_modify_stats, bms_ah_modify_stats, and bms_other_stats is unreachable, and bng_re_snapdump_mpc_stats() only reads the sec/msec slabs. On SR-IOV hosts with many VFs this pins hundreds of MiB unnecessarily. Also, struct bng_re_mpc_roce_stats_info is only ~56 bytes (kzalloc would suffice) and failing to allocate it returns -ENOMEM and aborts probe, contradicting the comment below that stats are optional diagnostics. Finally, bng_re_mpc_roce_diag_counters_clear() zeroes bm_mpc_consecutive_sent_err (which drives channel-stall detection) while leaving creq->bm_mpc_stall unchanged. [ ... ] > + } else if (((req_type =3D=3D MPC_CMD_HDR_REQ_TYPE_RCA) || > + (req_type =3D=3D MPC_CMD_HDR_REQ_TYPE_PFVF)) && > + (req_subtype =3D=3D MPC_CMD_HDR_REQ_SUB_TYPE_RCA_AH_MODIFY)) { [Severity: Low] Does this misclassify PFVF AH commands? MPC_CMD_HDR_REQ_SUB_TYPE_RCA_AH_MODIFY is 0x1, which for MPC_CMD_HDR_REQ_TYPE_PFVF matches MPC_CMD_HDR_REQ_SUB_TYPE_PFVF_AH_CREATE (0x1) rather than MPC_CMD_HDR_REQ_SUB_TYPE_PFVF_AH_MODIFY (0x3). [ ... ] > +void bng_re_mpc_roce_perf_debugfs_clear(struct bng_re_dev *rdev) > +{ > + struct bng_re_mpc_roce_stats_info *p =3D rdev->mpc_roce_creq.bm_stats_i= nfo; > + int i; > + > + if (!(p && p->bms_stats_enabled)) > + return; > + > + for (i =3D 0; i < BNG_RE_MPC_MAX_LATENCY_MSEC_SLAB_INDEX; i++) > + p->bms_lat_slab_msec[i] =3D 0; > + > + for (i =3D 0; i < BNG_RE_MPC_MAX_LATENCY_SEC_SLAB_INDEX; i++) > + p->bms_lat_slab_sec[i] =3D 0; > + > + for (i =3D 0; i < BNG_RE_MPC_MAX_STAT_INDEX; i++) { > + p->bms_qp_modify_stats[i] =3D 0; > + p->bms_ah_modify_stats[i] =3D 0; > + p->bms_other_stats[i] =3D 0; > + } > +} [Severity: Low] Does bng_re_mpc_roce_perf_debugfs_clear() race with bng_re_mpc_roce_add_perf_stats()? bng_re_roce_mpc_xmit() updates these arrays under creq->mpc_ctx_lock, but bng_re_mpc_roce_perf_debugfs_clear() zeroes them without taking creq->mpc_ctx_lock (and without resetting bms_*_stats_id). bng_re_mpc_roce_perf_debugfs_show() and bng_re_snapdump_mpc_stats() also read the arrays without locking or READ_ONCE(). [ ... ] > + /* Collect MPC perf stats if enabled */ > + if (p && p->bms_stats_enabled) { > + len +=3D snprintf(buf + len, buf_len - len, "=3D=3D\n"); > + if (len >=3D buf_len) > + return len; [Severity: Medium] Can bng_re_snapdump_mpc_stats() return a value larger than buf_len when the output is truncated? snprintf() returns the number of characters that would have been written, not the number actually written. With up to 3,000 msec slab entries, truncation will cause len to exceed buf_len and violate the documented return value, which can cause callers advancing a dump cursor to underflow remaining space or access past buf. Using scnprintf() throughout fixes this. > diff --git a/drivers/infiniband/hw/bng_re/bng_res.c b/drivers/infiniband/= hw/bng_re/bng_res.c > index f6e3528e7f4c0..c5f9fff56726d 100644 > --- a/drivers/infiniband/hw/bng_re/bng_res.c > +++ b/drivers/infiniband/hw/bng_re/bng_res.c [ ... ] > + dpit->max =3D min_t(unsigned long, (bar_len - reg->offset) / PAGE_SIZE, > + U32_MAX); > + if (dev_attr->max_dpi) > + dpit->max =3D min_t(u32, dpit->max, dev_attr->max_dpi); > + if (!dpit->max) { > + dev_err(&res->pdev->dev, "No DPIs available in doorbell BAR\n"); > + return -EINVAL; > + } > + > + dpit->app_tbl =3D kcalloc(dpit->max, sizeof(void *), GFP_KERNEL); [Severity: Low] Should dpit->app_tbl use kvcalloc() (paired with kvfree()) instead of kcalloc()? When the doorbell BAR exposes more than 4096 pages (> 16 MiB), this software-only pointer array exceeds PAGE_ALLOC_COSTLY_ORDER and can stall or fail with -ENOMEM on fragmented hosts during probe or rebind. > diff --git a/drivers/infiniband/hw/bng_re/bng_xid.c b/drivers/infiniband/= hw/bng_re/bng_xid.c > new file mode 100644 > index 0000000000000..1d59d684a768a > --- /dev/null > +++ b/drivers/infiniband/hw/bng_re/bng_xid.c [ ... ] > + qp_num_ids =3D qp_max + BNG_RE_DEF_FAST_QPMD_ENTRIES; > + > + res->qp_xids =3D bng_re_xm_init(qp_start, qp_num_ids, qp_max, BNG_RE_XI= D_AVOID_REUSE); [Severity: Medium] Can hardcoding BNG_RE_DEF_FAST_QPMD_ENTRIES (512) hand out QP XIDs beyond the QPC backing store allocated by bnge? bnge_alloc_ctx_mem() sizes the QPC backing store using the firmware-reported fast_qpmd_qps (which may be 0 or less than 512). Because bng_re_xi_free_compare() orders xm_free_tree by best-fit ascending size, once qp_max QPs are allocated and more than 512 consecutive lower QPs are freed and coalesced, the next allocation picks the smaller 512-entry tail block past qp_start + qp_max and hands out out-of-range XIDs. Separately, bng_re_hwrm_qp_limit_qcaps() in bng_dev.c reads all three split entries from resp.split_entry_0 without checking FUNC_BACKING_STORE_QCAPS_V2_RESP_FLAGS_TYPE_VALID or resp.subtype_valid_cnt, unlike bnge_hwrm_func_backing_store_qcaps(). > diff --git a/drivers/infiniband/hw/bng_re/bng_xid_allocator.c b/drivers/i= nfiniband/hw/bng_re/bng_xid_allocator.c > new file mode 100644 > index 0000000000000..6deaff7d5a39c > --- /dev/null > +++ b/drivers/infiniband/hw/bng_re/bng_xid_allocator.c [ ... ] > +/** > + * bng_re_xm_trans_range_by_pointer - trans range to next tree > + * > + * @param xm - > + * @param struct xid_node_info * - node to free > + * @param new_state =3D new state to go to > + * @return - 0 for success > + */ [Severity: Low] All 15 /** comment blocks in bng_xid_allocator.c use Doxygen @param syntax instead of kernel-doc @name: syntax and several list wrong or missing parameters (such as new_state here), which will trigger W=3D1 kernel-doc warnings. In bng_re_mpc_roce.c, bng_re_mpc_roce_perf_debugfs_show() and bng_re_snapdump_mpc_stats() also format u32 slab counts with %d and u64 totals with %lld instead of %u and %llu. [ ... ] > + bng_re_xm_trans_range_by_pointer(xm, nd); > + } > + return next; > +} [Severity: Medium] Does bng_re_xm_free_node_matching_tag() leak xm->xm_curr_active_ids? bng_re_xm_alloc_range() increments xm->xm_curr_active_ids and rejects allocations once it reaches xm->xm_max_active_ids. bng_re_xm_free_node_matching_tag() transitions matching X_ALLOCED ranges back to the free or pending tree via bng_re_xm_trans_range_by_pointer(), but never decrements xm->xm_curr_active_ids (or updates xs_free_op_ctr and xs_free_count_ctr), so freeing ranges via bng_re_xm_free_tag() permanently exhausts the active ID quota. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204155249.1002= 019-1-siva.kallam@broadcom.com?part=3D2