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

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