From owner-svn-src-stable-10@freebsd.org Fri Nov 4 03:25:36 2016 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 031ADC2B053; Fri, 4 Nov 2016 03:25:36 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B61A61525; Fri, 4 Nov 2016 03:25:35 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uA43PYkF010408; Fri, 4 Nov 2016 03:25:34 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uA43PYjq010404; Fri, 4 Nov 2016 03:25:34 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201611040325.uA43PYjq010404@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Fri, 4 Nov 2016 03:25:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r308281 - stable/10/sys/dev/cxgbe/tom X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Nov 2016 03:25:36 -0000 Author: jhb Date: Fri Nov 4 03:25:34 2016 New Revision: 308281 URL: https://svnweb.freebsd.org/changeset/base/308281 Log: MFC 277763,280146,287631: Various fixes to DDP. 277763: Lock the socket buffer before jumping to the 'out' label if sblock() fails in t4_soreceive_ddp(). 280146: Move special DDP handling for closing a connection into a new handle_ddp_close() function in t4_ddp.c as the logic is similar to handle_ddp_data(). This allows all knowledge of the special DDP mbufs to be private to t4_ddp.c as well. 287631: Add a comment to clarify how to determine the amount of received DDP data. Sponsored by: Chelsio Communications Modified: stable/10/sys/dev/cxgbe/tom/t4_cpl_io.c stable/10/sys/dev/cxgbe/tom/t4_ddp.c stable/10/sys/dev/cxgbe/tom/t4_tom.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/cxgbe/tom/t4_cpl_io.c ============================================================================== --- stable/10/sys/dev/cxgbe/tom/t4_cpl_io.c Fri Nov 4 01:56:29 2016 (r308280) +++ stable/10/sys/dev/cxgbe/tom/t4_cpl_io.c Fri Nov 4 03:25:34 2016 (r308281) @@ -1102,19 +1102,7 @@ do_peer_close(struct sge_iq *iq, const s sb = &so->so_rcv; SOCKBUF_LOCK(sb); if (__predict_false(toep->ddp_flags & (DDP_BUF0_ACTIVE | DDP_BUF1_ACTIVE))) { - m = get_ddp_mbuf(be32toh(cpl->rcv_nxt) - tp->rcv_nxt); - tp->rcv_nxt = be32toh(cpl->rcv_nxt); - toep->ddp_flags &= ~(DDP_BUF0_ACTIVE | DDP_BUF1_ACTIVE); - - KASSERT(toep->sb_cc >= sb->sb_cc, - ("%s: sb %p has more data (%d) than last time (%d).", - __func__, sb, sb->sb_cc, toep->sb_cc)); - toep->rx_credits += toep->sb_cc - sb->sb_cc; -#ifdef USE_DDP_RX_FLOW_CONTROL - toep->rx_credits -= m->m_len; /* adjust for F_RX_FC_DDP */ -#endif - sbappendstream_locked(sb, m); - toep->sb_cc = sb->sb_cc; + handle_ddp_close(toep, tp, sb, cpl->rcv_nxt); } socantrcvmore_locked(so); /* unlocks the sockbuf */ Modified: stable/10/sys/dev/cxgbe/tom/t4_ddp.c ============================================================================== --- stable/10/sys/dev/cxgbe/tom/t4_ddp.c Fri Nov 4 01:56:29 2016 (r308280) +++ stable/10/sys/dev/cxgbe/tom/t4_ddp.c Fri Nov 4 03:25:34 2016 (r308281) @@ -72,6 +72,8 @@ VNET_DECLARE(int, tcp_autorcvbuf_inc); VNET_DECLARE(int, tcp_autorcvbuf_max); #define V_tcp_autorcvbuf_max VNET(tcp_autorcvbuf_max) +static struct mbuf *get_ddp_mbuf(int len); + #define PPOD_SZ(n) ((n) * sizeof(struct pagepod)) #define PPOD_SIZE (PPOD_SZ(1)) @@ -403,6 +405,19 @@ handle_ddp_data(struct toepcb *toep, __b } tp = intotcpcb(inp); + + /* + * For RX_DDP_COMPLETE, len will be zero and rcv_nxt is the + * sequence number of the next byte to receive. The length of + * the data received for this message must be computed by + * comparing the new and old values of rcv_nxt. + * + * For RX_DATA_DDP, len might be non-zero, but it is only the + * length of the most recent DMA. It does not include the + * total length of the data received since the previous update + * for this DDP buffer. rcv_nxt is the sequence number of the + * first received byte from the most recent DMA. + */ len += be32toh(rcv_nxt) - tp->rcv_nxt; tp->rcv_nxt += len; tp->t_rcvtime = ticks; @@ -454,6 +469,37 @@ wakeup: return (0); } +void +handle_ddp_close(struct toepcb *toep, struct tcpcb *tp, struct sockbuf *sb, + __be32 rcv_nxt) +{ + struct mbuf *m; + int len; + + SOCKBUF_LOCK_ASSERT(sb); + INP_WLOCK_ASSERT(toep->inp); + len = be32toh(rcv_nxt) - tp->rcv_nxt; + + /* Signal handle_ddp() to break out of its sleep loop. */ + toep->ddp_flags &= ~(DDP_BUF0_ACTIVE | DDP_BUF1_ACTIVE); + if (len == 0) + return; + + tp->rcv_nxt += len; + KASSERT(toep->sb_cc >= sb->sb_cc, + ("%s: sb %p has more data (%d) than last time (%d).", + __func__, sb, sb->sb_cc, toep->sb_cc)); + toep->rx_credits += toep->sb_cc - sb->sb_cc; +#ifdef USE_DDP_RX_FLOW_CONTROL + toep->rx_credits -= len; /* adjust for F_RX_FC_DDP */ +#endif + + m = get_ddp_mbuf(len); + + sbappendstream_locked(sb, m); + toep->sb_cc = sb->sb_cc; +} + #define DDP_ERR (F_DDP_PPOD_MISMATCH | F_DDP_LLIMIT_ERR | F_DDP_ULIMIT_ERR |\ F_DDP_PPOD_PARITY_ERR | F_DDP_PADDING_ERR | F_DDP_OFFSET_ERR |\ F_DDP_INVALID_TAG | F_DDP_COLOR_ERR | F_DDP_TID_MISMATCH |\ @@ -991,7 +1037,7 @@ soreceive_rcvoob(struct socket *so, stru static char ddp_magic_str[] = "nothing to see here"; -struct mbuf * +static struct mbuf * get_ddp_mbuf(int len) { struct mbuf *m; @@ -1078,9 +1124,9 @@ t4_soreceive_ddp(struct socket *so, stru /* Prevent other readers from entering the socket. */ error = sblock(sb, SBLOCKWAIT(flags)); + SOCKBUF_LOCK(sb); if (error) goto out; - SOCKBUF_LOCK(sb); /* Easy one, no space to copyout anything. */ if (uio->uio_resid == 0) { Modified: stable/10/sys/dev/cxgbe/tom/t4_tom.h ============================================================================== --- stable/10/sys/dev/cxgbe/tom/t4_tom.h Fri Nov 4 01:56:29 2016 (r308280) +++ stable/10/sys/dev/cxgbe/tom/t4_tom.h Fri Nov 4 03:25:34 2016 (r308281) @@ -281,9 +281,10 @@ void t4_init_ddp(struct adapter *, struc void t4_uninit_ddp(struct adapter *, struct tom_data *); int t4_soreceive_ddp(struct socket *, struct sockaddr **, struct uio *, struct mbuf **, struct mbuf **, int *); -struct mbuf *get_ddp_mbuf(int); void enable_ddp(struct adapter *, struct toepcb *toep); void release_ddp_resources(struct toepcb *toep); +void handle_ddp_close(struct toepcb *, struct tcpcb *, struct sockbuf *, + uint32_t); void insert_ddp_data(struct toepcb *, uint32_t); /* ULP related */