Unverified Commit 534d8df2 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!14948 Mainline patch to olk-5.10 v3

Merge Pull Request from: @cxh269 
 
1. RDMA/hns: Fix different dgids mapping to the same dip_idx
2. Revert "RDMA/hns: Fix different dgids mapping to the same dip_idx"
3. RDMA/hns: Fix flush cqe error when racing with destroy qp
4. Revert "RDMA/hns: Fix flush cqe error when racing with destroy qp"

https://gitee.com/openeuler/kernel/issues/IBIXIN 
 
Link:https://gitee.com/openeuler/kernel/pulls/14948

 

Reviewed-by: default avatarChengchang Tang <tangchengchang@huawei.com>
Reviewed-by: default avatarLi Nan <linan122@huawei.com>
Signed-off-by: default avatarLi Nan <linan122@huawei.com>
parents 221f46c7 76734ef1
Loading
Loading
Loading
Loading
+2 −9
Original line number Diff line number Diff line
@@ -612,11 +612,6 @@ struct hns_roce_bank {
	u32 next; /* Next ID to allocate. */
};

struct hns_roce_idx_table {
	unsigned long *qpn_bitmap;
	unsigned long *dip_idx_bitmap;
};

struct hns_roce_qp_table {
	struct hns_roce_hem_table	qp_table;
	struct hns_roce_hem_table	irrl_table;
@@ -625,7 +620,7 @@ struct hns_roce_qp_table {
	struct mutex			scc_mutex;
	struct hns_roce_bank bank[HNS_ROCE_QP_BANK_NUM];
	struct mutex bank_mutex;
	struct hns_roce_idx_table	idx_table;
	struct xarray			dip_xa;
};

struct hns_roce_cq_table {
@@ -777,8 +772,8 @@ 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;
	struct hns_roce_dip *dip;
};

struct hns_roce_ib_iboe {
@@ -1176,8 +1171,6 @@ struct hns_roce_dev {
	enum hns_roce_device_state state;
	struct list_head	qp_list; /* list of all qps on this dev */
	spinlock_t		qp_list_lock; /* protect qp_list */
	struct list_head	dip_list; /* list of all dest ips on this dev */
	spinlock_t		dip_list_lock; /* protect dip_list */

	struct list_head        pgdir_list;
	struct mutex            pgdir_mutex;
+55 −60
Original line number Diff line number Diff line
@@ -2903,20 +2903,19 @@ static void hns_roce_free_link_table(struct hns_roce_dev *hr_dev)
	free_link_table_buf(hr_dev, &priv->ext_llm);
}

static void free_dip_list(struct hns_roce_dev *hr_dev)
static void free_dip_entry(struct hns_roce_dev *hr_dev)
{
	struct hns_roce_dip *hr_dip;
	struct hns_roce_dip *tmp;
	unsigned long flags;
	unsigned long idx;

	spin_lock_irqsave(&hr_dev->dip_list_lock, flags);
	xa_lock(&hr_dev->qp_table.dip_xa);

	list_for_each_entry_safe(hr_dip, tmp, &hr_dev->dip_list, node) {
		list_del(&hr_dip->node);
	xa_for_each(&hr_dev->qp_table.dip_xa, idx, hr_dip) {
		__xa_erase(&hr_dev->qp_table.dip_xa, hr_dip->dip_idx);
		kfree(hr_dip);
	}

	spin_unlock_irqrestore(&hr_dev->dip_list_lock, flags);
	xa_unlock(&hr_dev->qp_table.dip_xa);
}

static int hns_roce_v2_get_reset_page(struct hns_roce_dev *hr_dev)
@@ -3377,7 +3376,7 @@ static void hns_roce_v2_exit(struct hns_roce_dev *hr_dev)
	hns_roce_v2_put_reset_page(hr_dev);

	if (hr_dev->pci_dev->revision == PCI_REVISION_ID_HIP09)
		free_dip_list(hr_dev);
		free_dip_entry(hr_dev);
}

static inline void mbox_desc_init(struct hns_roce_post_mbox *mb,
@@ -5308,26 +5307,46 @@ static int modify_qp_rtr_to_rts(struct ib_qp *ibqp, int attr_mask,
	return 0;
}

static int alloc_dip_entry(struct xarray *dip_xa, u32 qpn)
{
	struct hns_roce_dip *hr_dip;
	int ret;

	hr_dip = xa_load(dip_xa, qpn);
	if (hr_dip)
		return 0;

	hr_dip = kzalloc(sizeof(*hr_dip), GFP_KERNEL);
	if (!hr_dip)
		return -ENOMEM;

	ret = xa_err(xa_store(dip_xa, qpn, hr_dip, GFP_KERNEL));
	if (ret)
		kfree(hr_dip);

	return ret;
}

static int get_dip_ctx_idx(struct ib_qp *ibqp, const struct ib_qp_attr *attr,
			   u32 *dip_idx)
{
	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 xarray *dip_xa = &hr_dev->qp_table.dip_xa;
	struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
	struct hns_roce_dip *hr_dip;
	unsigned long flags;
	unsigned long idx;
	int ret = 0;
	u32 idx;

	spin_lock_irqsave(&hr_dev->dip_list_lock, flags);
	ret = alloc_dip_entry(dip_xa, ibqp->qp_num);
	if (ret)
		return ret;

	if (!test_bit(ibqp->qp_num, dip_idx_bitmap))
		set_bit(ibqp->qp_num, qpn_bitmap);
	xa_lock(dip_xa);

	list_for_each_entry(hr_dip, &hr_dev->dip_list, node) {
		if (!memcmp(grh->dgid.raw, hr_dip->dgid, GID_LEN_V2)) {
	xa_for_each(dip_xa, idx, hr_dip) {
		if (hr_dip->qp_cnt &&
		    !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;
@@ -5338,31 +5357,24 @@ static int get_dip_ctx_idx(struct ib_qp *ibqp, const struct ib_qp_attr *attr,
	/* If no dgid is found, a new dip and a mapping between dgid and
	 * dip_idx will be created.
	 */
	hr_dip = kzalloc(sizeof(*hr_dip), GFP_ATOMIC);
	if (!hr_dip) {
		ret = -ENOMEM;
		goto out;
	}
	xa_for_each(dip_xa, idx, hr_dip) {
		if (hr_dip->qp_cnt)
			continue;

	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->dip_idx = idx;
		hr_dip->qp_cnt++;
		hr_qp->dip = hr_dip;
	list_add_tail(&hr_dip->node, &hr_dev->dip_list);
		break;
	}

	/* This should never happen. */
	if (WARN_ON_ONCE(!hr_qp->dip))
		ret = -ENOSPC;

out:
	spin_unlock_irqrestore(&hr_dev->dip_list_lock, flags);
	xa_unlock(dip_xa);
	return ret;
}

@@ -6303,27 +6315,15 @@ int hns_roce_v2_destroy_qp_common(struct hns_roce_dev *hr_dev,
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);
	xa_lock(&hr_dev->qp_table.dip_xa);

	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;
		}
	}
	if (!hr_dip->qp_cnt)
		memset(hr_dip->dgid, 0, GID_LEN_V2);

	spin_unlock_irqrestore(&hr_dev->dip_list_lock, flags);
	kfree(hr_dip);
	xa_unlock(&hr_dev->qp_table.dip_xa);
}

int hns_roce_v2_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)
@@ -6332,6 +6332,7 @@ int hns_roce_v2_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)
	struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
	unsigned long flags;
	int ret;

	/* Make sure flush_cqe() is completed */
	spin_lock_irqsave(&hr_qp->flush_lock, flags);
	set_bit(HNS_ROCE_STOP_FLUSH_FLAG, &hr_qp->flush_flag);
@@ -6341,12 +6342,6 @@ int hns_roce_v2_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)
	if (hr_qp->congest_type == HNS_ROCE_CONGEST_TYPE_DIP)
		put_dip_ctx_idx(hr_dev, hr_qp);

