Skip to content

Commit 213d2b9

Browse files
selvintxavierrleon
authored andcommitted
RDMA/bnxt_re: Protect the PD table bitmap
Syncrhonization is required to avoid simultaneous allocation of the PD. Add a new mutex lock to handle allocation from the PD table. Signed-off-by: Kashyap Desai <kashyap.desai@broadcom.com> Signed-off-by: Selvin Xavier <selvin.xavier@broadcom.com> Link: https://lore.kernel.org/r/1692032419-21680-2-git-send-email-selvin.xavier@broadcom.com Signed-off-by: Leon Romanovsky <leon@kernel.org>
1 parent 811e0ce commit 213d2b9

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

drivers/infiniband/hw/bnxt_re/ib_verbs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ int bnxt_re_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata)
619619
int rc = 0;
620620

621621
pd->rdev = rdev;
622-
if (bnxt_qplib_alloc_pd(&rdev->qplib_res.pd_tbl, &pd->qplib_pd)) {
622+
if (bnxt_qplib_alloc_pd(&rdev->qplib_res, &pd->qplib_pd)) {
623623
ibdev_err(&rdev->ibdev, "Failed to allocate HW PD");
624624
rc = -ENOMEM;
625625
goto fail;

drivers/infiniband/hw/bnxt_re/qplib_res.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -642,31 +642,44 @@ static void bnxt_qplib_init_sgid_tbl(struct bnxt_qplib_sgid_tbl *sgid_tbl,
642642
}
643643

644644
/* PDs */
645-
int bnxt_qplib_alloc_pd(struct bnxt_qplib_pd_tbl *pdt, struct bnxt_qplib_pd *pd)
645+
int bnxt_qplib_alloc_pd(struct bnxt_qplib_res *res, struct bnxt_qplib_pd *pd)
646646
{
647+
struct bnxt_qplib_pd_tbl *pdt = &res->pd_tbl;
647648
u32 bit_num;
649+
int rc = 0;
648650

651+
mutex_lock(&res->pd_tbl_lock);
649652
bit_num = find_first_bit(pdt->tbl, pdt->max);
650-
if (bit_num == pdt->max)
651-
return -ENOMEM;
653+
if (bit_num == pdt->max) {
654+
rc = -ENOMEM;
655+
goto exit;
656+
}
652657

653658
/* Found unused PD */
654659
clear_bit(bit_num, pdt->tbl);
655660
pd->id = bit_num;
656-
return 0;
661+
exit:
662+
mutex_unlock(&res->pd_tbl_lock);
663+
return rc;
657664
}
658665

659666
int bnxt_qplib_dealloc_pd(struct bnxt_qplib_res *res,
660667
struct bnxt_qplib_pd_tbl *pdt,
661668
struct bnxt_qplib_pd *pd)
662669
{
670+
int rc = 0;
671+
672+
mutex_lock(&res->pd_tbl_lock);
663673
if (test_and_set_bit(pd->id, pdt->tbl)) {
664674
dev_warn(&res->pdev->dev, "Freeing an unused PD? pdn = %d\n",
665675
pd->id);
666-
return -EINVAL;
676+
rc = -EINVAL;
677+
goto exit;
667678
}
668679
pd->id = 0;
669-
return 0;
680+
exit:
681+
mutex_unlock(&res->pd_tbl_lock);
682+
return rc;
670683
}
671684

672685
static void bnxt_qplib_free_pd_tbl(struct bnxt_qplib_pd_tbl *pdt)
@@ -691,6 +704,7 @@ static int bnxt_qplib_alloc_pd_tbl(struct bnxt_qplib_res *res,
691704

692705
pdt->max = max;
693706
memset((u8 *)pdt->tbl, 0xFF, bytes);
707+
mutex_init(&res->pd_tbl_lock);
694708

695709
return 0;
696710
}

drivers/infiniband/hw/bnxt_re/qplib_res.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ struct bnxt_qplib_res {
277277
struct net_device *netdev;
278278
struct bnxt_qplib_rcfw *rcfw;
279279
struct bnxt_qplib_pd_tbl pd_tbl;
280+
/* To protect the pd table bit map */
281+
struct mutex pd_tbl_lock;
280282
struct bnxt_qplib_sgid_tbl sgid_tbl;
281283
struct bnxt_qplib_dpi_tbl dpi_tbl;
282284
/* To protect the dpi table bit map */
@@ -368,7 +370,7 @@ void bnxt_qplib_free_hwq(struct bnxt_qplib_res *res,
368370
struct bnxt_qplib_hwq *hwq);
369371
int bnxt_qplib_alloc_init_hwq(struct bnxt_qplib_hwq *hwq,
370372
struct bnxt_qplib_hwq_attr *hwq_attr);
371-
int bnxt_qplib_alloc_pd(struct bnxt_qplib_pd_tbl *pd_tbl,
373+
int bnxt_qplib_alloc_pd(struct bnxt_qplib_res *res,
372374
struct bnxt_qplib_pd *pd);
373375
int bnxt_qplib_dealloc_pd(struct bnxt_qplib_res *res,
374376
struct bnxt_qplib_pd_tbl *pd_tbl,

0 commit comments

Comments
 (0)