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=IcTNgC8G; 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 90E7B5A004C for ; Tue, 01 Oct 2024 20:22:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727806943; 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=vFf2npG8n+3p3w1tDN+7i73sSne+5arY/lBNMXLTHBA=; b=IcTNgC8Ghb+UqDYbIoQYpSr6BP9AhWHt4eN/GWfmDwV3ZyVv3uUwgFz9QPlIN1NUIEwOVn B6S9mm4kbqtqdNhW4sclJ7joSO2dBZ5mCyUfd7o1ONnJ+arZHbTJL0TNuLeh65qsLJCfKd ttHOHp9AyDdJHdn5QXOKY/EdTPsOCrk= Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-56-sgYtqkJuPRGSQzi4_gPP-Q-1; Tue, 01 Oct 2024 14:22:22 -0400 X-MC-Unique: sgYtqkJuPRGSQzi4_gPP-Q-1 Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-2d8b4a23230so5938191a91.0 for ; Tue, 01 Oct 2024 11:22:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727806941; x=1728411741; 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=vFf2npG8n+3p3w1tDN+7i73sSne+5arY/lBNMXLTHBA=; b=UfPOB4lnucfDRa1lAvIjAWV/pJ/7QCmd6eBnlwqZD1RAsKbPtuvyEYC/Cm3qPwDsYy fBoJNKrMa1AaEtJohJvFa3Vj9Wp8q1nr6fNvKD4LPonGmPSVv96TuPn5mAUnp3u5VTvS zCXGsimWRgZhmaB0/8uAQvbVZ+V0d3HjtF6snLM/RbNBF3US4l5EOhi/CyMiLKPdV4PC hEVOmLQHrgFFWqH+5ruSFN4P2w+FhwSoVc3svkMIWdTy90GMPBq+AbuzwhDfhTGgC5Bs xUeB6ExLfPLIHyVNxaFgOv9Ptqn4GYeQZh1ocPQN+2KplaRmJgIJ6AQQtmdYquPynePF OFUw== X-Gm-Message-State: AOJu0YwNN90wyj0A4uj6Fw2XDn4/aHWXrjB41o83LL10rSTCjK0INOuN eAKNBwmDAP/5RO+RAymZgSrqUZ6J4V9cjUujuPJOMvztluthVfQc4ApmBcC4Ga2ZYKWqQEkmSle vWPuHdEQWNM2b2KjMdjMbxCwBPMsj7mOqzDF3yHlU2NQDnjePk9k5MqyzlDH37fLz3p1FAgBP/f ew1eczqrL6L+W+KsWq92+r45xyqed6jZet X-Received: by 2002:a17:90b:1b0e:b0:2e0:8e36:128 with SMTP id 98e67ed59e1d1-2e184526e45mr769222a91.5.1727806940796; Tue, 01 Oct 2024 11:22:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFC63NWQxZh9cB/xptfzkYQfykI5BOLKxceeGaVGfHcnSdnD4xKzWx9gfcwGIDM/A+xKr+hsQ== X-Received: by 2002:a17:90b:1b0e:b0:2e0:8e36:128 with SMTP id 98e67ed59e1d1-2e184526e45mr769195a91.5.1727806940277; Tue, 01 Oct 2024 11:22:20 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e06ccf0505sm14243591a91.0.2024.10.01.11.22.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 11:22:19 -0700 (PDT) Date: Tue, 1 Oct 2024 20:22:16 +0200 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH v5 4/5] tcp: Update TCP checksum using an iovec array Message-ID: <20241001202216.5c3ee274@elisabeth> In-Reply-To: <20241001092928.33755f2b@elisabeth> References: <20240927135349.675850-1-lvivier@redhat.com> <20240927135349.675850-5-lvivier@redhat.com> <20241001092928.33755f2b@elisabeth> 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: ERMRM572LHZE6ULIKXGPZNCTRLHKEYDG X-Message-ID-Hash: ERMRM572LHZE6ULIKXGPZNCTRLHKEYDG 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 Tue, 1 Oct 2024 09:29:28 +0200 Stefano Brivio wrote: > On Fri, 27 Sep 2024 15:53:48 +0200 > Laurent Vivier 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? -- 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; } -- it doesn't really improve on the "optimization opportunities" reported by clang-tidy but it silences the warning without much fuss. I can apply this on top if it looks okay to you. -- Stefano