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 8A6BBA0C41; Wed, 17 Nov 2021 12:03:20 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 799AD411ED; Wed, 17 Nov 2021 12:03:20 +0100 (CET) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2059.outbound.protection.outlook.com [40.107.236.59]) by mails.dpdk.org (Postfix) with ESMTP id C5FA64117D; Wed, 17 Nov 2021 12:03:18 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oHb8bBggk3ZURDvQknb4xY6y2wcpED9zuVfp3FTPWGFwYFQ5dQfNaYL2L4GduvaaTZ8D2Xvp39+CSJMj3ECTXCh8yPJkavt0nV6T4+uwleDa4/+PgBFGQRFCaLiUEbPkNd7GyabVdotGg/ZoW0u6xInhiaBqx4Vn4n0Ua2qHzHmpPfzHfOmPXcHlWayMesWJf+a7wkrINmtQ5Egcuy0I0zQPYXO053vIJqWBF8IHuw49d0AzGf05M+HhZKnPiA/jTv/zdlW3C8lQ4VBW3V6um8Vr4x/X77GTHsuTctCcttvXkUt/cKJ+V687E2UXFdPPIMfdiL9MbWMAJmcRFlShzQ== 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=YClSGpIjlX+C/lYlUOLU4xxq0eOJXb9GPl0epChs1B0=; b=V/2o2+qkuzqqA5PsgGnva61/hzNF1BRp0rc0xnHpytmVSaDT45hDY+vGEz7Hd3smyi9pjNk2c/26/FL0ijuXmsYQSOeECJQewk2VDuQkyYu4TsNBhMu+RJzdeJ7U6iz1B2NbrMyyyDrVCzzzI7jOL9FPEPcMRHGbINQ3EkeCdKqzmh7UhpV5n58ghm+5+8aeYWpsGCYuhtTDCghx/2Dp+jkjk1mcpMu5tJXCMlaRga0+MGRmCywx4fdeJlfyhXHZLwx7jpVrAuiBAAfbLvRoVPJGV/JPw5bKvqthD3lckYK+ky70jo6kz/pG7X/l4ZwA9C18UtNfVV3t3QD4Q40E8Q== 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=YClSGpIjlX+C/lYlUOLU4xxq0eOJXb9GPl0epChs1B0=; b=O5WmaMZXmzZ3CBnx/pj8vJjXEI+bMhyijBwvcnKnoUBYBM1GdHuQa+R5b3xeKr7hvFBKg9SdXpp2+We799Qo84yftuhTW/TP9WRDNx0wMEqIjJBiUIO7GvoyVgQsLPNBNBBQOgLh5NMWcyVcQ6o160CH0tzNWSoZ2E3h3mNoMpMA1PiHYYapaXx22OL2SKiAkQA3IEFG9tRdGZT9jCvUuKCaU3ygr8aIfP18M1GobUX3PmqKr3I6fP+s8uEJbhOHh7FdIpDHHUS3rr9ymrGkgn+QCIfcMe1DwBQ+iN8lf48RDtkVZu9v5u7APdYhd2RgmNh9DVQSFfMMXZYUfV8Hng== Received: from BN0PR04CA0197.namprd04.prod.outlook.com (2603:10b6:408:e9::22) by DM4PR12MB5326.namprd12.prod.outlook.com (2603:10b6:5:39f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.17; Wed, 17 Nov 2021 11:03:17 +0000 Received: from BN8NAM11FT042.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e9:cafe::ec) by BN0PR04CA0197.outlook.office365.com (2603:10b6:408:e9::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.26 via Frontend Transport; Wed, 17 Nov 2021 11:03:17 +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 BN8NAM11FT042.mail.protection.outlook.com (10.13.177.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4690.15 via Frontend Transport; Wed, 17 Nov 2021 11:03:17 +0000 Received: from nvidia.com (172.20.187.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 17 Nov 2021 11:03:14 +0000 From: To: CC: Matan Azrad , Raslan Darawsheh , Viacheslav Ovsiienko , Michael Baum , Subject: [PATCH] common/mlx5: fix memory leak in Windows dereg MR function Date: Wed, 17 Nov 2021 13:02:55 +0200 Message-ID: <20211117110255.2060417-1-michaelba@nvidia.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.5] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9a7050d5-409f-47e8-fa13-08d9a9b9dbe7 X-MS-TrafficTypeDiagnostic: DM4PR12MB5326: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:240; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: a6olKY1CiW4Y7vBQny26SrE6WhEHGtF652szicDZW4pZAExzvfKVieXGAS6KRxmukb9OPW+XusVuwcL9K1Rq6zg4v0LALc02ucRmmNJQnISTg8DpEotTa3n3DhKkR2y1YlW+nKvruOmZHRUUvpcp+sOErLxboR/rCKLG/7mYb36pHXEauC6Ya52Z1x3ElgWjCmWHhCOHNKzoEZVXKhBNhHFBv69FIjqkcSbHMzjW0vj/+a08I09tlHkc6BkUSqgGle25/RueknNcjytBtKEcSXG4MpX1bTmqRh5HicBm9COE/gLYiJ4BrvSlgAqO6d6kUQTgjOKclyI5J/hPpjcG7bGp9ZtAcScymeezr/OxbHd9eQ4FgYiU2PNDmSw+9oWAtxu5O3Gi15E76og9LSnBC2zG85FVipEkuX7yWtV19j095yOL6VIHU1l89U3/jYXQPK//vXTlUZ+3ibmHEkZqV3xdJkkQe0hvDl+nDb04uwjelMPuC8Fa9R/fCt/LyuZyPil08Ko27WAmxziMbFQAzrsCh/yHzNF6/evDK6eggjdJL76ZQG+bARuqnLDrJIIB/ENDWv5677pf4nPlgrGRYg96zhllBPMTvveSR5NQs21g5rPbZu3PeDJQZ0r2AbjSHLil1l3/3xyV5EUD0hQIEna4404vFSpA7uo0FrIQxIckpAoknjJrLkOA1DGUarHucaesxqLsghRtneEtvn/JgQ== 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)(46966006)(36840700001)(1076003)(26005)(36756003)(70586007)(508600001)(2906002)(316002)(2876002)(36860700001)(36906005)(6286002)(5660300002)(54906003)(55016002)(8676002)(82310400003)(450100002)(7696005)(4326008)(2616005)(6916009)(70206006)(426003)(83380400001)(7636003)(336012)(16526019)(6666004)(86362001)(186003)(356005)(47076005)(8936002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Nov 2021 11:03:17.1383 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9a7050d5-409f-47e8-fa13-08d9a9b9dbe7 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: BN8NAM11FT042.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5326 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 From: Michael Baum The "mlx5_devx_cmd_mkey_create" DevX cmd allocates DevX object using mlx5_malloc and then creates MKey using glue function. Compatibly, "mlx5_devx_cmd_destroy" cmd releases first the MKey using glue function, and then free the DevX object using mlx5_free. On Windows OS, the reg_mr function creates Mkey using "mlx5_devx_cmd_mkey_create" cmd, but dereg_mr function using directly glue function without freeing the object. This behavior causes memory leak at each MR release. In addition, the dereg_mr function makes sure that the MR pointer is valid before destroying its fields, but always calls the memset function that makes a difference to it. This patch moves the dereg_mr function to use "mlx5_devx_cmd_destroy" instead of glue function, and extends the validity test to the whole function. Fixes: ba420719823c ("common/mlx5: add reg/dereg MR on Windows") Cc: stable@dpdk.org Signed-off-by: Michael Baum Acked-by: Matan Azrad --- drivers/common/mlx5/windows/mlx5_common_os.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/common/mlx5/windows/mlx5_common_os.c b/drivers/common/mlx5/windows/mlx5_common_os.c index 5fb45d12ea..162c7476cc 100644 --- a/drivers/common/mlx5/windows/mlx5_common_os.c +++ b/drivers/common/mlx5/windows/mlx5_common_os.c @@ -368,9 +368,11 @@ mlx5_os_reg_mr(void *pd, static void mlx5_os_dereg_mr(struct mlx5_pmd_mr *pmd_mr) { - if (pmd_mr && pmd_mr->mkey) - claim_zero(mlx5_glue->devx_obj_destroy(pmd_mr->mkey->obj)); - if (pmd_mr && pmd_mr->obj) + if (!pmd_mr) + return; + if (pmd_mr->mkey) + claim_zero(mlx5_devx_cmd_destroy(pmd_mr->mkey)); + if (pmd_mr->obj) claim_zero(mlx5_os_umem_dereg(pmd_mr->obj)); memset(pmd_mr, 0, sizeof(*pmd_mr)); } -- 2.25.1