From: Laurent Vivier <lvivier@redhat.com>
To: passt-dev@passt.top
Cc: Laurent Vivier <lvivier@redhat.com>
Subject: [PATCH 5/7] ctx: Remove epollfd from context structure
Date: Fri, 31 Jul 2026 18:46:26 +0200 [thread overview]
Message-ID: <20260731164628.3556997-6-lvivier@redhat.com> (raw)
In-Reply-To: <20260731164628.3556997-1-lvivier@redhat.com>
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 <lvivier@redhat.com>
---
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] = "<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
next prev parent reply other threads:[~2026-07-31 16:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 16:46 [PATCH 0/7] multithreading: Add worker threads for queue pair processing Laurent Vivier
2026-07-31 16:46 ` [PATCH 1/7] vhost_user: Reset vq enable flag in vu_cleanup() Laurent Vivier
2026-07-31 16:46 ` [PATCH 2/7] threading: Add basic threading infrastructure Laurent Vivier
2026-07-31 16:46 ` [PATCH 3/7] passt: Integrate main event loop with " Laurent Vivier
2026-07-31 16:46 ` [PATCH 4/7] flow: Delegate epoll file descriptor management to threading subsystem Laurent Vivier
2026-07-31 16:46 ` Laurent Vivier [this message]
2026-07-31 16:46 ` [PATCH 6/7] vhost-user: Add per-qpair worker threads Laurent Vivier
2026-07-31 16:46 ` [PATCH 7/7] virtio: Prevent crash on virtqueue exhaustion with temporary workaround Laurent Vivier
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=20260731164628.3556997-6-lvivier@redhat.com \
--to=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).