Blame SOURCES/0001-net-mlx-fix-rdma-core-glue-path-with-EAL-plugins.patch

a6040a
From 08c028d08c42c1a4cd26aff1ed9c6438ddfd1206 Mon Sep 17 00:00:00 2001
a6040a
From: Adrien Mazarguil <adrien.mazarguil@6wind.com>
a6040a
Date: Fri, 2 Mar 2018 15:15:17 +0100
a6040a
Subject: [PATCH] net/mlx: fix rdma-core glue path with EAL plugins
a6040a
a6040a
Glue object files are looked up in RTE_EAL_PMD_PATH by default when set and
a6040a
should be installed in this directory.
a6040a
a6040a
During startup, EAL attempts to load them automatically like other plug-ins
a6040a
found there. While normally harmless, dlopen() fails when rdma-core is not
a6040a
installed, EAL interprets this as a fatal error and terminates the
a6040a
application.
a6040a
a6040a
This patch requests glue objects to be installed in a different directory
a6040a
to prevent their automatic loading by EAL since they are PMD helpers, not
a6040a
actual DPDK plug-ins.
a6040a
a6040a
Fixes: f6242d0655cd ("net/mlx: make rdma-core glue path configurable")
a6040a
Cc: stable@dpdk.org
a6040a
a6040a
Reported-by: Timothy Redaelli <tredaelli@redhat.com>
a6040a
Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
a6040a
Tested-by: Timothy Redaelli <tredaelli@redhat.com>
a6040a
---
a6040a
 doc/guides/nics/mlx4.rst |  7 +++---
a6040a
 doc/guides/nics/mlx5.rst |  7 +++---
a6040a
 drivers/net/mlx4/mlx4.c  | 50 +++++++++++++++++++++++++++++++++++++++-
a6040a
 drivers/net/mlx5/mlx5.c  | 50 +++++++++++++++++++++++++++++++++++++++-
a6040a
 4 files changed, 106 insertions(+), 8 deletions(-)
a6040a
a6040a
diff --git a/doc/guides/nics/mlx4.rst b/doc/guides/nics/mlx4.rst
a6040a
index 98b971667..afeff276e 100644
a6040a
--- a/doc/guides/nics/mlx4.rst
a6040a
+++ b/doc/guides/nics/mlx4.rst
a6040a
@@ -98,9 +98,10 @@ These options can be modified in the ``.config`` file.
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
+  plug-in which must either be installed in a directory whose name is based
a6040a
+  on ``CONFIG_RTE_EAL_PMD_PATH`` suffixed with ``-glue`` if set, or in a
a6040a
+  standard location for the dynamic linker (e.g. ``/lib``) if left to the
a6040a
+  default empty string (``""``).
a6040a
 
a6040a
   This option has no performance impact.
a6040a
 
a6040a
diff --git a/doc/guides/nics/mlx5.rst b/doc/guides/nics/mlx5.rst
a6040a
index 0e6e525c9..46d26e4c8 100644
a6040a
--- a/doc/guides/nics/mlx5.rst
a6040a
+++ b/doc/guides/nics/mlx5.rst
a6040a
@@ -171,9 +171,10 @@ These options can be modified in the ``.config`` file.
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
+  plug-in which must either be installed in a directory whose name is based
a6040a
+  on ``CONFIG_RTE_EAL_PMD_PATH`` suffixed with ``-glue`` if set, or in a
a6040a
+  standard location for the dynamic linker (e.g. ``/lib``) if left to the
a6040a
+  default empty string (``""``).
a6040a
 
a6040a
   This option has no performance impact.
a6040a
 
