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=D8ghYZSb; 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 615225A026F for ; Mon, 03 Nov 2025 03:57:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762138661; 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=hM3TD8G5JScqsM9K7j7s0Tn7+ERYzCdTiHdM5gA4Xeg=; b=D8ghYZSb3O06zersxq0MZYt5xxkdE4M3gKiWTIeU+QGx+1LcSD7rz2zv4D/sEr2zcAOf8d oKb1GaS7owvpeffGDpvDPOPEM4HcpGP5a9al6IwsfwHpTvqdfiWAqBW9oEm2uds909yFxG 8NZBsHIsHCFmv+V3XeBg061BAYYd73Q= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-321-2X9tK1kxMTiTWslDX4z_XQ-1; Sun, 02 Nov 2025 21:57:40 -0500 X-MC-Unique: 2X9tK1kxMTiTWslDX4z_XQ-1 X-Mimecast-MFC-AGG-ID: 2X9tK1kxMTiTWslDX4z_XQ_1762138659 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-64097bef0e2so1618824a12.3 for ; Sun, 02 Nov 2025 18:57:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762138659; x=1762743459; 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=hM3TD8G5JScqsM9K7j7s0Tn7+ERYzCdTiHdM5gA4Xeg=; b=K7OrA3mij6HRmzW5mm9qgyXVnfWkd2Oy1PvRJgZ0LiOJyw9JhiXhHJ64V0SeihkD3S XVdh6g/6iw/bFjTwJS/UWVTyb58upCiS855LuJZ7O6vzM8viax//qFdCT3lFNFbe5Jgy MZyU1D4RHi+KoApfcVpgUO+tkqBFlUwo/yY7PS5JAKSB16EI0u4vtq2OpZ3HAcOi4say KlITccfcQCvikVO7j6t45llM8qaQEM/YyipNhbCKDAW+1TEO+reqSZ/ElY7A3ld6wb2n uFVwR8oAFpgqeB57yHQi/J0C2MaRP3ZVPrh0nrMq4SqjCHzsvAAjyockqzUdEVG8N/Gx FUww== X-Gm-Message-State: AOJu0YzXneoJj707eSS6z8NFj2tchowe2NpQ5fs9XaGij4dMBMJgURcW fPWCrdbJkeGT7rwd6gCNyS66HyZJd6EyoS43rskSy28dZSlX+9KQcOqvdK8xMISJhXgYUh+kdVB Rs6w2RMZL+gR3qq1vGBd/0wqZhpcSETE7VPjp0csujULH0fYWuSFX61nlbTgvIV1TnGSAbrMxMS FcMEVbJ+7VgMzOY06ULCYgMUNMXUuT X-Gm-Gg: ASbGnct4zV3Erd8nt7hYbm92YAN3BCyPj5bIobssixdIY7tE5IZaasfpWa3zLlvDUJ/ FRtLSU6m7QBTZ38EXVgitm/TwNgWuQzn2BKmlSR0D0wuGmTSyMscuEeCUikZsbcQ6hXJ6cloUze YMEt6j3L6m8400DgdeQzf3AvJfzTTT/Vncz+S+Ix6nWB2QC00mup7yuo/p X-Received: by 2002:a05:6402:2786:b0:640:8bcc:4514 with SMTP id 4fb4d7f45d1cf-6408bcc59d2mr7493107a12.31.1762138658790; Sun, 02 Nov 2025 18:57:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHO1n6R4fYV9uvHOda4idIlnyT4XB/55jY3pSSr5AVgzTxDwvwsJrENbh/sspSsTEe8/LCU5i9c/gz8HyKEg6s= X-Received: by 2002:a05:6402:2786:b0:640:8bcc:4514 with SMTP id 4fb4d7f45d1cf-6408bcc59d2mr7493091a12.31.1762138658304; Sun, 02 Nov 2025 18:57:38 -0800 (PST) MIME-Version: 1.0 References: <20251031054242.7334-1-yuhuang@redhat.com> <20251031054242.7334-5-yuhuang@redhat.com> In-Reply-To: From: Yumei Huang Date: Mon, 3 Nov 2025 10:57:27 +0800 X-Gm-Features: AWmQ_bkI8TODWJwhcaZGv9URH60tlleO0wVlkVkZ9-xz3xSj7rnrVng-LRzMazk Message-ID: Subject: Re: [PATCH v7 4/5] tcp: Update data retransmission timeout To: David Gibson X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: H8tYZNHcQF3cojSlMpOVe7Gi_qfZMAm4Fi2nQp3n6P0_1762138659 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Message-ID-Hash: GRJWD63EIZANWOGYH7VI2EWUHSRMJGGD X-Message-ID-Hash: GRJWD63EIZANWOGYH7VI2EWUHSRMJGGD 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, sbrivio@redhat.com 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 Mon, Nov 3, 2025 at 9:38=E2=80=AFAM David Gibson wrote: > > On Fri, Oct 31, 2025 at 01:42:41PM +0800, Yumei Huang wrote: > > Use an exponential backoff timeout for data retransmission according > > to RFC 2988 and RFC 6298. Set the initial RTO to one second as discusse= d > > 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 > > As reported, the carried over R-b was a minor mistake, since the code > has changed, but here's a new one: > > Reviewed-by: David Gibson > > Small comment below, though. > > > --- > > tcp.c | 30 ++++++++++++------------------ > > 1 file changed, 12 insertions(+), 18 deletions(-) > > > > diff --git a/tcp.c b/tcp.c > > index bada88a..96ee56a 100644 > > --- a/tcp.c > > +++ b/tcp.c > > @@ -179,16 +179,13 @@ > > * > > * Timeouts are implemented by means of timerfd timers, set based on f= lags: > > * > > - * - SYN_TIMEOUT_INIT: if no ACK is received from tap/guest during han= dshake > > - * (flag ACK_FROM_TAP_DUE without ESTABLISHED event) within this tim= e, resend > > - * SYN. It's the starting timeout for the first SYN retry. Retry for > > - * TCP_MAX_RETRIES or (tcp_syn_retries + tcp_syn_linear_timeouts) ti= mes, > > - * reset the connection > > - * > > - * - ACK_TIMEOUT: if no ACK segment was received from tap/guest, after= 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 persi= sts 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 d= uring > > + * handshake (flag ACK_FROM_TAP_DUE without ESTABLISHED event) or af= ter > > + * sending data (flag ACK_FROM_TAP_DUE with ESTABLISHED event), re-s= end data > > + * from the socket and reset sequence to what was acknowledged. This= is the > > + * timeout for the first retry, in seconds. Retry for TCP_MAX_RETRIE= S times > > + * for established connections, or (tcp_syn_retries + > > + * tcp_syn_linear_timeouts) times during the handshake, reset the co= nnection > > * > > * - FIN_TIMEOUT: if a FIN segment was sent to tap/guest (flag ACK_FRO= M_TAP_DUE > > * with TAP_FIN_SENT event), and no ACK is received within this time= , reset > > @@ -342,8 +339,7 @@ enum { > > #define WINDOW_DEFAULT 14600 /* RFC 69= 28 */ > > > > #define ACK_INTERVAL 10 /* ms */ > > -#define SYN_TIMEOUT_INIT 1 /* s, RFC 6928 */ > > -#define ACK_TIMEOUT 2 > > +#define RTO_INIT 1 /* s, RFC 6298 */ > > #define FIN_TIMEOUT 60 > > #define ACT_TIMEOUT 7200 > > > > @@ -589,12 +585,10 @@ static void tcp_timer_ctl(const struct ctx *c, st= ruct tcp_tap_conn *conn) > > if (conn->flags & ACK_TO_TAP_DUE) { > > it.it_value.tv_nsec =3D (long)ACK_INTERVAL * 1000 * 1000; > > } else if (conn->flags & ACK_FROM_TAP_DUE) { > > - if (!(conn->events & ESTABLISHED)) { > > - int exp =3D conn->retries - c->tcp.syn_linear_tim= eouts; > > I didn't spot it in the previous patch, but this is (theoretically) > buggy. conn->retries is unsigned, so the subtraction will be > performed unsigned and only then cast to signed. I think that will > probably do the right thing in practice, but I don't think that's > guaranteed by the C standard (and might even be UB). I'm not sure, but I just googled it. IIUC, the uint8_t (conn->retries and c->tcp.syn_linear_timeouts) will go through integer promotion before subtraction. So the line is like: int exp =3D (int) conn->retries - (int) c->tcp.syn_linear_timeouts; Please correct me if I'm wrong. > > > - it.it_value.tv_sec =3D SYN_TIMEOUT_INIT << MAX(ex= p, 0); > > - } > > - else > > - it.it_value.tv_sec =3D ACK_TIMEOUT; > > + int exp =3D conn->retries; > > This change fixes it, by forcing the cast to a signed int before the > subtraction. It also removes the minor style error I noted in the > previous patch. Given that, I don't think we need to worry about > either of them. > > > + if (!(conn->events & ESTABLISHED)) > > + exp -=3D c->tcp.syn_linear_timeouts; > > + it.it_value.tv_sec =3D RTO_INIT << MAX(exp, 0); > > } else if (CONN_HAS(conn, SOCK_FIN_SENT | TAP_FIN_ACKED)) { > > it.it_value.tv_sec =3D FIN_TIMEOUT; > > } else { > > -- > > 2.49.0 > > > > -- > David Gibson (he or they) | I'll have my music baroque, and my code > david AT gibson.dropbear.id.au | minimalist, thank you, not the other wa= y > | around. > http://www.ozlabs.org/~dgibson --=20 Thanks, Yumei Huang