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=i6VfNdHB; 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 2AD285A026F for ; Fri, 17 Oct 2025 10:22:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1760689331; 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=bLZbCVroVjnKdMRLftWEXJEmR8DSNSbAdY2gz6S9xlk=; b=i6VfNdHBAVrCoPAL9g+4WKIi9o2vml9TG8tFg+ByD8yPNHdOHTo68EvzCrWpUcrWSQLO9B jCo15i5017IQO46HAQvB3Gd2vq0xawIV0SDnvM3podYF0Hk5GiTv+CzE6MpAQOmAKTnVo3 +eerPySqE4E04RwmkKLkNvrJfWPXLk0= 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-316-PZeS_7APOKOqX532mBO2jA-1; Fri, 17 Oct 2025 04:22:09 -0400 X-MC-Unique: PZeS_7APOKOqX532mBO2jA-1 X-Mimecast-MFC-AGG-ID: PZeS_7APOKOqX532mBO2jA_1760689328 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-634cdb5d528so3593550a12.1 for ; Fri, 17 Oct 2025 01:22:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760689328; x=1761294128; 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=bLZbCVroVjnKdMRLftWEXJEmR8DSNSbAdY2gz6S9xlk=; b=fJS1C4D29mYbL0kIzKLWsy/gI6fntgKjA8rX2xAqGtT1dNcMZJ2qkuahdiH0DdP8sg xoJsKbKPQWiXRTKT68VChQMimrVXKxeaXxgC0+hK58gHwVMFY7yB+a2aDTECh0iZ37p+ KumFbPED2gI2p3VDVIdaVahYSTNTiZgdoj62kAvsZDHFFJ7BPJaf1EPXwGjqZodjh1D9 EuAqlZUxU39de2iUKF9g/5LgjKW9hvouhEPkvUfKDcRYXMCwhDlk8vDafeCur5NMNUSz eBxtGds5ngF14RLmR7zIQpLITzC2OT3HIpJ4+jG1YYvW7Np4Qhu1zjmcDlytZBqoZUoq ZyRw== X-Gm-Message-State: AOJu0Ywj49ZAcbuiNK9HXvK0/QanSUifRosddus/Di+tfhKkeRxVH/TX n/H5Ip5ZNNv7WZIFX1JFru2kYmsH53r4W0uy80HV6VGEw6uHA3VXf+qgRH8uycKj0eRBktSHoIo RcYE3fyIfAdYlfi00kcZm52LNpCKIZkVP0ASFjZm0CuuM0E9YX3ehI6cr0tI4ehdGcjdLGLQgsp g8Xis6bKANaf1TTSw3fMm3y6UeXKUB X-Gm-Gg: ASbGnctAE4D3lcqUr7hrwYyWFwWOkllU0bz1ChpJ2BUppAL56dTQI1dth1bmA4a2JdS hPymW0eGml14g4d5ktE+05e+6VcWu1nt2DhaLeL8ljlwQ///Q4gtJyA0iAIJ2NogfotkmENlNDS 1vmxFUNwuZ4r6lYFxPeSA+ynetLiyhnA0GNsIp4OEPWsNVIXrb4zIa4um4 X-Received: by 2002:aa7:c302:0:b0:61c:b23f:417e with SMTP id 4fb4d7f45d1cf-63bfcdd507bmr5158857a12.2.1760689328139; Fri, 17 Oct 2025 01:22:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFObcNsjKSTzl0i4CWR8rct04M2rXFab/7RRNdcb8zRgVexqe1suUytcCOLHm6aWyrcQOZbLofcMUUrhjD2IMk= X-Received: by 2002:aa7:c302:0:b0:61c:b23f:417e with SMTP id 4fb4d7f45d1cf-63bfcdd507bmr5158827a12.2.1760689327578; Fri, 17 Oct 2025 01:22:07 -0700 (PDT) MIME-Version: 1.0 References: <20251017042743.15519-1-yuhuang@redhat.com> <20251017042743.15519-4-yuhuang@redhat.com> In-Reply-To: From: Yumei Huang Date: Fri, 17 Oct 2025 16:21:56 +0800 X-Gm-Features: AS18NWA5jZBK7Yxou0DXNFy73gQJ1G98VECTYF82YdNElB7S3wIwE365LqC6HPU Message-ID: Subject: Re: [PATCH v5 3/4] tcp: Resend SYN for inbound connections To: David Gibson X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: F6-PgyUO0D3fdcwhmXn7TwzjXunF2eD3laWPLs8DaRY_1760689328 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Message-ID-Hash: BFYHQTYXIZ5GLB372BCGZI5C6TMJB4E2 X-Message-ID-Hash: BFYHQTYXIZ5GLB372BCGZI5C6TMJB4E2 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 Fri, Oct 17, 2025 at 3:48=E2=80=AFPM David Gibson wrote: > > On Fri, Oct 17, 2025 at 01:46:15PM +0800, Yumei Huang wrote: > > On Fri, Oct 17, 2025 at 12:44=E2=80=AFPM David Gibson > > wrote: > > > > > > On Fri, Oct 17, 2025 at 12:27:42PM +0800, Yumei Huang wrote: > > > > If a client connects while guest is not connected or ready yet, > > > > resend SYN instead of just resetting connection after 10 seconds. > > > > > > > > Use the same backoff calculation for the timeout as linux kernel. > > > > > > > > Link: https://bugs.passt.top/show_bug.cgi?id=3D153 > > > > Signed-off-by: Yumei Huang > > > > --- > > > > tcp.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++-------- > > > > tcp.h | 5 +++++ > > > > 2 files changed, 52 insertions(+), 8 deletions(-) > > > > > > > > diff --git a/tcp.c b/tcp.c > > > > index 2ec4b0c..71e2da0 100644 > > > > --- a/tcp.c > > > > +++ b/tcp.c > > > > @@ -179,9 +179,11 @@ > > > > * > > > > * Timeouts are implemented by means of timerfd timers, set based = on flags: > > > > * > > > > - * - SYN_TIMEOUT: if no ACK is received from tap/guest during hand= shake (flag > > > > - * ACK_FROM_TAP_DUE without ESTABLISHED event) within this time,= reset the > > > > - * connection > > > > + * - 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 > > > > @@ -340,7 +342,7 @@ enum { > > > > #define WINDOW_DEFAULT 14600 /* RF= C 6928 */ > > > > > > > > #define ACK_INTERVAL 10 /* ms */ > > > > -#define SYN_TIMEOUT 10 /* s */ > > > > +#define SYN_TIMEOUT_INIT 1 /* s */ > > > > #define ACK_TIMEOUT 2 > > > > #define FIN_TIMEOUT 60 > > > > #define ACT_TIMEOUT 7200 > > > > @@ -365,6 +367,9 @@ uint8_t tcp_migrate_rcv_queue [TCP_= MIGRATE_RCV_QUEUE_MAX]; > > > > > > > > #define TCP_MIGRATE_RESTORE_CHUNK_MIN 1024 /* Try smaller w= hen above this */ > > > > > > > > +#define TCP_SYN_RETRIES "/proc/sys/net/ipv4/tcp_syn_r= etries" > > > > +#define TCP_SYN_LINEAR_TIMEOUTS "/proc/sys/net/ipv4/tcp_syn_l= inear_timeouts" \ > > > > + > > > > /* "Extended" data (not stored in the flow table) for TCP flow mig= ration */ > > > > static struct tcp_tap_transfer_ext migrate_ext[FLOW_MAX]; > > > > > > > > @@ -581,8 +586,13 @@ static void tcp_timer_ctl(const struct ctx *c,= struct tcp_tap_conn *conn) > > > > if (conn->flags & ACK_TO_TAP_DUE) { > > > > it.it_value.tv_nsec =3D (long)ACK_INTERVAL * 1000 * 1= 000; > > > > } else if (conn->flags & ACK_FROM_TAP_DUE) { > > > > - if (!(conn->events & ESTABLISHED)) > > > > - it.it_value.tv_sec =3D SYN_TIMEOUT; > > > > + if (!(conn->events & ESTABLISHED)) { > > > > + if (conn->retries < c->tcp.syn_linear_timeout= s) > > > > + it.it_value.tv_sec =3D SYN_TIMEOUT_IN= IT; > > > > + else > > > > + it.it_value.tv_sec =3D SYN_TIMEOUT_IN= IT << > > > > + (conn->retries - c->tcp.syn_l= inear_timeouts); > > > > + } > > > > else > > > > it.it_value.tv_sec =3D ACK_TIMEOUT; > > > > } else if (CONN_HAS(conn, SOCK_FIN_SENT | TAP_FIN_ACKED)) { > > > > @@ -2409,8 +2419,17 @@ void tcp_timer_handler(const struct ctx *c, = union epoll_ref ref) > > > > tcp_timer_ctl(c, conn); > > > > } else if (conn->flags & ACK_FROM_TAP_DUE) { > > > > if (!(conn->events & ESTABLISHED)) { > > > > - flow_dbg(conn, "handshake timeout"); > > > > - tcp_rst(c, conn); > > > > + if (conn->retries >=3D TCP_MAX_RETRIES || > > > > + conn->retries >=3D (c->tcp.tcp_syn_retrie= s + > > > > + c->tcp.syn_linear_timeo= uts)) { > > > > + flow_dbg(conn, "handshake timeout"); > > > > + tcp_rst(c, conn); > > > > + } else { > > > > + flow_trace(conn, "SYN timeout, retry"= ); > > > > + tcp_send_flag(c, conn, SYN); > > > > + conn->retries++; > > > > + tcp_timer_ctl(c, conn); > > > > + } > > > > } else if (CONN_HAS(conn, SOCK_FIN_SENT | TAP_FIN_ACK= ED)) { > > > > flow_dbg(conn, "FIN timeout"); > > > > tcp_rst(c, conn); > > > > @@ -2766,6 +2785,24 @@ static socklen_t tcp_probe_tcp_info(void) > > > > return sl; > > > > } > > > > > > > > +/** > > > > + * tcp_syn_params_init() - Get initial syn params for inbound conn= ection > > > > > > Stefano's comment wasn't 100% clear, but I believe he was suggesting > > > s/syn params/SYN parameters/ > > > in the comment here for clarity. > > > > Oops, I missed this one. > > > > > > > + * @c: Execution context > > > > +*/ > > > > +void tcp_syn_params_init(struct ctx *c) > > > > +{ > > > > + intmax_t tcp_syn_retries, syn_linear_timeouts; > > > > + > > > > + tcp_syn_retries =3D read_file_integer(TCP_SYN_RETRIES, 8); > > > > + syn_linear_timeouts =3D read_file_integer(TCP_SYN_LINEAR_TIME= OUTS, 1); > > > > + > > > > + c->tcp.tcp_syn_retries =3D MIN(tcp_syn_retries, UINT8_MAX); > > > > + c->tcp.syn_linear_timeouts =3D MIN(syn_linear_timeouts, UINT8= _MAX); > > > > + > > > > + debug("TCP SYN parameters: retries=3D%"PRIu8", linear_timeout= s=3D%"PRIu8, > > > > + c->tcp.tcp_syn_retries, c->tcp.syn_linear_timeouts); > > > > +} > > > > + > > > > /** > > > > * tcp_init() - Get initial sequence, hash secret, initialise per-= socket data > > > > * @c: Execution context > > > > @@ -2776,6 +2813,8 @@ int tcp_init(struct ctx *c) > > > > { > > > > ASSERT(!c->no_tcp); > > > > > > > > + tcp_syn_params_init(c); > > > > + > > > > tcp_sock_iov_init(c); > > > > > > > > memset(init_sock_pool4, 0xff, sizeof(init_sock_pool= 4)); > > > > diff --git a/tcp.h b/tcp.h > > > > index 234a803..bb58324 100644 > > > > --- a/tcp.h > > > > +++ b/tcp.h > > > > @@ -59,12 +59,17 @@ union tcp_listen_epoll_ref { > > > > * @fwd_out: Port forwarding configuration for outbound pa= ckets > > > > * @timer_run: Timestamp of most recent timer run > > > > * @pipe_size: Size of pipes for spliced connections > > > > + * @tcp_syn_retries: Number of times initial SYNs during handshake > > > > > > Perhaps, > > > > > > "Number of SYN retries using exponential backoff" > > > > It's not actually retries using exponential backoff. It's the total > > number of retries, including linear backoff and exponential backoff. > > That's what ip-sysctl.rst says, but as we discussed the other day, the > kernel code and behaviour seem to treat it as just the retries after > exhausting linear_timeouts. You are right. I forgot about that. > > > I got the "Number of times initial SYNs" from the kernel doc > > https://www.kernel.org/doc/Documentation/networking/ip-sysctl.rst. > > Right, but by cutting off the "will be retransmitted", it's no longer > grammatical (admittedly it's a pretty long confusing sentence). > > > Maybe "Number of SYN retries during handshake" ? What do you think? > > That would be good if the description in ip-sysctl.rst was accurate, > but it seems not to be. I probably should wait a bit before sending the v6. Anyway, I will wait and send the v7 next week to see if more comments from Stefano. Thanks for all the reviews and comments. > > > > > > > > + * @syn_linear_timeouts: Number of SYN retries using linear backof= f timeout > > > > + * before switching to exponential backoff tim= eout > > > > */ > > > > struct tcp_ctx { > > > > struct fwd_ports fwd_in; > > > > struct fwd_ports fwd_out; > > > > struct timespec timer_run; > > > > size_t pipe_size; > > > > + uint8_t tcp_syn_retries; > > > > + uint8_t syn_linear_timeouts; > > > > }; > > > > > > > > #endif /* TCP_H */ > > > > -- > > > > 2.47.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 othe= r way > > > | around. > > > http://www.ozlabs.org/~dgibson > > > > > > > > -- > > Thanks, > > > > Yumei Huang > > > > -- > 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