Unverified Commit 411657bf authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!3019 RDMA/hns: Some cleanups for openEuler

Merge Pull Request from: @stinft 
 
This group of patches fix the issues found in the code review.

Chengchang Tang (11):
  RDMA/hns: Use complete parentheses in macros
  RDMA/hns: Fix sleeping in setup_dca_buf_to_hw()
  RDMA/hns: Remove unnecessary checks for NULL in mtr_alloc_bufs()
  RDMA/hns: Improve the readability of free mr exception branch
  RDMA/hns: Fix incorrect print type in bond
  RDMA/hns: Fix a meaningless loop in free_buffer_pages_proc()
  RDMA/hns: Delete redundant assignment values
  RDMA/hns: Remove redundant address operations in print DCA logs
  RDMA/hns: Fix memory leak in free_mr_exit() and free_mr_init()
  RDMA/hns: Fix unhandled error code in dca uverbs
  RDMA/hns: Improve readabilties for dca uverbs
Junxian Huang (1):
  RDMA/hns: Fix several memory issues in roce bonding

bugzilla: https://gitee.com/openeuler/kernel/issues/I6GT7F 
 
Link:https://gitee.com/openeuler/kernel/pulls/3019

 

Reviewed-by: default avatarChengchang Tang <tangchengchang@huawei.com>
Signed-off-by: default avatarJialin Zhang <zhangjialin11@huawei.com>
parents 16063581 bbf86797
Loading
Loading
Loading
Loading
+11 −6
Original line number Original line Diff line number Diff line
@@ -284,7 +284,8 @@ static void hns_roce_clear_bond(struct hns_roce_bond_group *bond_grp)
out:
out:
	ret = hns_roce_cleanup_bond(bond_grp);
	ret = hns_roce_cleanup_bond(bond_grp);
	if (!ret)
	if (!ret)
		ibdev_info(&hr_dev->ib_dev, "RoCE clear bond finished!\n");
		ibdev_info(&bond_grp->main_hr_dev->ib_dev,
			   "RoCE clear bond finished!\n");
}
}


static void hns_roce_slave_changestate(struct hns_roce_bond_group *bond_grp)
static void hns_roce_slave_changestate(struct hns_roce_bond_group *bond_grp)
@@ -558,6 +559,12 @@ static struct hns_roce_die_info *alloc_die_info(int bus_num)
	return die_info;
	return die_info;
}
}


static void dealloc_die_info(struct hns_roce_die_info *die_info, u8 bus_num)
{
	xa_erase(&roce_bond_xa, bus_num);
	kvfree(die_info);
}

static int alloc_bond_id(struct hns_roce_bond_group *bond_grp)
static int alloc_bond_id(struct hns_roce_bond_group *bond_grp)
{
{
	u8 bus_num = bond_grp->bus_num;
	u8 bus_num = bond_grp->bus_num;
@@ -599,10 +606,8 @@ static int remove_bond_id(int bus_num, u8 bond_id)


	die_info->bond_id_mask &= ~BOND_ID(bond_id);
	die_info->bond_id_mask &= ~BOND_ID(bond_id);
	die_info->bgrps[bond_id] = NULL;
	die_info->bgrps[bond_id] = NULL;
	if (!die_info->bond_id_mask) {
	if (!die_info->bond_id_mask)
		kfree(die_info);
		dealloc_die_info(die_info, bus_num);
		xa_erase(&roce_bond_xa, bus_num);
	}


	return 0;
	return 0;
}
}
@@ -620,7 +625,7 @@ int hns_roce_cleanup_bond(struct hns_roce_bond_group *bond_grp)
	cancel_delayed_work(&bond_grp->bond_work);
	cancel_delayed_work(&bond_grp->bond_work);
	ret = remove_bond_id(bond_grp->bus_num, bond_grp->bond_id);
	ret = remove_bond_id(bond_grp->bus_num, bond_grp->bond_id);
	if (ret)
	if (ret)
		BOND_ERR_LOG("failed to remove bond id %d, ret = %d.\n",
		BOND_ERR_LOG("failed to remove bond id %u, ret = %d.\n",
			     bond_grp->bond_id, ret);
			     bond_grp->bond_id, ret);


	completion_no_waiter = completion_done(&bond_grp->bond_work_done);
	completion_no_waiter = completion_done(&bond_grp->bond_work_done);
