Skip to contentSkip to conversation

eal: update all buses default scan mode

PATCH In review Xueming Li 4 participants 9 messages Mar 16, 2021 – Jun 30, 2023

lore
Share & tools
lore

Xueming Li

author
#0 lore raw

PATCH 1/1 eal: update all buses default scan mode

When parsing EAL allowed or blocked device arguments, only device bus being parsed got default scan mode updated. If the devargs was vdev, PCI bus default scan mode not touched, all PCI bus devices will got probed even none appear in allowed list.

This patch update all buses default scan mode when parsing first devargs.

---
 lib/librte_eal/common/eal_common_bus.c     | 16 ++++++++++++++++
 lib/librte_eal/common/eal_common_devargs.c | 13 +++++--------
 lib/librte_eal/common/eal_private.h        |  9 +++++++++
 lib/librte_eal/rte_eal_exports.def         |  1 +
 lib/librte_eal/version.map                 |  2 ++
 5 files changed, 33 insertions(+), 8 deletions(-)
lib/librte_eal/common/eal_common_bus.c +16 -0
index baa5b532af..ebbb3995f6 100644
@@ -277,3 +277,19 @@ rte_bus_sigbus_handler(const void *failure_addr)
 
 	return ret;
 }
+
+static bool mode_set;
+
+void
+rte_bus_scan_mode_update(enum rte_bus_scan_mode mode)
+{
+	struct rte_bus *bus;
+
+	if (mode_set)
+		return;
+	TAILQ_FOREACH(bus, &rte_bus_list, next) {
+		if (bus->conf.scan_mode == RTE_BUS_SCAN_UNDEFINED)
+			bus->conf.scan_mode = mode;
+	}
+	mode_set = true;
+}
lib/librte_eal/common/eal_common_devargs.c +5 -8
index fcf3d9a3cc..3aedcb5c09 100644
@@ -301,7 +301,6 @@ int
 rte_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 {
 	struct rte_devargs *devargs = NULL;
-	struct rte_bus *bus = NULL;
 	const char *dev = devargs_str;
 
 	/* use calloc instead of rte_zmalloc as it's called early at init */
@@ -312,15 +311,13 @@ rte_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 	if (rte_devargs_parse(devargs, dev))
 		goto fail;
 	devargs->type = devtype;
-	bus = devargs->bus;
 	if (devargs->type == RTE_DEVTYPE_BLOCKED)
 		devargs->policy = RTE_DEV_BLOCKED;
-	if (bus->conf.scan_mode == RTE_BUS_SCAN_UNDEFINED) {
-		if (devargs->policy == RTE_DEV_ALLOWED)
-			bus->conf.scan_mode = RTE_BUS_SCAN_ALLOWLIST;
-		else if (devargs->policy == RTE_DEV_BLOCKED)
-			bus->conf.scan_mode = RTE_BUS_SCAN_BLOCKLIST;
-	}
+
+	if (devargs->policy == RTE_DEV_ALLOWED)
+		rte_bus_scan_mode_update(RTE_BUS_SCAN_ALLOWLIST);
+	else if (devargs->policy == RTE_DEV_BLOCKED)
+		rte_bus_scan_mode_update(RTE_BUS_SCAN_BLOCKLIST);
 	TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
 	return 0;
 
lib/librte_eal/common/eal_private.h +9 -0
index b8a0d20021..78b07508ec 100644
@@ -452,6 +452,15 @@ int rte_eal_memory_detach(void);
  */
 struct rte_bus *rte_bus_find_by_device_name(const char *str);
 
+/**
+ * Update all buses scan mode if not set, used by EAL parameter parsing.
+ *
+ * @param mode
+ *   Bus scan mode to be set.
+ */
+__rte_internal
+void rte_bus_scan_mode_update(enum rte_bus_scan_mode mode);
+
 /**
  * Create the unix channel for primary/secondary communication.
  *
lib/librte_eal/rte_eal_exports.def +1 -0
index 474cf123fa..2757f31461 100644
@@ -11,6 +11,7 @@ EXPORTS
 	rte_bus_probe
 	rte_bus_register
 	rte_bus_scan
+	rte_bus_scan_mode_update
 	rte_bus_unregister
 	rte_calloc
 	rte_calloc_socket
lib/librte_eal/version.map +2 -0
index fce90a112f..171bca478d 100644
@@ -417,6 +417,8 @@ EXPERIMENTAL {
 INTERNAL {
 	global:
 
+	rte_bus_scan_mode_update;
+
 	rte_mem_lock;
 	rte_mem_map;
 	rte_mem_page_size;
Signature · 1 line
2.25.1
#1 lore raw

2021-03-16 20:45 (UTC+0800), Xueming Li:
[...]

lib/librte_eal/common/eal_common_bus.c rte_bus_sigbus_handler(const void *failure_addr) · line 281

Quoted 10 lines
lib/librte_eal/common/eal_common_bus.c +2 -0
index baa5b532af..ebbb3995f6 100644
@@ -277,3 +277,19 @@ rte_bus_sigbus_handler(const void *failure_addr)
 
 	return ret;
 }
+
+static bool mode_set;

Could be function-local if we really want to save list traversals.

Quoted 14 lines
lib/librte_eal/common/eal_common_bus.c +14 -0
+
+void
+rte_bus_scan_mode_update(enum rte_bus_scan_mode mode)
+{
+	struct rte_bus *bus;
+
+	if (mode_set)
+		return;
+	TAILQ_FOREACH(bus, &rte_bus_list, next) {
+		if (bus->conf.scan_mode == RTE_BUS_SCAN_UNDEFINED)
+			bus->conf.scan_mode = mode;
+	}
+	mode_set = true;
+}

[...]

Quoted 20 lines

/**
* Create the unix channel for primary/secondary communication. *

lib/librte_eal/rte_eal_exports.def +1 -0
index 474cf123fa..2757f31461 100644
@@ -11,6 +11,7 @@ EXPORTS
 	rte_bus_probe
 	rte_bus_register
 	rte_bus_scan
+	rte_bus_scan_mode_update
 	rte_bus_unregister
 	rte_calloc
 	rte_calloc_socket
lib/librte_eal/version.map +0 -0
index fce90a112f..171bca478d 100644

lib/librte_eal/version.map EXPERIMENTAL { · line 424

Quoted 8 lines
lib/librte_eal/version.map +2 -0
@@ -417,6 +417,8 @@ EXPERIMENTAL {
 INTERNAL {
 	global:
 
+	rte_bus_scan_mode_update;
+
 	rte_mem_lock;
 	rte_mem_map;
 	rte_mem_page_size;

New function is private to EAL, so it doesn't need exporting.

#2 lore raw
Quoted 54 lines · Dmitry Kozlyuk

2021-03-16 20:45 (UTC+0800), Xueming Li:
[...]

lib/librte_eal/common/eal_common_bus.c rte_bus_sigbus_handler(const void *failure_addr) · line 281

Quoted 10 lines
lib/librte_eal/common/eal_common_bus.c +2 -0
index baa5b532af..ebbb3995f6 100644
@@ -277,3 +277,19 @@ rte_bus_sigbus_handler(const void *failure_addr)
 
 	return ret;
 }
+
+static bool mode_set;

Could be function-local if we really want to save list traversals.

Quoted 14 lines
lib/librte_eal/common/eal_common_bus.c +14 -0
+
+void
+rte_bus_scan_mode_update(enum rte_bus_scan_mode mode)
+{
+	struct rte_bus *bus;
+
+	if (mode_set)
+		return;
+	TAILQ_FOREACH(bus, &rte_bus_list, next) {
+		if (bus->conf.scan_mode == RTE_BUS_SCAN_UNDEFINED)
+			bus->conf.scan_mode = mode;
+	}
+	mode_set = true;
+}

[...]

Quoted 23 lines

/**
* Create the unix channel for primary/secondary communication. *

lib/librte_eal/rte_eal_exports.def +1 -0
index 474cf123fa..2757f31461 100644
@@ -11,6 +11,7 @@ EXPORTS
 	rte_bus_probe
 	rte_bus_register
 	rte_bus_scan
+	rte_bus_scan_mode_update
 	rte_bus_unregister
 	rte_calloc
 	rte_calloc_socket
lib/librte_eal/version.map +0 -0
index fce90a112f..171bca478d 100644
@@ -417,6 +417,8 @@ EXPERIMENTAL {
 INTERNAL {
 	global:
 
Quoted 8 lines

lib/librte_eal/version.map EXPERIMENTAL { · line 424

Quoted 5 lines
lib/librte_eal/version.map +2 -0
+	rte_bus_scan_mode_update;
+
 	rte_mem_lock;
 	rte_mem_map;
 	rte_mem_page_size;

New function is private to EAL, so it doesn't need exporting.

Right - it is annotated as INTERNAL.

#3 lore raw
Quoted 5 lines · Ray
Quoted 2 lines · Dmitry Kozlyuk

2021-03-16 20:45 (UTC+0800), Xueming Li:
[...]

[SNIP]

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

rte_mem_page_size;

New function is private to EAL, so it doesn't need exporting.

Right - it is annotated as INTERNAL.

Sorry, let me be clearer - it is being correctly annotated unless I have missed something.

#4 lore raw

2021-03-23 09:34 (UTC+0000), Kinsella, Ray:

Quoted 9 lines · Ray
Quoted 5 lines · Dmitry Kozlyuk
Quoted 2 lines

2021-03-16 20:45 (UTC+0800), Xueming Li:
[...]

[SNIP]

Quoted 2 lines
Quoted 2 lines
Quoted 1 line

rte_mem_page_size;

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

New function is private to EAL, so it doesn't need exporting.

Right - it is annotated as INTERNAL.

Sorry, let me be clearer - it is being correctly annotated unless I have missed something.

This function is purely internal to librte_eal. It doesn't need to be added to .map or .def. It also doesn't need __rte_internal, like other functions in eal_private.h don't need it either.

#5 lore raw
Quoted 13 lines · Dmitry Kozlyuk

2021-03-23 09:34 (UTC+0000), Kinsella, Ray:

Quoted 12 lines · Ray
Quoted 5 lines · Dmitry Kozlyuk
Quoted 2 lines

2021-03-16 20:45 (UTC+0800), Xueming Li:
[...]

[SNIP]

Quoted 5 lines
Quoted 4 lines
Quoted 1 line

rte_mem_page_size;

New function is private to EAL, so it doesn't need exporting.

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

Right - it is annotated as INTERNAL.

Sorry, let me be clearer - it is being correctly annotated unless I have missed something.

This function is purely internal to librte_eal. It doesn't need to be added to .map or .def. It also doesn't need __rte_internal, like other functions in eal_private.h don't need it either.

ok - I get you now - agreed.

author
#7 lore raw

PATCH 1/1 eal: update all buses default scan mode

In reply to Xueming Li

When parsing EAL allowed or blocked device arguments, only device bus being parsed got default scan mode updated. If the devargs was vdev, PCI bus default scan mode not touched, all PCI bus devices will got probed even none appear in allowed list.

This patch update all buses default scan mode when parsing first devargs.

---
 lib/librte_eal/common/eal_common_bus.c     | 15 +++++++++++++++
 lib/librte_eal/common/eal_common_devargs.c | 13 +++++--------
 lib/librte_eal/common/eal_private.h        |  8 ++++++++
 3 files changed, 28 insertions(+), 8 deletions(-)
lib/librte_eal/common/eal_common_bus.c +15 -0
index baa5b532af..d5818a456e 100644
@@ -277,3 +277,18 @@ rte_bus_sigbus_handler(const void *failure_addr)
 
 	return ret;
 }
+
+void
+rte_bus_scan_mode_update(enum rte_bus_scan_mode mode)
+{
+	struct rte_bus *bus;
+	static bool mode_set;
+
+	if (mode_set)
+		return;
+	TAILQ_FOREACH(bus, &rte_bus_list, next) {
+		if (bus->conf.scan_mode == RTE_BUS_SCAN_UNDEFINED)
+			bus->conf.scan_mode = mode;
+	}
+	mode_set = true;
+}
lib/librte_eal/common/eal_common_devargs.c +5 -8
index fcf3d9a3cc..3aedcb5c09 100644
@@ -301,7 +301,6 @@ int
 rte_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 {
 	struct rte_devargs *devargs = NULL;
-	struct rte_bus *bus = NULL;
 	const char *dev = devargs_str;
 
 	/* use calloc instead of rte_zmalloc as it's called early at init */
@@ -312,15 +311,13 @@ rte_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 	if (rte_devargs_parse(devargs, dev))
 		goto fail;
 	devargs->type = devtype;
-	bus = devargs->bus;
 	if (devargs->type == RTE_DEVTYPE_BLOCKED)
 		devargs->policy = RTE_DEV_BLOCKED;
-	if (bus->conf.scan_mode == RTE_BUS_SCAN_UNDEFINED) {
-		if (devargs->policy == RTE_DEV_ALLOWED)
-			bus->conf.scan_mode = RTE_BUS_SCAN_ALLOWLIST;
-		else if (devargs->policy == RTE_DEV_BLOCKED)
-			bus->conf.scan_mode = RTE_BUS_SCAN_BLOCKLIST;
-	}
+
+	if (devargs->policy == RTE_DEV_ALLOWED)
+		rte_bus_scan_mode_update(RTE_BUS_SCAN_ALLOWLIST);
+	else if (devargs->policy == RTE_DEV_BLOCKED)
+		rte_bus_scan_mode_update(RTE_BUS_SCAN_BLOCKLIST);
 	TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
 	return 0;
 
lib/librte_eal/common/eal_private.h +8 -0
index b8a0d20021..ddd6769849 100644
@@ -452,6 +452,14 @@ int rte_eal_memory_detach(void);
  */
 struct rte_bus *rte_bus_find_by_device_name(const char *str);
 
+/**
+ * Update all buses scan mode if not set, used by EAL parameter parsing.
+ *
+ * @param mode
+ *   Bus scan mode to be set.
+ */
+void rte_bus_scan_mode_update(enum rte_bus_scan_mode mode);
+
 /**
  * Create the unix channel for primary/secondary communication.
  *
Signature · 1 line
2.25.1
#6 lore raw
In reply to Kinsella, Ray

Thanks for comments, new version sent:
http://patchwork.dpdk.org/project/dpdk/patch/[email protected]/

Quoted 35 lines

-----Original Message-----
From: Kinsella, Ray <[email protected]>
Sent: Tuesday, March 23, 2021 5:59 PM
To: Dmitry Kozlyuk <[email protected]>
Cc: Xueming(Steven) Li <[email protected]>; [email protected]; Narcisa Ana Maria Vasile <[email protected]>; Dmitry Malloy <[email protected]>; Pallavi Kadam <[email protected]>; Neil Horman <[email protected]>
Subject: Re: [PATCH] eal: update all buses default scan mode

Quoted 13 lines · Dmitry Kozlyuk

2021-03-23 09:34 (UTC+0000), Kinsella, Ray:

Quoted 12 lines · Ray
Quoted 5 lines · Dmitry Kozlyuk
Quoted 2 lines

2021-03-16 20:45 (UTC+0800), Xueming Li:
[...]

[SNIP]

Quoted 5 lines
Quoted 4 lines
Quoted 1 line

rte_mem_page_size;

New function is private to EAL, so it doesn't need exporting.

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

Right - it is annotated as INTERNAL.

Sorry, let me be clearer - it is being correctly annotated unless I have missed something.

This function is purely internal to librte_eal. It doesn't need to be added to .map or .def. It also doesn't need __rte_internal, like other functions in eal_private.h don't need it either.

ok - I get you now - agreed.

#8 lore raw
In reply to Xueming Li
Quoted 9 lines · On Sun, 28 Mar 2021 21:12:22 +0800 Xueming Li <[email protected]> wrote:

When parsing EAL allowed or blocked device arguments, only device bus being parsed got default scan mode updated. If the devargs was vdev, PCI bus default scan mode not touched, all PCI bus devices will got probed even none appear in allowed list.

This patch update all buses default scan mode when parsing first devargs.

Looking back at this old patch, and wondering why it never got applied. Probably because it wasn't clear the exact problem.

It does raise the issue that scan_mode is currently a property of the bus, not global. This patch would cause setting of allowed list for PCI to also impact other bus types. That doesn't follow current practice.

If you want to resubmit, make it per bus.