From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202512 header.b=Yjo9SmiY; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 512B15A0623 for ; Mon, 12 Jan 2026 05:16:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202512; t=1768191392; bh=wmZzYsSX94PRpXOoa0HaANJYVra8Dffozh/YHTNvm4g=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Yjo9SmiYK3IuBXOWS8Orv51yc1UGjv52zMts+WGI/IGHxJromMCR+TncxcucNCqdJ Ecweg6mrRlpuQEFRzGYPkrZ5A37GXy4WzFXGrn/uddFprqrr8b9xuhnOUo/imlMtb/ wd4bmHBX64bQq3cC3dp49lkhFw4OQ5hJ3nKXfBDA7bYIIba9Qgkk9XxkF8ATa1iSSt pTUn7NadYoOhE1L40D6VIPReQx59XNZ5MjUrde+k3aaHbj0YGLgX79HbWZHs5HiqJ7 xEmXamSX5lelyz83qX80v1q484KFeBMneNyxutS1AkJIQKW1ugrMk/uaIiCAyPqaLc JURUzXpJhxH+A== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4dqJwc079Xz4wCZ; Mon, 12 Jan 2026 15:16:31 +1100 (AEDT) Date: Mon, 12 Jan 2026 15:09:47 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v3 2/6] tcp: cleanup timer creation Message-ID: References: <20260109165438.2492285-1-lvivier@redhat.com> <20260109165438.2492285-3-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="NyUrK6q/S4QYfLOc" Content-Disposition: inline In-Reply-To: <20260109165438.2492285-3-lvivier@redhat.com> Message-ID-Hash: TH572WA5PKETJN6QYGRHKVMTO7MWYWS6 X-Message-ID-Hash: TH572WA5PKETJN6QYGRHKVMTO7MWYWS6 X-MailFrom: dgibson@gandalf.ozlabs.org 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 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: --NyUrK6q/S4QYfLOc Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 09, 2026 at 05:54:34PM +0100, Laurent Vivier wrote: > Refactor tcp_timer_ctl() to use the epoll_add() helper instead of > manually constructing epoll_event and calling epoll_ctl() directly. >=20 > Also separate the error handling for timerfd_create() failure (-1) > from fd overflow (> FD_REF_MAX) to provide more specific debug > messages. The overflow case now logs the actual fd value, using > flow_dbg_perror() in this case was not correct (no errno set). >=20 > Delay setting conn->timer until epoll_add() succeeds, removing > redundant conn->timer =3D -1 assignments in error paths since the > timer is already -1 when we enter this block. >=20 > Signed-off-by: Laurent Vivier Reviewed-by: David Gibson > --- > tcp.c | 32 +++++++++++++++++--------------- > 1 file changed, 17 insertions(+), 15 deletions(-) >=20 > diff --git a/tcp.c b/tcp.c > index 5141cdc7e839..4b746b4ca16c 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -569,30 +569,32 @@ static void tcp_timer_ctl(const struct ctx *c, stru= ct tcp_tap_conn *conn) > return; > =20 > if (conn->timer =3D=3D -1) { > - union epoll_ref ref =3D { .type =3D EPOLL_TYPE_TCP_TIMER, > - .flow =3D FLOW_IDX(conn) }; > - struct epoll_event ev =3D { .data.u64 =3D ref.u64, > - .events =3D EPOLLIN | EPOLLET }; > - int epollfd =3D flow_epollfd(&conn->f); > + union epoll_ref ref; > int fd; > =20 > fd =3D timerfd_create(CLOCK_MONOTONIC, 0); > - if (fd =3D=3D -1 || fd > FD_REF_MAX) { > + if (fd =3D=3D -1) { > flow_dbg_perror(conn, "failed to get timer"); > - if (fd > -1) > - close(fd); > - conn->timer =3D -1; > return; > } > - conn->timer =3D fd; > - ref.fd =3D conn->timer; > + if (fd > FD_REF_MAX) { > + flow_dbg(conn, "timer fd overflow (%d > %d)", > + fd, FD_REF_MAX); > + close(fd); > + return; > + } > =20 > - if (epoll_ctl(epollfd, EPOLL_CTL_ADD, conn->timer, &ev)) { > - flow_dbg_perror(conn, "failed to add timer"); > - close(conn->timer); > - conn->timer =3D -1; > + ref.type =3D EPOLL_TYPE_TCP_TIMER; > + ref.flow =3D FLOW_IDX(conn); > + ref.fd =3D fd; > + if (epoll_add(flow_epollfd(&conn->f), EPOLLIN | EPOLLET, > + ref) < 0) { > + flow_dbg(conn, "failed to add timer"); > + close(fd); > return; > } > + > + conn->timer =3D fd; > } > =20 > if (conn->flags & ACK_TO_TAP_DUE) { > --=20 > 2.52.0 >=20 --=20 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 way | around. http://www.ozlabs.org/~dgibson --NyUrK6q/S4QYfLOc Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmlkdAoACgkQzQJF27ox 2GclPxAAnd+Qj00jM1fzEPPWHtPTn1PZA74ooDv2lQrpd51AOwIhqiKfQDxBxQwG 70YDdsr/HmN8i0HkEwn4TC+ZBnsdtWWLxo/Iy3OkTVY9uh6H43JhAMeJE8ZZXJ3f ZhTcLLeN+lspjrh7t6yzpFUUHJh5wMfCvJ9YjJ2rtKTXQAyk3tryxtChJuqoy7QL Qlp9zXaOooYH8trNfaI8i/m7JYZrxqkFdHPvMRimiBM1sO545PIRjPw72uwslFhK KhKGqEuzvx5Zn6tZJuNpTdpumekOhZ/+aaAqxGIxupMn18FGfnAeRr90fwvgi871 Fn5UN5A89D0gh+OdypXr70l60RFU38ZoGDPAU11PDE0Z2Ox5UWtmB/Fx/3YLYSKb UqZFFDB2rGd9kHfrQvTd3n6SGhDNcZNMO9nEs82IQ+8TBQP/gPU5gs6+Wk9tf9/j osUBTqEyObceh1/jy9ZEAcr7o6dWJjZPRoHvfywCpM9mUC+xR8jAToKuPD0qg43y y3czp8p2SlngHrpeXuIPdlPddyzM3mHwdLU8RISIDAPVTG6+v141wpGjsWkMICj3 0imlvkk0euEw2AMJDey2q6QlqqfrfmFVnh2vQ+cbk3dpNpuncduBw15Y3sZ6rK5M gUpI+m70rZPYOBYmp1VK5BgQLZblQkvZ9ty3la56GQ6Nrvt1Ahk= =gXB0 -----END PGP SIGNATURE----- --NyUrK6q/S4QYfLOc--