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 E574345CEF; Tue, 12 Nov 2024 09:22:01 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D36C5402C3; Tue, 12 Nov 2024 09:22:01 +0100 (CET) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2050.outbound.protection.outlook.com [40.107.220.50]) by mails.dpdk.org (Postfix) with ESMTP id 9CD7040298 for ; Tue, 12 Nov 2024 09:22:00 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VXgXsfIdYKt8LFenPEU6dMVg0Jmr1+ocKaICYfEQuQBAlCpZs0xdLAS/CPQAR3e5IiMbnHJOuotl2YB3gcQ8cmQifkGrewHgP+WvLA2UvuEc6zgJVYN3+EOGu7JwyyokeaWW9UdW5x+Mec+Oqo/HiIqRlj3mPJW2W8QJIegRJ9gbyzGOJABsAQ0ZMvciAk0tTR+OBDM+KDXb4FHNoOFJ45PXaNRnttiIH2P2/eQH3zhsnC2jMkBJyVB/vPCfhRV70joER9CX8dPsKAP1YAcw+dNOtqSz7dh7m1Lu1oiRIuQERzl2vTMXwwQfzCeHUz18fL89/B0DXVnaFM61sHBJEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=ZNQqzStID7LT7guQDd/B+K916kTHS73J19ku5a0PaW4=; b=MIDe2B6npcuCaU+FIoov4IRoTbRvAiZk7tnNWDVDd4bJYpnjqj6RJMrez8ML1ZSsedj0Phgbon2VcacXrWUkq7KJkSQ9n9Y9UB06WyagNuwnHYPTMhDC9BXEmgHO6FOCbH8R5pWAAs1q7E0GM4fVfcNj8emnaEZHCd+9yC/RPQ4SuPYyEX5aQqjX7R3SCwOMp3obsHD/JmLLEIqthYg2Nq0GqgxdSYIu4LNN1lm/TLDG7SJRfZ5eD08CLa25JyvMACC8CR9bv5ipplpYNTlp01sDQW0Yh7V/klWMGnOXtFG5YC6ZrvYrDLW9eC/nC4mJV09KKjIsj5lsBDAFOZqDXg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=ZNQqzStID7LT7guQDd/B+K916kTHS73J19ku5a0PaW4=; b=lJxCc5uk33W6Fw52qINiVyvXFhibSpFGPA7sy1M0IPBuYVAswpOnTIhlDX59LJQJYK3RvHKeBzmQ9Z640YM05p1gnLXQPoKZI+aPbFerdFRPj+Cbep3s7Q3pr+ldB7IggRyDax8B5Cz94jOzQP/jSlxbgH6GHAE7GqdDYB/tXWHntMvTSkP1jnX3Ck07uAjIbMG7HiJ2LV0Og2KOom596z9ti0HQWdAMOd3IJXKvl+rfxHOee9wpzpsjBKQnsYEDu1jS9+oqLv6xlmIQG17cla18gFVERryUid/b9le7bQPs5WP2i18yyRCa37wzGFfDLAgcEw967hFJWq7Y319dQA== Received: from BN0PR03CA0037.namprd03.prod.outlook.com (2603:10b6:408:e7::12) by BY5PR12MB4051.namprd12.prod.outlook.com (2603:10b6:a03:20c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.29; Tue, 12 Nov 2024 08:21:56 +0000 Received: from BL02EPF0001A100.namprd03.prod.outlook.com (2603:10b6:408:e7:cafe::d5) by BN0PR03CA0037.outlook.office365.com (2603:10b6:408:e7::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.29 via Frontend Transport; Tue, 12 Nov 2024 08:21:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by BL02EPF0001A100.mail.protection.outlook.com (10.167.242.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.14 via Frontend Transport; Tue, 12 Nov 2024 08:21:55 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 12 Nov 2024 00:21:43 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Tue, 12 Nov 2024 00:21:42 -0800 Received: from nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4 via Frontend Transport; Tue, 12 Nov 2024 00:21:40 -0800 From: Shani Peretz To: CC: , , , , Bing Zhao , Dariusz Sosnowski , Viacheslav Ovsiienko , "Ori Kam" , Matan Azrad Subject: [PATCH] common/mlx5: fix misalignment issue detected by ASan Date: Tue, 12 Nov 2024 10:21:26 +0200 Message-ID: <20241112082126.40349-1-shperetz@nvidia.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A100:EE_|BY5PR12MB4051:EE_ X-MS-Office365-Filtering-Correlation-Id: d09596be-2ac8-41c5-153e-08dd02f3120a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?4QFSxnQteQRupkpvnBYH/akuDxRpN2oPmrlpqS+3EyNSqki+2jKsOgHe3JAp?= =?us-ascii?Q?fZkgQpgzap7hclTACqFMcL/oYla0AM4FjMTb23B7HBk0vNRuGzWG6tzygpLd?= =?us-ascii?Q?nb/r17A+OcFXWEwFSnEcaiofZVapI2OvfRTP9QMXDiQ9XCtmOXuJiaiWswxc?= =?us-ascii?Q?sDTR33BZqb8UR9wJp1OtRMq1pvj3yIpA12aHV8cl//Gf72F4o/KJwjJLLBnN?= =?us-ascii?Q?KwqIGBEI23kyAYRfOQDCyF4OphQ4gNZPwdtdJJzUvNWFh9rlArn34YbMekAd?= =?us-ascii?Q?iiGMudlzB2Qv9fM02wsMGl41PU2QJjB2//iXrJi8XlFZXRr4SquWfBhDE5yB?= =?us-ascii?Q?uBR5tLignfAUYCbw16A3FjMSP5rLB2tK9ivibRQW+RwFtaKl3vynshTFB8Lu?= =?us-ascii?Q?e//wkl/x8q7O74xTNVawJfQY1EnYEUQIuGRZ9u6OLSR6lkGXBD6LzZk/KdqX?= =?us-ascii?Q?CIiIAlNGrcNC+vTqit9dx1ebxrpWoCPeLurquL0hbGDZA99GecZMYDHmjueD?= =?us-ascii?Q?xb41fCBoOemr2yKwjeHmK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am-Report: CIP:216.228.118.232; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge1.nvidia.com; CAT:NONE; SFS:(13230040)(1800799024)(36860700013)(376014)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2024 08:21:55.7562 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d09596be-2ac8-41c5-153e-08dd02f3120a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.232]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0001A100.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4051 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 ASan reported a runtime error due to misalignment involving three structures. The first issue arises when accessing l_inconst->cache[MLX5_LIST_GLOBAL]->h. If struct mlx5_list_cache is not properly aligned, the pointer gc, assigned to l_inconst->cache[MLX5_LIST_GLOBAL], could be misaligned. To address this, the __rte_aligned(16) attribute was added to struct mlx5_list_inconst in struct mlx5_list, which includes struct mlx5_list_cache, ensuring that the entire mlx5_list structure, including mlx5_list_cache, is aligned to 64 bytes. To resolve misalignment issues with struct mlx5_flow_handle, The initialization of resources for the ipool ensures that the ipool size is rounded up to the 8-byte boundary The error in assigning values to actions[i] was due to potential padding or misalignment in struct mlx5_modification_cmd. To prevent such issues, the __rte_packed attribute was added to struct mlx5_modification_cmd, ensuring that the structure is packed without extra padding which helps avoid misaligned memory accesses. Two performance degradation tests were conducted. Following are the results comparing this commit to the most recent commit in mlnx_dpdk_22.11 at that time (b69408ae453). Before asan misalignment fix (average kflows/sec) - Insertion - 4461.269, Deletion - 7799.9992 After: Insertion - 4579.0642 , Deletion - 7913.0034 Fixes: 9a4c36880704 ("common/mlx5: optimize cache list object memory") Cc: suanmingm@nvidia.com Signed-off-by: Shani Peretz Acked-by: Bing Zhao --- drivers/common/mlx5/mlx5_common_utils.h | 2 +- drivers/common/mlx5/mlx5_prm.h | 4 ++-- drivers/net/mlx5/mlx5.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/common/mlx5/mlx5_common_utils.h b/drivers/common/mlx5/mlx5_common_utils.h index c5eff7a0bf..9139bc6829 100644 --- a/drivers/common/mlx5/mlx5_common_utils.h +++ b/drivers/common/mlx5/mlx5_common_utils.h @@ -131,7 +131,7 @@ struct mlx5_list_inconst { * For huge amount of entries, please consider hash list. * */ -struct mlx5_list { +struct __rte_aligned(16) mlx5_list { struct mlx5_list_const l_const; struct mlx5_list_inconst l_inconst; }; diff --git a/drivers/common/mlx5/mlx5_prm.h b/drivers/common/mlx5/mlx5_prm.h index 359f02f17c..5d73751182 100644 --- a/drivers/common/mlx5/mlx5_prm.h +++ b/drivers/common/mlx5/mlx5_prm.h @@ -914,7 +914,7 @@ struct mlx5_modification_cmd { unsigned int field:12; unsigned int action_type:4; }; - }; + } __rte_packed; union { uint32_t data1; uint8_t data[4]; @@ -925,7 +925,7 @@ struct mlx5_modification_cmd { unsigned int dst_field:12; unsigned int rsvd4:4; }; - }; + } __rte_packed; }; typedef uint64_t u64; diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 52b90e6ff3..6e4473e2f4 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -907,7 +907,7 @@ mlx5_flow_ipool_create(struct mlx5_dev_ctx_shared *sh) */ case MLX5_IPOOL_MLX5_FLOW: cfg.size = sh->config.dv_flow_en ? - sizeof(struct mlx5_flow_handle) : + RTE_ALIGN_MUL_CEIL(sizeof(struct mlx5_flow_handle), 8) : MLX5_FLOW_HANDLE_VERBS_SIZE; break; #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) -- 2.34.1