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=SidfVbN9; 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 5CCD65A004E for ; Wed, 02 Oct 2024 11:00:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727859656; 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=7mf6W33oEtSSeYgIfl0BRRKk+lNLkIOnbbvNR2ERLvw=; b=SidfVbN9/+vOpdpPv2ldq2OMUlAVHVahAYM4Q+d+mgrCmmjczpfr/BD1XNW3hxFKclcLox NXzEXkbBXgLOHHAS+S28H+VqNcz/huD9YkIXHduTn2hDbdn+/L8Ml3j1WWMPKrrSu4y83e PrdQHrVu8mfiQxv1WhcMIo+mwR5Z0Lg= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-204-RqQT0UyIP5iRflaMXX1Byw-1; Wed, 02 Oct 2024 05:00:50 -0400 X-MC-Unique: RqQT0UyIP5iRflaMXX1Byw-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-42cc4345561so36774705e9.1 for ; Wed, 02 Oct 2024 02:00:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727859648; x=1728464448; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=aC7dWtxGYS4nIjhfEwi1FUbioZS/E2PG6lSoWle3lu0=; b=SYTXviQdTuN8uzUYapyrksA4iCOaxDSbJCXkHsKjRl7ox6fZGmxK1fo0rSML+x7ls/ w4m3WXezrBtUpKViY0Sgs8sL9NNJcL7ilopRcdCjtZmED3heQBMIAkLWJEGpF+g/tv2I X5hmqGdV3DhFLYqY905TZ9i/+CT0UWGTNruDbrGjfBnYdIJXsaBoT9Xv71tPkQodU1Bt Wqzoi6RrA/B8eIwb+eBRWJ85fYQfCAKhbgcLqxMeMb7u+8wKxzj/X7Urnvvic4kmf35A zr1dn1hD9m4JutU2TifAL3hFqU5c+cPfM7ugvUsQp16KZ5rud6Hrpe+RArSciYyLrnkQ 8YZg== X-Gm-Message-State: AOJu0YwUWYHuPtZmPB6nSefoF5HDg2WNdDogJXncrP0zaV2IGy+ARXqJ 30jAkz5QzbKE3THV4OjWh4AQWVlBXKRhOQy9Bx6sBP93zAQuZiTvcpgVlzI6AZ0mrLoF60QMeHm FI0TYMQaSkB/5HY99q/Azi0C9eAZmlZfqEU2TifewRFMBl/oc3CDV+od9Fi5rMaULmVahzLxsJk l3IZqfW3DGbxP+JAdcmVAMk1OsPciWvvDj X-Received: by 2002:a05:600c:511d:b0:42c:a72a:e8f4 with SMTP id 5b1f17b1804b1-42f777b798bmr18246715e9.14.1727859648066; Wed, 02 Oct 2024 02:00:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGJ9fypm3Gxsu/4MARBWysDebVpJq3nopplpdSmaPvmYe8Pg6/q+FiMNmAeOielTTPuUq6UFQ== X-Received: by 2002:a05:600c:511d:b0:42c:a72a:e8f4 with SMTP id 5b1f17b1804b1-42f777b798bmr18246485e9.14.1727859647601; Wed, 02 Oct 2024 02:00:47 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42f79d8d3c7sm12896495e9.4.2024.10.02.02.00.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2024 02:00:47 -0700 (PDT) Date: Wed, 02 Oct 2024 11:00:45 +0200 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH v5 4/5] tcp: Update TCP checksum using an iovec array User-Agent: K-9 Mail for Android In-Reply-To: <4efad680-ccf3-45a8-8929-cc5ae2be4760@redhat.com> References: <20240927135349.675850-1-lvivier@redhat.com> <20240927135349.675850-5-lvivier@redhat.com> <20241001092928.33755f2b@elisabeth> <20241001202216.5c3ee274@elisabeth> <4efad680-ccf3-45a8-8929-cc5ae2be4760@redhat.com> Message-ID: <21A5DD47-0291-44D7-A064-61BA36E4EA17@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 5QHCV2GWOG6FJ5NQTGI6I3JCZ3V2RF46 X-Message-ID-Hash: 5QHCV2GWOG6FJ5NQTGI6I3JCZ3V2RF46 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 2 October 2024 09:39:23 CEST, Laurent Vivier wrote: >On 01/10/2024 20:22, Stefano Brivio wrote: >> On Tue, 1 Oct 2024 09:29:28 +0200 >> Stefano Brivio wrote: >>=20 >>> On Fri, 27 Sep 2024 15:53:48 +0200 >>> Laurent Vivier wrote: >>>=20 >>>> [...] >>>>=20 >>>> +void tcp_update_check_tcp4(const struct iphdr *iph, >>>> +=09=09=09 const struct iovec *iov, int iov_cnt, >>>> +=09=09=09 size_t l4offset) >>>> { >>>> =09uint16_t l4len =3D ntohs(iph->tot_len) - sizeof(struct iphdr); >>>> =09struct in_addr saddr =3D { .s_addr =3D iph->saddr }; >>>> =09struct in_addr daddr =3D { .s_addr =3D iph->daddr }; >>>> -=09uint32_t sum =3D proto_ipv4_header_psum(l4len, IPPROTO_TCP, saddr,= daddr); >>>> +=09size_t check_ofs; >>>> +=09__sum16 *check; >>>> +=09int check_idx; >>>> +=09uint32_t sum; >>>> +=09uintptr_t ptr; >>>> + >>>> +=09sum =3D proto_ipv4_header_psum(l4len, IPPROTO_TCP, saddr, daddr); >>>> + >>>> +=09check_idx =3D iov_skip_bytes(iov, iov_cnt, >>>> +=09=09=09=09 l4offset + offsetof(struct tcphdr, check), >>>> +=09=09=09=09 &check_ofs); >>>> + >>>> +=09if (check_idx >=3D iov_cnt) { >>>> +=09=09err("TCP4 buffer is too small, iov size %zd, check offset %zd", >>>> +=09=09 iov_size(iov, iov_cnt), >>>> +=09=09 l4offset + offsetof(struct tcphdr, check)); >>>> +=09=09return; >>>> +=09} >>>> -=09bp->th.check =3D 0; >>>> -=09bp->th.check =3D csum(bp, l4len, sum); >>>> +=09if (check_ofs + sizeof(*check) > iov[check_idx].iov_len) { >>>> +=09=09err("TCP4 checksum field memory is not contiguous " >>>> +=09=09 "check_ofs %zd check_idx %d iov_len %zd", >>>> +=09=09 check_ofs, check_idx, iov[check_idx].iov_len); >>>> +=09=09return; >>>> +=09} >>>> + >>>> +=09ptr =3D (uintptr_t)((char *)iov[check_idx].iov_base + check_ofs); >>>> +=09if (ptr & (__alignof__(*check) - 1)) { >>>> +=09=09err("TCP4 checksum field is not correctly aligned in memory"); >>>> +=09=09return; >>>> +=09} >>>> + >>>> +=09check =3D (__sum16 *)ptr; >>>=20 >>> clang-tidy (14.0.6) says: >>>=20 >>> /home/sbrivio/passt/tcp.c:803:10: error: integer to pointer cast pessim= izes optimization opportunities [performance-no-int-to-ptr,-warnings-as-err= ors] >>> check =3D (__sum16 *)ptr; >>> ^ >>> /home/sbrivio/passt/tcp.c:854:10: error: integer to pointer cast pessim= izes optimization opportunities [performance-no-int-to-ptr,-warnings-as-err= ors] >>> check =3D (__sum16 *)ptr; >>> ^ >>>=20 >>> ...I'm still trying to figure out what that actually means. If it's >>> trivial I can fix that up on merge. >>=20 >> Something like this? > >It's ok for me. Do you want I resend a version with it or can you update t= he patch on the merge? No no, thanks, I'll update this on merge. --=20 Stefano