qed: iWARP - Use READ_ONCE and smp_store_release to access ep->state
authorMichal Kalderon <michal.kalderon@marvell.com>
Thu, 13 Jun 2019 08:29:40 +0000 (11:29 +0300)
committerDavid S. Miller <davem@davemloft.net>
Sat, 15 Jun 2019 02:23:30 +0000 (19:23 -0700)
Destroy QP waits for it's ep object state to be set to CLOSED
before proceeding. ep->state can be updated from a different
context. Add smp_store_release/READ_ONCE to synchronize.

Fixes: fc4c6065e661 ("qed: iWARP implement disconnect flows")
Signed-off-by: Ariel Elior <ariel.elior@marvell.com>
Signed-off-by: Michal Kalderon <michal.kalderon@marvell.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/qlogic/qed/qed_iwarp.c

index 7c71ea15251fae15fcc05e4926ecf5e5cb9fa04a..4c69adb0b535ebfc6868d33e9d4a6988d5016f79 100644 (file)
@@ -532,7 +532,8 @@ int qed_iwarp_destroy_qp(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp)
 
        /* Make sure ep is closed before returning and freeing memory. */
        if (ep) {
-               while (ep->state != QED_IWARP_EP_CLOSED && wait_count++ < 200)
+               while (READ_ONCE(ep->state) != QED_IWARP_EP_CLOSED &&
+                      wait_count++ < 200)
                        msleep(100);
 
                if (ep->state != QED_IWARP_EP_CLOSED)
@@ -1022,8 +1023,6 @@ qed_iwarp_mpa_complete(struct qed_hwfn *p_hwfn,
 
        params.ep_context = ep;
 
-       ep->state = QED_IWARP_EP_CLOSED;
-
        switch (fw_return_code) {
        case RDMA_RETURN_OK:
                ep->qp->max_rd_atomic_req = ep->cm_info.ord;
@@ -1083,6 +1082,10 @@ qed_iwarp_mpa_complete(struct qed_hwfn *p_hwfn,
                break;
        }
 
+       if (fw_return_code != RDMA_RETURN_OK)
+               /* paired with READ_ONCE in destroy_qp */
+               smp_store_release(&ep->state, QED_IWARP_EP_CLOSED);
+
        ep->event_cb(ep->cb_context, &params);
 
        /* on passive side, if there is no associated QP (REJECT) we need to
@@ -2825,7 +2828,9 @@ static void qed_iwarp_qp_in_error(struct qed_hwfn *p_hwfn,
        params.status = (fw_return_code == IWARP_QP_IN_ERROR_GOOD_CLOSE) ?
                         0 : -ECONNRESET;
 
-       ep->state = QED_IWARP_EP_CLOSED;
+       /* paired with READ_ONCE in destroy_qp */
+       smp_store_release(&ep->state, QED_IWARP_EP_CLOSED);
+
        spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
        list_del(&ep->list_entry);
        spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
@@ -2914,7 +2919,8 @@ qed_iwarp_tcp_connect_unsuccessful(struct qed_hwfn *p_hwfn,
        params.event = QED_IWARP_EVENT_ACTIVE_COMPLETE;
        params.ep_context = ep;
        params.cm_info = &ep->cm_info;
-       ep->state = QED_IWARP_EP_CLOSED;
+       /* paired with READ_ONCE in destroy_qp */
+       smp_store_release(&ep->state, QED_IWARP_EP_CLOSED);
 
        switch (fw_return_code) {
        case IWARP_CONN_ERROR_TCP_CONNECT_INVALID_PACKET: