DPDK patches and discussions
 help / color / mirror / Atom feed
From: longli@linuxonhyperv.com
To: Ferruh Yigit <ferruh.yigit@amd.com>,
	Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>,
	Wei Hu <weh@microsoft.com>
Cc: dev@dpdk.org, Long Li <longli@microsoft.com>
Subject: [PATCH 4/4] net/netvsc: cache device parameters for hot plug events
Date: Mon, 27 Jan 2025 17:35:06 -0800	[thread overview]
Message-ID: <1738028106-25239-4-git-send-email-longli@linuxonhyperv.com> (raw)
In-Reply-To: <1738028106-25239-1-git-send-email-longli@linuxonhyperv.com>

From: Long Li <longli@microsoft.com>

If a device is hot removed and hot plugged, it needs the same driver
parameters that are passed to EAL. However, during device removal, all
EAL driver parameters are freed as part of the cleanup.

Cache those driver parameters for future hot plug events. Because we don't
know which device will show up, cache all the PCI driver parameters.

Signed-off-by: Long Li <longli@microsoft.com>
---
 drivers/net/netvsc/hn_ethdev.c | 107 +++++++++++++++++++++++++++++----
 drivers/net/netvsc/hn_var.h    |   1 -
 drivers/net/netvsc/hn_vf.c     |   4 --
 3 files changed, 94 insertions(+), 18 deletions(-)

diff --git a/drivers/net/netvsc/hn_ethdev.c b/drivers/net/netvsc/hn_ethdev.c
index f848157b49..afbbccd822 100644
--- a/drivers/net/netvsc/hn_ethdev.c
+++ b/drivers/net/netvsc/hn_ethdev.c
@@ -95,6 +95,16 @@ static const uint8_t rss_default_key[NDIS_HASH_KEYSIZE_TOEPLITZ] = {
 	0x06, 0x3c, 0x25, 0xf3,	0xfc, 0x1f, 0xdc, 0x2a,
 };
 
+static rte_spinlock_t netvsc_lock = RTE_SPINLOCK_INITIALIZER;
+struct da_cache {
+	LIST_ENTRY(da_cache) list;
+	char name[RTE_DEV_NAME_MAX_LEN];
+	char *drv_str;
+};
+
+LIST_HEAD(da_cache_list, da_cache) da_cache_list;
+static unsigned int da_cache_usage;
+
 static struct rte_eth_dev *
 eth_dev_vmbus_allocate(struct rte_vmbus_device *dev, size_t private_data_size)
 {
@@ -623,16 +633,21 @@ static void netvsc_hotplug_retry(void *args)
 		       RTE_DIM(eth_addr.addr_bytes));
 
 		if (rte_is_same_ether_addr(&eth_addr, dev->data->mac_addrs)) {
+			struct da_cache *cache;
+
+			LIST_FOREACH(cache, &da_cache_list, list) {
+				if (strcmp(cache->name, d->name) == 0)
+					break;
+			}
+
 			PMD_DRV_LOG(NOTICE,
-				    "Found matching MAC address, adding device %s network name %s",
-				    d->name, dir->d_name);
+				    "Found matching MAC address, adding device %s network name %s args %s",
+				    d->name, dir->d_name, cache ? cache->drv_str : "");
 
 			/* If this device has been hot removed from this
 			 * parent device, restore its args.
 			 */
-			ret = rte_eal_hotplug_add(d->bus->name, d->name,
-						  hv->vf_devargs ?
-						  hv->vf_devargs : "");
+			ret = rte_eal_hotplug_add(d->bus->name, d->name, cache ? cache->drv_str : "");
 			if (ret) {
 				PMD_DRV_LOG(ERR,
 					    "Failed to add PCI device %s",
@@ -1409,9 +1424,6 @@ eth_hn_dev_uninit(struct rte_eth_dev *eth_dev)
 	ret_stop = hn_dev_stop(eth_dev);
 	hn_dev_close(eth_dev);
 
-	free(hv->vf_devargs);
-	hv->vf_devargs = NULL;
-
 	hn_detach(hv);
 	hn_chim_uninit(eth_dev);
 	rte_vmbus_chan_close(hv->channels[0]);
@@ -1423,6 +1435,61 @@ eth_hn_dev_uninit(struct rte_eth_dev *eth_dev)
 	return ret_stop;
 }
 
+static int populate_cache_list(void)
+{
+	int ret;
+	struct rte_devargs *da;
+
+	rte_spinlock_lock(&netvsc_lock);
+	da_cache_usage++;
+	if (da_cache_usage > 1) {
+		ret = 0;
+		goto out;
+	}
+
+	LIST_INIT(&da_cache_list);
+	RTE_EAL_DEVARGS_FOREACH("pci", da) {
+		struct da_cache *cache;
+
+		cache = rte_zmalloc("NETVSC-HOTADD", sizeof(*cache), rte_mem_page_size());
+		if (!cache) {
+			ret = -ENOMEM;
+			goto out;
+		}
+
+		strncpy(cache->name, da->name, sizeof(da->name));
+		cache->drv_str = strdup(da->drv_str);
+		if (!cache->drv_str) {
+			rte_free(cache);
+			ret = -ENOMEM;
+			goto out;
+		}
+
+		LIST_INSERT_HEAD(&da_cache_list, cache, list);
+	}
+out:
+	rte_spinlock_unlock(&netvsc_lock);
+	return ret;
+}
+
+static void remove_cache_list(void)
+{
+	struct da_cache *cache;
+
+	rte_spinlock_lock(&netvsc_lock);
+	da_cache_usage--;
+	if (da_cache_usage)
+		goto out;
+
+	LIST_FOREACH(cache, &da_cache_list, list) {
+		LIST_REMOVE(cache, list);
+		free(cache->drv_str);
+		rte_free(cache);
+	}
+out:
+	rte_spinlock_unlock(&netvsc_lock);
+}
+
 static int eth_hn_probe(struct rte_vmbus_driver *drv __rte_unused,
 			struct rte_vmbus_device *dev)
 {
@@ -1431,24 +1498,35 @@ static int eth_hn_probe(struct rte_vmbus_driver *drv __rte_unused,
 
 	PMD_INIT_FUNC_TRACE();
 
+	ret = populate_cache_list();
+	if (ret)
+		return ret;
+
 	ret = rte_dev_event_monitor_start();
 	if (ret) {
 		PMD_DRV_LOG(ERR, "Failed to start device event monitoring");
-		return ret;
+		goto fail;
 	}
 
 	eth_dev = eth_dev_vmbus_allocate(dev, sizeof(struct hn_data));
-	if (!eth_dev)
-		return -ENOMEM;
+	if (!eth_dev) {
+		rte_dev_event_monitor_stop();
+		ret = -ENOMEM;
+		goto fail;
+	}
 
 	ret = eth_hn_dev_init(eth_dev);
 	if (ret) {
 		eth_dev_vmbus_release(eth_dev);
 		rte_dev_event_monitor_stop();
-	} else {
-		rte_eth_dev_probing_finish(eth_dev);
+		goto fail;
 	}
 
+	rte_eth_dev_probing_finish(eth_dev);
+	return 0;
+
+fail:
+	remove_cache_list();
 	return ret;
 }
 
@@ -1469,6 +1547,9 @@ static int eth_hn_remove(struct rte_vmbus_device *dev)
 
 	eth_dev_vmbus_release(eth_dev);
 	rte_dev_event_monitor_stop();
+
+	remove_cache_list();
+
 	return 0;
 }
 
diff --git a/drivers/net/netvsc/hn_var.h b/drivers/net/netvsc/hn_var.h
index 0f638bc5fd..d2263e03e8 100644
--- a/drivers/net/netvsc/hn_var.h
+++ b/drivers/net/netvsc/hn_var.h
@@ -184,7 +184,6 @@ struct hn_data {
 
 	rte_spinlock_t	hotadd_lock;
 	LIST_HEAD(hotadd_list, hv_hotadd_context) hotadd_list;
-	char		*vf_devargs;
 };
 
 static inline struct vmbus_channel *
diff --git a/drivers/net/netvsc/hn_vf.c b/drivers/net/netvsc/hn_vf.c
index 4ff766ec8b..d922e685f4 100644
--- a/drivers/net/netvsc/hn_vf.c
+++ b/drivers/net/netvsc/hn_vf.c
@@ -130,10 +130,6 @@ static void hn_remove_delayed(void *args)
 		PMD_DRV_LOG(ERR, "rte_eth_dev_stop failed port_id=%u ret=%d",
 			    port_id, ret);
 
-	/* Record the device parameters for possible hotplug events */
-	if (dev->devargs && dev->devargs->args)
-		hv->vf_devargs = strdup(dev->devargs->args);
-
 	ret = rte_eth_dev_close(port_id);
 	if (ret)
 		PMD_DRV_LOG(ERR, "rte_eth_dev_close failed port_id=%u ret=%d",
-- 
2.34.1


  parent reply	other threads:[~2025-01-28  1:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-28  1:35 [PATCH 1/4] net/netvsc: scan all net devices under the PCI device longli
2025-01-28  1:35 ` [PATCH 2/4] net/netvsc: remove RTE device if all its net devices are removed longli
2025-01-28  1:35 ` [PATCH 3/4] net/netvsc: log error on failure to switch data path longli
2025-01-28  1:35 ` longli [this message]
2025-01-28 21:00   ` [PATCH 4/4] net/netvsc: cache device parameters for hot plug events Stephen Hemminger
2025-01-29  0:10     ` [EXTERNAL] " Long Li
2025-01-29  0:31       ` Stephen Hemminger
2025-01-29  0:54         ` Long Li
2025-01-30  3:59       ` Stephen Hemminger
2025-01-28 21:01   ` Stephen Hemminger

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=1738028106-25239-4-git-send-email-longli@linuxonhyperv.com \
    --to=longli@linuxonhyperv.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=longli@microsoft.com \
    --cc=weh@microsoft.com \
    /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).