Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 10 Nov 2003 13:00:04 -0800 (PST)
From:      Sam Leffler <sam@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 41927 for review
Message-ID:  <200311102100.hAAL04SK060419@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=41927

Change 41927 by sam@sam_ebb on 2003/11/10 12:59:48

	o add missing inpcb locking
	o add locking assertions for globally visible routines

Affected files ...

.. //depot/projects/netperf/sys/netinet/tcp_syncache.c#9 edit

Differences ...

==== //depot/projects/netperf/sys/netinet/tcp_syncache.c#9 (text+ko) ====

@@ -288,13 +288,14 @@
 	struct syncache_head *sch;
 {
 	struct syncache *sc2;
-	int s, i;
+	int i;
+
+	INP_INFO_WLOCK_ASSERT(&tcbinfo);
 
 	/*
 	 * Make sure that we don't overflow the per-bucket
 	 * limit or the total cache size limit.
 	 */
-	s = splnet();
 	if (sch->sch_length >= tcp_syncache.bucket_limit) {
 		/*
 		 * The bucket is full, toss the oldest element.
@@ -328,7 +329,6 @@
 	sch->sch_length++;
 	tcp_syncache.cache_count++;
 	tcpstat.tcps_sc_added++;
-	splx(s);
 }
 
 static void
@@ -336,7 +336,7 @@
 	struct syncache *sc;
 	struct syncache_head *sch;
 {
-	int s;
+	INP_INFO_WLOCK_ASSERT(&tcbinfo);
 
 	if (sch == NULL) {
 #ifdef INET6
@@ -351,8 +351,6 @@
 		}
 	}
 
-	s = splnet();
-
 	TAILQ_REMOVE(&sch->sch_bucket, sc, sc_hash);
 	sch->sch_length--;
 	tcp_syncache.cache_count--;
@@ -360,7 +358,6 @@
 	TAILQ_REMOVE(&tcp_syncache.timerq[sc->sc_rxtslot], sc, sc_timerq);
 	if (TAILQ_EMPTY(&tcp_syncache.timerq[sc->sc_rxtslot]))
 		callout_stop(&tcp_syncache.tt_timerq[sc->sc_rxtslot]);
-	splx(s);
 
 	syncache_free(sc);
 }
@@ -376,14 +373,12 @@
 	intptr_t slot = (intptr_t)xslot;
 	struct syncache *sc, *nsc;
 	struct inpcb *inp;
-	int s;
 
-	s = splnet();
 	INP_INFO_WLOCK(&tcbinfo);
         if (callout_pending(&tcp_syncache.tt_timerq[slot]) ||
             !callout_active(&tcp_syncache.tt_timerq[slot])) {
-		INP_INFO_WUNLOCK(&tcbinfo);
-                splx(s);
+		/* XXX can this happen? */
+		INP_INFO_WLOCK(&tcbinfo);
                 return;
         }
         callout_deactivate(&tcp_syncache.tt_timerq[slot]);
@@ -420,8 +415,7 @@
 	if (nsc != NULL)
 		callout_reset(&tcp_syncache.tt_timerq[slot],
 		    nsc->sc_rxttime - ticks, syncache_timer, (void *)(slot));
-	INP_INFO_WUNLOCK(&tcbinfo);
-	splx(s);
+	INP_INFO_WLOCK(&tcbinfo);
 }
 
 /*
@@ -434,39 +428,32 @@
 {
 	struct syncache *sc;
 	struct syncache_head *sch;
-	int s;
+
+	INP_INFO_WLOCK_ASSERT(&tcbinfo);
 
 #ifdef INET6
 	if (inc->inc_isipv6) {
 		sch = &tcp_syncache.hashbase[
 		    SYNCACHE_HASH6(inc, tcp_syncache.hashmask)];
 		*schp = sch;
-		s = splnet();
 		TAILQ_FOREACH(sc, &sch->sch_bucket, sc_hash) {
-			if (ENDPTS6_EQ(&inc->inc_ie, &sc->sc_inc.inc_ie)) {
-				splx(s);
+			if (ENDPTS6_EQ(&inc->inc_ie, &sc->sc_inc.inc_ie))
 				return (sc);
-			}
 		}
-		splx(s);
 	} else
 #endif
 	{
 		sch = &tcp_syncache.hashbase[
 		    SYNCACHE_HASH(inc, tcp_syncache.hashmask)];
 		*schp = sch;
-		s = splnet();
 		TAILQ_FOREACH(sc, &sch->sch_bucket, sc_hash) {
 #ifdef INET6
 			if (sc->sc_inc.inc_isipv6)
 				continue;
 #endif
-			if (ENDPTS_EQ(&inc->inc_ie, &sc->sc_inc.inc_ie)) {
-				splx(s);
+			if (ENDPTS_EQ(&inc->inc_ie, &sc->sc_inc.inc_ie))
 				return (sc);
-			}
 		}
-		splx(s);
 	}
 	return (NULL);
 }
@@ -484,6 +471,8 @@
 	struct syncache *sc;
 	struct syncache_head *sch;
 
+	INP_INFO_WLOCK_ASSERT(&tcbinfo);
+
 	sc = syncache_lookup(inc, &sch);
 	if (sc == NULL)
 		return;
@@ -514,6 +503,8 @@
 	struct syncache *sc;
 	struct syncache_head *sch;
 
+	INP_INFO_WLOCK_ASSERT(&tcbinfo);
+
 	sc = syncache_lookup(inc, &sch);
 	if (sc != NULL) {
 		syncache_drop(sc, sch);
@@ -529,6 +520,8 @@
 	struct syncache *sc;
 	struct syncache_head *sch;
 
+	INP_INFO_WLOCK_ASSERT(&tcbinfo);
+
 	/* we are called at splnet() here */
 	sc = syncache_lookup(inc, &sch);
 	if (sc == NULL)
