From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0055.outbound.protection.outlook.com [104.47.2.55]) by dpdk.org (Postfix) with ESMTP id 4FA56271 for ; Sat, 20 Jan 2018 22:24: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=gz5W8in/vHOoB5RcLzgZMRUf9QukW3wPFOPyNiS+ZQg=; b=xHttxFXzrSlIhuQKBB/0WdgNvnVp5LXPf5Ym7vItD87cmw7+QNR+TGDpz9oacDSOTHEOqakQUR8hHEE4/aHluil30IaFoM0EOp4MDgz9vNxRCkwjnqj8Ni3ymCx+K7eZPTDdiFpXkMMx+QBsIu6a60iOnYcROg4dP7pPJf1Zmbc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; Received: from mellanox.com (37.142.13.130) by HE1PR0502MB3804.eurprd05.prod.outlook.com (2603:10a6:7:86::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.428.17; Sat, 20 Jan 2018 21:24:47 +0000 From: Matan Azrad To: Thomas Monjalon , Gaetan Rivet , Jingjing Wu Cc: dev@dpdk.org, Neil Horman , Bruce Richardson , Konstantin Ananyev Date: Sat, 20 Jan 2018 21:24:25 +0000 Message-Id: <1516483468-9048-5-git-send-email-matan@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1516483468-9048-1-git-send-email-matan@mellanox.com> References: <1516293317-30748-1-git-send-email-matan@mellanox.com> <1516483468-9048-1-git-send-email-matan@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: HE1PR0402CA0047.eurprd04.prod.outlook.com (2603:10a6:7:7c::36) To HE1PR0502MB3804.eurprd05.prod.outlook.com (2603:10a6:7:86::30) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e430082d-f96f-4420-bb49-08d5604c3c0b X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(48565401081)(2017052603307)(7153060)(7193020); SRVR:HE1PR0502MB3804; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0502MB3804; 3:xPP/2ez/ylNX0LD8aSRhsezoQEM8aI0op/o5HU5kw/hgezUNlOnJvg3NCC89vSPPYEZ40oqjdmgwUNVFyA9zozLoToKpf9aqWZj0F+GbVWoRNCS9kmMbdsNkAx/3aZbD2MHC8eWSZF7K/4VoO1wGInA/67A6kQgQY3SRTNkA25772p+9kXqxl5DNzyEsQd/9aY9PGgPXxslN+EPm6f3P1B50UKD5mOrk5nVXBLZ+hPZOkdMG4nEkbBTxcPj8SGIo; 25:Inzy3cQQqFB0pGT6p9vwUto/3LoO/jSr5xaEQw6JuurCCXZ+SzdNJ2IornNioD3PPBmna7n78euP+nX5olpjbF/p3CB4OPjWxfcrQtbX2KB1OyPq9fNTwgFH/TBm3DmSSZTtSBRogoyA3jCHKMuDO4pAaEaRqp9mei7rxpAnBnXNjOQHJ0VtIq30HK1PgoEFd/yBiI8r4McPBwMi22EuF+q3ZHM6LZ5u4HycS9GtrPZrzAdNqXnH/lrQ5WRWIVe+z4jYpx27ZLw/1+guYBa5llPQX9odr186IsgM8NXQTdv9KD+o2B4oT2Vogb7iCTBE2WimPyOjV6rnss7LP4cWdg==; 31:npu4xI+Elg6fEXW3uleoWR1I1whfGTSlg29xgeOvWmjah6ORfuD0QwoDUhEn6el6SXa1C4W4a43NEcwR6M8Ymcdkn8XXKhHo3AZHE7W8Gz+qQd1M+Jnsi7/XHa7wWzt7v3DwDZGq/Q+Q66M0j9ihEWSyTKnU61tvhj34/mdwC+4uh3dNq36laHpnhKZr9u1m3TiBTa4n9+fvwXLapKNL1uf1WGmyyNUwzkdSdajxhKA= X-MS-TrafficTypeDiagnostic: HE1PR0502MB3804: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; HE1PR0502MB3804; 20:K9OEWZIEbOAaBwlYtdpaNF6K8tjEAihnPYOoJ8YAvuHLCM0oAOmbamIg7tSVSv38uItA8GaSWhMYBJtISxJRJB3u5CgB0AcJ//ICpcfXvcLBCJSNlpU1FPR921ntDswoZAkeEIrWfI+YWErxiA+6h4FqTKBeFSuYruApj/IAQorBCP/t01LK0XZeWnDBtt5shOjixV+bE16Y0WESP15vWKKiMT3Lm9P9gMT76NBz9luzZtN2EX3eONKuXZnD0+Ni+wy/Xk9p7RXZMTzDHwVgHIGGTiNVkpDimUYxFXVX9Ik28f2cB22S367+CuM9eOMb6GMvxBs3Fd1lSxP+A4LMDt0xGRQkP7HRbEbJGz/al9zR3GMy7m1vpdAC2qY62YIvXuLTkENReoh3Jkgkt0Vcnrm0S5pT8oiFWhKZosf5wbzUgVGeaGUKyGFo7aH4wKvL+IE5TrkS101wb670V9QL6CRVA83WYjm9VXWBPHpOs3HEY39XKnCwL7ampETGexS+; 4:T3iB7Ly6+ycqk9zAdHKNfLmxs/AdPUwA7v8fOIMPzfy6nYGKosxMdgOMKDPhuggf0lLdMv5a8vbZyTTR21+wbNxuZfGKCgLTtmMbKaLCPy+puYrUIq2pwSCZ9OosSQZIABKbdP7+huydUpM0nRXa1qV9BOT95xRjJICKsz8BinnnMF8Y7n4OXh+hlfXtL98CkFD6JCD/OkJ9LbJIBVB9ldOTsONtNOFJN0ZYCJesnqn3SF2Q8atHFk7dF2m9mslmMVR/vzRGk6azdzj5Pyge5mx5TQjkihieIaDY731NnqnMACsRQ90rqekIQgjw/zuynhP+myluavUBT5oyVWMdV9/OvkkopSmbMC0Za+hNrOQ= 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)(8121501046)(5005006)(3231023)(2400081)(944501161)(3002001)(93006095)(93001095)(10201501046)(6055026)(6041288)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(6072148)(201708071742011); SRVR:HE1PR0502MB3804; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:HE1PR0502MB3804; X-Forefront-PRVS: 0558D3C5AC X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39860400002)(39380400002)(396003)(376002)(366004)(346002)(199004)(189003)(97736004)(53936002)(26005)(8676002)(305945005)(66066001)(2950100002)(6666003)(69596002)(86362001)(55016002)(575784001)(68736007)(50466002)(5890100001)(4720700003)(21086003)(48376002)(6116002)(50226002)(478600001)(25786009)(36756003)(2906002)(5660300001)(4326008)(47776003)(110136005)(52116002)(54906003)(33026002)(105586002)(8936002)(81166006)(386003)(7736002)(106356001)(316002)(59450400001)(81156014)(16526018)(7696005)(51416003)(76176011)(3846002)(16586007); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0502MB3804; 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; HE1PR0502MB3804; 23:OLTrAXFMvQNzRWTP6paJMmgHWC4Ey6Hm9UJxaF0?= =?us-ascii?Q?GwwNQoN8VIm9g+qya4Uoj0kNz6+nPrwYYMBqSdXeQPzzb2dXHCp7ET0plmWA?= =?us-ascii?Q?Arj949ojNm+0oLrNXJ0Yjr0xdKpL/XzSf+x/vE7FM29yQTWnnIVkpedOjddn?= =?us-ascii?Q?5DKWL4aGFDUgt+w6VxajfJrFIsduf9KK418qU+Z3VrJLVH+nKJOKEznS58wj?= =?us-ascii?Q?mqDaX8j2cLvlnU37DLBMOW3vib59aw2ApLxd+vmJZKyBI7vBMqXTI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qzU87p1EQjMWXIk5GpMfqH0wbkWA7qJp SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jan 2018 21:24:47.1944 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e430082d-f96f-4420-bb49-08d5604c3c0b X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0502MB3804 Subject: [dpdk-dev] [PATCH v4 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: Sat, 20 Jan 2018 21:24:49 -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 | 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 af0e072..f616775 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_shared_data_lock = 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]; @@ -202,21 +205,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 local threads to allocate shared data only once. */ + rte_spinlock_lock(&rte_eth_shared_data_lock); + if (rte_eth_dev_shared_data == NULL) + rte_eth_dev_shared_data_alloc(); + rte_spinlock_unlock(&rte_eth_shared_data_lock); + + /* 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; } - if (rte_eth_dev_shared_data == NULL) - rte_eth_dev_shared_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); @@ -224,7 +233,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; } @@ -238,10 +251,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 local threads to attach shared data only once. */ + rte_spinlock_lock(&rte_eth_shared_data_lock); if (rte_eth_dev_shared_data == NULL) rte_eth_dev_shared_data_alloc(); + rte_spinlock_unlock(&rte_eth_shared_data_lock); + + /* 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) @@ -251,12 +270,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