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=hfVSl39w; 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 9AB255A0272 for ; Fri, 31 Jul 2026 18:46:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785516398; 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=/TJjB/Mfn8OmYkR3/zIrHdZcCC3JjEVW4i44o0Df39c=; b=hfVSl39w0J+K3V+GmBvESGihNvCqY4Fx3L9CpcuKoZgQ953bVpe2HNhymoL4xmdPZUYXx0 C2lBs9clH6FMDZcS9/T1t9F7O/Sl87yl5LtMbMvNeojF9FuANuh2Y2lQPE7qXTwy3GPRVb 2ZDqlNibwjk+3ZIX0dHI4lTkSiHqQzo= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-108-pdWA4H_6PoSHoIOrdpV5zA-1; Fri, 31 Jul 2026 12:46:36 -0400 X-MC-Unique: pdWA4H_6PoSHoIOrdpV5zA-1 X-Mimecast-MFC-AGG-ID: pdWA4H_6PoSHoIOrdpV5zA_1785516396 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2087B1956094 for ; Fri, 31 Jul 2026 16:46:36 +0000 (UTC) Received: from lenovo-t14s.redhat.corp (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5EE19423; Fri, 31 Jul 2026 16:46:35 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH 5/7] ctx: Remove epollfd from context structure Date: Fri, 31 Jul 2026 18:46:26 +0200 Message-ID: <20260731164628.3556997-6-lvivier@redhat.com> In-Reply-To: <20260731164628.3556997-1-lvivier@redhat.com> References: <20260731164628.3556997-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 4032UteX9Vppey--DpnlfVZI4DmasZ1HIb8AWLuTG4s_1785516396 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: L3E5QP7ZV6N25B2GGBQ75ILTLBNGIPOU X-Message-ID-Hash: L3E5QP7ZV6N25B2GGBQ75ILTLBNGIPOU X-MailFrom: lvivier@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: Laurent Vivier 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: The main epoll file descriptor is now managed by the threading subsystem, so there's no need to store it in the context structure. All code that previously accessed c->epollfd now calls threading_epollfd(THREADING_ID_DEFAULT) to get the main event loop's epoll file descriptor. Signed-off-by: Laurent Vivier --- conf.c | 10 +++++++--- fwd.c | 4 +++- netlink.c | 4 +++- passt.c | 1 - passt.h | 2 -- pasta.c | 3 ++- pif.c | 3 ++- repair.c | 12 ++++++++---- tap.c | 9 ++++++--- tcp_splice.c | 1 + vhost_user.c | 9 +++++---- 11 files changed, 37 insertions(+), 21 deletions(-) diff --git a/conf.c b/conf.c index faf268140321..733bad4228cb 100644 --- a/conf.c +++ b/conf.c @@ -53,6 +53,7 @@ #include "pesto.h" #include "serialise.h" #include "parse.h" +#include "threading.h" #define NETNS_RUN_DIR "/run/netns" @@ -1164,7 +1165,8 @@ static void conf_sock_listen(const struct ctx *c) die_perror("Couldn't listen on configuration socket"); ref.fd = c->fd_control_listen; - if (epoll_add(c->epollfd, EPOLLIN | EPOLLET, ref)) + if (epoll_add(threading_epollfd(THREADING_ID_DEFAULT), + EPOLLIN | EPOLLET, ref)) die_perror("Couldn't add configuration socket to epoll"); } @@ -2117,7 +2119,8 @@ static int conf_recv_rules(const struct ctx *c, int fd) static void conf_close(struct ctx *c) { debug("Closing configuration socket"); - epoll_ctl(c->epollfd, EPOLL_CTL_DEL, c->fd_control, NULL); + epoll_ctl(threading_epollfd(THREADING_ID_DEFAULT), EPOLL_CTL_DEL, + c->fd_control, NULL); close(c->fd_control); c->fd_control = -1; } @@ -2180,7 +2183,8 @@ retry: warn_perror("Can't get configuration client credentials"); c->fd_control = ref.fd = fd; - rc = epoll_add(c->epollfd, EPOLLIN | EPOLLET, ref); + rc = epoll_add(threading_epollfd(THREADING_ID_DEFAULT), + EPOLLIN | EPOLLET, ref); if (rc < 0) { warn_perror("epoll_ctl() on configuration socket"); goto fail; diff --git a/fwd.c b/fwd.c index 5679a3d606ea..fa6679ea1b2e 100644 --- a/fwd.c +++ b/fwd.c @@ -33,6 +33,7 @@ #include "netlink.h" #include "arp.h" #include "ndp.h" +#include "threading.h" #define NEIGH_TABLE_SLOTS 1024 #define NEIGH_TABLE_SIZE (NEIGH_TABLE_SLOTS / 2) @@ -377,7 +378,8 @@ static int fwd_sync_one(const struct ctx *c, uint8_t pif, unsigned idx, /* We don't want to listen on this port */ if (fd >= 0) { /* We already are, so stop */ - epoll_del(c->epollfd, fd); + epoll_del(threading_epollfd(THREADING_ID_DEFAULT), + fd); close(fd); socks[port - rule->first] = -1; } diff --git a/netlink.c b/netlink.c index 8d20dbb57fb8..8fffe490b6f3 100644 --- a/netlink.c +++ b/netlink.c @@ -37,6 +37,7 @@ #include "ip.h" #include "netlink.h" #include "epoll_ctl.h" +#include "threading.h" /* Same as RTA_NEXT() but for nexthops: RTNH_NEXT() doesn't take 'attrlen' */ #define RTNH_NEXT_AND_DEC(rtnh, attrlen) \ @@ -1292,7 +1293,8 @@ int nl_neigh_notify_init(const struct ctx *c) } ev.data.u64 = ref.u64; - if (epoll_ctl(c->epollfd, EPOLL_CTL_ADD, nl_sock_neigh, &ev) == -1) { + if (epoll_ctl(threading_epollfd(THREADING_ID_DEFAULT), EPOLL_CTL_ADD, + nl_sock_neigh, &ev) == -1) { warn_perror("epoll_ctl() on neighbour notifier socket failed"); close(nl_sock_neigh); nl_sock_neigh = -1; diff --git a/passt.c b/passt.c index 57290a5a7c6e..469e2525f545 100644 --- a/passt.c +++ b/passt.c @@ -376,7 +376,6 @@ int main(int argc, char **argv) madvise(pkt_buf, sizeof(pkt_buf), MADV_HUGEPAGE); threading_init(); - c->epollfd = threading_epollfd(THREADING_ID_DEFAULT); if (getrlimit(RLIMIT_NOFILE, &limit)) die_perror("Failed to get maximum value of open files limit"); diff --git a/passt.h b/passt.h index 00ef5a8f85e5..40abc5995ffd 100644 --- a/passt.h +++ b/passt.h @@ -190,7 +190,6 @@ struct ip6_ctx { * @no_netns_quit: In pasta mode, don't exit if fs-bound namespace is gone * @netns_base: Base name for fs-bound namespace, if any, in pasta mode * @netns_dir: Directory of fs-bound namespace, if any, in pasta mode - * @epollfd: File descriptor for epoll instance * @fd_tap_listen: File descriptor for listening AF_UNIX socket, if any * @fd_tap: AF_UNIX socket, tuntap device, or pre-opened socket * @fd_control_listen: Listening control/configuration socket, if any @@ -266,7 +265,6 @@ struct ctx { char netns_base[PATH_MAX]; char netns_dir[PATH_MAX]; - int epollfd; int fd_tap_listen; int fd_tap; int fd_control_listen; diff --git a/pasta.c b/pasta.c index 5aa56b78d262..0a742a4f9abe 100644 --- a/pasta.c +++ b/pasta.c @@ -50,6 +50,7 @@ #include "netlink.h" #include "log.h" #include "epoll_ctl.h" +#include "threading.h" #define HOSTNAME_PREFIX "pasta-" @@ -517,7 +518,7 @@ void pasta_netns_quit_init(const struct ctx *c) ref.fd = fd; - epoll_add(c->epollfd, EPOLLIN, ref); + epoll_add(threading_epollfd(THREADING_ID_DEFAULT), EPOLLIN, ref); } /** diff --git a/pif.c b/pif.c index 8ade587c623a..e0a36413878b 100644 --- a/pif.c +++ b/pif.c @@ -16,6 +16,7 @@ #include "ip.h" #include "inany.h" #include "epoll_ctl.h" +#include "threading.h" const char pif_type_str[][PIF_NAME_SIZE] = { [PIF_NONE] = "", @@ -130,7 +131,7 @@ int pif_listen(const struct ctx *c, uint8_t proto, uint8_t pif, goto fail; } - ret = epoll_add(c->epollfd, EPOLLIN, ref); + ret = epoll_add(threading_epollfd(THREADING_ID_DEFAULT), EPOLLIN, ref); if (ret < 0) goto fail; diff --git a/repair.c b/repair.c index f31ccceed7c6..7560242cf1c1 100644 --- a/repair.c +++ b/repair.c @@ -23,6 +23,7 @@ #include "flow.h" #include "flow_table.h" #include "epoll_ctl.h" +#include "threading.h" #include "repair.h" @@ -58,8 +59,9 @@ void repair_sock_init(const struct ctx *c) } ref.fd = c->fd_repair_listen; - if (epoll_add(c->epollfd, EPOLLIN | EPOLLHUP | EPOLLET, ref)) - err("repair helper socket epoll_ctl(), won't migrate"); + if (epoll_add(threading_epollfd(THREADING_ID_DEFAULT), + EPOLLIN | EPOLLHUP | EPOLLET, ref)) + err_perror("repair helper socket epoll_ctl(), won't migrate"); } /** @@ -115,7 +117,8 @@ int repair_listen_handler(struct ctx *c, uint32_t events) ref.fd = c->fd_repair; - rc = epoll_add(c->epollfd, EPOLLHUP | EPOLLET, ref); + rc = epoll_add(threading_epollfd(THREADING_ID_DEFAULT), + EPOLLHUP | EPOLLET, ref); if (rc < 0) { debug("epoll_ctl() on TCP_REPAIR helper socket"); close(c->fd_repair); @@ -134,7 +137,8 @@ void repair_close(struct ctx *c) { debug("Closing TCP_REPAIR helper socket"); - epoll_ctl(c->epollfd, EPOLL_CTL_DEL, c->fd_repair, NULL); + epoll_ctl(threading_epollfd(THREADING_ID_DEFAULT), EPOLL_CTL_DEL, + c->fd_repair, NULL); close(c->fd_repair); c->fd_repair = -1; } diff --git a/tap.c b/tap.c index 25cde67538ac..d9be6bcc41a0 100644 --- a/tap.c +++ b/tap.c @@ -61,6 +61,7 @@ #include "vhost_user.h" #include "vu_common.h" #include "epoll_ctl.h" +#include "threading.h" /* Maximum allowed frame lengths (including L2 header) */ @@ -1226,7 +1227,7 @@ void tap_sock_reset(struct ctx *c) passt_exit(EXIT_SUCCESS); /* Close the connected socket, wait for a new connection */ - epoll_del(c->epollfd, c->fd_tap); + epoll_del(threading_epollfd(THREADING_ID_DEFAULT), c->fd_tap); close(c->fd_tap); c->fd_tap = -1; if (c->mode == MODE_VU) @@ -1417,7 +1418,8 @@ static void tap_sock_unix_init(const struct ctx *c) ref.fd = c->fd_tap_listen; - epoll_add(c->epollfd, EPOLLIN | EPOLLET, ref); + epoll_add(threading_epollfd(THREADING_ID_DEFAULT), EPOLLIN | EPOLLET, + ref); } /** @@ -1465,7 +1467,8 @@ static void tap_start_connection(const struct ctx *c) break; } - epoll_add(c->epollfd, EPOLLIN | EPOLLRDHUP, ref); + epoll_add(threading_epollfd(THREADING_ID_DEFAULT), + EPOLLIN | EPOLLRDHUP, ref); if (!tap_is_ready(c)) return; diff --git a/tcp_splice.c b/tcp_splice.c index 8617e62cea9a..fc5b6c25670d 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -56,6 +56,7 @@ #include "inany.h" #include "flow.h" #include "epoll_ctl.h" +#include "threading.h" #include "flow_table.h" diff --git a/vhost_user.c b/vhost_user.c index 8ba3949e4e9d..ad316aee12c3 100644 --- a/vhost_user.c +++ b/vhost_user.c @@ -44,6 +44,7 @@ #include "pcap.h" #include "migrate.h" #include "epoll_ctl.h" +#include "threading.h" /* vhost-user version we are compatible with */ #define VHOST_USER_VERSION 1 @@ -736,7 +737,7 @@ static bool vu_get_vring_base_exec(struct vu_dev *vdev, vdev->vq[idx].call_fd = -1; } if (vdev->vq[idx].kick_fd != -1) { - epoll_del(vdev->context->epollfd, vdev->vq[idx].kick_fd); + epoll_del(threading_epollfd(THREADING_ID_DEFAULT), vdev->vq[idx].kick_fd); close(vdev->vq[idx].kick_fd); vdev->vq[idx].kick_fd = -1; } @@ -757,7 +758,7 @@ static void vu_set_watch(const struct vu_dev *vdev, int idx) .queue = idx }; - epoll_add(vdev->context->epollfd, EPOLLIN, ref); + epoll_add(threading_epollfd(THREADING_ID_DEFAULT), EPOLLIN, ref); } /** @@ -802,7 +803,7 @@ static bool vu_set_vring_kick_exec(struct vu_dev *vdev, vu_check_queue_msg_file(vmsg); if (vdev->vq[idx].kick_fd != -1) { - epoll_del(vdev->context->epollfd, vdev->vq[idx].kick_fd); + epoll_del(threading_epollfd(THREADING_ID_DEFAULT), vdev->vq[idx].kick_fd); close(vdev->vq[idx].kick_fd); vdev->vq[idx].kick_fd = -1; } @@ -1095,7 +1096,7 @@ void vu_cleanup(struct vu_dev *vdev) vq->err_fd = -1; } if (vq->kick_fd != -1) { - epoll_del(vdev->context->epollfd, vq->kick_fd); + epoll_del(threading_epollfd(THREADING_ID_DEFAULT), vq->kick_fd); close(vq->kick_fd); vq->kick_fd = -1; } -- 2.54.0