Skip to content

Commit eb653ed

Browse files
Junxian Huangjgunthorpe
authored andcommitted
RDMA/hns: Bugfix for incorrect association between dip_idx and dgid
dip_idx and dgid should be a one-to-one mapping relationship, but when qp_num loops back to the start number, it may happen that two different dgid are assiociated to the same dip_idx incorrectly. One solution is to store the qp_num that is not assigned to dip_idx in an array. When a dip_idx needs to be allocated to a new dgid, an spare qp_num is extracted and assigned to dip_idx. Fixes: f91696f ("RDMA/hns: Support congestion control type selection according to the FW") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Junxian Huang <[email protected]> Signed-off-by: Yangyang Li <[email protected]> Signed-off-by: Wenpeng Liang <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 074f315 commit eb653ed

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

drivers/infiniband/hw/hns/hns_roce_device.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,12 @@ struct hns_roce_bank {
496496
u32 next; /* Next ID to allocate. */
497497
};
498498

499+
struct hns_roce_idx_table {
500+
u32 *spare_idx;
501+
u32 head;
502+
u32 tail;
503+
};
504+
499505
struct hns_roce_qp_table {
500506
struct hns_roce_hem_table qp_table;
501507
struct hns_roce_hem_table irrl_table;
@@ -504,6 +510,7 @@ struct hns_roce_qp_table {
504510
struct mutex scc_mutex;
505511
struct hns_roce_bank bank[HNS_ROCE_QP_BANK_NUM];
506512
struct mutex bank_mutex;
513+
struct hns_roce_idx_table idx_table;
507514
};
508515

509516
struct hns_roce_cq_table {
@@ -1144,7 +1151,7 @@ int hns_roce_mtr_map(struct hns_roce_dev *hr_dev, struct hns_roce_mtr *mtr,
11441151
void hns_roce_init_pd_table(struct hns_roce_dev *hr_dev);
11451152
void hns_roce_init_mr_table(struct hns_roce_dev *hr_dev);
11461153
void hns_roce_init_cq_table(struct hns_roce_dev *hr_dev);
1147-
void hns_roce_init_qp_table(struct hns_roce_dev *hr_dev);
1154+
int hns_roce_init_qp_table(struct hns_roce_dev *hr_dev);
11481155
void hns_roce_init_srq_table(struct hns_roce_dev *hr_dev);
11491156
void hns_roce_init_xrcd_table(struct hns_roce_dev *hr_dev);
11501157

drivers/infiniband/hw/hns/hns_roce_hw_v2.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4501,12 +4501,18 @@ static int get_dip_ctx_idx(struct ib_qp *ibqp, const struct ib_qp_attr *attr,
45014501
{
45024502
const struct ib_global_route *grh = rdma_ah_read_grh(&attr->ah_attr);
45034503
struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device);
4504+
u32 *spare_idx = hr_dev->qp_table.idx_table.spare_idx;
4505+
u32 *head = &hr_dev->qp_table.idx_table.head;
4506+
u32 *tail = &hr_dev->qp_table.idx_table.tail;
45044507
struct hns_roce_dip *hr_dip;
45054508
unsigned long flags;
45064509
int ret = 0;
45074510

45084511
spin_lock_irqsave(&hr_dev->dip_list_lock, flags);
45094512

4513+
spare_idx[*tail] = ibqp->qp_num;
4514+
*tail = (*tail == hr_dev->caps.num_qps - 1) ? 0 : (*tail + 1);
4515+
45104516
list_for_each_entry(hr_dip, &hr_dev->dip_list, node) {
45114517
if (!memcmp(grh->dgid.raw, hr_dip->dgid, 16)) {
45124518
*dip_idx = hr_dip->dip_idx;
@@ -4524,7 +4530,8 @@ static int get_dip_ctx_idx(struct ib_qp *ibqp, const struct ib_qp_attr *attr,
45244530
}
45254531

45264532
memcpy(hr_dip->dgid, grh->dgid.raw, sizeof(grh->dgid.raw));
4527-
hr_dip->dip_idx = *dip_idx = ibqp->qp_num;
4533+
hr_dip->dip_idx = *dip_idx = spare_idx[*head];
4534+
*head = (*head == hr_dev->caps.num_qps - 1) ? 0 : (*head + 1);
45284535
list_add_tail(&hr_dip->node, &hr_dev->dip_list);
45294536

45304537
out:

drivers/infiniband/hw/hns/hns_roce_main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,12 @@ static int hns_roce_setup_hca(struct hns_roce_dev *hr_dev)
746746
goto err_uar_table_free;
747747
}
748748

749+
ret = hns_roce_init_qp_table(hr_dev);
750+
if (ret) {
751+
dev_err(dev, "Failed to init qp_table.\n");
752+
goto err_uar_table_free;
753+
}
754+
749755
hns_roce_init_pd_table(hr_dev);
750756

751757
if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_XRC)
@@ -755,8 +761,6 @@ static int hns_roce_setup_hca(struct hns_roce_dev *hr_dev)
755761

756762
hns_roce_init_cq_table(hr_dev);
757763

758-
hns_roce_init_qp_table(hr_dev);
759-
760764
if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_SRQ) {
761765
hns_roce_init_srq_table(hr_dev);
762766
}

drivers/infiniband/hw/hns/hns_roce_qp.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1411,12 +1411,17 @@ bool hns_roce_wq_overflow(struct hns_roce_wq *hr_wq, u32 nreq,
14111411
return cur + nreq >= hr_wq->wqe_cnt;
14121412
}
14131413

1414-
void hns_roce_init_qp_table(struct hns_roce_dev *hr_dev)
1414+
int hns_roce_init_qp_table(struct hns_roce_dev *hr_dev)
14151415
{
14161416
struct hns_roce_qp_table *qp_table = &hr_dev->qp_table;
14171417
unsigned int reserved_from_bot;
14181418
unsigned int i;
14191419

1420+
qp_table->idx_table.spare_idx = kcalloc(hr_dev->caps.num_qps,
1421+
sizeof(u32), GFP_KERNEL);
1422+
if (!qp_table->idx_table.spare_idx)
1423+
return -ENOMEM;
1424+
14201425
mutex_init(&qp_table->scc_mutex);
14211426
mutex_init(&qp_table->bank_mutex);
14221427
xa_init(&hr_dev->qp_table_xa);
@@ -1434,6 +1439,8 @@ void hns_roce_init_qp_table(struct hns_roce_dev *hr_dev)
14341439
HNS_ROCE_QP_BANK_NUM - 1;
14351440
hr_dev->qp_table.bank[i].next = hr_dev->qp_table.bank[i].min;
14361441
}
1442+
1443+
return 0;
14371444
}
14381445

14391446
void hns_roce_cleanup_qp_table(struct hns_roce_dev *hr_dev)
@@ -1442,4 +1449,5 @@ void hns_roce_cleanup_qp_table(struct hns_roce_dev *hr_dev)
14421449

14431450
for (i = 0; i < HNS_ROCE_QP_BANK_NUM; i++)
14441451
ida_destroy(&hr_dev->qp_table.bank[i].ida);
1452+
kfree(hr_dev->qp_table.idx_table.spare_idx);
14451453
}

0 commit comments

Comments
 (0)