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

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] RDMA/bng_re: u8 sgid_index in struct bng_sp_ah truncates 16-bit
  HW GID ID
- [Medium] RDMA/bng_re: dest_ah_wq lacks WQ_MEM_RECLAIM for flush in
  bng_re_dealloc_pd()
- [Medium] RDMA/bng_re: bng_re_create_ah() omits udata validation and
  response zero-pad
- [Medium] RDMA/bng_re: TOCTOU and slot-reuse race on sgid_tbl.hw_id in
  bng_re_create_ah()
- [Medium] RDMA/bng_re: un-ratelimited error logs on user AH create
  failures
- [Low] RDMA/bng_re: missing static qualifier for
  bng_re_posted_destroy_ah()
--

commit 4aa82821c41dc952a28686bc8dc4fa9145fbfc1c
Author: Mohammed Faraaz <mohammed.faraaz@broadcom.com>

RDMA/bng_re: Add AH verbs

This commit adds the create, destroy, and query AH verbs for bng_re, along
with the MPC AH modify command path, a workqueue for deferred non-sleepable
AH destroys, and the uverbs response structure.

> diff --git a/drivers/infiniband/hw/bng_re/bng_dev.c b/drivers/infiniband/hw/bng_re/bng_dev.c
> index 33556edaf37cd..2b6a4694a37e9 100644
> --- a/drivers/infiniband/hw/bng_re/bng_dev.c
> +++ b/drivers/infiniband/hw/bng_re/bng_dev.c

[ ... ]

> @@ -555,6 +570,12 @@ static int bng_re_dev_init(struct bng_re_dev *rdev)
>  	}
>  	bng_re_debugfs_add_mpc(rdev);
>  	bng_re_debugfs_add_mpctune(rdev);
> +
> +	rdev->dest_ah_wq = alloc_ordered_workqueue("bng_re_dest_ah", 0);
> +	if (!rdev->dest_ah_wq) {
> +		rc = -ENOMEM;
> +		goto deinit_mpc;
> +	}
>  	return 0;

[Severity: Medium]
Should dest_ah_wq be allocated with WQ_MEM_RECLAIM?

bng_re_dealloc_pd() calls flush_workqueue(rdev->dest_ah_wq), and storage
RDMA ULPs such as NVMe-oF/RDMA call ib_dealloc_pd() from WQ_MEM_RECLAIM
workqueues (for example nvme_reset_wq via nvme_rdma_error_recovery_work()
-> ... -> nvme_rdma_free_dev() -> ib_dealloc_pd()).  Flushing a
!WQ_MEM_RECLAIM workqueue from a WQ_MEM_RECLAIM worker triggers WARN_ONCE
in check_flush_dependency() and risks a reclaim deadlock under memory
pressure because bng_re_dest_ah has no rescuer thread.

[ ... ]

> diff --git a/drivers/infiniband/hw/bng_re/bng_sp.h b/drivers/infiniband/hw/bng_re/bng_sp.h
> index 74375615146b1..838566c0a4aa0 100644
> --- a/drivers/infiniband/hw/bng_re/bng_sp.h
> +++ b/drivers/infiniband/hw/bng_re/bng_sp.h
> @@ -207,6 +207,22 @@ struct bng_re_hw_stats {
>  	struct bng_re_rstat            rstat;
>  };
>  
> +struct bng_sp_ah {
> +	struct bng_re_gid			dgid;
> +	struct bng_sp_pd			*pd;
> +	u32				id;
> +	u8				sgid_index;

[Severity: High]
Won't declaring sgid_index as u8 truncate 16-bit firmware HW GID IDs?

sgid_tbl.hw_id is a u16 array and struct ah_modify_data expects __le16
sgid_index, so any firmware-assigned ID >= 256 has its upper byte dropped
when bng_re_create_ah() assigns sgid_tbl.hw_id[ctx->idx] into
ah->sp_ah.sgid_index.  bng_sp_fill_mpc_ah_modify_parms() then zero-extends
the truncated value, programming the wrong source GID index into the HW AH.
Changing sgid_index to u16 fixes this.

[ ... ]

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

[ ... ]

> @@ -1568,3 +1575,185 @@ int bng_re_destroy_srq(struct ib_srq *ib_srq, struct ib_udata *udata)
>  
>  	return 0;
>  }
> +
> +void bng_re_posted_destroy_ah(struct work_struct *work)

