Skip to contentSkip to conversation

RDMA/bnxt_re: Update the toggle page handling of CQ and SRQ

PATCH Superseded Selvin Xavier 1 participant 3 messages Jun 22

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Selvin Xavier

author maintainer
#0 lore raw

cover RDMA/bnxt_re: Update the toggle page handling of CQ and SRQ

Based on the suggestion from Jason (
https://patchwork.kernel.org/project/linux-rdma/patch/[email protected]/)
, adding the uverb object to retrieve the CQ an SRQ structures while getting the toggle mem. To work with older rdma-core, retain the existing code with modification.

The rdma-core pull request is here: https://github.com/linux-rdma/rdma-core/pull/1761

Please review and apply the series.

Thanks,
Selvin Xavier

Selvin Xavier (2):
RDMA/bnxt_re: Replace per-device hash tables with per-context XArray RDMA/bnxt_re: Add uverbs object handle path for CQ/SRQ toggle page

 drivers/infiniband/hw/bnxt_re/bnxt_re.h  |   6 --
 drivers/infiniband/hw/bnxt_re/ib_verbs.c |  58 ++++++++---
 drivers/infiniband/hw/bnxt_re/ib_verbs.h |   5 +-
 drivers/infiniband/hw/bnxt_re/main.c     |   5 -
 drivers/infiniband/hw/bnxt_re/uapi.c     | 124 +++++++++++------------
 include/uapi/rdma/bnxt_re-abi.h          |   4 +
 6 files changed, 112 insertions(+), 90 deletions(-)
Signature · 1 line
2.39.3
author maintainer
#1 lore raw

PATCH 1/2 RDMA/bnxt_re: Replace per-device hash tables with per-context XArray

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, and relies on the XArray's built-in locking to close the synchronization gap.

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.

---
 drivers/infiniband/hw/bnxt_re/bnxt_re.h  |  6 ---
 drivers/infiniband/hw/bnxt_re/ib_verbs.c | 51 +++++++++++++++++-------
 drivers/infiniband/hw/bnxt_re/ib_verbs.h |  4 +-
 drivers/infiniband/hw/bnxt_re/main.c     |  5 ---
 drivers/infiniband/hw/bnxt_re/uapi.c     | 37 ++---------------
 5 files changed, 42 insertions(+), 61 deletions(-)
drivers/infiniband/hw/bnxt_re/bnxt_re.h +0 -6
index 3a7ce4729fcf..a43e678151d3 100644
@@ -41,7 +41,6 @@
 #define __BNXT_RE_H__
 #include <rdma/uverbs_ioctl.h>
 #include "hw_counters.h"
-#include <linux/hashtable.h>
 #define ROCE_DRV_MODULE_NAME		"bnxt_re"
 
 #define BNXT_RE_DESC	"Broadcom NetXtreme-C/E RoCE Driver"
@@ -158,9 +157,6 @@ struct bnxt_re_nq_record {
 	struct mutex		load_lock;
 };
 
-#define MAX_CQ_HASH_BITS		(16)
-#define MAX_SRQ_HASH_BITS		(16)
-
 static inline bool bnxt_re_chip_gen_p7(u16 chip_num)
 {
 	return (chip_num == CHIP_NUM_58818 ||
@@ -215,8 +211,6 @@ struct bnxt_re_dev {
 	struct bnxt_re_pacing pacing;
 	struct work_struct dbq_fifo_check_work;
 	struct delayed_work dbq_pacing_work;
-	DECLARE_HASHTABLE(cq_hash, MAX_CQ_HASH_BITS);
-	DECLARE_HASHTABLE(srq_hash, MAX_SRQ_HASH_BITS);
 	struct dentry			*dbg_root;
 	struct dentry			*qp_debugfs;
 	unsigned long			event_bitmap;
drivers/infiniband/hw/bnxt_re/ib_verbs.c +37 -14

117 lines not on this page · raw message

drivers/infiniband/hw/bnxt_re/ib_verbs.h +2 -2
index 22bf81668cfb..76f407cd3435 100644
@@ -78,7 +78,6 @@ struct bnxt_re_srq {
 	struct ib_umem		*umem;
 	spinlock_t		lock;		/* protect srq */
 	void			*uctx_srq_page;
-	struct hlist_node       hash_entry;
 };
 
 struct bnxt_re_qp {
@@ -113,7 +112,6 @@ struct bnxt_re_cq {
 	struct ib_umem		*resize_umem;
 	int			resize_cqe;
 	void			*uctx_cq_page;
-	struct hlist_node	hash_entry;
 };
 
 struct bnxt_re_mr {
@@ -147,6 +145,8 @@ struct bnxt_re_ucontext {
 	void			*shpg;
 	spinlock_t		sh_lock;	/* protect shpg */
 	struct rdma_user_mmap_entry *shpage_mmap;
+	struct xarray		cq_xa;		/* cqid → bnxt_re_cq, for toggle page lookup */
+	struct xarray		srq_xa;		/* srqid → bnxt_re_srq, for toggle page lookup */
 	u64 cmask;
 };
 
drivers/infiniband/hw/bnxt_re/main.c +0 -5
index d25fdc458120..637f023b18ac 100644
@@ -54,7 +54,6 @@
 #include <rdma/ib_user_verbs.h>
 #include <rdma/ib_umem.h>
 #include <rdma/ib_addr.h>
-#include <linux/hashtable.h>
 #include <linux/bnxt/ulp.h>
 
 #include "roce_hsi.h"
@@ -2337,10 +2336,6 @@ static int bnxt_re_dev_init(struct bnxt_re_dev *rdev, u8 op_type)
 		if (!(rdev->qplib_res.en_dev->flags & BNXT_EN_FLAG_ROCE_VF_RES_MGMT))
 			bnxt_re_vf_res_config(rdev);
 	}
-	hash_init(rdev->cq_hash);
-	if (rdev->chip_ctx->modes.toggle_bits & BNXT_QPLIB_SRQ_TOGGLE_BIT)
-		hash_init(rdev->srq_hash);
-
 	bnxt_re_debugfs_add_pdev(rdev);
 
 	bnxt_re_init_dcb_wq(rdev);
drivers/infiniband/hw/bnxt_re/uapi.c +3 -34
index 263238a6e4cd..9485aa890b04 100644
@@ -22,32 +22,6 @@
 #include "bnxt_re.h"
 #include "ib_verbs.h"
 
-static struct bnxt_re_cq *bnxt_re_search_for_cq(struct bnxt_re_dev *rdev, u32 cq_id)
-{
-	struct bnxt_re_cq *cq = NULL, *tmp_cq;
-
-	hash_for_each_possible(rdev->cq_hash, tmp_cq, hash_entry, cq_id) {
-		if (tmp_cq->qplib_cq.id == cq_id) {
-			cq = tmp_cq;
-			break;
-		}
-	}
-	return cq;
-}
-
-static struct bnxt_re_srq *bnxt_re_search_for_srq(struct bnxt_re_dev *rdev, u32 srq_id)
-{
-	struct bnxt_re_srq *srq = NULL, *tmp_srq;
-
-	hash_for_each_possible(rdev->srq_hash, tmp_srq, hash_entry, srq_id) {
-		if (tmp_srq->qplib_srq.id == srq_id) {
-			srq = tmp_srq;
-			break;
-		}
-	}
-	return srq;
-}
-
 static int UVERBS_HANDLER(BNXT_RE_METHOD_NOTIFY_DRV)(struct uverbs_attr_bundle *attrs)
 {
 	struct bnxt_re_ucontext *uctx;
@@ -246,9 +220,8 @@ static int UVERBS_HANDLER(BNXT_RE_METHOD_GET_TOGGLE_MEM)(struct uverbs_attr_bund
 	struct bnxt_re_user_mmap_entry *entry;
 	struct bnxt_re_ucontext *uctx;
 	struct ib_ucontext *ib_uctx;
-	struct bnxt_re_dev *rdev;
-	struct bnxt_re_srq *srq;
 	u32 length = PAGE_SIZE;
+	struct bnxt_re_srq *srq;
 	struct bnxt_re_cq *cq;
 	u64 mem_offset;
 	u32 offset = 0;
@@ -265,31 +238,27 @@ static int UVERBS_HANDLER(BNXT_RE_METHOD_GET_TOGGLE_MEM)(struct uverbs_attr_bund
 		return err;
 
 	uctx = container_of(ib_uctx, struct bnxt_re_ucontext, ib_uctx);
-	rdev = uctx->rdev;
 	err = uverbs_copy_from(&res_id, attrs, BNXT_RE_TOGGLE_MEM_RES_ID);
 	if (err)
 		return err;
 
 	switch (res_type) {
 	case BNXT_RE_CQ_TOGGLE_MEM:
-		cq = bnxt_re_search_for_cq(rdev, res_id);
+		cq = xa_load(&uctx->cq_xa, res_id);
 		if (!cq)
 			return -EINVAL;
-
 		addr = (u64)cq->uctx_cq_page;
 		if (!addr)
 			return -EOPNOTSUPP;
 		break;
 	case BNXT_RE_SRQ_TOGGLE_MEM:
-		srq = bnxt_re_search_for_srq(rdev, res_id);
+		srq = xa_load(&uctx->srq_xa, res_id);
 		if (!srq)
 			return -EINVAL;
-
 		addr = (u64)srq->uctx_srq_page;
 		if (!addr)
 			return -EOPNOTSUPP;
 		break;
-
 	default:
 		return -EOPNOTSUPP;
 	}
Signature · 1 line
2.39.3
author maintainer
#2 lore raw

PATCH 2/2 RDMA/bnxt_re: Add uverbs object handle path for CQ/SRQ toggle page

In reply to Selvin Xavier

The current GET_TOGGLE_MEM ioctl requires the caller to supply a type enum and a raw hardware queue ID (RES_ID). The kernel looks up the CQ or SRQ by that ID without verifying that the caller owns the resource.

Add a new, preferred code path that accepts standard uverbs object handles (BNXT_RE_TOGGLE_MEM_CQ_HANDLE / BNXT_RE_TOGGLE_MEM_SRQ_HANDLE) instead.

Only newer rdma-core versions support this path. Capability is negotiated during context creation using the req mask (BNXT_RE_COMP_MASK_REQ_UCNTX_TOGGLE_MEM_UOBJ_SUPPORT) and resp mask (BNXT_RE_UCNTX_CMASK_TOGGLE_MEM_UOBJ_SUPPORT). The existing TYPE + RES_ID path is retained for backward compatibility with older rdma-core.

---
 drivers/infiniband/hw/bnxt_re/ib_verbs.c |  7 +-
 drivers/infiniband/hw/bnxt_re/ib_verbs.h |  1 +
 drivers/infiniband/hw/bnxt_re/uapi.c     | 95 ++++++++++++++++--------
 include/uapi/rdma/bnxt_re-abi.h          |  4 +
 4 files changed, 74 insertions(+), 33 deletions(-)
drivers/infiniband/hw/bnxt_re/ib_verbs.c +6 -1
index 72b4c47d694a..301116dcf55f 100644
@@ -4825,7 +4825,8 @@ int bnxt_re_alloc_ucontext(struct ib_ucontext *ctx, struct ib_udata *udata)
 		rc = ib_copy_validate_udata_in_cm(
 			udata, ureq, comp_mask,
 			BNXT_RE_COMP_MASK_REQ_UCNTX_POW2_SUPPORT |
-				BNXT_RE_COMP_MASK_REQ_UCNTX_VAR_WQE_SUPPORT);
+				BNXT_RE_COMP_MASK_REQ_UCNTX_VAR_WQE_SUPPORT |
+				BNXT_RE_COMP_MASK_REQ_UCNTX_TOGGLE_MEM_UOBJ_SUPPORT);
 		if (rc)
 			goto cfail;
 		if (ureq.comp_mask & BNXT_RE_COMP_MASK_REQ_UCNTX_POW2_SUPPORT) {
@@ -4838,6 +4839,10 @@ int bnxt_re_alloc_ucontext(struct ib_ucontext *ctx, struct ib_udata *udata)
 			if (resp.mode == BNXT_QPLIB_WQE_MODE_VARIABLE)
 				uctx->cmask |= BNXT_RE_UCNTX_CAP_VAR_WQE_ENABLED;
 		}
+		if (ureq.comp_mask & BNXT_RE_COMP_MASK_REQ_UCNTX_TOGGLE_MEM_UOBJ_SUPPORT) {
+			uctx->cmask |= BNXT_RE_UCNTX_CAP_TOGGLE_MEM_UOBJ;
+			resp.comp_mask |= BNXT_RE_UCNTX_CMASK_TOGGLE_MEM_UOBJ_SUPPORT;
+		}
 	}
 
 	xa_init(&uctx->cq_xa);
drivers/infiniband/hw/bnxt_re/ib_verbs.h +1 -0
index 76f407cd3435..85e594a25448 100644
@@ -193,6 +193,7 @@ static inline u16 bnxt_re_get_rwqe_size(int nsge)
 enum {
 	BNXT_RE_UCNTX_CAP_POW2_DISABLED = 0x1ULL,
 	BNXT_RE_UCNTX_CAP_VAR_WQE_ENABLED = 0x2ULL,
+	BNXT_RE_UCNTX_CAP_TOGGLE_MEM_UOBJ = 0x4ULL,
 };
 
 static inline u32 bnxt_re_init_depth(u32 ent, u32 max,
drivers/infiniband/hw/bnxt_re/uapi.c +63 -32

133 lines not on this page · raw message

include/uapi/rdma/bnxt_re-abi.h +4 -0
index a4599d7b736a..a6cfd68ed8f5 100644
@@ -57,6 +57,7 @@ enum {
 	BNXT_RE_UCNTX_CMASK_POW2_DISABLED = 0x10ULL,
 	BNXT_RE_UCNTX_CMASK_MSN_TABLE_ENABLED = 0x40,
 	BNXT_RE_UCNTX_CMASK_QP_RATE_LIMIT_ENABLED = 0x80ULL,
+	BNXT_RE_UCNTX_CMASK_TOGGLE_MEM_UOBJ_SUPPORT = 0x400000ULL,
 };
 
 enum bnxt_re_wqe_mode {
@@ -68,6 +69,7 @@ enum bnxt_re_wqe_mode {
 enum {
 	BNXT_RE_COMP_MASK_REQ_UCNTX_POW2_SUPPORT = 0x01,
 	BNXT_RE_COMP_MASK_REQ_UCNTX_VAR_WQE_SUPPORT = 0x02,
+	BNXT_RE_COMP_MASK_REQ_UCNTX_TOGGLE_MEM_UOBJ_SUPPORT = 0x20,
 };
 
 struct bnxt_re_uctx_req {
@@ -218,6 +220,8 @@ enum bnxt_re_var_toggle_mem_attrs {
 	BNXT_RE_TOGGLE_MEM_MMAP_PAGE,
 	BNXT_RE_TOGGLE_MEM_MMAP_OFFSET,
 	BNXT_RE_TOGGLE_MEM_MMAP_LENGTH,
+	BNXT_RE_TOGGLE_MEM_CQ_HANDLE,
+	BNXT_RE_TOGGLE_MEM_SRQ_HANDLE,
 };
 
 enum bnxt_re_toggle_mem_attrs {
Signature · 1 line
2.39.3