From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dispatch1-us1.ppe-hosted.com (dispatch1-us1.ppe-hosted.com [148.163.129.52]) by dpdk.org (Postfix) with ESMTP id 3F6045B30; Wed, 11 Jul 2018 11:49:58 +0200 (CEST) X-Virus-Scanned: Proofpoint Essentials engine Received: from webmail.solarflare.com (webmail.solarflare.com [12.187.104.26]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1-us3.ppe-hosted.com (Proofpoint Essentials ESMTP Server) with ESMTPS id C3C73600053; Wed, 11 Jul 2018 09:49:56 +0000 (UTC) Received: from sfocexch01r.SolarFlarecom.com (10.20.40.34) by ocex03.SolarFlarecom.com (10.20.40.36) with Microsoft SMTP Server (TLS) id 15.0.1044.25; Wed, 11 Jul 2018 02:49:54 -0700 Received: from ocex03.SolarFlarecom.com (10.20.40.36) by sfocexch01r.SolarFlarecom.com (10.20.40.34) with Microsoft SMTP Server (TLS) id 15.0.1044.25; Wed, 11 Jul 2018 02:49:52 -0700 Received: from opal.uk.solarflarecom.com (10.17.10.1) by ocex03.SolarFlarecom.com (10.20.40.36) with Microsoft SMTP Server (TLS) id 15.0.1044.25 via Frontend Transport; Wed, 11 Jul 2018 02:49:51 -0700 Received: from ukv-loginhost.uk.solarflarecom.com (ukv-loginhost.uk.solarflarecom.com [10.17.10.39]) by opal.uk.solarflarecom.com (8.13.8/8.13.8) with ESMTP id w6B9noac010293; Wed, 11 Jul 2018 10:49:50 +0100 Received: from ukv-loginhost.uk.solarflarecom.com (localhost [127.0.0.1]) by ukv-loginhost.uk.solarflarecom.com (Postfix) with ESMTP id C8C3F16546A; Wed, 11 Jul 2018 10:49:50 +0100 (BST) From: Andrew Rybchenko To: CC: Thomas Monjalon , Ferruh Yigit , Ivan Malov , "David Marchand" , Date: Wed, 11 Jul 2018 10:49:33 +0100 Message-ID: <1531302573-16946-1-git-send-email-arybchenko@solarflare.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-MDID: 1531302597-NmL2GZZ8MWXG Subject: [dpdk-dev] [PATCH] ethdev: fix port ID retrieval on vdev attach 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: Wed, 11 Jul 2018 09:49:58 -0000 From: Ivan Malov Attaching a vdev port may result in multiple ports actually added because a vdev port may have slave devices to be attached implicitly. Ethdev attach API has to fill in the port ID to be read back by the user and what it does is take the last assigned ID from the common list after attach completion. Such an ID may belong to a slave device and not to the vdev. This mistake must be precluded by requesting the port ID by name of device being attached. Fixes: b0fb26685570 ("ethdev: convert to EAL hotplug") Cc: David Marchand Cc: stable@dpdk.org Reported-by: Andrew Rybchenko Signed-off-by: Ivan Malov Signed-off-by: Andrew Rybchenko --- lib/librte_ethdev/rte_ethdev.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 16b8258a7..dbb9244ec 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -46,7 +46,6 @@ int rte_eth_dev_logtype; static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data"; struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS]; -static uint16_t eth_dev_last_created_port; /* spinlock for eth device callbacks */ static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER; @@ -284,8 +283,6 @@ eth_dev_get(uint16_t port_id) eth_dev->data = &rte_eth_dev_shared_data->data[port_id]; - eth_dev_last_created_port = port_id; - return eth_dev; } @@ -646,7 +643,6 @@ eth_err(uint16_t port_id, int ret) int rte_eth_dev_attach(const char *devargs, uint16_t *port_id) { - int current = rte_eth_dev_count_total(); struct rte_devargs da; int ret = -1; @@ -665,24 +661,10 @@ rte_eth_dev_attach(const char *devargs, uint16_t *port_id) if (ret < 0) goto err; - /* no point looking at the port count if no port exists */ - if (!rte_eth_dev_count_total()) { - RTE_ETHDEV_LOG(ERR, "No port found for device (%s)\n", da.name); - ret = -1; - goto err; - } - - /* if nothing happened, there is a bug here, since some driver told us - * it did attach a device, but did not create a port. - * FIXME: race condition in case of plug-out of another device - */ - if (current == rte_eth_dev_count_total()) { - ret = -1; - goto err; - } - - *port_id = eth_dev_last_created_port; - ret = 0; + ret = rte_eth_dev_get_port_by_name(da.name, port_id); + if (ret != 0) + RTE_ETHDEV_LOG(ERR, "No port found for device (%s)\n", + da.name); err: free(da.args); -- 2.17.1