From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 0D93FA0527;
	Wed, 25 Nov 2020 11:01:47 +0100 (CET)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id E9054C952;
	Wed, 25 Nov 2020 11:01:43 +0100 (CET)
Received: from us-smtp-delivery-124.mimecast.com
 (us-smtp-delivery-124.mimecast.com [216.205.24.124])
 by dpdk.org (Postfix) with ESMTP id 5068BC93C
 for <dev@dpdk.org>; Wed, 25 Nov 2020 11:01:41 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1606298499;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 in-reply-to:in-reply-to:references:references;
 bh=vkmzNo2kc7IxQRhpQBs7U6HLKt6FBbIA+1JSsR9j0og=;
 b=YeSCVYduuSykBctg2dfoZHqlKoI18yH7H0Khx0F6Vc+TuYrHZE/C++eeslxqyjKPnsxKnC
 eLOplZeJGHbn/3Afl2DM5b6bKPFe+EK+dOmpVkvaM3MWdz0G3+/E/0F3Q7kwqhTqILQgCd
 c4C7x2UB06LoTySee6M9kA/LKY1UHHI=
Received: from mail-vk1-f198.google.com (mail-vk1-f198.google.com
 [209.85.221.198]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-547-gf1b6dJBNwq4b3MdifHz1w-1; Wed, 25 Nov 2020 05:01:37 -0500
X-MC-Unique: gf1b6dJBNwq4b3MdifHz1w-1
Received: by mail-vk1-f198.google.com with SMTP id p199so254321vkp.23
 for <dev@dpdk.org>; Wed, 25 Nov 2020 02:01:36 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:references:in-reply-to:from:date
 :message-id:subject:to:cc;
 bh=vkmzNo2kc7IxQRhpQBs7U6HLKt6FBbIA+1JSsR9j0og=;
 b=Hlu/3FabEeHpRE1xEhJGkbAMSpFYD0XyOAQnktjurAOfITRV8nA4P4HbGPyQ8yKPV3
 5PtaJYh7X3bc9VC5IjT7o4ViwEBbjTP3NMPSRFxGJbBosnH3bM7bQpbXroFZM2px+7u0
 JpoRC25JPOt/N/6ae33dQkWe/nsnM18FiZkibh1e8U8Xb3zkZYe0pCi/SDJzrcOtg5nZ
 jLAYxFG6vJCdaghPvTfZUbh+8ZCFY3NJRoWuh/X75gEZD9S/vTIB303KuirLejBG3h7k
 bExPOpKZLrTpoc0T+tlZII76PdCWOzDx0WSA853ANypnGXvjy9flAAbtIEpCBpMNThl6
 UwYg==
X-Gm-Message-State: AOAM533th2Gx1m7YXd30ZlQArqPebj6CodSk7V22TFtN6cS/9ox48ydB
 aJpX7UaYdJ4W+1Kri5tczj+wYvC0Yo6eFHETbkE74hEv/Uq4WDCaUgi/leAZ+9RRZtvCSIl2I7A
 ne3JbmPaISLieCBQcUdU=
X-Received: by 2002:ab0:6dd3:: with SMTP id r19mr954190uaf.86.1606298496118;
 Wed, 25 Nov 2020 02:01:36 -0800 (PST)
X-Google-Smtp-Source: ABdhPJw1ufGnj8sCs4NKgkH1Ac4OVzyNjFVPHwtlWlyhWLbR6Rgh2l5k11rv/yZutGCGy40aEYkkaUlcQ8X6Bm0Mbx8=
X-Received: by 2002:ab0:6dd3:: with SMTP id r19mr954166uaf.86.1606298495749;
 Wed, 25 Nov 2020 02:01:35 -0800 (PST)
MIME-Version: 1.0
References: <cover.1606229937.git.tredaelli@redhat.com>
 <4a04b06b040ac16c45addf92fb43f59b070f185a.1606229937.git.tredaelli@redhat.com>
In-Reply-To: <4a04b06b040ac16c45addf92fb43f59b070f185a.1606229937.git.tredaelli@redhat.com>
From: David Marchand <david.marchand@redhat.com>
Date: Wed, 25 Nov 2020 11:01:25 +0100
Message-ID: <CAJFAV8yXfTphNviB10tyo5mLy+yuS3dcVVAHL9Q67b2s+cuurw@mail.gmail.com>
To: Timothy Redaelli <tredaelli@redhat.com>
Cc: Anatoly Burakov <anatoly.burakov@intel.com>, 
 Bruce Richardson <bruce.richardson@intel.com>, dev <dev@dpdk.org>,
 dpdk stable <stable@dpdk.org>
Authentication-Results: relay.mimecast.com;
 auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmarchan@redhat.com
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Type: text/plain; charset="UTF-8"
Subject: Re: [dpdk-dev] [dpdk-stable] [PATCH 2/2] eal: fix loading of shared
 libs from driver plugin directories
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

On Tue, Nov 24, 2020 at 4:15 PM Timothy Redaelli <tredaelli@redhat.com> wrote:
>
> Commit 49b536fc3060 ("eal: load only shared libs from driver plugin directories")
> introduced a check that any shared library must ends with .so, but it can't
> work, at least, on Fedora/CentOS/RHEL since .so symlinks are not installed
> when you install dpdk package, but only when you install dpdk-devel package.
>
> This commit adds also a check for .so.ABI_VERSION to check for shared
> lib.
>
> See Fedora Packaging Guidelines for more informations:
> https://docs.fedoraproject.org/en-US/packaging-guidelines/#_devel_packages
>
> Fixes: 49b536fc3060 ("eal: load only shared libs from driver plugin directories")
> Cc: bruce.richardson@intel.com
> Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>
> ---
>  lib/librte_eal/common/eal_common_options.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
> index e6f77ad217..e9e2362c53 100644
> --- a/lib/librte_eal/common/eal_common_options.c
> +++ b/lib/librte_eal/common/eal_common_options.c
> @@ -402,8 +402,10 @@ eal_plugindir_init(const char *path)
>                 struct stat sb;
>                 int nlen = strnlen(dent->d_name, sizeof(dent->d_name));
>
> -               /* check if name ends in .so */
> -               if (strcmp(&dent->d_name[nlen - 3], ".so") != 0)
> +               /* check if name ends in .so or .so.ABI_VERSION */
> +               if (strcmp(&dent->d_name[nlen - 3], ".so") != 0 &&
> +                   strcmp(&dent->d_name[nlen - 4 - strlen(ABI_VERSION)],
> +                          ".so."ABI_VERSION) != 0)
>                         continue;
>
>                 snprintf(sopath, sizeof(sopath), "%s/%s", path, dent->d_name);

A first doubt I had about this patch is about multiple loading of the
same driver, and its effects.
So I first had a look at the main branch current state (using
devtools/test-null.sh) and I can see multiple loading already happens
for statically linked drivers like the bond driver.

$ LD_LIBRARY_PATH=build/lib gdb build/app/dpdk-testpmd -ex "b main"
-ex "run -c 3 --no-huge -m 20 -d build/drivers '--log-level=*:debug'
-a 0:0.0 --vdev net_null1 --vdev net_null2 -- --no-mlockall
--total-num-mbufs=2048 -ia"
...
(gdb) info sharedlibrary
...
0x00007ffff796d5b0  0x00007ffff797d2d6  Yes
/home/dmarchan/dpdk/build/app/../drivers/librte_net_bond.so.21
...
(gdb) b rte_eal_init
(gdb) c
(gdb) finish
...
EAL: open shared lib build/drivers/librte_net_avp.so
EAL: open shared lib build/drivers/librte_net_bond.so
EAL: open shared lib build/drivers/librte_net_ixgbe.so
...
(gdb) set $elm=*(struct shared_driver *)solib_list.tqh_first
(gdb) while $elm
p $elm
set $elm=*(struct shared_driver *)($elm.next.tqe_next)
end
...
$67 = {next = {tqe_next = 0x5c3350, tqe_prev = 0x5c1310}, name =
"build/drivers/librte_net_avp.so", '\000' <repeats 4064 times>,
lib_handle = 0x616870}
$68 = {next = {tqe_next = 0x5c4370, tqe_prev = 0x5c2330}, name =
"build/drivers/librte_net_bond.so", '\000' <repeats 4063 times>,
lib_handle = 0x7ffff7995a80}
$69 = {next = {tqe_next = 0x5c5390, tqe_prev = 0x5c3350}, name =
"build/drivers/librte_net_ixgbe.so", '\000' <repeats 4062 times>,
lib_handle = 0x7ffff7942fc0}
...

I could not confirm the 0x7ffff7995a80 handle points at the first load
of the bond driver.
gdb does not seem to know of the linker internal structures, a bit
hard to tell but the addresses are in the same range, so likely the
same object.

I confirmed the bond constructor only being called once when the bond
driver is loaded because of static link:

$ LD_LIBRARY_PATH=build/lib gdb build/app/dpdk-testpmd -ex "b
vdrvinitfn_pmd_bond_drv" -ex "run -c 3 --no-huge -m 20 -d
build/drivers '--log-level=*:debug' -a 0:0.0 --vdev net_null1 --vdev
net_null2 -- --no-mlockall --total-num-mbufs=2048 -ia"
GNU gdb (GDB) Fedora 8.3.50.20190824-30.fc31
...
Reading symbols from build/app/dpdk-testpmd...
Function "vdrvinitfn_pmd_bond_drv" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (vdrvinitfn_pmd_bond_drv) pending.
Starting program: /home/dmarchan/dpdk/build/app/dpdk-testpmd -c 3
--no-huge -m 20 -d build/drivers '--log-level=*:debug' -a 0:0.0 --vdev
net_null1 --vdev net_null2 -- --no-mlockall --total-num-mbufs=2048 -ia
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib64/libthread_db.so.1".

Breakpoint 1, vdrvinitfn_pmd_bond_drv () at
../drivers/net/bonding/rte_eth_bond_pmd.c:3755
3755    RTE_PMD_REGISTER_VDEV(net_bonding, pmd_bond_drv);
Missing separate debuginfos, use: dnf debuginfo-install
elfutils-libelf-0.179-2.fc31.x86_64 glibc-2.30-13.fc31.x86_64
jansson-2.12-4.fc31.x86_64 libbsd-0.9.1-4.fc31.x86_64
libfdt-1.6.0-1.fc31.x86_64 numactl-libs-2.0.12-3.fc31.x86_64
zlib-1.2.11-20.fc31.x86_64

(gdb) c
Continuing.
...
EAL: open shared lib build/drivers/librte_net_avp.so
EAL: open shared lib build/drivers/librte_net_bond.so
EAL: open shared lib build/drivers/librte_net_ixgbe.so
...
testpmd>


Now, about this patch.
In this test, it has the effect of loading all drivers twice (or
thrice if statically linked).
I see no problem with it since the linker is intelligent enough and
constructors are only called once.


My only remaining doubt is whether we should be looking for
.ABI_VERSION or .ABI_MAJOR extension.
This could be discussed, but in its current form, this patch lgtm.

Acked-by: David Marchand <david.marchand@redhat.com>


-- 
David Marchand