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=202410 header.b=jWvYoiTN; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id EDF8D5A0622 for ; Wed, 27 Nov 2024 04:54:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202410; t=1732679649; bh=zQNjOB3wQgjXwTiJDL/OvKzAYduZGAWvh7FWG2aau2M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jWvYoiTNvtrjvxh1wN1XYVOnqQ1peJP1/ar0M8UyzjeAJEXmZusL5IkYj2in3y8wL 3tF3QBU++YCjNkY96x/VhpCTOIgOihv+YhEOtz7nVVlobKjpSbsIwqh2TJi4W/FaLV CGu9y3GsjIeIYqpjRtszC+Yadr02SJjyhaFKMp5eUgKHIBlO7tYFhGsw8hIQTPrqBL WV6jBHwpQ6LSzODYtKwctxNquiOwFi9caauygQz1ajVA2ISicKucKRbnI9wgz0tY4V 9YCFh3vm3VzWlL//Ou3eO2sVlmEyZVoXhAKG3XFi5tnTKGF0Imo1QdmUDKXbJ5Xg22 T9EDibjETAvyw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4XyltT5hzYz4xgk; Wed, 27 Nov 2024 14:54:09 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 7/7] tcp_vu: Remove unnecessary tcp_vu_update_check() function Date: Wed, 27 Nov 2024 14:54:10 +1100 Message-ID: <20241127035410.1167773-8-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241127035410.1167773-1-david@gibson.dropbear.id.au> References: <20241127035410.1167773-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: PT2LLEBPZEAIWI3NI4ZLP52PHAV4UA76 X-Message-ID-Hash: PT2LLEBPZEAIWI3NI4ZLP52PHAV4UA76 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: Because the vhost-user <-> virtio-net path ignores checksums, we usually don't calculate them when sending packets to the guest. So, we always pass no_tcp_csum=true to tcp_fill_headers(). We do want accurate checksums when capturing packets though, so the captures don't show bogus values. Currently we handle this by updating the checksum field immediately before writing the packet to the capture file, using tcp_vu_update_check(). This is unnecessary, though: in each case tcp_fill_headers() is called not very long before, so we can alter its no_tcp_csum parameter pased on whether we're generating captures or not. Signed-off-by: David Gibson --- tcp_vu.c | 59 +++++++++++--------------------------------------------- 1 file changed, 11 insertions(+), 48 deletions(-) diff --git a/tcp_vu.c b/tcp_vu.c index a611a5b..4c60897 100644 --- a/tcp_vu.c +++ b/tcp_vu.c @@ -60,40 +60,6 @@ static size_t tcp_vu_hdrlen(bool v6) return hdrlen; } -/** - * tcp_vu_update_check() - Calculate TCP checksum - * @tapside: Address information for one side of the flow - * @iov: Pointer to the array of IO vectors - * @iov_cnt: Length of the array - */ -static void tcp_vu_update_check(const struct flowside *tapside, - struct iovec *iov, int iov_cnt) -{ - char *base = iov[0].iov_base; - struct iov_tail payload; - struct tcphdr *th; - uint32_t psum; - - if (inany_v4(&tapside->oaddr)) { - const struct in_addr *src4 = inany_v4(&tapside->oaddr); - const struct in_addr *dst4 = inany_v4(&tapside->eaddr); - const struct iphdr *iph = vu_ip(base); - size_t l4len = ntohs(iph->tot_len) - sizeof(*iph); - - th = vu_payloadv4(base); - psum = proto_ipv4_header_psum(l4len, IPPROTO_TCP, *src4, *dst4); - } else { - const struct ipv6hdr *ip6h = vu_ip(base); - size_t l4len = ntohs(ip6h->payload_len); - - th = vu_payloadv6(base); - psum = proto_ipv6_header_psum(l4len, IPPROTO_TCP, - &ip6h->saddr, &ip6h->daddr); - } - payload = IOV_TAIL(iov, iov_cnt, (char *)(th + 1) - base); - tcp_update_csum(psum, th, &payload); -} - /** * tcp_vu_send_flag() - Send segment with flags to vhost-user (no payload) * @c: Execution context @@ -106,7 +72,6 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) { struct vu_dev *vdev = c->vdev; struct vu_virtq *vq = &vdev->vq[VHOST_USER_RX_QUEUE]; - const struct flowside *tapside = TAPFLOW(conn); size_t optlen, hdrlen; struct vu_virtq_element flags_elem[2]; struct ipv6hdr *ip6h = NULL; @@ -171,10 +136,9 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) payload = IOV_TAIL(flags_elem[0].in_sg, 1, hdrlen); tcp_fill_headers(conn, NULL, ip4h, ip6h, th, &payload, - NULL, seq, true); + NULL, seq, !*c->pcap); if (*c->pcap) { - tcp_vu_update_check(tapside, &flags_elem[0].in_sg[0], 1); pcap_iov(&flags_elem[0].in_sg[0], 1, sizeof(struct virtio_net_hdr_mrg_rxbuf)); } @@ -318,15 +282,16 @@ static ssize_t tcp_vu_sock_recv(const struct ctx *c, /** * tcp_vu_prepare() - Prepare the frame header - * @c: Execution context - * @conn: Connection pointer - * @iov: Pointer to the array of IO vectors - * @iov_cnt: Number of entries in @iov - * @check: Checksum, if already known + * @c: Execution context + * @conn: Connection pointer + * @iov: Pointer to the array of IO vectors + * @iov_cnt: Number of entries in @iov + * @check: Checksum, if already known + * @no_tcp_csum: Do not set TCP checksum */ static void tcp_vu_prepare(const struct ctx *c, struct tcp_tap_conn *conn, struct iovec *iov, size_t iov_cnt, - const uint16_t **check) + const uint16_t **check, bool no_tcp_csum) { const struct flowside *toside = TAPFLOW(conn); bool v6 = !(inany_v4(&toside->eaddr) && inany_v4(&toside->oaddr)); @@ -370,7 +335,7 @@ static void tcp_vu_prepare(const struct ctx *c, struct tcp_tap_conn *conn, th->ack = 1; tcp_fill_headers(conn, NULL, ip4h, ip6h, th, &payload, - *check, conn->seq_to_tap, true); + *check, conn->seq_to_tap, no_tcp_csum); if (ip4h) *check = &ip4h->check; } @@ -388,8 +353,7 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn) uint32_t wnd_scaled = conn->wnd_from_tap << conn->ws_from_tap; struct vu_dev *vdev = c->vdev; struct vu_virtq *vq = &vdev->vq[VHOST_USER_RX_QUEUE]; - const struct flowside *tapside = TAPFLOW(conn); - size_t fillsize, hdrlen; + size_t hdrlen, fillsize; int v6 = CONN_V6(conn); uint32_t already_sent; const uint16_t *check; @@ -482,10 +446,9 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn) if (i + 1 == head_cnt) check = NULL; - tcp_vu_prepare(c, conn, iov, buf_cnt, &check); + tcp_vu_prepare(c, conn, iov, buf_cnt, &check, !*c->pcap); if (*c->pcap) { - tcp_vu_update_check(tapside, iov, buf_cnt); pcap_iov(iov, buf_cnt, sizeof(struct virtio_net_hdr_mrg_rxbuf)); } -- 2.47.0