From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B071DA0A0C; Wed, 28 Jul 2021 18:07:54 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7B56C40E64; Wed, 28 Jul 2021 18:07:54 +0200 (CEST) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2047.outbound.protection.outlook.com [40.107.236.47]) by mails.dpdk.org (Postfix) with ESMTP id EE7A940142; Wed, 28 Jul 2021 18:07:52 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jytzhfyza787HhR8Ytl1aANpPvUM9R5EHvX4NDzoboYK3nZPHHeQPTaYaFJ9rrYCE2vyqq/sxLJA8iofn3d5SvJZUtDDO87+lidn9LKLrJMJRFrHYoqCK19x7T+vg955DuAWtGB725cLPtBCo9t83AkFCsbEO8g+DbOF8YxEcKx7p9Jcg/3BPtpavhvCJV8ZNYCgsM8lzKXv3weWYEossOwrRMwxO9qefVDXdLZCDQzbuu0EcgdoTtadwXOPUoRDQO2AcxK4oOkTJx+DBBCDvJzMx0osmGn/lSZ+wvy9AqUfT0QKU4v75Tgz0As8HEulwGmvwvY43+RI72BS+Br0iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yWIHkRGdS1JSuXC9cHS3beMxNu0tBIV1Qo2hWwFLl2s=; b=KZefEthHSEBOIM4zukH7gw8FvA2BsuvpjNA5i4pe0MI1UGoZb4poKIRB0JUJSXaj7/TidHxNvdzSultO6sCpmCLPR/rKmrmOgxv6qAtZvzsq0LckhgDGlo/Zi3QXfHCUqS0GVisT6yE6/RghPenT7d/BY9Cfu/JU6Eo8wS2RwNTBwcI6yc0OpHAeWwbd/bMzGTkcDbe4sYAYZCAQIHPRtY5dLh+AINWKpAx4E6EEiRH1ArY1LM3iVl8FllFUiIQk9Ak6v1RQyfU20gZhlcHXHIDhY5MUsWWIut6lbIFw9Xzovalbkwse5WK45j6Z7SwMawd8srbVzdzilJPpg6uXxg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yWIHkRGdS1JSuXC9cHS3beMxNu0tBIV1Qo2hWwFLl2s=; b=RWg7NrnR/JV/H2Ew4eMljn9g9WuLZjIQpgkGaLtFpJ6+GXOLN6C5esmSpOf9sp4GATPpSLwK3jST1kqu1q1k1ESVG+zJdlNMCQxlFM1++7kiN3aSXFeBsnuYMxq/0ub8NkttqJ7n0fZEw3+DU05n4jPdI1GdQLjyWMGI9HGDwO3McsoaETdiPgyCHh+zg5seaJgoapejc25ZbF5bidwhw+w+RZeSBvhVkHGCu8pqAn6Zc2rAKDzCeSKcpRrV4jc+n4vHE2ArqRrd6mCh9dcXRiBS+ORVv18dQ1ZazovIfjA860ubL//hqATdc6HG9K/bYZH+T5nE1pH9fnOAbAMAUg== Received: from BY5PR12MB4834.namprd12.prod.outlook.com (2603:10b6:a03:1b2::17) by BYAPR12MB3496.namprd12.prod.outlook.com (2603:10b6:a03:d8::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.29; Wed, 28 Jul 2021 16:07:51 +0000 Received: from BY5PR12MB4834.namprd12.prod.outlook.com ([fe80::3814:b909:389e:4030]) by BY5PR12MB4834.namprd12.prod.outlook.com ([fe80::3814:b909:389e:4030%5]) with mapi id 15.20.4373.019; Wed, 28 Jul 2021 16:07:51 +0000 From: Gregory Etelson To: Olivier Matz CC: "dev@dpdk.org" , Ajit Khaparde , Andrew Rybchenko , Ferruh Yigit , NBU-Contact-Thomas Monjalon , "stable@dpdk.org" , Xiaoyun Li Thread-Topic: [PATCH v2] app/testpmd: fix TX checksum calculation for tunnel Thread-Index: AQHXguh4syGJazA4nE2s7L8tXYr5f6tYb2+AgAAQKhA= Date: Wed, 28 Jul 2021 16:07:51 +0000 Message-ID: References: <20210719083309.15428-1-getelson@nvidia.com> <20210727130757.30724-1-getelson@nvidia.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: 6wind.com; dkim=none (message not signed) header.d=none;6wind.com; dmarc=none action=none header.from=nvidia.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1c9a20c2-89eb-4ed4-820d-08d951e1d9d4 x-ms-traffictypediagnostic: BYAPR12MB3496: x-ld-processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3513; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ioJusSd+F6wrvvAujG4EjyDTOTBTdy3rw0lleDXbQvxzp9RgFnoZ5BDBTQ778ajUfczAooevW1d/Y0Ng27S9zwZm4sQhwSOz7eDY9gopIYtaUyl+XhshWgSBqKWcRZXuMNmeZ4Hkk3Rd3/+k5IJ5FmJ3ztKgHx3EixmE34OAg7XwmysOpj6KLzm8QkFggh7BrQ48roMRBkXt+qMerkOsesJZKQsDyIPR1wUFtCt6LgK9FKG4aHoGQp62EpX+imudMp9Nv/yRNHJQboJWcAMOj5fzpX0g5GGy+JOrYjzN1fZUFY0HNiBHMegTBx+Fr/mPOPbk1NDuy4tRaMLnHWDb2GcELpGY8NUegWneFgYlWa+D8ljJW1HRyGt3889/GGLjeRdn65IWSxBla20L0aOZHmtKnZecsH3my6gHE7PcUpVoI/PAhreHxb7IoqbLbK9wdQfdMpvz+wMr0Ov+H7bOh+rVLM3UltFU2Z24oFDdpjmivQ+glTvmAc5v0+yUTvGuqoyHrdF31JzgK2Hbm+D/Sfzzy/4KYwj+qAFI7DFNbhsWd4gRg9/kNLpUSM1Xyo2NfiYxI+m8p3RlogzWinOTg2eVja5byiIpFHxoVyTZU+QIvtn+e69p9UYgYgRRlrYCmajqCYy2tgxWiISrYj54/X5iC1SmkmQ7k9Sx4yNXyl2kgd/k1KpvdY5T2Gyc0EenvmyuS5tKUzQGAPE85mfFQJdq+PrDq75P0nONtIhCgQWv5irGDQjfFrQCatiKZ5EPcGqWtewsnTJKgn80+5a8vweznWb+k0X9HTWVmv7EKfHUIotAicz6jGuqHbHn145XTFYPNPPneoGCdOinPeMoh4PGz8KwroEja2NFZHhUUcg= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BY5PR12MB4834.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(376002)(396003)(136003)(366004)(39860400002)(9686003)(66446008)(8936002)(8676002)(966005)(55016002)(86362001)(76116006)(38100700002)(6506007)(7696005)(5660300002)(316002)(478600001)(71200400001)(83380400001)(64756008)(186003)(4326008)(66946007)(122000001)(66476007)(2906002)(26005)(33656002)(54906003)(66556008)(38070700005)(52536014)(6916009)(21314003); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?sjG4z7Lsv+K/rCDfYTyRbwZnj9c68IFLYR/vfADKDcGGHP2Pl8EbppJxc23f?= =?us-ascii?Q?VpCEFtW6PpVWa9ZxN+SLNbsuvkvrsXGoxxO8X5lQ+5w4zdsi+cWJkjDTuuvT?= =?us-ascii?Q?C+YtL+OL3wmQjMJCd8OBWtRiCRoqPt2ZHVX9oZwC0R0Jviw2n0munrDfahrl?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+gZ8RWrQu0DDtIYq/wiU9M/Ik6sTI+YYXboVYWXjtKabzi?= =?us-ascii?Q?Qmnse33nWgbvVm00ox7MSjoi3dfyu4Yr5YKOY6mIT7543ovIJnlDpWXGTg3R?= =?us-ascii?Q?HqTYXr4ewuhxQVtNfBikwj+gAJHT6JC0iMa2xVPbesYdGysRm70449Wz1uYQ?= =?us-ascii?Q?e43dj3dFocnX84skYyEE81STuAHM4z7I5h8N4k5vxkEJeP6OGtgOokjED5UP?= =?us-ascii?Q?xNmNPECkW4MY/6zLq1vQZZmxLaGTrSwhi87mT0U1m86cRcqVrQ5G9s78r+B7?= =?us-ascii?Q?vOaq1iYaeWp+1d1/LyQOuKGp?= x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BY5PR12MB4834.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1c9a20c2-89eb-4ed4-820d-08d951e1d9d4 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Jul 2021 16:07:51.2270 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: nPR7mWGiFQcx13giFJFBHAAXHdIz4XGIff/jklz6ogL590pwQ4EWTf+pPxTM6QApweZnImYkxJxPoobpXjcI/A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3496 Subject: Re: [dpdk-dev] [PATCH v2] app/testpmd: fix TX checksum calculation for tunnel X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Hello Oliver, Please see my comments below > On Tue, Jul 27, 2021 at 04:07:57PM +0300, Gregory Etelson wrote: > > TX checksum of a tunnelled packet can be calculated for outer headers > > only or for both outer and inner parts. The calculation method is > > determined by application. > > If TX checksum calculation can be offloaded, hardware ignores existing > > checksum value and replaces it with an updated result. >=20 > This is not always true. Actually, the checksum value is optionally set b= y > software to the value that is expected by the hardware to offload the > checksum correctly. This is done through rte_eth_tx_prepare(), which is c= alled > in csumonly test engine. >=20 > For instance, on an ixgbe NIC, it does: >=20 > rte_eth_tx_prepare() > eth_dev->tx_pkt_prepare() > ixgbe_prep_pkts() > rte_net_intel_cksum_flags_prepare() > if packet is IP, set IP checksum to 0 > if packet is TCP or UDP, set L4 checksum to the phdr csum >=20 > This driver-specific rte_eth_tx_prepare() can indeed do nothing and let t= he > hardware ignore the checksum in the packet. > You are right. I'll update the patch comment in v3. =20 > > If TX checksum is calculated by a software, existing value must be > > zeroed first. > > The testpmd checksum forwarding engine always zeroed inner checksums. > > If inner checksum calculation was offloaded, that header was left with > > 0 checksum value. > > Following outer software checksum calculation produced wrong value. > > The patch zeroes inner IPv4 checksum only before software calculation. >=20 > Sorry, I think I don't understand the issue. Are you trying to compute th= e inner > checksum by hardware and the outer checksum by software? >=20 Correct. Inner checksum is offloaded and outer computed in software. =20 Consider this example: Tunneled packet arrived at port A and being forwarded through port B. The packet arrived at port A with correct inner checksums - L3 and L4. Port B TX offloads inner L3 only. process_inner_cksums() sets "ipv4_hdr->hdr_checksum =3D 0;" unconditionally= . Inner L3 checksum value will be restored by port B TX checksum offload, but= when=20 process_outer_cksums() runs software calculation on outer L4 it will use 0 = and produce wrong result. Therefore, the patch zeros inner checksum values only before actual softwar= e calculations. > > Fixes: 51f694dd40f5 ("app/testpmd: rework checksum forward engine") >=20 > I'm not sure the problem origin is this commit (however, I may have > misunderstood your issue). >=20 > At the time this commit was done, it was required to set the TCP/UDP > checksum to the pseudo header checksum to offload an L4 checksum. See: > https://git.dpdk.org/dpdk/tree/lib/librte_mbuf/rte_mbuf.h?id=3D51f694dd40= f5 > #n107 >=20 > The introduction of rte_eth_tx_prepare() API removed this need, see: > https://git.dpdk.org/dpdk/commit/?id=3D6b520d54ebfe >=20 > Thanks, > Olivier >=20 > > Cc: stable@dpdk.org > > > > Signed-off-by: Gregory Etelson > > --- > > v2: > > remove blank line between Fixes and Cc explicitly compare with 0 > > value in `if ()` > > --- > > app/test-pmd/csumonly.c | 23 ++++++++++++----------- > > 1 file changed, 12 insertions(+), 11 deletions(-) > > > > diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c index > > 0161f72175..bd5ad64a57 100644 > > --- a/app/test-pmd/csumonly.c > > +++ b/app/test-pmd/csumonly.c > > @@ -480,17 +480,18 @@ process_inner_cksums(void *l3_hdr, const struct > > testpmd_offload_info *info, > > > > if (info->ethertype =3D=3D _htons(RTE_ETHER_TYPE_IPV4)) { > > ipv4_hdr =3D l3_hdr; > > - ipv4_hdr->hdr_checksum =3D 0; > > > > ol_flags |=3D PKT_TX_IPV4; > > if (info->l4_proto =3D=3D IPPROTO_TCP && tso_segsz) { > > ol_flags |=3D PKT_TX_IP_CKSUM; > > } else { > > - if (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) > > + if (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM) { > > ol_flags |=3D PKT_TX_IP_CKSUM; > > - else > > + } else if (ipv4_hdr->hdr_checksum !=3D 0) { > > + ipv4_hdr->hdr_checksum =3D 0; > > ipv4_hdr->hdr_checksum =3D > > rte_ipv4_cksum(ipv4_hdr); > > + } > > } > > } else if (info->ethertype =3D=3D _htons(RTE_ETHER_TYPE_IPV6)) > > ol_flags |=3D PKT_TX_IPV6; @@ -501,10 +502,10 @@ > > process_inner_cksums(void *l3_hdr, const struct testpmd_offload_info > *info, > > udp_hdr =3D (struct rte_udp_hdr *)((char *)l3_hdr + info-= >l3_len); > > /* do not recalculate udp cksum if it was 0 */ > > if (udp_hdr->dgram_cksum !=3D 0) { > > - udp_hdr->dgram_cksum =3D 0; > > - if (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) > > + if (tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) { > > ol_flags |=3D PKT_TX_UDP_CKSUM; > > - else { > > + } else { > > + udp_hdr->dgram_cksum =3D 0; > > udp_hdr->dgram_cksum =3D > > get_udptcp_checksum(l3_hdr, udp_h= dr, > > info->ethertype); @@ > > -514,12 +515,12 @@ process_inner_cksums(void *l3_hdr, const struct > testpmd_offload_info *info, > > ol_flags |=3D PKT_TX_UDP_SEG; > > } else if (info->l4_proto =3D=3D IPPROTO_TCP) { > > tcp_hdr =3D (struct rte_tcp_hdr *)((char *)l3_hdr + info-= >l3_len); > > - tcp_hdr->cksum =3D 0; > > if (tso_segsz) > > ol_flags |=3D PKT_TX_TCP_SEG; > > - else if (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) > > + else if (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) { > > ol_flags |=3D PKT_TX_TCP_CKSUM; > > - else { > > + } else if (tcp_hdr->cksum !=3D 0) { > > + tcp_hdr->cksum =3D 0; > > tcp_hdr->cksum =3D > > get_udptcp_checksum(l3_hdr, tcp_hdr, > > info->ethertype); @@ -529,13 > > +530,13 @@ process_inner_cksums(void *l3_hdr, const struct > testpmd_offload_info *info, > > } else if (info->l4_proto =3D=3D IPPROTO_SCTP) { > > sctp_hdr =3D (struct rte_sctp_hdr *) > > ((char *)l3_hdr + info->l3_len); > > - sctp_hdr->cksum =3D 0; > > /* sctp payload must be a multiple of 4 to be > > * offloaded */ > > if ((tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) && > > ((ipv4_hdr->total_length & 0x3) =3D=3D 0)) { > > ol_flags |=3D PKT_TX_SCTP_CKSUM; > > - } else { > > + } else if (sctp_hdr->cksum !=3D 0) { > > + sctp_hdr->cksum =3D 0; > > /* XXX implement CRC32c, example available in > > * RFC3309 */ > > } > > -- > > 2.32.0 > >