Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Selvin Xavier <selvin.xavier@broadcom.com>
Cc: jgg@ziepe.ca, linux-rdma@vger.kernel.org,
	andrew.gospodarek@broadcom.com,
	kalesh-anakkur.purayil@broadcom.com,
	sriharsha.basavapatna@broadcom.com, alhouseenyousef@gmail.com
Subject: Re: [PATCH for-next v3 1/4] RDMA/bnxt_re: Replace per-device hash tables with per-context XArrays
Date: Tue, 14 Jul 2026 15:19:44 +0300	[thread overview]
Message-ID: <20260714121944.GC19233@unreal> (raw)
In-Reply-To: <20260713135830.1934471-2-selvin.xavier@broadcom.com>

On Mon, Jul 13, 2026 at 06:58:27AM -0700, Selvin Xavier wrote:
> The CQ and SRQ hash tables (cq_hash, srq_hash) on struct bnxt_re_dev
> were used exclusively to look up a toggle-page pointer from a
> user-space-supplied hardware queue ID in the GET_TOGGLE_MEM
> ioctl handler. This approach has couple of problems. First,
> because the tables are per-device, any user can look up another
> user's CQ or SRQ by guessing the hardware queue ID. Second,
> concurrent add and remove operations on the hash table are not
> protected by any lock, leaving a race window.
> 
> The correct fix is to retrieve the CQ and SRQ objects via the uverbs
> object handle, which gives built-in ownership verification and reference
> pinning for the duration of the ioctl. That is added in the next patch of
> this series.
> 
> To maintain backward compatibility with older rdma-core versions that
> do not send a uverbs object handle, the driver must continue to support
> the existing TYPE + RES_ID lookup path. This patch replaces the per-device
> hash tables with per-ucontext XArrays (cq_xa and srq_xa on struct
> bnxt_re_ucontext), which narrows the lookup scope to the calling context,
> eliminating the cross-user visibility. Also adds Xarray locking mechanism
> for synchronization.
> 
> The GET_TOGGLE_MEM ioctl handler is updated to call xa_load()
> in place of the now-removed bnxt_re_search_for_cq()/
> bnxt_re_search_for_srq() helpers. No ABI changes are required.
> 
> Signed-off-by: Selvin Xavier <selvin.xavier@broadcom.com>
> ---
>  drivers/infiniband/hw/bnxt_re/bnxt_re.h  |  5 --
>  drivers/infiniband/hw/bnxt_re/ib_verbs.c | 76 ++++++++++++++++++------
>  drivers/infiniband/hw/bnxt_re/ib_verbs.h |  6 +-
>  drivers/infiniband/hw/bnxt_re/main.c     |  4 --
>  drivers/infiniband/hw/bnxt_re/uapi.c     | 75 ++++++++---------------
>  5 files changed, 87 insertions(+), 79 deletions(-)

<...>

> +		if (uctx) {
> +			xa_lock(&uctx->srq_xa);
> +			__xa_erase(&uctx->srq_xa, srq->qplib_srq.id);
> +			xa_unlock(&uctx->srq_xa);

Something very minor, there is no need in this lock->__erase->unlock
pattern, use xa_erase() directly as it will perform locking internally.

> +			free_page((unsigned long)srq->uctx_srq_page);

It is worth to get rid of get_zeroed_page/free_page too.
https://lore.kernel.org/linux-rdma/20260713-b4-rdma-v2-0-65d2a1a5180c@kernel.org/T/#t

Thanks

  reply	other threads:[~2026-07-14 12:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-13 13:58 [PATCH for-next v3 0/4] RDMA/bnxt_re: Update the toggle page handling of CQ and SRQ Selvin Xavier
2026-07-13 13:58 ` [PATCH for-next v3 1/4] RDMA/bnxt_re: Replace per-device hash tables with per-context XArrays Selvin Xavier
2026-07-14 12:19   ` Leon Romanovsky [this message]
2026-07-13 13:58 ` [PATCH for-next v3 2/4] RDMA/bnxt_re: Defer toggle page free to rdma_user_mmap_entry teardown Selvin Xavier
2026-07-13 13:58 ` [PATCH for-next v3 3/4] RDMA/bnxt_re: Fix toggle page UAF in GET_TOGGLE_MEM with mmap entry refcount Selvin Xavier
2026-07-13 13:58 ` [PATCH for-next v3 4/4] RDMA/bnxt_re: Add uverbs object handle path for CQ/SRQ toggle page Selvin Xavier

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=20260714121944.GC19233@unreal \
    --to=leon@kernel.org \
    --cc=alhouseenyousef@gmail.com \
    --cc=andrew.gospodarek@broadcom.com \
    --cc=jgg@ziepe.ca \
    --cc=kalesh-anakkur.purayil@broadcom.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=selvin.xavier@broadcom.com \
    --cc=sriharsha.basavapatna@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