PERFORCE change 137051 for review

Kip Macy kmacy at FreeBSD.org
Fri Mar 7 05:07:28 UTC 2008


http://perforce.freebsd.org/chv.cgi?CH=137051

Change 137051 by kmacy at kmacy:entropy:iwarp on 2008/03/07 05:07:04

	fix race between shutting down offload and ddp pending 

Affected files ...

.. //depot/projects/iwarp/sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c#20 edit
.. //depot/projects/iwarp/sys/dev/cxgb/ulp/tom/cxgb_cpl_socket.c#16 edit

Differences ...

==== //depot/projects/iwarp/sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c#20 (text+ko) ====

@@ -1064,6 +1064,7 @@
 	struct tcpcb *tp = toep->tp_tp;
 	struct toedev *tdev = toep->tp_toedev;
 	struct t3cdev *cdev;
+	struct socket *so;
 	unsigned int tid = toep->tp_tid;
 
 	if (!tdev)
@@ -1093,8 +1094,21 @@
 	toep->tp_tp = NULL;
 	if (tp) {
 		INP_LOCK_ASSERT(tp->t_inpcb);
+		so = tp->t_inpcb->inp_socket;
+
+		/*
+		 * cancel any offloaded reads
+		 *
+		 */
+		SOCKBUF_LOCK(&so->so_rcv);
 		tp->t_toe = NULL;
 		tp->t_flags &= ~TF_TOE;
+		if (toep->tp_ddp_state.user_ddp_pending) {
+			t3_cancel_ubuf(toep);
+			toep->tp_ddp_state.user_ddp_pending = 0;
+		} 
+		sorwakeup_locked(so);
+			
 	}
 	
 	if (toep->tp_state == TCPS_SYN_SENT) {

==== //depot/projects/iwarp/sys/dev/cxgb/ulp/tom/cxgb_cpl_socket.c#16 (text+ko) ====

@@ -578,22 +578,29 @@
 		return (err);
 
 	SOCKBUF_LOCK(&so->so_rcv);
+	if ((tp->t_flags & TF_TOE) == 0) {
+		SOCKBUF_UNLOCK(&so->so_rcv);
+		err = EAGAIN;
+		goto done_unlocked;
+	}
+	
 	p->user_ddp_pending = 0;
 restart:
+	if ((tp->t_flags & TF_TOE) == 0) {
+		SOCKBUF_UNLOCK(&so->so_rcv);
+		err = EAGAIN;
+		goto done_unlocked;
+	}
+
 	len = uio->uio_resid;
 	m = so->so_rcv.sb_mb;
 	target = (flags & MSG_WAITALL) ? len : so->so_rcv.sb_lowat;
 	user_ddp_ok = p->ubuf_ddp_ready;
 	p->cancel_ubuf = 0;
-
+	
 	if (len == 0)
 		goto done;
-#if 0	
-	while (m && m->m_len == 0) {
-		so->so_rcv.sb_mb = m_free(m);
-		m = so->so_rcv.sb_mb;
-	}
-#endif	
+
 	if (m) 
 		goto got_mbuf;
 
@@ -774,6 +781,12 @@
 		if (avail != (resid - uio->uio_resid))
 			printf("didn't copy all bytes :-/ avail=%d offset=%d pktlen=%d resid=%d uio_resid=%d copied=%d copied_unacked=%d is_ddp(m)=%d\n",
 			    avail, offset, m->m_pkthdr.len, resid, uio->uio_resid, copied, copied_unacked, is_ddp(m));
+
+		if ((tp->t_flags & TF_TOE) == 0) {
+			SOCKBUF_UNLOCK(&so->so_rcv);
+			err = EAGAIN;
+			goto done_unlocked;
+		}
 	}
 	
 	copied += avail;
@@ -839,6 +852,11 @@
 		goto restart;
 
 	done:
+	if ((tp->t_flags & TF_TOE) == 0) {
+		SOCKBUF_UNLOCK(&so->so_rcv);
+		err = EAGAIN;
+		goto done_unlocked;
+	}
 	/*
 	 * If we can still receive decide what to do in preparation for the
 	 * next receive.  Note that RCV_SHUTDOWN is set if the connection
@@ -846,8 +864,6 @@
 	 */
 	if (__predict_true((so->so_state & (SS_ISDISCONNECTING|SS_ISDISCONNECTED)) == 0)) {
 		if (p->user_ddp_pending) {
-			SOCKBUF_UNLOCK(&so->so_rcv);
-			SOCKBUF_LOCK(&so->so_rcv);
 			user_ddp_ok = 0;
 			t3_cancel_ubuf(toep);
 			if (so->so_rcv.sb_mb) {
@@ -882,7 +898,7 @@
 #endif
 	SOCKBUF_UNLOCK(&so->so_rcv);
 done_unlocked:	
-	if (copied_unacked) {
+	if (copied_unacked && (tp->t_flags & TF_TOE)) {
 		INP_LOCK(inp);
 		t3_cleanup_rbuf(tp, copied_unacked);
 		INP_UNLOCK(inp);
@@ -915,7 +931,6 @@
 	 *  - iovcnt is 1
 	 *
 	 */
-	
 	if ((tp->t_flags & TF_TOE) && uio && ((flags & (MSG_WAITALL|MSG_OOB|MSG_PEEK|MSG_DONTWAIT)) == 0)
 	    && (uio->uio_iovcnt == 1) && (mp0 == NULL)) {
 		tdev =  TOE_DEV(so);
@@ -924,6 +939,8 @@
 		if ((uio->uio_resid > zcopy_thres) &&
 		    (uio->uio_iovcnt == 1)
 		    && zcopy_enabled) {
+			CTR3(KTR_CXGB, "cxgb_soreceive: t_flags=0x%x flags=0x%x uio_resid=%d",
+			    tp->t_flags, flags, uio->uio_resid);
 			rv = t3_soreceive(so, flagsp, uio);
 			if (rv != EAGAIN)
 				return (rv);


More information about the p4-projects mailing list