All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hariprasad Shenai <hariprasad@chelsio.com>
To: netdev@vger.kernel.org, linux-rdma@vger.kernel.org
Cc: davem@davemloft.net, roland@purestorage.com, kumaras@chelsio.com,
	dm@chelsio.com, swise@opengridcomputing.com, leedom@chelsio.com,
	santosh@chelsio.com, hariprasad@chelsio.com,
	nirranjan@chelsio.com
Subject: [PATCH net-next 22/31] iw_cxgb4: lock around accept/reject downcalls.
Date: Wed, 26 Feb 2014 20:37:01 +0530	[thread overview]
Message-ID: <1393427230-14532-23-git-send-email-hariprasad@chelsio.com> (raw)
In-Reply-To: <1393427230-14532-1-git-send-email-hariprasad@chelsio.com>

From: Steve Wise <swise@opengridcomputing.com>

There is a race between ULP threads doing an accept/reject, and the
ingress processing thread handling close/abort for the same connection.
The accept/reject path needs to hold the lock to serialize these paths.

Signed-off-by: Steve Wise <swise@opengridcomputing.com>
---
 drivers/infiniband/hw/cxgb4/cm.c |   31 +++++++++++++++++++++----------
 1 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
index 11c99a6..cbeaa58 100644
--- a/drivers/infiniband/hw/cxgb4/cm.c
+++ b/drivers/infiniband/hw/cxgb4/cm.c
@@ -775,7 +775,7 @@ static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
 	ep->mpa_skb = skb;
 	c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
 	start_ep_timer(ep);
-	state_set(&ep->com, MPA_REQ_SENT);
+	__state_set(&ep->com, MPA_REQ_SENT);
 	ep->mpa_attr.initiator = 1;
 	ep->snd_seq += mpalen;
 	return;
@@ -941,7 +941,7 @@ static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
 	skb_get(skb);
 	t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
 	ep->mpa_skb = skb;
-	state_set(&ep->com, MPA_REP_SENT);
+	__state_set(&ep->com, MPA_REP_SENT);
 	ep->snd_seq += mpalen;
 	return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
 }
@@ -959,6 +959,7 @@ static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
 	PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
 	     be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
 
+	mutex_lock(&ep->com.mutex);
 	dst_confirm(ep->dst);
 
 	/* setup the hwtid for this connection */
@@ -982,7 +983,7 @@ static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
 		send_mpa_req(ep, skb, 1);
 	else
 		send_mpa_req(ep, skb, mpa_rev);
-
+	mutex_unlock(&ep->com.mutex);
 	return 0;
 }
 
