RDMA/mana_ib: Add kernel RC and fast registration support
Subsystems (5)
v6 cover RDMA/mana_ib: Add kernel RC and fast registration support
From: Konstantin Taranov <[email protected]>
Add kernel RC QPs and fast-registration MRs to the MANA RDMA driver for kernel consumers such as NVMe/RDMA and NFS/RDMA.
Implement QP creation and state management, work request posting, completion processing, error handling, and queue draining. Kernel RC QPs require extended-WQE and power-of-two-SQ hardware support.
Tested with krping, NVMe/RDMA, and NFS/RDMA, including RC send and receive error recovery with krping and NVMe/RDMA.
v6:
- Patch 08: Notify software flushes after posting to error-listed QPs. Add reporting pending software flush for IB_CQ_REPORT_MISSED_EVENTS.
- Patch 09: Check fenced WQEs on error cqes to prevent flushing completed WQEs. Add mana_ib_cq_clean on QP reset to discard stale CQEs. QID 0 is an invalid value for RNIC and safe dor discarding. Add error_pending flag to prevent a deffered ERR request to error reset QPs.
v5:
- Patch 01: Reject max_num_sg above MANA_MAX_FMR_PAGES.
- Patch 02: Validate kernel QP queue sizes and SGE limits to prevent overflows. Ensure that queue size cannnot be 0.
- Patch 06: Preserve fence flags on unsignaled WQEs. Check message length and read sges before posting a wqe.
- Patch 08: Remove the unused QP state field.
v4:
- Patch 01: Use an explicit 64-byte FMR MST alignment
- Patch 02: Validate that the RNIC firmware reports at least two send SGEs and subtract the reserved SGE only for RNIC-based mana_ib.
- Patch 07: Add missing wqe_size to shadow wqe for SEND/Write, and return a missed-event hint for cached CQEs when CQ is armed
v3:
- Patch 07: Mask arm_psn to 24 bits before ringing the doorbell.
- Patch 08: Exclude userspace QPs from kernel software-state handling and CQ error-list insertion, and unlink UC QPs during destruction.
v2:
- Patch 03: Validate fixed-WQE capacity for the header, OOB and SGEs.
- Patch 04: Preserve UC QP modification support.
- Patch 08: Skip software CQ notifications for direct-polling CQs.
- Patch 09: Flush that ERR work during QP teardown.
- Patch 10: Limit drain callbacks to RC QPs and avoid completion callbacks for direct-polling CQs.
Konstantin Taranov (10):
RDMA/mana_ib: Allocate and map fast-registration MRs RDMA/mana: Create and destroy kernel RC QPs net/mana: Extend GDMA encoding for new RDMA WQEs RDMA/mana_ib: Maintain kernel RC QP state RDMA/mana_ib: Post receive WRs on kernel RC QPs RDMA/mana_ib: Post send and memory-management WRs on RC QPs RDMA/mana_ib: Poll RC completions using PSN and FSN progress RDMA/mana_ib: Flush and notify CQs when kernel QPs enter ERR RDMA/mana_ib: Handle error CQEs for RC QPs RDMA/mana_ib: Drain kernel receive and send queues
drivers/infiniband/hw/mana/cq.c | 354 +++++++++++++++++-- drivers/infiniband/hw/mana/device.c | 4 + drivers/infiniband/hw/mana/main.c | 15 +- drivers/infiniband/hw/mana/mana_ib.h | 137 +++++++- drivers/infiniband/hw/mana/mr.c | 87 ++++- drivers/infiniband/hw/mana/qp.c | 427 +++++++++++++++++++++-- drivers/infiniband/hw/mana/shadow_queue.h | 22 ++ drivers/infiniband/hw/mana/wr.c | 433 +++++++++++++++++++++++- drivers/net/ethernet/microsoft/mana/gdma_main.c | 55 ++- include/net/mana/gdma.h | 38 ++- 10 files changed, 1506 insertions(+), 66 deletions(-)
Signature · 1 line
2.43.0
PATCH v6 1/10 RDMA/mana_ib: Allocate and map fast-registration MRs
From: Konstantin Taranov <[email protected]>
Implement alloc_mr and map_mr_sg for memory-registration MRs.
---
v5:
- Reject max_num_sg above MANA_MAX_FMR_PAGES
v4:
- Use an explicit 64-byte FMR MST alignment
drivers/infiniband/hw/mana/device.c | 2 + drivers/infiniband/hw/mana/main.c | 3 +- drivers/infiniband/hw/mana/mana_ib.h | 48 +++++++++++++++ drivers/infiniband/hw/mana/mr.c | 87 +++++++++++++++++++++++++++- include/net/mana/gdma.h | 15 +++++ 5 files changed, 153 insertions(+), 2 deletions(-)
drivers/infiniband/hw/mana/device.c +2 -0
@@ -19,6 +19,7 @@ static const struct ib_device_ops mana_ib_dev_ops = { .add_gid = mana_ib_gd_add_gid, .alloc_mw = mana_ib_alloc_mw, + .alloc_mr = mana_ib_alloc_mr, .alloc_pd = mana_ib_alloc_pd, .alloc_ucontext = mana_ib_alloc_ucontext, .create_ah = mana_ib_create_ah,
@@ -40,6 +41,7 @@ static const struct ib_device_ops mana_ib_dev_ops = { .get_dma_mr = mana_ib_get_dma_mr, .get_link_layer = mana_ib_get_link_layer, .get_port_immutable = mana_ib_get_port_immutable, + .map_mr_sg = mana_ib_map_mr_sg, .mmap = mana_ib_mmap, .modify_qp = mana_ib_modify_qp, .modify_wq = mana_ib_modify_wq,
drivers/infiniband/hw/mana/main.c +2 -1
@@ -133,7 +133,7 @@ int mana_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata) sizeof(resp));if (!udata) - flags |=GDMA_PD_FLAG_ALLOW_GPA_MR ; + flags |=GDMA_PD_FLAG_ALLOW_GPA_MR |GDMA_PD_FLAG_ALLOW_FMR_MR ; req.flags = flags; err =mana_gd_send_request (gc,sizeof (req), &req,sizeof (resp), &resp);
@@ -647,6 +647,7 @@ int mana_ib_query_device(struct ib_device *ibdev, struct ib_device_attr *props, props->max_ah =INT_MAX ; props->max_pkeys =1 ; props->local_ca_ack_delay =MANA_CA_ACK_DELAY ; + props->max_fast_reg_page_list_len =MANA_MAX_FMR_PAGES ;if (!mana_ib_is_rnic (dev)) props->raw_packet_caps =IB_RAW_PACKET_CAP_IP_CSUM ;
drivers/infiniband/hw/mana/mana_ib.h +48 -0
78 lines not on this page · raw message
drivers/infiniband/hw/mana/mr.c +86 -1
122 lines not on this page · raw message
include/net/mana/gdma.h +15 -0
@@ -865,6 +865,8 @@ enum gdma_mr_access_flags {GDMA_ACCESS_FLAG_REMOTE_WRITE =BIT_ULL (3 ),GDMA_ACCESS_FLAG_REMOTE_ATOMIC =BIT_ULL (4 ),GDMA_ACCESS_FLAG_BIND_MW =BIT_ULL (5 ), +GDMA_ACCESS_FLAG_INVALIDATE =BIT_ULL (6 ), + GDMA_ACCESS_FLAG_FMR = BIT_ULL(7), };/* GDMA_CREATE_DMA_REGION */
@@ -917,6 +919,7 @@ struct gdma_destroy_dma_region_req {enum gdma_pd_flags {GDMA_PD_FLAG_ALLOW_GPA_MR =BIT (0 ), +GDMA_PD_FLAG_ALLOW_FMR_MR =BIT (1 ),GDMA_PD_FLAG_SHORT_PDN =BIT (2 ), };
@@ -953,6 +956,11 @@ enum gdma_mr_type {* address that is set up in the MST */ GDMA_MR_TYPE_GVA =2 , +/* Fast Memory - MRs are initially put in the free state, +* and the specified number of PTEs are reserved for future fast +* memory registrations +*/ +GDMA_MR_TYPE_FMR =3 ,/* Guest zero-based address MRs */ GDMA_MR_TYPE_ZBVA = 4,/* Device address MRs */
@@ -982,6 +990,9 @@ struct gdma_create_mr_params {u64 length;enum gdma_mr_access_flags access_flags; } da; +struct { +u32 rsvd_pte_count; + } fmr; }; };
@@ -1006,6 +1017,10 @@ struct gdma_create_mr_request {u64 offset;enum gdma_mr_access_flags access_flags; }__packed da; +struct { +u32 page_size; +u32 rsvd_pte_count; + } __packed fmr; } __packed;u32 reserved_2;union {
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH rdma-next v6 01/10] RDMA/mana_ib: Allocate and map fast-registration MRs
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
From: Konstantin Taranov <[email protected]>
Implement
alloc_mrandmap_mr_sgfor memory-registration MRs.Signed-off-by Konstantin Taranov <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v6 2/10 RDMA/mana: Create and destroy kernel RC QPs
In reply to Konstantin TaranovFrom: Konstantin Taranov <[email protected]>
Implement kernel RC QP creation and destruction. This feature requires extended-WQE and power-of-two-SQ support from the HW.
---
v5:
- Validate kernel QP queue sizes before allocating queues.
- Bound SGE counts and enforce the TX/RX WQE size limits. v4:
- Reject RNIC firmware send-SGE counts below 2.
- Subtract the reserved SGE for extra-large OOB only for RNIC mana_ib.
drivers/infiniband/hw/mana/main.c | 10 +- drivers/infiniband/hw/mana/mana_ib.h | 6 + drivers/infiniband/hw/mana/qp.c | 206 +++++++++++++++++++++++++-- 3 files changed, 211 insertions(+), 11 deletions(-)
drivers/infiniband/hw/mana/main.c +9 -1
@@ -733,6 +733,13 @@ int mana_ib_gd_query_adapter_caps(struct mana_ib_dev *dev)if (err)return err; +/* Hardware supports at least one data SGE plus one reserved for extra-large OOB. */ +if (resp.max_send_sge_count <2 ) { +ibdev_err (&dev->ib_dev,"Invalid max_send_sge_count %u, expected at least 2\n" , + resp.max_send_sge_count); +return -EINVAL ; + } + caps->max_sq_id = resp.max_sq_id; caps->max_rq_id = resp.max_rq_id; caps->max_cq_id = resp.max_cq_id;
@@ -748,7 +755,8 @@ int mana_ib_gd_query_adapter_caps(struct mana_ib_dev *dev) resp.max_requester_sq_size /GDMA_MAX_SQE_SIZE , resp.max_requester_rq_size / GDMA_MAX_RQE_SIZE); caps->max_inline_data_size = resp.max_inline_data_size; - caps->max_send_sge_count = resp.max_send_sge_count; +/* Account for the SGE reserved for extra-large OOB. */ + caps->max_send_sge_count = resp.max_send_sge_count -1 ; caps->max_recv_sge_count = resp.max_recv_sge_count; caps->feature_flags = resp.feature_flags;
drivers/infiniband/hw/mana/mana_ib.h +6 -0
@@ -267,6 +267,10 @@ struct mana_ib_qp {u32 sq_psn;bool sq_sig_all; +/* Serializes receive WR posting. */ +spinlock_t rq_lock; +/* Serializes send and memory-management WR posting. */ +spinlock_t sq_lock;/* Serializes QP modification and error-list transitions. */ struct mutex modify_lock;
@@ -274,6 +278,7 @@ struct mana_ib_qp {struct list_head recv_err_node;struct shadow_queue shadow_rq;struct shadow_queue shadow_sq; +struct shadow_queue shadow_mmq;refcount_t refcount;struct completion free;
@@ -315,6 +320,7 @@ enum mana_ib_adapter_features {MANA_IB_FEATURE_DEV_COUNTERS_SUPPORT =BIT (5 ),MANA_IB_FEATURE_MULTI_PORTS_SUPPORT =BIT (6 ),MANA_IB_FEATURE_MSN_IN_WQE_SUPPORT =BIT (7 ), +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), };
drivers/infiniband/hw/mana/qp.c +196 -10
263 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH rdma-next v6 02/10] RDMA/mana: Create and destroy kernel RC QPs
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
From: Konstantin Taranov <[email protected]>
Implement kernel RC QP creation and destruction. This feature requires extended-WQE and power-of-two-SQ support from the HW.
Signed-off-by Konstantin Taranov <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v6 3/10 net/mana: Extend GDMA encoding for new RDMA WQEs
In reply to Konstantin TaranovFrom: Konstantin Taranov <[email protected]>
Extend mana_gd_post_work_request() to support extra-large OOB data and fixed-size WQEs. These formats are supported only for power-of-two WQE sizes.
For fixed-size WQEs, use num_pad_sge to specify the padding size. Encode the WQE header fields required by RC QPs based on the WR flags.
---
v2:
- Reject fixed WQEs that cannot fit the header, aligned OOB and SGEs.
.../net/ethernet/microsoft/mana/gdma_main.c | 55 ++++++++++++++++--- include/net/mana/gdma.h | 21 +++++-- 2 files changed, 63 insertions(+), 13 deletions(-)
drivers/net/ethernet/microsoft/mana/gdma_main.c +47 -8
@@ -1699,8 +1699,27 @@ static u32 mana_gd_write_client_oob(const struct gdma_wqe_request *wqe_req, header->num_sge = wqe_req->num_sge; header->inline_oob_size_div4 = client_oob_size /sizeof (u32); +if (client_oob_size ==INLINE_OOB_EXTRA_LARGE_SIZE ) { +/* Extra large oob is encoded as 7 */ + header->inline_oob_size_div4 =7 ; +/* Extra large oob has 8 byte padding */ + client_oob_size +=8 ; + } + +if (wqe_req->wqe_size_in_bu) { + header->num_sge = (wqe_req->wqe_size_in_bu *GDMA_WQE_BU_SIZE + -sizeof (struct gdma_wqe ) - client_oob_size) /sizeof (struct gdma_sge ); + header->num_pad_sge = header->num_sge - wqe_req->num_sge; + } + + header->check_rsn = !!(wqe_req->flags &GDMA_WR_CHECK_RSN ); + header->check_sn = !!(wqe_req->flags &GDMA_WR_CHECK_SN ); + header->fence = !!(wqe_req->flags &GDMA_WR_FENCE ); + header->fence_extended = !!(wqe_req->flags &GDMA_WR_FENCE_EXTENDED ); + header->generation1 = !!(wqe_req->flags &GDMA_WR_GENERATION_1 ); +if (oob_in_sgl) { -WARN_ON_ONCE (wqe_req->num_sge <2 ); +WARN_ON_ONCE (wqe_req->num_sge <1 ); header->client_oob_in_sgl =1 ;
@@ -1714,8 +1733,10 @@ static u32 mana_gd_write_client_oob(const struct gdma_wqe_request *wqe_req,/* The size of gdma_wqe + client_oob_size must be less than or equal * to one Basic Unit (i.e. 32 bytes), so the pointer can't go beyond * the queue memory buffer boundary. +* The exception is when the WQE size is fixed and a power of 2, as +* such a wqe cannot go beyond the queue memory buffer boundary. */ - ptr = wqe_ptr +sizeof (header); + ptr = wqe_ptr +sizeof (struct gdma_wqe );if (wqe_req->inline_oob_data && wqe_req->inline_oob_size >0 ) {memcpy (ptr, wqe_req->inline_oob_data, wqe_req->inline_oob_size);
@@ -1724,8 +1745,8 @@ static u32 mana_gd_write_client_oob(const struct gdma_wqe_request *wqe_req,memset (ptr + wqe_req->inline_oob_size,0 , client_oob_size - wqe_req->inline_oob_size); } - -return sizeof (header) + client_oob_size; +/* The hw requires that (gdma_wqe + client_oob_size) is sge size aligned */ +return ALIGN (sizeof (struct gdma_wqe ) + client_oob_size,sizeof (struct gdma_sge )); } static void mana_gd_write_sgl(struct gdma_queue *wq, u32 sgl_offset,
@@ -1784,7 +1805,8 @@ int mana_gd_post_work_request(struct gdma_queue *wq,return -EINVAL ;if (wq->type ==GDMA_RQ ) { -if (client_oob_size !=0 ) +if (client_oob_size !=0 && + client_oob_size !=INLINE_OOB_SMALL_SIZE )return -EINVAL ; client_oob_size =INLINE_OOB_SMALL_SIZE ;
@@ -1792,15 +1814,32 @@ int mana_gd_post_work_request(struct gdma_queue *wq, max_wqe_size =GDMA_MAX_RQE_SIZE ; }else {if (client_oob_size !=INLINE_OOB_SMALL_SIZE && - client_oob_size !=INLINE_OOB_LARGE_SIZE ) + client_oob_size !=INLINE_OOB_LARGE_SIZE && + client_oob_size !=INLINE_OOB_EXTRA_LARGE_SIZE )return -EINVAL ; max_wqe_size =GDMA_MAX_SQE_SIZE ; } sgl_data_size =sizeof (struct gdma_sge ) * wqe_req->num_sge; - wqe_size =ALIGN (sizeof (struct gdma_wqe ) + client_oob_size + - sgl_data_size,GDMA_WQE_BU_SIZE ); +if (wqe_req->wqe_size_in_bu) { + wqe_size = wqe_req->wqe_size_in_bu *GDMA_WQE_BU_SIZE ; + oob_len =ALIGN (sizeof (struct gdma_wqe ) + client_oob_size, +sizeof (struct gdma_sge )); +if (wqe_size < oob_len || + wqe_req->num_sge > (wqe_size - oob_len) /sizeof (struct gdma_sge )) +return -EINVAL ; + }else { + wqe_size =ALIGN (sizeof (struct gdma_wqe ) + client_oob_size + + sgl_data_size,GDMA_WQE_BU_SIZE ); + } +/* Ensure the WQE size is a power of 2 when a fixed wqe size or extra large OOB are used. +* Otherwise, the WQE may cross the queue memory buffer boundary, which is not allowed. +*/ +if (wqe_req->wqe_size_in_bu || client_oob_size ==INLINE_OOB_EXTRA_LARGE_SIZE ) { +if (!is_power_of_2 (wqe_size)) +return -EINVAL ; + }if (wqe_size > max_wqe_size)return -EINVAL ;
include/net/mana/gdma.h +16 -5
@@ -56,6 +56,11 @@ enum gdma_work_request_flags {GDMA_WR_OOB_IN_SGL =BIT (0 ),GDMA_WR_PAD_BY_SGE0 =BIT (1 ),GDMA_WR_IB_SGL =BIT (2 ), +GDMA_WR_CHECK_SN =BIT (3 ), +GDMA_WR_CHECK_RSN =BIT (4 ), +GDMA_WR_FENCE =BIT (5 ), +GDMA_WR_FENCE_EXTENDED =BIT (6 ), + GDMA_WR_GENERATION_1 = BIT(7), }; enum gdma_eqe_type {
@@ -219,8 +224,8 @@ struct gdma_wqe_request {struct ib_sge *ib_sgl; };u32 num_sge; - -u32 inline_oob_size; +u16 wqe_size_in_bu; +u16 inline_oob_size;const void *inline_oob_data;u32 flags;
@@ -538,7 +543,9 @@ void mana_gd_ring_dim(struct gdma_queue *cq, u32 mod_usec, bool mod_usec_vld, u32 mod_comps, bool mod_comps_vld);struct gdma_wqe { -u32 reserved :24 ; +u32 num_pad_sge :5 ; +u32 generation1 :1 ; +u32 reserved :18 ;u32 last_vbytes :8 ;union {
@@ -548,9 +555,13 @@ struct gdma_wqe { u32 num_sge :8; u32 inline_oob_size_div4:3; u32 client_oob_in_sgl :1; - u32 reserved1 :4; + u32 check_rsn :1; + u32 fence :1; + u32 fence_extended :1; + u32 reserved1 :1; u32 client_data_unit :14; - u32 reserved2 :2; + u32 check_sn :1; + u32 reserved2 :1; }; }; };/* HW DATA */
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH rdma-next v6 03/10] net/mana: Extend GDMA encoding for new RDMA WQEs
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
From: Konstantin Taranov <[email protected]>
Extend
mana_gd_post_work_request()to support extra-large OOB data and fixed-size WQEs. These formats are supported only for power-of-two WQE sizes.For fixed-size WQEs, use
num_pad_sgeto specify the padding size. Encode the WQE header fields required by RC QPs based on the WR flags.Signed-off-by Konstantin Taranov <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH v6 4/10 RDMA/mana_ib: Maintain kernel RC QP state
In reply to Konstantin TaranovFrom: Konstantin Taranov <[email protected]>
Update mana_ib_modify_qp_state() to support RC QPs. Initialize the packet, message, and frame counters for use by work requests.
Arm the requester receive queue at the initial PSN so that a CQE is generated when the specified PSN is acknowledged, indicating send completions.
---
v2:
- Preserve IB_QPT_UC handling in mana_ib_modify_qp().
drivers/infiniband/hw/mana/mana_ib.h | 5 +++++ drivers/infiniband/hw/mana/qp.c | 22 ++++++++++++++++++++-- include/net/mana/gdma.h | 2 ++ 3 files changed, 27 insertions(+), 2 deletions(-)
drivers/infiniband/hw/mana/mana_ib.h +5 -0
@@ -265,7 +265,12 @@ struct mana_ib_qp {/* The port on the IB device, starting with 1 */ u32 port;u32 sq_psn; +u32 sq_ssn; +u32 sq_fsn; +u16 sq_rsn; +bool pending_mmq_fence;bool sq_sig_all; +enum ib_mtu mtu;/* Serializes receive WR posting. */ spinlock_t rq_lock;
drivers/infiniband/hw/mana/qp.c +20 -2
@@ -779,8 +779,10 @@ static void mana_remove_qp_from_cqs(struct mana_ib_qp *qp, bool reset)spin_lock_irqsave (&send_cq->cq_lock, flags);list_del_init (&qp->send_err_node);/* Keep shadow reset serialized with hardware polling and SW flushing. */ -if (reset) +if (reset) {reset_shadow_queue (&qp->shadow_sq); +reset_shadow_queue (&qp->shadow_mmq); + }spin_unlock_irqrestore (&send_cq->cq_lock, flags);spin_lock_irqsave (&recv_cq->cq_lock, flags);
@@ -1071,11 +1073,16 @@ static int mana_ib_gd_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,static void mana_ib_modify_qp_state (struct ib_qp *ibqp,struct ib_qp_attr *attr,int attr_mask,struct ib_udata *udata) { + struct mana_ib_dev *mdev = container_of(ibqp->device, struct mana_ib_dev, ib_dev); struct mana_ib_qp *qp = container_of(ibqp, struct mana_ib_qp, ibqp); +struct gdma_queue *rq;if (udata)return ; +if (attr_mask &IB_QP_PATH_MTU ) + qp->mtu = attr->path_mtu; +if (attr_mask &IB_QP_STATE ) {switch (attr->qp_state) {case IB_QPS_RESET :
@@ -1086,8 +1093,19 @@ static void mana_ib_modify_qp_state(struct ib_qp *ibqp, struct ib_qp_attr *attr, } } -if (attr_mask &IB_QP_SQ_PSN ) +if (attr_mask &IB_QP_SQ_PSN ) { + qp->sq_ssn =1 ; + qp->sq_rsn =1 ; + qp->sq_fsn =1 ; qp->sq_psn = attr->sq_psn; + qp->pending_mmq_fence = false; + +if (qp->ibqp.qp_type ==IB_QPT_RC ) { + rq = qp->rc_qp.queues[MANA_RC_RECV_QUEUE_REQUESTER ].kmem; +mana_gd_wq_ring_doorbell_ext (mdev_to_gc (mdev), rq, attr->sq_psn, +SET_ARM_BIT ,MANA_PSN_CLIENT_OFFSET ); + } + } } int mana_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
include/net/mana/gdma.h +2 -0
@@ -605,6 +605,8 @@ struct gdma_cqe {#define GDMA_EQE_OWNER_BITS 3 +#define MANA_PSN_CLIENT_OFFSET 0x8 +union gdma_eqe_info {u32 as_uint32;
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH rdma-next v6 04/10] RDMA/mana_ib: Maintain kernel RC QP state
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
From: Konstantin Taranov <[email protected]>
Update
mana_ib_modify_qp_state()to support RC QPs. Initialize the packet, message, and frame counters for use by work requests.Arm the requester receive queue at the initial PSN so that a CQE is generated when the specified PSN is acknowledged, indicating send completions.
Signed-off-by Konstantin Taranov <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
PATCH v6 5/10 RDMA/mana_ib: Post receive WRs on kernel RC QPs
In reply to Konstantin TaranovFrom: Konstantin Taranov <[email protected]>
Implement receive request posting for RC QPs. When posting a batch of WRs, ring the doorbell periodically to prevent the u8 counter from overflowing.
--- drivers/infiniband/hw/mana/wr.c | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
drivers/infiniband/hw/mana/wr.c +37 -0
@@ -70,6 +70,41 @@ static int mana_ib_post_recv_ud(struct mana_ib_qp *qp, const struct ib_recv_wr *return err; } +static int mana_ib_post_recv_rc (struct mana_ib_qp *qp,const struct ib_recv_wr *wr, +const struct ib_recv_wr **bad_wr) +{ + struct mana_ib_dev *mdev = container_of(qp->ibqp.device, struct mana_ib_dev, ib_dev); +struct mana_ib_queue *ib_rq =mana_qp_get_rq (qp); +unsigned long flags; +u8 wqe_cnt =0 ; +int err =0 ; + +spin_lock_irqsave (&qp->rq_lock, flags); + +for (; wr; wr = wr->next) { + err =mana_ib_post_rq (qp, wr); +if (unlikely (err)) { + *bad_wr = wr; +break ; + } + wqe_cnt++; +if (wqe_cnt ==0xFF ) { +mana_gd_wq_ring_doorbell_ext (mdev_to_gc (mdev), ib_rq->kmem, + ib_rq->kmem->head *GDMA_WQE_BU_SIZE , + wqe_cnt,0 ); + wqe_cnt =0 ; + } + } + +if (wqe_cnt) +mana_gd_wq_ring_doorbell_ext (mdev_to_gc (mdev), ib_rq->kmem, + ib_rq->kmem->head *GDMA_WQE_BU_SIZE , + wqe_cnt,0 ); + +spin_unlock_irqrestore (&qp->rq_lock, flags); +return err; +} +int mana_ib_post_recv (struct ib_qp *ibqp,const struct ib_recv_wr *wr,const struct ib_recv_wr **bad_wr) {
@@ -79,6 +114,8 @@ int mana_ib_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr,case IB_QPT_UD :case IB_QPT_GSI :return mana_ib_post_recv_ud (qp, wr, bad_wr); +case IB_QPT_RC : +return mana_ib_post_recv_rc (qp, wr, bad_wr);default :/* Unsupported QP type */ *bad_wr = wr;
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH rdma-next v6 05/10] RDMA/mana_ib: Post receive WRs on kernel RC QPs
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
From: Konstantin Taranov <[email protected]>
Implement receive request posting for RC QPs. When posting a batch of WRs, ring the doorbell periodically to prevent the u8 counter from overflowing.
Signed-off-by Konstantin Taranov <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH v6 6/10 RDMA/mana_ib: Post send and memory-management WRs on RC QPs
In reply to Konstantin TaranovFrom: Konstantin Taranov <[email protected]>
Implement send work request posting for RC QPs. Post communication WRs to the send queue and memory WRs to the memory management queue.
Advertise the memory management extensions on adapters that support extended WQEs.
---
v5:
- Preserve fence flags on unsignaled WQEs.
- Check message length for WQEs to prevent overflows.
- Reject read WRs that use more sges than supported.
drivers/infiniband/hw/mana/main.c | 2 + drivers/infiniband/hw/mana/mana_ib.h | 1 + drivers/infiniband/hw/mana/wr.c | 355 +++++++++++++++++++++++++++ 3 files changed, 358 insertions(+)
drivers/infiniband/hw/mana/main.c +2 -0
@@ -632,6 +632,8 @@ int mana_ib_query_device(struct ib_device *ibdev, struct ib_device_attr *props, props->max_qp = dev->adapter_caps.max_qp_count; props->max_qp_wr = dev->adapter_caps.max_qp_wr; props->device_cap_flags =IB_DEVICE_RC_RNR_NAK_GEN ; +if (dev->adapter_caps.feature_flags &MANA_IB_FEATURE_EXTENDED_WQE_FORMAT ) + props->device_cap_flags |=IB_DEVICE_MEM_MGT_EXTENSIONS ; props->max_send_sge = dev->adapter_caps.max_send_sge_count; props->max_recv_sge = dev->adapter_caps.max_recv_sge_count; props->max_sge_rd = dev->adapter_caps.max_recv_sge_count;
drivers/infiniband/hw/mana/mana_ib.h +1 -0
@@ -325,6 +325,7 @@ enum mana_ib_adapter_features {MANA_IB_FEATURE_DEV_COUNTERS_SUPPORT =BIT (5 ),MANA_IB_FEATURE_MULTI_PORTS_SUPPORT =BIT (6 ),MANA_IB_FEATURE_MSN_IN_WQE_SUPPORT =BIT (7 ), +MANA_IB_FEATURE_FMR_IN_OOB_SUPPORT =BIT (8 ),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),
drivers/infiniband/hw/mana/wr.c +355 -0
373 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH rdma-next v6 06/10] RDMA/mana_ib: Post send and memory-management WRs on RC QPs
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
From: Konstantin Taranov <[email protected]>
Implement send work request posting for RC QPs. Post communication WRs to the send queue and memory WRs to the memory management queue.
Advertise the memory management extensions on adapters that support extended WQEs.
Signed-off-by Konstantin Taranov <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
PATCH v6 7/10 RDMA/mana_ib: Poll RC completions using PSN and FSN progress
In reply to Konstantin TaranovFrom: Konstantin Taranov <[email protected]>
Decode RC receive completions, armed-PSN notifications, and MMQ completions. Retire requester and MMQ shadow entries using their sequence numbers, honor cross-queue fence dependencies, and suppress successful WCs for unsignaled work requests.
On an ARMED completion, rearm the next signal PSN to generate the next send CQE.
---
v4:
- Assign wqe_size in shadow wqes for RC SEND/WRITE wrs
- Report a missed-event hint for a cached CQE for arming CQ v3:
- Mask arm_psn to 24 bits before ringing the requester doorbell.
drivers/infiniband/hw/mana/cq.c | 155 ++++++++++++++++++++-- drivers/infiniband/hw/mana/mana_ib.h | 31 +++++ drivers/infiniband/hw/mana/shadow_queue.h | 22 +++ drivers/infiniband/hw/mana/wr.c | 3 + 4 files changed, 200 insertions(+), 11 deletions(-)
drivers/infiniband/hw/mana/cq.c +144 -11
@@ -5,6 +5,12 @@#include "mana_ib.h" +#define PSN_SIGN_BIT 0x800000 +#define PSN_GE (PSN1 ,PSN2 ) ((((PSN1) - (PSN2)) & PSN_SIGN_BIT) == 0) +#define PSN_GT (PSN1 ,PSN2 ) PSN_GE(PSN1, (PSN2) + 1) +#define PSN_LE (PSN1 ,PSN2 ) PSN_GE(PSN2, PSN1) +#define PSN_LT (PSN1 ,PSN2 ) PSN_GT(PSN2, PSN1) +static enum ib_wc_status vendor_error_to_wc_error (uint32_t vendor_error) {switch (vendor_error) {
@@ -277,15 +283,18 @@ int mana_ib_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags) struct mana_ib_cq *cq = container_of(ibcq, struct mana_ib_cq, ibcq);struct gdma_queue *gdma_cq = cq->queue.kmem;unsigned long irq_flags; +bool missed = false;if (!gdma_cq)return -EINVAL ;spin_lock_irqsave (&cq->cq_lock, irq_flags);mana_ib_cq_doorbell (cq,SET_ARM_BIT ); +if (flags &IB_CQ_REPORT_MISSED_EVENTS ) + missed = cq->has_pending_cqe;spin_unlock_irqrestore (&cq->cq_lock, irq_flags); -return 0 ; +return missed; }struct mana_cq_poll {
@@ -311,10 +320,10 @@ static struct ib_wc *mana_fill_wc(struct mana_ib_qp *qp,return wc; } -static void mana_complete_send (struct mana_ib_qp *qp, +static void mana_complete_send (struct mana_ib_qp *qp,bool mmq,struct mana_cq_poll *poll,u32 vendor_error) { -struct shadow_queue *shadow = &qp->shadow_sq; +struct shadow_queue *shadow = mmq ? &qp->shadow_mmq : &qp->shadow_sq;struct shadow_wqe_header *wqe =shadow_queue_get_next_to_consume (shadow);struct gdma_queue *queue;
@@ -324,8 +333,19 @@ static void mana_complete_send(struct mana_ib_qp *qp,if (vendor_error || !(wqe->flags &MANA_WQ_NO_SIGNAL_WC ))mana_fill_wc (qp, poll, wqe, wqe->send_opcode, vendor_error); - queue =mana_qp_get_sq (qp)->kmem; - queue->tail += wqe->wqe_size_in_bu; +if (mmq) { + queue = qp->rc_qp.queues[MANA_RC_SEND_QUEUE_MMQ ].kmem; + queue->tail += wqe->wqe_size_in_bu; + }else { + queue =mana_qp_get_sq (qp)->kmem; +if (wqe->send_opcode ==IB_WC_RDMA_READ ) { + qp->rc_qp.queues[MANA_RC_RECV_QUEUE_REQUESTER ].kmem->tail += + wqe->wqe_size_in_bu; + queue->tail += qp->rc_qp.wqe_size_in_bu; + }else { + queue->tail += wqe->wqe_size_in_bu; + } + }shadow_queue_advance_consumer (shadow); }
@@ -354,7 +374,7 @@ static void handle_ud_sq_cqe(struct mana_ib_qp *qp, struct mana_rdma_cqe *rdma_creturn ;for (; to_complete; to_complete--) -mana_complete_send (qp, poll,VENDOR_ERR_OK ); +mana_complete_send (qp, false, poll,VENDOR_ERR_OK ); } static void handle_rq_cqe(struct mana_ib_qp *qp, struct gdma_comp *cqe,
@@ -382,6 +402,21 @@ static void handle_rq_cqe(struct mana_ib_qp *qp, struct gdma_comp *cqe, wc->src_qp = rdma_cqe->ud_recv.src_qpn; wc->wc_flags |=IB_WC_GRH ;break ; +case CQE_TYPE_RC_WRITE_IMM : + wc->opcode =IB_WC_RECV_RDMA_WITH_IMM ; + fallthrough; +case CQE_TYPE_RC_SEND_IMM : + wc->wc_flags |=IB_WC_WITH_IMM ; + wc->ex.imm_data =cpu_to_be32 (rdma_cqe->rc_recv.imm_data); + fallthrough; +case CQE_TYPE_RC_SEND : + wc->byte_len = rdma_cqe->rc_recv.msg_len; +break ; +case CQE_TYPE_RC_SEND_INV : + wc->wc_flags |=IB_WC_WITH_INVALIDATE ; + wc->byte_len = rdma_cqe->rc_recv.msg_len; + wc->ex.invalidate_rkey = rdma_cqe->rc_recv.imm_data; +break ;default :break ; }
@@ -390,17 +425,105 @@ static void handle_rq_cqe(struct mana_ib_qp *qp, struct gdma_comp *cqe,shadow_queue_advance_consumer (&qp->shadow_rq); } +/* +* A fenced WQE can acknowledge the other send queue. Retire those dependencies +* first, without losing the fence when the caller's WC array fills up. +*/ +static bool mana_advance_send (struct mana_ib_qp *qp,bool mmq,u32 seq, +struct mana_cq_poll *poll) +{ +struct shadow_queue *shadow = mmq ? &qp->shadow_mmq : &qp->shadow_sq; +struct shadow_queue *other = mmq ? &qp->shadow_sq : &qp->shadow_mmq; +struct shadow_wqe_header *shadow_wqe; + +while ((shadow_wqe =shadow_queue_get_next_to_consume (shadow))) { +if (PSN_LT (seq, mmq ? shadow_wqe->fsn : shadow_wqe->wqe_offset_or_psn)) +break ; +if (poll->produced == poll->budget) +return false; +if (shadow_wqe->flags &MANA_WQ_FENCE_WC ) { +u32 dependency = mmq ? shadow_wqe->wqe_offset_or_psn : shadow_wqe->fsn; +struct shadow_wqe_header *other_wqe; + +while ((other_wqe =shadow_queue_get_next_to_consume (other))) { +if (PSN_LT (dependency, mmq ? other_wqe->wqe_offset_or_psn : + other_wqe->fsn)) +break ; +mana_complete_send (qp, !mmq, poll,VENDOR_ERR_OK ); +if (poll->produced == poll->budget) +return false; + } + } + +mana_complete_send (qp, mmq, poll,VENDOR_ERR_OK ); + } + +return true; +} + +static bool handle_mmq_cqe (struct mana_ib_qp *qp,u32 fsn, +struct mana_cq_poll *poll) +{ +return mana_advance_send (qp, true, fsn, poll); +} + +static bool handle_psn_cqe (struct mana_ib_qp *qp,u32 psn, +struct mana_cq_poll *poll) +{ + struct mana_ib_dev *mdev = container_of(qp->ibqp.device, struct mana_ib_dev, ib_dev); +struct shadow_wqe_header *shadow_wqe; +struct gdma_queue *recv_q; +bool consumed; +u32 arm_psn; + +if (qp->ibqp.qp_type !=IB_QPT_RC ) +return true; + + recv_q = qp->rc_qp.queues[MANA_RC_RECV_QUEUE_REQUESTER ].kmem; + + consumed =mana_advance_send (qp, false, psn, poll); +if (consumed) { + shadow_wqe =shadow_queue_get_next_to_signal (&qp->shadow_sq); + arm_psn = shadow_wqe ? shadow_wqe->wqe_offset_or_psn : psn +1 ; + arm_psn &=MANA_WQE_OFFSET_MASK ; +mana_gd_wq_ring_doorbell_ext (mdev_to_gc (mdev), recv_q, arm_psn, +SET_ARM_BIT ,MANA_PSN_CLIENT_OFFSET ); + } + +return consumed; +} + +static bool next_shadow_wqe_is_sq (struct shadow_wqe_header *shadow_wqe_sq, +struct shadow_wqe_header *shadow_wqe_mq) +{ +if (!shadow_wqe_mq) +return true; + +if (!shadow_wqe_sq) +return false; + +return (PSN_LE (shadow_wqe_sq->wqe_offset_or_psn, shadow_wqe_mq->wqe_offset_or_psn) && +PSN_LE (shadow_wqe_sq->fsn, shadow_wqe_mq->fsn)); +} +static bool mana_handle_cqe (struct mana_ib_cq *cq,struct mana_ib_dev *mdev,struct mana_cq_poll *poll) {struct gdma_comp *cqe = &cq->pending_cqe;struct mana_rdma_cqe *rdma_cqe = (struct mana_rdma_cqe *)cqe->cqe_data;struct mana_ib_qp *qp =mana_get_qp_ref (mdev, cqe->wq_num, cqe->is_sq); +bool consumed = true;if (!qp)return true;switch (rdma_cqe->cqe_type) { +case CQE_TYPE_ARMED_CMPL : + consumed =handle_psn_cqe (qp, rdma_cqe->rc_armed_completion.psn, poll); +break ; +case CQE_TYPE_LWR : + consumed =handle_mmq_cqe (qp, rdma_cqe->rc_mm.fsn, poll); +break ;case CQE_TYPE_UD_SEND :if (cqe->is_sq) {handle_ud_sq_cqe (qp, rdma_cqe, poll);
@@ -408,6 +531,10 @@ static bool mana_handle_cqe(struct mana_ib_cq *cq, struct mana_ib_dev *mdev, } fallthrough;case CQE_TYPE_UD_SEND_IMM : +case CQE_TYPE_RC_SEND : +case CQE_TYPE_RC_SEND_IMM : +case CQE_TYPE_RC_SEND_INV : +case CQE_TYPE_RC_WRITE_IMM :handle_rq_cqe (qp, cqe, poll);break ;default :
@@ -416,21 +543,27 @@ static bool mana_handle_cqe(struct mana_ib_cq *cq, struct mana_ib_dev *mdev,break ; }mana_put_qp_ref (qp); -return true; +return consumed; }static void mana_flush_completions (struct mana_ib_cq *cq,struct mana_cq_poll *poll) { -struct shadow_wqe_header *wqe; +struct shadow_wqe_header *sq_wqe, *mmq_wqe, *wqe;struct mana_ib_qp *qp; +bool next_is_sq;if (poll->produced >= poll->budget)return ;list_for_each_entry (qp, &cq->send_err_qp_list, send_err_node) { -while (poll->produced < poll->budget && -shadow_queue_get_next_to_consume (&qp->shadow_sq)) -mana_complete_send (qp, poll,VENDOR_ERR_SW_FLUSHED ); +while (poll->produced < poll->budget) { + sq_wqe =shadow_queue_get_next_to_consume (&qp->shadow_sq); + mmq_wqe =shadow_queue_get_next_to_consume (&qp->shadow_mmq); +if (!sq_wqe && !mmq_wqe) +break ; + next_is_sq =next_shadow_wqe_is_sq (sq_wqe, mmq_wqe); +mana_complete_send (qp, !next_is_sq, poll,VENDOR_ERR_SW_FLUSHED ); + }if (poll->produced == poll->budget)return ; }
drivers/infiniband/hw/mana/mana_ib.h +31 -0
@@ -689,6 +689,12 @@ enum mana_ib_error_code {enum mana_ib_cqe_type {CQE_TYPE_UD_SEND =1 ,CQE_TYPE_UD_SEND_IMM =2 , +CQE_TYPE_RC_SEND =3 , +CQE_TYPE_RC_SEND_IMM =4 , +CQE_TYPE_RC_SEND_INV =5 , +CQE_TYPE_RC_WRITE_IMM =6 , +CQE_TYPE_ARMED_CMPL =7 , +CQE_TYPE_LWR =8 , };/* HW DATA */ struct mana_rdma_cqe {
@@ -712,6 +718,31 @@ struct mana_rdma_cqe {u32 imm_data;u32 rx_wqe_offset; } ud_recv; +struct { +u32 cqe_type :8 ; +u32 reserved1 :24 ; +u32 msg_len; +u32 psn :24 ; +u32 reserved2 :8 ; +u32 imm_data; +u32 rx_wqe_offset; + } rc_recv; +struct { +u32 cqe_type :8 ; +u32 reserved1 :24 ; +u32 msn :24 ; +u32 syndrome :8 ; +u32 psn :24 ; +u32 reserved2 :8 ; + } rc_armed_completion; +struct { +u32 cqe_type :8 ; +u32 reserved1 :24 ; +u32 psn :24 ; +u32 reserved2 :8 ; +u32 fsn :24 ; +u32 reserved3 :8 ; + } rc_mm; }; };/* HW DATA */
drivers/infiniband/hw/mana/shadow_queue.h +22 -0
@@ -26,6 +26,8 @@ struct shadow_queue {u64 prod_idx;/* Unmasked consumer index, Incremented on cq polling */ u64 cons_idx; +/* Unmasked index of next-to-signal shadow WQE */ +u64 next_to_signal_idx;/* queue size in wqes */ u32 length;/* distance between elements in bytes */
@@ -50,6 +52,7 @@ static inline void reset_shadow_queue(struct shadow_queue *queue) { queue->prod_idx =0 ; queue->cons_idx =0 ; + queue->next_to_signal_idx =0 ; }static inline void destroy_shadow_queue (struct shadow_queue *queue)
@@ -105,4 +108,23 @@ static inline void shadow_queue_advance_consumer(struct shadow_queue *queue) smp_store_release(&queue->cons_idx, queue->cons_idx + 1); } +static inline struct shadow_wqe_header * +shadow_queue_get_next_to_signal (struct shadow_queue *queue) +{ +struct shadow_wqe_header *wqe =NULL ; +/* Inspect only entries that have been fully published by posting. */ +u64 prod_idx =smp_load_acquire (&queue->prod_idx); + + queue->next_to_signal_idx =max (queue->next_to_signal_idx, + queue->cons_idx); +while (queue->next_to_signal_idx < prod_idx) { + wqe =shadow_queue_get_element (queue, queue->next_to_signal_idx); + queue->next_to_signal_idx++; +if (!(wqe->flags &MANA_WQ_NO_SIGNAL_WC )) +return wqe; + } + +return NULL ; +} +#endif
drivers/infiniband/hw/mana/wr.c +3 -0
@@ -415,6 +415,9 @@ static int mana_ib_post_sq(struct mana_ib_qp *qp, const struct ib_send_wr *wr)if (err)return err; +if (wr->opcode !=IB_WR_RDMA_READ ) + shadow_wqe->wqe_size_in_bu = wqe_info.wqe_size_in_bu; + shadow_wqe->wr_id = wr->wr_id; shadow_wqe->send_opcode =convert_wr_to_wc (wr->opcode);if (!signaled)
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH rdma-next v6 07/10] RDMA/mana_ib: Poll RC completions using PSN and FSN progress
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
From: Konstantin Taranov <[email protected]>
Decode RC receive completions, armed-PSN notifications, and MMQ completions. Retire requester and MMQ shadow entries using their sequence numbers, honor cross-queue fence dependencies, and suppress successful WCs for unsignaled work requests.
On an ARMED completion, rearm the next signal PSN to generate the next send CQE.
Signed-off-by Konstantin Taranov <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
PATCH v6 8/10 RDMA/mana_ib: Flush and notify CQs when kernel QPs enter ERR
In reply to Konstantin TaranovFrom: Konstantin Taranov <[email protected]>
Complete the RC software flush path by adding a kernel QP to the CQ error lists when it transitions to the ERR state.
Invoke the CQ handlers after the transition to flush pending work requests.
---
v6:
- Notify after posting to error-listed QPs adn reuse new helper for GSI.
- Report pending flush WCs (mana_ib_cq_has_flush_work) for IB_CQ_REPORT_MISSED_EVENTS v5:
- Remove the unused QP state field.
v3:
- Skip kernel state update handling for userspace QPs.
- Warn and refuse to add userspace QPs to the CQ error lists.
- Add mana_remove_qp_from_cqs() for UC
v2:
- Skip software CQ notifications for IB_POLL_DIRECT.
drivers/infiniband/hw/mana/cq.c | 27 +++++++++++++++-- drivers/infiniband/hw/mana/qp.c | 53 ++++++++++++++++++++++++++++++--- drivers/infiniband/hw/mana/wr.c | 42 +++++++++++++++++++------- 3 files changed, 105 insertions(+), 17 deletions(-)
drivers/infiniband/hw/mana/cq.c +25 -2
@@ -278,6 +278,25 @@ static inline void mana_ib_cq_doorbell(struct mana_ib_cq *cq, uint8_t arm)mana_gd_wq_ring_doorbell_ext (mdev_to_gc (mdev), gdma_cq, idx, arm,0 ); } +static bool mana_ib_cq_has_flush_work (struct mana_ib_cq *cq) +{ +struct mana_ib_qp *qp; + +list_for_each_entry (qp, &cq->send_err_qp_list, send_err_node) { +if (!shadow_queue_empty (&qp->shadow_sq)) +return true; +if (!shadow_queue_empty (&qp->shadow_mmq)) +return true; + } + +list_for_each_entry (qp, &cq->recv_err_qp_list, recv_err_node) { +if (!shadow_queue_empty (&qp->shadow_rq)) +return true; + } + +return false; +} +int mana_ib_arm_cq (struct ib_cq *ibcq,enum ib_cq_notify_flags flags) { struct mana_ib_cq *cq = container_of(ibcq, struct mana_ib_cq, ibcq);
@@ -290,8 +309,12 @@ int mana_ib_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags)spin_lock_irqsave (&cq->cq_lock, irq_flags);mana_ib_cq_doorbell (cq,SET_ARM_BIT ); -if (flags &IB_CQ_REPORT_MISSED_EVENTS ) +if (flags &IB_CQ_REPORT_MISSED_EVENTS ) { missed = cq->has_pending_cqe; +/* Software flushes cannot retrigger the hardware CQ notification. */ +if (!missed) + missed =mana_ib_cq_has_flush_work (cq); + }spin_unlock_irqrestore (&cq->cq_lock, irq_flags);return missed;
@@ -589,7 +612,7 @@ static void mana_drain_gsi_sq(struct mana_ib_qp *qp)list_add_tail (&qp->send_err_node, &cq->send_err_qp_list);spin_unlock_irqrestore (&cq->cq_lock, flags); -if (cq->ibcq.comp_handler) +if (cq->ibcq.poll_ctx !=IB_POLL_DIRECT && cq->ibcq.comp_handler) cq->ibcq.comp_handler (&cq->ibcq, cq->ibcq.cq_context); }
drivers/infiniband/hw/mana/qp.c +49 -4
105 lines not on this page · raw message
drivers/infiniband/hw/mana/wr.c +31 -11
93 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH rdma-next v6 08/10] RDMA/mana_ib: Flush and notify CQs when kernel QPs enter ERR
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
From: Konstantin Taranov <[email protected]>
Complete the RC software flush path by adding a kernel QP to the CQ error lists when it transitions to the ERR state.
Invoke the CQ handlers after the transition to flush pending work requests.
Signed-off-by Konstantin Taranov <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
PATCH v6 9/10 RDMA/mana_ib: Handle error CQEs for RC QPs
In reply to Konstantin TaranovFrom: Konstantin Taranov <[email protected]>
Decode hardware error CQEs and process them on the corresponding work queue. Complete the failing shadow entry with the vendor status from the CQE.
Defer transitioning RC QPs to the ERR state so that the other work queues can be flushed.
Clear pending CQEs for a kernel QP after a hardware RESET by setting their QIDs to zero. Discard CQEs with a zero QID.
Mark deferred errors as pending when scheduling work to prevent stale work from moving a reset and reused QP to ERR.
---
v6:
- Check fenced WQEs on error cqes to prevent flushing completed WQEs.
- Add mana_ib_cq_clean on QP reset to discard stale CQEs. QID 0 is an invalid value for RNIC and safe dor discarding.
- Add error_pending flag to prevent deffered ERR request to error reset QPs.
- Update commit message
v2:
- Flush error_work after draining QP references during teardown.
drivers/infiniband/hw/mana/cq.c | 202 ++++++++++++++++++++++++--- drivers/infiniband/hw/mana/mana_ib.h | 44 +++++- drivers/infiniband/hw/mana/qp.c | 43 +++++- 3 files changed, 262 insertions(+), 27 deletions(-)
drivers/infiniband/hw/mana/cq.c +180 -22
@@ -5,6 +5,8 @@#include "mana_ib.h" +#define MANA_CQE_INVALID_QID 0 +#define PSN_SIGN_BIT 0x800000#define PSN_GE (PSN1 ,PSN2 ) ((((PSN1) - (PSN2)) & PSN_SIGN_BIT) == 0)#define PSN_GT (PSN1 ,PSN2 ) PSN_GE(PSN1, (PSN2) + 1)
@@ -18,6 +20,7 @@ static enum ib_wc_status vendor_error_to_wc_error(uint32_t vendor_error)return IB_WC_SUCCESS ;case VENDOR_ERR_RX_PKT_LEN :case VENDOR_ERR_RX_MSG_LEN_OVFL : +case VENDOR_ERR_RX_READRESP_LEN_MISMATCH :return IB_WC_LOC_LEN_ERR ;case VENDOR_ERR_TX_GDMA_CORRUPTED_WQE :case VENDOR_ERR_TX_PCIE_WQE :
@@ -37,12 +40,30 @@ static enum ib_wc_status vendor_error_to_wc_error(uint32_t vendor_error)case VENDOR_ERR_TX_ATB_WQE_ACCESS_VIOLATION :case VENDOR_ERR_TX_ATB_WQE_ADDR_RANGE :case VENDOR_ERR_TX_ATB_WQE_CONFIG_ERR : +case VENDOR_ERR_TX_RDMA_ATB_CMD_MISS : +case VENDOR_ERR_TX_RDMA_ATB_CMD_IDX_ERROR : +case VENDOR_ERR_TX_RDMA_ATB_CMD_TAG_MISMATCH_ERROR : +case VENDOR_ERR_TX_RDMA_ATB_CMD_PDID_MISMATCH_ERROR : +case VENDOR_ERR_TX_RDMA_ATB_CMD_AR_ERROR : +case VENDOR_ERR_TX_RDMA_ATB_CMD_PT_OVF : +case VENDOR_ERR_TX_RDMA_ATB_CMD_PT_LENGHT_MISMATCH : +case VENDOR_ERR_TX_RDMA_ATB_CMD_ILLEGAL_CMD :case VENDOR_ERR_RX_ATB_SGE_ADDR_RANGE :case VENDOR_ERR_RX_ATB_SGE_MISSCONFIG :return IB_WC_LOC_PROT_ERR ;case VENDOR_ERR_RX_ATB_SGE_ADDR_RIGHT :case VENDOR_ERR_RX_GFID :return IB_WC_LOC_ACCESS_ERR ; +case VENDOR_ERR_RX_OP_REQ : +return IB_WC_REM_INV_REQ_ERR ; +case VENDOR_ERR_RX_ATB_RKEY_MISCONFIG_ERR : +case VENDOR_ERR_RX_ATB_RKEY_ADDR_RIGHT : +case VENDOR_ERR_RX_ATB_RKEY_ADDR_RANGE : +case VENDOR_ERR_RX_REMOTE_ACCESS_NAK : +return IB_WC_REM_ACCESS_ERR ; +case VENDOR_ERR_RX_INVALID_REQ_NAK : +case VENDOR_ERR_RX_REMOTE_OP_ERR_NAK : +return IB_WC_REM_OP_ERR ;case VENDOR_ERR_RX_MISBEHAVING_CLIENT :case VENDOR_ERR_RX_CLIENT_ID :case VENDOR_ERR_RX_PCIE :
@@ -58,6 +79,10 @@ static enum ib_wc_status vendor_error_to_wc_error(uint32_t vendor_error)case VENDOR_ERR_RX_NOT_EMPTY_ON_DISABLE :case VENDOR_ERR_SW_FLUSHED :return IB_WC_WR_FLUSH_ERR ; +case VENDOR_ERR_TX_RETRY_LIMIT_EXCEEDED : +return IB_WC_RETRY_EXC_ERR ; +case VENDOR_ERR_RX_RNR_NAK : +return IB_WC_RNR_RETRY_EXC_ERR ;default :return IB_WC_GENERAL_ERR ; }
@@ -235,19 +260,24 @@ void mana_ib_remove_cq_cb(struct mana_ib_dev *mdev, struct mana_ib_cq *cq) gc->cq_table[cq->queue.id] =NULL ; } -static inline bool gdma_cq_idx_produced (struct gdma_queue *gdma_cq,uint32_t idx) +static struct gdma_cqe *mana_ib_get_cqe (struct gdma_queue *gdma_cq,u32 idx) {struct gdma_mem_info *gmi = &gdma_cq->mem_info;u32 num_cqe = gdma_cq->queue_size /GDMA_CQE_SIZE ; -u32 expected_bits = (idx / num_cqe) &GDMA_CQE_OWNER_MASK ;u32 offset = (idx % num_cqe) *GDMA_CQE_SIZE ; -struct gdma_cqe *cqe;if (gmi->nr_pages) - cqe = gmi->pages_va[offset /PAGE_SIZE ] + - (offset & (PAGE_SIZE -1 )); -else - cqe = gdma_cq->queue_mem_ptr + offset; +return gmi->pages_va[offset /PAGE_SIZE ] + + (offset & (PAGE_SIZE -1 )); + +return gdma_cq->queue_mem_ptr + offset; +} + +static inline bool gdma_cq_idx_produced (struct gdma_queue *gdma_cq,uint32_t idx) +{ +u32 num_cqe = gdma_cq->queue_size /GDMA_CQE_SIZE ; +u32 expected_bits = (idx / num_cqe) &GDMA_CQE_OWNER_MASK ; +struct gdma_cqe *cqe =mana_ib_get_cqe (gdma_cq, idx);return cqe->cqe_info.owner_bits == expected_bits; }
@@ -278,6 +308,43 @@ static inline void mana_ib_cq_doorbell(struct mana_ib_cq *cq, uint8_t arm)mana_gd_wq_ring_doorbell_ext (mdev_to_gc (mdev), gdma_cq, idx, arm,0 ); } +static bool mana_ib_cqe_matches_qp (struct mana_ib_qp *qp,u32 wq_num,bool is_sq) +{ +struct mana_ib_queue *wq = is_sq ?mana_qp_get_sq (qp) :mana_qp_get_rq (qp); + +return (wq_num & ~MANA_QID_SUBTYPE_MASK ) == (wq->id & ~MANA_QID_SUBTYPE_MASK ); +} + +void mana_ib_cq_clean (struct mana_ib_cq *cq,struct mana_ib_qp *qp) +{ +struct gdma_queue *gdma_cq = cq->queue.kmem; +struct gdma_cqe *cqe; +u32 num_cqe, idx, i; + +lockdep_assert_held (&cq->cq_lock); + +if (!gdma_cq) +return ; + +if (cq->has_pending_cqe && +mana_ib_cqe_matches_qp (qp, cq->pending_cqe.wq_num, cq->pending_cqe.is_sq)) + cq->has_pending_cqe = false; + +/* Hardware RESET has completed, so this QP cannot produce new CQEs. */ + num_cqe = gdma_cq->queue_size /GDMA_CQE_SIZE ; +for (i =0 ; i < num_cqe; i++) { + idx = gdma_cq->head + i; +if (!gdma_cq_idx_produced (gdma_cq, idx)) +break ; + +/* Read CQE contents only after observing their owner bits. */ +rmb (); + cqe =mana_ib_get_cqe (gdma_cq, idx); +if (mana_ib_cqe_matches_qp (qp, cqe->cqe_info.wq_num, cqe->cqe_info.is_sq)) + cqe->cqe_info.wq_num =MANA_CQE_INVALID_QID ; + } +} +static bool mana_ib_cq_has_flush_work (struct mana_ib_cq *cq) {struct mana_ib_qp *qp;
@@ -452,11 +519,33 @@ static void handle_rq_cqe(struct mana_ib_qp *qp, struct gdma_comp *cqe,* A fenced WQE can acknowledge the other send queue. Retire those dependencies * first, without losing the fence when the caller's WC array fills up. */ +static bool mana_complete_send_dependencies (struct mana_ib_qp *qp,bool mmq, +const struct shadow_wqe_header *wqe, +struct mana_cq_poll *poll) +{ +struct shadow_queue *other = mmq ? &qp->shadow_sq : &qp->shadow_mmq; +u32 dependency = mmq ? wqe->wqe_offset_or_psn : wqe->fsn; +struct shadow_wqe_header *other_wqe; + +if (!(wqe->flags &MANA_WQ_FENCE_WC )) +return true; + +while ((other_wqe =shadow_queue_get_next_to_consume (other))) { +if (PSN_LT (dependency, mmq ? other_wqe->wqe_offset_or_psn : + other_wqe->fsn)) +break ; +if (poll->produced == poll->budget) +return false; +mana_complete_send (qp, !mmq, poll,VENDOR_ERR_OK ); + } + +return poll->produced < poll->budget; +} +static bool mana_advance_send (struct mana_ib_qp *qp,bool mmq,u32 seq,struct mana_cq_poll *poll) {struct shadow_queue *shadow = mmq ? &qp->shadow_mmq : &qp->shadow_sq; -struct shadow_queue *other = mmq ? &qp->shadow_sq : &qp->shadow_mmq;struct shadow_wqe_header *shadow_wqe;while ((shadow_wqe =shadow_queue_get_next_to_consume (shadow))) {
@@ -464,19 +553,8 @@ static bool mana_advance_send(struct mana_ib_qp *qp, bool mmq, u32 seq,break ;if (poll->produced == poll->budget)return false; -if (shadow_wqe->flags &MANA_WQ_FENCE_WC ) { -u32 dependency = mmq ? shadow_wqe->wqe_offset_or_psn : shadow_wqe->fsn; -struct shadow_wqe_header *other_wqe; - -while ((other_wqe =shadow_queue_get_next_to_consume (other))) { -if (PSN_LT (dependency, mmq ? other_wqe->wqe_offset_or_psn : - other_wqe->fsn)) -break ; -mana_complete_send (qp, !mmq, poll,VENDOR_ERR_OK ); -if (poll->produced == poll->budget) -return false; - } - } +if (!mana_complete_send_dependencies (qp, mmq, shadow_wqe, poll)) +return false;mana_complete_send (qp, mmq, poll,VENDOR_ERR_OK ); }
@@ -516,6 +594,79 @@ static bool handle_psn_cqe(struct mana_ib_qp *qp, u32 psn,return consumed; } +static bool mana_cqe_is_send (struct mana_ib_qp *qp,struct gdma_comp *cqe) +{ +u32 qtype = cqe->wq_num &MANA_QID_SUBTYPE_MASK ; + +if (qp->ibqp.qp_type !=IB_QPT_RC ) +return cqe->is_sq; + +return cqe->is_sq ? (qtype ==MANA_QID_SUBTYPE_SREQ || + qtype ==MANA_QID_SUBTYPE_MMQ ) : + qtype ==MANA_QID_SUBTYPE_RREQ ; +} + +static void mana_ib_schedule_qp_error (struct mana_ib_qp *qp) +{ +/* CQ polling cannot sleep; teardown drains this reference before freeing. */ +atomic_set (&qp->error_pending,1 ); +refcount_inc (&qp->refcount); +if (!schedule_work (&qp->error_work)) +mana_put_qp_ref (qp); +} + +static bool handle_error_cqe (struct mana_ib_cq *cq,struct mana_ib_qp *qp, +struct gdma_comp *cqe,struct mana_cq_poll *poll) +{ +bool mmq = cqe->is_sq && (cqe->wq_num &MANA_QID_SUBTYPE_MASK ) ==MANA_QID_SUBTYPE_MMQ ; +struct mana_rdma_cqe *rdma_cqe = (struct mana_rdma_cqe *)cqe->cqe_data; +bool send =mana_cqe_is_send (qp, cqe); +u32 vendor_err = rdma_cqe->error.vendor_error; +struct shadow_wqe_header *shadow_wqe; +struct shadow_queue *shadow_q; + +if (send && qp->ibqp.qp_type ==IB_QPT_RC ) { +/* The error PSN/FSN belongs to the failing WQE, not a success. */ +if (!mana_advance_send (qp, mmq, rdma_cqe->error.psn -1 , poll)) +return false; +if (poll->produced == poll->budget) +return false; + } + +if (!send) + shadow_q = &qp->shadow_rq; +else if (mmq) + shadow_q = &qp->shadow_mmq; +else + shadow_q = &qp->shadow_sq; + + shadow_wqe =shadow_queue_get_next_to_consume (shadow_q); +if (shadow_wqe) { +if (send) { +if (!mana_complete_send_dependencies (qp, mmq, shadow_wqe, poll)) +return false; + +mana_complete_send (qp, mmq, poll, vendor_err); + }else { +mana_fill_wc (qp, poll, shadow_wqe,IB_WC_RECV , vendor_err); +shadow_queue_advance_consumer (shadow_q); + } + } + +/* Hardware has stopped DMA for the queues flushed below. */ +if (send) { +if (list_empty (&qp->send_err_node)) +list_add_tail (&qp->send_err_node, &cq->send_err_qp_list); + }else { +if (list_empty (&qp->recv_err_node)) +list_add_tail (&qp->recv_err_node, &cq->recv_err_qp_list); + } +if (qp->ibqp.qp_type !=IB_QPT_GSI ) +mana_ib_schedule_qp_error (qp); + +return true; +} +static bool next_shadow_wqe_is_sq (struct shadow_wqe_header *shadow_wqe_sq,struct shadow_wqe_header *shadow_wqe_mq) {
@@ -534,9 +685,13 @@ static bool mana_handle_cqe(struct mana_ib_cq *cq, struct mana_ib_dev *mdev, {struct gdma_comp *cqe = &cq->pending_cqe;struct mana_rdma_cqe *rdma_cqe = (struct mana_rdma_cqe *)cqe->cqe_data; -struct mana_ib_qp *qp =mana_get_qp_ref (mdev, cqe->wq_num, cqe->is_sq); +struct mana_ib_qp *qp;bool consumed = true; +if (cqe->wq_num ==MANA_CQE_INVALID_QID ) +return true; + + qp =mana_get_qp_ref (mdev, cqe->wq_num, cqe->is_sq);if (!qp)return true;
@@ -547,6 +702,9 @@ static bool mana_handle_cqe(struct mana_ib_cq *cq, struct mana_ib_dev *mdev,case CQE_TYPE_LWR : consumed =handle_mmq_cqe (qp, rdma_cqe->rc_mm.fsn, poll);break ; +case CQE_TYPE_ERROR : + consumed =handle_error_cqe (cq, qp, cqe, poll); +break ;case CQE_TYPE_UD_SEND :if (cqe->is_sq) {handle_ud_sq_cqe (qp, rdma_cqe, poll);
drivers/infiniband/hw/mana/mana_ib.h +43 -1
108 lines not on this page · raw message
drivers/infiniband/hw/mana/qp.c +39 -4
98 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH rdma-next v6 09/10] RDMA/mana_ib: Handle error CQEs for RC QPs
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] RDMA/mana_ib: handle_error_cqe() leaves active GSI QPs on CQ error lists --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] RDMA/mana_ib: handle_error_cqe() leaves active GSI QPs on CQ error lists --
commit 1bb70d4df95cbf22f7fdb1b2cc6c47bc5b5ed6d5
Author: Konstantin Taranov <[email protected]>
RDMA/mana_ib: Handle error CQEs for RC QPs
This commit adds handling for hardware error CQEs on RC QPs, deferring the transition to the ERR state via a workqueue so that other work queues can be flushed. It also cleans pending CQEs upon QP reset and tracks deferred error state to avoid transitioning reset and reused QPs to ERR.
Quoted 4 lines
drivers/infiniband/hw/mana/cq.c +0
-0
[ ... ]
Quoted 4 lines
drivers/infiniband/hw/mana/cq.c +0
-0@@ -516,6 +594,79 @@ static bool handle_psn_cqe(struct mana_ib_qp *qp, u32 psn,return consumed; }
[ ... ]
Quoted 38 lines
drivers/infiniband/hw/mana/cq.c +38
-0+static bool handle_error_cqe (struct mana_ib_cq *cq,struct mana_ib_qp *qp, +struct gdma_comp *cqe,struct mana_cq_poll *poll) +{ +bool mmq = cqe->is_sq && (cqe->wq_num &MANA_QID_SUBTYPE_MASK ) ==MANA_QID_SUBTYPE_MMQ ; +struct mana_rdma_cqe *rdma_cqe = (struct mana_rdma_cqe *)cqe->cqe_data; +bool send =mana_cqe_is_send (qp, cqe); +u32 vendor_err = rdma_cqe->error.vendor_error; +struct shadow_wqe_header *shadow_wqe; +struct shadow_queue *shadow_q; + +if (send && qp->ibqp.qp_type ==IB_QPT_RC ) { +/* The error PSN/FSN belongs to the failing WQE, not a success. */ +if (!mana_advance_send (qp, mmq, rdma_cqe->error.psn -1 , poll)) +return false; +if (poll->produced == poll->budget) +return false; + } + +if (!send) + shadow_q = &qp->shadow_rq; +else if (mmq) + shadow_q = &qp->shadow_mmq; +else + shadow_q = &qp->shadow_sq; + + shadow_wqe =shadow_queue_get_next_to_consume (shadow_q); +if (shadow_wqe) { +if (send) { +if (!mana_complete_send_dependencies (qp, mmq, shadow_wqe, poll)) +return false; + +mana_complete_send (qp, mmq, poll, vendor_err); + }else { +mana_fill_wc (qp, poll, shadow_wqe,IB_WC_RECV , vendor_err); +shadow_queue_advance_consumer (shadow_q); + } + } +
drivers/infiniband/hw/mana/cq.c static bool handle_psn_cqe(struct mana_ib_qp *qp, u32 psn, · line 665
Quoted 10 lines
drivers/infiniband/hw/mana/cq.c +10
-0+/* Hardware has stopped DMA for the queues flushed below. */ +if (send) { +if (list_empty (&qp->send_err_node)) +list_add_tail (&qp->send_err_node, &cq->send_err_qp_list); + }else { +if (list_empty (&qp->recv_err_node)) +list_add_tail (&qp->recv_err_node, &cq->recv_err_qp_list); + } +if (qp->ibqp.qp_type !=IB_QPT_GSI ) +mana_ib_schedule_qp_error (qp);
[Severity: High]
As reported by Sashiko on v5 [1], in handle_error_cqe(), mana_ib_schedule_qp_error() is skipped when qp->ibqp.qp_type == IB_QPT_GSI, but qp->send_err_node or qp->recv_err_node is still unconditionally added to cq->send_err_qp_list or cq->recv_err_qp_list.
QPs are only removed from those error lists in mana_remove_qp_from_cqs() on a transition to IB_QPS_RESET in mana_ib_modify_qp_state(), or during QP destruction:
drivers/infiniband/hw/mana/qp.c:mana_ib_modify_qp_state() {
if (attr_mask & IB_QP_STATE) {
switch (attr->qp_state) {
case IB_QPS_RESET:
mana_remove_qp_from_cqs(qp, true);
...
break;
default:
break;
}
}However, the MAD layer never transitions a GSI QP to IB_QPS_RESET. On a GSI send error, ib_mad_send_done() -> ib_mad_send_error() transitions the QP from IB_QPS_SQE back to IB_QPS_RTS and reposts the WRs via ib_post_send() -> mana_ib_post_send_ud():
drivers/infiniband/hw/mana/wr.c:mana_ib_post_send_ud() {
...
if (ring_sq) {
mana_gd_wq_ring_doorbell(mdev_to_gc(mdev), queue);
mana_ib_notify_flush(qp->ibqp.send_cq, &qp->send_err_node);
}
}Because qp->send_err_node remains on cq->send_err_qp_list while the GSI QP is active in IB_QPS_RTS, won't mana_flush_completions() immediately software-flush all in-flight and newly posted GSI WRs with IB_WC_WR_FLUSH_ERR, causing ib_mad_send_done() to DMA-unmap buffers while hardware still owns them and permanently breaking GSI traffic on the port? Similarly, if a receive error occurs while the GSI RQ remains active in RTS, adding qp->recv_err_node would flush all pre-posted GSI receive WRs.
Should adding the QP to cq->send_err_qp_list and cq->recv_err_qp_list also be skipped for IB_QPT_GSI (or cleaned up when transitioning back to IB_QPS_RTS)?
[1] https://lore.kernel.org/r/[email protected]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
PATCH v6 10/10 RDMA/mana_ib: Drain kernel receive and send queues
In reply to Konstantin TaranovFrom: Konstantin Taranov <[email protected]>
Implement the core drain callbacks by moving the QP to ERR, posting a completion-bearing marker, and waiting until that marker is flushed.
---
v2:
- Limit the drain callbacks to RC QPs.
- Skip completion callbacks for IB_POLL_DIRECT and retain direct polling.
drivers/infiniband/hw/mana/device.c | 2 + drivers/infiniband/hw/mana/mana_ib.h | 2 + drivers/infiniband/hw/mana/qp.c | 103 +++++++++++++++++++++++++++ 3 files changed, 107 insertions(+)
drivers/infiniband/hw/mana/device.c +2 -0
@@ -38,6 +38,8 @@ static const struct ib_device_ops mana_ib_dev_ops = { .destroy_rwq_ind_table = mana_ib_destroy_rwq_ind_table, .destroy_wq = mana_ib_destroy_wq, .disassociate_ucontext = mana_ib_disassociate_ucontext, + .drain_rq = mana_ib_drain_rq, + .drain_sq = mana_ib_drain_sq, .get_dma_mr = mana_ib_get_dma_mr, .get_link_layer = mana_ib_get_link_layer, .get_port_immutable = mana_ib_get_port_immutable,
drivers/infiniband/hw/mana/mana_ib.h +2 -0
@@ -1060,6 +1060,8 @@ int mana_ib_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr,int mana_ib_post_send (struct ib_qp *ibqp,const struct ib_send_wr *wr,const struct ib_send_wr **bad_wr); +void mana_ib_drain_sq (struct ib_qp *ibqp); +void mana_ib_drain_rq (struct ib_qp *ibqp);void mana_drain_gsi_sqs (struct mana_ib_dev *mdev);int mana_ib_poll_cq (struct ib_cq *ibcq,int num_entries,struct ib_wc *wc);int mana_ib_arm_cq (struct ib_cq *ibcq,enum ib_cq_notify_flags flags);
drivers/infiniband/hw/mana/qp.c +103 -0
106 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH rdma-next v6 10/10] RDMA/mana_ib: Drain kernel receive and send queues
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] RDMA/mana_ib: redundant comp_handler calls and duplicated drain logic in qp.c --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] RDMA/mana_ib: redundant comp_handler calls and duplicated drain logic in qp.c --
commit 5e7a469ad596532936441484def77d5229b5cbff
Author: Konstantin Taranov <[email protected]>
RDMA/mana_ib: Drain kernel receive and send queues
This commit implements the drain_sq and drain_rq device operations for mana_ib by transitioning RC QPs to the error state, posting a marker work request, and waiting for its completion.
Quoted 101 lines
drivers/infiniband/hw/mana/qp.c +93
-0@@ -1398,3 +1398,106 @@ int mana_ib_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)return -ENOENT ; } + +struct mana_ib_drain_cqe { +struct ib_cqe cqe; +struct completion done; +}; + +static void mana_ib_drain_qp_done (struct ib_cq *cq,struct ib_wc *wc) +{ +struct mana_ib_drain_cqe *cqe =container_of (wc->wr_cqe, + struct mana_ib_drain_cqe, + cqe); +complete (&cqe->done); +} + +void mana_ib_drain_sq (struct ib_qp *ibqp) +{ +struct ib_qp_attr attr = { .qp_state =IB_QPS_ERR }; +struct mana_ib_drain_cqe sdrain; +struct ib_rdma_wr swr = { + .wr = { + .next =NULL , + .wr_cqe = &sdrain.cqe, + .opcode =IB_WR_SEND , + }, + }; +const struct ib_send_wr *bad_swr; +struct ib_cq *cq = ibqp->send_cq; +int ret; + +if (ibqp->qp_type !=IB_QPT_RC ) { +ibdev_err (ibqp->device,"SQ drain is only supported for RC QPs (type %u)\n" , + ibqp->qp_type); +return ; + } + + ret =ib_modify_qp (ibqp, &attr,IB_QP_STATE ); +if (ret) { +ibdev_err (ibqp->device,"Failed to drain SQ: modify QP returned %d\n" , ret); +return ; + } + + sdrain.cqe.done = mana_ib_drain_qp_done; +init_completion (&sdrain.done); + + ret =ib_post_send (ibqp, &swr.wr, &bad_swr); +if (ret) { +ibdev_err (ibqp->device,"Failed to post SQ drain WR: %d\n" , ret); +return ; + } + +if (cq->poll_ctx !=IB_POLL_DIRECT && cq->comp_handler) + cq->comp_handler (cq, cq->cq_context); + +if (cq->poll_ctx ==IB_POLL_DIRECT ) { +while (!wait_for_completion_timeout (&sdrain.done,HZ /10 )) +ib_process_cq_direct (cq,-1 ); + }else { +wait_for_completion (&sdrain.done); + } +} + +void mana_ib_drain_rq (struct ib_qp *ibqp) +{ +struct ib_qp_attr attr = { .qp_state =IB_QPS_ERR }; +struct mana_ib_drain_cqe rdrain; +struct ib_recv_wr rwr = { + .next =NULL , + .wr_cqe = &rdrain.cqe, + }; +struct ib_cq *cq = ibqp->recv_cq; +int ret; + +if (ibqp->qp_type !=IB_QPT_RC ) { +ibdev_err (ibqp->device,"RQ drain is only supported for RC QPs (type %u)\n" , + ibqp->qp_type); +return ; + } + + ret =ib_modify_qp (ibqp, &attr,IB_QP_STATE ); +if (ret) { +ibdev_err (ibqp->device,"Failed to drain RQ: modify QP returned %d\n" , ret); +return ; + } + + rdrain.cqe.done = mana_ib_drain_qp_done; +init_completion (&rdrain.done); + + ret =ib_post_recv (ibqp, &rwr,NULL ); +if (ret) { +ibdev_err (ibqp->device,"Failed to post RQ drain WR: %d\n" , ret); +return ; + } +
drivers/infiniband/hw/mana/qp.c int mana_ib_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata) · line 1503
Quoted 10 lines
drivers/infiniband/hw/mana/qp.c +10
-0+if (cq->poll_ctx !=IB_POLL_DIRECT && cq->comp_handler) + cq->comp_handler (cq, cq->cq_context); + +if (cq->poll_ctx ==IB_POLL_DIRECT ) { +while (!wait_for_completion_timeout (&rdrain.done,HZ /10 )) +ib_process_cq_direct (cq,-1 ); + }else { +wait_for_completion (&rdrain.done); + } +}
[Severity: Low]
Are custom mana_ib_drain_sq() and mana_ib_drain_rq() callbacks needed in mana_ib_dev_ops, and does calling cq->comp_handler() here invoke the completion handler twice?
When ib_modify_qp() transitions the QP to IB_QPS_ERR, mana_ib_modify_qp_state() calls mana_add_qp_to_error_cqs() to link qp->send_err_node and qp->recv_err_node onto the CQ error lists.
Then, when ib_post_send() and ib_post_recv() run, mana_ib_post_send_rc() and mana_ib_post_recv_rc() already call mana_ib_notify_flush(), which invokes ibcq->comp_handler(ibcq, ibcq->cq_context) when ibcq->poll_ctx is not IB_POLL_DIRECT. Calling cq->comp_handler() again right after ib_post_send() and ib_post_recv() triggers a redundant second invocation.
More broadly, since mana_ib_modify_qp(), mana_ib_post_sq() (which supports 0-SGE IB_WR_RDMA_WRITE WRs), and mana_ib_post_rq() already handle software flushing and CQ notification via mana_ib_notify_flush(), could mana_ib simply rely on the generic __ib_drain_sq() and __ib_drain_rq() fallbacks in drivers/infiniband/core/verbs.c instead of duplicating them here (which also restricts drain_rq to IB_QPT_RC even though mana_ib_post_recv_ud() supports flushing UD and GSI receive queues)?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10