patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Shahaf Shuler <shahafs@mellanox.com>
To: bluca@debian.org
Cc: stable@dpdk.org, nelio.laranjeiro@6wind.com, yskoh@mellanox.com,
	adrien.mazarguil@6wind.com
Subject: [dpdk-stable] [PATCH 05/33] net/mlx: fix rdma-core glue path with EAL plugins
Date: Sun,  6 May 2018 09:05:34 +0300	[thread overview]
Message-ID: <fd44735e638fe3e9d8ae9822757dda3b15ca8ba2.1525586525.git.shahafs@mellanox.com> (raw)
In-Reply-To: <cover.1525586525.git.shahafs@mellanox.com>

From: Adrien Mazarguil <adrien.mazarguil@6wind.com>

[ upstream commit 08c028d08c42c1a4cd26aff1ed9c6438ddfd1206 ]

Glue object files are looked up in RTE_EAL_PMD_PATH by default when set and
should be installed in this directory.

During startup, EAL attempts to load them automatically like other plug-ins
found there. While normally harmless, dlopen() fails when rdma-core is not
installed, EAL interprets this as a fatal error and terminates the
application.

This patch requests glue objects to be installed in a different directory
to prevent their automatic loading by EAL since they are PMD helpers, not
actual DPDK plug-ins.

Fixes: f6242d0655cd ("net/mlx: make rdma-core glue path configurable")
Cc: stable@dpdk.org

Reported-by: Timothy Redaelli <tredaelli@redhat.com>
Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
Tested-by: Timothy Redaelli <tredaelli@redhat.com>
---
 doc/guides/nics/mlx4.rst |  7 +++---
 doc/guides/nics/mlx5.rst |  7 +++---
 drivers/net/mlx4/mlx4.c  | 50 ++++++++++++++++++++++++++++++++++++++++++-
 drivers/net/mlx5/mlx5.c  | 50 ++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 106 insertions(+), 8 deletions(-)

diff --git a/doc/guides/nics/mlx4.rst b/doc/guides/nics/mlx4.rst
index 98b9716672..afeff276eb 100644
--- a/doc/guides/nics/mlx4.rst
+++ b/doc/guides/nics/mlx4.rst
@@ -98,9 +98,10 @@ These options can be modified in the ``.config`` file.
   missing with ``ldd(1)``.
 
   It works by moving these dependencies to a purpose-built rdma-core "glue"
-  plug-in, which must either be installed in ``CONFIG_RTE_EAL_PMD_PATH`` if
-  set, or in a standard location for the dynamic linker (e.g. ``/lib``) if
-  left to the default empty string (``""``).
+  plug-in which must either be installed in a directory whose name is based
+  on ``CONFIG_RTE_EAL_PMD_PATH`` suffixed with ``-glue`` if set, or in a
+  standard location for the dynamic linker (e.g. ``/lib``) if left to the
+  default empty string (``""``).
 
   This option has no performance impact.
 
diff --git a/doc/guides/nics/mlx5.rst b/doc/guides/nics/mlx5.rst
index 0e6e525c91..46d26e4c8a 100644
--- a/doc/guides/nics/mlx5.rst
+++ b/doc/guides/nics/mlx5.rst
@@ -171,9 +171,10 @@ These options can be modified in the ``.config`` file.
   missing with ``ldd(1)``.
 
   It works by moving these dependencies to a purpose-built rdma-core "glue"
-  plug-in, which must either be installed in ``CONFIG_RTE_EAL_PMD_PATH`` if
-  set, or in a standard location for the dynamic linker (e.g. ``/lib``) if
-  left to the default empty string (``""``).
+  plug-in which must either be installed in a directory whose name is based
+  on ``CONFIG_RTE_EAL_PMD_PATH`` suffixed with ``-glue`` if set, or in a
+  standard location for the dynamic linker (e.g. ``/lib``) if left to the
+  default empty string (``""``).
 
   This option has no performance impact.
 
diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c
index ee93dafe66..fb8a8b8484 100644
--- a/drivers/net/mlx4/mlx4.c
+++ b/drivers/net/mlx4/mlx4.c
@@ -708,11 +708,53 @@ static struct rte_pci_driver mlx4_driver = {
 #ifdef RTE_LIBRTE_MLX4_DLOPEN_DEPS
 
 /**
+ * Suffix RTE_EAL_PMD_PATH with "-glue".
+ *
+ * This function performs a sanity check on RTE_EAL_PMD_PATH before
+ * suffixing its last component.
+ *
+ * @param buf[out]
+ *   Output buffer, should be large enough otherwise NULL is returned.
+ * @param size
+ *   Size of @p out.
+ *
+ * @return
+ *   Pointer to @p buf or @p NULL in case suffix cannot be appended.
+ */
+static char *
+mlx4_glue_path(char *buf, size_t size)
+{
+	static const char *const bad[] = { "/", ".", "..", NULL };
+	const char *path = RTE_EAL_PMD_PATH;
+	size_t len = strlen(path);
+	size_t off;
+	int i;
+
+	while (len && path[len - 1] == '/')
+		--len;
+	for (off = len; off && path[off - 1] != '/'; --off)
+		;
+	for (i = 0; bad[i]; ++i)
+		if (!strncmp(path + off, bad[i], (int)(len - off)))
+			goto error;
+	i = snprintf(buf, size, "%.*s-glue", (int)len, path);
+	if (i == -1 || (size_t)i >= size)
+		goto error;
+	return buf;
+error:
+	ERROR("unable to append \"-glue\" to last component of"
+	      " RTE_EAL_PMD_PATH (\"" RTE_EAL_PMD_PATH "\"),"
+	      " please re-configure DPDK");
+	return NULL;
+}
+
+/**
  * Initialization routine for run-time dependency on rdma-core.
  */
 static int
 mlx4_glue_init(void)
 {
+	char glue_path[sizeof(RTE_EAL_PMD_PATH) - 1 + sizeof("-glue")];
 	const char *path[] = {
 		/*
 		 * A basic security check is necessary before trusting
@@ -720,7 +762,13 @@ mlx4_glue_init(void)
 		 */
 		(geteuid() == getuid() && getegid() == getgid() ?
 		 getenv("MLX4_GLUE_PATH") : NULL),
-		RTE_EAL_PMD_PATH,
+		/*
+		 * When RTE_EAL_PMD_PATH is set, use its glue-suffixed
+		 * variant, otherwise let dlopen() look up libraries on its
+		 * own.
+		 */
+		(*RTE_EAL_PMD_PATH ?
+		 mlx4_glue_path(glue_path, sizeof(glue_path)) : ""),
 	};
 	unsigned int i = 0;
 	void *handle = NULL;
diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index 61cb93101a..0ca16d11d7 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -1043,11 +1043,53 @@ static struct rte_pci_driver mlx5_driver = {
 #ifdef RTE_LIBRTE_MLX5_DLOPEN_DEPS
 
 /**
+ * Suffix RTE_EAL_PMD_PATH with "-glue".
+ *
+ * This function performs a sanity check on RTE_EAL_PMD_PATH before
+ * suffixing its last component.
+ *
+ * @param buf[out]
+ *   Output buffer, should be large enough otherwise NULL is returned.
+ * @param size
+ *   Size of @p out.
+ *
+ * @return
+ *   Pointer to @p buf or @p NULL in case suffix cannot be appended.
+ */
+static char *
+mlx5_glue_path(char *buf, size_t size)
+{
+	static const char *const bad[] = { "/", ".", "..", NULL };
+	const char *path = RTE_EAL_PMD_PATH;
+	size_t len = strlen(path);
+	size_t off;
+	int i;
+
+	while (len && path[len - 1] == '/')
+		--len;
+	for (off = len; off && path[off - 1] != '/'; --off)
+		;
+	for (i = 0; bad[i]; ++i)
+		if (!strncmp(path + off, bad[i], (int)(len - off)))
+			goto error;
+	i = snprintf(buf, size, "%.*s-glue", (int)len, path);
+	if (i == -1 || (size_t)i >= size)
+		goto error;
+	return buf;
+error:
+	ERROR("unable to append \"-glue\" to last component of"
+	      " RTE_EAL_PMD_PATH (\"" RTE_EAL_PMD_PATH "\"),"
+	      " please re-configure DPDK");
+	return NULL;
+}
+
+/**
  * Initialization routine for run-time dependency on rdma-core.
  */
 static int
 mlx5_glue_init(void)
 {
+	char glue_path[sizeof(RTE_EAL_PMD_PATH) - 1 + sizeof("-glue")];
 	const char *path[] = {
 		/*
 		 * A basic security check is necessary before trusting
@@ -1055,7 +1097,13 @@ mlx5_glue_init(void)
 		 */
 		(geteuid() == getuid() && getegid() == getgid() ?
 		 getenv("MLX5_GLUE_PATH") : NULL),
-		RTE_EAL_PMD_PATH,
+		/*
+		 * When RTE_EAL_PMD_PATH is set, use its glue-suffixed
+		 * variant, otherwise let dlopen() look up libraries on its
+		 * own.
+		 */
+		(*RTE_EAL_PMD_PATH ?
+		 mlx5_glue_path(glue_path, sizeof(glue_path)) : ""),
 	};
 	unsigned int i = 0;
 	void *handle = NULL;
-- 
2.12.0

  parent reply	other threads:[~2018-05-06  6:06 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-06  6:05 [dpdk-stable] [PATCH 00/33] mlx5 backports for 18.02.2 stable Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 01/33] net/mlx: control netdevices through ioctl only Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 02/33] net/mlx5: fix flow creation with a single target queue Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 03/33] net/mlx5: fix tunnel offloads cap query Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 04/33] net/mlx5: fix disabling Tx packet inlining Shahaf Shuler
2018-05-06  6:05 ` Shahaf Shuler [this message]
2018-05-06  6:05 ` [dpdk-stable] [PATCH 06/33] net/mlx5: fix sriov flag Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 07/33] net/mlx5: name parameters in function prototypes Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 08/33] net/mlx5: mark parameters with unused attribute Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 09/33] net/mlx5: normalize function prototypes Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 10/33] net/mlx5: add missing function documentation Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 11/33] net/mlx5: remove useless empty lines Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 12/33] net/mlx5: remove control path locks Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 13/33] net/mlx5: prefix all functions with mlx5 Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 14/33] net/mlx5: change non failing function return values Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 15/33] net/mlx5: standardize on negative errno values Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 16/33] net/mlx5: fix existing file removal Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 17/33] net/mlx5: fix ARM build Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 18/33] net/mlx5: remove kernel version check Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 19/33] net/mlx5: fix link status behavior Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 20/33] net/mlx5: fix link status to use wait to complete Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 21/33] net/mlx5: fix TSO enablement Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 22/33] net/mlx5: fix icc build Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 23/33] net/mlx5: fix RSS key length query Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 24/33] net/mlx: fix warnings for unused compiler arguments Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 25/33] net/mlx5: fix link status initialization Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 26/33] net/mlx5: fix RSS flow action bounds check Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 27/33] net/mlx5: split L3/L4 in flow director Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 28/33] net/mlx5: fix flow director mask Shahaf Shuler
2018-05-06  6:05 ` [dpdk-stable] [PATCH 29/33] net/mlx5: fix flow director rule deletion crash Shahaf Shuler
2018-05-08  9:49 ` [dpdk-stable] [PATCH 00/33] mlx5 backports for 18.02.2 stable Luca Boccassi
2018-05-08  9:56   ` Luca Boccassi
2018-05-09  7:51     ` Shahaf Shuler
2018-05-09 10:27       ` Luca Boccassi
2018-05-09 11:18         ` Shahaf Shuler
2018-05-09 14:03           ` Luca Boccassi
2018-05-09 15:03 ` [dpdk-stable] [PATCH v2 00/20] " Shahaf Shuler
2018-05-09 15:03   ` [dpdk-stable] [PATCH v2 01/20] net/mlx: control netdevices through ioctl only Shahaf Shuler
2018-05-09 15:03   ` [dpdk-stable] [PATCH v2 02/20] net/mlx5: name parameters in function prototypes Shahaf Shuler
2018-05-09 15:03   ` [dpdk-stable] [PATCH v2 03/20] net/mlx5: mark parameters with unused attribute Shahaf Shuler
2018-05-09 15:03   ` [dpdk-stable] [PATCH v2 04/20] net/mlx5: normalize function prototypes Shahaf Shuler
2018-05-09 15:03   ` [dpdk-stable] [PATCH v2 05/20] net/mlx5: add missing function documentation Shahaf Shuler
2018-05-09 15:03   ` [dpdk-stable] [PATCH v2 06/20] net/mlx5: remove useless empty lines Shahaf Shuler
2018-05-09 15:03   ` [dpdk-stable] [PATCH v2 07/20] net/mlx5: remove control path locks Shahaf Shuler
2018-05-09 15:04   ` [dpdk-stable] [PATCH v2 08/20] net/mlx5: prefix all functions with mlx5 Shahaf Shuler
2018-05-09 15:04   ` [dpdk-stable] [PATCH v2 09/20] net/mlx5: change non failing function return values Shahaf Shuler
2018-05-09 15:04   ` [dpdk-stable] [PATCH v2 10/20] net/mlx5: standardize on negative errno values Shahaf Shuler
2018-05-09 15:04   ` [dpdk-stable] [PATCH v2 11/20] net/mlx5: remove kernel version check Shahaf Shuler
2018-05-09 15:04   ` [dpdk-stable] [PATCH v2 12/20] net/mlx5: fix link status behavior Shahaf Shuler
2018-05-09 15:17     ` Shahaf Shuler
2018-05-09 15:04   ` [dpdk-stable] [PATCH v2 13/20] net/mlx5: fix link status to use wait to complete Shahaf Shuler
2018-05-09 15:17     ` Shahaf Shuler
2018-05-09 15:04   ` [dpdk-stable] [PATCH v2 14/20] net/mlx5: fix link status initialization Shahaf Shuler
2018-05-09 15:17     ` Shahaf Shuler
2018-05-09 15:04   ` [dpdk-stable] [PATCH v2 15/20] net/mlx5: split L3/L4 in flow director Shahaf Shuler
2018-05-09 15:04   ` [dpdk-stable] [PATCH v2 16/20] net/mlx5: fix flow director mask Shahaf Shuler
2018-05-09 15:17     ` Shahaf Shuler
2018-05-09 15:04   ` [dpdk-stable] [PATCH v2 17/20] net/mlx5: fix ethtool link setting call order Shahaf Shuler
2018-05-09 15:04   ` [dpdk-stable] [PATCH v2 18/20] net/mlx5: fix socket connection return value Shahaf Shuler
2018-05-09 15:04   ` [dpdk-stable] [PATCH v2 19/20] net/mlx5: fix probe return value polarity Shahaf Shuler
2018-05-09 15:04   ` [dpdk-stable] [PATCH v2 20/20] net/mlx5: fix flow validation Shahaf Shuler
2018-05-09 15:17     ` Shahaf Shuler
2018-05-09 15:15   ` [dpdk-stable] [PATCH v2 00/20] mlx5 backports for 18.02.2 stable Shahaf Shuler
2018-05-09 16:04   ` Luca Boccassi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fd44735e638fe3e9d8ae9822757dda3b15ca8ba2.1525586525.git.shahafs@mellanox.com \
    --to=shahafs@mellanox.com \
    --cc=adrien.mazarguil@6wind.com \
    --cc=bluca@debian.org \
    --cc=nelio.laranjeiro@6wind.com \
    --cc=stable@dpdk.org \
    --cc=yskoh@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).