@@ -567,6 +560,9 @@
 	struct socket *so;
 	struct tcpcb *tp;
 
+	GIANT_REQUIRED;			/* XXX until socket locking */
+	INP_INFO_WLOCK_ASSERT(&tcbinfo);
+
 	/*
 	 * Ok, create the full blown connection, and set things up
 	 * as they would have been set up if we had created the
@@ -580,13 +576,14 @@
 		 * retransmits the ACK,
 		 */
 		tcpstat.tcps_listendrop++;
-		goto abort;
+		goto abort2;
 	}
 #ifdef MAC
 	mac_set_socket_peer_from_mbuf(m, so);
 #endif
 
 	inp = sotoinpcb(so);
+	INP_LOCK(inp);
 
 	/*
 	 * Insert new socket into hash list.
@@ -744,10 +741,14 @@
                 tp->snd_cwnd = tp->t_maxseg;
 	callout_reset(tp->tt_keep, tcp_keepinit, tcp_timer_keep, tp);
 
+	INP_UNLOCK(inp);
+
 	tcpstat.tcps_accepts++;
 	return (so);
 
 abort:
+	INP_UNLOCK(inp);
+abort2:
 	if (so != NULL)
 		(void) soabort(so);
 	return (NULL);
@@ -771,6 +772,8 @@
 	struct syncache_head *sch;
 	struct socket *so;
 
+	INP_INFO_WLOCK_ASSERT(&tcbinfo);
+
 	sc = syncache_lookup(inc, &sch);
 	if (sc == NULL) {
 		/*
@@ -846,7 +849,9 @@
 	struct syncache_head *sch;
 	struct mbuf *ipopts = NULL;
 	struct rmxp_tao *taop;
-	int i, s, win;
+	int i, win;
+
+	INP_INFO_WLOCK_ASSERT(&tcbinfo);
 
 	so = *sop;
 	tp = sototcpcb(so);
@@ -894,11 +899,10 @@
 #else
 		if (syncache_respond(sc, m) == 0) {
 #endif
-		        s = splnet();
+			/* NB: guarded by INP_INFO_WLOCK(&tcbinfo) */
 			TAILQ_REMOVE(&tcp_syncache.timerq[sc->sc_rxtslot],
 			    sc, sc_timerq);
 			SYNCACHE_TIMEOUT(sc, sc->sc_rxtslot);
-		        splx(s);
 		 	tcpstat.tcps_sndacks++;
 			tcpstat.tcps_sndtotal++;
 		}