[Severity: Low]
bng_re_posted_destroy_ah() is only referenced in bng_re_destroy_ah() in this
file, so it can be static and its prototype removed from bng_verbs.h.

[ ... ]

> +	if (ctx->idx >= rdev->bng_res.sgid_tbl.max ||
> +	    rdev->bng_res.sgid_tbl.hw_id[ctx->idx] == 0xFFFF) {
> +		ibdev_err(&rdev->ibdev, "GID index %u has no HW id", ctx->idx);
> +		return -EINVAL;
> +	}
> +	ah->sp_ah.sgid_index = rdev->bng_res.sgid_tbl.hw_id[ctx->idx];

[Severity: Medium]
Can concurrent GID deletion and addition race with this hw_id lookup?

rdma_create_ah() holds only a kref on sgid_attr, and del_gid() in
drivers/infiniband/core/cache.c calls ops.del_gid() immediately without
waiting for that kref to drop.  Because sgid_tbl has no lock shared with
bng_re_create_ah(), the double read of hw_id[ctx->idx] can observe 0xFFFF
after the check passes:

CPU0                                 CPU1
bng_re_create_ah()                   del_gid()
  ctx = rdma_read_gid_hw_context()     bng_re_del_gid()
  check hw_id[ctx->idx] != 0xFFFF        bng_sp_del_sgid()
                                           sgid_tbl->hw_id[idx] = 0xFFFF
  sgid_index = hw_id[ctx->idx]  <-- reads 0xFFFF

In addition, bng_sp_del_sgid() zeroes sgid_tbl->tbl[index].gid immediately,
so a concurrent bng_sp_add_sgid() can reuse ctx->idx for a different GID or
VLAN and bng_re_create_ah() will program that unrelated hw_id into the AH.

[ ... ]

> +	rc = bng_sp_fill_and_send_mpc_ah_modify(&rdev->bng_res,
> +						ahs, 1, false, block);
> +	if (rc) {
> +		ibdev_err(&rdev->ibdev, "Failed to create HW AH");
> +		return rc;
> +	}
> +
> +	if (udata) {
> +		struct bng_re_ah_resp resp = {};
> +
> +		resp.ah_id = ah->sp_ah.id;
> +		rc = ib_copy_to_udata(udata, &resp,
> +				      min(udata->outlen, sizeof(resp)));

[Severity: Medium]
Should bng_re_create_ah() validate empty input udata with
ib_is_udata_in_empty(udata) and return the response via
ib_respond_udata(udata, resp), as bng_re_alloc_pd() does?

Without ib_is_udata_in_empty(), non-zero driver input from newer userspace
is silently ignored instead of returning -EOPNOTSUPP.  Using raw
ib_copy_to_udata() also skips zero-filling trailing bytes when
udata->outlen exceeds sizeof(resp).

> +		if (rc) {
> +			ibdev_err(&rdev->ibdev, "Failed to copy AH response");
> +			goto fail_destroy;
> +		}

[Severity: Medium]
Can an unprivileged uverbs user flood the kernel log through these error
paths?

Calling IB_USER_VERBS_CMD_CREATE_AH with an unmapped or read-only response
buffer triggers this un-ratelimited ibdev_err() on every syscall.  Once the
AH XID pool is exhausted, every subsequent user create_ah call also emits
two un-ratelimited errors: dev_err() in bng_sp_fill_and_send_mpc_ah_modify()
and ibdev_err() on "Failed to create HW AH" above.  Using ibdev_dbg() or
ratelimited logging (as in bng_re_create_user_cq() and bng_re_destroy_ah())
avoids user-triggerable log flooding.

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

  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 [this message]
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-251735@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=siva.kallam@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox