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 03FFCA0C43; Mon, 18 Oct 2021 18:15:44 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BF4D240142; Mon, 18 Oct 2021 18:15:44 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mails.dpdk.org (Postfix) with ESMTP id C795A40141 for ; Mon, 18 Oct 2021 18:15:43 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10141"; a="208386431" X-IronPort-AV: E=Sophos;i="5.85,382,1624345200"; d="scan'208";a="208386431" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2021 09:14:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,382,1624345200"; d="scan'208";a="661428183" Received: from fmsmsx605.amr.corp.intel.com ([10.18.126.85]) by orsmga005.jf.intel.com with ESMTP; 18 Oct 2021 09:14:09 -0700 Received: from fmsmsx604.amr.corp.intel.com (10.18.126.84) by fmsmsx605.amr.corp.intel.com (10.18.126.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.12; Mon, 18 Oct 2021 09:14:09 -0700 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.12 via Frontend Transport; Mon, 18 Oct 2021 09:14:09 -0700 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.173) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2242.12; Mon, 18 Oct 2021 09:14:09 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nJKfNi+wot3J5N1wwaXfIZJAWbup7fSo+kaBxjgxL2rQIrNc7cWc4oRulNwqBO9rmwYVINCxWiQyT1kLrB2Kly3M1rtJbFpgMrIAtx/Pny2vqrjv807Ln98xqRdjXf4eApVM3KBhGMB6Wd3iprGYuloFCCUB1Fybk/8/yXldpuJWmJAESvDyXyzezbthra8UdkWW4lr+BimnuzEi9RltV0P1nrLUr20Itb3n4bitBmn8IH71NKsX9zJaq/6sfzwmaEGKByEsbhfsKWG+4fs7+7nKqX6vrJsJHInrJaI3m0q8TiehoNqw9Z+wESzNmT3x+8VRiFVB+Q8MPK92dAZJxg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9Kx8p8yEmflBXBYVltaojCawASmTiWHJIHHOrBltUms=; b=fiVIQcUNYE9QB4fyNDSKIWrYEeHGPCkGwC64D9EVEQ2h0qJ3uhkv4YzbtPAVTJTLS5m7qS8InwzeF+w5y1KKDdJBlyl2OtopjgS4TQc/xY5pWHLUqUgrvl0DC5WXnzEb3aiTn3OJrp0LNZjITfPjH7f8Apl58K3t6M5+OMZeC6VcsAdUKgonxr3nN66kjrBZwXr7JdwUvJ7pg8HkLqCDBXdcYu5+Pxq6J7oXXZz2x6o4+IUffpSlXgK8ppvx7j5lbMvDI22gbiPOFoNf6J9hdZtqracyqbqh/GSFrFSQt1e8dydSLU1AQ63II+r5JF01NGGxQlxA3fbjeBbIbDPkWg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9Kx8p8yEmflBXBYVltaojCawASmTiWHJIHHOrBltUms=; b=pGNpPDGtPiDwXx+6mGy4zJo4GDh20Gk3uk9e7uoUALQ2DmFtVhME8FSnf+Z6wsvpCWWWCp1YkWjeEvr96DwtcjHkFKfLW0BEqh5ftEo7/50zuhEATHCN6p6dH9SRsVTEhlAdZYb4O6BredA84GodfYJ3W4SgucVyLf36m21PqeA= Authentication-Results: 6wind.com; dkim=none (message not signed) header.d=none;6wind.com; dmarc=none action=none header.from=intel.com; Received: from PH0PR11MB5000.namprd11.prod.outlook.com (2603:10b6:510:41::19) by PH0PR11MB4871.namprd11.prod.outlook.com (2603:10b6:510:30::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Mon, 18 Oct 2021 16:14:07 +0000 Received: from PH0PR11MB5000.namprd11.prod.outlook.com ([fe80::bd7d:29be:3342:632c]) by PH0PR11MB5000.namprd11.prod.outlook.com ([fe80::bd7d:29be:3342:632c%5]) with mapi id 15.20.4608.018; Mon, 18 Oct 2021 16:14:07 +0000 Message-ID: <7e604c46-b2cd-09d6-bcd8-068a5c19122a@intel.com> Date: Mon, 18 Oct 2021 17:14:01 +0100 Content-Language: en-US To: Olivier Matz , =?UTF-8?Q?Morten_Br=c3=b8rup?= , Georg Sauthoff CC: Thomas Monjalon , David Marchand , References: <20211017203718.801998-1-mail@gms.tf> <20211017203718.801998-2-mail@gms.tf> <98CBD80474FA8B44BF855DF32C47DC35D86C46@smartserver.smartshare.dk> From: Ferruh Yigit X-User: ferruhy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: DB6PR0501CA0047.eurprd05.prod.outlook.com (2603:10a6:4:67::33) To PH0PR11MB5000.namprd11.prod.outlook.com (2603:10b6:510:41::19) MIME-Version: 1.0 Received: from [192.168.0.206] (37.228.236.146) by DB6PR0501CA0047.eurprd05.prod.outlook.com (2603:10a6:4:67::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Mon, 18 Oct 2021 16:14:06 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8dcdfeee-62d2-43e8-0973-08d992524fee X-MS-TrafficTypeDiagnostic: PH0PR11MB4871: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: L1vGt53Q6UeTsVFZ0Vf6AFZxjDGjlR83r53KpDRAKsx3YltH+RXU7ZOqGOWfXxoFwWTpk69IC5QbgNXqovYbw9igXGxa7CYqcYQI+rHuZSpE7JMPWA/5KgYUinQlrQGf9CSvSw8MbKocX+WZCmoFG4qgiIXOwO+JhAoXtuYo5B23khcMNUws9CFQglt9Y3JJGExGyhHJQFS8GAvFBfnhfcSvcnKzFYqY5iGizqw+IpPdbnPcp7z1UYIj9UTGQjJD3814WdTCwZFF97cmrxdTgY/u2fLUy1TdnqkhYzu0krxz0kXhi0am/wG3kV1xCoNcVh6B78/5Vs54ChkDEpZ9zjXaER8yVGGg35aYd05cdnlZWDhS6DpKv14H4nF9zOLqMqP2v9+K0jUzEOSmeorFQxmEzNHmZP4ijgcsYnEVaLiV+cBGqU/IrmpDHvBVGsmEV1+1S6OlbdYxLfcJqc05puhKQEETyAadrLuIGI0T150P6CuZAhLQN++6adO+MR7siYaMMxTK/KD6b4DDMp9vxoIDyjC97k5eQ/5fTBfaeoRVbHenbbpif70TWu6NSqg1wOOkqhnAXT+xT+jOZJrYTSluSWAlolE5BwbBSiF6Mm80mRw5Ha0auSsroA/Dv5LtrQI63cnVUMAfRnuJOTitcAstd+25r26XRh+6etXyFtxZkWjYvID1JxINZ2K6Ifxqdc6wOyG1RzPlYjl/U4X0Ag== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR11MB5000.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(31696002)(4326008)(8936002)(5660300002)(86362001)(44832011)(8676002)(508600001)(31686004)(66574015)(82960400001)(2906002)(2616005)(36756003)(110136005)(54906003)(6486002)(53546011)(186003)(66556008)(66476007)(83380400001)(26005)(6666004)(66946007)(38100700002)(16576012)(316002)(956004)(45980500001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?UytzMmIvbmYwQ3VsaU1Jekl3UlRxNmdKNi8xRVcrRDhBL3paNVRLRkx1UUhS?= =?utf-8?B?RlhHYXFJZEg5TXBJemd6M1ZvZEV0bkZLMy9xQXM2d0JaMVdVc1plMzNtN0ZP?= =?utf-8?B?dzFPOVdKbG1WOWhQYUo0d0xSQUNnd3FlU3ppTzduNnZJYjRwUzY0ZjZuaTFW?= =?utf-8?B?bkdSZk1wRWdSd0lkQ3kreVR0aEZuY0V3U3hua2xPYm5nUVFobVNjazBZa1Ey?= =?utf-8?B?U2d6aTBYYUNRN3pMVU5LbFk1bldGeGhmaE5POGdIWVNoR0pTR0FMNU4zSHNk?= =?utf-8?B?aFp6MHlXMW1UWjF5L0JCYTcwLzk2TUJoY2ZxQnZUM3NzY3Z3K0Y3SHV0enRW?= =?utf-8?B?eU1nWjJZM0pmRDJqOUR1YkdXelNvcWRZR3JrY045YTZRV3dseE41c3JaRk1v?= =?utf-8?B?Slh0Q3MzKzd2bk5oNmR3ak5vMWk0dHBvalJScGVHK2ZpNTBqV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GEzU1JmSDE5ZkJBRnYxa2tXTmxj?= =?utf-8?B?RG95cDVsVjZndlIvNkFmTGZBVmxSamd5bGhPL3pNNFRpMHhzeXNPVW1qUVVu?= =?utf-8?B?MllZODlMbExVZzcwRnpORVlwQzh4OUNtdnhDVmxCV29yZVlSeWFuYlZRaFFK?= =?utf-8?B?NEVFWjhaY25DQlJNbEdrS1lzc2VJL0czNUt5L1F6RVFKM2pqZ2VuL1pUT2RS?= =?utf-8?B?K1pTWEZkdUllSitueWFUc3BzVksrTEY5bXJDVE1id0MzYkhYNXVpbWJIWmw3?= =?utf-8?B?NDdOb1l3Q2Z1SFBSVzFBL2wyeC9RUi9Ka0VDKzlUNWR6NlBpSXhteTVoWEQr?= =?utf-8?B?RE9RWnE1QkFqY3hMbjNrejQzUWFtcW5QN1p4SjR2SFFaYlJyVHdqUHlkMjRy?= =?utf-8?Q?5pqVZwuJSSwyudIZ5zSs0ftQIpuLU0haN8fyV35?= X-MS-Exchange-CrossTenant-Network-Message-Id: 8dcdfeee-62d2-43e8-0973-08d992524fee X-MS-Exchange-CrossTenant-AuthSource: PH0PR11MB5000.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2021 16:14:07.8008 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mk9XAut0/7V9GvBGWN6C3FLWFQUv45PT05p8V0gZVrhMgoDq8JPVrI3IgTFMptW4NQcJeuY6QRatWBT5TTdV+g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB4871 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH v2 1/1] net: fix aliasing issue in checksum computation 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" On 10/18/2021 8:58 AM, Olivier Matz wrote: > On Mon, Oct 18, 2021 at 09:35:41AM +0200, Morten Brørup wrote: >>> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Georg Sauthoff >>> Sent: Sunday, 17 October 2021 22.37 >> >> +Ferruh, as delegate to v1 in Patchwork. >> >>> >>> That means a superfluous cast is removed and aliasing through a uint8_t >>> pointer is eliminated. NB: The C standard specifies that a unsigned >>> char >>> pointer may alias while the C standard doesn't include such requirement >>> for uint8_t pointers. >>> >>> Also simplified the loop since a modern C compiler can speed up (i.e. >>> auto-vectorize) it in a similar way. For example, GCC auto-vectorizes >>> it >>> for Haswell using AVX registers while halving the number of >>> instructions >>> in the generated code. >>> >>> Signed-off-by: Georg Sauthoff >>> --- >>> lib/net/rte_ip.h | 27 ++++++++------------------- >>> 1 file changed, 8 insertions(+), 19 deletions(-) >>> >>> diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h >>> index 05948b69b7..1b8c6519a9 100644 >>> --- a/lib/net/rte_ip.h >>> +++ b/lib/net/rte_ip.h >>> @@ -141,29 +141,18 @@ rte_ipv4_hdr_len(const struct rte_ipv4_hdr >>> *ipv4_hdr) >>> static inline uint32_t >>> __rte_raw_cksum(const void *buf, size_t len, uint32_t sum) >>> { >>> - /* workaround gcc strict-aliasing warning */ >>> - uintptr_t ptr = (uintptr_t)buf; >>> + /* extend strict-aliasing rules */ >>> typedef uint16_t __attribute__((__may_alias__)) u16_p; >>> - const u16_p *u16_buf = (const u16_p *)ptr; >>> - >>> - while (len >= (sizeof(*u16_buf) * 4)) { >>> - sum += u16_buf[0]; >>> - sum += u16_buf[1]; >>> - sum += u16_buf[2]; >>> - sum += u16_buf[3]; >>> - len -= sizeof(*u16_buf) * 4; >>> - u16_buf += 4; >>> - } >>> - while (len >= sizeof(*u16_buf)) { >>> + const u16_p *u16_buf = (const u16_p *)buf; >>> + const u16_p *end = u16_buf + len / sizeof(*u16_buf); >>> + >>> + for (; u16_buf != end; ++u16_buf) >>> sum += *u16_buf; >>> - len -= sizeof(*u16_buf); >>> - u16_buf += 1; >>> - } >>> >>> - /* if length is in odd bytes */ >>> - if (len == 1) { >>> + /* if length is odd, keeping it byte order independent */ >>> + if (unlikely(len % 2)) { >>> uint16_t left = 0; >>> - *(uint8_t *)&left = *(const uint8_t *)u16_buf; >>> + *(unsigned char*)&left = *(const unsigned char *)end; >>> sum += left; >>> } >>> >>> -- >>> 2.31.1 >>> >> >> Great work documenting your thoughts behind this patch, Georg! I, for one, didn't know about the aliasing difference between uint8_t and unsigned char. :-) >> >> After taking a good look at v2 and the Godbolt reference to confirm the claimed benefits, there can be no doubts about this patch. > > +1, thanks for the good documentation > >> Reviewed-by: Morten Brørup > > Acked-by: Olivier Matz > Updated patch title as: "net: fix aliasing in checksum computation" Added fixes tags: Fixes: 6006818cfb26 ("net: new checksum functions") Fixes: e079655c41fb ("net: fix build with gcc 4.4.7 and strict aliasing") Cc: stable@dpdk.org Following warning fixed in next-net: ERROR:POINTER_LOCATION: "(foo*)" should be "(foo *)" #65: FILE: lib/net/rte_ip.h:168: + *(unsigned char*)&left = *(const unsigned char *)end; Applied to dpdk-next-net/main, thanks.