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=202504 header.b=MhAguZIF; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id CA9AD5A0008 for ; Wed, 09 Apr 2025 08:35:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202504; t=1744180543; bh=ij89eDhOIfN/AyeABoT/C7IZJylGMAVEOxKKwSwlQew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MhAguZIFGDLRP5YVUWXHjx3cG+/MUNjfJNhbnfr+cu2qbie/5ivLcg7Co4qizIeWL VPDSW819CkkqXs2r3rrCqRgOtvZ0J8lVwZ9IYCRZ0VP/v9wCdJ5auAnU5cGORsgP5u gnrGHUkPiEiSFUhONqO0D0Q/vug3tsziSClNw0lHMyANmGzILBx6AXv0UijhYCgs04 Au+/Dv0CEnsSFD4BzzYgSaiag6GE5UNd5lrqoTIK0n8IgzOqkcJuYzTjJBcB47AWq6 jFoAlb7xCJHJfCXlMMIoH4a0rL5BHqTN/yGz8MIxPzjH8om2R36pQX5T/FBkrIczdz 4eCMP1ZpHh71g== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ZXY9W4FtGz4wbZ; Wed, 9 Apr 2025 16:35:43 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 2/2] tcp_splice: Don't clobber errno before checking for EAGAIN Date: Wed, 9 Apr 2025 16:35:41 +1000 Message-ID: <20250409063541.1411177-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250409063541.1411177-1-david@gibson.dropbear.id.au> References: <20250409063541.1411177-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: GZZ2BNZIDTSYV243VPSVO3UZRJHES3AZ X-Message-ID-Hash: GZZ2BNZIDTSYV243VPSVO3UZRJHES3AZ 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: 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: Like many places, tcp_splice_sock_handler() needs to handle EAGAIN specially, in this case for both of its splice() calls. Unfortunately it tests for EAGAIN some time after those calls. In between there has been at least a flow_trace() which could have clobbered errno. Move the test on errno closer to the relevant system calls to avoid this problem. Signed-off-by: David Gibson --- tcp_splice.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tcp_splice.c b/tcp_splice.c index 7c3b56f9..60455d64 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -526,13 +526,15 @@ retry: c->tcp.pipe_size, SPLICE_F_MOVE | SPLICE_F_NONBLOCK); while (readlen < 0 && errno == EINTR); + + if (readlen < 0 && errno != EAGAIN) + goto close; + flow_trace(conn, "%zi from read-side call", readlen); - if (readlen < 0) { - if (errno != EAGAIN) - goto close; - } else if (!readlen) { + + if (!readlen) { eof = 1; - } else { + } else if (readlen > 0) { never_read = 0; if (readlen >= (long)c->tcp.pipe_size * 90 / 100) @@ -549,6 +551,9 @@ retry: SPLICE_F_MOVE | more | SPLICE_F_NONBLOCK); while (written < 0 && errno == EINTR); + if (written < 0 && errno != EAGAIN) + goto close; + flow_trace(conn, "%zi from write-side call (passed %zi)", written, c->tcp.pipe_size); @@ -580,9 +585,6 @@ retry: conn->written[fromsidei] += written > 0 ? written : 0; if (written < 0) { - if (errno != EAGAIN) - goto close; - if (conn->read[fromsidei] == conn->written[fromsidei]) break; -- 2.49.0