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 12/13] RDMA/bng_re: Add QP verbs
Date: Sat, 05 Dec 2026 16:10:13 +0000	[thread overview]
Message-ID: <sashiko-outbox-251736@kernel.org> (raw)
In-Reply-To: <20261204155249.1002019-13-siva.kallam@broadcom.com>

Thank you for your contribution! Sashiko AI review found 25 potential
issues to consider:
- [High] RDMA/bng_re: DMA use-after-free on timeout in bng_sp_query_qp()
- [High] RDMA/bng_re: premature QP teardown after initial MPC modify
  timeout
- [High] RDMA/bng_re: PAGE_SIZE QP HWQ pgsize silently falls back to 4K
  on 16K hosts
- [High] RDMA/bng_re: __bng_re_modify_qp() skips ib_modify_qp_is_ok()
  without state
- [High] RDMA/bng_re: __bng_re_modify_qp() lacks rollback and drops GID
  ref on fault
- [High] RDMA/bng_re: __bng_re_query_qp() omits IB_AH_GRH, port_num,
  dmac, pkey_index
- [Medium] RDMA/bng_re: stale req_buffer_count and modify_flags across
  QP modify
- [Medium] RDMA/bng_re: missing dbinfo.flags epoch reset in
  bng_re_clean_qp()
- [Medium] RDMA/bng_re: unsynchronized sgid_tbl.hw_id reads in QP modify
  and query
- [Medium] RDMA/bng_re: qp_destroy_qp_mpc() leaves QP_FREE set on
  destroy failure
- [Medium] RDMA/bng_re: __bng_re_modify_qp() leaves dirty sp_qp state on
  failure
- [Medium] RDMA/bng_re: bng_re_init_user_qp() misses VA alignment check
  for FWO=0
- [Medium] RDMA/bng_re: incomplete udata validation in QP create and
  modify verbs
- [Medium] RDMA/bng_re: __clean_cq() omits RES_UD_CFA and V3 CQE types
- [Medium] RDMA/bng_re: missing udata validation in QP create, modify,
  and destroy verbs
- [Medium] RDMA/bng_re: __bng_re_modify_qp() ignores IB_QP_CUR_STATE and
  pkey_index
- [Medium] RDMA/bng_re: stale modify_flags, req_buffer_count, and epoch
  bits on RESET
- [Medium] RDMA/bng_re: bng_re_update_ah_dscp_sl() zeroes DSCP/SL from
  empty DCB tables
- [Medium] RDMA/bng_re: unclamped pow2 SQ/RQ depths break valid QP
  creation
- [Medium] RDMA/bng_re: __bng_re_modify_qp() ignores
  qp_attr->en_sqd_async_notify
- [Medium] RDMA/bng_re: bng_re_init_qpmtu() accepts invalid negative MTU
  values
- [Low] RDMA/bng_re: wrong ext_stats check on unused sp_qp fields
- [Low] RDMA/bng_re: bng_re_clean_qp() scans shared CQ twice with IRQs
  disabled
- [Low] RDMA/bng_re: duplicate QP state helper, macro, HSI struct, and
  dead ext_stats
- [Low] RDMA/bng_re: bng_re_lock_cqs() and bng_re_unlock_cqs() lack
  annotations
--

commit 8f8045d9012224af63922783e0bf5b836093cf49
Author: Usman S. Ansari <usman.ansari@broadcom.com>

RDMA/bng_re: Add QP verbs

This commit adds the create_qp, modify_qp, query_qp, and destroy_qp verbs
along with their MPC/RCFW slowpath helpers, QP reference table, and user
ABI structures for the bng_re driver.

> diff --git a/drivers/infiniband/hw/bng_re/bng_sp.c b/drivers/infiniband/hw/bng_re/bng_sp.c
> index 2e46742c335ca..5122a7af9ef29 100644
> --- a/drivers/infiniband/hw/bng_re/bng_sp.c
> +++ b/drivers/infiniband/hw/bng_re/bng_sp.c

[ ... ]

