Blame SOURCES/mlnx-dpdk-0008-net-mlx-make-rdma-core-glue-path-configurable.patch

a6040a
From 3218c0fc3b87a634415114bc6ee84444d8399f43 Mon Sep 17 00:00:00 2001
a6040a
From: Adrien Mazarguil <adrien.mazarguil@6wind.com>
a6040a
Date: Thu, 1 Feb 2018 14:30:57 +0100
a6040a
Subject: [PATCH 8/9] net/mlx: make rdma-core glue path configurable
a6040a
a6040a
Since rdma-core glue libraries are intrinsically tied to their respective
a6040a
PMDs and used as internal plug-ins, their presence in the default search
a6040a
path among other system libraries for the dynamic linker is not necessarily
a6040a
desired.
a6040a
a6040a
This commit enables their installation and subsequent look-up at run time
a6040a
in RTE_EAL_PMD_PATH if configured to a nonempty string. This path can also
a6040a
be overridden by environment variables MLX[45]_GLUE_PATH.
a6040a
a6040a
Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
a6040a
(cherry picked from commit 4143e796d50334d4d13e1b2c98139f2ac08c8178)
a6040a
---
a6040a
 doc/guides/nics/mlx4.rst | 17 +++++++++++++++++
a6040a
 doc/guides/nics/mlx5.rst | 14 ++++++++++++++
a6040a
 drivers/net/mlx4/mlx4.c  | 43 ++++++++++++++++++++++++++++++++++++++++++-
a6040a
 drivers/net/mlx5/mlx5.c  | 43 ++++++++++++++++++++++++++++++++++++++++++-
a6040a
 4 files changed, 115 insertions(+), 2 deletions(-)
a6040a
a6040a
diff --git a/doc/guides/nics/mlx4.rst b/doc/guides/nics/mlx4.rst
a6040a
index 5912722..19ccf9c 100644
a6040a
--- a/doc/guides/nics/mlx4.rst
a6040a
+++ b/doc/guides/nics/mlx4.rst
a6040a
@@ -97,6 +97,11 @@ These options can be modified in the ``.config`` file.
a6040a
   ``CONFIG_RTE_BUILD_SHARED_LIB`` disabled) and they won't show up as
a6040a
   missing with ``ldd(1)``.
a6040a
 
a6040a
+  It works by moving these dependencies to a purpose-built rdma-core "glue"
a6040a
+  plug-in, which must either be installed in ``CONFIG_RTE_EAL_PMD_PATH`` if
a6040a
+  set, or in a standard location for the dynamic linker (e.g. ``/lib``) if
a6040a
+  left to the default empty string (``""``).
a6040a
+
a6040a
   This option has no performance impact.
a6040a
 
a6040a
 - ``CONFIG_RTE_LIBRTE_MLX4_DEBUG`` (default **n**)
a6040a
@@ -121,6 +126,18 @@ These options can be modified in the ``.config`` file.
a6040a
 
a6040a
   This value is always 1 for RX queues since they use a single MP.
a6040a
 
a6040a
+Environment variables
a6040a
+~~~~~~~~~~~~~~~~~~~~~
a6040a
+
a6040a
+- ``MLX4_GLUE_PATH``
a6040a
+
a6040a
+  A list of directories in which to search for the rdma-core "glue" plug-in,
a6040a
+  separated by colons or semi-colons.
a6040a
+
a6040a
+  Only matters when compiled with ``CONFIG_RTE_LIBRTE_MLX4_DLOPEN_DEPS``
a6040a
+  enabled and most useful when ``CONFIG_RTE_EAL_PMD_PATH`` is also set,
a6040a
+  since ``LD_LIBRARY_PATH`` has no effect in this case.
a6040a
+
a6040a
 Run-time configuration
a6040a
 ~~~~~~~~~~~~~~~~~~~~~~
a6040a
 
a6040a
diff --git a/doc/guides/nics/mlx5.rst b/doc/guides/nics/mlx5.rst
a6040a
index 6ee4a47..5f53eed 100644
a6040a
--- a/doc/guides/nics/mlx5.rst
a6040a
+++ b/doc/guides/nics/mlx5.rst
a6040a
@@ -157,6 +157,11 @@ These options can be modified in the ``.config`` file.
a6040a
   ``CONFIG_RTE_BUILD_SHARED_LIB`` disabled) and they won't show up as
a6040a
   missing with ``ldd(1)``.
a6040a
 
a6040a
+  It works by moving these dependencies to a purpose-built rdma-core "glue"
a6040a
+  plug-in, which must either be installed in ``CONFIG_RTE_EAL_PMD_PATH`` if
a6040a
+  set, or in a standard location for the dynamic linker (e.g. ``/lib``) if
a6040a
+  left to the default empty string (``""``).
a6040a
+
a6040a
   This option has no performance impact.
a6040a
 
a6040a
 - ``CONFIG_RTE_LIBRTE_MLX5_DEBUG`` (default **n**)
a6040a
@@ -176,6 +181,15 @@ These options can be modified in the ``.config`` file.
a6040a
 Environment variables
a6040a
 ~~~~~~~~~~~~~~~~~~~~~
a6040a
 
a6040a
+- ``MLX5_GLUE_PATH``
a6040a
+
a6040a
+  A list of directories in which to search for the rdma-core "glue" plug-in,
a6040a
+  separated by colons or semi-colons.
a6040a
+
a6040a
+  Only matters when compiled with ``CONFIG_RTE_LIBRTE_MLX5_DLOPEN_DEPS``
a6040a
+  enabled and most useful when ``CONFIG_RTE_EAL_PMD_PATH`` is also set,
a6040a
+  since ``LD_LIBRARY_PATH`` has no effect in this case.
a6040a
+
a6040a
 - ``MLX5_PMD_ENABLE_PADDING``
