From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30062.outbound.protection.outlook.com [40.107.3.62]) by dpdk.org (Postfix) with ESMTP id CB0EBA48D for ; Mon, 22 Jan 2018 17:38:49 +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=MQBs1TlNpOq5ACac0UBw4jJEt9UFFk5XdH/l6R1EXgw=; b=N4xWIS1i86JyjmLm5dwy1AhTgk9QYwOEEDsV0vkyngXiqbCay3eoGF/OIWdiNaYMuzYlIby7qG3CFT/DupvzZuP5qLUfibKBsBDxbrtR2yqQ85XOUxH47fjsW+Qtce6albkvu73j0JL900+ds5PtY7UdLZIBmilzlT5CUxo+7Fk= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; Received: from mellanox.com (37.142.13.130) by HE1PR0502MB3802.eurprd05.prod.outlook.com (2603:10a6:7:86::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.428.17; Mon, 22 Jan 2018 16:38:46 +0000 From: Matan Azrad To: Thomas Monjalon , Gaetan Rivet , Jingjing Wu Cc: dev@dpdk.org, Neil Horman , Bruce Richardson , Konstantin Ananyev Date: Mon, 22 Jan 2018 16:38:20 +0000 Message-Id: <1516639103-27166-5-git-send-email-matan@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1516639103-27166-1-git-send-email-matan@mellanox.com> References: <1516483468-9048-1-git-send-email-matan@mellanox.com> <1516639103-27166-1-git-send-email-matan@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: HE1PR0102CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:7:7d::35) To HE1PR0502MB3802.eurprd05.prod.outlook.com (2603:10a6:7:86::28) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2e8cb780-d0b3-4361-087b-08d561b69c63 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(48565401081)(2017052603307)(7153060)(7193020); SRVR:HE1PR0502MB3802; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0502MB3802; 3:lcR24EN2fnhE8mzFx7TaEOeOhbxf0tzOHitdzpukW6HN+YRhBpp0g+2v9TTxyyINoNvIWsNDuTbZDIT1mZFzUgRVFxHF1taXLxhiyxr3e5zYA+C74gJOzdccJLQNB/ahLwMfD630C1np+eMwYlmUdPLfimIQJDG8U4iqGpCaGsjIhrhUreO1k9ap1nSlzYHnRcr4tmsIn+kjyBDNrSkaRH4A1WdP37TVjXjJDnNiPc75oeLCMMwPRTFii/1JwgQs; 25:11kYH/FWdJ0uYnmxYBPmwbQuv33geCWDjnjTMP12I6bpcM9d0z1+sMLBByt/UuJIco9olTZi7dDUOhSK1CYu19EHTHS2+FeyYeyoVTJEHAadr3HC0+59MRPqqDSHIDCgLPnLiW/VZTDaeE9Rkjm8ZNefdPQVImSzEI+x66b4mhjmEslPQ8tNpYcIHsv7gX/lUYKOQITxkagekKjPOtkMupX3Ykeupvr6WMYZZuM2GyzNzHWtFbqVbEMcD6xzwbPBZc7Te8eKr4HjI8GA/s/0GbeEyc1g743ICzB1Z3ZhDsKput7CAy8RpG5DvGASYUsBr9RwXDOWFOD4Woo4HgXEow==; 31:kmvc1en2uONy76BWv7HOCoK2AjM/lHkeHTBZbm2SvCK6o/l8/D7p4T/ngt0fIBx6Isr0UcsE5gZcylBMbbygQCNRre0/yKpEQXEOJHzcadWbE0hXpma/YscGPNC6WCy2MW/bJ+Cu30ovTS49gtdRXT6jy6Q0n+Kcv+iRrMMNW+eduErSLWcJIsvMmTWvzazeD2v8Iqz8l4gAGzu5QKRAdj7tf7jptfUiUx6mpo0Xp/k= X-MS-TrafficTypeDiagnostic: HE1PR0502MB3802: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; HE1PR0502MB3802; 20:fvUllyPMFCgacC1nhbLJveGwjbZgYBPfEP8dMFfjcqutOvzmhi1i5Ttt8uvG5C28yVQAhovHSv3k7OJHUGTq4euZrz7cDWpubCMF+V4xwJCSGB7II6uzoW80Bh0AOiG4RTYwSCokP/SAOCfWON1gNgWH+a6rxhYLZtz2rqvmTUeHeNWELMUdoIb85vsmVQs0sTaDdUPKbLnJFqjict5PysbwqSVR22eD0qTBwA2LHNHnI60aGk2GLoYFnSy4ij7kvm8Xof/nWT9474juDLSawf/rLE1Y802lmQFhwAzRuQptOp22/lq8/c4srGY91stEiuRpm2rxGhLWKKcWvPE5TiU6urmJoCrmT3M9Ew4noYx+5WGxdf1cIOjOuPws8N9me4NKk+EHNwjqFHyzuWbClq5MNOdmgEhsg5j8PC+z7QfuRU9fTzQvIz9Q/GgJZGAtkL4BASWKHBuvtehz25jpy0WbPSccg5bWgb4PwSo9DwTYU8RK+/bydXs+NEuxYAhq; 4:flOaBlxPzd5hQrxLQTyegyP04j1Z4THdFIsCpIjajJxsPy+eCGGJdA1cOOTNSs90Y2umHsmiYnjxsM0nQ5xwot8u2vaH7cqWaP8dFKAWbSomXcJpGbOGWIsaRqJ8yXgHIKeaoSMLftAlkLdtzQheHwEw4G3nsVZbF0O+F1hK7NGwp7YycZ/9+6Hl0cjvwD/MVpahFVL9Psrg0668h4A0U80VITvallUnenrBLKmDi9wknzFwbQ2ljldm0cufsajyVZao6k4Y0idA7DYkjp652k39iVFISym7AhsNPYJF5XTGlJcf7tDs5quK/JgAuGnbZtZ5ZziQdmxO+kPjKb3HMlLh2Mp8R261EEyImPMJCCc= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(60795455431006)(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231023)(2400081)(944501161)(3002001)(10201501046)(6055026)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123560045)(20161123564045)(6072148)(201708071742011); SRVR:HE1PR0502MB3802; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:HE1PR0502MB3802; X-Forefront-PRVS: 0560A2214D X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(39380400002)(366004)(396003)(376002)(39860400002)(199004)(189003)(5660300001)(53936002)(47776003)(8936002)(50226002)(2906002)(68736007)(4720700003)(55016002)(6666003)(2950100002)(69596002)(478600001)(76176011)(7696005)(316002)(52116002)(386003)(16586007)(36756003)(51416003)(59450400001)(6116002)(3846002)(16526018)(8676002)(81166006)(81156014)(66066001)(110136005)(48376002)(26005)(54906003)(86362001)(25786009)(106356001)(5890100001)(105586002)(50466002)(305945005)(4326008)(7736002)(97736004)(21086003)(33026002); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0502MB3802; H:mellanox.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; HE1PR0502MB3802; 23:yEukpUNGNfCg3YaqJD0OW3u3JjdLQvhTNM6ZdIo?= =?us-ascii?Q?805LaGXlHwJJpQKITehrC5nzAZOGKw5cxAVQB3SLQzyMxblhR+FhEh8mcneb?= =?us-ascii?Q?WvS+VEmzm1ICE3ba18iuZAtORTItqsAJw1tiX3Zlv2hEeKIseejNMOuy8nrV?= =?us-ascii?Q?CyRy6turfWInSdfNa6hCd1zu20IrlHWCFbqnGIuqhfepsWWjLbvqw5hQG9rZ?= =?us-ascii?Q?0b2CrJxaVKiqbITomZOYRDfeT0fuP7PHqKCi3TJKrbrHFUsZhFkRmIK0N/Ql?= =?us-ascii?Q?HmBl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iagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2018 16:38:46.6752 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2e8cb780-d0b3-4361-087b-08d561b69c63 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0502MB3802 Subject: [dpdk-dev] [PATCH v5 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: Mon, 22 Jan 2018 16:38:50 -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 Acked-by: Konstantin Ananyev --- lib/librte_ether/rte_ethdev.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 3d2b90c..19650ae 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -268,20 +268,23 @@ 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; + + rte_eth_dev_shared_data_prepare(); + + /* Synchronize port creation between primary and secondary threads. */ + rte_spinlock_lock(&rte_eth_dev_shared_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; } - rte_eth_dev_shared_data_prepare(); - 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); @@ -289,7 +292,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_shared_data->ownership_lock); + + if (eth_dev != NULL) + _rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_NEW, NULL); return eth_dev; } @@ -303,10 +310,13 @@ 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; rte_eth_dev_shared_data_prepare(); + /* Synchronize port attachment to primary port creation and release. */ + rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock); + for (i = 0; i < RTE_MAX_ETHPORTS; i++) { if (strcmp(rte_eth_dev_shared_data->data[i].name, name) == 0) break; @@ -315,12 +325,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_shared_data->ownership_lock); return eth_dev; } -- 1.8.3.1