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=202602 header.b=EK35vrXp; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id D20135A0627 for ; Wed, 20 May 2026 15:09:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1779282534; bh=hS0Zm9abiDKImaIsiSPjOpT9Q49hlgcrOO8zMWIhoak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EK35vrXpzKDEyr2D1ynooWTHYrsI38uOGO1F5PTXQbP77DrJWt0b9bcho5ItiCoVu ZlhOMbNkQ5M2omSkBRdV8SOmH2CtiSRu2318jZmjSCmzijkttdzNsWwsvakcdcUdPP w6mtuYBQI483yuOWwwnW+3WqTEtJTSgQ8mjRl2Z/OwtUze49i2lCvocwXiEvrKN2GM O/zjZbI/RrTspX51sJ4Lpo0Sc4FLxCvJ13W0IvfLOG7VPdZJTplVE6hM0VxbWl8CSa 7XJzDLAXWUA2QtL7jHmfjfdXlYoSelACQj27hYwzJhH/i6o3jUesrKh2qGJ85w9cHi a4t2XoOkO7uSQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gLBgp1lXBz59Gj; Wed, 20 May 2026 23:08:54 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 5/6] tcp_splice: Simplify EPOLLRDHUP / eof / FIN handling Date: Wed, 20 May 2026 23:08:50 +1000 Message-ID: <20260520130851.436931-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260520130851.436931-1-david@gibson.dropbear.id.au> References: <20260520130851.436931-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 6EIDL46ACYWMOAA27HXHK34PBEBAXQ25 X-Message-ID-Hash: 6EIDL46ACYWMOAA27HXHK34PBEBAXQ25 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: Paul Holzinger , David Gibson 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: There are two ways we can tell one of our sockets has received a FIN. We can either see an EPOLLRDHUP epoll event, or we can get a zero-length read (EOF) on the socket. We currently use both, in a mildly confusing way: we only set the FIN_RCVD() flag based on the EPOLLRDHUP event, but then some other close out logic is based on seeing an EOF. Simplify this by setting the flag based on only the EOF. To make sure we don't miss an event if we get an EPOLLRDHUP with no data, we trigger the forwarding path for EPOLLRDHUP as well as EPOLLIN. Signed-off-by: David Gibson --- tcp_splice.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tcp_splice.c b/tcp_splice.c index 8fbd490f..b45f0060 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -487,7 +487,6 @@ static int tcp_splice_forward(struct ctx *c, struct uint8_t lowat_set_flag = RCVLOWAT_SET(fromsidei); uint8_t lowat_act_flag = RCVLOWAT_ACT(fromsidei); int never_read = 1; - int eof = 0; while (1) { ssize_t readlen, written; @@ -510,7 +509,7 @@ retry: flow_trace(conn, "%zi from read-side call", readlen); if (!readlen) { - eof = 1; + conn_event(conn, FIN_RCVD(fromsidei)); } else if (readlen > 0) { never_read = 0; @@ -579,11 +578,12 @@ retry: written < conn->pending[fromsidei]) goto retry; - if (eof) + if (conn->events & FIN_RCVD(fromsidei)) break; } - if (!conn->pending[fromsidei] && eof) { + if (!conn->pending[fromsidei] && + conn->events & FIN_RCVD(fromsidei)) { unsigned sidei; flow_foreach_sidei(sidei) { @@ -643,17 +643,13 @@ void tcp_splice_sock_handler(struct ctx *c, union epoll_ref ref, goto reset; } - if (events & EPOLLRDHUP) - /* For side 0 this is fake, but implied */ - conn_event(conn, FIN_RCVD(evsidei)); - if (events & EPOLLOUT) { if (tcp_splice_forward(c, conn, !evsidei)) goto reset; conn_event(conn, ~OUT_WAIT(evsidei)); } - if (events & EPOLLIN) { + if (events & (EPOLLIN | EPOLLRDHUP)) { if (tcp_splice_forward(c, conn, evsidei)) goto reset; } -- 2.54.0