a6040a
 
a6040a
   Enables HW packet padding in PCI bus transactions.
a6040a
diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c
a6040a
index e41acf1..6b29a8b 100644
a6040a
--- a/drivers/net/mlx4/mlx4.c
a6040a
+++ b/drivers/net/mlx4/mlx4.c
a6040a
@@ -712,11 +712,52 @@ struct mlx4_conf {
a6040a
 static int
a6040a
 mlx4_glue_init(void)
a6040a
 {
a6040a
+	const char *path[] = {
a6040a
+		/*
a6040a
+		 * A basic security check is necessary before trusting
a6040a
+		 * MLX4_GLUE_PATH, which may override RTE_EAL_PMD_PATH.
a6040a
+		 */
a6040a
+		(geteuid() == getuid() && getegid() == getgid() ?
a6040a
+		 getenv("MLX4_GLUE_PATH") : NULL),
a6040a
+		RTE_EAL_PMD_PATH,
a6040a
+	};
a6040a
+	unsigned int i = 0;
a6040a
 	void *handle = NULL;
a6040a
 	void **sym;
a6040a
 	const char *dlmsg;
a6040a
 
a6040a
-	handle = dlopen(MLX4_GLUE, RTLD_LAZY);
a6040a
+	while (!handle && i != RTE_DIM(path)) {
a6040a
+		const char *end;
a6040a
+		size_t len;
a6040a
+		int ret;
a6040a
+
a6040a
+		if (!path[i]) {
a6040a
+			++i;
a6040a
+			continue;
a6040a
+		}
a6040a
+		end = strpbrk(path[i], ":;");
a6040a
+		if (!end)
a6040a
+			end = path[i] + strlen(path[i]);
a6040a
+		len = end - path[i];
a6040a
+		ret = 0;
a6040a
+		do {
a6040a
+			char name[ret + 1];
a6040a
+
a6040a
+			ret = snprintf(name, sizeof(name), "%.*s%s" MLX4_GLUE,
a6040a
+				       (int)len, path[i],
a6040a
+				       (!len || *(end - 1) == '/') ? "" : "/");
a6040a
+			if (ret == -1)
a6040a
+				break;
a6040a
+			if (sizeof(name) != (size_t)ret + 1)
a6040a
+				continue;
a6040a
+			DEBUG("looking for rdma-core glue as \"%s\"", name);
a6040a
+			handle = dlopen(name, RTLD_LAZY);
a6040a
+			break;
a6040a
+		} while (1);
a6040a
+		path[i] = end + 1;
a6040a
+		if (!*end)
a6040a
+			++i;
a6040a
+	}
a6040a
 	if (!handle) {
a6040a
 		rte_errno = EINVAL;
a6040a
 		dlmsg = dlerror();
a6040a
diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
a6040a
index 6618d2c..403e26b 100644
a6040a
--- a/drivers/net/mlx5/mlx5.c
a6040a
+++ b/drivers/net/mlx5/mlx5.c
a6040a
@@ -1033,11 +1033,52 @@ struct mlx5_args {
a6040a
 static int
a6040a
 mlx5_glue_init(void)
a6040a
 {
a6040a
+	const char *path[] = {
a6040a
+		/*
a6040a
+		 * A basic security check is necessary before trusting
a6040a
+		 * MLX5_GLUE_PATH, which may override RTE_EAL_PMD_PATH.
a6040a
+		 */
a6040a
+		(geteuid() == getuid() && getegid() == getgid() ?
a6040a
+		 getenv("MLX5_GLUE_PATH") : NULL),
a6040a
+		RTE_EAL_PMD_PATH,
a6040a
+	};
a6040a
+	unsigned int i = 0;
a6040a
 	void *handle = NULL;
a6040a
 	void **sym;
a6040a
 	const char *dlmsg;
a6040a
 
a6040a
-	handle = dlopen(MLX5_GLUE, RTLD_LAZY);
a6040a
+	while (!handle && i != RTE_DIM(path)) {
a6040a
+		const char *end;
a6040a
+		size_t len;
a6040a
+		int ret;
a6040a
+
a6040a
+		if (!path[i]) {
a6040a
+			++i;
a6040a
+			continue;
a6040a
+		}
a6040a
+		end = strpbrk(path[i], ":;");
a6040a
+		if (!end)
a6040a
+			end = path[i] + strlen(path[i]);
a6040a
+		len = end - path[i];
a6040a
+		ret = 0;
a6040a
+		do {
a6040a
+			char name[ret + 1];
a6040a
+
a6040a
+			ret = snprintf(name, sizeof(name), "%.*s%s" MLX5_GLUE,
a6040a
+				       (int)len, path[i],
a6040a
+				       (!len || *(end - 1) == '/') ? "" : "/");
a6040a
+			if (ret == -1)
a6040a
+				break;
a6040a
+			if (sizeof(name) != (size_t)ret + 1)
a6040a
+				continue;
a6040a
+			DEBUG("looking for rdma-core glue as \"%s\"", name);
a6040a
+			handle = dlopen(name, RTLD_LAZY);
a6040a
+			break;
a6040a
+		} while (1);
a6040a
+		path[i] = end + 1;
a6040a
+		if (!*end)
a6040a
+			++i;
a6040a
+	}
a6040a
 	if (!handle) {
a6040a
 		rte_errno = EINVAL;
a6040a
 		dlmsg = dlerror();
a6040a
-- 
a6040a
1.8.3.1
a6040a