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 586CEA00BE for ; Thu, 10 Mar 2022 15:55:19 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4483441144; Thu, 10 Mar 2022 15:55:19 +0100 (CET) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mails.dpdk.org (Postfix) with ESMTP id 6E02B4113E; Thu, 10 Mar 2022 15:55:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646924117; x=1678460117; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=gruWDVDocuQVRH1und0HOupED1Y2hs0G1GVWF3cnNLM=; b=M4D8AURxriV94z/MAMVHOoUGvy8Cuf/VtJzNcaenNuzPwAFwYc3CCeyF 7ddHZqboHpaI8BohNpExNE71svgLGPOOT1kJSIeQk3VAW+LfLQpNxRgdn IxacC1bqAyfmfdkHbuILd+md7iAHH6Yer0v35/M9yooMUUF27gU8QLde/ wEVgXQi67Siz20dJgYZsLfG9dySaKlF0Cp+i610vez/Ww2UoCfSbg4H5+ t1W2SXGUWI2lxeHsW+oT+zxZiVL61++S088s0JKPbcThoxf3mOYDdpzMB z6WPF770EN3AHi/KDp4eYixnTAf7xxlPKUM/M4YdPGltoCwHJOAyiR7RA g==; X-IronPort-AV: E=McAfee;i="6200,9189,10281"; a="235872526" X-IronPort-AV: E=Sophos;i="5.90,171,1643702400"; d="scan'208";a="235872526" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Mar 2022 06:55:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,171,1643702400"; d="scan'208";a="712386777" Received: from orsmsx604.amr.corp.intel.com ([10.22.229.17]) by orsmga005.jf.intel.com with ESMTP; 10 Mar 2022 06:55:15 -0800 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX604.amr.corp.intel.com (10.22.229.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Thu, 10 Mar 2022 06:55:14 -0800 Received: from orsmsx604.amr.corp.intel.com (10.22.229.17) by ORSMSX610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Thu, 10 Mar 2022 06:55:14 -0800 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx604.amr.corp.intel.com (10.22.229.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Frontend Transport; Thu, 10 Mar 2022 06:55:14 -0800 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.175) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.21; Thu, 10 Mar 2022 06:55:13 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WFTrb8xhGiM//EPwM6QXu2/YjeWTPxnhAuRfmlQMr0aKknkeCpy1YjkY9KJEqn9R13LjTc05JhUQ2uWb8DY1aVAeaybecthQAJHUdntwrZBCyjLN0V+9lExPAItll9ZP6zC1iERmfOraMTrb1DSLYIZ/qtGME8uMCpuI6lDiG/IVmD9DOjpj3LIp0SiaLYdktIRr19yyXXsp858t+kIjc71K0qvQVAvx5ugXH6foomFGvfcY2FKbVkHlCYhMT0ef9rxDW7Gks2bNjxUcKc/A1zFyx5jhveORLp7Kop6aEXfrAUJp4/x8vhgWURAr1RRgzAguAGBEeIaZZapnED3VFQ== 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=gruWDVDocuQVRH1und0HOupED1Y2hs0G1GVWF3cnNLM=; b=esHp5aBLCUE8DC2iAMtaGWANQl6d1lp2NKDywo0H4GDy59hV/yBPxTgy0xP9JyDCqJFw4Q7zXOfyoUeZn7GG4a/4XJ3P9uN+0nto74gaw0tLIJoylc0B4E60mkTbHZ/7QRLlBy2cPz2tqD3BcYEHYeG6cjVFs/frJCq2QNNhonn8Awq33XmG4IgLEKT+DuZET/52BEagoLquxwt+Vkjn3hix/qWfA3hRy3pxb/RIQ4C0Xwi7dk+J+42UCtDJ9XCxhNQQkHfUnCsLomvSoVV5GjDNy2W1vfAznzLQyqxm9L7Cqi8FpQ1jxZaZ3n0mgEPre+XlTozYcOLnjKeJLgFAxg== 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 Received: from DM6PR11MB4491.namprd11.prod.outlook.com (2603:10b6:5:204::19) by BL0PR11MB3009.namprd11.prod.outlook.com (2603:10b6:208:31::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.15; Thu, 10 Mar 2022 14:55:11 +0000 Received: from DM6PR11MB4491.namprd11.prod.outlook.com ([fe80::ad2b:63fd:4cdd:130d]) by DM6PR11MB4491.namprd11.prod.outlook.com ([fe80::ad2b:63fd:4cdd:130d%4]) with mapi id 15.20.5061.022; Thu, 10 Mar 2022 14:55:11 +0000 From: "Ananyev, Konstantin" To: Luc Pelletier , "Richardson, Bruce" CC: "dev@dpdk.org" , "Li, Xiaoyun" , "stable@dpdk.org" Subject: RE: [PATCH v7] eal: fix rte_memcpy strict aliasing/alignment bugs Thread-Topic: [PATCH v7] eal: fix rte_memcpy strict aliasing/alignment bugs Thread-Index: AQHYKmZ5ykQ+CLdXFkCjUa77Y9VwTqy4xyQQ Date: Thu, 10 Mar 2022 14:55:11 +0000 Message-ID: References: <20220115194102.444140-1-lucp.at.work@gmail.com> <20220225163804.506142-1-lucp.at.work@gmail.com> In-Reply-To: <20220225163804.506142-1-lucp.at.work@gmail.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.6.401.20 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e3b73a32-077f-4c64-d8ff-08da02a5f9fa x-ms-traffictypediagnostic: BL0PR11MB3009:EE_ x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: NGPWBRwR3l+3TNWdE+023aoQS6+WDe5ieBt98SUdzVXkrCoXWQt7uHLLlnbLjws/hrnHBXbNc6f3OOk31W5Qhr/pAoL7fZVmwe6AK+bLKYdpe77PcQzyj+k930a2IsdhctP0trzuVyDrz/SwlhnnlUiahTd2ONIdLNYfOhaTzPdivc/V3I3Jc+eAki633s02B113GqObC+vkVKbf0d6FDyk7CklTLsEF1CP+kJgtlu5oD6XfYaJLjn1zMLj4a15Iec/jaKUUNulT03HYJRHPYYtfxqZ0P1fO6XcPTJiulKq9ce7yH8WzI6Rxmx4nM2Aowa/I/kmtFFrzZ2uTnMtro7pn2EtSf2zkFO4XszNLCe4kEKWPWS/UYIldDTOLjDvJ+w7ZUE1Or+8/M6S5aQoUU01PPeAr9182aDRVXTxN/xON9sdxqKvXClFXsqbQFA/QDVsm7SfkKIKFxOcurBE4g8xoFVywrvP3NfLj4XNvwkvA7WfBxMKgoy56Wpxjut4rjMxRB4zgxj60ejOBMzY+DUQ0NRTU+lG/AceOXHk/zgh2Y1DTUNOpbReZrxx/MAxrfJ++enNbGiLziK7x9XhsC4Prcx9++r/0p8aUDuhBknq24c7sfBhMQgAa3IAjFYKJIHd3b5nkCewYqhyhwLuBwYB5Op3yY7nn9h6xI9XK6dype9DKmtG0ZScpsYAsVNcLIWHUg4qLFdrjQxsRl/58Gw== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR11MB4491.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(9686003)(26005)(508600001)(86362001)(6506007)(71200400001)(186003)(38100700002)(38070700005)(83380400001)(8676002)(122000001)(7696005)(5660300002)(8936002)(66946007)(4326008)(66556008)(66476007)(66446008)(64756008)(76116006)(52536014)(33656002)(55016003)(2906002)(54906003)(6636002)(110136005)(316002)(82960400001); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?0Bm7NyYRSlSKHrk+PazQAZm8O0uKJ4iozsHjdWII9e4HYIq5v/TkbbeERRyy?= =?us-ascii?Q?5IhQgqTAKnxjGkqHvuRcgy3tNrPvR0M62UjLAehuTDuxUKNHalFn2SFkUfeS?= =?us-ascii?Q?HhzXD8sIUe+elREoEfRynz1gBH+TcAaAFWC/W2UfMFWX+6+MOMwBOaa2ats1?= =?us-ascii?Q?QLo/Gabzz9o02l5Ru/C3CklbrK+9+7bsVgWY7VirvzyT5Qlg0bbq5qaMGJK/?= =?us-ascii?Q?KDpM049oyBKr55LYYCaZUMnr+u7bHc1AnAqgFTnlMbGYIPHZMQJqfTvRRF8v?= =?us-ascii?Q?Wmu+oFZv1AKbDVei/39JZkvXnisPC30lPqJGLZRX1ZjC4vlTek9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S4u1qE5vzyQJV478Hm2wXupdSchOlTsoonII7UsU9/19?= =?us-ascii?Q?j+ftitVgVtbMSL7YkCxU9UFkqsa9f9e8B30N+votFjqdqPogkg0Taby0vO3C?= =?us-ascii?Q?qarEB2lfh5WPz9ye/c7duGRgUsQQbzCDbw5UKu8hDuDAI2gxz0ypztR+wg+v?= =?us-ascii?Q?rUPU8DUi318ojYMYWB697W4H1w0Gu4vyDOl2inIoF1/YPRv40tDIQt1iM1ZK?= =?us-ascii?Q?4jQXEseArCaTMDslIt8+rvd0gsJfEAXQAg+VNoDE9EYUvUCP6WbhOQ9zrt4b?= =?us-ascii?Q?W16EELQdOkeYJLW4RrJs+fFil2wbzSYO2xnw5LsebCPqY0aRvQvEhB5KpJ0j?= =?us-ascii?Q?D6ypuYUJ/m37QYuqf4CaR6JWaUkVicih7UdLZMdMz0d/fysG07lSV/EqSzuW?= =?us-ascii?Q?YBLhiXIT1zvZt3b9EG9gtdmLwcFdyy9ccBmql4VtXXUihFpflZPkdvcgEFRS?= =?us-ascii?Q?Or2zBg=3D=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB4491.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e3b73a32-077f-4c64-d8ff-08da02a5f9fa X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Mar 2022 14:55:11.2391 (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: h0wnEUsIqVPY3Q6+IGEYJB2nJ/XNcqVkLneK/1bvPQ+dCZ6ebNLK0p93VdTa9IjVNJwKwCAbT6WqCkjuBPoh48LaqlqnqnwEnY0AtEAqqyc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR11MB3009 X-OriginatorOrg: intel.com X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org > Calls to rte_memcpy for 1 < n < 16 could result in unaligned > loads/stores, which is undefined behaviour according to the C > standard, and strict aliasing violations. >=20 > The code was changed to use a packed structure that allows aliasing > (using the __may_alias__ attribute) to perform the load/store > operations. This results in code that has the same performance as the > original code and that is also C standards-compliant. >=20 > Fixes: d35cc1fe6a7a ("eal/x86: revert select optimized memcpy at run-time= ") > Cc: Xiaoyun Li > Cc: stable@dpdk.org >=20 > Signed-off-by: Luc Pelletier > --- > v7: > * Fix coding style issue by adding new __rte_may_alias macro rather > than directly use __attribute__ >=20 > v6: > * Refocus to fix strict aliasing problems discovered following > discussions in this thread. > * Modified the code to use __may_alias__ and packed structure. This fixes > both the undefined behaviour of unaligned access (which is not the main > concern), and also fixes the strict aliasing violations (which can cause > major bugs, as demonstrated in a previous message in this thread). > * Renamed new function from rte_mov15_or_less_unaligned to > rte_mov15_or_less. > * Modified code that copies <=3D 15 bytes to call rte_mov15_or_less. >=20 > v5: > * Replaced assembly with pure C code that uses a packed structure to make > unaligned loads conform to C standard. >=20 > v4: > * Added volatile to asm statements, which is required under gcc. >=20 > v3: > * Removed for loop and went back to using assembly. >=20 > v2: > * Replaced assembly with a regular for loop that copies bytes one by > one. >=20 > v1: > * Fix undefined behaviour of unaligned stores/loads by using assembly > to perform stores/loads. LGTM, thanks for highlighting and fixing the problem. Acked-by: Konstantin Ananyev Tested-by: Konstantin Ananyev As a side note, we probably need to check other similar places in DPDK code= .=20