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 67CFEA0C43; Sun, 12 Sep 2021 12:37:26 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2DE6441123; Sun, 12 Sep 2021 12:37:03 +0200 (CEST) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2053.outbound.protection.outlook.com [40.107.243.53]) by mails.dpdk.org (Postfix) with ESMTP id D454D4003D; Sun, 12 Sep 2021 12:36:59 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Chx4wQRb84Oh6vjmWZHb7wUj2dJq52MMoq4ebOUyMWceRVY1Ms2FfDlja5jIbJxr6eMVU7wUCi1eFj3RlOAo4v5LWchd2pVnVLLONK6lDvRtMPOwtJkwBxvQVV+xfKnIaFqTyOUbwjI8bWl8EfYIrxGBmdRf60ONdmMi/yVVnCT+vtyyC/WQo4EdSsRGh4EMH3O+xUNP6iW/RZv9f6jrfdBtgoUF129tF7alMz/jhC0L7Kc1p8izp474j9l/8QCR8y4eJEcULB6zRAw793Oa2HrutxdWRZ/aRxSaaCK4dOWA8eXQqRCT3sp6GIuRxeqLaoxYY9IPg9BY8VFgL2IONg== 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; bh=yXULFrZQQipRGBJ5uwZr4/vkOOkDIu9qcrynYAHDElY=; b=JJ5iC0t1uAimXbOVnuQB5Y5rdpGwcIhRBjwXp8vOGaj+qpvfqrbwsn7oQa8pr+MMLXoBv9rvoza20YTGBHK2BBXryQmqk64fcU7FlDWmoWnFxX9ItdJwZuZeg5IeYbzwGrDgBZL8dHKTgNsdNxOslKzQQJzfQ0AJOJsiUaYEImfB7msEcJdu1N4liDPHZ91UZShlkxOhvdvzwlNvQlAA0CYK47NNeUUEt55bom0ud6vX9xK/LKWr+BaWVr/7Tt81oQ5GWbq/P7oAt/81f0sE2Q7stXB5gc7bW6KUgIt2tfn965WTTINbSCBWeb+OcmrXcjyIRmOycLqeOQGh4r6b6g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none 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=yXULFrZQQipRGBJ5uwZr4/vkOOkDIu9qcrynYAHDElY=; b=gF0XyqehIIVx+fnd2eHKrg4xSBJuKXs+Px7oz7/b3TBNDIeQWd130DJMArJG2LelXEERtW90JyNCwSQ97TwJxhPQ9N869GTfTpgbY9MA6gXCtacq1pppQKQuD9lCvl1o94+f8y89SwAs70gGaLpBnzeiOt5gK5tLZOTelWWfq2dRBdJp/gXh5PR6L0m2zK61G1RkuX9wYb3g3/uKyaofo3pdrDV6cpRC+FIqe9sF3iacS5XBpiqmAg1rrEBUDx5FAuksjy+FicQNMuuuRgeFiAnbRHg6v6KC87a+aen3/Hn0U+YZP17CSZRTOhOVF4FhZcm540ZReXvugU06DExlLg== Received: from BN9PR03CA0210.namprd03.prod.outlook.com (2603:10b6:408:f9::35) by BY5PR12MB3972.namprd12.prod.outlook.com (2603:10b6:a03:1a8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.17; Sun, 12 Sep 2021 10:36:58 +0000 Received: from BN8NAM11FT023.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f9:cafe::2c) by BN9PR03CA0210.outlook.office365.com (2603:10b6:408:f9::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Sun, 12 Sep 2021 10:36:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by BN8NAM11FT023.mail.protection.outlook.com (10.13.177.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4500.14 via Frontend Transport; Sun, 12 Sep 2021 10:36:58 +0000 Received: from DRHQMAIL107.nvidia.com (10.27.9.16) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 12 Sep 2021 10:36:57 +0000 Received: from nvidia.com (172.20.187.5) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 12 Sep 2021 10:36:55 +0000 From: Michael Baum To: CC: Matan Azrad , Raslan Darawsheh , Viacheslav Ovsiienko , Date: Sun, 12 Sep 2021 13:36:27 +0300 Message-ID: <20210912103628.257499-6-michaelba@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210912103628.257499-1-michaelba@nvidia.com> References: <20210831203732.3411134-1-michaelba@nvidia.com> <20210912103628.257499-1-michaelba@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.5] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To DRHQMAIL107.nvidia.com (10.27.9.16) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7c7b3842-df95-4c5a-cd37-08d975d93f89 X-MS-TrafficTypeDiagnostic: BY5PR12MB3972: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cMdepdL0b7b2SHo9gdY+Xz9jPrJs7GtP25oD+hGYuKGFraolkgknLmhu0kcmsHtJ7Iu3pWFxADxVAK5ctYtTLyXLYNjYYX1dH00v6UmQpZf67mQATtR9r5t2Q2tXyZIXoS0/D16ZcPJlKnpyFcNjQbH5cOq/u3bLSEdX51m+rnWleupjSXCw7KH/uFNC7OFLihAvcVt/02fn24j2KJ+yOSE0X0JPWMlVrIrhSViOTzYiWhdXOuYjngYt9weUqIUf68mzzOqQt3oLRCALEypTrkZbvEFl40Icczv6hgggmIcGrgjRTAvboqkD1nKbmSW39TEuUZECi0f5fIlbcP71YNob/YYRPLNretpjhDpGPv41TUZab8+u8SJ0E+rchbrZWlALnxiuxkwgnwucAJLujjg+dVyaQMGEdcgNFx81vqTs1S8Jb7EY0GurJUIvhOd62hYyvqpd3JC/nN7var1XXuH5SAu4vcX7Z+hiDO1ZyxAvhnOT7Y3VjP53xGm8gQsDIQEFq0s9GyKxPolcDDWjAbLzTfp5tSTogMVBMIOQIZXuIhvPULHRKNrKMD7pFakGBuLuruljJ9ndwgjnmmtuF4k9Q68vdtBs5Eez3moKxJ/6yjLp5r9i3wQ6ysq2X4HXu+W9yhJcKogfk5Gif8hhBDuBgmEmqMkgld7AJDaU1VooRw1Qo+dhFq5lw3H22n+psjMGbqJ85Uth2PqS2FMf+g== X-Forefront-Antispam-Report: CIP:216.228.112.35; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid04.nvidia.com; CAT:NONE; SFS:(4636009)(346002)(136003)(396003)(376002)(39860400002)(46966006)(36840700001)(478600001)(1076003)(450100002)(5660300002)(6286002)(8676002)(70206006)(6666004)(86362001)(83380400001)(426003)(70586007)(6916009)(54906003)(2906002)(26005)(36906005)(8936002)(82740400003)(36860700001)(82310400003)(16526019)(7636003)(7696005)(356005)(55016002)(316002)(47076005)(2616005)(336012)(36756003)(186003)(4326008); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2021 10:36:58.2195 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7c7b3842-df95-4c5a-cd37-08d975d93f89 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.35]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT023.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB3972 Subject: [dpdk-dev] [PATCH v2 5/6] common/mlx5: fix device list operation concurrency 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 Sender: "dev" The MLX5 common driver has a global list of mlx5 devices which are probed. In probe function it create one and insert it to the list. Similarly it removes the device in remove function. These operations are not safe as there can be such operations in parallel, by different threads. Add global lock for the list and use it to insert or remove. Fixes: 8a41f4deccc3 ("common/mlx5: introduce layer for multiple class drivers") Cc: stable@dpdk.org Signed-off-by: Michael Baum Acked-by: Matan Azrad --- drivers/common/mlx5/mlx5_common.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/common/mlx5/mlx5_common.c b/drivers/common/mlx5/mlx5_common.c index f6e440dca1..4321cb3a9c 100644 --- a/drivers/common/mlx5/mlx5_common.c +++ b/drivers/common/mlx5/mlx5_common.c @@ -50,6 +50,7 @@ static TAILQ_HEAD(mlx5_drivers, mlx5_class_driver) drivers_list = /* Head of devices. */ static TAILQ_HEAD(mlx5_devices, mlx5_common_device) devices_list = TAILQ_HEAD_INITIALIZER(devices_list); +static pthread_mutex_t devices_list_lock; static const struct { const char *name; @@ -222,7 +223,9 @@ mlx5_dev_to_pci_str(const struct rte_device *dev, char *addr, size_t size) static void dev_release(struct mlx5_common_device *dev) { + pthread_mutex_lock(&devices_list_lock); TAILQ_REMOVE(&devices_list, dev, next); + pthread_mutex_unlock(&devices_list_lock); rte_free(dev); } @@ -315,7 +318,9 @@ mlx5_common_dev_probe(struct rte_device *eal_dev) if (!dev) return -ENOMEM; dev->dev = eal_dev; + pthread_mutex_lock(&devices_list_lock); TAILQ_INSERT_HEAD(&devices_list, dev, next); + pthread_mutex_unlock(&devices_list_lock); new_device = true; } /* @@ -440,6 +445,7 @@ mlx5_common_init(void) if (mlx5_common_initialized) return; + pthread_mutex_init(&devices_list_lock, NULL); mlx5_glue_constructor(); mlx5_common_driver_init(); mlx5_common_initialized = true; -- 2.25.1