From: Xinghai Cen cenxinghai@h-partners.com
driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IBIXIN CVE: NA
----------------------------------------------------------------------
This reverts commit ae7d7dfce702c70b20bacda46315193709cd1771.
Fixes: ae7d7dfce702 ("RDMA/hns: Fix different dgids mapping to the same dip_idx") Signed-off-by: Xinghai Cen cenxinghai@h-partners.com --- drivers/infiniband/hw/hns/hns_roce_device.h | 6 +-- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 58 +++------------------ drivers/infiniband/hw/hns/hns_roce_hw_v2.h | 1 - drivers/infiniband/hw/hns/hns_roce_qp.c | 17 ++---- 4 files changed, 15 insertions(+), 67 deletions(-)
diff --git a/drivers/infiniband/hw/hns/hns_roce_device.h b/drivers/infiniband/hw/hns/hns_roce_device.h index f12e56969fd3..b56cdb9d1d85 100644 --- a/drivers/infiniband/hw/hns/hns_roce_device.h +++ b/drivers/infiniband/hw/hns/hns_roce_device.h @@ -613,8 +613,9 @@ struct hns_roce_bank { };
struct hns_roce_idx_table { - unsigned long *qpn_bitmap; - unsigned long *dip_idx_bitmap; + u32 *spare_idx; + u32 head; + u32 tail; };
struct hns_roce_qp_table { @@ -777,7 +778,6 @@ struct hns_roce_qp { u8 priority; bool delayed_destroy_flag; struct hns_roce_mtr_node *mtr_node; - struct hns_roce_dip *dip; spinlock_t flush_lock; };
diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c index 27f14fc9a34a..fd600711d9df 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c @@ -5313,24 +5313,21 @@ static int get_dip_ctx_idx(struct ib_qp *ibqp, const struct ib_qp_attr *attr, { const struct ib_global_route *grh = rdma_ah_read_grh(&attr->ah_attr); struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device); - unsigned long *dip_idx_bitmap = hr_dev->qp_table.idx_table.dip_idx_bitmap; - unsigned long *qpn_bitmap = hr_dev->qp_table.idx_table.qpn_bitmap; - struct hns_roce_qp *hr_qp = to_hr_qp(ibqp); + u32 *spare_idx = hr_dev->qp_table.idx_table.spare_idx; + u32 *head = &hr_dev->qp_table.idx_table.head; + u32 *tail = &hr_dev->qp_table.idx_table.tail; struct hns_roce_dip *hr_dip; unsigned long flags; int ret = 0; - u32 idx;
spin_lock_irqsave(&hr_dev->dip_list_lock, flags);
- if (!test_bit(ibqp->qp_num, dip_idx_bitmap)) - set_bit(ibqp->qp_num, qpn_bitmap); + spare_idx[*tail] = ibqp->qp_num; + *tail = (*tail == hr_dev->caps.num_qps - 1) ? 0 : (*tail + 1);
list_for_each_entry(hr_dip, &hr_dev->dip_list, node) { if (!memcmp(grh->dgid.raw, hr_dip->dgid, GID_LEN_V2)) { *dip_idx = hr_dip->dip_idx; - hr_dip->qp_cnt++; - hr_qp->dip = hr_dip; goto out; } } @@ -5344,21 +5341,9 @@ static int get_dip_ctx_idx(struct ib_qp *ibqp, const struct ib_qp_attr *attr, goto out; }
- idx = find_first_bit(qpn_bitmap, hr_dev->caps.num_qps); - if (idx < hr_dev->caps.num_qps) { - *dip_idx = idx; - clear_bit(idx, qpn_bitmap); - set_bit(idx, dip_idx_bitmap); - } else { - ret = -ENOENT; - kfree(hr_dip); - goto out; - } - memcpy(hr_dip->dgid, grh->dgid.raw, sizeof(grh->dgid.raw)); - hr_dip->dip_idx = *dip_idx; - hr_dip->qp_cnt++; - hr_qp->dip = hr_dip; + hr_dip->dip_idx = *dip_idx = spare_idx[*head]; + *head = (*head == hr_dev->caps.num_qps - 1) ? 0 : (*head + 1); list_add_tail(&hr_dip->node, &hr_dev->dip_list);
out: @@ -6300,32 +6285,6 @@ int hns_roce_v2_destroy_qp_common(struct hns_roce_dev *hr_dev, return ret; }
-static void put_dip_ctx_idx(struct hns_roce_dev *hr_dev, - struct hns_roce_qp *hr_qp) -{ - unsigned long *dip_idx_bitmap = hr_dev->qp_table.idx_table.dip_idx_bitmap; - unsigned long *qpn_bitmap = hr_dev->qp_table.idx_table.qpn_bitmap; - struct hns_roce_dip *hr_dip = hr_qp->dip; - unsigned long flags; - - spin_lock_irqsave(&hr_dev->dip_list_lock, flags); - - if (hr_dip) { - hr_dip->qp_cnt--; - if (!hr_dip->qp_cnt) { - clear_bit(hr_dip->dip_idx, dip_idx_bitmap); - set_bit(hr_dip->dip_idx, qpn_bitmap); - - list_del(&hr_dip->node); - } else { - hr_dip = NULL; - } - } - - spin_unlock_irqrestore(&hr_dev->dip_list_lock, flags); - kfree(hr_dip); -} - int hns_roce_v2_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata) { struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device); @@ -6339,9 +6298,6 @@ int hns_roce_v2_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata) spin_unlock_irqrestore(&hr_qp->flush_lock, flags); flush_work(&hr_qp->flush_work.work);
- if (hr_qp->congest_type == HNS_ROCE_CONGEST_TYPE_DIP) - put_dip_ctx_idx(hr_dev, hr_qp); - ret = hns_roce_v2_destroy_qp_common(hr_dev, hr_qp, udata); if (ret) ibdev_err_ratelimited(&hr_dev->ib_dev, diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.h b/drivers/infiniband/hw/hns/hns_roce_hw_v2.h index 41f868d4b3f1..570b972354b6 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.h +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.h @@ -1457,7 +1457,6 @@ struct hns_roce_v2_priv { struct hns_roce_dip { u8 dgid[GID_LEN_V2]; u32 dip_idx; - u32 qp_cnt; struct list_head node; /* all dips are on a list */ };
diff --git a/drivers/infiniband/hw/hns/hns_roce_qp.c b/drivers/infiniband/hw/hns/hns_roce_qp.c index a3eb05e8471e..06e46d82c828 100644 --- a/drivers/infiniband/hw/hns/hns_roce_qp.c +++ b/drivers/infiniband/hw/hns/hns_roce_qp.c @@ -1837,18 +1837,11 @@ int hns_roce_init_qp_table(struct hns_roce_dev *hr_dev) unsigned int reserved_from_bot; unsigned int i;
- qp_table->idx_table.qpn_bitmap = bitmap_zalloc(hr_dev->caps.num_qps, - GFP_KERNEL); - if (!qp_table->idx_table.qpn_bitmap) + qp_table->idx_table.spare_idx = kcalloc(hr_dev->caps.num_qps, + sizeof(u32), GFP_KERNEL); + if (!qp_table->idx_table.spare_idx) return -ENOMEM;
- qp_table->idx_table.dip_idx_bitmap = bitmap_zalloc(hr_dev->caps.num_qps, - GFP_KERNEL); - if (!qp_table->idx_table.dip_idx_bitmap) { - bitmap_free(qp_table->idx_table.qpn_bitmap); - return -ENOMEM; - } - mutex_init(&qp_table->scc_mutex); mutex_init(&qp_table->bank_mutex); xa_init(&hr_dev->qp_table_xa); @@ -1877,6 +1870,6 @@ void hns_roce_cleanup_qp_table(struct hns_roce_dev *hr_dev) for (i = 0; i < HNS_ROCE_QP_BANK_NUM; i++) ida_destroy(&hr_dev->qp_table.bank[i].ida); mutex_destroy(&hr_dev->qp_table.bank_mutex); - bitmap_free(hr_dev->qp_table.idx_table.qpn_bitmap); - bitmap_free(hr_dev->qp_table.idx_table.dip_idx_bitmap); + mutex_destroy(&hr_dev->qp_table.scc_mutex); + kfree(hr_dev->qp_table.idx_table.spare_idx); }