@@ -913,7 +917,7 @@
 		 * Treat this as if the cache was full; drop the oldest 
 		 * entry and insert the new one.
 		 */
-		s = splnet();
+		/* NB: guarded by INP_INFO_WLOCK(&tcbinfo) */
 		for (i = SYNCACHE_MAXREXMTS; i >= 0; i--) {
 			sc = TAILQ_FIRST(&tcp_syncache.timerq[i]);
 			if (sc != NULL)
@@ -921,7 +925,6 @@
 		}
 		sc->sc_tp->ts_recent = ticks;
 		syncache_drop(sc, NULL);
-		splx(s);
 		tcpstat.tcps_sc_zonefail++;
 		sc = uma_zalloc(tcp_syncache.zone, M_NOWAIT);
 		if (sc == NULL) {
@@ -1085,6 +1088,7 @@
 	struct ip *ip = NULL;
 	struct rtentry *rt;
 	struct tcphdr *th;
+	struct inpcb *inp;
 #ifdef INET6
 	struct ip6_hdr *ip6 = NULL;
 #endif
@@ -1141,8 +1145,10 @@
 	m->m_len = tlen;
 	m->m_pkthdr.len = tlen;
 	m->m_pkthdr.rcvif = NULL;
+	inp = sc->sc_tp->t_inpcb;
+	INP_LOCK(inp);
 #ifdef MAC
-	mac_create_mbuf_from_socket(sc->sc_tp->t_inpcb->inp_socket, m);
+	mac_create_mbuf_from_socket(inp->inp_socket, m);
 #endif
 
 #ifdef INET6
@@ -1170,8 +1176,8 @@
 		ip->ip_p = IPPROTO_TCP;
 		ip->ip_src = sc->sc_inc.inc_laddr;
 		ip->ip_dst = sc->sc_inc.inc_faddr;
-		ip->ip_ttl = sc->sc_tp->t_inpcb->inp_ip_ttl;   /* XXX */
-		ip->ip_tos = sc->sc_tp->t_inpcb->inp_ip_tos;   /* XXX */
+		ip->ip_ttl = inp->inp_ip_ttl;   /* XXX */
+		ip->ip_tos = inp->inp_ip_tos;   /* XXX */
 
 		/*
 		 * See if we should do MTU discovery.  Route lookups are
@@ -1243,8 +1249,7 @@
 		th->th_sum = in6_cksum(m, IPPROTO_TCP, hlen, tlen - hlen);
 		ip6->ip6_hlim = in6_selecthlim(NULL,
 		    ro6->ro_rt ? ro6->ro_rt->rt_ifp : NULL);
-		error = ip6_output(m, NULL, ro6, 0, NULL, NULL,
-				sc->sc_tp->t_inpcb);
+		error = ip6_output(m, NULL, ro6, 0, NULL, NULL, inp);
 	} else
 #endif
 	{
@@ -1262,9 +1267,9 @@
 			    mtod(m, void *), th, 0);
 		}
 #endif
-		error = ip_output(m, sc->sc_ipopts, &sc->sc_route, 0, NULL,
-				sc->sc_tp->t_inpcb);
+		error = ip_output(m, sc->sc_ipopts, &sc->sc_route, 0, NULL,inp);
 	}
+	INP_UNLOCK(inp);
 	return (error);
 }
 
@@ -1331,6 +1336,8 @@
 	int idx, i;
 	struct md5_add add;
 
+	/* NB: single threaded; could add INP_INFO_WLOCK_ASSERT(&tcbinfo) */
+
 	idx = ((ticks << SYNCOOKIE_TIMESHIFT) / hz) & SYNCOOKIE_WNDMASK;
 	if (tcp_secret[idx].ts_expire < ticks) {
 		for (i = 0; i < 4; i++)
@@ -1379,6 +1386,8 @@
 	int wnd, idx;
 	struct md5_add add;
 
+	/* NB: single threaded; could add INP_INFO_WLOCK_ASSERT(&tcbinfo) */
+
 	data = (th->th_ack - 1) ^ (th->th_seq - 1);	/* remove ISS */
 	idx = data & SYNCOOKIE_WNDMASK;
 	if (tcp_secret[idx].ts_expire < ticks ||



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200311102100.hAAL04SK060419>