From owner-freebsd-stable@freebsd.org Wed Oct 12 09:52:36 2016 Return-Path: Delivered-To: freebsd-stable@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 D2FF1C0C6ED for ; Wed, 12 Oct 2016 09:52:36 +0000 (UTC) (envelope-from slw@zxy.spb.ru) Received: from zxy.spb.ru (zxy.spb.ru [195.70.199.98]) (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 92B36E47; Wed, 12 Oct 2016 09:52:36 +0000 (UTC) (envelope-from slw@zxy.spb.ru) Received: from slw by zxy.spb.ru with local (Exim 4.86 (FreeBSD)) (envelope-from ) id 1buGDC-000Ig8-0U; Wed, 12 Oct 2016 12:52:34 +0300 Date: Wed, 12 Oct 2016 12:52:33 +0300 From: Slawa Olhovchenkov To: Julien Charbon Cc: Konstantin Belousov , freebsd-stable@FreeBSD.org, hiren panchasara Subject: Re: 11.0 stuck on high network load Message-ID: <20161012095233.GC57714@zxy.spb.ru> References: <20161010142941.GV54003@zxy.spb.ru> <52d634aa-639c-bef7-1f10-c46dbadc4d85@freebsd.org> <20161010173531.GI6177@zxy.spb.ru> <8143cd8f-c007-2378-b004-b2b037402d03@freebsd.org> <20161011121145.GJ6177@zxy.spb.ru> <20161012084045.GA57714@zxy.spb.ru> <20161012092945.GB57714@zxy.spb.ru> <4b0d4b58-6d13-3cd5-6991-27163f27acca@freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4b0d4b58-6d13-3cd5-6991-27163f27acca@freebsd.org> User-Agent: Mutt/1.5.24 (2015-08-30) X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: slw@zxy.spb.ru X-SA-Exim-Scanned: No (on zxy.spb.ru); SAEximRunCond expanded to false X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Oct 2016 09:52:36 -0000 On Wed, Oct 12, 2016 at 11:42:38AM +0200, Julien Charbon wrote: > On 10/12/16 11:29 AM, Slawa Olhovchenkov wrote: > > On Wed, Oct 12, 2016 at 11:19:48AM +0200, Julien Charbon wrote: > > > >>> if INP_WLOCK is like spinlock -- this is dead lock. > >>> if INP_WLOCK is like mutex -- thread1 resheduled. > >> > >> Thanks, I understand you question now. No an interrupt cannot bypass a > >> lock: Here INP_WLOCK is like mutex -- thread1 resheduled. > > > > Thanks, nice. > > > >>>>> As I remeber race created by call tcp_twstart() at time of end > >>>>> tcp_close(), at path sofree()-tcp_usr_detach() and unexpected > >>>>> INP_TIMEWAIT state in the tcp_usr_detach(). INP_TIMEWAIT set in tcp_twstart() > >>>> > >>>> Exactly, thus the current fix is: If you already have the INP_DROPPED > >>>> flag set you are not allowed to call tcp_twstart(), actually it is a > >>>> good candidate for a new INVARIANT. Let me add that. > >>>> > >>>>> After check source code I am found invocation of tcp_twstart() in > >>>>> sys/netinet/tcp_stacks/fastpath.c, sys/netinet/tcp_input.c, > >>>>> sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c, sys/dev/cxgbe/tom/t4_cpl_io.c. > >>>>> > >>>>> Invocation from sys/netinet/tcp_stacks/fastpath.c and > >>>>> sys/netinet/tcp_input.c guarded by INP_WLOCK in tcp_input(), and now > >>>>> will be OK. > >>>>> > >>>>> Invocation from sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c and > >>>>> sys/dev/cxgbe/tom/t4_cpl_io.c is not clear to me, I am see independed > >>>>> INP_WLOCK. Is this OK? > >>>>> > >>>>> Can be thread A wants do_peer_close() directed from chelsio IRQ > >>>>> handler, bypass tcp_input()? > >>>> > >>>> If you look carefully INP_WLOCK is used in cxgb_cpl_io.c and > >>>> t4_cpl_io.c before calling tcp_twstart(). > >>> > >>> Yes, and you remeber: sys/netinet/tcp_subr.c > >>> > >>> 1535 struct tcpcb * > >>> 1536 tcp_close(struct tcpcb *tp) > >>> 1537 { > >>> ... > >>> 1569 INP_WUNLOCK(inp); > >>> 1570 ACCEPT_LOCK(); > >>> 1571 SOCK_LOCK(so); > >>> 1572 so->so_state &= ~SS_PROTOREF; > >>> 1573 sofree(so); > >>> 1574 return (NULL); > >>> > >>> sofree() call tcp_usr_detach() and in tcp_usr_detach() we have > >>> unexpected INP_TIMEWAIT. > >> > >> I see, thus just for the context: The TCP stack in sys/dev/cxgb* is a > >> TOE (TCP Offload Engine?) TCP stack for Chelsio NICs, it is a > >> separate/side TCP stack that is used only with TCP_OFFLOAD option. > >> > >> This TOE TCP stack actually has its own set of detach()/input() > >> functions and seems to check INP_DROPPED flag properly. I guess @np > >> check fixes in socket TCP stack and decides which one can also impact > >> the Chelsio TOE TCP stack. Some bugs are only in socket TCP stack, some > >> are only in TOE TCP stack. > > > > I am fear about other direction -- setting INP_TIMEWAIT in Chelsio TOE > > TCP stack and impact this to > > tcp_timer_2msl()/tcp_close()/sofree()/tcp_usr_detach() path. > > I see, I expect no problem on this side as tcp_timer_2msl() checks the > INP_TIMEWAIT flag and do not call tcp_close() if set. I am about case when at time of first INP_WUNLOCK() tcp_timer_2msl() don't see INP_TIMEWAIT, call tcp_close(), tcp_close() do INP_WUNLOCK() and now Chelsio TOE take INP_WLOCK, do tcp_twstart() and set INP_TIMEWAIT. After this tcp_timer_2msl resume and have unexpected INP_TIMEWAIT in tcp_usr_detach().