	/* Make sure flush_cqe() is completed */
	spin_lock_irqsave(&hr_qp->flush_lock, flags);
	set_bit(HNS_ROCE_STOP_FLUSH_FLAG, &hr_qp->flush_flag);
	spin_unlock_irqrestore(&hr_qp->flush_lock, flags);
	flush_work(&hr_qp->flush_work.work);

	ret = hns_roce_v2_destroy_qp_common(hr_dev, hr_qp, udata);
	if (ret)
		ibdev_err_ratelimited(&hr_dev->ib_dev,
+0 −1
Original line number Diff line number Diff line
@@ -1458,7 +1458,6 @@ 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 */
};

struct fmea_ram_ecc {
+0 −2
Original line number Diff line number Diff line
@@ -1319,8 +1319,6 @@ static int hns_roce_setup_hca(struct hns_roce_dev *hr_dev)

	INIT_LIST_HEAD(&hr_dev->qp_list);
	spin_lock_init(&hr_dev->qp_list_lock);
	INIT_LIST_HEAD(&hr_dev->dip_list);
	spin_lock_init(&hr_dev->dip_list_lock);

	INIT_LIST_HEAD(&hr_dev->uctx_list);
	mutex_init(&hr_dev->uctx_list_mutex);
+3 −14
Original line number Diff line number Diff line
@@ -1837,21 +1837,10 @@ 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)
		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);
	xa_init(&qp_table->dip_xa);

	reserved_from_bot = hr_dev->caps.reserved_qps;

@@ -1876,7 +1865,7 @@ 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);
	xa_destroy(&hr_dev->qp_table.dip_xa);
	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);
}