+24 −21
Original line number Original line Diff line number Diff line
@@ -346,7 +346,7 @@ static int setup_dca_buf_to_hw(struct hns_roce_dev *hr_dev,
	int ret;
	int ret;


	/* alloc a tmp array to store buffer's dma address */
	/* alloc a tmp array to store buffer's dma address */
	pages = kvcalloc(count, sizeof(dma_addr_t), GFP_ATOMIC);
	pages = kcalloc(count, sizeof(dma_addr_t), GFP_ATOMIC);
	if (!pages)
	if (!pages)
		return -ENOMEM;
		return -ENOMEM;


@@ -369,7 +369,7 @@ static int setup_dca_buf_to_hw(struct hns_roce_dev *hr_dev,
	ret = config_dca_qpc(hr_dev, hr_qp, pages, count);
	ret = config_dca_qpc(hr_dev, hr_qp, pages, count);
err_get_pages:
err_get_pages:
	/* drop tmp array */
	/* drop tmp array */
	kvfree(pages);
	kfree(pages);


	return ret;
	return ret;
}
}
@@ -882,7 +882,7 @@ static int free_buffer_pages_proc(struct dca_mem *mem, int index, void *param)
	}
	}


	for (; changed && i < mem->page_count; i++)
	for (; changed && i < mem->page_count; i++)
		if (dca_page_is_free(state))
		if (dca_page_is_free(&mem->states[i]))
			free_pages++;
			free_pages++;


	if (changed && free_pages == mem->page_count)
	if (changed && free_pages == mem->page_count)
@@ -1657,27 +1657,27 @@ DECLARE_UVERBS_NAMED_METHOD(
			    UVERBS_ATTR_TYPE(u32), UA_MANDATORY));
			    UVERBS_ATTR_TYPE(u32), UA_MANDATORY));


static inline struct hns_roce_qp *
static inline struct hns_roce_qp *
uverbs_attr_to_hr_qp(struct uverbs_attr_bundle *attrs)
uverbs_attr_to_hr_qp(struct uverbs_attr_bundle *attrs, u16 idx)
{
{
	struct ib_uobject *uobj =
	struct ib_uobject *uobj = uverbs_attr_get_uobject(attrs, idx);
		uverbs_attr_get_uobject(attrs, 1U << UVERBS_ID_NS_SHIFT);


	if (uobj_get_object_id(uobj) == UVERBS_OBJECT_QP)
	if (IS_ERR(uobj))
		return to_hr_qp(uobj->object);
		return ERR_CAST(uobj);


	return NULL;
	return to_hr_qp(uobj->object);
}
}


