public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Laurent Vivier <lvivier@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 2/3] tcp: Register fds with epoll at flow creation
Date: Mon, 19 Jan 2026 15:48:19 +1100	[thread overview]
Message-ID: <aW23kwct4VdhbfRu@zatzit> (raw)
In-Reply-To: <20260116155223.2717168-3-lvivier@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 3957 bytes --]

On Fri, Jan 16, 2026 at 04:52:22PM +0100, Laurent Vivier wrote:
> Register connection sockets with epoll using empty events
> (events=0) in tcp_conn_from_tap(), tcp_tap_conn_from_sock()
> and tcp_flow_repair_socket().
> 
> This allows tcp_epoll_ctl() to always use EPOLL_CTL_MOD, removing
> the need to check whether fds are already registered. As a result, the
> conditional ADD/MOD logic is no longer needed, simplifying the function.
> 
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>

Couple of queries, but the concept looks good.

> ---
>  flow.c |  1 +
>  tcp.c  | 36 ++++++++++++++----------------------
>  2 files changed, 15 insertions(+), 22 deletions(-)
> 
> diff --git a/flow.c b/flow.c
> index cefe6c8b5b24..532339ce7fe1 100644
> --- a/flow.c
> +++ b/flow.c
> @@ -357,6 +357,7 @@ static void flow_set_state(struct flow_common *f, enum flow_state state)
>   *
>   * Return: true if flow is registered with epoll, false otherwise
>   */
> +/* cppcheck-suppress unusedFunction */
>  bool flow_in_epoll(const struct flow_common *f)
>  {
>  	return f->epollid != EPOLLFD_ID_INVALID;
> diff --git a/tcp.c b/tcp.c
> index 1db861705ddb..d9bca041dea8 100644
> --- a/tcp.c
> +++ b/tcp.c
> @@ -528,37 +528,22 @@ static uint32_t tcp_conn_epoll_events(uint8_t events, uint8_t conn_flags)
>  static int tcp_epoll_ctl(struct tcp_tap_conn *conn)
>  {
>  	uint32_t events;
> -	int m;
>  
>  	if (conn->events == CLOSED) {
> -		if (flow_in_epoll(&conn->f)) {
> -			int epollfd = flow_epollfd(&conn->f);
> +		int epollfd = flow_epollfd(&conn->f);
>  
> -			epoll_del(epollfd, conn->sock);
> -			if (conn->timer != -1)
> -				epoll_del(epollfd, conn->timer);
> -		}
> +		epoll_del(epollfd, conn->sock);
> +		if (conn->timer != -1)
> +			epoll_del(epollfd, conn->timer);
>  
>  		return 0;
>  	}
>  
>  	events = tcp_conn_epoll_events(conn->events, conn->flags);
>  
> -	if (flow_in_epoll(&conn->f)) {
> -		m = EPOLL_CTL_MOD;
> -	} else {
> -		flow_epollid_set(&conn->f, EPOLLFD_ID_DEFAULT);
> -		m = EPOLL_CTL_ADD;
> -	}
> -
> -	if (flow_epoll_set(&conn->f, m, events, conn->sock,
> -			   !TAPSIDE(conn)) < 0) {
> -		int ret = -errno;
> -
> -		if (m == EPOLL_CTL_ADD)
> -			flow_epollid_clear(&conn->f);
> -		return ret;
> -	}
> +	if (flow_epoll_set(&conn->f, EPOLL_CTL_MOD, events, conn->sock,
> +			   !TAPSIDE(conn)) < 0)
> +		return -errno;
>  
>  	return 0;
>  }
> @@ -1710,6 +1695,8 @@ static void tcp_conn_from_tap(const struct ctx *c, sa_family_t af,
>  	conn->sock = s;
>  	conn->timer = -1;
>  	conn->listening_sock = -1;
> +	flow_epollid_set(&conn->f, EPOLLFD_ID_DEFAULT);
> +	flow_epoll_set(&conn->f, EPOLL_CTL_ADD, 0, s, !TAPSIDE(conn));

Do we need to handle errors here?

Because this is conn_from_tap(), we know that !TAPSIDE() will always
be TGTSIDE in this case.

>  	conn_event(c, conn, TAP_SYN_RCVD);
>  
>  	conn->wnd_to_tap = WINDOW_DEFAULT;
> @@ -2433,6 +2420,8 @@ static void tcp_tap_conn_from_sock(const struct ctx *c, union flow *flow,
>  	conn->sock = s;
>  	conn->timer = -1;
>  	conn->ws_to_tap = conn->ws_from_tap = 0;
> +	flow_epollid_set(&conn->f, EPOLLFD_ID_DEFAULT);
> +	flow_epoll_set(&conn->f, EPOLL_CTL_ADD, 0, s, !TAPSIDE(conn));

Same comments as above, except here we know it's INISIDE.

>  	conn_event(c, conn, SOCK_ACCEPTED);
>  
>  	hash = flow_hash_insert(c, TAP_SIDX(conn));
> @@ -3825,6 +3814,9 @@ int tcp_flow_migrate_target(struct ctx *c, int fd)
>  		return 0;
>  	}
>  
> +	flow_epollid_set(&conn->f, EPOLLFD_ID_DEFAULT);
> +	flow_epoll_set(&conn->f, EPOLL_CTL_ADD, 0, conn->sock, !TAPSIDE(conn));
> +
>  	flow_hash_insert(c, TAP_SIDX(conn));
>  	FLOW_ACTIVATE(conn);
>  
> -- 
> 2.52.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 way
				| around.
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2026-01-19  4:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-16 15:52 [PATCH 0/3] Register TCP flows with epoll at creation time Laurent Vivier
2026-01-16 15:52 ` [PATCH 1/3] tcp_splice: Register fds with epoll at flow creation Laurent Vivier
2026-01-19  4:45   ` David Gibson
2026-01-19  8:10     ` Laurent Vivier
2026-01-19  8:36       ` David Gibson
2026-01-16 15:52 ` [PATCH 2/3] tcp: " Laurent Vivier
2026-01-19  4:48   ` David Gibson [this message]
2026-01-19  8:56     ` Laurent Vivier
2026-01-16 15:52 ` [PATCH 3/3] flow: Remove EPOLLFD_ID_INVALID Laurent Vivier
2026-01-19  4:51   ` David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aW23kwct4VdhbfRu@zatzit \
    --to=david@gibson.dropbear.id.au \
    --cc=lvivier@redhat.com \
    --cc=passt-dev@passt.top \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).