git: 8840ae228807 - main - tcp: don't store VNET in every tcpcb, take it from the inpcbinfo

From: Gleb Smirnoff <glebius_at_FreeBSD.org>
Date: Tue, 08 Nov 2022 18:25:00 UTC
The branch main has been updated by glebius:

URL: https://cgit.FreeBSD.org/src/commit/?id=8840ae2288079b1221ab4e6623110b50d0092542

commit 8840ae2288079b1221ab4e6623110b50d0092542
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2022-11-08 18:24:40 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2022-11-08 18:24:40 +0000

    tcp: don't store VNET in every tcpcb, take it from the inpcbinfo
    
    Reviewed by:            rscheff
    Differential revision:  https://reviews.freebsd.org/D37125
---
 sys/kern/uipc_ktls.c    |  2 +-
 sys/netinet/tcp_subr.c  |  3 ---
 sys/netinet/tcp_timer.c | 18 +++++++++++-------
 sys/netinet/tcp_var.h   |  1 -
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/sys/kern/uipc_ktls.c b/sys/kern/uipc_ktls.c
index 521c416b5234..b4e5004ed1f8 100644
--- a/sys/kern/uipc_ktls.c
+++ b/sys/kern/uipc_ktls.c
@@ -1748,7 +1748,7 @@ ktls_reset_send_tag(void *context, int pending)
 		if (!in_pcbrele_wlocked(inp)) {
 			if (!(inp->inp_flags & INP_DROPPED)) {
 				tp = intotcpcb(inp);
-				CURVNET_SET(tp->t_vnet);
+				CURVNET_SET(inp->inp_vnet);
 				tp = tcp_drop(tp, ECONNABORTED);
 				CURVNET_RESTORE();
 				if (tp != NULL)
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
index acd82b4e851c..58e410edf0bb 100644
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -2260,9 +2260,6 @@ tcp_newtcpcb(struct inpcb *inp)
 	}
 #endif
 
-#ifdef VIMAGE
-	tp->t_vnet = inp->inp_vnet;
-#endif
 	tp->t_timers = &tm->tt;
 	TAILQ_INIT(&tp->t_segq);
 	tp->t_maxseg =
diff --git a/sys/netinet/tcp_timer.c b/sys/netinet/tcp_timer.c
index 0ef17603beea..cf11dee8af68 100644
--- a/sys/netinet/tcp_timer.c
+++ b/sys/netinet/tcp_timer.c
@@ -254,9 +254,9 @@ tcp_timer_delack(void *xtp)
 	struct inpcb *inp = tptoinpcb(tp);
 #endif
 
-	CURVNET_SET(tp->t_vnet);
-
 	INP_WLOCK(inp);
+	CURVNET_SET(inp->inp_vnet);
+
 	if (callout_pending(&tp->t_timers->tt_delack) ||
 	    !callout_active(&tp->t_timers->tt_delack)) {
 		INP_WUNLOCK(inp);
@@ -318,7 +318,6 @@ tcp_timer_2msl(void *xtp)
 {
 	struct tcpcb *tp = xtp;
 	struct inpcb *inp = tptoinpcb(tp);
-	CURVNET_SET(tp->t_vnet);
 #ifdef TCPDEBUG
 	int ostate;
 
@@ -326,6 +325,8 @@ tcp_timer_2msl(void *xtp)
 #endif
 
 	INP_WLOCK(inp);
+	CURVNET_SET(inp->inp_vnet);
+
 	tcp_log_end_status(tp, TCP_EI_STATUS_2MSL);
 	tcp_free_sackholes(tp);
 	if (callout_pending(&tp->t_timers->tt_2msl) ||
@@ -394,7 +395,6 @@ tcp_timer_keep(void *xtp)
 	struct tcpcb *tp = xtp;
 	struct inpcb *inp = tptoinpcb(tp);
 	struct tcptemp *t_template;
-	CURVNET_SET(tp->t_vnet);
 #ifdef TCPDEBUG
 	int ostate;
 
@@ -402,6 +402,8 @@ tcp_timer_keep(void *xtp)
 #endif
 
 	INP_WLOCK(inp);
+	CURVNET_SET(inp->inp_vnet);
+
 	if (callout_pending(&tp->t_timers->tt_keep) ||
 	    !callout_active(&tp->t_timers->tt_keep)) {
 		INP_WUNLOCK(inp);
@@ -539,7 +541,6 @@ tcp_timer_persist(void *xtp)
 #endif
 	bool progdrop;
 	int outrv;
-	CURVNET_SET(tp->t_vnet);
 #ifdef TCPDEBUG
 	int ostate;
 
@@ -547,6 +548,8 @@ tcp_timer_persist(void *xtp)
 #endif
 
 	INP_WLOCK(inp);
+	CURVNET_SET(inp->inp_vnet);
+
 	if (callout_pending(&tp->t_timers->tt_persist) ||
 	    !callout_active(&tp->t_timers->tt_persist)) {
 		INP_WUNLOCK(inp);
@@ -619,7 +622,6 @@ tcp_timer_rexmt(void * xtp)
 {
 	struct epoch_tracker et;
 	struct tcpcb *tp = xtp;
-	CURVNET_SET(tp->t_vnet);
 	struct inpcb *inp = tptoinpcb(tp);
 	int rexmt, outrv;
 	bool isipv6;
@@ -630,6 +632,8 @@ tcp_timer_rexmt(void * xtp)
 #endif
 
 	INP_WLOCK(inp);
+	CURVNET_SET(inp->inp_vnet);
+
 	if (callout_pending(&tp->t_timers->tt_rexmt) ||
 	    !callout_active(&tp->t_timers->tt_rexmt)) {
 		INP_WUNLOCK(inp);
@@ -1090,8 +1094,8 @@ tcp_timer_discard(void *ptp)
 	struct tcpcb *tp = (struct tcpcb *)ptp;
 	struct inpcb *inp = tptoinpcb(tp);
 
-	CURVNET_SET(tp->t_vnet);
 	INP_WLOCK(inp);
+	CURVNET_SET(inp->inp_vnet);
 	NET_EPOCH_ENTER(et);
 
 	KASSERT((tp->t_timers->tt_flags & TT_STOPPED) != 0,
diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h
index 12d18b420bbc..2cfc1ff3f21a 100644
--- a/sys/netinet/tcp_var.h
+++ b/sys/netinet/tcp_var.h
@@ -181,7 +181,6 @@ struct tcpcb {
 	struct mbuf *t_in_pkt;
 	struct mbuf *t_tail_pkt;
 	struct tcp_timer *t_timers;	/* All the TCP timers in one struct */
-	struct	vnet *t_vnet;		/* back pointer to parent vnet */
 	uint32_t snd_ssthresh;		/* snd_cwnd size threshold for
 					 * for slow start exponential to
 					 * linear switch