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=f7zAp/kY; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id 78D855A0262 for ; Wed, 25 Sep 2024 19:39:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727285964; 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: in-reply-to:in-reply-to:references:references; bh=AOS5lntCGYPDKI4rGYpvfWcnukZDNFdNm0iBBWeeQ0k=; b=f7zAp/kYhS10hMNJNPq3QGDJV6PFFzRTVrOaLSC6xndrbB0czoNBZ6dQ97tdl/qqkgVF6I GtOdoXaSFZMXff0vlGgBgb2k1K6FoXv5mCkNY80YgOD4EvnKQdihHz8FFi/zTVrx/p79DM 7Qy4mk/0NC1o9zxBq5ATvyO2sr3iLSM= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-513-OD4WuI7iNxWdHgNgaXdjsQ-1; Wed, 25 Sep 2024 13:39:23 -0400 X-MC-Unique: OD4WuI7iNxWdHgNgaXdjsQ-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-42cb2c5d634so366405e9.0 for ; Wed, 25 Sep 2024 10:39:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727285961; x=1727890761; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=AOS5lntCGYPDKI4rGYpvfWcnukZDNFdNm0iBBWeeQ0k=; b=QvOOj4U+M5ha2TotJsmUbEgfu9PEJHj2IDaxt2a5f5jMjrE/43v3Joi1Zn7FDn15ir cw97ouyewFnLNfMVeV/Fksp5S3q1TUc/ojcGxvR+lwbimTBrz89MDUWKGcDfP/rzVJsJ 18bNKzIHDqpiNb2MziQim4mBVwmOV+t13CvGWccXsrBZ7ODz3sbdeLnmZ7xQrgS+FTDV XT2IjnDHspw2+2abkPDL9fdlLIC9qQzsBlVPsK48fdYzWdNSOOXUfNlYJZz7H8sAueGS 2GqxoBE3ZUZ1qTo0Zq1l1HHkH5zMjlGjHcjwTLUXutUCWpmg+kIZGUR/oG6bLFED9nbv IyBA== X-Gm-Message-State: AOJu0YzwOXgQw8QxyZuIM87Fn+2BSaAiYOpNshh5lJ+44toQv3gkgO++ 3duM0s2Td3oRdwVp8zuqgq/zy6N66VUvefpIsyxMuF0Ikxs76dAibU+8xgyNZ3m9KHesc7YWhZB YLBxg45c9Da77Et7+zaL9xtl6/+ab9niW2O3YDa7ccuGEBi4G5/NYj6DbOf04ssuu2m/yx1mNeQ PwykXfFVgbLodsKczOx+2oaRcAeJ9obhng X-Received: by 2002:a7b:cb0f:0:b0:42c:bf70:a303 with SMTP id 5b1f17b1804b1-42f04f6adbemr19359475e9.29.1727285961526; Wed, 25 Sep 2024 10:39:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEAJ1ej/TBAgFFtfaJIRPOjTUVyeXhR/RSzpeb/yEZ568wG7coDT19oVKSKy3JGJtQdRprZkg== X-Received: by 2002:a7b:cb0f:0:b0:42c:bf70:a303 with SMTP id 5b1f17b1804b1-42f04f6adbemr19359275e9.29.1727285960957; Wed, 25 Sep 2024 10:39:20 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42e969fbca4sm24429525e9.19.2024.09.25.10.39.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 10:39:20 -0700 (PDT) Date: Wed, 25 Sep 2024 19:39:19 +0200 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH v2 4/4] tcp: Update TCP checksum using an iovec array Message-ID: <20240925193919.6bfe0df4@elisabeth> In-Reply-To: <20240925081125.205974-5-lvivier@redhat.com> References: <20240925081125.205974-1-lvivier@redhat.com> <20240925081125.205974-5-lvivier@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 2A2SSYTMRKRJ5SQBFWGKGTFZGNA4LTCI X-Message-ID-Hash: 2A2SSYTMRKRJ5SQBFWGKGTFZGNA4LTCI X-MailFrom: sbrivio@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: passt-dev@passt.top 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: On Wed, 25 Sep 2024 10:11:25 +0200 Laurent Vivier wrote: > TCP header and payload are supposed to be in the same buffer, > and tcp_update_check_tcp4()/tcp_update_check_tcp6() compute > the checksum from the base address of the header using the > length of the IP payload. > > In the future (for vhost-user) we need to dispatch the TCP header and > the TCP payload through several buffers. To be able to manage that, we > provide an iovec array that points to the data of the TCP frame. > We provide also an offset to be able to provide an array that contains > the TCP frame embedded in an lower level frame, and this offset points > to the TCP header inside the iovec array. > > Signed-off-by: Laurent Vivier > --- > > Notes: > v2: > - s/payload_offset/l4offset/ > - check memory address of the checksum (alignment, iovec boundaries) > > checksum.c | 1 - > tcp.c | 116 ++++++++++++++++++++++++++++++++++++++++------------- > 2 files changed, 88 insertions(+), 29 deletions(-) > > diff --git a/checksum.c b/checksum.c > index 68ffaddb5bb0..4854c1937c39 100644 > --- a/checksum.c > +++ b/checksum.c > @@ -503,7 +503,6 @@ uint16_t csum(const void *buf, size_t len, uint32_t init) > * > * Return: 16-bit folded, complemented checksum > */ > -/* cppcheck-suppress unusedFunction */ > uint16_t csum_iov(const struct iovec *iov, size_t n, size_t offset, > uint32_t init) > { > diff --git a/tcp.c b/tcp.c > index c9472d905520..f0a6f7a507a7 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -755,36 +755,81 @@ static void tcp_sock_set_bufsize(const struct ctx *c, int s) > } > > /** > - * tcp_update_check_tcp4() - Update TCP checksum from stored one > - * @iph: IPv4 header > - * @bp: TCP header followed by TCP payload > - */ > -static void tcp_update_check_tcp4(const struct iphdr *iph, > - struct tcp_payload_t *bp) > + * tcp_update_check_tcp4() - Calculate TCP checksum for IPv6 > + * @src: IPv4 source address > + * @dst: IPv4 destination address > + * @iov: Pointer to the array of IO vectors > + * @iov_cnt: Length of the array > + * @l4offset: IPv4 payload offset in the iovec array > + */ > +void tcp_update_check_tcp4(struct in_addr src, > + struct in_addr dst, > + const struct iovec *iov, int iov_cnt, > + size_t l4offset) > { > - uint16_t l4len = ntohs(iph->tot_len) - sizeof(struct iphdr); > - struct in_addr saddr = { .s_addr = iph->saddr }; > - struct in_addr daddr = { .s_addr = iph->daddr }; > - uint32_t sum = proto_ipv4_header_psum(l4len, IPPROTO_TCP, saddr, daddr); > + size_t check_ofs; > + __sum16 *check; > + int check_idx; > + uint32_t sum; > + > + sum = proto_ipv4_header_psum(iov_size(iov, iov_cnt) - l4offset, > + IPPROTO_TCP, src, dst); > + > + check_idx = iov_skip_bytes(iov, iov_cnt, > + l4offset + offsetof(struct tcphdr, check), > + &check_ofs); > + > + if (check_idx >= iov_cnt) > + die("TCP4 buffer is too small"); > + if (check_ofs + sizeof(*check) > iov[check_idx].iov_len) > + die("TCP4 checksum field memory is not contiguous"); I'm not really fond of those die() calls. First off, they should report a couple more details (at least check_idx, iov_cnt). Second, we could fail gracefully (hence, we should) instead of aborting the whole thing: those could be err() calls. If we fail to calculate checksums, we can leave them as zero, and the receiver will drop those frames anyway, if you don't want to add complexity (propagation of return values) for something that should never happen. The rest looks good to me, but I didn't go through David's comments so I'll wait for his review before applying. -- Stefano