From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 14CBD5A004E for ; Wed, 24 Jul 2024 05:31:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1721791872; bh=/y8EKY3se2Nt3q+vxIOt7hBIXcyrxHArjae+oB5T7yA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MeykyO9WfNaCayVNx0Xq5HJBr/L8G2I0hvXP9TtsvlTNI/7oE+BLPxFKLpIVa7NUb bwXalK1VAa4mEqRTbTqdj3NpgUStjF80G66h7oGSTk2zjgDZIjxrTwvCBvGvSko97k KK8AciBpQejdClw9Ig0mSnjaPYz5Lk0UHk+kk3xEQl7g0ymq/3PCdzaApsX+0778j8 p/p3L3TV1wkDhbi+bd/tUhdOZ1FUFry/k4kaACnobrlEzQ37xehoJzONssdlqZEppm XgtduvCmeHAbiQV/BGRmx0at5vkp/Tzb1U8j3P34YZ7T4DJTEf0KxoIMnyQBb71oKo 14xPWNYangKmw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WTKL80qbNz4wd4; Wed, 24 Jul 2024 13:31:12 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 2/2] tcp: Correctly update SO_PEEK_OFF when tcp_send_frames() drops frames Date: Wed, 24 Jul 2024 13:31:09 +1000 Message-ID: <20240724033109.422311-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240724033109.422311-1-david@gibson.dropbear.id.au> References: <20240724033109.422311-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: UJECWD2KIF3ER6RAX5J5JM7DC6GSOCDF X-Message-ID-Hash: UJECWD2KIF3ER6RAX5J5JM7DC6GSOCDF 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: When using the new SO_PEEK_OFF feature on TCP sockets, we must adjust the SO_PEEK_OFF value whenever we move conn->seq_to_tap backwards. Although it was discussed during development, somewhere during the shuffles the case where we move the pointer backwards because we lost frames while sending them to the guest. This can happen, for example, if the socket buffer on the Unix socket to qemu overflows. Fixing this is slightly complicated because we need to pass a non-const context pointer to some places we previously didn't need it. While we're there also fix a small stylistic issue in the function comment for tcp_revert_seq() - it was using spaces instead of tabs. Fixes: e63d281871ef ("tcp: leverage support of SO_PEEK_OFF socket...") Signed-off-by: David Gibson --- tcp_buf.c | 23 ++++++++++++++--------- tcp_buf.h | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/tcp_buf.c b/tcp_buf.c index 9b198984..c31e9f31 100644 --- a/tcp_buf.c +++ b/tcp_buf.c @@ -235,12 +235,13 @@ void tcp_flags_flush(const struct ctx *c) /** * tcp_revert_seq() - Revert affected conn->seq_to_tap after failed transmission - * @conns: Array of connection pointers corresponding to queued frames - * @frames: Two-dimensional array containing queued frames with sub-iovs - * @num_frames: Number of entries in the two arrays to be compared + * @ctx: Execution context + * @conns: Array of connection pointers corresponding to queued frames + * @frames: Two-dimensional array containing queued frames with sub-iovs + * @num_frames: Number of entries in the two arrays to be compared */ -static void tcp_revert_seq(struct tcp_tap_conn **conns, struct iovec (*frames)[TCP_NUM_IOVS], - int num_frames) +static void tcp_revert_seq(struct ctx *c, struct tcp_tap_conn **conns, + struct iovec (*frames)[TCP_NUM_IOVS], int num_frames) { int i; @@ -248,11 +249,15 @@ static void tcp_revert_seq(struct tcp_tap_conn **conns, struct iovec (*frames)[T const struct tcphdr *th = frames[i][TCP_IOV_PAYLOAD].iov_base; struct tcp_tap_conn *conn = conns[i]; uint32_t seq = ntohl(th->seq); + uint32_t peek_offset; if (SEQ_LE(conn->seq_to_tap, seq)) continue; conn->seq_to_tap = seq; + peek_offset = conn->seq_to_tap - conn->seq_ack_from_tap; + if (tcp_set_peek_offset(conn->sock, peek_offset)) + tcp_rst(c, conn); } } @@ -260,14 +265,14 @@ static void tcp_revert_seq(struct tcp_tap_conn **conns, struct iovec (*frames)[T * tcp_payload_flush() - Send out buffers for segments with data * @c: Execution context */ -void tcp_payload_flush(const struct ctx *c) +void tcp_payload_flush(struct ctx *c) { size_t m; m = tap_send_frames(c, &tcp6_l2_iov[0][0], TCP_NUM_IOVS, tcp6_payload_used); if (m != tcp6_payload_used) { - tcp_revert_seq(&tcp6_frame_conns[m], &tcp6_l2_iov[m], + tcp_revert_seq(c, &tcp6_frame_conns[m], &tcp6_l2_iov[m], tcp6_payload_used - m); } tcp6_payload_used = 0; @@ -275,7 +280,7 @@ void tcp_payload_flush(const struct ctx *c) m = tap_send_frames(c, &tcp4_l2_iov[0][0], TCP_NUM_IOVS, tcp4_payload_used); if (m != tcp4_payload_used) { - tcp_revert_seq(&tcp4_frame_conns[m], &tcp4_l2_iov[m], + tcp_revert_seq(c, &tcp4_frame_conns[m], &tcp4_l2_iov[m], tcp4_payload_used - m); } tcp4_payload_used = 0; @@ -353,7 +358,7 @@ int tcp_buf_send_flag(struct ctx *c, struct tcp_tap_conn *conn, int flags) * @no_csum: Don't compute IPv4 checksum, use the one from previous buffer * @seq: Sequence number to be sent */ -static void tcp_data_to_tap(const struct ctx *c, struct tcp_tap_conn *conn, +static void tcp_data_to_tap(struct ctx *c, struct tcp_tap_conn *conn, ssize_t dlen, int no_csum, uint32_t seq) { struct iovec *iov; diff --git a/tcp_buf.h b/tcp_buf.h index 14be7b94..3db4c56e 100644 --- a/tcp_buf.h +++ b/tcp_buf.h @@ -9,7 +9,7 @@ void tcp_sock4_iov_init(const struct ctx *c); void tcp_sock6_iov_init(const struct ctx *c); void tcp_flags_flush(const struct ctx *c); -void tcp_payload_flush(const struct ctx *c); +void tcp_payload_flush(struct ctx *c); int tcp_buf_data_from_sock(struct ctx *c, struct tcp_tap_conn *conn); int tcp_buf_send_flag(struct ctx *c, struct tcp_tap_conn *conn, int flags); -- 2.45.2