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=1796487014; b=RpCiIFB1HW0Pm1ZgdWvWpcQI7lxdk26poRbfbY2hDu4vnVDMeyci09JROt5W7u6/cOGJ AW1Z2odDCPQ3xuN6i4fjdFC465fQ2OKrmbh6vjR49QcnJmbotl5bqqkD2p35NyDbwf+Fj 6dzqFMc0x1t3btuqgH8VY6SUXyRYszT0OmpRXC/byF2jMOrAanHZviVmQcX4aBv4RwiRa Lcp7eLMSA2790DcrfnafeTfXIVau/FwIiql+J2ij9x+UBVZFj92fopIT5nKBpHqmuHkV4 C5gjQWpJg8xkYQY24J/yQYcU6DQa5j6ieaJa9o07a2/mqcNjWUmpsBoiTMa+AcjkDpA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796487014; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Tj1upOLqsb6wff7JWu4uLfZifPR21hEegs4q6IJjpF4=; b=o3+DTyhgvyVG7tYFQPETLEd79kA6RxSW+iIds5CM613S/Qko3LN/54MhcMKi/biqof4J ddwloOHZ2KT/JWrLRU5MDxlzkb83N3RMrbmTpbsi1kEqiDgtQkIOSG6voYrO2Hi/HKcu1 HsulagovaLgSu+4GilxUsgwA7l72Qh0ytfYaTzB5vaXpV2UYMTzAVRclbT+Xg9A672Pa7 1gyNzEEP7vvvwmzxqaPrZh8q1B74VyRMKrS3M53x/zQg3E/35Hh2LL0JDr4lnaLYeCz+w Vl39/rkp2CLcJx6r6n4tPe609jcb2O1V3ui734/YR1QT7v/hutvrUxTFkMQLxx7XUeQ== 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=chj7HIow; 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 8D250606A332 for ; Sat, 5 Dec 2026 16:10:14 +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=chj7HIow Received: by smtp.kernel.org (Postfix) with ESMTPSA id 071E71F00A13; Sat, 5 Dec 2026 16:10:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796487014; bh=Tj1upOLqsb6wff7JWu4uLfZifPR21hEegs4q6IJjpF4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=chj7HIow3IgXYNWC3YKKBFBVZsHTH0AMs5fw9PNkTajqE82IBBm9brs8M+JVWmbiU jqS7uQ/RNpwsskBMJlJ0IUnza4p0SElOOoyr3THNoI3sTbZ525bOnginx6Jo/1qmKG 0Xugm7Q4zg7qdDbMsBo9hIY/Qxs+ZZOT9j0dTKxPpqezKR/dJ/YSM385w6AXO8wNEr err5QiRqijCZ7RbRmyHNU3sTHc3lTtq88AbXlVEDFKv2EBX/NvHGeDSGhr2eb2SoSo nX17qGV1iSLUvz6J1QIKQzSK024VGh3R6JVPG5IzMcpkgx5YZ2FpKsCbeNaUAb4o0E knLih9H9jTwRg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RDMA v2 12/13] RDMA/bng_re: Add QP verbs Reply-To: sashiko-reviews@lists.linux.dev To: "Siva Reddy Kallam" Cc: linux-rdma@vger.kernel.org In-Reply-To: <20261204155249.1002019-13-siva.kallam@broadcom.com> References: <20261204155249.1002019-1-siva.kallam@broadcom.com> <20261204155249.1002019-13-siva.kallam@broadcom.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 16:10:13 +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: 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=3D0 - [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 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/h= w/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 =3D &cq->hwq; > + u32 peek_flags, peek_cons; > + struct cq_base *hw_cqe; > + int i; > + > + peek_flags =3D cq->dbinfo.flags; > + peek_cons =3D cq_hwq->cons; > + /* This loop will terminate based on value of i */ > + for (i =3D 0; i < cq_hwq->max_elements; i++) { > + hw_cqe =3D 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 =3D (struct cq_req *)hw_cqe; > + > + if (qp =3D=3D le64_to_cpu(cqe->qp_handle)) > + cqe->qp_handle =3D 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 =3D (struct cq_res_rc *)hw_cqe; > + > + if (qp =3D=3D le64_to_cpu(cqe->qp_handle)) > + cqe->qp_handle =3D 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 =3D 0; > + qp->sq.hwq.cons =3D 0; > + qp->sq.swq_start =3D 0; > + qp->sq.swq_last =3D 0; > + __clean_cq(qp->rcq, (u64)(unsigned long)qp); > + qp->rq.hwq.prod =3D 0; > + qp->rq.hwq.cons =3D 0; > + qp->rq.swq_start =3D 0; > + qp->rq.swq_last =3D 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 =3D=3D 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 !=3D qp->scq) avoids doubling the cq_lock hold time against bng_fp_process_cqn(). [ ... ] > + if (sp->type !=3D CMDQ_CREATE_QP_TYPE_GSI && > + _is_ext_stats_supported(sp->dev_cap_ext_flags)) { > + d->ext_stats_ctx_id =3D cpu_to_le32(sp->roce_stat_ext_xid); > + qp_flags |=3D 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 =3D 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 =3D 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 =3D 0 hw_id[0] =3D 0xFFFF bng_sp_fill_mpc_qp_modify_parms() d->sgid_index =3D 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 =3D 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=3D%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 =3D 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/infiniban= d/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 =3D 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 =3D 4096 (within max_rq_wqes =3D 4351) rounds rq->max_wqe to 81= 92, exceeding BNG_VAR_MAX_WQE, and requesting max_send_wr =3D 4096 with max_send_sge >=3D 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 =3D PAGE_SIZE; > + sp_qp->sq.sg_info.pgshft =3D 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 =3D 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 =3D 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 =3D 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 sh= ould work fine */ > + qp_attr->ah_attr.grh.flow_label =3D sp_qp->udp_sport; > + qp_attr->ah_attr.grh.sgid_index =3D sp_qp->ah.host_sgid_index; > + qp_attr->ah_attr.grh.hop_limit =3D sp_qp->ah.hop_limit; > + qp_attr->ah_attr.grh.traffic_class =3D sp_qp->ah.traffic_class; > + qp_attr->ah_attr.sl =3D 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 !=3D 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 !=3D 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 =3D rdev->tc_rec[0].roce_dscp; > + qp->sp_qp.ah.sl =3D 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 =3D bng_re_cmdq_new_state_to_ib(qp->sp_qp.cur_qp_state); > + new_qp_state =3D 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 >=3D 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 =3D 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 |=3D > + CMDQ_MODIFY_QP_MODIFY_MASK_EN_SQD_ASYNC_NOTIFY; > + qp->sp_qp.en_sqd_async_notify =3D 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 =3D=3D 0 currently enables SQD async notifications inst= ead 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 =3D=3D IB_QPS_RESET) > + qp->sp_qp.rtr_transition_pending =3D 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 =3D 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 =3D 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/infiniban= d/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 =3D qp_attr->path_mtu; > + qpmtu_int =3D ib_mtu_enum_to_int(qpmtu); > + if (qpmtu_int > ifmtu_int) > + return -EINVAL; > + } > + qp->sp_qp.path_mtu =3D __from_ib_mtu(qpmtu); > + qp->sp_qp.mtu =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204155249.1002= 019-1-siva.kallam@broadcom.com?part=3D12