RDMA/bnxt_re: Generic driver fixes
Subsystems (2)
Selvin Xavier
maintainercover RDMA/bnxt_re: Generic driver fixes
Includes fixes for few issues pointed by sashiko. Also, some generic fixes found during internal code reviews.
Please review and Apply.
Thanks,
Selvin Xavier
Selvin Xavier (11):
RDMA/bnxt_re : Initialize dpi variable to zero RDMA/bnxt_re: Add ownership check while getting the CQ toggle page RDMA/bnxt_re: Add ownership check while getting the SRQ toggle page RDMA/bnxt_re: Avoid displaying the kernel pointer RDMA/bnxt_re: Add a max slot check for SQ
RDMA/bnxt_re: Avoid repeated requests to allocate WC pages RDMA/bnxt_re: Avoid any race while handling the hash list of CQ RDMA/bnxt_re: Avoid any race while handling the hash list of SRQ RDMA/bnxt_re: Fix the cleanup upon error during srq create RDMA/bnxt_re: Fix the cleanup upon error during CQ create RDMA/bnxt_re: Fail DBR related page allocation UAPIs if the feature is
disabled
drivers/infiniband/hw/bnxt_re/bnxt_re.h | 2 ++ drivers/infiniband/hw/bnxt_re/ib_verbs.c | 35 ++++++++++++++++++++++-- drivers/infiniband/hw/bnxt_re/ib_verbs.h | 2 ++ drivers/infiniband/hw/bnxt_re/main.c | 4 +-- drivers/infiniband/hw/bnxt_re/qplib_sp.h | 1 + drivers/infiniband/hw/bnxt_re/uapi.c | 19 ++++++++++++- 6 files changed, 57 insertions(+), 6 deletions(-)
Signature · 1 line
2.39.3
Selvin Xavier
maintainerPATCH 1/11 RDMA/bnxt_re : Initialize dpi variable to zero
dpi is initialized only for BNXT_RE_ALLOC_WC_PAGE, but copied for all the cases. So initialize the dpi to 0.
--- drivers/infiniband/hw/bnxt_re/uapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/bnxt_re/uapi.c +1 -1
@@ -76,8 +76,8 @@ static int UVERBS_HANDLER(BNXT_RE_METHOD_ALLOC_PAGE)(struct uverbs_attr_bundle *struct ib_ucontext *ib_uctx;struct bnxt_re_dev *rdev;u64 mmap_offset; +u32 dpi =0 ;u32 length; -u32 dpi;u64 addr;int err;
Signature · 1 line
2.39.3
Selvin Xavier
maintainerPATCH 2/11 RDMA/bnxt_re: Add ownership check while getting the CQ toggle page
In reply to Selvin XavierThe cq resource id provided by user-space is used for searching the driver CQ structure. Validate if the context currently issuing the request is same as the context created the resource.
--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 1 + drivers/infiniband/hw/bnxt_re/ib_verbs.h | 1 + drivers/infiniband/hw/bnxt_re/uapi.c | 3 +++ 3 files changed, 5 insertions(+)
drivers/infiniband/hw/bnxt_re/ib_verbs.c +1 -0
@@ -3489,6 +3489,7 @@ int bnxt_re_create_user_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attreturn -EINVAL ; cq->rdev = rdev; + cq->uctx = &uctx->ib_uctx; cctx = rdev->chip_ctx; cq->qplib_cq.cq_handle = (u64 )(unsigned long )(&cq->qplib_cq);
drivers/infiniband/hw/bnxt_re/ib_verbs.h +1 -0
@@ -102,6 +102,7 @@ struct bnxt_re_qp {struct bnxt_re_cq {struct ib_cq ib_cq;struct bnxt_re_dev *rdev; +struct ib_ucontext *uctx;spinlock_t cq_lock;/* protect cq */ u16 cq_count;u16 cq_period;
drivers/infiniband/hw/bnxt_re/uapi.c +3 -0
@@ -251,6 +251,9 @@ static int UVERBS_HANDLER(BNXT_RE_METHOD_GET_TOGGLE_MEM)(struct uverbs_attr_bundif (!cq)return -EINVAL ; +if (cq->uctx != ib_uctx) +return -EINVAL ; + addr = (u64 )cq->uctx_cq_page;break ;case BNXT_RE_SRQ_TOGGLE_MEM :
Signature · 1 line
2.39.3
Selvin Xavier
maintainerPATCH 3/11 RDMA/bnxt_re: Add ownership check while getting the SRQ toggle page
In reply to Selvin XavierThe SRQ resource id provided by user-space is used for searching the driver SRQ structure. Validate if the context currently issuing the request is same as the context created the resource.
--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 1 + drivers/infiniband/hw/bnxt_re/ib_verbs.h | 1 + drivers/infiniband/hw/bnxt_re/uapi.c | 3 +++ 3 files changed, 5 insertions(+)
drivers/infiniband/hw/bnxt_re/ib_verbs.c +1 -0
@@ -2225,6 +2225,7 @@ int bnxt_re_create_srq(struct ib_srq *ib_srq, uctx = rdma_udata_to_drv_context(udata, struct bnxt_re_ucontext, ib_uctx); srq->rdev = rdev; + srq->uctx = udata ? &uctx->ib_uctx :NULL ; srq->qplib_srq.pd = &pd->qplib_pd; srq->qplib_srq.dpi = &rdev->dpi_privileged;/* Allocate 1 more than what's provided so posting max doesn't
drivers/infiniband/hw/bnxt_re/ib_verbs.h +1 -0
@@ -73,6 +73,7 @@ struct bnxt_re_ah {struct bnxt_re_srq {struct ib_srq ib_srq;struct bnxt_re_dev *rdev; +struct ib_ucontext *uctx;u32 srq_limit;struct bnxt_qplib_srq qplib_srq;struct ib_umem *umem;
drivers/infiniband/hw/bnxt_re/uapi.c +3 -0
@@ -261,6 +261,9 @@ static int UVERBS_HANDLER(BNXT_RE_METHOD_GET_TOGGLE_MEM)(struct uverbs_attr_bundif (!srq)return -EINVAL ; +if (srq->uctx != ib_uctx) +return -EINVAL ; + addr = (u64 )srq->uctx_srq_page;break ;
Signature · 1 line
2.39.3
Selvin Xavier
maintainerPATCH 4/11 RDMA/bnxt_re: Avoid displaying the kernel pointer
In reply to Selvin XavierWhile dumping the info on MR using the rdma tool, we dump the mr_hwq which is a kernel pointer. There is no need to expose this value for end user. So avoid it.
--- drivers/infiniband/hw/bnxt_re/main.c | 2 -- 1 file changed, 2 deletions(-)
drivers/infiniband/hw/bnxt_re/main.c +0 -2
@@ -1093,8 +1093,6 @@ static int bnxt_re_fill_res_mr_entry(struct sk_buff *msg, struct ib_mr *ib_mr) goto err;if (rdma_nl_put_driver_u32 (msg,"element_size" , mr_hwq->element_size)) goto err; -if (rdma_nl_put_driver_u64_hex (msg,"hwq" , (unsigned long )mr_hwq)) - goto err;if (rdma_nl_put_driver_u64_hex (msg,"va" , mr->qplib_mr.va)) goto err;
Signature · 1 line
2.39.3
Selvin Xavier
maintainerPATCH 5/11 RDMA/bnxt_re: Add a max slot check for SQ
In reply to Selvin XavierThe variable WQE mode must be validated against the maximum slots supported by HW. The max supported value is 64K. Adding a max check and fail if user supplied value is more than the max supported.
--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 3 +++ drivers/infiniband/hw/bnxt_re/qplib_sp.h | 1 + 2 files changed, 4 insertions(+)
drivers/infiniband/hw/bnxt_re/ib_verbs.c +3 -0
@@ -1748,6 +1748,9 @@ static int bnxt_re_init_qp_attr(struct bnxt_re_qp *qp, struct bnxt_re_pd *pd,return qptype; qplqp->type = (u8 )qptype; qplqp->wqe_mode =bnxt_re_is_var_size_supported (rdev, uctx); +if (uctx && qplqp->wqe_mode ==BNXT_QPLIB_WQE_MODE_VARIABLE && + ureq->sq_slots >BNXT_RE_MAX_SQ_SLOTS ) +return -EINVAL ;if (fixed_que_attr) {if (qplqp->wqe_mode !=BNXT_QPLIB_WQE_MODE_VARIABLE )return -EOPNOTSUPP ;
drivers/infiniband/hw/bnxt_re/qplib_sp.h +1 -0
@@ -369,6 +369,7 @@ int bnxt_qplib_destroy_flow(struct bnxt_qplib_res *res);#define BNXT_VAR_MAX_SLOT_ALIGN 256#define BNXT_VAR_MAX_SGE 13#define BNXT_RE_MAX_RQ_WQES 65536 +#define BNXT_RE_MAX_SQ_SLOTS 65536#define BNXT_STATIC_MAX_SGE 6
Signature · 1 line
2.39.3
Selvin Xavier
maintainerPATCH 6/11 RDMA/bnxt_re: Avoid repeated requests to allocate WC pages
In reply to Selvin XavierApplications can request for allocating multiple WC pages for the same ucontext. As of now, supporting only 1 WC page per ucontext. Adding a check to fail the repeated requests.
--- drivers/infiniband/hw/bnxt_re/uapi.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/infiniband/hw/bnxt_re/uapi.c +3 -0
@@ -99,6 +99,9 @@ static int UVERBS_HANDLER(BNXT_RE_METHOD_ALLOC_PAGE)(struct uverbs_attr_bundle *switch (alloc_type) {case BNXT_RE_ALLOC_WC_PAGE :if (cctx->modes.db_push) { +/* already allocated — one WC page per context */ +if (uctx->wcdpi.dbr) +return -EEXIST ;if (bnxt_qplib_alloc_dpi (&rdev->qplib_res, &uctx->wcdpi, uctx,BNXT_QPLIB_DPI_TYPE_WC ))return -ENOMEM ;
Signature · 1 line
2.39.3
Selvin Xavier
maintainerRe: [PATCH 06/11] RDMA/bnxt_re: Avoid repeated requests to allocate WC pages
Quoted 18 lines · Selvin Xavier
Applications can request for allocating multiple WC pages for the same ucontext. As of now, supporting only 1 WC page per ucontext. Adding a check to fail the repeated requests.
Fixes eee6268421a2 ("RDMA/bnxt_re: Move the UAPI methods to a dedicated file")Fixes 360da60d6c6e ("RDMA/bnxt_re: Enable low latency push")Reviewed-by Kalesh AP <[email protected]>Signed-off-by Selvin Xavier <[email protected]>--- drivers/infiniband/hw/bnxt_re/uapi.c | 3 +++ 1 file changed, 3 insertions(+)drivers/infiniband/hw/bnxt_re/uapi.c +0
-0
drivers/infiniband/hw/bnxt_re/uapi.c static int UVERBS_HANDLER(BNXT_RE_METHOD_ALLOC_PAGE)(struct uverbs_attr_bundle * · line 104
Quoted 6 lines
drivers/infiniband/hw/bnxt_re/uapi.c +3
-0@@ -99,6 +99,9 @@ static int UVERBS_HANDLER(BNXT_RE_METHOD_ALLOC_PAGE)(struct uverbs_attr_bundle *switch (alloc_type) {case BNXT_RE_ALLOC_WC_PAGE :if (cctx->modes.db_push) { +/* already allocated — one WC page per context */ +if (uctx->wcdpi.dbr) +return -EEXIST ;
Sashiko pointed out a regression about a synchronization issue. I will rework on it. thanks.
Quoted 6 lines
drivers/infiniband/hw/bnxt_re/uapi.c +0
-1if (bnxt_qplib_alloc_dpi (&rdev->qplib_res, &uctx->wcdpi, uctx,BNXT_QPLIB_DPI_TYPE_WC ))return -ENOMEM ; --2.39.3
Selvin Xavier
maintainerPATCH 7/11 RDMA/bnxt_re: Avoid any race while handling the hash list of CQ
In reply to Selvin XavierAdding/Deleting to/from hash list needs to be synchronized with the traversing of the hash list. Adding a mutex for this synchronization to avoid any usage of the CQ structures after the CQ is freed.
--- drivers/infiniband/hw/bnxt_re/bnxt_re.h | 1 + drivers/infiniband/hw/bnxt_re/ib_verbs.c | 4 ++++ drivers/infiniband/hw/bnxt_re/main.c | 1 + drivers/infiniband/hw/bnxt_re/uapi.c | 2 ++ 4 files changed, 8 insertions(+)
drivers/infiniband/hw/bnxt_re/bnxt_re.h +1 -0
@@ -217,6 +217,7 @@ struct bnxt_re_dev {struct delayed_work dbq_pacing_work;DECLARE_HASHTABLE (cq_hash,MAX_CQ_HASH_BITS );DECLARE_HASHTABLE (srq_hash,MAX_SRQ_HASH_BITS ); +struct mutex cq_hash_lock;/* guards cq_hash */ struct dentry *dbg_root;struct dentry *qp_debugfs;unsigned long event_bitmap;
drivers/infiniband/hw/bnxt_re/ib_verbs.c +4 -0
@@ -3458,7 +3458,9 @@ int bnxt_re_destroy_cq(struct ib_cq *ib_cq, struct ib_udata *udata)if (cctx->modes.toggle_bits &BNXT_QPLIB_CQ_TOGGLE_BIT ) {free_page ((unsigned long )cq->uctx_cq_page); +mutex_lock (&rdev->cq_hash_lock);hash_del (&cq->hash_entry); +mutex_unlock (&rdev->cq_hash_lock); }bnxt_qplib_destroy_cq (&rdev->qplib_res, &cq->qplib_cq);
@@ -3536,7 +3538,9 @@ int bnxt_re_create_user_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attspin_lock_init (&cq->cq_lock);if (cctx->modes.toggle_bits &BNXT_QPLIB_CQ_TOGGLE_BIT ) { +mutex_lock (&rdev->cq_hash_lock);hash_add (rdev->cq_hash, &cq->hash_entry, cq->qplib_cq.id); +mutex_unlock (&rdev->cq_hash_lock);/* Allocate a page */ cq->uctx_cq_page = (void *)get_zeroed_page (GFP_KERNEL );if (!cq->uctx_cq_page) {
drivers/infiniband/hw/bnxt_re/main.c +1 -0
@@ -2338,6 +2338,7 @@ static int bnxt_re_dev_init(struct bnxt_re_dev *rdev, u8 op_type)bnxt_re_vf_res_config (rdev); }hash_init (rdev->cq_hash); +mutex_init (&rdev->cq_hash_lock);if (rdev->chip_ctx->modes.toggle_bits &BNXT_QPLIB_SRQ_TOGGLE_BIT )hash_init (rdev->srq_hash);
drivers/infiniband/hw/bnxt_re/uapi.c +2 -0
@@ -26,12 +26,14 @@ static struct bnxt_re_cq *bnxt_re_search_for_cq(struct bnxt_re_dev *rdev, u32 cq {struct bnxt_re_cq *cq =NULL , *tmp_cq; +mutex_lock (&rdev->cq_hash_lock);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 ; } } +mutex_unlock (&rdev->cq_hash_lock);return cq; }
Signature · 1 line
2.39.3
Selvin Xavier
maintainerPATCH 8/11 RDMA/bnxt_re: Avoid any race while handling the hash list of SRQ
In reply to Selvin XavierAdding/Deleting to/from hash list needs to be synchronized with the traversing of the hash list. Adding a mutex for this synchronization to avoid any usage of the SRQ structures after the SRQ is freed.
--- drivers/infiniband/hw/bnxt_re/bnxt_re.h | 1 + drivers/infiniband/hw/bnxt_re/ib_verbs.c | 4 ++++ drivers/infiniband/hw/bnxt_re/main.c | 1 + drivers/infiniband/hw/bnxt_re/uapi.c | 2 ++ 4 files changed, 8 insertions(+)
drivers/infiniband/hw/bnxt_re/bnxt_re.h +1 -0
@@ -218,6 +218,7 @@ struct bnxt_re_dev {DECLARE_HASHTABLE (cq_hash,MAX_CQ_HASH_BITS );DECLARE_HASHTABLE (srq_hash,MAX_SRQ_HASH_BITS );struct mutex cq_hash_lock;/* guards cq_hash */ +struct mutex srq_hash_lock;/* guards srq_hash */ struct dentry *dbg_root;struct dentry *qp_debugfs;unsigned long event_bitmap;
drivers/infiniband/hw/bnxt_re/ib_verbs.c +4 -0
@@ -2154,7 +2154,9 @@ int bnxt_re_destroy_srq(struct ib_srq *ib_srq, struct ib_udata *udata)if (rdev->chip_ctx->modes.toggle_bits &BNXT_QPLIB_SRQ_TOGGLE_BIT ) {free_page ((unsigned long )srq->uctx_srq_page); +mutex_lock (&rdev->srq_hash_lock);hash_del (&srq->hash_entry); +mutex_unlock (&rdev->srq_hash_lock); }bnxt_qplib_destroy_srq (&rdev->qplib_res, qplib_srq);ib_umem_release (srq->umem);
@@ -2264,7 +2266,9 @@ int bnxt_re_create_srq(struct ib_srq *ib_srq, resp.srqid = srq->qplib_srq.id;if (rdev->chip_ctx->modes.toggle_bits &BNXT_QPLIB_SRQ_TOGGLE_BIT ) { +mutex_lock (&rdev->srq_hash_lock);hash_add (rdev->srq_hash, &srq->hash_entry, srq->qplib_srq.id); +mutex_unlock (&rdev->srq_hash_lock); srq->uctx_srq_page = (void *)get_zeroed_page (GFP_KERNEL );if (!srq->uctx_srq_page) { rc = -ENOMEM ;
drivers/infiniband/hw/bnxt_re/main.c +1 -0
@@ -2341,6 +2341,7 @@ static int bnxt_re_dev_init(struct bnxt_re_dev *rdev, u8 op_type)mutex_init (&rdev->cq_hash_lock);if (rdev->chip_ctx->modes.toggle_bits &BNXT_QPLIB_SRQ_TOGGLE_BIT )hash_init (rdev->srq_hash); +mutex_init (&rdev->srq_hash_lock);bnxt_re_debugfs_add_pdev (rdev);
drivers/infiniband/hw/bnxt_re/uapi.c +2 -0
@@ -41,12 +41,14 @@ static struct bnxt_re_srq *bnxt_re_search_for_srq(struct bnxt_re_dev *rdev, u32 {struct bnxt_re_srq *srq =NULL , *tmp_srq; +mutex_lock (&rdev->srq_hash_lock);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 ; } } +mutex_unlock (&rdev->srq_hash_lock);return srq; }
Signature · 1 line
2.39.3
Selvin Xavier
maintainerPATCH 9/11 RDMA/bnxt_re: Fix the cleanup upon error during srq create
In reply to Selvin XavierFix the failure path of SRQ create. Destroy the SRQ from HW and delete from the hashlist if the page allocation fails. Also, add an explicit check for NULL before calling free_page.
--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/infiniband/hw/bnxt_re/ib_verbs.c +9 -0
@@ -2272,6 +2272,8 @@ int bnxt_re_create_srq(struct ib_srq *ib_srq, srq->uctx_srq_page = (void *)get_zeroed_page (GFP_KERNEL );if (!srq->uctx_srq_page) { rc = -ENOMEM ; +bnxt_qplib_destroy_srq (&rdev->qplib_res, + &srq->qplib_srq); goto fail; } resp.comp_mask |=BNXT_RE_SRQ_TOGGLE_PAGE_SUPPORT ;
@@ -2291,6 +2293,13 @@ int bnxt_re_create_srq(struct ib_srq *ib_srq,return 0 ; fail: +if (rdev->chip_ctx->modes.toggle_bits &BNXT_QPLIB_SRQ_TOGGLE_BIT ) { +mutex_lock (&rdev->srq_hash_lock); +hash_del (&srq->hash_entry); +mutex_unlock (&rdev->srq_hash_lock); +if (srq->uctx_srq_page) +free_page ((unsigned long )srq->uctx_srq_page); + }ib_umem_release (srq->umem); exit:return rc;
Signature · 1 line
2.39.3
Selvin Xavier
maintainerPATCH 10/11 RDMA/bnxt_re: Fix the cleanup upon error during CQ create
In reply to Selvin XavierFix the failure path of SRQ create. Destroy the SRQ from HW and delete from the hashlist if the page allocation fails. Also, add an explicit check for NULL before calling free_page.
--- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/infiniband/hw/bnxt_re/ib_verbs.c +10 -3
@@ -3568,14 +3568,21 @@ int bnxt_re_create_user_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *att resp.phase = cq->qplib_cq.period; rc =ib_respond_udata (udata, resp);if (rc) - goto free_mem; + goto free_page;return 0 ; -free_mem: -free_page ((unsigned long )cq->uctx_cq_page); +free_page: +if (cq->uctx_cq_page) +free_page ((unsigned long )cq->uctx_cq_page); + destroy_cq:bnxt_qplib_destroy_cq (&rdev->qplib_res, &cq->qplib_cq); +if (cctx->modes.toggle_bits &BNXT_QPLIB_CQ_TOGGLE_BIT ) { +mutex_lock (&rdev->cq_hash_lock); +hash_del (&cq->hash_entry); +mutex_unlock (&rdev->cq_hash_lock); + } free_umem:ib_umem_release (cq->umem);return rc;
Signature · 1 line
2.39.3
Selvin Xavier
maintainerPATCH 11/11 RDMA/bnxt_re: Fail DBR related page allocation UAPIs if the feature is disabled
In reply to Selvin XavierNo need to support the DBR related page allocations if the pacing feature is disabled. Fail the request if pacing is disabled.
--- drivers/infiniband/hw/bnxt_re/uapi.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/infiniband/hw/bnxt_re/uapi.c +4 -0
@@ -119,12 +119,16 @@ static int UVERBS_HANDLER(BNXT_RE_METHOD_ALLOC_PAGE)(struct uverbs_attr_bundle *break ;case BNXT_RE_ALLOC_DBR_BAR_PAGE : +if (!rdev->pacing.dbr_pacing) +return -EOPNOTSUPP ; length =PAGE_SIZE ; addr = (u64 )rdev->pacing.dbr_bar_addr; mmap_flag =BNXT_RE_MMAP_DBR_BAR ;break ;case BNXT_RE_ALLOC_DBR_PAGE : +if (!rdev->pacing.dbr_pacing) +return -EOPNOTSUPP ; length =PAGE_SIZE ; addr = (u64 )rdev->pacing.dbr_page; mmap_flag =BNXT_RE_MMAP_DBR_PAGE ;
Signature · 1 line
2.39.3