From: Laurent Vivier <lvivier@redhat.com>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH v5 4/5] tcp: Update TCP checksum using an iovec array
Date: Wed, 2 Oct 2024 09:39:23 +0200 [thread overview]
Message-ID: <4efad680-ccf3-45a8-8929-cc5ae2be4760@redhat.com> (raw)
In-Reply-To: <20241001202216.5c3ee274@elisabeth>
On 01/10/2024 20:22, Stefano Brivio wrote:
> On Tue, 1 Oct 2024 09:29:28 +0200
> Stefano Brivio <sbrivio@redhat.com> wrote:
>
>> On Fri, 27 Sep 2024 15:53:48 +0200
>> Laurent Vivier <lvivier@redhat.com> wrote:
>>
>>> [...]
>>>
>>> +void tcp_update_check_tcp4(const struct iphdr *iph,
>>> + 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;
>>> + uintptr_t ptr;
>>> +
>>> + sum = proto_ipv4_header_psum(l4len, IPPROTO_TCP, saddr, daddr);
>>> +
>>> + check_idx = iov_skip_bytes(iov, iov_cnt,
>>> + l4offset + offsetof(struct tcphdr, check),
>>> + &check_ofs);
>>> +
>>> + if (check_idx >= iov_cnt) {
>>> + err("TCP4 buffer is too small, iov size %zd, check offset %zd",
>>> + iov_size(iov, iov_cnt),
>>> + l4offset + offsetof(struct tcphdr, check));
>>> + return;
>>> + }
>>>
>>> - bp->th.check = 0;
>>> - bp->th.check = csum(bp, l4len, sum);
>>> + if (check_ofs + sizeof(*check) > iov[check_idx].iov_len) {
>>> + err("TCP4 checksum field memory is not contiguous "
>>> + "check_ofs %zd check_idx %d iov_len %zd",
>>> + check_ofs, check_idx, iov[check_idx].iov_len);
>>> + return;
>>> + }
>>> +
>>> + ptr = (uintptr_t)((char *)iov[check_idx].iov_base + check_ofs);
>>> + if (ptr & (__alignof__(*check) - 1)) {
>>> + err("TCP4 checksum field is not correctly aligned in memory");
>>> + return;
>>> + }
>>> +
>>> + check = (__sum16 *)ptr;
>>
>> clang-tidy (14.0.6) says:
>>
>> /home/sbrivio/passt/tcp.c:803:10: error: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr,-warnings-as-errors]
>> check = (__sum16 *)ptr;
>> ^
>> /home/sbrivio/passt/tcp.c:854:10: error: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr,-warnings-as-errors]
>> check = (__sum16 *)ptr;
>> ^
>>
>> ...I'm still trying to figure out what that actually means. If it's
>> trivial I can fix that up on merge.
>
> Something like this?
It's ok for me. Do you want I resend a version with it or can you update the patch on the
merge?
Thanks,
Laurent
>
> --
> diff --git a/tcp.c b/tcp.c
> index ffd82e1..2b8edda 100644
> --- a/tcp.c
> +++ b/tcp.c
> @@ -772,7 +772,7 @@ void tcp_update_check_tcp4(const struct iphdr *iph,
> __sum16 *check;
> int check_idx;
> uint32_t sum;
> - uintptr_t ptr;
> + char *ptr;
>
> sum = proto_ipv4_header_psum(l4len, IPPROTO_TCP, saddr, daddr);
>
> @@ -794,8 +794,8 @@ void tcp_update_check_tcp4(const struct iphdr *iph,
> return;
> }
>
> - ptr = (uintptr_t)((char *)iov[check_idx].iov_base + check_ofs);
> - if (ptr & (__alignof__(*check) - 1)) {
> + ptr = (char *)iov[check_idx].iov_base + check_ofs;
> + if ((uintptr_t)ptr & (__alignof__(*check) - 1)) {
> err("TCP4 checksum field is not correctly aligned in memory");
> return;
> }
> @@ -822,7 +822,7 @@ void tcp_update_check_tcp6(const struct ipv6hdr *ip6h,
> __sum16 *check;
> int check_idx;
> uint32_t sum;
> - uintptr_t ptr;
> + char *ptr;
>
> sum = proto_ipv6_header_psum(l4len, IPPROTO_TCP, &ip6h->saddr,
> &ip6h->daddr);
> @@ -845,8 +845,8 @@ void tcp_update_check_tcp6(const struct ipv6hdr *ip6h,
> return;
> }
>
> - ptr = (uintptr_t)((char *)iov[check_idx].iov_base + check_ofs);
> - if (ptr & (__alignof__(*check) - 1)) {
> + ptr = (char *)iov[check_idx].iov_base + check_ofs;
> + if ((uintptr_t)ptr & (__alignof__(*check) - 1)) {
> err("TCP6 checksum field is not correctly aligned in memory");
> return;
> }
>
next prev parent reply other threads:[~2024-10-02 7:39 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-27 13:53 [PATCH v5 0/5] tcp: use csum_iov() in tcp_update_check_tcp[4|6]() Laurent Vivier
2024-09-27 13:53 ` [PATCH v5 1/5] tcp: Use tcp_payload_t rather than tcphdr Laurent Vivier
2024-09-27 13:53 ` [PATCH v5 2/5] pcap: Add an offset argument in pcap_iov() Laurent Vivier
2024-09-27 13:53 ` [PATCH v5 3/5] checksum: Add an offset argument in csum_iov() Laurent Vivier
2024-09-30 2:51 ` David Gibson
2024-09-27 13:53 ` [PATCH v5 4/5] tcp: Update TCP checksum using an iovec array Laurent Vivier
2024-09-30 2:56 ` David Gibson
2024-10-01 7:29 ` Stefano Brivio
2024-10-01 18:22 ` Stefano Brivio
2024-10-02 7:39 ` Laurent Vivier [this message]
2024-10-02 9:00 ` Stefano Brivio
2024-10-03 12:58 ` Laurent Vivier
2024-09-27 13:53 ` [PATCH v5 5/5] udp: Update UDP " Laurent Vivier
2024-09-30 2:58 ` David Gibson
2024-10-02 14:32 ` [PATCH v5 0/5] tcp: use csum_iov() in tcp_update_check_tcp[4|6]() Stefano Brivio
2024-10-02 14:46 ` Stefano Brivio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4efad680-ccf3-45a8-8929-cc5ae2be4760@redhat.com \
--to=lvivier@redhat.com \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).