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=Ill2t1TB; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 29E525A061D for ; Tue, 28 Oct 2025 12:44:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761651872; 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=p06DPrcd1bdQH5U33rWuQKUWyi0HIzN9Szj1uQzwQbA=; b=Ill2t1TBQ3wYTC3YGK/qlyiez0CpMGO5s9XGqDxafqD1BJh1q2Q9fhL/Tr1CtCspBWHghy mC4TXVKsoYO3I3+LUtcvdH5R4d/UAzLlT3RIOTL5bvOjV2SHF7BOjwB2co4gEAiUaE750f BNwulbG+FprTM4CBFpa5mjizvRtZUWw= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-628-djVItwNVPz6m3fli2UCbYQ-1; Tue, 28 Oct 2025 07:44:31 -0400 X-MC-Unique: djVItwNVPz6m3fli2UCbYQ-1 X-Mimecast-MFC-AGG-ID: djVItwNVPz6m3fli2UCbYQ_1761651870 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3ef9218daf5so3131871f8f.1 for ; Tue, 28 Oct 2025 04:44:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761651870; x=1762256670; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=GYDWhE+EXLVSWuK5Sb5RmmsdPZmHiax5xH7xDZwICQ0=; b=GctkpO97Q52HXVzMgm8CDzSXWTn9Cn2sRvuokGdcqSpp9u6VMJSnq9bz/Qj+eva295 mERdRvmvdVTSvhGyz7F97qYHq1c4tqc4CBNqmAoNtFI7pXDW9mu3PJduXPUCipFbU0e3 lFpwUN6z6xUccw8B9yytSaACf6efOWCjFADRWNB8AgD9U1Ew/uF51KV9bbXqigby1R/n FdJodkS+U/SmZuBSx6zUe8kbuWaSNkjpNvwjbpIml2+iS0YL0AwvlJrkCQqz5m4xviu5 0rCV9LiRudvfpB6kiQ2I1gMsr/N2Z+Vg9Qa/DpEomgX66yS4PpBTayoqujRYxA5lhSaB kzPg== X-Gm-Message-State: AOJu0Yx98kx+EH1L/LEvU9nwIAMMUgoS+yM49xNoKdLn/lxFf0Vc/1t9 Z2UuxtwniVLWBqD0GvFRO35qRXBqW3uiq5HD8nms/sptGO4cHvFHjzyXFiYwEFfOeBHmAG0e8Oa D/X3IyBC6mhu7gm6WeKbk5tVaG31vkqbp0yjobK+U0tMJr4Alq0sSH16BhfSpfA== X-Gm-Gg: ASbGncs5UE8dbpBiDWyO7lFxPKSdh8QLoozS2GETV1EmulaL93LfZ+frTE5o1bmHqNj rMbyWMbut4U7kOehV4vpVfy80OXtJAwqGWGPGshKgLj3cSDQzMBv47PunwLqWbF/Wo+WpBLpngP mQm4wbbVnciVLy3CKqh73Z0PJRZfrf4CBFtgBUOvLorY6jQ5EeTKPua/sg5W8ZOdqW/c5IoZ14h tMDyb8uHB1LdkuyvD4x6UUiFEUiimfW4pK4z8ExuhN3+CfMNNl1BHiqO4JYY7sbOk4/Db3sFeuw rzfL4IwBTps93cMWq6T1AGZziD3kpvpF8548NaFrC4aMK9ux9QeG17+8h0j6HSwbptV2ifIPwQ1 F9Z+IXxLLSw== X-Received: by 2002:a05:6000:2884:b0:428:5659:8209 with SMTP id ffacd0b85a97d-429a7e70a2dmr3027998f8f.33.1761651869798; Tue, 28 Oct 2025 04:44:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGyXE+ZbJqKkcHGTJRy18t1zGFuBb+B7v9XQOcnBPexkM3A7qCTY9Nfp5EIuwmLxdM+lc8PzA== X-Received: by 2002:a05:6000:2884:b0:428:5659:8209 with SMTP id ffacd0b85a97d-429a7e70a2dmr3027972f8f.33.1761651869226; Tue, 28 Oct 2025 04:44:29 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-429952df6b9sm20717708f8f.44.2025.10.28.04.44.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 04:44:27 -0700 (PDT) Date: Tue, 28 Oct 2025 12:44:26 +0100 From: Stefano Brivio To: Yumei Huang Subject: Re: [PATCH v6 4/4] tcp: Update data retransmission timeout Message-ID: <20251028124426.534fd236@elisabeth> In-Reply-To: References: <20251017062838.21041-1-yuhuang@redhat.com> <20251017062838.21041-5-yuhuang@redhat.com> <20251024010438.16e19757@elisabeth> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: dA5zgG0802BiYjWkMjpZaSqePi-ao7Z8kTo3h4XmzzY_1761651870 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: X5WUZQTAKKHVNIW5ICET6KRCC7WFTKFZ X-Message-ID-Hash: X5WUZQTAKKHVNIW5ICET6KRCC7WFTKFZ X-MailFrom: sbrivio@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, 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: > > =20 > > > Use an exponential backoff timeout for data retransmission according > > > to RFC 2988 and RFC 6298. Set the initial RTO to one second as discus= sed > > > in Appendix A of RFC 6298. > > > > > > Also combine the macros defining the initial RTO for both SYN and ACK= . > > > > > > 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 h= andshake > > > - * (flag ACK_FROM_TAP_DUE without ESTABLISHED event) within this t= ime, resend > > > - * SYN. It's the starting timeout for the first SYN retry. If this= 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, aft= er sending > > > - * data (flag ACK_FROM_TAP_DUE with ESTABLISHED event), re-send da= ta from the > > > - * socket and reset sequence to what was acknowledged. If this per= sists for > > > - * more than TCP_MAX_RETRIES times in a row, reset the connection > > > + * - RTO_INIT: if no ACK segment was received from tap/guest, either= during > > > + * handshake (flag ACK_FROM_TAP_DUE without ESTABLISHED event) or = after > > > + * sending data (flag ACK_FROM_TAP_DUE with ESTABLISHED event), re= -send data > > > + * from the socket and reset sequence to what was acknowledged. Th= is is the > > > + * timeout for the first retry, in seconds. If this persists too m= any times > > > + * in a row, reset the connection: TCP_MAX_RETRIES for established > > > + * connections, or (tcp_syn_retries + tcp_syn_linear_timeouts) dur= ing the > > > + * handshake. > > > * > > > * - FIN_TIMEOUT: if a FIN segment was sent to tap/guest (flag ACK_F= ROM_TAP_DUE > > > * with TAP_FIN_SENT event), and no ACK is received within this ti= me, reset > > > @@ -342,8 +340,7 @@ enum { > > > #define WINDOW_DEFAULT 14600 /* RFC = 6928 */ > > > > > > #define ACK_INTERVAL 10 /* ms */ > > > -#define SYN_TIMEOUT_INIT 1 /* s */ > > > -#define ACK_TIMEOUT 2 > > > +#define RTO_INIT 1 /* s, RFC 6298 = */ > > > #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_timeouts) > > > - it.it_value.tv_sec =3D SYN_TIMEOUT_INIT= ; > > > + it.it_value.tv_sec =3D RTO_INIT; > > > else > > > - it.it_value.tv_sec =3D SYN_TIMEOUT_INIT= << > > > + it.it_value.tv_sec =3D RTO_INIT << > > > (conn->retries - c->tcp.syn_lin= ear_timeouts); > > > } > > > else > > > - it.it_value.tv_sec =3D ACK_TIMEOUT; > > > + it.it_value.tv_sec =3D RTO_INIT << conn->retrie= s; =20 > > > > 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. =20 >=20 > 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: =09it.it_value.tv_sec =3D RTO_INIT =09if (!(conn->events & ESTABLISHED)) { =09=09if (conn->retries >=3D c->tcp.syn_linear_timeouts) =09=09=09it.it_value.tv_sec <<=3D (conn->retries - =09=09=09=09=09=09c->tcp.syn_linear_timeouts); but anyway, see below. > But it seems more complicated. What do you think? Or maybe, building on my latest comment to 3/4: =09=09int factor =3D conn->retries; =09=09if (!(conn->events & ESTABLISHED)) =09=09=09factor -=3D c->tcp.syn_linear_timeouts; =09=09it.it_value.tv_sec =3D RTO_INIT << MAX(factor, 0); ? > > =20 > > > } else if (CONN_HAS(conn, SOCK_FIN_SENT | TAP_FIN_ACKED)) { > > > it.it_value.tv_sec =3D FIN_TIMEOUT; > > > } else { =20 > > > > 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 helper > > from 2/4, but it's not a strong preference from my side, as the series > > makes sense in any case. =20 >=20 > Reading tcp_rto_max_ms can be easy with the helper. My concern is > about the way we get the total time for retries. >=20 > I used to do it like this in v2, > https://archives.passt.top/passt-dev/20251010074700.22177-4-yuhuang@redha= t.com/: >=20 > +#define RETRY_ELAPSED(timeout_init, retries) \ > + ((timeout_init) * ((1 << ((retries) + 1)) - 2)) >=20 > Though the formula is not quite right, we could refine it as below: >=20 > #define RETRY_ELAPSED(retries) ((RTO_INIT) * ((1 << ((retries) + 1)) - 1)= ) >=20 > Does it make sense to get the time this way? Well, it also depends on c->tcp.syn_linear_timeouts, right? 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: --- =09=09it.it_value.tv_sec =3D MIN(it.it_value.tv_sec, c->tcp.rto_max); =09} ... =09if (timerfd_settime(conn->timer, 0, &it, NULL)) =09=09flow_perror(conn, "failed to set timer"); --- --=20 Stefano