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 B1312A0C4C; Tue, 23 Nov 2021 13:48:58 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 45F8A40040; Tue, 23 Nov 2021 13:48:58 +0100 (CET) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2068.outbound.protection.outlook.com [40.107.237.68]) by mails.dpdk.org (Postfix) with ESMTP id 2ACE84003C for ; Tue, 23 Nov 2021 13:48:57 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RmdD6B+XSSPAlID29wCsvgsH+eIbI51NFjIfVz9OPY4JOJ6HuIFASQrzzqIG7vXclORFEVzZ75nfQEJYnOfbwCThVOjjfPvfcq7os3BBJKG5Hum+oMyIN2B2nKPbPXu9SwpxBMJw5fX9i8FonWGhzgrllvjzUvE+ZOsRac5LttdHc+naSLyXwY+R8Ve1QmUDnm4LY25/lbGo3m1SrR8wHPRZIvtw6RUGqqSiNChO5IGDwEOtU1+/A+uqOfZ+PbsE1msGpOcWi9NDXCVZTqydkjjX7HjT8a/kAdSz/w2r7iK5YS2HyVKa+APLnB4BR1v5D7tYKkEIGR4DvZ4oH372Fw== 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=BNK5AZc7TnyKgZ/CMfNe3ivUI2Bzbt1/NfywfN4rbwo=; b=oKGDYLqtPr6YYsGPtW1wE50fFAV8Iub7Nc1IP8Knan2SM6Iu1koQTtwFFQgUE89JThefZlFGFvPuoTm57w3lV4wDA0JiNLJTy2M/4AfDiHwp5n0HSuWPmy9g/mopm5xrWF0PcpjkcsW6peFqr3voXOtHK7atD5fXY0cy3AUJRbuutFQYNbQNI9qNa2yo8rzceB89b1wjhI0hz5ip9rYmnSP/g8qotmAfRzCRWgJDTHip48ra7zWuEGElvY1WSfUrRInZ/4/C0oOlke/GmNJzc7pdCMPnfCpSAxY8zVnqvBKE15Mvz9Fz+QVGq5vu0jOyl/u+fdb6qb//JBK8PydgdQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=BNK5AZc7TnyKgZ/CMfNe3ivUI2Bzbt1/NfywfN4rbwo=; b=j5l24polaFKIDuJiYM4h5UWsxBLZae6Z5pEVs2t6sf9dduvRC4uDV6NfX76bm7ESuZSj6xaU2iqBDYIZNhj7okCI2Do4dQ7uLI1E7P9rypIs9tUsYpIKJi8SB09Jf0/9LGyoVQPI7apohTi+W0LNkEuOjHD0xlw52xa2QNLOqUZ1Yq6ms8OJiE+csrNCKD64YjYsPdtKQY44Cncz+FDfGBa7Xw2Uy512XGXgtfHldaCeEYcAICp924+iYzUU9r+skTcwkk88xmQxX1jH1XCrVbpokgAhq76jqD86DwYkxmvK7k4UPBB3ZXTYNjad3yvQ1aKEZrx+V5C53mGJPFC/0Q== Received: from CO2PR04CA0182.namprd04.prod.outlook.com (2603:10b6:104:5::12) by BN8PR12MB4625.namprd12.prod.outlook.com (2603:10b6:408:71::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.21; Tue, 23 Nov 2021 12:48:55 +0000 Received: from CO1NAM11FT059.eop-nam11.prod.protection.outlook.com (2603:10b6:104:5:cafe::38) by CO2PR04CA0182.outlook.office365.com (2603:10b6:104:5::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.19 via Frontend Transport; Tue, 23 Nov 2021 12:48:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) 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.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by CO1NAM11FT059.mail.protection.outlook.com (10.13.174.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4713.20 via Frontend Transport; Tue, 23 Nov 2021 12:48:55 +0000 Received: from nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 23 Nov 2021 12:48:50 +0000 From: Bing Zhao To: , CC: , , Dmitry Kozlyuk Subject: [PATCH] common/mlx5: fix shared MR ranges allocation Date: Tue, 23 Nov 2021 14:48:35 +0200 Message-ID: <20211123124835.17514-1-bingz@nvidia.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e75f9c63-6fd5-4188-f311-08d9ae7f9c06 X-MS-TrafficTypeDiagnostic: BN8PR12MB4625: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:70; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VTRBn2yBDNMTTBKBtuHDvJ4mYTtib63wXNf53VPJl/vtbP/2StzZ00K1LJrrGNj23H4kvL/5MAsijEFvYMquhlP5BfiDzxBN1r8hNJJyHO0zdIwnZcipLg6Uq/ImhoCi11TKMJTTx299zPx2rCYZqll05zCnDwg16ANfsxLyLyJZ74xexiu93pu5nF6n6Bdtp3+JuBHiwBjkl2hLNyreQuQnlPUf/W0sLB7W2E+4jZsjo19MmO+OKeLhC74lgOFLPSCvZtNdVhJrMSbvo/FUikkimcDQytuVCd/debkNLk9mP/2MrpjUqJl0ZX9fEj/Z771iMCkvc9G2ZzJQToFx9pR2vXx9dksLHihjWMSPJO+n9KqwNobfgXf70mZ3w6LsN2NUlsXUSuMPtwFFkR9BDEFEghnH6SJH8g9Qjgv9NA3bJv8aFEZoGEHwPbTBOBiPFK6uNsTipmIzWZ/UHc4Orq7pJxEmh2I4CCu0nH2V9Q07+c7V/XdYfJTSifdwR+usiOdi+uYt5dRqMoCmuGUU0uRBURWBULHmQhAQ5YOGj+oiybCM5vvy+xIz6GFIVKnjx0JffXbVQ9Bcj4NcSEaHSJd4inPejWFbnzGVOR2KAcV/VuPN7Hyo23s7qj+mvSTV/KpEV10IvIiLl+jV300ptMaxdS0+yBq5US4djLQYfspm1signfjEPSjepld96+yJM/Vn4FLRztsidTkHJGvvaA== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(36840700001)(46966006)(2616005)(83380400001)(70206006)(70586007)(36860700001)(6636002)(110136005)(356005)(4326008)(316002)(7696005)(82310400004)(55016003)(2906002)(6666004)(336012)(508600001)(8676002)(426003)(86362001)(5660300002)(6286002)(107886003)(47076005)(26005)(8936002)(186003)(7636003)(16526019)(36906005)(54906003)(36756003)(1076003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Nov 2021 12:48:55.0307 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e75f9c63-6fd5-4188-f311-08d9ae7f9c06 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT059.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB4625 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 Memory regions (MRs) were allocated in one chunk of memory with a mempool registration object. However, MRs can be reused among different mempool registrations. When the registration that allocated the MRs originally was destroyed, the dangling pointers to the MRs could be left in other registrations sharing these MRs. Splitting the memory allocation of registration structure and MRs in this commit solves this pointer reference issue. Fixes: 690b2a88c2f7 ("common/mlx5: add mempool registration facilities") Signed-off-by: Bing Zhao Acked-by: Viacheslav Ovsiienko Reviewed-by: Dmitry Kozlyuk --- drivers/common/mlx5/mlx5_common_mr.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/common/mlx5/mlx5_common_mr.c b/drivers/common/mlx5/mlx5_common_mr.c index 47121d8ff7..01f35ebcdf 100644 --- a/drivers/common/mlx5/mlx5_common_mr.c +++ b/drivers/common/mlx5/mlx5_common_mr.c @@ -1515,15 +1515,23 @@ mlx5_mempool_reg_create(struct rte_mempool *mp, unsigned int mrs_n, struct mlx5_mempool_reg *mpr = NULL; mpr = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, - sizeof(*mpr) + mrs_n * sizeof(mpr->mrs[0]), + sizeof(struct mlx5_mempool_reg), RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY); if (mpr == NULL) { DRV_LOG(ERR, "Cannot allocate mempool %s registration object", mp->name); return NULL; } + mpr->mrs = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, + mrs_n * sizeof(struct mlx5_mempool_mr), + RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY); + if (!mpr->mrs) { + DRV_LOG(ERR, "Cannot allocate mempool %s registration MRs", + mp->name); + mlx5_free(mpr); + return NULL; + } mpr->mp = mp; - mpr->mrs = (struct mlx5_mempool_mr *)(mpr + 1); mpr->mrs_n = mrs_n; mpr->is_extmem = is_extmem; return mpr; @@ -1544,6 +1552,7 @@ mlx5_mempool_reg_destroy(struct mlx5_mr_share_cache *share_cache, for (i = 0; i < mpr->mrs_n; i++) share_cache->dereg_mr_cb(&mpr->mrs[i].pmd_mr); + mlx5_free(mpr->mrs); } mlx5_free(mpr); } -- 2.27.0