@@ -2567,22 +2568,28 @@ static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
 
 int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
 {
-	int err;
+	int err = 0;
+	int disconnect = 0;
 	struct c4iw_ep *ep = to_ep(cm_id);
 	PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
 
-	if (state_read(&ep->com) == DEAD) {
+
+	mutex_lock(&ep->com.mutex);
+	if (ep->com.state == DEAD) {
 		c4iw_put_ep(&ep->com);
 		return -ECONNRESET;
 	}
 	set_bit(ULP_REJECT, &ep->com.history);
-	BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
+	BUG_ON(ep->com.state != MPA_REQ_RCVD);
 	if (mpa_rev == 0)
 		abort_connection(ep, NULL, GFP_KERNEL);
 	else {
 		err = send_mpa_reject(ep, pdata, pdata_len);
-		err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
+		disconnect = 1;
 	}
+	mutex_unlock(&ep->com.mutex);
+	if (disconnect)
+		err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
 	c4iw_put_ep(&ep->com);
 	return 0;
 }
@@ -2597,12 +2604,14 @@ int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
 	struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
 
 	PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
-	if (state_read(&ep->com) == DEAD) {
+
+	mutex_lock(&ep->com.mutex);
+	if (ep->com.state == DEAD) {
 		err = -ECONNRESET;
 		goto err;
 	}
 
-	BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
+	BUG_ON(ep->com.state != MPA_REQ_RCVD);
 	BUG_ON(!qp);
 
 	set_bit(ULP_ACCEPT, &ep->com.history);
@@ -2671,14 +2680,16 @@ int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
 	if (err)
 		goto err1;
 
-	state_set(&ep->com, FPDU_MODE);
+	__state_set(&ep->com, FPDU_MODE);
 	established_upcall(ep);
+	mutex_unlock(&ep->com.mutex);
 	c4iw_put_ep(&ep->com);
 	return 0;
 err1:
 	ep->com.cm_id = NULL;
 	cm_id->rem_ref(cm_id);
 err:
+	mutex_unlock(&ep->com.mutex);
 	c4iw_put_ep(&ep->com);
 	return err;
 }
-- 
1.7.1

  parent reply	other threads:[~2014-02-26 15:07 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-26 15:06 [PATCH net-next 00/31] Misc. fixes for cxgb4 and iw_cxgb4 Hariprasad Shenai
2014-02-26 15:06 ` [PATCH net-next 01/31] cxgb4: Fix some small bugs in t4_sge_init_soft() when our Page Size is 64KB Hariprasad Shenai
2014-02-26 15:06 ` [PATCH net-next 02/31] cxgb4: Add code to dump SGE registers when hitting idma hangs Hariprasad Shenai
2014-02-26 15:06 ` [PATCH net-next 03/31] cxgb4: Rectify emitting messages about SGE Ingress DMA channels being potentially stuck Hariprasad Shenai
2014-02-26 15:06 ` [PATCH net-next 04/31] cxgb4: Updates for T5 SGE's Egress Congestion Threshold Hariprasad Shenai
2014-02-26 15:06 ` [PATCH net-next 05/31] cxgb4: use spinlock_irqsave/spinlock_irqrestore for db lock Hariprasad Shenai
2014-02-26 15:06 ` [PATCH net-next 06/31] iw_cxgb4: cap CQ size at T4_MAX_IQ_SIZE Hariprasad Shenai
2014-02-26 15:06 ` [PATCH net-next 07/31] iw_cxgb4: Allow loopback connections Hariprasad Shenai
2014-02-26 15:06 ` [PATCH net-next 08/31] iw_cxgb4: release neigh entry in error paths Hariprasad Shenai
2014-02-26 15:06 ` [PATCH net-next 09/31] iw_cxgb4: Treat CPL_ERR_KEEPALV_NEG_ADVICE as negative advice Hariprasad Shenai
2014-02-26 15:06 ` [PATCH net-next 10/31] cxgb4/iw_cxgb4: Doorbell Drop Avoidance Bug Fixes Hariprasad Shenai
     [not found]   ` <1393427230-14532-11-git-send-email-hariprasad-ut6Up61K2wZBDgjK7y7TUQ@public.gmane.org>
2014-02-26 23:12     ` David Miller
     [not found]       ` <20140226.181216.1563503549713890339.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2014-02-27 17:11         ` Steve Wise
2014-02-27 17:11           ` Steve Wise
2014-02-27 18:05           ` David Miller
2014-02-27 18:21             ` Stephen Hemminger
     [not found]             ` <20140227.130544.1892840202381139797.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2014-03-04 23:22               ` Ben Hutchings
     [not found]                 ` <1393975366.16256.23.camel-nDn/Rdv9kqW9Jme8/bJn5UCKIB8iOfG2tUK59QYPAWc@public.gmane.org>
2014-03-05  5:34                   ` Hariprasad S
2014-03-05  5:34                     ` Hariprasad S
2014-02-26 15:06 ` [PATCH net-next 11/31] iw_cxgb4: use the BAR2/WC path for kernel QPs and T5 devices Hariprasad Shenai
2014-02-26 15:06 ` [PATCH net-next 12/31] iw_cxgb4: Fix incorrect BUG_ON conditions Hariprasad Shenai
2014-02-26 15:06 ` [PATCH net-next 13/31] iw_cxgb4: Mind the sq_sig_all/sq_sig_type QP attributes Hariprasad Shenai
2014-02-26 15:06 ` [PATCH net-next 14/31] iw_cxgb4: default peer2peer mode to 1 Hariprasad Shenai
2014-02-26 15:06 ` [PATCH net-next 15/31] iw_cxgb4: save the correct map length for fast_reg_page_lists Hariprasad Shenai
2014-02-26 15:06 ` [PATCH net-next 16/31] iw_cxgb4: don't leak skb in c4iw_uld_rx_handler() Hariprasad Shenai
2014-02-26 15:06 ` [PATCH net-next 17/31] iw_cxgb4: fix possible memory leak in RX_PKT processing Hariprasad Shenai
2014-02-26 15:06 ` [PATCH net-next 18/31] iw_cxgb4: ignore read reponse type 1 CQEs Hariprasad Shenai
2014-02-26 15:06 ` [PATCH net-next 19/31] iw_cxgb4: connect_request_upcall fixes Hariprasad Shenai
2014-02-26 15:06 ` [PATCH net-next 20/31] iw_cxgb4: adjust tcp snd/rcv window based on link speed Hariprasad Shenai
2014-02-26 15:07 ` [PATCH net-next 21/31] iw_cxgb4: update snd_seq when sending MPA messages Hariprasad Shenai
2014-02-26 15:07 ` Hariprasad Shenai [this message]
2014-02-26 15:07 ` [PATCH net-next 23/31] iw_cxgb4: drop RX_DATA packets if the endpoint is gone Hariprasad Shenai
2014-02-26 15:07 ` [PATCH net-next 24/31] iw_cxgb4: rx_data() needs to hold the ep mutex Hariprasad Shenai
2014-02-26 15:07 ` [PATCH net-next 25/31] iw_cxgb4: endpoint timeout fixes Hariprasad Shenai
2014-02-26 15:07 ` [PATCH net-next 26/31] iw_cxgb4: rmb() after reading valid gen bit Hariprasad Shenai
2014-02-26 15:07 ` [PATCH net-next 27/31] iw_cxgb4: wc_wmb() needed after DB writes Hariprasad Shenai
2014-02-26 15:07 ` [PATCH net-next 28/31] iw_cxgb4: SQ flush fix Hariprasad Shenai
2014-02-26 15:07 ` [PATCH net-next 29/31] iw_cxgb4: minor fixes/cleanup Hariprasad Shenai
2014-02-26 15:07 ` [PATCH net-next 30/31] iw_cxgb4: Max fastreg depth depends on DSGL support Hariprasad Shenai
2014-02-26 15:07 ` [PATCH net-next 31/31] Revert "cxgb4: Don't assume LSO only uses SGL path in t4_eth_xmit()" Hariprasad Shenai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1393427230-14532-23-git-send-email-hariprasad@chelsio.com \
    --to=hariprasad@chelsio.com \
    --cc=davem@davemloft.net \
    --cc=dm@chelsio.com \
    --cc=kumaras@chelsio.com \
    --cc=leedom@chelsio.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nirranjan@chelsio.com \
    --cc=roland@purestorage.com \
    --cc=santosh@chelsio.com \
    --cc=swise@opengridcomputing.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.