DPDK patches and discussions
 help / color / mirror / Atom feed
From: Andrew Rybchenko <arybchenko@solarflare.com>
To: <dev@dpdk.org>
Cc: Thomas Monjalon <thomas@monjalon.net>,
	Ferruh Yigit <ferruh.yigit@intel.com>,
	Ivan Malov <ivan.malov@oktetlabs.ru>,
	"David Marchand" <david.marchand@6wind.com>, <stable@dpdk.org>
Subject: [dpdk-dev] [PATCH] ethdev: fix port ID retrieval on vdev attach
Date: Wed, 11 Jul 2018 10:49:33 +0100	[thread overview]
Message-ID: <1531302573-16946-1-git-send-email-arybchenko@solarflare.com> (raw)

From: Ivan Malov <ivan.malov@oktetlabs.ru>

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 <david.marchand@6wind.com>
Cc: stable@dpdk.org

Reported-by: Andrew Rybchenko <arybchenko@solarflare.com>
Signed-off-by: Ivan Malov <ivan.malov@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
---
 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

             reply	other threads:[~2018-07-11  9:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-11  9:49 Andrew Rybchenko [this message]
2018-07-11 10:02 ` Thomas Monjalon
2018-07-11 10:15   ` Andrew Rybchenko
2018-07-11 10:52     ` Thomas Monjalon
2018-07-11 11:10       ` Andrew Rybchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1531302573-16946-1-git-send-email-arybchenko@solarflare.com \
    --to=arybchenko@solarflare.com \
    --cc=david.marchand@6wind.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=ivan.malov@oktetlabs.ru \
    --cc=stable@dpdk.org \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).