roccet sets .cong_control, so tcp_slow_start_after_idle_check() returns early and roccet implements the idle restart in cwnd_event_tx_start(). An RTO retransmission also raises CA_EVENT_TX_START: tcp_enter_loss() marks the outstanding packets lost, which drains the in-flight count while tp->packets_out stays non-zero. If delta >= icsk_rto, roccet_cwnd_event_tx_start() then takes the idle restart and overwrites tp->snd_ssthresh with tcp_snd_cwnd() == TCP_INIT_CWND. When a TLP probe was sent, the RTO timer is rearmed for a full icsk_rto at that point and the probe is the last transmit, so the first RTO is affected. Without TLP, the first RTO can escape: the timer is armed when the first packet of the flight is sent, and pacing spreads the following ones, so now - tp->lsndtime < icsk_rto. The second RTO is always affected, since it fires one backed-off icsk_rto after the first RTO retransmit. roccet_state(TCP_CA_Loss) calls roccet_reset(), which clears the private state; ca->state is already LAUNCH and last_max_cwnd is already 0 when roccet_cwnd_event_tx_start() runs, with or without this fix. The only field the idle restart breaks is tp->snd_ssthresh: it overwrites the value preserved by roccet_state() with TCP_INIT_CWND. Skip the idle restart while packets are outstanding. The packetdrill test in the next patch fails at the first RTO without this fix (snd_ssthresh == 10) and passes with it. Fixes: 819d59638796 ("tcp: Add TCP ROCCET congestion control module.") Link: https://lore.kernel.org/all/179179785248.434549.16829837649351382748@kernel.org/ Signed-off-by: Zhiqi Zhang --- net/ipv4/tcp_roccet.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_roccet.c b/net/ipv4/tcp_roccet.c index 04b9e52466..1769e4bbe3 100644 --- a/net/ipv4/tcp_roccet.c +++ b/net/ipv4/tcp_roccet.c @@ -1144,8 +1144,12 @@ static void roccet_cwnd_event_tx_start(struct sock *sk) ca->epoch_start = now; } - /* After idle periods, go into LAUNCH with slow start */ - if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_slow_start_after_idle) && + /* After idle periods, go into LAUNCH with slow start. + * We are not idle if packets are outstanding (e.g. RTO retransmit), + * see tcp_slow_start_after_idle_check(). + */ + if (!tp->packets_out && + READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_slow_start_after_idle) && delta >= inet_csk(sk)->icsk_rto) { tp->snd_ssthresh = tcp_snd_cwnd(tp); tcp_snd_cwnd_set(tp, min(TCP_INIT_CWND, tp->snd_cwnd_clamp)); -- 2.54.0 (Apple Git-157) Add a packetdrill test for the ROCCET idle restart on RTO. TLP is enabled, so the first RTO is affected; the test asserts that tp->snd_ssthresh stays at the prior cwnd (20) across the first and second RTOs. The test fails at the first RTO without the preceding fix (snd_ssthresh == 10) and passes with it. A variant with tcp_early_retrans=0 (no TLP) fails at the second RTO only. CONFIG_TCP_CONG_ADVANCED and CONFIG_TCP_CONG_ROCCET are added to the packetdrill config; ROCCET is only visible when advanced congestion control is enabled. Test written by Eric Dumazet. Suggested-by: Eric Dumazet Signed-off-by: Zhiqi Zhang --- .../testing/selftests/net/packetdrill/config | 2 + .../net/packetdrill/tcp_roccet_rto.pkt | 63 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 tools/testing/selftests/net/packetdrill/tcp_roccet_rto.pkt diff --git a/tools/testing/selftests/net/packetdrill/config b/tools/testing/selftests/net/packetdrill/config index b7df8bf309..6e012141d5 100644 --- a/tools/testing/selftests/net/packetdrill/config +++ b/tools/testing/selftests/net/packetdrill/config @@ -6,6 +6,8 @@ CONFIG_NET_SCH_FIFO=y CONFIG_NET_SCH_FQ=y CONFIG_SYN_COOKIES=y CONFIG_SYSCTL=y +CONFIG_TCP_CONG_ADVANCED=y CONFIG_TCP_CONG_CUBIC=y +CONFIG_TCP_CONG_ROCCET=y CONFIG_TCP_MD5SIG=y CONFIG_TUN=y diff --git a/tools/testing/selftests/net/packetdrill/tcp_roccet_rto.pkt b/tools/testing/selftests/net/packetdrill/tcp_roccet_rto.pkt new file mode 100644 index 0000000000..dabaf07f32 --- /dev/null +++ b/tools/testing/selftests/net/packetdrill/tcp_roccet_rto.pkt @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-2.0 +// Test that ROCCET does not take its "restart after idle" path on RTO. +// +// An RTO retransmit raises CA_EVENT_TX_START, because all outstanding +// packets were just marked lost (tcp_packets_in_flight() == 0) while +// tp->packets_out is not zero. If (now - tp->lsndtime) >= icsk_rto, +// roccet_cwnd_event_tx_start() used to overwrite the snd_ssthresh +// that tcp_enter_loss() had just set with TCP_INIT_CWND. +// +// TLP is enabled here. The RTO timer is rearmed for a full icsk_rto when +// the loss probe is sent, and the probe is the last transmit, so the +// very first RTO is affected. + +`./defaults.sh +./set_sysctls.py /proc/sys/net/ipv4/tcp_slow_start_after_idle=1` + + 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 + +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 + +0 setsockopt(3, SOL_TCP, TCP_CONGESTION, "roccet", 6) = 0 + +0 bind(3, ..., ...) = 0 + +0 listen(3, 1) = 0 + + +0 < S 0:0(0) win 65535 + +0 > S. 0:0(0) ack 1 + +.1 < . 1:1(0) ack 1 win 511 + +0 accept(3, ..., ...) = 4 + +// ROCCET paces its packets: do not expect precise outgoing packets, +// rely on TCP_INFO instead. + +0 write(4, ..., 10000) = 10000 + +.1 < . 1:1(0) ack 10001 win 511 + +0 %{ assert tcpi_snd_cwnd == 20, tcpi_snd_cwnd }% + +// RTT is 100ms, RTO is ~300ms. Nothing is acked from now on. + +0 write(4, ..., 20000) = 20000 + +// TLP fires ~250ms after the write. + +.4 %{ +assert tcpi_ca_state == TCP_CA_Open, tcpi_ca_state +assert tcpi_total_retrans == 1, tcpi_total_retrans +}% + +// First RTO, ~300ms after the TLP probe. +// ROCCET is still in LAUNCH state: ssthresh is set to the prior cwnd. + +.3 %{ +assert tcpi_ca_state == TCP_CA_Loss, tcpi_ca_state +assert tcpi_backoff == 1, tcpi_backoff +assert tcpi_total_retrans == 2, tcpi_total_retrans +assert tcpi_snd_cwnd == 10, tcpi_snd_cwnd +assert tcpi_snd_ssthresh == 20, tcpi_snd_ssthresh +}% + +// Second RTO, ~600ms after the first one. + +.6 %{ +assert tcpi_ca_state == TCP_CA_Loss, tcpi_ca_state +assert tcpi_backoff == 2, tcpi_backoff +assert tcpi_total_retrans == 3, tcpi_total_retrans +assert tcpi_snd_cwnd == 10, tcpi_snd_cwnd +assert tcpi_snd_ssthresh == 20, tcpi_snd_ssthresh +}% + +// Reset sysctls +`/tmp/sysctl_restore_${PPID}.sh` -- 2.54.0 (Apple Git-157)