From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=f/sxbTiS; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 70DD75A0619 for ; Wed, 29 Oct 2025 04:07:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761707219; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OP+7ei+VGBIT1VqwPvgAP1DjiLq/0O/FbkmWb/JuBMI=; b=f/sxbTiSo3NZiHhYA7nLr9PWNO3n7ZhkeuH2agcRd8S8bQVRnYAhhM7XvwbPMFfS/P7i15 lWbE5bT6SzycJRvuKZ6Phqx2bc+Uaoba/Zd5hTLn2HO9b+K6P333KtJh8jtKuxUs5JOYvW nCs+tEZR3xS2bwsEx3b0B0VMlnPkg04= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-245-IVPybkoGMcqJAcLuWG6qtA-1; Tue, 28 Oct 2025 23:06:57 -0400 X-MC-Unique: IVPybkoGMcqJAcLuWG6qtA-1 X-Mimecast-MFC-AGG-ID: IVPybkoGMcqJAcLuWG6qtA_1761707217 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-63c299835ebso602887a12.0 for ; Tue, 28 Oct 2025 20:06:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761707216; x=1762312016; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OP+7ei+VGBIT1VqwPvgAP1DjiLq/0O/FbkmWb/JuBMI=; b=ikui4UsvrPnBh25ObIM/bVWOSxC+aqc79d07YmjrYqenv5+SI//7m2TysZ9UmC326r AMPqR76GfM2hd16YsdejKzSn3b8otYBJu8bkaYc6RAZ6F5OUw4oKXcihQVwQDbSoHdiZ aHsEZqDBy5sGceB+8EBHdFl964KQBsFqpmkQ+g3TJHhPWkxWwnaV2hzQIPStwCHd4ZLM DMPgmBxC63WmkfYZZSHPWKDpADc2eBe4nY4ATga8G5HCgnLizUq9JpU0Rc0iJSnZvmcv ufbz2SL2hxltDTOoizp+hBc2IVyRcdg2PDu2IfD5jbcFomcyaGYIfCdpGGMiq7B/JBbs PxHA== X-Gm-Message-State: AOJu0YxEO+OQib1ZvdDDX8octGHk69I3KM3mkQqXiHVeYxLpl81WsM2h tAYgVvxvW0dqIscF+5MNMm20K+DLEAW+wKa0Pr33fslMoPM6jm5K2rCTRHr0x2CpzwlnDn+7HUL z/fG4YiBIrgjDXZvKdP7H8O6IlIw7xXmOKD1WnASrnGZjbHYckYayX8eqLl1J9PYroUqEHjvNwo kj2eayUIK4M/vFhrRWk+8ltHgtWiKRtkxXV9l/GZI= X-Gm-Gg: ASbGncsU1iMnMx3JQtG0MK1uiGkwGJmJBlH55Ib/FSql0Tvt5qrHD7CNdIHOerHhEkj Rp4l2IFxCiJdEnp+Ll5CX433GsDahGS1XCeciX5bRSZhWhusngrUMqUPek7221MJ3Rw1XLtc6JH c9bHv8Z7mAEXwESi3An/A529KYV/DhKGdDu9LG+HFKoelLqqkQWN6qYhpd X-Received: by 2002:a05:6402:208b:20b0:631:6acd:fa3a with SMTP id 4fb4d7f45d1cf-63f4bca1889mr3569686a12.4.1761707216332; Tue, 28 Oct 2025 20:06:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE09TFldN6m4fV5J2S7nWTQb3wF3wf6yU5duiOzangBwtW8ch96fhp9Z9g76lmAbqgdk9Hg+/gjUZd/FNcZ+B4= X-Received: by 2002:a05:6402:208b:20b0:631:6acd:fa3a with SMTP id 4fb4d7f45d1cf-63f4bca1889mr3569675a12.4.1761707215912; Tue, 28 Oct 2025 20:06:55 -0700 (PDT) MIME-Version: 1.0 References: <20251017062838.21041-1-yuhuang@redhat.com> <20251017062838.21041-5-yuhuang@redhat.com> <20251024010438.16e19757@elisabeth> <20251028124426.534fd236@elisabeth> In-Reply-To: <20251028124426.534fd236@elisabeth> From: Yumei Huang Date: Wed, 29 Oct 2025 11:06:44 +0800 X-Gm-Features: AWmQ_bkXOHP7yJ3B3JEuzXnPWv6MZgjRs93oWFgTWw4PDBbzTELrHktMXHS51Bo Message-ID: Subject: Re: [PATCH v6 4/4] tcp: Update data retransmission timeout To: Stefano Brivio X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: _OEitGvsBjhNCruFTCkSOSnAp0mmhxrDEl1qh2uE4lU_1761707217 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 5JGQUTJO36XP7HS7TLWKDXKB7UK65LDY X-Message-ID-Hash: 5JGQUTJO36XP7HS7TLWKDXKB7UK65LDY X-MailFrom: yuhuang@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top, david@gibson.dropbear.id.au X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Tue, Oct 28, 2025 at 7:44=E2=80=AFPM Stefano Brivio = wrote: > > On Tue, 28 Oct 2025 16:09:03 +0800 > Yumei Huang wrote: > > > On Fri, Oct 24, 2025 at 7:04=E2=80=AFAM Stefano Brivio wrote: > > > > > > On Fri, 17 Oct 2025 14:28:38 +0800 > > > Yumei Huang wrote: > > > > > > > Use an exponential backoff timeout for data retransmission accordin= g > > > > to RFC 2988 and RFC 6298. Set the initial RTO to one second as disc= ussed > > > > in Appendix A of RFC 6298. > > > > > > > > Also combine the macros defining the initial RTO for both SYN and A= CK. > > > > > > > > Signed-off-by: Yumei Huang > > > > Reviewed-by: David Gibson > > > > --- > > > > tcp.c | 27 ++++++++++++--------------- > > > > 1 file changed, 12 insertions(+), 15 deletions(-) > > > > > > > > diff --git a/tcp.c b/tcp.c > > > > index 9385132..dc0ec6c 100644 > > > > --- a/tcp.c > > > > +++ b/tcp.c > > > > @@ -179,16 +179,14 @@ > > > > * > > > > * Timeouts are implemented by means of timerfd timers, set based = on flags: > > > > * > > > > - * - SYN_TIMEOUT_INIT: if no ACK is received from tap/guest during= handshake > > > > - * (flag ACK_FROM_TAP_DUE without ESTABLISHED event) within this= time, resend > > > > - * SYN. It's the starting timeout for the first SYN retry. If th= is persists > > > > - * for more than TCP_MAX_RETRIES or (tcp_syn_retries + > > > > - * tcp_syn_linear_timeouts) times in a row, reset the connection > > > > - * > > > > - * - ACK_TIMEOUT: if no ACK segment was received from tap/guest, a= fter sending > > > > - * data (flag ACK_FROM_TAP_DUE with ESTABLISHED event), re-send = data from the > > > > - * socket and reset sequence to what was acknowledged. If this p= ersists for > > > > - * more than TCP_MAX_RETRIES times in a row, reset the connectio= n > > > > + * - RTO_INIT: if no ACK segment was received from tap/guest, eith= er during > > > > + * handshake (flag ACK_FROM_TAP_DUE without ESTABLISHED event) o= r after > > > > + * sending data (flag ACK_FROM_TAP_DUE with ESTABLISHED event), = re-send data > > > > + * from the socket and reset sequence to what was acknowledged. = This is the > > > > + * timeout for the first retry, in seconds. If this persists too= many times > > > > + * in a row, reset the connection: TCP_MAX_RETRIES for establish= ed > > > > + * connections, or (tcp_syn_retries + tcp_syn_linear_timeouts) d= uring the > > > > + * handshake. > > > > * > > > > * - FIN_TIMEOUT: if a FIN segment was sent to tap/guest (flag ACK= _FROM_TAP_DUE > > > > * with TAP_FIN_SENT event), and no ACK is received within this = time, reset > > > > @@ -342,8 +340,7 @@ enum { > > > > #define WINDOW_DEFAULT 14600 /* RF= C 6928 */ > > > > > > > > #define ACK_INTERVAL 10 /* ms */ > > > > -#define SYN_TIMEOUT_INIT 1 /* s */ > > > > -#define ACK_TIMEOUT 2 > > > > +#define RTO_INIT 1 /* s, RFC 629= 8 */ > > > > #define FIN_TIMEOUT 60 > > > > #define ACT_TIMEOUT 7200 > > > > > > > > @@ -588,13 +585,13 @@ static void tcp_timer_ctl(const struct ctx *c= , struct tcp_tap_conn *conn) > > > > } else if (conn->flags & ACK_FROM_TAP_DUE) { > > > > if (!(conn->events & ESTABLISHED)) { > > > > if (conn->retries < c->tcp.syn_linear_timeout= s) > > > > - it.it_value.tv_sec =3D SYN_TIMEOUT_IN= IT; > > > > + it.it_value.tv_sec =3D RTO_INIT; > > > > else > > > > - it.it_value.tv_sec =3D SYN_TIMEOUT_IN= IT << > > > > + it.it_value.tv_sec =3D RTO_INIT << > > > > (conn->retries - c->tcp.syn_l= inear_timeouts); > > > > } > > > > else > > > > - it.it_value.tv_sec =3D ACK_TIMEOUT; > > > > + it.it_value.tv_sec =3D RTO_INIT << conn->retr= ies; > > > > > > Same as on 3/4, but here it's clearly more convenient: just assign > > > RTO_INIT, and multiply as needed in the if / else clauses. > > > > I guess we can't just assign RTO_INIT. Maybe assign it only when > > retries=3D=3D0, otherwise multiply as it.it_value.tv_sec <<=3D1. > > Why can't you do that? Say: > > it.it_value.tv_sec =3D RTO_INIT > if (!(conn->events & ESTABLISHED)) { > if (conn->retries >=3D c->tcp.syn_linear_timeouts) > it.it_value.tv_sec <<=3D (conn->retries - > c->tcp.syn_linear_timeout= s); > > but anyway, see below. > > > But it seems more complicated. What do you think? > > Or maybe, building on my latest comment to 3/4: > > int factor =3D conn->retries; > > if (!(conn->events & ESTABLISHED)) > factor -=3D c->tcp.syn_linear_timeouts; > > it.it_value.tv_sec =3D RTO_INIT << MAX(factor, 0); > > ? Yeah, I understand this part now. > > > > > > > > } else if (CONN_HAS(conn, SOCK_FIN_SENT | TAP_FIN_ACKED)) { > > > > it.it_value.tv_sec =3D FIN_TIMEOUT; > > > > } else { > > > > > > The rest of the series looks good to me. > > > > > > It might be slightly more practical to factor in directly the RTO > > > clamp, and I don't think it's complicated now that you have the helpe= r > > > from 2/4, but it's not a strong preference from my side, as the serie= s > > > makes sense in any case. > > > > Reading tcp_rto_max_ms can be easy with the helper. My concern is > > about the way we get the total time for retries. > > > > I used to do it like this in v2, > > https://archives.passt.top/passt-dev/20251010074700.22177-4-yuhuang@red= hat.com/: > > > > +#define RETRY_ELAPSED(timeout_init, retries) \ > > + ((timeout_init) * ((1 << ((retries) + 1)) - 2)) > > > > Though the formula is not quite right, we could refine it as below: > > > > #define RETRY_ELAPSED(retries) ((RTO_INIT) * ((1 << ((retries) + 1)) - = 1)) > > > > Does it make sense to get the time this way? > > Well, it also depends on c->tcp.syn_linear_timeouts, right? Not really, it's only used for data retransmission, so syn_linear_timeouts is not relevant. Probably I should name it more clearly. > > But in any case, do you really need to calculate that explicitly? I was > thinking that you can just clamp the value when you use it in > tcp_timer_ctl(). > > If c->tcp.rto_max is DIV_ROUND_CLOSEST(x, 1000), where 'x' is the value > you read from the kernel, then I guess it's just: > > --- > it.it_value.tv_sec =3D MIN(it.it_value.tv_sec, c->tcp.rto= _max); After reading the comments in v3 when tcp_rto_max_ms was first mentioned again, I realized I got something wrong again. I thought it was for the total timeout for all retries, so I need to calculate that and decide to reset the connection as in v2. Anyway, you are right. We don't need to do that. Thanks for your patience. > } ... > > if (timerfd_settime(conn->timer, 0, &it, NULL)) > flow_perror(conn, "failed to set timer"); > --- > > -- > Stefano > --=20 Thanks, Yumei Huang