public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH] tcp_vu: Compute IPv4 header checksum if dlen changes
@ 2024-11-28 12:08 Laurent Vivier
  2024-11-28 13:04 ` Stefano Brivio
  0 siblings, 1 reply; 2+ messages in thread
From: Laurent Vivier @ 2024-11-28 12:08 UTC (permalink / raw)
  To: passt-dev; +Cc: Laurent Vivier

In tcp_vu_data_from_sock() we compute IPv4 header checksum only
for the first and the last packets, and re-use the first packet checksum
for all the other packets as the content of the header doesn't change.

It's more accurate to check the dlen value to know if the checksum
should change as dlen is the only information that can change in the
loop.

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 tcp_vu.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/tcp_vu.c b/tcp_vu.c
index bbae918c3bb3..4e4e916ded78 100644
--- a/tcp_vu.c
+++ b/tcp_vu.c
@@ -381,12 +381,12 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn)
 	struct vu_dev *vdev = c->vdev;
 	struct vu_virtq *vq = &vdev->vq[VHOST_USER_RX_QUEUE];
 	const struct flowside *tapside = TAPFLOW(conn);
+	ssize_t len, previous_dlen;
 	size_t fillsize, hdrlen;
 	int v6 = CONN_V6(conn);
 	uint32_t already_sent;
 	const uint16_t *check;
 	int i, iov_cnt;
-	ssize_t len;
 
 	if (!vu_queue_enabled(vq) || !vu_queue_started(vq)) {
 		debug("Got packet, but RX virtqueue not usable yet");
@@ -460,19 +460,17 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn)
 	 */
 
 	hdrlen = tcp_vu_hdrlen(v6);
-	for (i = 0, check = NULL; i < head_cnt; i++) {
+	for (i = 0, previous_dlen = -1, check = NULL; i < head_cnt; i++) {
 		struct iovec *iov = &elem[head[i]].in_sg[0];
 		int buf_cnt = head[i + 1] - head[i];
 		ssize_t dlen = iov_size(iov, buf_cnt) - hdrlen;
 
 		vu_set_vnethdr(vdev, iov->iov_base, buf_cnt);
 
-		/* we compute IPv4 header checksum only for the
-		 * first and the last, all other checksums are the
-		 * same as the first one
-		 */
-		if (i + 1 == head_cnt)
+		/* The IPv4 header checksum varies only with dlen */
+		if (previous_dlen != dlen)
 			check = NULL;
+		previous_dlen = dlen;
 
 		tcp_vu_prepare(c, conn, iov->iov_base, dlen, &check);
 
-- 
@@ -381,12 +381,12 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn)
 	struct vu_dev *vdev = c->vdev;
 	struct vu_virtq *vq = &vdev->vq[VHOST_USER_RX_QUEUE];
 	const struct flowside *tapside = TAPFLOW(conn);
+	ssize_t len, previous_dlen;
 	size_t fillsize, hdrlen;
 	int v6 = CONN_V6(conn);
 	uint32_t already_sent;
 	const uint16_t *check;
 	int i, iov_cnt;
-	ssize_t len;
 
 	if (!vu_queue_enabled(vq) || !vu_queue_started(vq)) {
 		debug("Got packet, but RX virtqueue not usable yet");
@@ -460,19 +460,17 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn)
 	 */
 
 	hdrlen = tcp_vu_hdrlen(v6);
-	for (i = 0, check = NULL; i < head_cnt; i++) {
+	for (i = 0, previous_dlen = -1, check = NULL; i < head_cnt; i++) {
 		struct iovec *iov = &elem[head[i]].in_sg[0];
 		int buf_cnt = head[i + 1] - head[i];
 		ssize_t dlen = iov_size(iov, buf_cnt) - hdrlen;
 
 		vu_set_vnethdr(vdev, iov->iov_base, buf_cnt);
 
-		/* we compute IPv4 header checksum only for the
-		 * first and the last, all other checksums are the
-		 * same as the first one
-		 */
-		if (i + 1 == head_cnt)
+		/* The IPv4 header checksum varies only with dlen */
+		if (previous_dlen != dlen)
 			check = NULL;
+		previous_dlen = dlen;
 
 		tcp_vu_prepare(c, conn, iov->iov_base, dlen, &check);
 
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tcp_vu: Compute IPv4 header checksum if dlen changes
  2024-11-28 12:08 [PATCH] tcp_vu: Compute IPv4 header checksum if dlen changes Laurent Vivier
@ 2024-11-28 13:04 ` Stefano Brivio
  0 siblings, 0 replies; 2+ messages in thread
From: Stefano Brivio @ 2024-11-28 13:04 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: passt-dev

On Thu, 28 Nov 2024 13:08:41 +0100
Laurent Vivier <lvivier@redhat.com> wrote:

> In tcp_vu_data_from_sock() we compute IPv4 header checksum only
> for the first and the last packets, and re-use the first packet checksum
> for all the other packets as the content of the header doesn't change.
> 
> It's more accurate to check the dlen value to know if the checksum
> should change as dlen is the only information that can change in the
> loop.
> 
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>

Applied.

-- 
Stefano


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-11-28 13:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-28 12:08 [PATCH] tcp_vu: Compute IPv4 header checksum if dlen changes Laurent Vivier
2024-11-28 13:04 ` Stefano Brivio

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).