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 4852FA00C4 for ; Thu, 3 Nov 2022 11:45:05 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 39B5741145; Thu, 3 Nov 2022 11:45:05 +0100 (CET) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2041.outbound.protection.outlook.com [40.107.220.41]) by mails.dpdk.org (Postfix) with ESMTP id DBCCC40694; Thu, 3 Nov 2022 11:45:02 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DRZSOVSANJ1sYTuZKfbmdcfYlJU4JbfOZTRuzLkYQkVzIP0LLVpQqZFDoehFo0j4rfuke7VF2fHBpWKh5FHWRIJHrxYFB3IIOo3dbAxXRxVXanla5IZjHq3WsK/qqz+tzxXt6KeC5q6TacvvnNyzlZ7vSj9YrWEmkwocZuTM4aA8FCtuTn85XsTPgzaSDMN6M0E/y/ckOSq3NXnYpoC9UmD8veuz5Kwam8vGmd1i365cISWwEPLgSe3BdB2qC2ujEkWmbBD/jxHUNZIToAf1lPuxDgDzJm1u+Q/6P5XgB2Hg8iMdVXPxARKmcarBsRwFHYnobDedCJ769Age3KDOqw== 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=V40qzf9hP0p20RYDstkuxf8xDnunVFWqY7CE3TssGx4=; b=fMOW8ywoEy/dtbxwBvIv++3Ahh9qBUWZkQw80J6nsWd6Dr9wd1JKu0zjpgQ4tvRuA39dsebsFKutzM3N/mH/YhmgEIf0TeZOPt2ZgMaBjNuharChTyUFQ77jG5XesDYg1IzT1AKszmC5oe/Y9CW7j563ONLnLLqaPgZP2k3ShWp6+P+1Hshafp1MTeeJRgXrclS/Fciu+Gsx6raroy+CK6rgWbU0z5UV1miQMmuxIxkfxkaf3iCsgZzPpJ+PaRuVD1AEC2+lttgi+PcxdTIYV314DSCsvtEAF3fTQikfe/38cvGkfpOAPmJCFrCrTSbh6cphO6C7a61PQ+SHL9qw5g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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 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=V40qzf9hP0p20RYDstkuxf8xDnunVFWqY7CE3TssGx4=; b=nKnuU/eos8n8uCCTMB8uuDGxAH9giRwfWIk58tIbpSZw9meqLaTecbDyEPeaV23i1yJfqOVqwGTDgora8ePAwdNV/iw0Ig8Q6mdtXPq8oZVvjUDkXh+Km3TCFd3rAVarJInDi5bvK1c0ps7D6Wwqg1wGzdHwSG77WJdTTKbsZDkU2n3AJy+Kj7XVjgdnXpvJ0+2eyZ9hs9nSuh7cNOmP4ZiLRYC4pUAokzcauBSUWZ9q8oumC527H+ovMm8uLs4ngK+6hNnrJ7s4HZfp688TY0hWSc3xSXq01oCfNXrFzdOgrc3RKSVXD7aeTzeC20e63SLw/3M4qSRB9poQcie/Sg== Received: from MW4PR03CA0317.namprd03.prod.outlook.com (2603:10b6:303:dd::22) by PH7PR12MB6665.namprd12.prod.outlook.com (2603:10b6:510:1a7::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.22; Thu, 3 Nov 2022 10:45:00 +0000 Received: from CO1NAM11FT021.eop-nam11.prod.protection.outlook.com (2603:10b6:303:dd:cafe::34) by MW4PR03CA0317.outlook.office365.com (2603:10b6:303:dd::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.22 via Frontend Transport; Thu, 3 Nov 2022 10:45:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CO1NAM11FT021.mail.protection.outlook.com (10.13.175.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.20 via Frontend Transport; Thu, 3 Nov 2022 10:45:00 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Thu, 3 Nov 2022 03:44:45 -0700 Received: from nvidia.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Thu, 3 Nov 2022 03:44:42 -0700 From: Gregory Etelson To: CC: , , , , Viacheslav Ovsiienko , "Anatoly Burakov" , Dmitry Kozlyuk Subject: [PATCH] common/mlx5: fix shared mempool subscription Date: Thu, 3 Nov 2022 12:44:27 +0200 Message-ID: <20221103104427.1677-1-getelson@nvidia.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT021:EE_|PH7PR12MB6665:EE_ X-MS-Office365-Filtering-Correlation-Id: a25f10b1-d9ed-46df-0985-08dabd88751c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Vnus01n/3nnncl0NDA/zpNCZqNbDZkVveixsYz/UMd0V8iOeFtCtUeZueJKL/4vlHbRT08tEIyFCu4KmjdCFKAuAJ/CcUqcBq4BdauyIagc8U7WFT8hwVTPsX3xS9lbNnyTCIdaz+yNg+jY1WhhXBetIDJ+FE2hTcGo5wtG6VwzFHcOJ0/dm4nUbVZ1RKqxj4QD8+qKLXHAUGI+PKk7RxuiPlaGm8Lqytdc7P0Gi6abFNQSZa+CePsTbPRdVtHpU3T0AlErCyNx6PTU6vXXuKUwg/OUnLVjzOT6tJDC5DIaq5o0SEhNUzPg6l6koVy28mzBtu5KplmmXyKYzqYVpFi7zEnbkz7BdVvqriyfgKT18YTPj8tLAyezeQTcOZUgv/SygKZ1GlF/hPG+7iiBlqKIlNXx+5stRn2j5dwuHlu+jliWaRob8DRejDzuBEPS1wF2hAL4aArgRnSYRifdsBJs2St7KzUGt1hoWJsfcIhiCD/M+K1rb4rtbU5xW27X4rxc4144v7qPYO39lqcYykULrbNjSdndNL6SWncH6QJs7WzBt6CDtsN5E+4Qp9GBQK1KJoSpzOlQGqjQXadEAuguudUA9dyjuuOYmR5hyhazV7dIc2hffWJCOkrU077dndAd7Y4fx/Yx8gmgxVLQE7SFCy9NO03hKtc6bAOuXoPn2yxH5rio7hxNjHOYI/y9044IPfUhvZ4za6UNupAt0WVeQuARxOxcu772ts0ZERXnyQOLWPLIIYc6qboS7U4OtQcLFCBJXEE5xmrgdKYXt6w== X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230022)(4636009)(376002)(39860400002)(346002)(396003)(136003)(451199015)(46966006)(36840700001)(40470700004)(66899015)(82310400005)(36756003)(107886003)(8936002)(7696005)(6666004)(5660300002)(2906002)(36860700001)(8676002)(70206006)(316002)(55016003)(70586007)(4326008)(40480700001)(6916009)(54906003)(40460700003)(41300700001)(356005)(7636003)(86362001)(82740400003)(47076005)(26005)(426003)(478600001)(186003)(336012)(1076003)(2616005)(6286002)(83380400001)(16526019); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2022 10:45:00.2601 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a25f10b1-d9ed-46df-0985-08dabd88751c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT021.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6665 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 MLX5 PMD counted each mempool subscribe invocation. The PMD expected that the mempool subscription will be deleted after the mempool counter dropped to 0. However, current PMD design unsubscribes mempool callbacks only once. As the result, the PMD destroyed mlx5_common_device but kept shared RX subscription callback. EAL tried to activate that callback and crashed. The patch removes mempool subscriptions counter. The PMD registers mempool subscription once only. An attempt to register existing subscription returns EEXIST. Also, the PMD expects to remove subscription when mempool unsubscribe was activated. Fixes: 8ad97e4b3215 ("common/mlx5: fix multi-process mempool registration") Cc: stable@dpdk.org Signed-off-by: Gregory Etelson Acked-by: Matan Azrad --- drivers/common/mlx5/mlx5_common.c | 22 +++++++++++----------- drivers/common/mlx5/mlx5_common_mr.c | 1 - drivers/common/mlx5/mlx5_common_mr.h | 1 - 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/drivers/common/mlx5/mlx5_common.c b/drivers/common/mlx5/mlx5_common.c index bf22c0694d..0ad14a48c7 100644 --- a/drivers/common/mlx5/mlx5_common.c +++ b/drivers/common/mlx5/mlx5_common.c @@ -577,6 +577,11 @@ mlx5_dev_mempool_event_cb(enum rte_mempool_event event, struct rte_mempool *mp, } } +/** + * Primary and secondary processes share the `cdev` pointer. + * Callbacks addresses are local in each process. + * Therefore, each process can register private callbacks. + */ int mlx5_dev_mempool_subscribe(struct mlx5_common_device *cdev) { @@ -588,14 +593,13 @@ mlx5_dev_mempool_subscribe(struct mlx5_common_device *cdev) /* Callback for this device may be already registered. */ ret = rte_mempool_event_callback_register(mlx5_dev_mempool_event_cb, cdev); - if (ret != 0 && rte_errno != EEXIST) - goto exit; - __atomic_add_fetch(&cdev->mr_scache.mempool_cb_reg_n, 1, - __ATOMIC_ACQUIRE); /* Register mempools only once for this device. */ - if (rte_eal_process_type() == RTE_PROC_PRIMARY) + if (ret == 0 && rte_eal_process_type() == RTE_PROC_PRIMARY) { rte_mempool_walk(mlx5_dev_mempool_register_cb, cdev); - ret = 0; + goto exit; + } + if (ret != 0 && rte_errno == EEXIST) + ret = 0; exit: rte_rwlock_write_unlock(&cdev->mr_scache.mprwlock); return ret; @@ -604,15 +608,11 @@ mlx5_dev_mempool_subscribe(struct mlx5_common_device *cdev) static void mlx5_dev_mempool_unsubscribe(struct mlx5_common_device *cdev) { - uint32_t mempool_cb_reg_n; int ret; + MLX5_ASSERT(cdev->dev != NULL); if (!cdev->config.mr_mempool_reg_en) return; - mempool_cb_reg_n = __atomic_sub_fetch(&cdev->mr_scache.mempool_cb_reg_n, - 1, __ATOMIC_RELEASE); - if (mempool_cb_reg_n > 0) - return; /* Stop watching for mempool events and unregister all mempools. */ ret = rte_mempool_event_callback_unregister(mlx5_dev_mempool_event_cb, cdev); diff --git a/drivers/common/mlx5/mlx5_common_mr.c b/drivers/common/mlx5/mlx5_common_mr.c index 1d54102b54..0e1d2434ab 100644 --- a/drivers/common/mlx5/mlx5_common_mr.c +++ b/drivers/common/mlx5/mlx5_common_mr.c @@ -1138,7 +1138,6 @@ mlx5_mr_create_cache(struct mlx5_mr_share_cache *share_cache, int socket) &share_cache->dereg_mr_cb); rte_rwlock_init(&share_cache->rwlock); rte_rwlock_init(&share_cache->mprwlock); - share_cache->mempool_cb_reg_n = 0; /* Initialize B-tree and allocate memory for global MR cache table. */ return mlx5_mr_btree_init(&share_cache->cache, MLX5_MR_BTREE_CACHE_N * 2, socket); diff --git a/drivers/common/mlx5/mlx5_common_mr.h b/drivers/common/mlx5/mlx5_common_mr.h index f774ccbf33..13eb350980 100644 --- a/drivers/common/mlx5/mlx5_common_mr.h +++ b/drivers/common/mlx5/mlx5_common_mr.h @@ -81,7 +81,6 @@ struct mlx5_mr_share_cache { uint32_t dev_gen; /* Generation number to flush local caches. */ rte_rwlock_t rwlock; /* MR cache Lock. */ rte_rwlock_t mprwlock; /* Mempool Registration Lock. */ - uint32_t mempool_cb_reg_n; /* Mempool event callback registrants. */ struct mlx5_mr_btree cache; /* Global MR cache table. */ struct mlx5_mr_list mr_list; /* Registered MR list. */ struct mlx5_mr_list mr_free_list; /* Freed MR list. */ -- 2.34.1