static int UVERBS_HANDLER(HNS_IB_METHOD_DCA_MEM_ATTACH)(
static int UVERBS_HANDLER(HNS_IB_METHOD_DCA_MEM_ATTACH)(
	struct uverbs_attr_bundle *attrs)
	struct uverbs_attr_bundle *attrs)
{
{
	struct hns_roce_qp *hr_qp = uverbs_attr_to_hr_qp(attrs);
	struct hns_roce_qp *hr_qp = uverbs_attr_to_hr_qp(attrs,
					HNS_IB_ATTR_DCA_MEM_ATTACH_HANDLE);
	struct hns_dca_attach_attr attr = {};
	struct hns_dca_attach_attr attr = {};
	struct hns_dca_attach_resp resp = {};
	struct hns_dca_attach_resp resp = {};
	int ret;
	int ret;


	if (!hr_qp)
	if (IS_ERR(hr_qp))
		return -EINVAL;
		return PTR_ERR(hr_qp);


	ret = uverbs_copy_from(&attr.sq_offset, attrs,
	ret = uverbs_copy_from(&attr.sq_offset, attrs,
			     HNS_IB_ATTR_DCA_MEM_ATTACH_SQ_OFFSET);
			     HNS_IB_ATTR_DCA_MEM_ATTACH_SQ_OFFSET);
@@ -1724,12 +1724,13 @@ DECLARE_UVERBS_NAMED_METHOD(
static int UVERBS_HANDLER(HNS_IB_METHOD_DCA_MEM_DETACH)(
static int UVERBS_HANDLER(HNS_IB_METHOD_DCA_MEM_DETACH)(
	struct uverbs_attr_bundle *attrs)
	struct uverbs_attr_bundle *attrs)
{
{
	struct hns_roce_qp *hr_qp = uverbs_attr_to_hr_qp(attrs);
	struct hns_roce_qp *hr_qp = uverbs_attr_to_hr_qp(attrs,
					HNS_IB_ATTR_DCA_MEM_DETACH_HANDLE);
	struct hns_dca_detach_attr attr = {};
	struct hns_dca_detach_attr attr = {};
	int ret;
	int ret;


	if (!hr_qp)
	if (IS_ERR(hr_qp))
		return -EINVAL;
		return PTR_ERR(hr_qp);


	ret = uverbs_copy_from(&attr.sq_idx, attrs,
	ret = uverbs_copy_from(&attr.sq_idx, attrs,
			       HNS_IB_ATTR_DCA_MEM_DETACH_SQ_INDEX);
			       HNS_IB_ATTR_DCA_MEM_DETACH_SQ_INDEX);
@@ -1751,19 +1752,21 @@ DECLARE_UVERBS_NAMED_METHOD(
static int UVERBS_HANDLER(HNS_IB_METHOD_DCA_MEM_QUERY)(
static int UVERBS_HANDLER(HNS_IB_METHOD_DCA_MEM_QUERY)(
	struct uverbs_attr_bundle *attrs)
	struct uverbs_attr_bundle *attrs)
{
{
	struct hns_roce_qp *hr_qp = uverbs_attr_to_hr_qp(attrs);
	struct hns_roce_qp *hr_qp = uverbs_attr_to_hr_qp(attrs,
					HNS_IB_ATTR_DCA_MEM_QUERY_HANDLE);
	struct dca_page_query_active_attr active_attr = {};
	struct dca_page_query_active_attr active_attr = {};
	struct hns_roce_dca_ctx *ctx = NULL;
	struct hns_roce_dca_ctx *ctx = NULL;
	struct hns_roce_dev *hr_dev = NULL;
	struct hns_roce_dev *hr_dev = NULL;
	u32 page_idx, page_ofs;
	u32 page_idx, page_ofs;
	int ret;
	int ret;


	if (hr_qp)
	if (IS_ERR(hr_qp))
		return PTR_ERR(hr_qp);

	hr_dev = to_hr_dev(hr_qp->ibqp.device);
	hr_dev = to_hr_dev(hr_qp->ibqp.device);
	if (hr_dev)
	ctx = hr_qp_to_dca_ctx(hr_dev, hr_qp);
	ctx = hr_qp_to_dca_ctx(hr_dev, hr_qp);
	if (!ctx)
	if (!ctx)
		return -EINVAL;
		return -ENOENT;


	ret = uverbs_copy_from(&page_idx, attrs,
	ret = uverbs_copy_from(&page_idx, attrs,
			       HNS_IB_ATTR_DCA_MEM_QUERY_PAGE_INDEX);
			       HNS_IB_ATTR_DCA_MEM_QUERY_PAGE_INDEX);
+6 −6
Original line number Original line Diff line number Diff line
@@ -61,16 +61,16 @@ enum {
	 (sizeof(struct scatterlist) + sizeof(void *)))
	 (sizeof(struct scatterlist) + sizeof(void *)))


#define check_whether_bt_num_3(type, hop_num) \
#define check_whether_bt_num_3(type, hop_num) \
	(type < HEM_TYPE_MTT && hop_num == 2)
	((type) < HEM_TYPE_MTT && (hop_num) == 2)


#define check_whether_bt_num_2(type, hop_num) \
#define check_whether_bt_num_2(type, hop_num) \
	((type < HEM_TYPE_MTT && hop_num == 1) || \
	(((type) < HEM_TYPE_MTT && (hop_num) == 1) || \
	(type >= HEM_TYPE_MTT && hop_num == 2))
	((type) >= HEM_TYPE_MTT && (hop_num) == 2))


#define check_whether_bt_num_1(type, hop_num) \
#define check_whether_bt_num_1(type, hop_num) \
	((type < HEM_TYPE_MTT && hop_num == HNS_ROCE_HOP_NUM_0) || \
	(((type) < HEM_TYPE_MTT && (hop_num) == HNS_ROCE_HOP_NUM_0) || \
	(type >= HEM_TYPE_MTT && hop_num == 1) || \
	((type) >= HEM_TYPE_MTT && (hop_num) == 1) || \
	(type >= HEM_TYPE_MTT && hop_num == HNS_ROCE_HOP_NUM_0))
	((type) >= HEM_TYPE_MTT && (hop_num) == HNS_ROCE_HOP_NUM_0))


struct hns_roce_hem_chunk {
struct hns_roce_hem_chunk {
	struct list_head	 list;
	struct list_head	 list;
+36 −18
Original line number Original line Diff line number Diff line
@@ -463,7 +463,7 @@ static int check_send_valid(struct hns_roce_dev *hr_dev,
	if (check_dca_attach_enable(hr_qp)) {
	if (check_dca_attach_enable(hr_qp)) {
		ret = dca_attach_qp_buf(hr_dev, hr_qp);
		ret = dca_attach_qp_buf(hr_dev, hr_qp);
		if (unlikely(ret)) {
		if (unlikely(ret)) {
			ibdev_err(&hr_dev->ib_dev,
			ibdev_err(ibdev,
				  "failed to attach DCA for QP-%ld send!\n",
				  "failed to attach DCA for QP-%ld send!\n",
				  hr_qp->qpn);
				  hr_qp->qpn);
			return ret;
			return ret;
@@ -2850,6 +2850,19 @@ static struct ib_pd *free_mr_init_pd(struct hns_roce_dev *hr_dev)
	return pd;
	return pd;
}
}


static void free_mr_uninit_pd(struct hns_roce_dev *hr_dev)
{
	struct hns_roce_v2_priv *priv = hr_dev->priv;
	struct hns_roce_v2_free_mr *free_mr = &priv->free_mr;

	if (!free_mr->rsv_pd)
		return;

	hns_roce_dealloc_pd(&free_mr->rsv_pd->ibpd, NULL);
	kvfree(free_mr->rsv_pd);
	free_mr->rsv_pd = NULL;
}

static struct ib_cq *free_mr_init_cq(struct hns_roce_dev *hr_dev)
static struct ib_cq *free_mr_init_cq(struct hns_roce_dev *hr_dev)
{
{
	struct hns_roce_v2_priv *priv = hr_dev->priv;
	struct hns_roce_v2_priv *priv = hr_dev->priv;
@@ -2887,6 +2900,19 @@ static struct ib_cq *free_mr_init_cq(struct hns_roce_dev *hr_dev)
	return cq;
	return cq;
}
}


static void free_mr_uninit_cq(struct hns_roce_dev *hr_dev)
{
	struct hns_roce_v2_priv *priv = hr_dev->priv;
	struct hns_roce_v2_free_mr *free_mr = &priv->free_mr;

	if (!free_mr->rsv_cq)
		return;

	hns_roce_destroy_cq(&free_mr->rsv_cq->ib_cq, NULL);
	kvfree(free_mr->rsv_cq);
	free_mr->rsv_cq = NULL;
}

static struct hns_roce_qp *create_free_mr_qp(struct hns_roce_dev *hr_dev,
static struct hns_roce_qp *create_free_mr_qp(struct hns_roce_dev *hr_dev,
					     struct ib_pd *pd, struct ib_cq *cq)
					     struct ib_pd *pd, struct ib_cq *cq)
{
{
@@ -2916,14 +2942,14 @@ static void free_mr_exit(struct hns_roce_dev *hr_dev)
{
{
	struct hns_roce_v2_priv *priv = hr_dev->priv;
	struct hns_roce_v2_priv *priv = hr_dev->priv;
	struct hns_roce_v2_free_mr *free_mr = &priv->free_mr;
	struct hns_roce_v2_free_mr *free_mr = &priv->free_mr;
	struct hns_roce_qp *hr_qp;
	struct ib_qp *qp;
	int ret;
	int ret;
	int i;
	int i;


	for (i = 0; i < ARRAY_SIZE(free_mr->rsv_qp); i++) {
	for (i = 0; i < ARRAY_SIZE(free_mr->rsv_qp); i++) {
		if (free_mr->rsv_qp[i]) {
		if (free_mr->rsv_qp[i]) {
			hr_qp = to_hr_qp(&free_mr->rsv_qp[i]->ibqp);
			qp = &free_mr->rsv_qp[i]->ibqp;
			ret = hns_roce_v2_destroy_qp_common(hr_dev, hr_qp, NULL);
			ret = hns_roce_v2_destroy_qp(qp, NULL);
			if (ret)
			if (ret)
				ibdev_err(&hr_dev->ib_dev,
				ibdev_err(&hr_dev->ib_dev,
					  "failed to destroy qp in free mr.\n");
					  "failed to destroy qp in free mr.\n");
@@ -2932,16 +2958,8 @@ static void free_mr_exit(struct hns_roce_dev *hr_dev)
		}
		}
	}
	}


	if (free_mr->rsv_cq) {
	free_mr_uninit_cq(hr_dev);
		hns_roce_destroy_cq(&free_mr->rsv_cq->ib_cq, NULL);
	free_mr_uninit_pd(hr_dev);
		kfree(free_mr->rsv_cq);
	}

	if (free_mr->rsv_pd) {
		hns_roce_dealloc_pd(&free_mr->rsv_pd->ibpd, NULL);
		free_mr->rsv_pd = NULL;
		kfree(free_mr->rsv_pd);
	}
}
}


static int free_mr_alloc_res(struct hns_roce_dev *hr_dev)
static int free_mr_alloc_res(struct hns_roce_dev *hr_dev)
@@ -2976,12 +2994,12 @@ static int free_mr_alloc_res(struct hns_roce_dev *hr_dev)
	return 0;
	return 0;


create_failed_qp:
create_failed_qp:
	hns_roce_destroy_cq(cq, NULL);
	for (i--; i >= 0; i--)
	kfree(cq);
		hns_roce_v2_destroy_qp(&free_mr->rsv_qp[i]->ibqp, NULL);
	free_mr_uninit_cq(hr_dev);


create_failed_cq:
create_failed_cq:
	hns_roce_dealloc_pd(pd, NULL);
	free_mr_uninit_pd(hr_dev);
	kfree(pd);


	return ret;
	return ret;
}
}
+11 −1
Original line number Original line Diff line number Diff line
@@ -1114,14 +1114,24 @@ static int hns_roce_register_device(struct hns_roce_dev *hr_dev)


	if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_BOND) {
	if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_BOND) {
		ret = hr_dev->hw->bond_init(hr_dev);
		ret = hr_dev->hw->bond_init(hr_dev);
		if (ret)
		if (ret) {
			dev_err(dev, "roce bond init failed, ret = %d\n", ret);
			dev_err(dev, "roce bond init failed, ret = %d\n", ret);
			/* For non-bond devices, the failure of bond_init does
			 * not affect other functions.
			 */
			if (hr_dev->hw->bond_is_active(hr_dev))
				goto error_bond_init;
			else
				ret = 0;
		}
	}
	}


	hr_dev->active = true;
	hr_dev->active = true;


	return ret;
	return ret;


error_bond_init:
	unregister_netdevice_notifier(&iboe->nb);
error_failed_setup_mtu_mac:
error_failed_setup_mtu_mac:
	ib_unregister_device(ib_dev);
	ib_unregister_device(ib_dev);


Loading