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 02/13] RDMA/bng_re: Add MPC, XID management, doorbell infrastructure
Date: Sat, 05 Dec 2026 16:10:06 +0000	[thread overview]
Message-ID: <sashiko-outbox-251726@kernel.org> (raw)
In-Reply-To: <20261204155249.1002019-3-siva.kallam@broadcom.com>

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 <raqib.jones@broadcom.com>

> 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 <raqib.jones@broadcom.com>
> Signed-off-by: Siva Reddy Kallam <siva.kallam@broadcom.com>

[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/infiniband/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 trigger
> + * 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 = 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 = 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 (<softirq>)
bng_mpc_stop_irq()
  spin_lock_bh(&mpc->hwq.lock)
  mpc->requested = 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 requested

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 = 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 = 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 = mpc->rdev;
> +	struct bng_re_ring_attr rattr = {};
> +	int depth;
> +	int rc;
> +
> +	depth = BNG_NQE_MAX_CNT;
> +	mpc->hwq.max_elements = depth;
> +	rc = 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/infiniband/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 = 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 = 0
tx_sw_ring[idx].last_cons = 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 = new_ctx
                                    tx_sw_ring[idx].last_cons = 0
  [reordered handle=0 / last_cons=INV overwrites new_ctx]  <-- data corruption

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 = 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 = &rdev->mpc_roce_creq;
> +	struct bng_re_res *res = &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 =
> +		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 = 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 = cons + 1;
> +		if (cons_next >= cq_hwq->max_elements)
> +			cons_next = 0;
> +
> +		mpcmp2 = 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 — same V polarity / consumer epoch */
> +		if (!(!!(mpcmp2->mpc_cmp_v & cpu_to_le32(MPC_CMP_V)) ==
> +		      !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 == 0 avoids this.

[ ... ]

> +	if (READ_ONCE(creq->bm_mpc_uninstall_pending)) {
> +		rc = -EHOSTUNREACH;
> +		dev_warn(rdev_to_dev(rdev), "%s QUIT(0): driver uninit in progress\n",
> +			 __func__);
> +		goto exit;
> +	}
> +
> +	dc = creq->bm_diag_counters;
> +	if (!creq->mpc_tune_params || !dc) {
> +		dev_err(rdev_to_dev(rdev), "%s: MPC channel not initialized\n", __func__);
> +		rc = -EINVAL;
> +		goto exit;
> +	}

[ ... ]

> + exit:
> +	poll_end_time = jiffies;
> +
> +	spin_lock_irqsave(&creq->mpc_ctx_lock, flags);
> +	/* Track available buffer space */
> +	creq->avail_buffer = bng_re_mpc_tx_avail(creq);
> +	creq->min_avail_buffer = 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 = 1
  smp_mb()
  bng_re_check_mpc_pending_empty()
    (observes pending == 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 == 1
                                    goto exit
                                    bng_re_mpc_roce_add_perf_stats()
                                      p->bms_lat_slab_sec[...]++  <-- use-after-free
      rdev->...bm_stats_info = 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 = kzalloc_obj(*ctx, GFP_ATOMIC);
> +
> +	if (!ctx) {
> +		rc = -ENOMEM;
> +		dev_err(rdev_to_dev(rdev), "%s: ctx alloc failed\n", __func__);
> +		goto exit;
> +	}
> +	refcount_set(&ctx->refcnt, 1);
> +	ctx->poll_cmp = 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) >= 0) {
> +				rc = -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 == (unsigned long)ctx)
> +			*(unsigned long *)pctx = 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 = new_ctx
spin_lock(&creq->mpc_ctx_lock)
if (*(unsigned long *)pctx == 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 = BNGE_PAGE_SHIFT;
> +		req.page_tbl_depth = 1;
> +	} else {
> +		req.page_size = 4;
> +		req.page_tbl_depth = 0;
> +	}

[ ... ]

> +	if (tx_pages > 1) {
> +		req.page_size = BNGE_PAGE_SHIFT;
> +		req.page_tbl_depth = 1;
> +	} else {
> +		req.page_size = 4;
> +		req.page_tbl_depth = 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 == 1 or cq_pages == 1 (true on 16 KiB and 64 KiB
kernels), the else branches set req.page_size = 4 (16 bytes in log2) instead
of leaving req.page_size = 0 as bng_re_net_ring_alloc() and bnge do when
page_tbl_depth == 0.

[ ... ]

> +int bng_re_mpc_roce_alloc_stats(struct bng_re_dev *rdev)
> +{
> +	struct bng_re_mpc_roce_stats_info *p;
> +
> +	p = vzalloc(sizeof(*p));
> +	if (!p)
> +		return -ENOMEM;
> +
> +	p->bms_stats_enabled = false;
> +	p->bms_qp_modify_stats = vzalloc(sizeof(u64) * BNG_RE_MPC_MAX_STAT_INDEX);
> +	p->bms_ah_modify_stats = vzalloc(sizeof(u64) * BNG_RE_MPC_MAX_STAT_INDEX);
> +	p->bms_other_stats = 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 = 1 when calling
bng_re_mpc_roce_perf_debugfs_show(), so the level >= 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 == MPC_CMD_HDR_REQ_TYPE_RCA) ||
> +		    (req_type == MPC_CMD_HDR_REQ_TYPE_PFVF)) &&
> +		   (req_subtype == 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 = rdev->mpc_roce_creq.bm_stats_info;
> +	int i;
> +
> +	if (!(p && p->bms_stats_enabled))
> +		return;
> +
> +	for (i = 0; i < BNG_RE_MPC_MAX_LATENCY_MSEC_SLAB_INDEX; i++)
> +		p->bms_lat_slab_msec[i] = 0;
> +
> +	for (i = 0; i < BNG_RE_MPC_MAX_LATENCY_SEC_SLAB_INDEX; i++)
> +		p->bms_lat_slab_sec[i] = 0;
> +
> +	for (i = 0; i < BNG_RE_MPC_MAX_STAT_INDEX; i++) {
> +		p->bms_qp_modify_stats[i] = 0;
> +		p->bms_ah_modify_stats[i] = 0;
> +		p->bms_other_stats[i] = 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 += snprintf(buf + len, buf_len - len, "==\n");
> +		if (len >= 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 = min_t(unsigned long, (bar_len - reg->offset) / PAGE_SIZE,
> +			  U32_MAX);
> +	if (dev_attr->max_dpi)
> +		dpit->max = 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 = 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 = qp_max + BNG_RE_DEF_FAST_QPMD_ENTRIES;
> +
> +	res->qp_xids = bng_re_xm_init(qp_start, qp_num_ids, qp_max, BNG_RE_XID_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/infiniband/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 = 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=1 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.

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

  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 [this message]
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
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-251726@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.