From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10046.outbound.protection.outlook.com [40.107.1.46]) by dpdk.org (Postfix) with ESMTP id C7B151B362 for ; Thu, 18 Jan 2018 17:35:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=EZ4z/pk6tAmL7zTe7q8DPYT8Ojzld80zQ8/AB6ISUOk=; b=b6s80CssJoY8tf24LtwPxBfWz2Wew8hexjOKWQCbtLuGnHgOjaN5FWjzRg+7bCsl1VRpxpPCoX92lKpIgR1CSFNSOHrY2Ao3hwQ7Twe2x74s9V1/sMga97kfVv8lleE1uoL2NBKkNrlyVxVxut/kpA3LBN7anRi0VY3/FAnp7pU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; Received: from mellanox.com (37.142.13.130) by VI1PR0502MB3806.eurprd05.prod.outlook.com (2603:10a6:803:12::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.407.7; Thu, 18 Jan 2018 16:35:36 +0000 From: Matan Azrad To: Thomas Monjalon , Gaetan Rivet , Jingjing Wu Cc: dev@dpdk.org, Neil Horman , Bruce Richardson , Konstantin Ananyev Date: Thu, 18 Jan 2018 16:35:14 +0000 Message-Id: <1516293317-30748-5-git-send-email-matan@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1516293317-30748-1-git-send-email-matan@mellanox.com> References: <1515318351-4756-1-git-send-email-matan@mellanox.com> <1516293317-30748-1-git-send-email-matan@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: VI1PR0802CA0021.eurprd08.prod.outlook.com (2603:10a6:800:aa::31) To VI1PR0502MB3806.eurprd05.prod.outlook.com (2603:10a6:803:12::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e079babb-7105-4d12-23f4-08d55e91810c X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(48565401081)(2017052603307)(7153060)(7193020); SRVR:VI1PR0502MB3806; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0502MB3806; 3:DKyHkG8Mxhh4MDGODqOK4zoRYlzB+cHVfAjIv299vesWmP8mGKkTAfXqRvFyU//iOJRWow6jHVUTM60rF9EcWHBisJIHkaUifU60FOb7DafzJg/iQhaCun8R396o9etXjDEx9CurGXKmsAod2coAx6oWTkTKGan33Gu9+dghn3LBH5WYx/57qzLgYgbhlswjXCSt9kTZjPmfbmjLwsM47SAJE0efrSt3gd/SdnTow36cTqil0o856oM0a11PXjN6; 25:MwwqL/IAI1D4SaQoLr3Hlb6NF4EXNubRcdMqbs0jJlo7+JDTFEumC48GTpZHs5XDFQhK8c/2xQ5WsHUE0stv7gdcm5PwJjs+YYw0/9BLs3hvu7UwqoNqn4uBa3BadL1AHo7b/IYGAgTTCOMEtwO9n1W6Jthq/cWFOGGj9+FgQDbvpaBSY2sMWPoAcsRE10LoeNv42LsoqfPLL6KYDhWMyW67c/Bug+fVfNeU1dmx+gESMNvTHHt6tuAxSdE5yesGTqc/4SVCamk5PazEaYEKhFrvB3ta/RAwhQmeX1mbS/kr9fLyYVa1+qD5Iaq7UeXpp/oQT2HUy8pztxqKObLOyQ==; 31:od+edKDq9xeaNtmpKYa6ix7FCrzw+/h07w/V7obr1vJGBppqD3Z4bagKG5p6evjLX2DPpph9R5sVUTSaqYhjRYE/sm38KUm1H9m+jH+xuo2pZTVIFNwDtmFY0fpFmTSALFNuMsGYVXSrCz9jE4c5C5hnkIxVr9Q8H+qvRtVNbX5fHw/sTYlmx/OkwuZdPsnIhLuIuQk8EMUZ23Yq7Sn0BUF0JTAphIgDEbRqUM7cKNw= X-MS-TrafficTypeDiagnostic: VI1PR0502MB3806: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; VI1PR0502MB3806; 20:1p1trpIS7zYQ6qHgH2x7I24II7O2uQvejrzRtGIwQABQfTd8Vi8JWdxdc6RQkAi0UlFfHEmJDN6EMqI6/Vi2ASPrY+2BV/AY2rXqt55qR9Aq6ENdtxezmlgzmj2v38Y2u/eizNpciv8ZDSsDYQKpCMBNas3WJGHDEjJI3HeShCw7/cVyArPF4bIcGtI2f7Fz6+C+owW5z0Hppmn+rhbX+NnKhqukYPtd1t2OcVYD6WdwEVV3FnuCsTYEOU6w1KVyKbR/vfC/fPQ3JtK0GKuboClMSdEDFtgQqKsoKs6E6jsDh2L7qJRXeNr0yB8EOx/zknQ6bUpzkMW6MikkaJv7ixnVdamgkaUKCcnwDEySMIgJT0czTt42Nj6g1HLZbxucJuAMOfX9nKUZWkFIML2PXjei8kMtRQwzeKPaDJpOXinzlq0OAKg7jCIPEL2D9a+VipnxRz/w0kf+FOe8u0UJ2k+f0lTSx6gPMYd8w8r8NW+RkQVPFvFzJ+gDnzw74LSo; 4:o/oUpDb/DnZP0VDPtT9JtQr7rkrOVMTgflfI+5TbdDbRXdbrmSbgL8KtTZ9g6LjTH3kpXbGKD3jSgvDMBMI4mASK3os8X0Bnd2js/fp/3/m/iKEDrAjo50CuOn+SxqXb0RDW03BxGFCh4REw3qWcnBojlrz55kbdYvr6N90OVJvltnTkBxKiFLdNvzYah9MWHf36HszHuJuElWcE7wj/aQXmJopi6FMqJU+z+mIl0iEDwPa6R482XVQw5C/zGcZgKVSB7ACxAj0jpzUyd2RF0a/FiCvJdyeTHhnyNqvSDOgWq61zURDrfAtu8tltbU6D X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(60795455431006); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3002001)(3231023)(2400064)(944501161)(6055026)(6041268)(20161123562045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011); SRVR:VI1PR0502MB3806; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:VI1PR0502MB3806; X-Forefront-PRVS: 05568D1FF7 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(39860400002)(396003)(376002)(39380400002)(366004)(189003)(199004)(2950100002)(47776003)(4720700003)(478600001)(21086003)(50466002)(86362001)(106356001)(5890100001)(7736002)(16586007)(76176011)(305945005)(59450400001)(36756003)(3846002)(25786009)(386003)(52116002)(55016002)(7696005)(4326008)(97736004)(33026002)(51416003)(54906003)(53936002)(68736007)(16526018)(6116002)(316002)(105586002)(110136005)(5660300001)(2906002)(6666003)(66066001)(50226002)(81156014)(81166006)(48376002)(69596002)(8676002)(26005)(8936002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0502MB3806; H:mellanox.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0502MB3806; 23:Lp8/3yCc5R1cKqS4AI0gxbJ6erlbTifU/IZ4sI4?= =?us-ascii?Q?7nLWa6qv76uw+4erdVnnlEFhcjEGsGv1DgXsG/QBnzh/Q9EaBgnKqtEmQitf?= =?us-ascii?Q?OgwXF882CQAqlFZml4NIojkJpnDES4NBsqUdGWFZuCb4HdwQOotsl/W8rIDr?= =?us-ascii?Q?Lj///fD6/X7oe1vrm8PZJpNKesSCAhqTlF7TTKp8id2gkFOeqZP2OFuwwOsN?= =?us-ascii?Q?ihk+iOv1i0RXyUzgui0UiJNN2hPmWqn2gilSDgylnLjxd1/N5Fv7jgDlZMRn?= =?us-ascii?Q?fE/BuwGg1+gA4I9jTieXdX2YzuOA/XekMZV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Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2018 16:35:36.3618 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e079babb-7105-4d12-23f4-08d55e91810c X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0502MB3806 Subject: [dpdk-dev] [PATCH v3 4/7] ethdev: synchronize port allocation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Jan 2018 16:35:39 -0000 Ethernet port allocation was not thread safe, means 2 threads which tried to allocate a new port at the same time might get an identical port identifier and caused to memory overwrite. Actually, all the port configurations were not thread safe from ethdev point of view. The port ownership mechanism added to the ethdev is a good point to redefine the synchronization rules in ethdev: 1. The port allocation and port release synchronization will be managed by ethdev. 2. The port usage synchronization will be managed by the port owner. 3. The port ownership synchronization will be managed by ethdev. Add port allocation synchronization to complete the new rules. Signed-off-by: Matan Azrad --- lib/librte_ether/rte_ethdev.c | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index b740370..b75cbb2 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -52,6 +52,9 @@ /* spinlock for add/remove tx callbacks */ static rte_spinlock_t rte_eth_tx_cb_lock = RTE_SPINLOCK_INITIALIZER; +/* spinlock for shared data allocation */ +static rte_spinlock_t rte_eth_share_data_alloc = RTE_SPINLOCK_INITIALIZER; + /* store statistics names and its offset in stats structure */ struct rte_eth_xstats_name_off { char name[RTE_ETH_XSTATS_NAME_SIZE]; @@ -198,21 +201,27 @@ struct rte_eth_dev * rte_eth_dev_allocate(const char *name) { uint16_t port_id; - struct rte_eth_dev *eth_dev; + struct rte_eth_dev *eth_dev = NULL; + + /* Synchronize share data one time allocation between local threads. */ + rte_spinlock_lock(&rte_eth_share_data_alloc); + if (rte_eth_dev_share_data == NULL) + rte_eth_dev_share_data_alloc(); + rte_spinlock_unlock(&rte_eth_share_data_alloc); + + /* Synchronize port creation between primary and secondary threads. */ + rte_spinlock_lock(&rte_eth_dev_share_data->ownership_lock); port_id = rte_eth_dev_find_free_port(); if (port_id == RTE_MAX_ETHPORTS) { RTE_PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n"); - return NULL; + goto unlock; } - if (rte_eth_dev_share_data == NULL) - rte_eth_dev_share_data_alloc(); - if (rte_eth_dev_allocated(name) != NULL) { RTE_PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n", name); - return NULL; + goto unlock; } eth_dev = eth_dev_get(port_id); @@ -220,7 +229,11 @@ struct rte_eth_dev * eth_dev->data->port_id = port_id; eth_dev->data->mtu = ETHER_MTU; - _rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_NEW, NULL); +unlock: + rte_spinlock_unlock(&rte_eth_dev_share_data->ownership_lock); + + if (eth_dev != NULL) + _rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_NEW, NULL); return eth_dev; } @@ -234,10 +247,16 @@ struct rte_eth_dev * rte_eth_dev_attach_secondary(const char *name) { uint16_t i; - struct rte_eth_dev *eth_dev; + struct rte_eth_dev *eth_dev = NULL; + /* Synchronize share data one time attachment between local threads. */ + rte_spinlock_lock(&rte_eth_share_data_alloc); if (rte_eth_dev_share_data == NULL) rte_eth_dev_share_data_alloc(); + rte_spinlock_unlock(&rte_eth_share_data_alloc); + + /* Synchronize port attachment to primary port creation and release. */ + rte_spinlock_lock(&rte_eth_dev_share_data->ownership_lock); for (i = 0; i < RTE_MAX_ETHPORTS; i++) { if (strcmp(rte_eth_dev_share_data->data[i].name, name) == 0) @@ -247,12 +266,12 @@ struct rte_eth_dev * RTE_PMD_DEBUG_TRACE( "device %s is not driven by the primary process\n", name); - return NULL; + } else { + eth_dev = eth_dev_get(i); + RTE_ASSERT(eth_dev->data->port_id == i); } - eth_dev = eth_dev_get(i); - RTE_ASSERT(eth_dev->data->port_id == i); - + rte_spinlock_unlock(&rte_eth_dev_share_data->ownership_lock); return eth_dev; } -- 1.8.3.1