From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none 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=NLF4CbJJ; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 5D2265A061B for ; Thu, 28 Nov 2024 13:08:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732795726; 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; bh=c+mBuRbiuKxigpnVg96RFVPE+u5bDdkNfeLFwvlZeV0=; b=NLF4CbJJX8AGlXJHKelddCO4dzYyy2RV3Lur0dFbHwbdFlg2o+vNUGt10xRxEdf8UUjojA z7MzZPs7S7YkHNFZ3tTVdLzJpAABO61KT8NLclqRDgWvwnAQzfahh1gbJEfsB0l3jE1BUM gHKqZgR38dTRkdyTvRB4HTEf3Nv+4Gk= Received: from mx-prod-mc-04.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-536-zd8C-5RAPIyNBAVvaP-oqg-1; Thu, 28 Nov 2024 07:08:44 -0500 X-MC-Unique: zd8C-5RAPIyNBAVvaP-oqg-1 X-Mimecast-MFC-AGG-ID: zd8C-5RAPIyNBAVvaP-oqg Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CBBE11955F3F for ; Thu, 28 Nov 2024 12:08:43 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.39.193.95]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E03EA1955D47; Thu, 28 Nov 2024 12:08:42 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH] tcp_vu: Compute IPv4 header checksum if dlen changes Date: Thu, 28 Nov 2024 13:08:41 +0100 Message-ID: <20241128120841.4129705-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: rdQlXj3uW83B49mf6Y2aPvQmm1sxcUvBa6Sae9dLwIg_1732795723 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: AHW7TH26TLVWW4HBPQUZXGWHRJWHHVRA X-Message-ID-Hash: AHW7TH26TLVWW4HBPQUZXGWHRJWHHVRA 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_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 --- 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); -- 2.47.0