[RFC PATCH 43/44] eal_cfg: support device and driver lists
Bruce Richardson
bruce.richardson at intel.com
Wed Apr 29 18:58:35 CEST 2026
Support configuring lists of devices, allowlist, blocklist and vdev
list, as well as lists of plugin paths.
Signed-off-by: Bruce Richardson <bruce.richardson at intel.com>
---
app/test/meson.build | 2 +-
app/test/test_eal_cfg.c | 128 ++++++++++++++++++++++++++++++++++++++
lib/eal_cfg/eal_cfg.c | 75 ++++++++++++++++++++++
lib/eal_cfg/rte_eal_cfg.h | 89 ++++++++++++++++++++++++++
4 files changed, 293 insertions(+), 1 deletion(-)
diff --git a/app/test/meson.build b/app/test/meson.build
index 3d39e82dd8..dccc27c18d 100644
--- a/app/test/meson.build
+++ b/app/test/meson.build
@@ -66,7 +66,7 @@ source_file_deps = {
'test_distributor_perf.c': ['distributor'],
'test_dmadev.c': ['dmadev', 'bus_vdev'],
'test_dmadev_api.c': ['dmadev'],
- 'test_eal_cfg.c': ['eal_cfg'],
+ 'test_eal_cfg.c': ['eal_cfg', 'ethdev', 'bus_vdev'],
'test_eal_flags.c': [],
'test_eal_fs.c': [],
'test_efd.c': ['efd', 'net'],
diff --git a/app/test/test_eal_cfg.c b/app/test/test_eal_cfg.c
index ceaa42260a..cf197e3eaa 100644
--- a/app/test/test_eal_cfg.c
+++ b/app/test/test_eal_cfg.c
@@ -13,6 +13,7 @@
#include <rte_vect.h>
#include <rte_eal_cfg.h>
+#include <rte_ethdev.h>
#include <rte_thread.h>
#include <stdlib.h>
#include <string.h>
@@ -142,6 +143,42 @@ subtest_eal_cfg_init_null(void)
return TEST_SUCCESS;
}
+/* Test that two net_null vdevs configured via add_vdev appear as ethdevs after init. */
+static int
+subtest_eal_cfg_init_null_pmd_vdevs(void)
+{
+#ifdef RTE_NET_NULL
+ struct rte_eal_cfg *cfg;
+ uint16_t port_id;
+ int ret;
+
+ cfg = rte_eal_cfg_create();
+ TEST_ASSERT_NOT_NULL(cfg, "rte_eal_cfg_create returned NULL");
+
+ TEST_ASSERT(rte_eal_cfg_add_vdev(cfg, "net_null0") == 0,
+ "Failed to add net_null0 vdev");
+ TEST_ASSERT(rte_eal_cfg_add_vdev(cfg, "net_null1") == 0,
+ "Failed to add net_null1 vdev");
+
+ ret = rte_eal_init_from_cfg("test_prog", cfg);
+ TEST_ASSERT(ret == 0,
+ "rte_eal_init_from_cfg failed: ret=%d rte_errno=%d", ret, rte_errno);
+
+ rte_eal_cfg_free(cfg);
+
+ TEST_ASSERT(rte_eth_dev_count_avail() == 2,
+ "Expected 2 ethdevs, got %u", rte_eth_dev_count_avail());
+
+ TEST_ASSERT(rte_eth_dev_get_port_by_name("net_null0", &port_id) == 0,
+ "Expected to find port net_null0");
+ TEST_ASSERT(rte_eth_dev_get_port_by_name("net_null1", &port_id) == 0,
+ "Expected to find port net_null1");
+
+ rte_eal_cleanup();
+#endif /* RTE_NET_NULL */
+ return TEST_SUCCESS;
+}
+
/* Test that lcore cpusets configured via set_lcore are visible post-init. */
static int
subtest_eal_cfg_init_lcore_affinity(void)
@@ -255,6 +292,7 @@ test_eal_cfg_init(void)
TEST_CFG_FN(subtest_eal_cfg_init_empty),
TEST_CFG_FN(subtest_eal_cfg_init_with_values),
TEST_CFG_FN(subtest_eal_cfg_init_lcore_affinity),
+ TEST_CFG_FN(subtest_eal_cfg_init_null_pmd_vdevs),
{ NULL, NULL }
};
@@ -823,6 +861,94 @@ test_eal_cfg_in_memory(void)
return TEST_SUCCESS;
}
+/* Test add_device_allow, add_device_block, add_vdev, add_plugin. */
+static int
+test_eal_cfg_devopt(void)
+{
+ struct rte_eal_cfg *cfg;
+
+ /* NULL cfg */
+ rte_errno = 0;
+ TEST_ASSERT(rte_eal_cfg_add_device_allow(NULL, "0000:00:01.0") == -1,
+ "Expected -1 for NULL cfg");
+ TEST_ASSERT(rte_errno == EINVAL,
+ "Expected EINVAL for NULL cfg, got %d", rte_errno);
+
+ rte_errno = 0;
+ TEST_ASSERT(rte_eal_cfg_add_device_block(NULL, "0000:00:01.0") == -1,
+ "Expected -1 for NULL cfg");
+ TEST_ASSERT(rte_errno == EINVAL,
+ "Expected EINVAL for NULL cfg, got %d", rte_errno);
+
+ rte_errno = 0;
+ TEST_ASSERT(rte_eal_cfg_add_vdev(NULL, "net_ring0") == -1,
+ "Expected -1 for NULL cfg");
+ TEST_ASSERT(rte_errno == EINVAL,
+ "Expected EINVAL for NULL cfg, got %d", rte_errno);
+
+ cfg = rte_eal_cfg_create();
+ TEST_ASSERT_NOT_NULL(cfg, "rte_eal_cfg_create returned NULL");
+
+ /* empty string rejected */
+ rte_errno = 0;
+ TEST_ASSERT(rte_eal_cfg_add_device_allow(cfg, "") == -1,
+ "Expected -1 for empty devargs");
+ TEST_ASSERT(rte_errno == EINVAL,
+ "Expected EINVAL for empty devargs, got %d", rte_errno);
+
+ /* valid allow entries */
+ TEST_ASSERT(rte_eal_cfg_add_device_allow(cfg, "0000:00:01.0") == 0,
+ "Expected 0 for add_device_allow");
+ TEST_ASSERT(rte_eal_cfg_add_device_allow(cfg, "0000:00:02.0,key=val") == 0,
+ "Expected 0 for add_device_allow with args");
+
+ /* valid block entry */
+ TEST_ASSERT(rte_eal_cfg_add_device_block(cfg, "0000:00:03.0") == 0,
+ "Expected 0 for add_device_block");
+
+ /* valid vdev entry */
+ TEST_ASSERT(rte_eal_cfg_add_vdev(cfg, "net_ring0") == 0,
+ "Expected 0 for add_vdev");
+ TEST_ASSERT(rte_eal_cfg_add_vdev(cfg, "net_ring1,size=1024") == 0,
+ "Expected 0 for add_vdev with args");
+
+ rte_eal_cfg_free(cfg);
+ return TEST_SUCCESS;
+}
+
+/* Test add_plugin. */
+static int
+test_eal_cfg_plugin(void)
+{
+ struct rte_eal_cfg *cfg;
+
+ /* NULL cfg */
+ rte_errno = 0;
+ TEST_ASSERT(rte_eal_cfg_add_plugin(NULL, "/path/to/lib.so") == -1,
+ "Expected -1 for NULL cfg");
+ TEST_ASSERT(rte_errno == EINVAL,
+ "Expected EINVAL for NULL cfg, got %d", rte_errno);
+
+ cfg = rte_eal_cfg_create();
+ TEST_ASSERT_NOT_NULL(cfg, "rte_eal_cfg_create returned NULL");
+
+ /* empty string rejected */
+ rte_errno = 0;
+ TEST_ASSERT(rte_eal_cfg_add_plugin(cfg, "") == -1,
+ "Expected -1 for empty path");
+ TEST_ASSERT(rte_errno == EINVAL,
+ "Expected EINVAL for empty path, got %d", rte_errno);
+
+ /* valid plugin paths */
+ TEST_ASSERT(rte_eal_cfg_add_plugin(cfg, "/usr/lib/dpdk/pmds/librte_net_ring.so") == 0,
+ "Expected 0 for add_plugin");
+ TEST_ASSERT(rte_eal_cfg_add_plugin(cfg, "/usr/lib/dpdk/pmds") == 0,
+ "Expected 0 for add_plugin with directory/glob");
+
+ rte_eal_cfg_free(cfg);
+ return TEST_SUCCESS;
+}
+
#ifndef RTE_EXEC_ENV_WINDOWS /* windows is missing the necessary macros for comparing CPUSETs etc. */
/* Test set/get_lcore and set/is_service_lcore. */
static int
@@ -975,6 +1101,8 @@ static struct unit_test_suite eal_cfg_testsuite = {
TEST_CASE(test_eal_cfg_hugepage_dir),
TEST_CASE(test_eal_cfg_huge_unlink),
TEST_CASE(test_eal_cfg_in_memory),
+ TEST_CASE(test_eal_cfg_devopt),
+ TEST_CASE(test_eal_cfg_plugin),
TEST_CASE(test_eal_cfg_lcore),
TEST_CASE(test_eal_cfg_service_lcore),
TEST_CASES_END()
diff --git a/lib/eal_cfg/eal_cfg.c b/lib/eal_cfg/eal_cfg.c
index 78f130c257..258e4fa11b 100644
--- a/lib/eal_cfg/eal_cfg.c
+++ b/lib/eal_cfg/eal_cfg.c
@@ -14,9 +14,11 @@
#include <eal_export.h>
#include <rte_bitops.h>
+#include <rte_devargs.h>
#include <rte_errno.h>
#include <rte_lcore.h>
#include <rte_log.h>
+#include <rte_string_fns.h>
#include <rte_thread.h>
#include <rte_vect.h>
@@ -536,6 +538,79 @@ rte_eal_cfg_set_in_memory(struct rte_eal_cfg *cfg, bool val)
RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eal_cfg_get_in_memory, 26.07)
EAL_CFG_GETTER(bool, in_memory, false)
+static int
+cfg_add_devopt(struct rte_eal_cfg *cfg, enum rte_devtype type, const char *devargs)
+{
+ struct device_option *devopt;
+ size_t arglen;
+
+ CFG_REQUIRE_NOT_NULL(cfg);
+
+ if (devargs == NULL || devargs[0] == '\0') {
+ EAL_CFG_LOG(ERR, "%s: devargs is NULL or empty", __func__);
+ rte_errno = EINVAL;
+ return -1;
+ }
+
+ arglen = strlen(devargs) + 1;
+ devopt = calloc(1, sizeof(*devopt) + arglen);
+ if (devopt == NULL) {
+ rte_errno = ENOMEM;
+ return -1;
+ }
+
+ devopt->type = type;
+ strlcpy(devopt->arg, devargs, arglen);
+ TAILQ_INSERT_TAIL(&cfg->user_cfg.devopt_list, devopt, next);
+ return 0;
+}
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eal_cfg_add_device_allow, 26.07)
+int
+rte_eal_cfg_add_device_allow(struct rte_eal_cfg *cfg, const char *devargs)
+{
+ return cfg_add_devopt(cfg, RTE_DEVTYPE_ALLOWED, devargs);
+}
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eal_cfg_add_device_block, 26.07)
+int
+rte_eal_cfg_add_device_block(struct rte_eal_cfg *cfg, const char *devargs)
+{
+ return cfg_add_devopt(cfg, RTE_DEVTYPE_BLOCKED, devargs);
+}
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eal_cfg_add_vdev, 26.07)
+int
+rte_eal_cfg_add_vdev(struct rte_eal_cfg *cfg, const char *devargs)
+{
+ return cfg_add_devopt(cfg, RTE_DEVTYPE_VIRTUAL, devargs);
+}
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eal_cfg_add_plugin, 26.07)
+int
+rte_eal_cfg_add_plugin(struct rte_eal_cfg *cfg, const char *path)
+{
+ struct eal_plugin_path *p;
+
+ CFG_REQUIRE_NOT_NULL(cfg);
+
+ if (path == NULL || path[0] == '\0') {
+ EAL_CFG_LOG(ERR, "%s: path is NULL or empty", __func__);
+ rte_errno = EINVAL;
+ return -1;
+ }
+
+ p = calloc(1, sizeof(*p));
+ if (p == NULL) {
+ rte_errno = ENOMEM;
+ return -1;
+ }
+
+ strlcpy(p->name, path, sizeof(p->name));
+ TAILQ_INSERT_TAIL(&cfg->user_cfg.plugin_list, p, next);
+ return 0;
+}
+
RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eal_cfg_set_lcore, 26.07)
int
rte_eal_cfg_set_lcore(struct rte_eal_cfg *cfg, unsigned int lcore_id,
diff --git a/lib/eal_cfg/rte_eal_cfg.h b/lib/eal_cfg/rte_eal_cfg.h
index 34a52d70e8..200010c40a 100644
--- a/lib/eal_cfg/rte_eal_cfg.h
+++ b/lib/eal_cfg/rte_eal_cfg.h
@@ -25,6 +25,7 @@ extern "C" {
#include <rte_os.h>
#include <rte_compat.h>
+#include <rte_devargs.h>
#include <rte_eal.h>
#include <rte_pci_dev_feature_defs.h>
@@ -568,6 +569,94 @@ __rte_experimental
bool
rte_eal_cfg_is_service_lcore(const struct rte_eal_cfg *cfg, unsigned int lcore_id);
+/**
+ * @}
+ */
+
+/**
+ * @name Device allow/block/virtual configuration
+ * @{
+ */
+
+/**
+ * Add a device allow entry (equivalent to -a / --allow).
+ *
+ * Appends a PCI or other bus device address to the allow list.
+ * Only devices on the allow list are probed when an allow list is present.
+ * Multiple calls may be made to allow multiple devices.
+ *
+ * @param cfg
+ * Configuration handle. Must not be NULL.
+ * @param devargs
+ * Device argument string, e.g. "0000:00:01.0" or "0000:00:01.0,key=val".
+ * Must not be NULL or empty.
+ * @return
+ * 0 on success, or -1 with rte_errno set to EINVAL (NULL or empty devargs
+ * or NULL cfg) or ENOMEM on allocation failure.
+ */
+__rte_experimental
+int
+rte_eal_cfg_add_device_allow(struct rte_eal_cfg *cfg, const char *devargs);
+
+/**
+ * Add a device block entry (equivalent to -b / --block).
+ *
+ * Appends a device address to the block list, preventing it from being probed.
+ *
+ * @param cfg
+ * Configuration handle. Must not be NULL.
+ * @param devargs
+ * Device argument string. Must not be NULL or empty.
+ * @return
+ * 0 on success, or -1 with rte_errno set to EINVAL or ENOMEM.
+ */
+__rte_experimental
+int
+rte_eal_cfg_add_device_block(struct rte_eal_cfg *cfg, const char *devargs);
+
+/**
+ * Add a virtual device (equivalent to --vdev).
+ *
+ * Appends a virtual device entry to the configuration.
+ *
+ * @param cfg
+ * Configuration handle. Must not be NULL.
+ * @param devargs
+ * Virtual device argument string, e.g. "net_ring0" or
+ * "net_ring0,size=1024". Must not be NULL or empty.
+ * @return
+ * 0 on success, or -1 with rte_errno set to EINVAL or ENOMEM.
+ */
+__rte_experimental
+int
+rte_eal_cfg_add_vdev(struct rte_eal_cfg *cfg, const char *devargs);
+
+/**
+ * @}
+ */
+
+/**
+ * @name Plugin configuration
+ * @{
+ */
+
+/**
+ * Add a plugin (shared library) to load at EAL initialisation (equivalent to -d).
+ *
+ * Each call appends one entry. Glob patterns are supported for directory
+ * expansion as with the -d command-line option.
+ *
+ * @param cfg
+ * Configuration handle. Must not be NULL.
+ * @param path
+ * Path to the shared library or a glob pattern. Must not be NULL or empty.
+ * @return
+ * 0 on success, or -1 with rte_errno set to EINVAL or ENOMEM.
+ */
+__rte_experimental
+int
+rte_eal_cfg_add_plugin(struct rte_eal_cfg *cfg, const char *path);
+
/**
* @}
*/
--
2.51.0
More information about the dev
mailing list