From owner-svn-src-head@freebsd.org  Tue Aug 16 13:08:05 2016
Return-Path: <owner-svn-src-head@freebsd.org>
Delivered-To: svn-src-head@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 056F2BBBDF8;
 Tue, 16 Aug 2016 13:08:05 +0000 (UTC) (envelope-from rrs@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 BC42615F6;
 Tue, 16 Aug 2016 13:08:04 +0000 (UTC) (envelope-from rrs@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.37])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u7GD833v093051;
 Tue, 16 Aug 2016 13:08:03 GMT (envelope-from rrs@FreeBSD.org)
Received: (from rrs@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id u7GD83Nx093050;
 Tue, 16 Aug 2016 13:08:03 GMT (envelope-from rrs@FreeBSD.org)
Message-Id: <201608161308.u7GD83Nx093050@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: rrs set sender to rrs@FreeBSD.org
 using -f
From: Randall Stewart <rrs@FreeBSD.org>
Date: Tue, 16 Aug 2016 13:08:03 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-head@freebsd.org
Subject: svn commit: r304219 - head/sys/netinet
X-SVN-Group: head
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-head@freebsd.org
X-Mailman-Version: 2.1.22
Precedence: list
List-Id: SVN commit messages for the src tree for head/-current
 <svn-src-head.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/svn-src-head>,
 <mailto:svn-src-head-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-head/>
List-Post: <mailto:svn-src-head@freebsd.org>
List-Help: <mailto:svn-src-head-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/svn-src-head>,
 <mailto:svn-src-head-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Tue, 16 Aug 2016 13:08:05 -0000

Author: rrs
Date: Tue Aug 16 13:08:03 2016
New Revision: 304219
URL: https://svnweb.freebsd.org/changeset/base/304219

Log:
  Comments describing how to properly use the new lock_add functions
  and its respective companion.
  
  Sponsored by:	Netflix Inc.

Modified:
  head/sys/netinet/tcp_timer.c

Modified: head/sys/netinet/tcp_timer.c
==============================================================================
--- head/sys/netinet/tcp_timer.c	Tue Aug 16 12:40:56 2016	(r304218)
+++ head/sys/netinet/tcp_timer.c	Tue Aug 16 13:08:03 2016	(r304219)
@@ -301,6 +301,25 @@ tcp_timer_delack(void *xtp)
 	CURVNET_RESTORE();
 }
 
+/*
+ * When a timer wants to remove a TCB it must
+ * hold the INP_INFO_RLOCK(). The timer function
+ * should only have grabbed the INP_WLOCK() when
+ * it entered. To safely switch to holding both the
+ * INP_INFO_RLOCK() and the INP_WLOCK() we must first
+ * grab a reference on the inp, this will hold the inp
+ * so that it can't be removed. We then unlock and grab
+ * the info-read lock. Once we have the INP_INFO_RLOCK() we
+ * proceed again to get the INP_WLOCK() but after that
+ * we must check if someone else deleted the pcb i.e.
+ * the inp_flags check.	If so we return 1 otherwise 
+ * we return 0.
+ *
+ * No matter which the tcp_inpinfo_lock_add() function
+ * returns the caller must afterwards call tcp_inpinfo_lock_del()
+ * to drop the locks and reference properly.
+ */
+
 int
 tcp_inpinfo_lock_add(struct inpcb *inp)
 {