Commit ae7d7dfc authored by Feng Fang's avatar Feng Fang Committed by Chengchang Tang
Browse files

RDMA/hns: Fix different dgids mapping to the same dip_idx

driver inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IAL7SX



----------------------------------------------------------------------

The mapping between dgid and dip_idx should be one-to-one. When two QPs
use the same dgid, the first QP is repeatedly created and deleted,
and different dgids are used, the problem that different dgids correspond
to the same dip_idx occurs.

This patch creates qpn_bitmap and dip_idx_map to record qp_num and
dip_idx. The bit corresponding to qpn_bitmap is set to 1 only when
qp_num is different from the used dip_idx. When dip_idx is no longer
used, the bit corresponding to dip_idx_map is cleared, and the bit
corresponding to qpn_bitmap is set to 1. When dip_idx needs to be
allocated, the index whose first bit is 1 is found from qpn_bitmap.
The bit corresponding to dip_idx_map is set to 1, and the bit
corresponding to qpn_bitmap is cleared.

Fixes: 2493138e ("RDMA/hns: Bugfix for incorrect association between dip_idx and dgid")
Fixes: f91696f2 ("RDMA/hns: Support congestion control type selection according to the FW")
Signed-off-by: default avatarFeng Fang <fangfeng4@huawei.com>
Signed-off-by: default avatarXinghai Cen <cenxinghai@h-partners.com>
parent 62cce932
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -607,9 +607,8 @@ struct hns_roce_bank {
};

struct hns_roce_idx_table {
	u32 *spare_idx;
	u32 head;
	u32 tail;
	unsigned long *qpn_bitmap;
	unsigned long *dip_idx_bitmap;
};

struct hns_roce_qp_table {
@@ -770,6 +769,7 @@ struct hns_roce_qp {
	u8			priority;
	bool			delayed_destroy_flag;
	struct hns_roce_mtr_node *mtr_node;
	struct hns_roce_dip *dip;
};

struct hns_roce_ib_iboe {
+51 −7
Original line number Diff line number Diff line
@@ -5308,21 +5308,24 @@ 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);
	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;
	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);
	struct hns_roce_dip *hr_dip;
	unsigned long flags;
	int ret = 0;
	u32 idx;

	spin_lock_irqsave(&hr_dev->dip_list_lock, flags);

	spare_idx[*tail] = ibqp->qp_num;
	*tail = (*tail == hr_dev->caps.num_qps - 1) ? 0 : (*tail + 1);
	if (!test_bit(ibqp->qp_num, dip_idx_bitmap))
		set_bit(ibqp->qp_num, qpn_bitmap);

	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;
		}
	}
@@ -5336,9 +5339,21 @@ 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 = spare_idx[*head];
	*head = (*head == hr_dev->caps.num_qps - 1) ? 0 : (*head + 1);
	hr_dip->dip_idx = *dip_idx;
	hr_dip->qp_cnt++;
	hr_qp->dip = hr_dip;
	list_add_tail(&hr_dip->node, &hr_dev->dip_list);

out:
@@ -6278,12 +6293,41 @@ 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);
	struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
	int ret;

	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,
+1 −0
Original line number Diff line number Diff line
@@ -1451,6 +1451,7 @@ 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 */
};

+12 −5
Original line number Diff line number Diff line
@@ -1760,11 +1760,18 @@ int hns_roce_init_qp_table(struct hns_roce_dev *hr_dev)
	unsigned int reserved_from_bot;
	unsigned int i;

	qp_table->idx_table.spare_idx = kcalloc(hr_dev->caps.num_qps,
					sizeof(u32), GFP_KERNEL);
	if (!qp_table->idx_table.spare_idx)
	qp_table->idx_table.qpn_bitmap = bitmap_zalloc(hr_dev->caps.num_qps,
						       GFP_KERNEL);
	if (!qp_table->idx_table.qpn_bitmap)
		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);
@@ -1793,6 +1800,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);
	mutex_destroy(&hr_dev->qp_table.scc_mutex);
	kfree(hr_dev->qp_table.idx_table.spare_idx);
	bitmap_free(hr_dev->qp_table.idx_table.qpn_bitmap);
	bitmap_free(hr_dev->qp_table.idx_table.dip_idx_bitmap);
}