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=bwdlaIqW; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id E12355A004E for ; Mon, 12 Jan 2026 05:00:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202512; t=1768190404; bh=aPJIHu2TDPj8EPREFHHHHOCdxprzkrvBKWRuf5JOs2E=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bwdlaIqW/wCXZE+0p82CFhauicBy6IY1R3IfUDKf+/wgPIdS/bYs+4YoxCu0CcsVH 3RK0fXy5dWIBcm3axPxVVoXPljZaZ4fZu4RgKyR4YuXtVC0XAif0zTFs/BQSDYiLN5 yaYR3cOiyajOg0Kz9JHLAbsCWv8JJ/bvNvCJmrHUvIQSEjbf3F1cGUjmBtu+UNdPS1 Mt8q/sAqH1wJJSvHjvmmhW3poc4sk5YLlbceYsyGu/J5zQe8GOgwDJnjsl1Ilv4E8H agIa8f/ZtEzRXHFjJCYJGjSvrEBshdvf7f9JR5H2+0YvAhBPZwV5k7Zt49zRONFGSX TNtY0A+cK3cvw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4dqJYc3yJwz4wCZ; Mon, 12 Jan 2026 15:00:04 +1100 (AEDT) Date: Mon, 12 Jan 2026 14:59:59 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH] tcp: cleanup timer creation Message-ID: References: <20260109112034.2089680-1-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="EbJWAPjUYgnUxQaf" Content-Disposition: inline In-Reply-To: <20260109112034.2089680-1-lvivier@redhat.com> Message-ID-Hash: HJNUQTLEZF6OUCFNZ744A3QWBBL6JMIF X-Message-ID-Hash: HJNUQTLEZF6OUCFNZ744A3QWBBL6JMIF 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: --EbJWAPjUYgnUxQaf Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 09, 2026 at 12:20: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 e7fa85f346b2..58e5064db6b6 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -581,30 +581,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 --EbJWAPjUYgnUxQaf Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmlkcb4ACgkQzQJF27ox 2GcxlA//Sm2Un4bAcz6ZyEAXCK3Z1q8c9X2tC7jKSiH9Hlu8V+SiYBkRzds+XlAU k8P0x1yeqx7AkZQqtzSAszk+sSKfSUsDqXeXkqEaNXmeMGPDdzeY/D0Df+7y40U4 4NpbFEuRfcSeTmEgsk/0Q02Q/ImxIDWeLvseJT3myS2OSoh2ZT7j6GsDT4Byhmwh ydHtyoc+/n83uPBi3iGMf1ORGp7/JUY1n8sF1VPUTyro2viEk9nGUZ20n3kZnpza sXZXkSC7+yOspJhGekoargfnKJZqKYdMG8L0ju3SP4f7p3UQLlwi7RGrkMNcXzeK /o0kwNh4XAPFcNJJXnobqZtyn5nvuKLseAwDDrYF0zDe+OLPqvaBTStqw82/RnA8 th/5RjuUIGC/N4A62kQzuXYHc/AKtnelh8SdpIjJjNuueGH4DDjl+1dK50JWOrt+ NQzcm3uKfYkWcM/03kNEHWDAvUvGxaqbxJXM0NXGSqri1FSw4c6+lusUm1bxVgqh Zp9c6ZJ3g1QC3wMLlWikV1/VEP/2vtxRIrvdNlf/a/QQLhYYZKpwRuERev4JN9vt F7YzfqrO2EEpczg5TAsUUPGr+yGaHvJxQSzqXhaLZWhIlC4LEfRxiDinXZn82zKb /nUZYjRrCnFCxg5xAZHZduiPLshpJnwGXpVPevbAAlCjiCujLGQ= =1hRw -----END PGP SIGNATURE----- --EbJWAPjUYgnUxQaf--