From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by dpdk.org (Postfix) with ESMTP id CD0BE5B3C for ; Fri, 2 Mar 2018 15:15:31 +0100 (CET) Received: by mail-wr0-f193.google.com with SMTP id m12so10223287wrm.13 for ; Fri, 02 Mar 2018 06:15:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=S8Y4PwmTfcj5MUV0rvUrWHkrWAQjqJQpS7wNZwtFaC8=; b=AaxBIxLbMqxp6+Za1YUsvz7UA+RhlXaw3QmZfJohteR8sCHo5ejCwf3LIxOYVFTFW9 JeePu1p3DrItdcQLt8E2MfJNJs543ugk2fsN48yaiAAoOS7n8dH7KuXmHQBtd1V0wYkn E/5MDBQ/E2vXwIzMkZ7yBESrVdLvkY9ta2q4nrwSn+p6kevcx/v/Z7w9vFP6RDqvByC5 3kluvmniSf/mPtw1MBtg7oc7eaar4JPTxQaU1uJPE6SHvrxF0BAn1pnon8vrI7Fw/rMP r3pefMscsJ7RvKOL7/uAEBepk2hvtWOkNR7uhsbaHiV9BQ/cPc4bzpS+BZpP3reKf/nf psdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=S8Y4PwmTfcj5MUV0rvUrWHkrWAQjqJQpS7wNZwtFaC8=; b=P4iEB+5GSsra/BNeSpGeHRL7sDhcxcPuSItQ/jmnUM7UKEAM5qU5KkZA6f4BXDD8fS 4gdftPe/GsH5CO54jJXFqqyi7YGg4KEG/X6mIk3KmjqnHGEVq7F9N6nLLxr7XUgS59uD BkdW9HejjI6CanzfX7650XIY8+Vx094El/TmxJVykhPOeK2/YGadBzH/fT48Sk2ZSrMG QLzHUBDitrHalG19MUzMtbDXBb2sz55gAgtv2yokouudOxLeqG6ZSGCXLptRcMlguYPa O6PUDq4yWETERLlDxJj/eu3soIqqW+4ecuXFCKAbdU1AUpHWVlYM/bVRLvAKVzI0ZQrW xu8w== X-Gm-Message-State: APf1xPA8Lcd9/+fH7Dbqsk85JJ06URYITVr6LZf79OaftUAalGkwyh8x 11MH44m9y5K0G60+uodMhHZYjA== X-Google-Smtp-Source: AG47ELsz82z99XkMzrrnEo+sNLhDV3BDGed0y1NNj9kJ2yjLfiX96hwLd9VEE+u6ke8uooclhEhuCg== X-Received: by 10.223.198.200 with SMTP id c8mr4995262wrh.14.1520000131183; Fri, 02 Mar 2018 06:15:31 -0800 (PST) Received: from 6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p12sm5005129wre.89.2018.03.02.06.15.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 06:15:30 -0800 (PST) Date: Fri, 2 Mar 2018 15:15:17 +0100 From: Adrien Mazarguil To: Shahaf Shuler Cc: dev@dpdk.org, stable@dpdk.org, Timothy Redaelli Message-ID: <20180302141211.30818-1-adrien.mazarguil@6wind.com> References: <20180301124129.9606-1-adrien.mazarguil@6wind.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180301124129.9606-1-adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.11.0 Subject: [dpdk-dev] [PATCH v2] net/mlx: fix rdma-core glue path with EAL plugins X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Mar 2018 14:15:32 -0000 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 Signed-off-by: Adrien Mazarguil --- 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 98b971667..afeff276e 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 0e6e525c9..46d26e4c8 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 ee93dafe6..fb8a8b848 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 61cb93101..0ca16d11d 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.11.0