From nobody Sat Nov 13 16:34:27 2021 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 23112183B287; Sat, 13 Nov 2021 16:34:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Hs1J40Vtmz4rWl; Sat, 13 Nov 2021 16:34:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E6BA716C24; Sat, 13 Nov 2021 16:34:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1ADGYRdY069573; Sat, 13 Nov 2021 16:34:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1ADGYRZU069572; Sat, 13 Nov 2021 16:34:27 GMT (envelope-from git) Date: Sat, 13 Nov 2021 16:34:27 GMT Message-Id: <202111131634.1ADGYRZU069572@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 9a06a8245548 - main - tcp_timers: check for (INP_TIMEWAIT | INP_DROPPED) only once List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9a06a82455487991e6a71e5ce8e96c5bf3b8df3c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=9a06a82455487991e6a71e5ce8e96c5bf3b8df3c commit 9a06a82455487991e6a71e5ce8e96c5bf3b8df3c Author: Gleb Smirnoff AuthorDate: 2021-11-10 05:22:54 +0000 Commit: Gleb Smirnoff CommitDate: 2021-11-13 16:32:06 +0000 tcp_timers: check for (INP_TIMEWAIT | INP_DROPPED) only once All timers keep inpcb locked through their execution. We need to check these flags only once. Checking for INP_TIMEWAIT earlier is is also safer, since such inpcbs point into tcptw rather than tcpcb, and any dereferences of inp_ppcb as tcpcb are erroneous. Reviewed by: rrs, hselasky Differential revision: https://reviews.freebsd.org/D32967 --- sys/netinet/tcp_timer.c | 41 ++++------------------------------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/sys/netinet/tcp_timer.c b/sys/netinet/tcp_timer.c index 139e32172531..feea3765821c 100644 --- a/sys/netinet/tcp_timer.c +++ b/sys/netinet/tcp_timer.c @@ -328,7 +328,7 @@ tcp_timer_2msl(void *xtp) return; } callout_deactivate(&tp->t_timers->tt_2msl); - if ((inp->inp_flags & INP_DROPPED) != 0) { + if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { INP_WUNLOCK(inp); CURVNET_RESTORE(); return; @@ -341,26 +341,14 @@ tcp_timer_2msl(void *xtp) * too long delete connection control block. Otherwise, check * again in a bit. * - * If in TIME_WAIT state just ignore as this timeout is handled in - * tcp_tw_2msl_scan(). - * * If fastrecycle of FIN_WAIT_2, in FIN_WAIT_2 and receiver has closed, * there's no point in hanging onto FIN_WAIT_2 socket. Just close it. * Ignore fact that there were recent incoming segments. */ - if ((inp->inp_flags & INP_TIMEWAIT) != 0) { - INP_WUNLOCK(inp); - CURVNET_RESTORE(); - return; - } if (tcp_fast_finwait2_recycle && tp->t_state == TCPS_FIN_WAIT_2 && tp->t_inpcb && tp->t_inpcb->inp_socket && (tp->t_inpcb->inp_socket->so_rcv.sb_state & SBS_CANTRCVMORE)) { TCPSTAT_INC(tcps_finwait2_drops); - if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { - tcp_inpinfo_lock_del(inp, tp); - goto out; - } NET_EPOCH_ENTER(et); tp = tcp_close(tp); NET_EPOCH_EXIT(et); @@ -371,10 +359,6 @@ tcp_timer_2msl(void *xtp) callout_reset(&tp->t_timers->tt_2msl, TP_KEEPINTVL(tp), tcp_timer_2msl, tp); } else { - if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { - tcp_inpinfo_lock_del(inp, tp); - goto out; - } NET_EPOCH_ENTER(et); tp = tcp_close(tp); NET_EPOCH_EXIT(et); @@ -419,7 +403,7 @@ tcp_timer_keep(void *xtp) return; } callout_deactivate(&tp->t_timers->tt_keep); - if ((inp->inp_flags & INP_DROPPED) != 0) { + if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { INP_WUNLOCK(inp); CURVNET_RESTORE(); return; @@ -498,10 +482,6 @@ tcp_timer_keep(void *xtp) dropit: TCPSTAT_INC(tcps_keepdrops); - if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { - tcp_inpinfo_lock_del(inp, tp); - goto out; - } NET_EPOCH_ENTER(et); tp = tcp_drop(tp, ETIMEDOUT); @@ -513,7 +493,6 @@ dropit: TCP_PROBE2(debug__user, tp, PRU_SLOWTIMO); NET_EPOCH_EXIT(et); tcp_inpinfo_lock_del(inp, tp); - out: CURVNET_RESTORE(); } @@ -539,7 +518,7 @@ tcp_timer_persist(void *xtp) return; } callout_deactivate(&tp->t_timers->tt_persist); - if ((inp->inp_flags & INP_DROPPED) != 0) { + if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { INP_WUNLOCK(inp); CURVNET_RESTORE(); return; @@ -562,10 +541,6 @@ tcp_timer_persist(void *xtp) (ticks - tp->t_rcvtime >= tcp_maxpersistidle || ticks - tp->t_rcvtime >= TCP_REXMTVAL(tp) * tcp_totbackoff)) { TCPSTAT_INC(tcps_persistdrop); - if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { - tcp_inpinfo_lock_del(inp, tp); - goto out; - } NET_EPOCH_ENTER(et); tp = tcp_drop(tp, ETIMEDOUT); NET_EPOCH_EXIT(et); @@ -579,10 +554,6 @@ tcp_timer_persist(void *xtp) if (tp->t_state > TCPS_CLOSE_WAIT && (ticks - tp->t_rcvtime) >= TCPTV_PERSMAX) { TCPSTAT_INC(tcps_persistdrop); - if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { - tcp_inpinfo_lock_del(inp, tp); - goto out; - } NET_EPOCH_ENTER(et); tp = tcp_drop(tp, ETIMEDOUT); NET_EPOCH_EXIT(et); @@ -630,7 +601,7 @@ tcp_timer_rexmt(void * xtp) return; } callout_deactivate(&tp->t_timers->tt_rexmt); - if ((inp->inp_flags & INP_DROPPED) != 0) { + if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { INP_WUNLOCK(inp); CURVNET_RESTORE(); return; @@ -651,10 +622,6 @@ tcp_timer_rexmt(void * xtp) if (++tp->t_rxtshift > TCP_MAXRXTSHIFT) { tp->t_rxtshift = TCP_MAXRXTSHIFT; TCPSTAT_INC(tcps_timeoutdrop); - if (inp->inp_flags & (INP_TIMEWAIT | INP_DROPPED)) { - tcp_inpinfo_lock_del(inp, tp); - goto out; - } NET_EPOCH_ENTER(et); tp = tcp_drop(tp, ETIMEDOUT); NET_EPOCH_EXIT(et);