a6040a
diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c
a6040a
index ee93dafe6..fb8a8b848 100644
a6040a
--- a/drivers/net/mlx4/mlx4.c
a6040a
+++ b/drivers/net/mlx4/mlx4.c
a6040a
@@ -707,12 +707,54 @@ static struct rte_pci_driver mlx4_driver = {
a6040a
 
a6040a
 #ifdef RTE_LIBRTE_MLX4_DLOPEN_DEPS
a6040a
 
a6040a
+/**
a6040a
+ * Suffix RTE_EAL_PMD_PATH with "-glue".
a6040a
+ *
a6040a
+ * This function performs a sanity check on RTE_EAL_PMD_PATH before
a6040a
+ * suffixing its last component.
a6040a
+ *
a6040a
+ * @param buf[out]
a6040a
+ *   Output buffer, should be large enough otherwise NULL is returned.
a6040a
+ * @param size
a6040a
+ *   Size of @p out.
a6040a
+ *
a6040a
+ * @return
a6040a
+ *   Pointer to @p buf or @p NULL in case suffix cannot be appended.
a6040a
+ */
a6040a
+static char *
a6040a
+mlx4_glue_path(char *buf, size_t size)
a6040a
+{
a6040a
+	static const char *const bad[] = { "/", ".", "..", NULL };
a6040a
+	const char *path = RTE_EAL_PMD_PATH;
a6040a
+	size_t len = strlen(path);
a6040a
+	size_t off;
a6040a
+	int i;
a6040a
+
a6040a
+	while (len && path[len - 1] == '/')
a6040a
+		--len;
a6040a
+	for (off = len; off && path[off - 1] != '/'; --off)
a6040a
+		;
a6040a
+	for (i = 0; bad[i]; ++i)
a6040a
+		if (!strncmp(path + off, bad[i], (int)(len - off)))
a6040a
+			goto error;
a6040a
+	i = snprintf(buf, size, "%.*s-glue", (int)len, path);
a6040a
+	if (i == -1 || (size_t)i >= size)
a6040a
+		goto error;
a6040a
+	return buf;
a6040a
+error:
a6040a
+	ERROR("unable to append \"-glue\" to last component of"
a6040a
+	      " RTE_EAL_PMD_PATH (\"" RTE_EAL_PMD_PATH "\"),"
a6040a
+	      " please re-configure DPDK");
a6040a
+	return NULL;
a6040a
+}
a6040a
+
a6040a
 /**
a6040a
  * Initialization routine for run-time dependency on rdma-core.
a6040a
  */
a6040a
 static int
a6040a
 mlx4_glue_init(void)
a6040a
 {
a6040a
+	char glue_path[sizeof(RTE_EAL_PMD_PATH) - 1 + sizeof("-glue")];
a6040a
 	const char *path[] = {
a6040a
 		/*
a6040a
 		 * A basic security check is necessary before trusting
a6040a
@@ -720,7 +762,13 @@ mlx4_glue_init(void)
a6040a
 		 */
a6040a
 		(geteuid() == getuid() && getegid() == getgid() ?
a6040a
 		 getenv("MLX4_GLUE_PATH") : NULL),
a6040a
-		RTE_EAL_PMD_PATH,
a6040a
+		/*
a6040a
+		 * When RTE_EAL_PMD_PATH is set, use its glue-suffixed
a6040a
+		 * variant, otherwise let dlopen() look up libraries on its
a6040a
+		 * own.
a6040a
+		 */
a6040a
+		(*RTE_EAL_PMD_PATH ?
a6040a
+		 mlx4_glue_path(glue_path, sizeof(glue_path)) : ""),
a6040a
 	};
a6040a
 	unsigned int i = 0;
a6040a
 	void *handle = NULL;
a6040a
diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
a6040a
index 61cb93101..0ca16d11d 100644
a6040a
--- a/drivers/net/mlx5/mlx5.c
a6040a
+++ b/drivers/net/mlx5/mlx5.c
a6040a
@@ -1042,12 +1042,54 @@ static struct rte_pci_driver mlx5_driver = {
a6040a
 
a6040a
 #ifdef RTE_LIBRTE_MLX5_DLOPEN_DEPS
a6040a
 
a6040a
+/**
a6040a
+ * Suffix RTE_EAL_PMD_PATH with "-glue".
a6040a
+ *
a6040a
+ * This function performs a sanity check on RTE_EAL_PMD_PATH before
a6040a
+ * suffixing its last component.
a6040a
+ *
a6040a
+ * @param buf[out]
a6040a
+ *   Output buffer, should be large enough otherwise NULL is returned.
a6040a
+ * @param size
a6040a
+ *   Size of @p out.
a6040a
+ *
a6040a
+ * @return
a6040a
+ *   Pointer to @p buf or @p NULL in case suffix cannot be appended.
a6040a
+ */
a6040a
+static char *
a6040a
+mlx5_glue_path(char *buf, size_t size)
a6040a
+{
a6040a
+	static const char *const bad[] = { "/", ".", "..", NULL };
a6040a
+	const char *path = RTE_EAL_PMD_PATH;
a6040a
+	size_t len = strlen(path);
a6040a
+	size_t off;
a6040a
+	int i;
a6040a
+
a6040a
+	while (len && path[len - 1] == '/')
a6040a
+		--len;
a6040a
+	for (off = len; off && path[off - 1] != '/'; --off)
a6040a
+		;
a6040a
+	for (i = 0; bad[i]; ++i)
a6040a
+		if (!strncmp(path + off, bad[i], (int)(len - off)))
a6040a
+			goto error;
a6040a
+	i = snprintf(buf, size, "%.*s-glue", (int)len, path);
a6040a
+	if (i == -1 || (size_t)i >= size)
a6040a
+		goto error;
a6040a
+	return buf;
a6040a
+error:
a6040a
+	ERROR("unable to append \"-glue\" to last component of"
a6040a
+	      " RTE_EAL_PMD_PATH (\"" RTE_EAL_PMD_PATH "\"),"
a6040a
+	      " please re-configure DPDK");
a6040a
+	return NULL;
a6040a
+}
a6040a
+
a6040a
 /**
a6040a
  * Initialization routine for run-time dependency on rdma-core.
a6040a
  */
a6040a
 static int
a6040a
 mlx5_glue_init(void)
a6040a
 {
a6040a
+	char glue_path[sizeof(RTE_EAL_PMD_PATH) - 1 + sizeof("-glue")];
a6040a
 	const char *path[] = {
a6040a
 		/*
a6040a
 		 * A basic security check is necessary before trusting
a6040a
@@ -1055,7 +1097,13 @@ mlx5_glue_init(void)
a6040a
 		 */
a6040a
 		(geteuid() == getuid() && getegid() == getgid() ?
a6040a
 		 getenv("MLX5_GLUE_PATH") : NULL),
a6040a
-		RTE_EAL_PMD_PATH,
a6040a
+		/*
a6040a
+		 * When RTE_EAL_PMD_PATH is set, use its glue-suffixed
a6040a
+		 * variant, otherwise let dlopen() look up libraries on its
a6040a
+		 * own.
a6040a
+		 */
a6040a
+		(*RTE_EAL_PMD_PATH ?
a6040a
+		 mlx5_glue_path(glue_path, sizeof(glue_path)) : ""),
a6040a
 	};
a6040a
 	unsigned int i = 0;
a6040a
 	void *handle = NULL;
a6040a
-- 
a6040a
2.17.0
a6040a