From 18f1f2023e7bbee66b1fd805b55985fd33d12fe9 Mon Sep 17 00:00:00 2001 From: zhaoweibo Date: Wed, 26 Apr 2023 11:21:57 +0800 Subject: [PATCH] RDMA/hns: Add check for user-configured max_inline_data value driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I51UWX CVE: NA ------------------------------------------------------------- When the user-configured max_inline_data value exceeds the hardware specification, an err needs to be returned. Fixes: 87d3b87b92b9 ("RDMA/hns: Optimize qp param setup flow") Signed-off-by: zhaoweibo Reviewed-by: Chunzhi Hu Signed-off-by: Zhang Changzhong --- drivers/infiniband/hw/hns/hns_roce_qp.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/infiniband/hw/hns/hns_roce_qp.c b/drivers/infiniband/hw/hns/hns_roce_qp.c index 6f266932c988..df14a6909fd7 100644 --- a/drivers/infiniband/hw/hns/hns_roce_qp.c +++ b/drivers/infiniband/hw/hns/hns_roce_qp.c @@ -756,6 +756,22 @@ static void free_qp_buf(struct hns_roce_qp *hr_qp, struct ib_pd *ib_pd) hns_roce_free_recv_inline_buffer(hr_qp); } +static int set_max_inline_data(struct hns_roce_dev *hr_dev, + struct ib_qp_init_attr *init_attr) +{ + if (init_attr->cap.max_inline_data > hr_dev->caps.max_sq_inline) + return -EINVAL; + + if (init_attr->qp_type == IB_QPT_UD) + init_attr->cap.max_inline_data = 0; + + if (init_attr->cap.max_inline_data) + init_attr->cap.max_inline_data = roundup_pow_of_two( + init_attr->cap.max_inline_data); + + return 0; +} + static int set_qp_param(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp, struct ib_qp_init_attr *init_attr, struct ib_udata *udata, @@ -763,6 +779,10 @@ static int set_qp_param(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp, { int ret; + ret = set_max_inline_data(hr_dev, init_attr); + if (ret != 0) + return -EINVAL; + hr_qp->ibqp.qp_type = init_attr->qp_type; if (init_attr->sq_sig_type == IB_SIGNAL_ALL_WR) -- GitLab