IB/mlx5: Reset flow support for IB kernel ULPs
Subsystems (3)
PATCH 1/1 IB/mlx5: Reset flow support for IB kernel ULPs
From: Maor Gottlieb <maorg-VPRAkNaXOzVWk0Htik3J/[email protected]>
The driver exposes interfaces that directly relate to HW state. Upon fatal error, consumers of these interfaces (ULPs) that rely on completion of all their posted work-request could hang, thereby introducing dependencies in shutdown order. To prevent this from happening, we manage the relevant resources (CQs, QPs) that are used by the device. Upon a fatal error, we now generate simulated completions for outstanding WQEs that were not completed at the time the HW was reset.
It includes invoking the completion event handler for all involved CQs so that the ULPs will poll those CQs. When polled we return simulated CQEs with IB_WC_WR_FLUSH_ERR return code enabling ULPs to clean up their resources and not wait forever for completions upon receiving remove_one.
The above change requires an extra check in the data path to make sure that when device is in error state, the simulated CQEs will be returned and no further WQEs will be posted.
--- drivers/infiniband/hw/mlx5/cq.c | 87 +++++++++++++++++++++++++++++++- drivers/infiniband/hw/mlx5/main.c | 62 +++++++++++++++++++++++ drivers/infiniband/hw/mlx5/mlx5_ib.h | 8 +++ drivers/infiniband/hw/mlx5/mr.c | 4 ++ drivers/infiniband/hw/mlx5/qp.c | 98 +++++++++++++++++++++++++++++------- drivers/infiniband/hw/mlx5/srq.c | 10 +++- include/linux/mlx5/cq.h | 2 + 7 files changed, 250 insertions(+), 21 deletions(-)
drivers/infiniband/hw/mlx5/cq.c +86 -1
@@ -424,6 +424,83 @@ static void get_sig_err_item(struct mlx5_sig_err_cqe *cqe, item->key =be32_to_cpu (cqe->mkey); } +static void sw_send_comp (struct mlx5_ib_qp *qp,int num_entries, +struct ib_wc *wc,int *npolled) +{ +struct mlx5_ib_wq *wq; +unsigned int cur; +unsigned int idx; +int np; +int i; + + wq = &qp->sq; + cur = wq->head - wq->tail; + np = *npolled; + +if (cur ==0 ) +return ; + +for (i =0 ; i < cur && np < num_entries; i++) { + idx = wq->last_poll & (wq->wqe_cnt -1 ); + wc->wr_id = wq->wrid[idx]; + wc->status =IB_WC_WR_FLUSH_ERR ; + wc->vendor_err =MLX5_CQE_SYNDROME_WR_FLUSH_ERR ; + wq->tail++; + np++; + wc->qp = &qp->ibqp; + wc++; + wq->last_poll = wq->w_list[idx].next; + } + *npolled = np; +} + +static void sw_recv_comp (struct mlx5_ib_qp *qp,int num_entries, +struct ib_wc *wc,int *npolled) +{ +struct mlx5_ib_wq *wq; +unsigned int cur; +int np; +int i; + + wq = &qp->rq; + cur = wq->head - wq->tail; + np = *npolled; + +if (cur ==0 ) +return ; + +for (i =0 ; i < cur && np < num_entries; i++) { + wc->wr_id = wq->wrid[wq->tail & (wq->wqe_cnt -1 )]; + wc->status =IB_WC_WR_FLUSH_ERR ; + wc->vendor_err =MLX5_CQE_SYNDROME_WR_FLUSH_ERR ; + wq->tail++; + np++; + wc->qp = &qp->ibqp; + wc++; + } + *npolled = np; +} + +static void mlx5_ib_poll_sw_comp (struct mlx5_ib_cq *cq,int num_entries, +struct ib_wc *wc,int *npolled) +{ +struct mlx5_ib_qp *qp; + + *npolled =0 ; +/* Find uncompleted WQEs belonging to that cq and retrun mmics ones */ +list_for_each_entry (qp, &cq->list_send_qp, cq_send_list) { +sw_send_comp (qp, num_entries, wc + *npolled, npolled); +if (*npolled >= num_entries) +return ; + } + +list_for_each_entry (qp, &cq->list_recv_qp, cq_recv_list) { +sw_recv_comp (qp, num_entries, wc + *npolled, npolled); +if (*npolled >= num_entries) +return ; + } +} +static int mlx5_poll_one (struct mlx5_ib_cq *cq,struct mlx5_ib_qp **cur_qp,struct ib_wc *wc)
@@ -594,12 +671,18 @@ int mlx5_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc) {struct mlx5_ib_cq *cq =to_mcq (ibcq);struct mlx5_ib_qp *cur_qp =NULL ; +struct mlx5_ib_dev *dev =to_mdev (cq->ibcq.device); +struct mlx5_core_dev *mdev = dev->mdev;unsigned long flags;int soft_polled =0 ;int npolled;int err =0 ;spin_lock_irqsave (&cq->lock, flags); +if (mdev->state ==MLX5_DEVICE_STATE_INTERNAL_ERROR ) { +mlx5_ib_poll_sw_comp (cq, num_entries, wc, &npolled); + goto out; + }if (unlikely (!list_empty (&cq->wc_list))) soft_polled =poll_soft_wc (cq, num_entries, wc);
@@ -612,7 +695,7 @@ int mlx5_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc)if (npolled)mlx5_cq_set_ci (&cq->mcq); - +out:spin_unlock_irqrestore (&cq->lock, flags);if (err ==0 || err == -EAGAIN )
@@ -842,6 +925,8 @@ struct ib_cq *mlx5_ib_create_cq(struct ib_device *ibdev, cq->resize_buf =NULL ; cq->resize_umem =NULL ; cq->create_flags = attr->flags; +INIT_LIST_HEAD (&cq->list_send_qp); +INIT_LIST_HEAD (&cq->list_recv_qp);if (context) { err = create_cq_user(dev, udata, context, cq, entries,
drivers/infiniband/hw/mlx5/main.c +62 -0
80 lines not on this page · raw message
drivers/infiniband/hw/mlx5/mlx5_ib.h +8 -0
@@ -340,6 +340,9 @@ struct mlx5_ib_qp {spinlock_t disable_page_faults_lock;struct mlx5_ib_pfault pagefaults[MLX5_IB_PAGEFAULT_CONTEXTS ];#endif +struct list_head qps_list; +struct list_head cq_recv_list; +struct list_head cq_send_list; };struct mlx5_ib_cq_buf {
@@ -401,6 +404,8 @@ struct mlx5_ib_cq {struct mlx5_ib_cq_buf *resize_buf;struct ib_umem *resize_umem;int cqe_size; +struct list_head list_send_qp; +struct list_head list_recv_qp;u32 create_flags;struct list_head wc_list;enum ib_cq_notify_flags notify_flags;
@@ -581,6 +586,9 @@ struct mlx5_ib_dev {struct srcu_struct mr_srcu;#endif struct mlx5_ib_flow_db flow_db; +/* protect resources needed as part of reset flow */ +spinlock_t reset_flow_resource_lock; +struct list_head qp_list; };static inline struct mlx5_ib_cq *to_mibcq (struct mlx5_core_cq *mcq)
drivers/infiniband/hw/mlx5/mr.c +4 -0
@@ -1193,12 +1193,16 @@ error:static int unreg_umr (struct mlx5_ib_dev *dev,struct mlx5_ib_mr *mr) { +struct mlx5_core_dev *mdev = dev->mdev;struct umr_common *umrc = &dev->umrc;struct mlx5_ib_umr_context umr_context;struct mlx5_umr_wr umrwr = {};struct ib_send_wr *bad;int err; +if (mdev->state ==MLX5_DEVICE_STATE_INTERNAL_ERROR ) +return 0 ; +mlx5_ib_init_umr_context (&umr_context); umrwr.wr.wr_cqe = &umr_context.cqe;
drivers/infiniband/hw/mlx5/qp.c +79 -19
226 lines not on this page · raw message
drivers/infiniband/hw/mlx5/srq.c +9 -1
@@ -458,6 +458,8 @@ int mlx5_ib_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,struct mlx5_ib_srq *srq =to_msrq (ibsrq);struct mlx5_wqe_srq_next_seg *next;struct mlx5_wqe_data_seg *scat; +struct mlx5_ib_dev *dev =to_mdev (ibsrq->device); +struct mlx5_core_dev *mdev = dev->mdev;unsigned long flags;int err =0 ;int nreq;
@@ -465,6 +467,12 @@ int mlx5_ib_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,spin_lock_irqsave (&srq->lock, flags); +if (mdev->state ==MLX5_DEVICE_STATE_INTERNAL_ERROR ) { + err = -EIO ; + *bad_wr = wr; + goto out; + } +for (nreq =0 ; wr; nreq++, wr = wr->next) {if (unlikely (wr->num_sge > srq->msrq.max_gs)) { err = -EINVAL ;
@@ -507,7 +515,7 @@ int mlx5_ib_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr, *srq->db.db =cpu_to_be32 (srq->wqe_ctr); } - +out:spin_unlock_irqrestore (&srq->lock, flags);return err;
include/linux/mlx5/cq.h +2 -0
@@ -58,6 +58,8 @@ struct mlx5_core_cq {void (*comp)(struct mlx5_core_cq *);void *priv; } tasklet_ctx; +int reset_notify_added; +struct list_head reset_notify; };
Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 1466164898-31060-1-git-send-email-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org
Quoted 17 lines · Leon Romanovsky
From: Maor Gottlieb <maorg-VPRAkNaXOzVWk0Htik3J/[email protected]>
The driver exposes interfaces that directly relate to HW state. Upon fatal error, consumers of these interfaces (ULPs) that rely on completion of all their posted work-request could hang, thereby introducing dependencies in shutdown order. To prevent this from happening, we manage the relevant resources (CQs, QPs) that are used by the device. Upon a fatal error, we now generate simulated completions for outstanding WQEs that were not completed at the time the HW was reset.
It includes invoking the completion event handler for all involved CQs so that the ULPs will poll those CQs. When polled we return simulated CQEs with
IB_WC_WR_FLUSH_ERRreturn code enabling ULPs to clean up their resources and not wait forever for completions upon receivingremove_one.
Quoted 6 lines
The above change requires an extra check in the data path to make sure that when device is in error state, the simulated CQEs will be returned and no further WQEs will be posted.
Signed-off-by Leon Romanovsky <[email protected]>
Thanks, this has been accepted for 4.8.
Signature · 2 lines
Doug Ledford <[email protected]> GPG KeyID: 0E572FDD