RDMA/hns: Check atomic wr length

[ Upstream commit 6afa2c0bfb ]

8 bytes is the only supported length of atomic. Add this check in
set_rc_wqe(). Besides, stop processing WQEs and return from
set_rc_wqe() if there is any error.

Fixes: 384f881851 ("RDMA/hns: Add atomic support")
Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
Link: https://lore.kernel.org/r/20240710133705.896445-2-huangjunxian6@hisilicon.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Junxian Huang 2024-07-10 21:36:58 +08:00 committed by Greg Kroah-Hartman
parent a60111f96e
commit 72bbfe07f7
2 changed files with 9 additions and 2 deletions

View File

@ -90,6 +90,8 @@
/* Configure to HW for PAGE_SIZE larger than 4KB */ /* Configure to HW for PAGE_SIZE larger than 4KB */
#define PG_SHIFT_OFFSET (PAGE_SHIFT - 12) #define PG_SHIFT_OFFSET (PAGE_SHIFT - 12)
#define ATOMIC_WR_LEN 8
#define HNS_ROCE_IDX_QUE_ENTRY_SZ 4 #define HNS_ROCE_IDX_QUE_ENTRY_SZ 4
#define SRQ_DB_REG 0x230 #define SRQ_DB_REG 0x230

View File

@ -595,11 +595,16 @@ static inline int set_rc_wqe(struct hns_roce_qp *qp,
(wr->send_flags & IB_SEND_SIGNALED) ? 1 : 0); (wr->send_flags & IB_SEND_SIGNALED) ? 1 : 0);
if (wr->opcode == IB_WR_ATOMIC_CMP_AND_SWP || if (wr->opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
wr->opcode == IB_WR_ATOMIC_FETCH_AND_ADD) wr->opcode == IB_WR_ATOMIC_FETCH_AND_ADD) {
if (msg_len != ATOMIC_WR_LEN)
return -EINVAL;
set_atomic_seg(wr, rc_sq_wqe, valid_num_sge); set_atomic_seg(wr, rc_sq_wqe, valid_num_sge);
else if (wr->opcode != IB_WR_REG_MR) } else if (wr->opcode != IB_WR_REG_MR) {
ret = set_rwqe_data_seg(&qp->ibqp, wr, rc_sq_wqe, ret = set_rwqe_data_seg(&qp->ibqp, wr, rc_sq_wqe,
&curr_idx, valid_num_sge); &curr_idx, valid_num_sge);
if (ret)
return ret;
}
/* /*
* The pipeline can sequentially post all valid WQEs into WQ buffer, * The pipeline can sequentially post all valid WQEs into WQ buffer,