From 10534f0ef2ca73e8e59a38e51969cae864f9fbbf Mon Sep 17 00:00:00 2001 From: wenglianfa Date: Thu, 13 Mar 2025 17:26:51 +0800 Subject: [PATCH 54/55] libhns: Fix wrong max inline data value mainline inclusion from mainline-v56.0-65 commit 8307b7c54ed81c343ec874e2066de79260b666d2 category: bugfix bugzilla: https://gitee.com/src-openeuler/rdma-core/issues/IC1V44 CVE: NA Reference: https://github.com/linux-rdma/rdma-core/pull/1579/commits/8307b7c54ed81c343e... --------------------------------------------------------------------- When cap.max_inline_data is 0, it will be modified to 1 since roundup_pow_of_two(0) == 1, which violates users' expectations. Here fix it. Fixes: 2aff0d55098c ("libhns: Fix the problem of sge nums") Signed-off-by: wenglianfa Signed-off-by: Junxian Huang Signed-off-by: Xinghai Cen --- providers/hns/hns_roce_u_verbs.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/providers/hns/hns_roce_u_verbs.c b/providers/hns/hns_roce_u_verbs.c index f0098ed..5fe169e 100644 --- a/providers/hns/hns_roce_u_verbs.c +++ b/providers/hns/hns_roce_u_verbs.c @@ -1494,6 +1494,16 @@ static unsigned int get_sge_num_from_max_inl_data(bool is_ud, return inline_sge; } +static uint32_t get_max_inline_data(struct hns_roce_context *ctx, + struct ibv_qp_cap *cap) +{ + if (cap->max_inline_data) + return min_t(uint32_t, roundup_pow_of_two(cap->max_inline_data), + ctx->max_inline_data); + + return 0; +} + static void set_ext_sge_param(struct hns_roce_context *ctx, struct ibv_qp_init_attr_ex *attr, struct hns_roce_qp *qp, unsigned int wr_cnt) @@ -1510,9 +1520,7 @@ static void set_ext_sge_param(struct hns_roce_context *ctx, attr->cap.max_send_sge); if (ctx->config & HNS_ROCE_RSP_EXSGE_FLAGS) { - attr->cap.max_inline_data = min_t(uint32_t, roundup_pow_of_two( - attr->cap.max_inline_data), - ctx->max_inline_data); + attr->cap.max_inline_data = get_max_inline_data(ctx, &attr->cap); inline_ext_sge = max(ext_wqe_sge_cnt, get_sge_num_from_max_inl_data(is_ud, -- 2.33.0