> @@ -1200,3 +1226,834 @@ int bng_sp_fill_and_send_mpc_ah_modify(struct bng_re_res *res,

[ ... ]

> +static void __clean_cq(struct bng_sp_cq *cq, u64 qp)
> +{
> +	struct bng_re_hwq *cq_hwq = &cq->hwq;
> +	u32 peek_flags, peek_cons;
> +	struct cq_base *hw_cqe;
> +	int i;
> +
> +	peek_flags = cq->dbinfo.flags;
> +	peek_cons = cq_hwq->cons;
> +	/* This loop will terminate based on value of i */
> +	for (i = 0; i < cq_hwq->max_elements; i++) {
> +		hw_cqe = bng_re_get_qe(cq_hwq, peek_cons, NULL);
> +		if (!CQE_CMP_VALID(hw_cqe, peek_flags))
> +			break; /* ring is consumed in order: first invalid CQE ends the scan */
> +		/*
> +		 * The valid test of the entry must be done first before
> +		 * reading any further.
> +		 */
> +		dma_rmb();
> +		switch (hw_cqe->cqe_type_toggle & CQ_BASE_CQE_TYPE_MASK) {
> +		case CQ_BASE_CQE_TYPE_REQ:
> +		case CQ_BASE_CQE_TYPE_TERMINAL:
> +		{
> +			struct cq_req *cqe = (struct cq_req *)hw_cqe;
> +
> +			if (qp == le64_to_cpu(cqe->qp_handle))
> +				cqe->qp_handle = 0;
> +			break;
> +		}
> +		case CQ_BASE_CQE_TYPE_RES_RC:
> +		case CQ_BASE_CQE_TYPE_RES_UD:
> +		case CQ_BASE_CQE_TYPE_RES_RAWETH_QP1:
> +		{
> +			struct cq_res_rc *cqe = (struct cq_res_rc *)hw_cqe;
> +
> +			if (qp == le64_to_cpu(cqe->qp_handle))
> +				cqe->qp_handle = 0;
> +			break;
> +		}
> +		default:
> +			break;
> +		}

[Severity: Medium]
Does __clean_cq() miss CQ_BASE_CQE_TYPE_RES_UD_CFA and the V3 CQE types?

bng_sp_fill_mpc_qp_create_parms() unconditionally sets
CMDQ_CREATE_QP_QP_FLAGS_RESPONDER_UD_CQE_WITH_CFA for every GSI and UD QP,
so hardware emits CQ_BASE_CQE_TYPE_RES_UD_CFA responder CQEs (which carry
qid in struct cq_res_ud_cfa rather than qp_handle).  Any unpolled
RES_UD_CFA or V3 CQE falls through to default and is left referencing a
reset or freed kernel QP.

[ ... ]

> +void bng_re_clean_qp(struct bng_sp_qp *qp)
> +{
> +	unsigned long flags;
> +
> +	bng_re_acquire_cq_flush_locks(qp, &flags);
> +	__clean_cq(qp->scq, (u64)(unsigned long)qp);
> +	qp->sq.hwq.prod = 0;
> +	qp->sq.hwq.cons = 0;
> +	qp->sq.swq_start = 0;
> +	qp->sq.swq_last = 0;
> +	__clean_cq(qp->rcq, (u64)(unsigned long)qp);
> +	qp->rq.hwq.prod = 0;
> +	qp->rq.hwq.cons = 0;
> +	qp->rq.swq_start = 0;
> +	qp->rq.swq_last = 0;

[Severity: Medium]
Should bng_re_clean_qp() also clear qp->sq.dbinfo.flags and
qp->rq.dbinfo.flags?

bng_hwq_incr_prod() flips the producer epoch bit in dbinfo->flags on each
wraparound, and both bng_ring_prod_db() and __bng_re_modify_qp() encode
that bit into doorbells and rq_prod_idx.  If a kernel QP wraps an odd
number of times before moving to RESET and being reused, leaving
dbinfo.flags set causes a doorbell epoch mismatch with the reset hardware
context.

[Severity: Low]
When qp->rcq == qp->scq, does bng_re_clean_qp() scan the same CQ twice
with IRQs disabled?

bng_re_init_qp_attr() aliases scq and rcq for single-CQ QPs, and ULPs
often share one CQ.  Since the first __clean_cq() already scrubs all
matching requester and responder CQEs, guarding the second call with
if (qp->rcq != qp->scq) avoids doubling the cq_lock hold time against
bng_fp_process_cqn().

[ ... ]

> +	if (sp->type != CMDQ_CREATE_QP_TYPE_GSI &&
> +	    _is_ext_stats_supported(sp->dev_cap_ext_flags)) {
> +		d->ext_stats_ctx_id = cpu_to_le32(sp->roce_stat_ext_xid);
> +		qp_flags |= CMDQ_CREATE_QP_QP_FLAGS_EXT_STATS_CTX_VALID;
> +	}

[Severity: Low]
Is this ext_stats check testing the wrong capability flag on unpopulated
fields?

_is_ext_stats_supported() tests CREQ_QUERY_FUNC_RESP_SB_EXT_STATS (a
dev_cap_flags bit) against sp->dev_cap_ext_flags, and neither
sp->dev_cap_ext_flags nor sp->roce_stat_ext_xid is ever populated in the
driver.

[ ... ]

> +	if (bng_re_init_fw_state_rtr_enabled(res->cctx))
> +		d->rq_prod_idx = cpu_to_le16(sp->req_buffer_count);

[Severity: Medium]
Should d->rq_prod_idx only be populated from sp->req_buffer_count on the
initial RTR transition for non-SRQ QPs?

sp->req_buffer_count is never cleared after RTR or on RESET, so this
unconditionally overwrites the 0 set for SRQ QPs in
bng_sp_fill_mpc_qp_create_parms() and re-sends a stale producer index on
post-RTR transitions and recycled RESET->INIT->RTR QPs.

[ ... ]

> +	if (m & CMDQ_MODIFY_QP_MODIFY_MASK_SGID_INDEX)
> +		d->sgid_index = cpu_to_le16(res->sgid_tbl.hw_id[sp->ah.sgid_index]);

[Severity: Medium]
Can this read of res->sgid_tbl.hw_id[] race with concurrent GID table
updates or program an invalid 0xFFFF hardware GID index?

bng_sp_add_sgid() and bng_sp_del_sgid() mutate sgid_tbl.hw_id[] under
ib_core's GID table lock, which is not held during modify_qp() or
query_qp():

CPU0                                CPU1
bng_re_modify_qp()                  bng_re_del_gid()
  __filter_modify_flags()             bng_sp_del_sgid()
    qp->ah.sgid_index = 0               hw_id[0] = 0xFFFF
  bng_sp_fill_mpc_qp_modify_parms()
    d->sgid_index = hw_id[0]  <-- unsynchronized read / 0xFFFF

For UD/GSI INIT->RTR without IB_QP_AV, __filter_modify_flags() defaults
ah.sgid_index to 0 without holding a GID reference or checking for 0xFFFF.
bng_sp_query_qp() also scans all of res->sgid_tbl.hw_id[] without
synchronization.

[ ... ]

> +	rc = bng_re_roce_mpc_xmit(rdev, &cmd, sizeof(cmd),
> +				  &resp, sizeof(resp), false);
> +
> +	if (rc) {
> +		dev_err(&res->pdev->dev, "MPC: QP modify failed for QP %d, rc=%d\n",
> +			qp->sp_qp.id, rc);
> +		return rc;
> +	}

[Severity: High]
Can an -ETIMEDOUT or -EHOSTUNREACH failure on the initial QP create lead
to DMA use-after-free when the QP is later destroyed?

In bng_re_roce_mpc_xmit(), those errors can be returned after
bng_re_mpc_roce_send() has already posted the command to hardware.
Returning early here leaves BNG_SP_QP_FLAG_MPC_ALLOW_QP_DESTROY clear, so
a subsequent bng_re_destroy_qp() -> qp_destroy_qp_mpc() skips sending
QP_FREE, releases the XID/IQM, and frees the SQ/RQ HWQ DMA rings and user
umems while hardware may still execute the create and DMA to them.
Sibling bng_sp_fill_and_send_mpc_ah_modify() preserves the resource on
-ETIMEDOUT and -EHOSTUNREACH for the same reason.

[ ... ]

> +	dma_free_coherent(&rcfw->pdev->dev, sbuf.size,
> +			  sbuf.sb, sbuf.dma_addr);
> +
> +	return rc;
> +}

[Severity: High]
Can this unconditional dma_free_coherent() cause a DMA use-after-free if
CMDQ_BASE_OPCODE_QUERY_QP times out?

In bng_re_rcfw_send_message(), once the command is posted (msg->posted is
true), a timeout only marks crsqe->is_waiter_alive = false and returns
-ETIMEDOUT without cancelling firmware's DMA to sbuf.dma_addr.  Calling
bng_re_free_sbuf(rcfw, &sbuf, &msg, rc) here, as bng_re_get_roce_stats()
and bng_re_qext_stat() do, would avoid freeing the buffer while firmware
may still write to it.

> diff --git a/drivers/infiniband/hw/bng_re/bng_verbs.c b/drivers/infiniband/hw/bng_re/bng_verbs.c
> index a54ab2b9b96fe..de424085b9c44 100644
> --- a/drivers/infiniband/hw/bng_re/bng_verbs.c
> +++ b/drivers/infiniband/hw/bng_re/bng_verbs.c

[ ... ]

> @@ -1757,3 +1787,1565 @@ int bng_re_query_ah(struct ib_ah *ib_ah, struct rdma_ah_attr *ah_attr)

[ ... ]

> +		rq->max_wqe = bng_re_init_depth(init_attr->cap.max_recv_wr + 1,
> +						uctx);

[Severity: Medium]
Should the rounded queue depth be clamped to dev_attr->max_rq_wqes + 1
here and dev_attr->max_sq_wqes + 1 in bng_re_init_sq_attr()?

When userspace does not set BNG_RE_COMP_MASK_REQ_UCNTX_POW2_SUPPORT,
bng_re_init_depth() rounds up to a power of two.  Requesting
max_recv_wr = 4096 (within max_rq_wqes = 4351) rounds rq->max_wqe to 8192,
exceeding BNG_VAR_MAX_WQE, and requesting max_send_wr = 4096 with
max_send_sge >= 6 pushes sqsz past BNG_RE_MAX_SQSZ (65535), causing valid
create_qp() calls to fail with -EINVAL in bng_re_create_qp_stage1().

[ ... ]

> +	sp_qp->sq.sg_info.pgsize = PAGE_SIZE;
> +	sp_qp->sq.sg_info.pgshft = PAGE_SHIFT;

[Severity: High]
Does using PAGE_SIZE here (and in bng_re_init_rq_attr() and
bng_re_init_user_qp()) break QP rings on 16KB-page kernels?

bng_re_base_pg_size() only encodes 4K, 8K, 64K, 2M, 8M, and 1G, silently
falling back to BNG_RE_HWRM_PG_SIZE_4K for 16KB.  On a 16KB-page host,
the PBL is populated with 16KB DMA blocks while hardware is told they are
4KB, causing hardware to misaddress the ring past the first 4KB.

[ ... ]

> +	if (udata) {
> +		if (udata->inlen < sizeof(ureq))
> +			dev_warn_once(rdev_to_dev(rdev),
> +				      "Update the library ulen %d klen %d",
> +				      (unsigned int)udata->inlen,
> +				      (unsigned int)sizeof(ureq));
> +		rc = ib_copy_from_udata(&ureq, udata, min(udata->inlen, sizeof(ureq)));
> +		if (rc)
> +			return rc;
> +		/* No create QP comp_mask bits are defined yet */
> +		if (ureq.comp_mask)
> +			return -EOPNOTSUPP;
> +	}

[Severity: Medium]
Should truncated udata and non-zero trailing bytes be rejected here and in
__bng_re_modify_qp()?

If udata->inlen is smaller than sizeof(ureq), this only logs a warning
instead of rejecting a request missing qpsva/qprva, and trailing bytes
beyond sizeof(ureq) are never checked with ib_is_udata_cleared().
__bng_re_modify_qp() similarly does not reject unknown ureq.comp_mask
bits, non-zero ureq.rsvd, truncated req_buffer_count, or non-zero trailing
input bytes.

[ ... ]

> +	umem = ib_umem_get_va(&rdev->ibdev, ureq.qpsva, bytes,
> +			      IB_ACCESS_LOCAL_WRITE);

[Severity: Medium]
Does bng_re_init_user_qp() need to check PAGE_SIZE alignment on ureq.qpsva
and ureq.qprva?

bng_fill_user_dma_pages() populates the PBL with page-aligned DMA block
addresses and bng_sp_fill_mpc_qp_create_parms() hardcodes both SQ_FWO and
RQ_FWO to 0.  If userspace passes a non-page-aligned VA, hardware DMAs
starting at offset 0 of the first pinned page, desynchronizing WQE
indexing and corrupting user memory preceding the ring in that page.

[ ... ]

> +static enum ib_qp_state bng_re_cmdq_new_state_to_ib(u8 state)

[Severity: Low]
This isn't a bug, but bng_re_cmdq_new_state_to_ib() duplicates
__to_ib_qp_state() added in bng_verbs.h in the same patch.

There are a few similar cleanups in this patch: BNG_RE_XID_AVOID_REUSE is
redefined in bng_verbs.h despite already being defined in bng_re.h, struct
mpc_qp_modify_cmd and struct qp_modify_data duplicate 55 fields verbatim
instead of embedding qp_modify_data, and the ext_stats check in
bng_sp_fill_mpc_qp_create_parms() is dead code on uninitialized fields.

[ ... ]

> +	qp_attr->ah_attr.type = RDMA_AH_ATTR_TYPE_ROCE;
> +	memcpy(qp_attr->ah_attr.grh.dgid.raw, sp_qp->ah.dgid.data,
> +	       sizeof(sp_qp->ah.dgid.data));
> +	/* Mapping 16 bit udp_sport into 32 bit flow_lablel for qp_query, it should work fine */
> +	qp_attr->ah_attr.grh.flow_label = sp_qp->udp_sport;
> +	qp_attr->ah_attr.grh.sgid_index = sp_qp->ah.host_sgid_index;
> +	qp_attr->ah_attr.grh.hop_limit = sp_qp->ah.hop_limit;
> +	qp_attr->ah_attr.grh.traffic_class = sp_qp->ah.traffic_class;
> +	qp_attr->ah_attr.sl = sp_qp->ah.sl;

[Severity: High]
Does omitting IB_AH_GRH in qp_attr->ah_attr.ah_flags cause uverbs to drop
all GRH attributes on every query_qp() call?

copy_ah_attr_to_uverbs() only copies dgid, flow_label, sgid_index,
hop_limit, and traffic_class when IB_AH_GRH is set.  In addition,
qp_attr->ah_attr.port_num is left as 0, roce.dmac is never copied from
sb->dest_mac, and bng_sp_query_qp() stores the raw firmware PKey value
(0xFFFF) in qp->pkey_index instead of an index (0).

[ ... ]

> +static unsigned long bng_re_lock_cqs(struct bng_re_qp *qp)
> +{
> +	struct bng_re_cq *first, *second;
> +	unsigned long flags;
> +
> +	bng_re_order_cqs(qp, &first, &second);
> +	spin_lock_irqsave(&first->cq_lock, flags);
> +	if (second != first)
> +		spin_lock_nested(&second->cq_lock, SINGLE_DEPTH_NESTING);
> +
> +	return flags;
> +}
> +
> +static void bng_re_unlock_cqs(struct bng_re_qp *qp, unsigned long flags)
> +{
> +	struct bng_re_cq *first, *second;
> +
> +	bng_re_order_cqs(qp, &first, &second);
> +	if (second != first)
> +		spin_unlock(&second->cq_lock);
> +	spin_unlock_irqrestore(&first->cq_lock, flags);
> +}

[Severity: Low]
Should bng_re_lock_cqs() and bng_re_unlock_cqs() carry __acquires() /
__releases() and balancing __acquire() / __release() annotations like
bng_re_acquire_cq_flush_locks() and bng_re_release_cq_flush_locks() in
bng_sp.c?  Without them, sparse and Clang context analysis will report
context-imbalance warnings.

[ ... ]

> +	if (!dscp_valid && !pcp_valid) {
> +		dev_warn_ratelimited(rdev_to_dev(qp->rdev),
> +				     "Given DSCP %d and/or SL %d not mapping to lossless queue",
> +				     dscp, pri);
> +		dev_warn_ratelimited(rdev_to_dev(qp->rdev),
> +				     "Changing to default roce traffic class DSCP %d and SL %d",
> +				     rdev->tc_rec[0].roce_dscp, rdev->tc_rec[0].roce_prio);
> +	}
> +
> +default_queue:
> +	qp->sp_qp.ah.traffic_class = rdev->tc_rec[0].roce_dscp;
> +	qp->sp_qp.ah.sl = rdev->tc_rec[0].roce_prio;
> +	return 0;

[Severity: Medium]
Does bng_re_update_ah_dscp_sl() always overwrite non-zero caller DSCP and
SL values with 0?

The DCB fields added to struct bng_re_dev (d2p_count, d2p, p2cos,
lossless_q_count, lossless_qid, and tc_rec) are never populated anywhere
in the driver.  As a result, every modify_qp(IB_QP_AV) with non-zero
traffic_class or sl emits warnings and falls through to default_queue,
resetting both fields to 0.

[ ... ]

> +	if (udata && ib_copy_from_udata(&ureq, udata, min(udata->inlen, sizeof(ureq)))) {
> +		dev_err(rdev_to_dev(rdev), "qp %#x udata copy failed",
> +			qp->sp_qp.id);
> +		return -EINVAL;
> +	}

[Severity: Medium]
Should udata handling across create_qp, modify_qp, and destroy_qp follow
the same UAPI validation helpers used by the CQ verbs?

Here ib_copy_from_udata() failure returns -EINVAL instead of -EFAULT, and
unknown comp_mask bits, non-zero ureq.rsvd, short inlen, and trailing
input bytes are not rejected.  Both bng_re_create_qp() and
__bng_re_modify_qp() also use ib_copy_to_udata() instead of
ib_respond_udata() (leaving trailing output bytes unzeroed for larger
user buffers), and bng_re_destroy_qp() omits ib_no_udata_io(udata).

> +	if (qp_attr_mask & IB_QP_STATE) {
> +		curr_qp_state = bng_re_cmdq_new_state_to_ib(qp->sp_qp.cur_qp_state);
> +		new_qp_state = qp_attr->qp_state;

[Severity: Medium]
Should __bng_re_modify_qp() validate IB_QP_CUR_STATE and reject
out-of-range pkey_index values?

bng_re_query_device() advertises IB_DEVICE_CURR_QP_STATE_MOD, yet
IB_QP_CUR_STATE is never checked against curr_qp_state.  Likewise,
IB_QP_PKEY_INDEX accepts any u16 without checking
qp_attr->pkey_index >= dev_attr->max_pkey.

[ ... ]

> +		if (!ib_modify_qp_is_ok(curr_qp_state, new_qp_state,
> +					ib_qp->qp_type, qp_attr_mask)) {

[Severity: High]
Does nesting ib_modify_qp_is_ok() inside if (qp_attr_mask & IB_QP_STATE)
bypass state-machine validation whenever IB_QP_STATE is omitted?

When IB_QP_STATE is not set, the else branch sets
new_qp_state = curr_qp_state and applies every attribute in qp_attr_mask
without calling ib_modify_qp_is_ok().  An unprivileged uverbs caller can
pass illegal attributes for the QP's type or state (such as IB_QP_AV on a
UD QP, or IB_QP_DEST_QPN / IB_QP_ACCESS_FLAGS in RESET or ERR) directly
into sp_qp and firmware.

[ ... ]

> +	if (qp_attr_mask & IB_QP_EN_SQD_ASYNC_NOTIFY) {
> +		qp->sp_qp.modify_flags |=
> +				CMDQ_MODIFY_QP_MODIFY_MASK_EN_SQD_ASYNC_NOTIFY;
> +		qp->sp_qp.en_sqd_async_notify = true;
> +	}

[Severity: Medium]
Should this assign !!qp_attr->en_sqd_async_notify instead of
unconditionally setting true?  Passing IB_QP_EN_SQD_ASYNC_NOTIFY with
en_sqd_async_notify == 0 currently enables SQD async notifications instead
of disabling them.

[ ... ]

> +	if (qp_attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) {
> +		if (qp_attr->max_dest_rd_atomic >
> +		    dev_attr->max_qp_init_rd_atom) {
> +			ibdev_err(&rdev->ibdev,
> +				  "max_dest_rd_atomic requested%d is > dev_max%d",
> +				  qp_attr->max_dest_rd_atomic,
> +				  dev_attr->max_qp_init_rd_atom);
> +			return -EINVAL;
> +		}

[Severity: Medium]
Does returning -EINVAL here (or on later checks and firmware errors) leave
partially mutated fields and modify_flags dirty in qp->sp_qp?

Earlier attribute blocks already wrote into qp->sp_qp and OR'd bits into
qp->sp_qp.modify_flags, and the firmware error path only restores
qp->sp_qp.state.  Because init_fw_state_rtr is enabled and modify_flags is
not reset while rtr_transition_pending is true, rejected values persist in
bng_re_query_qp() and leak into the next RTR transition.

[ ... ]

> +			else if (qp_attr->qp_state == IB_QPS_RESET)
> +				qp->sp_qp.rtr_transition_pending = true;

[Severity: Medium]
Should transitioning to IB_QPS_RESET also clear qp->sp_qp.modify_flags and
qp->sp_qp.req_buffer_count?

Without clearing them, an INIT->RESET transition leaves pre-reset
modify_flags latched for the next RESET->INIT->RTR, and an
RTS->RESET->INIT->RTR sequence sends the stale req_buffer_count into
d->rq_prod_idx even when the RQ is empty.  (As noted in bng_re_clean_qp(),
sq/rq dbinfo.flags epoch bits are also left uncleared on RESET.)

[ ... ]

> +	if (udata) {
> +		rc = bng_re_copy_to_udata(rdev, &resp,
> +					  min(udata->outlen, sizeof(resp)),
> +					  udata);
> +		if (rc) {
> +			dev_err(rdev_to_dev(rdev), "%s: qp:%d error copying user data:%d\n",
> +				__func__, qp->sp_qp.id, rc);
> +			return rc;
> +		}
> +	}

[Severity: High]
Can a fault in bng_re_copy_to_udata() after firmware has committed the
modify leave hardware referencing a GID entry whose reference ib_core
drops?

When __bng_re_modify_qp() returns an error here, _ib_modify_qp() skips
updating qp->av_sgid_attr and calls rdma_unfill_sgid_attr(), releasing the
GID reference even though firmware is already using that GID.  Similarly,
if an earlier validation check fails after IB_QP_AV wrote ah.sgid_index
into qp->sp_qp without rollback, that unreferenced index stays latched for
the next modify.

[ ... ]

> +	if (test_bit(BNG_SP_QP_FLAG_MPC_ALLOW_QP_DESTROY, &qp->sp_qp.flags)) {
> +		/* Set the QP Free flag for actual QP destroy */
> +		set_bit(BNG_SP_QP_FLAG_MPC_QP_FREE, &qp->sp_qp.flags);
> +		rc = bng_sp_fill_and_send_mpc_qp_modify(res, qp);
> +	}

[Severity: Medium]
If bng_sp_fill_and_send_mpc_qp_modify() fails during destroy, should
BNG_SP_QP_FLAG_MPC_QP_FREE and the overwritten sp_qp.state / modify_flags
be rolled back?

When bng_re_destroy_qp() returns an error, ib_destroy_qp_user() leaves the
QP alive.  With BNG_SP_QP_FLAG_MPC_QP_FREE still set, any later
bng_re_modify_qp() on that surviving QP skips create parameters and sends
QP_FREE to firmware, destroying the QP in hardware while host state still
treats it as live.

> diff --git a/drivers/infiniband/hw/bng_re/bng_verbs.h b/drivers/infiniband/hw/bng_re/bng_verbs.h
> index eb2b3da09fd52..8c9c8fe2f2e80 100644
> --- a/drivers/infiniband/hw/bng_re/bng_verbs.h
> +++ b/drivers/infiniband/hw/bng_re/bng_verbs.h

[ ... ]

> @@ -99,6 +159,143 @@ static inline u16 bng_re_get_rwqe_size(int nsge)

[ ... ]

> +	if (mask & IB_QP_PATH_MTU) {
> +		qpmtu = qp_attr->path_mtu;
> +		qpmtu_int = ib_mtu_enum_to_int(qpmtu);
> +		if (qpmtu_int > ifmtu_int)
> +			return -EINVAL;
> +	}
> +	qp->sp_qp.path_mtu = __from_ib_mtu(qpmtu);
> +	qp->sp_qp.mtu = qpmtu_int;

[Severity: Medium]
Can an invalid enum ib_mtu value from userspace bypass this MTU check?

ib_mtu_enum_to_int() returns -1 for unrecognized values (and ifmtu_int is
-1 when netdev MTU is below 256), so qpmtu_int > ifmtu_int evaluates to
false.  That stores (u32)-1 in sp_qp.mtu and falls into __from_ib_mtu()'s
default case, programming a 2048-byte path MTU even on a smaller-MTU link.

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

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