RDMA/mana_ib: support enhanced connection establishment
Subsystems (2)
PATCH 1/1 RDMA/mana_ib: support enhanced connection establishment
From: Snehal Sanghvi <[email protected]>
Expose ECE when the firmware supports it. Return the firmware ECE offer for RC and UC QPs, and use the RNIC set-state V4 layout for every modify so that user ECE options reach the firmware and its current options are returned; 0 means no update, and option bits are interpreted by the firmware. Without firmware support, requests keep their legacy layout.
---
Matching rdma-core userspace implementation:
https://github.com/linux-rdma/rdma-core/pull/1866
drivers/infiniband/hw/mana/main.c | 12 +++++++-- drivers/infiniband/hw/mana/mana_ib.h | 20 ++++++++++++--- drivers/infiniband/hw/mana/qp.c | 38 ++++++++++++++++++++-------- include/uapi/rdma/mana-abi.h | 15 +++++++++-- 4 files changed, 67 insertions(+), 18 deletions(-)
drivers/infiniband/hw/mana/main.c +10 -2
@@ -250,6 +250,8 @@ int mana_ib_alloc_ucontext(struct ib_ucontext *ibcontext, ucmd_resp.comp_mask |=MANA_IB_UCNTX_RC_EXT_SUPPORT ;if (mdev->adapter_caps.feature_flags &MANA_IB_FEATURE_RC_QP_SQ_POW2_SUPPORT ) ucmd_resp.comp_mask |=MANA_IB_UCNTX_RC_SQ_POW2_SUPPORT ; +if (mana_ib_ece_supported (mdev)) + ucmd_resp.comp_mask |=MANA_IB_UCNTX_ECE_SUPPORT ; ret =ib_respond_udata (udata, ucmd_resp);if (ret)return ret;
@@ -1054,7 +1056,8 @@ int mana_ib_gd_destroy_cq(struct mana_ib_dev *mdev, struct mana_ib_cq *cq) }int mana_ib_gd_create_rc_qp (struct mana_ib_dev *mdev,struct mana_ib_qp *qp, -struct ib_qp_init_attr *attr,u32 doorbell,u64 flags) +struct ib_qp_init_attr *attr,u32 doorbell,u64 flags, +u32 *ece_options) { struct mana_ib_cq *send_cq = container_of(qp->ibqp.send_cq, struct mana_ib_cq, ibcq); struct mana_ib_cq *recv_cq = container_of(qp->ibqp.recv_cq, struct mana_ib_cq, ibcq);
@@ -1092,11 +1095,14 @@ int mana_ib_gd_create_rc_qp(struct mana_ib_dev *mdev, struct mana_ib_qp *qp,/* The GDMA regions are now owned by the RNIC QP handle */ qp->rc_qp.queues[i].gdma_region =GDMA_INVALID_DMA_REGION ; } +if (ece_options &&mana_ib_ece_supported (mdev)) + *ece_options = resp.ece_options;return 0 ; }int mana_ib_gd_create_uc_qp (struct mana_ib_dev *mdev,struct mana_ib_qp *qp, -struct ib_qp_init_attr *attr,u32 doorbell,u64 flags) +struct ib_qp_init_attr *attr,u32 doorbell,u64 flags, +u32 *ece_options) { struct mana_ib_cq *send_cq = container_of(qp->ibqp.send_cq, struct mana_ib_cq, ibcq); struct mana_ib_cq *recv_cq = container_of(qp->ibqp.recv_cq, struct mana_ib_cq, ibcq);
@@ -1131,6 +1137,8 @@ int mana_ib_gd_create_uc_qp(struct mana_ib_dev *mdev, struct mana_ib_qp *qp,/* The GDMA regions are now owned by the RNIC QP handle */ qp->uc_qp.queues[i].gdma_region =GDMA_INVALID_DMA_REGION ; } +if (mana_ib_ece_supported (mdev)) + *ece_options = resp.ece_options;return 0 ; }
drivers/infiniband/hw/mana/mana_ib.h +16 -4
@@ -339,6 +339,7 @@ enum mana_ib_adapter_features {MANA_IB_FEATURE_EXTENDED_WQE_FORMAT =BIT (9 ),MANA_IB_FEATURE_RC_QP_SQ_POW2_SUPPORT =BIT (14 ),MANA_IB_FEATURE_MULTI_PORT_GSI_SUPPORT =BIT (15 ), + MANA_IB_FEATURE_ECE_SUPPORT = BIT(19), }; struct mana_ib_query_adapter_caps_resp {
@@ -476,7 +477,7 @@ struct mana_rnic_create_qp_resp {struct gdma_resp_hdr hdr;mana_handle_t rc_qp_handle;u32 queue_ids[MANA_RC_QUEUE_TYPE_MAX ]; -u32 reserved; +u32 ece_options; };/* HW Data*/ struct mana_rnic_destroy_rnic_qp_req {
@@ -509,7 +510,7 @@ struct mana_rnic_create_uc_qp_resp {struct gdma_resp_hdr hdr;mana_handle_t qp_handle;u32 queue_ids[MANA_UC_QUEUE_TYPE_MAX ]; -u32 reserved; +u32 ece_options; };/* HW Data*/ struct mana_rnic_create_udqp_req {
@@ -585,11 +586,15 @@ struct mana_rnic_set_qp_state_req {u8 local_ack_timeout;u8 max_rd_atomic;u16 reserved2; +u32 mana_attr_mask; +u32 ece_options;u32 reserved3; };/* HW Data */ struct mana_rnic_set_qp_state_resp {struct gdma_resp_hdr hdr; +u32 ece_options; +u32 reserved; };/* HW Data */ enum WQE_OPCODE_TYPES {
@@ -913,6 +918,11 @@ static inline bool mana_ib_is_rnic(struct mana_ib_dev *mdev)return mdev->gdma_dev->dev_id.type ==GDMA_DEVICE_MANA_IB ; } +static inline bool mana_ib_ece_supported (struct mana_ib_dev *mdev) +{ +return mdev->adapter_caps.feature_flags &MANA_IB_FEATURE_ECE_SUPPORT ; +} +static inline struct net_device *mana_ib_get_netdev (struct ib_device *ibdev,u32 port) { struct mana_ib_dev *mdev = container_of(ibdev, struct mana_ib_dev, ib_dev);
@@ -1046,10 +1056,12 @@ int mana_ib_gd_create_cq(struct mana_ib_dev *mdev, struct mana_ib_cq *cq, u32 doint mana_ib_gd_destroy_cq (struct mana_ib_dev *mdev,struct mana_ib_cq *cq);int mana_ib_gd_create_rc_qp (struct mana_ib_dev *mdev,struct mana_ib_qp *qp, -struct ib_qp_init_attr *attr,u32 doorbell,u64 flags); +struct ib_qp_init_attr *attr,u32 doorbell,u64 flags, +u32 *ece_options);int mana_ib_gd_destroy_rnic_qp (struct mana_ib_dev *mdev,struct mana_ib_qp *qp);int mana_ib_gd_create_uc_qp (struct mana_ib_dev *mdev,struct mana_ib_qp *qp, -struct ib_qp_init_attr *attr,u32 doorbell,u64 flags); +struct ib_qp_init_attr *attr,u32 doorbell,u64 flags, +u32 *ece_options);int mana_ib_gd_create_ud_qp (struct mana_ib_dev *mdev,struct mana_ib_qp *qp,struct ib_qp_init_attr *attr,u32 doorbell,u32 type);int mana_ib_gd_destroy_ud_qp (struct mana_ib_dev *mdev,struct mana_ib_qp *qp);
drivers/infiniband/hw/mana/qp.c +28 -10
@@ -656,7 +656,7 @@ static int mana_ib_create_rc_qp(struct ib_qp *ibqp, struct ib_pd *ibpd, qp->rc_qp.wqe_size_in_bu = wqe_size /GDMA_WQE_BU_SIZE ; } - err =mana_ib_gd_create_rc_qp (mdev, qp, attr, doorbell, flags); + err =mana_ib_gd_create_rc_qp (mdev, qp, attr, doorbell, flags, &resp.ece_options);if (err) {ibdev_err (&mdev->ib_dev,"Failed to create rc qp %d\n" , err); goto destroy_queues;
@@ -720,7 +720,7 @@ static int mana_ib_create_uc_qp(struct ib_qp *ibqp, struct ib_pd *ibpd, goto destroy_queues; } - err =mana_ib_gd_create_uc_qp (mdev, qp, attr, doorbell, flags); + err =mana_ib_gd_create_uc_qp (mdev, qp, attr, doorbell, flags, &resp.ece_options);if (err) goto destroy_queues;
@@ -920,7 +920,7 @@ static int mana_ib_create_rc_qp_kernel(struct ib_qp *ibqp, struct ib_pd *ibpd,if (err) goto destroy_queues; - err =mana_ib_gd_create_rc_qp (mdev, qp, attr, doorbell, flags); + err =mana_ib_gd_create_rc_qp (mdev, qp, attr, doorbell, flags,NULL );if (err) goto deinit_queues;
@@ -996,18 +996,33 @@ static int mana_ib_gd_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, struct mana_ib_qp *qp = container_of(ibqp, struct mana_ib_qp, ibqp);struct mana_rnic_set_qp_state_resp resp = {};struct mana_rnic_set_qp_state_req req = {}; +struct mana_ib_modify_qp_resp uresp = {}; +struct mana_ib_modify_qp ucmd = {};struct gdma_context *gc =mdev_to_gc (mdev);struct mana_port_context *mpc;struct net_device *ndev; +bool ece =mana_ib_ece_supported (mdev);int err; - err =ib_no_udata_io (udata); -if (err) -return err; +if (udata && udata->inlen) { + err =ib_copy_validate_udata_in_cm (udata, ucmd, ece_options,0 ); +if (err) +return err; + }else { + err =ib_no_udata_io (udata); +if (err) +return err; + } -mana_gd_init_req_hdr (&req.hdr,MANA_IB_SET_QP_STATE ,sizeof (req),sizeof (resp)); +/* ece_options 0 means no ECE update; only firmware with ECE gets V4. */ + req.ece_options = ucmd.ece_options; +mana_gd_init_req_hdr (&req.hdr,MANA_IB_SET_QP_STATE , + ece ?sizeof (req) :offsetofend (typeof (req), mana_attr_mask), + ece ?sizeof (resp) :sizeof (resp.hdr)); - req.hdr.req.msg_version =GDMA_MESSAGE_V3 ; + req.hdr.req.msg_version = ece ?GDMA_MESSAGE_V4 :GDMA_MESSAGE_V3 ; +if (ece) + req.hdr.resp.msg_version =GDMA_MESSAGE_V2 ; req.hdr.dev_id = mdev->gdma_dev->dev_id; req.adapter = mdev->adapter_handle; req.qp_handle = qp->qp_handle;
@@ -1056,11 +1071,14 @@ static int mana_ib_gd_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, req.ah_attr.flow_label = attr->ah_attr.grh.flow_label; } - err =mana_gd_send_request (gc,sizeof (req), &req,sizeof (resp), &resp); + err =mana_gd_send_request (gc, req.hdr.req.msg_size, &req, req.hdr.resp.msg_size, &resp);if (err)return err; -return 0 ; +if (!udata || !udata->inlen) +return 0 ; + uresp.ece_options = resp.ece_options; +return ib_respond_udata (udata, uresp); } static bool mana_ib_modify_qp_state(struct ib_qp *ibqp, struct ib_qp_attr *attr,
include/uapi/rdma/mana-abi.h +13 -2
@@ -64,7 +64,17 @@ struct mana_ib_create_rc_qp {struct mana_ib_create_rc_qp_resp {__u32 queue_id[4 ];__u32 mmq_id; -__u32 reserved; +__u32 ece_options; +}; + +struct mana_ib_modify_qp { +__u32 comp_mask; +__u32 ece_options; +}; + +struct mana_ib_modify_qp_resp { +__u32 comp_mask; +__u32 ece_options; };struct mana_ib_create_uc_qp {
@@ -75,7 +85,7 @@ struct mana_ib_create_uc_qp {struct mana_ib_create_uc_qp_resp {__u32 queue_id[3 ]; -__u32 reserved; +__u32 ece_options; };struct mana_ib_create_wq {
@@ -112,6 +122,7 @@ enum mana_ib_ucontext_support {MANA_IB_UCNTX_ALLOC_PDN_SUPPORT =1 <<0 ,MANA_IB_UCNTX_RC_EXT_SUPPORT =1 <<1 ,MANA_IB_UCNTX_RC_SQ_POW2_SUPPORT =1 <<2 , + MANA_IB_UCNTX_ECE_SUPPORT = 1 << 3, }; struct mana_ib_alloc_ucontext_resp {
base-commit: 7404c82cbf1246e0e84e2ec21834d23c26f9a8ed
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 2 related pre-existing issues it does not introduce: - [Critical] RDMA/mana_ib: null pointer…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 2 related pre-existing issues it does not introduce:
- [Critical] RDMA/mana_ib: null pointer dereference in mana_ib_gd_create_rc_qp() [1]
- [High] RDMA/mana_ib: integer overflow in mana_ib_create_rc_qp() [2] --
commit e575bd297d63089e7e8cc394cb0a9db17a952542
Author: Snehal Sanghvi <[email protected]>
RDMA/mana_ib: support enhanced connection establishment
This commit exposes enhanced connection establishment (ECE) capabilities to user space when supported by firmware, returns firmware ECE offers on RC and UC QP creation, and uses the RNIC V4 set-state layout during QP modifications to exchange ECE options with firmware.
Quoted 4 lines
drivers/infiniband/hw/mana/main.c +0
-0
[ ... ]
drivers/infiniband/hw/mana/main.c int mana_ib_gd_destroy_cq(struct mana_ib_dev *mdev, struct mana_ib_cq *cq) · line 1063
Quoted 10 lines
drivers/infiniband/hw/mana/main.c +2
-1@@ -1054,7 +1056,8 @@ int mana_ib_gd_destroy_cq(struct mana_ib_dev *mdev, struct mana_ib_cq *cq) }int mana_ib_gd_create_rc_qp (struct mana_ib_dev *mdev,struct mana_ib_qp *qp, -struct ib_qp_init_attr *attr,u32 doorbell,u64 flags) +struct ib_qp_init_attr *attr,u32 doorbell,u64 flags, +u32 *ece_options) { struct mana_ib_cq *send_cq = container_of(qp->ibqp.send_cq, struct mana_ib_cq, ibcq); struct mana_ib_cq *recv_cq = container_of(qp->ibqp.recv_cq, struct mana_ib_cq, ibcq);
[Severity: Critical]
This problem wasn't introduced by this patch, but can qp->ibqp.send_cq and qp->ibqp.recv_cq be NULL here [1]?
When user space creates an RC, UC, or UD QP via UVERBS_METHOD_QP_CREATE with an indirection table (rwq_ind_tbl) and max_send_wr = 0, the uverbs core treats both CQs as optional and leaves qp->ibqp.send_cq and qp->ibqp.recv_cq NULL. Applying container_of() to them and reading send_cq->cq_handle and recv_cq->cq_handle in mana_ib_gd_create_rc_qp() (as well as mana_ib_gd_create_uc_qp(), mana_ib_gd_create_ud_qp(), and mana_remove_qp_from_cqs()) causes a NULL pointer dereference.
drivers/infiniband/hw/mana/qp.c static int mana_ib_create_rc_qp(struct ib_qp *ibqp, struct ib_pd *ibpd, · line 659
Quoted 10 lines
drivers/infiniband/hw/mana/qp.c +1
-1@@ -656,7 +656,7 @@ static int mana_ib_create_rc_qp(struct ib_qp *ibqp, struct ib_pd *ibpd, qp->rc_qp.wqe_size_in_bu = wqe_size /GDMA_WQE_BU_SIZE ; } - err =mana_ib_gd_create_rc_qp (mdev, qp, attr, doorbell, flags); + err =mana_ib_gd_create_rc_qp (mdev, qp, attr, doorbell, flags, &resp.ece_options);
[Severity: High]
This problem wasn't introduced by this patch, but can an unvalidated attr->cap.max_send_sge overflow the 32-bit wqe_size calculation in mana_ib_fixed_wqe_size() [2]?
drivers/infiniband/hw/mana/qp.c:mana_ib_wqe_size() {
u32 wqe_size = sge * sizeof(struct gdma_sge) + sizeof(struct gdma_wqe) + oob_size;
return ALIGN(wqe_size, GDMA_WQE_BU_SIZE);
}drivers/infiniband/hw/mana/qp.c:mana_ib_fixed_wqe_size() {
return roundup_pow_of_two(mana_ib_wqe_size(sge, oob_size));
}When MANA_IB_RC_QP_FIXED_WQE is set, user-controlled attr->cap.max_send_sge is passed to mana_ib_fixed_wqe_size() without a bounds check against mdev->adapter_caps.max_send_sge_count. If sge is 0x0ffffffc, ALIGN(wqe_size, GDMA_WQE_BU_SIZE) wraps to 0 and roundup_pow_of_two(0) performs an out-of-bounds shift (1UL << 64), or if wqe_size exceeds 0x80000000, roundup_pow_of_two() returns 0x100000000UL which truncates to 0 in u32 and sets qp->rc_qp.wqe_size_in_bu to 0.
[1] https://sashiko.dev/#/bug/linux-86b919ff-d815-475b-90a6-38b75879f413
[2] https://sashiko.dev/#/bug/linux-c09403d1-5db1-420f-88f0-f4df2a2d57af
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1