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

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