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=RHeIlbe1; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 1F5635A0772 for ; Fri, 19 Dec 2025 17:45:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1766162731; 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=kRnEk54ZVBihhjxvkzInd1RThypOWdz2f4enLJtuQrM=; b=RHeIlbe1IblNDAh+1OuhBYILg5iuXqnyWHdHayR0Soii9MOSs9wUugaOLMw4GMX6OTAp8h HNoscTJetO1lwZsbIG9WRd5wkDuFnQXaiXWv/dMluIpq3WxCRzBLouDdpMEhuST5/2ybK3 RQa8DQMYZWqS/fY2Q5L6i10K/dMZ3Z4= Received: from mx-prod-mc-03.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-299-rDSg4046MzaEgYDAI_cdww-1; Fri, 19 Dec 2025 11:45:29 -0500 X-MC-Unique: rDSg4046MzaEgYDAI_cdww-1 X-Mimecast-MFC-AGG-ID: rDSg4046MzaEgYDAI_cdww_1766162728 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 843AC1956046 for ; Fri, 19 Dec 2025 16:45:28 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.32.145]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8C4FC180049F; Fri, 19 Dec 2025 16:45:27 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH 5/7] flow: Use epoll_id_to_fd[EPOLLFD_ID_DEFAULT] in flow_epollid_set() Date: Fri, 19 Dec 2025 17:45:16 +0100 Message-ID: <20251219164518.930012-6-lvivier@redhat.com> In-Reply-To: <20251219164518.930012-1-lvivier@redhat.com> References: <20251219164518.930012-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: RJf2kbJGyMUKAdsFmfO4B2-H2a9_8G2vuJNVwSHG0UY_1766162728 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: JI75XREPRUHBDUNRC7PKNNCG566M4RH5 X-Message-ID-Hash: JI75XREPRUHBDUNRC7PKNNCG566M4RH5 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: In tcp_epoll_ctl() and tcp_splice_epoll_ctl(), flow_epollid_set() is called after flow_epoll_set() to set the epollid to EPOLLFD_ID_DEFAULT. When updating an existing flow (EPOLL_CTL_MOD), flow_epoll_set() already retrieves the correct epoll fd via flow_epollfd(). For new additions (EPOLL_CTL_ADD), we can use epoll_id_to_fd[EPOLLFD_ID_DEFAULT] directly instead of c->epollfd, since that's the epollid that will be set. This removes the need for the ctx parameter from flow_epoll_set() and simplifies the API. The change cascades through all callers: tcp.c, icmp.c, udp_flow.c, and tcp_splice.c. In tcp_splice.c, removing ctx from flow_epoll_set() calls allows us to also remove the ctx parameter from tcp_splice_epoll_ctl() and conn_event_do(), further simplifying the splice connection handling. Signed-off-by: Laurent Vivier --- flow.c | 8 +++----- flow.h | 5 ++--- icmp.c | 2 +- tcp.c | 6 +++--- tcp_splice.c | 32 ++++++++++++++------------------ udp_flow.c | 2 +- 6 files changed, 24 insertions(+), 31 deletions(-) diff --git a/flow.c b/flow.c index 9c98102e3616..a3f75015a078 100644 --- a/flow.c +++ b/flow.c @@ -393,7 +393,6 @@ void flow_epollid_clear(struct flow_common *f) /** * flow_epoll_set() - Add or modify epoll registration for a flow socket - * @c: Execution context * @type: epoll type * @f: Flow to register socket for * @events: epoll events to watch for @@ -402,9 +401,8 @@ void flow_epollid_clear(struct flow_common *f) * * Return: 0 on success, -1 on error (from epoll_ctl()) */ -int flow_epoll_set(const struct ctx *c, enum epoll_type type, - const struct flow_common *f, uint32_t events, int fd, - unsigned int sidei) +int flow_epoll_set(enum epoll_type type, const struct flow_common *f, + uint32_t events, int fd, unsigned int sidei) { struct epoll_event ev; union epoll_ref ref; @@ -423,7 +421,7 @@ int flow_epoll_set(const struct ctx *c, enum epoll_type type, epollfd = flow_epollfd(f); } else { m = EPOLL_CTL_ADD; - epollfd = c->epollfd; + epollfd = epoll_id_to_fd[EPOLLFD_ID_DEFAULT]; } break; case EPOLL_TYPE_TCP_TIMER: { diff --git a/flow.h b/flow.h index 388fab124238..9740ede8963e 100644 --- a/flow.h +++ b/flow.h @@ -265,9 +265,8 @@ bool flow_in_epoll(const struct flow_common *f); int flow_epollfd(const struct flow_common *f); void flow_epollid_set(struct flow_common *f, int epollid); void flow_epollid_clear(struct flow_common *f); -int flow_epoll_set(const struct ctx *c, enum epoll_type type, - const struct flow_common *f, uint32_t events, int fd, - unsigned int sidei); +int flow_epoll_set(enum epoll_type type, const struct flow_common *f, + uint32_t events, int fd, unsigned int sidei); void flow_epollid_register(int epollid, int epollfd); void flow_defer_handler(const struct ctx *c, const struct timespec *now); int flow_migrate_source_early(struct ctx *c, const struct migrate_stage *stage, diff --git a/icmp.c b/icmp.c index 235759567060..f0b6fcff1776 100644 --- a/icmp.c +++ b/icmp.c @@ -210,7 +210,7 @@ static struct icmp_ping_flow *icmp_ping_new(const struct ctx *c, goto cancel; flow_epollid_set(&pingf->f, EPOLLFD_ID_DEFAULT); - if (flow_epoll_set(c, EPOLL_TYPE_PING, &pingf->f, EPOLLIN, pingf->sock, + if (flow_epoll_set(EPOLL_TYPE_PING, &pingf->f, EPOLLIN, pingf->sock, TGTSIDE) < 0) { close(pingf->sock); goto cancel; diff --git a/tcp.c b/tcp.c index 2907af282551..ec4f6d2ecc04 100644 --- a/tcp.c +++ b/tcp.c @@ -543,14 +543,14 @@ static int tcp_epoll_ctl(const struct ctx *c, struct tcp_tap_conn *conn) events = tcp_conn_epoll_events(conn->events, conn->flags); - if (flow_epoll_set(c, EPOLL_TYPE_TCP, &conn->f, events, conn->sock, + if (flow_epoll_set(EPOLL_TYPE_TCP, &conn->f, events, conn->sock, !TAPSIDE(conn))) return -errno; flow_epollid_set(&conn->f, EPOLLFD_ID_DEFAULT); if (conn->timer != -1) { - if (flow_epoll_set(c, EPOLL_TYPE_TCP_TIMER, &conn->f, + if (flow_epoll_set(EPOLL_TYPE_TCP_TIMER, &conn->f, EPOLLIN | EPOLLET, conn->timer, 0)) return -errno; } @@ -582,7 +582,7 @@ static void tcp_timer_ctl(const struct ctx *c, struct tcp_tap_conn *conn) return; } - if (flow_epoll_set(c, EPOLL_TYPE_TCP_TIMER, &conn->f, + if (flow_epoll_set(EPOLL_TYPE_TCP_TIMER, &conn->f, EPOLLIN | EPOLLET, fd, 0)) { flow_dbg_perror(conn, "failed to add timer"); close(fd); diff --git a/tcp_splice.c b/tcp_splice.c index 7367f435367b..ccf627f4427d 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -135,22 +135,20 @@ static uint32_t tcp_splice_conn_epoll_events(uint16_t events, unsigned sidei) /** * tcp_splice_epoll_ctl() - Add/modify/delete epoll state from connection events - * @c: Execution context * @conn: Connection pointer * * Return: 0 on success, negative error code on failure (not on deletion) */ -static int tcp_splice_epoll_ctl(const struct ctx *c, - struct tcp_splice_conn *conn) +static int tcp_splice_epoll_ctl(struct tcp_splice_conn *conn) { uint32_t events[2]; events[0] = tcp_splice_conn_epoll_events(conn->events, 0); events[1] = tcp_splice_conn_epoll_events(conn->events, 1); - if (flow_epoll_set(c, EPOLL_TYPE_TCP_SPLICE, &conn->f, events[0], + if (flow_epoll_set(EPOLL_TYPE_TCP_SPLICE, &conn->f, events[0], conn->s[0], 0) || - flow_epoll_set(c, EPOLL_TYPE_TCP_SPLICE, &conn->f, events[1], + flow_epoll_set(EPOLL_TYPE_TCP_SPLICE, &conn->f, events[1], conn->s[1], 1)) { int ret = -errno; flow_perror(conn, "ERROR on epoll_ctl()"); @@ -204,12 +202,10 @@ static void conn_flag_do(struct tcp_splice_conn *conn, /** * conn_event_do() - Set and log connection events, update epoll state - * @c: Execution context * @conn: Connection pointer * @event: Connection event */ -static void conn_event_do(const struct ctx *c, struct tcp_splice_conn *conn, - unsigned long event) +static void conn_event_do(struct tcp_splice_conn *conn, unsigned long event) { if (event & (event - 1)) { int flag_index = fls(~event); @@ -231,14 +227,14 @@ static void conn_event_do(const struct ctx *c, struct tcp_splice_conn *conn, flow_dbg(conn, "%s", tcp_splice_event_str[flag_index]); } - if (tcp_splice_epoll_ctl(c, conn)) + if (tcp_splice_epoll_ctl(conn)) conn_flag(c, conn, CLOSING); } -#define conn_event(c, conn, event) \ +#define conn_event(conn, event) \ do { \ flow_trace(conn, "event at %s:%i",__func__, __LINE__); \ - conn_event_do(c, conn, event); \ + conn_event_do(conn, event); \ } while (0) @@ -320,7 +316,7 @@ static int tcp_splice_connect_finish(const struct ctx *c, } if (!(conn->events & SPLICE_ESTABLISHED)) - conn_event(c, conn, SPLICE_ESTABLISHED); + conn_event(conn, SPLICE_ESTABLISHED); return 0; } @@ -367,7 +363,7 @@ static int tcp_splice_connect(const struct ctx *c, struct tcp_splice_conn *conn) pif_sockaddr(c, &sa, tgtpif, &tgt->eaddr, tgt->eport); - conn_event(c, conn, SPLICE_CONNECT); + conn_event(conn, SPLICE_CONNECT); if (connect(conn->s[1], &sa.sa, socklen_inany(&sa))) { if (errno != EINPROGRESS) { @@ -376,7 +372,7 @@ static int tcp_splice_connect(const struct ctx *c, struct tcp_splice_conn *conn) return -errno; } } else { - conn_event(c, conn, SPLICE_ESTABLISHED); + conn_event(conn, SPLICE_ESTABLISHED); return tcp_splice_connect_finish(c, conn); } @@ -485,14 +481,14 @@ void tcp_splice_sock_handler(struct ctx *c, union epoll_ref ref, if (events & EPOLLOUT) { fromsidei = !evsidei; - conn_event(c, conn, ~OUT_WAIT(evsidei)); + conn_event(conn, ~OUT_WAIT(evsidei)); } else { fromsidei = evsidei; } if (events & EPOLLRDHUP) /* For side 0 this is fake, but implied */ - conn_event(c, conn, FIN_RCVD(evsidei)); + conn_event(conn, FIN_RCVD(evsidei)); swap: eof = 0; @@ -574,7 +570,7 @@ retry: if (conn->read[fromsidei] == conn->written[fromsidei]) break; - conn_event(c, conn, OUT_WAIT(!fromsidei)); + conn_event(conn, OUT_WAIT(!fromsidei)); break; } @@ -596,7 +592,7 @@ retry: if ((conn->events & FIN_RCVD(sidei)) && !(conn->events & FIN_SENT(!sidei))) { shutdown(conn->s[!sidei], SHUT_WR); - conn_event(c, conn, FIN_SENT(!sidei)); + conn_event(conn, FIN_SENT(!sidei)); } } } diff --git a/udp_flow.c b/udp_flow.c index 42f3622d621c..07ff589670c1 100644 --- a/udp_flow.c +++ b/udp_flow.c @@ -84,7 +84,7 @@ static int udp_flow_sock(const struct ctx *c, } flow_epollid_set(&uflow->f, EPOLLFD_ID_DEFAULT); - rc = flow_epoll_set(c, EPOLL_TYPE_UDP, &uflow->f, EPOLLIN, s, sidei); + rc = flow_epoll_set(EPOLL_TYPE_UDP, &uflow->f, EPOLLIN, s, sidei); if (rc < 0) { close(s); return rc; -- 2.51.1