From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <anatoly.burakov@intel.com>
Received: from mga17.intel.com (mga17.intel.com [192.55.52.151])
 by dpdk.org (Postfix) with ESMTP id 98C561C699
 for <dev@dpdk.org>; Fri, 13 Apr 2018 18:10:19 +0200 (CEST)
X-Amp-Result: SKIPPED(no attachment in message)
X-Amp-File-Uploaded: False
Received: from orsmga008.jf.intel.com ([10.7.209.65])
 by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;
 13 Apr 2018 09:10:18 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.48,446,1517904000"; d="scan'208";a="33464816"
Received: from aburakov-mobl.ger.corp.intel.com (HELO [10.237.220.128])
 ([10.237.220.128])
 by orsmga008.jf.intel.com with ESMTP; 13 Apr 2018 09:10:17 -0700
To: Adrien Mazarguil <adrien.mazarguil@6wind.com>
Cc: dev@dpdk.org
References: <20180413153749.28208-1-adrien.mazarguil@6wind.com>
 <20180413155417.29643-1-adrien.mazarguil@6wind.com>
From: "Burakov, Anatoly" <anatoly.burakov@intel.com>
Message-ID: <0d2c152d-2b62-3772-8a40-05d73bb2ef74@intel.com>
Date: Fri, 13 Apr 2018 17:10:17 +0100
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101
 Thunderbird/52.7.0
MIME-Version: 1.0
In-Reply-To: <20180413155417.29643-1-adrien.mazarguil@6wind.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
Subject: Re: [dpdk-dev] [PATCH v2 1/2] eal: fix undefined behavior in fbarray
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://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Fri, 13 Apr 2018 16:10:20 -0000

On 13-Apr-18 4:56 PM, Adrien Mazarguil wrote:
> According to GCC documentation [1], the __builtin_clz() family of functions
> yield undefined behavior when fed a zero value. There is one instance in
> the fbarray code where this can occur.
> 
> Clang (at least version 3.8.0-2ubuntu4) seems much more sensitive to this
> than GCC and yields random results when compiling optimized code, as shown
> below:
> 
>   #include <stdio.h>
> 
>   int main(void)
>   {
>           volatile unsigned long long moo;
>           int x;
> 
>           moo = 0;
>           x = __builtin_clzll(moo);
>           printf("%d\n", x);
>           return 0;
>   }
> 
>   $ gcc -O3 -o test test.c && ./test
>   63
>   $ clang -O3 -o test test.c && ./test
>   1742715559
>   $ clang -O0 -o test test.c && ./test
>   63
> 
> Even 63 can be considered an unexpected result given the number of leading
> zeroes should be the full width of the underlying type, i.e. 64.
> 
> In practice it causes find_next_n() to sometimes return negative values
> interpreted as errors by caller functions, which prevents DPDK applications
> from starting due to inability to find free memory segments:
> 
>   # testpmd [...]
>   EAL: Detected 32 lcore(s)
>   EAL: Detected 2 NUMA nodes
>   EAL: No free hugepages reported in hugepages-1048576kB
>   EAL: Multi-process socket /var/run/.rte_unix
>   EAL: eal_memalloc_alloc_seg_bulk(): couldn't find suitable memseg_list
>   EAL: FATAL: Cannot init memory
> 
>   EAL: Cannot init memory
> 
>   PANIC in main():
>   Cannot init EAL
>   4: [./build/app/testpmd(_start+0x29) [0x462289]]
>   3: [/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)
>       [0x7f19d54fc830]]
>   2: [./build/app/testpmd(main+0x8a3) [0x466193]]
>   1: [./build/app/testpmd(__rte_panic+0xd6) [0x4efaa6]]
>   Aborted
> 
> This problem appears with commit 66cc45e293ed ("mem: replace memseg with
> memseg lists") however the root cause is introduced by a prior patch.
> 
> [1] https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
> 
> Fixes: c44d09811b40 ("eal: add shared indexed file-backed array")
> Cc: Anatoly Burakov <anatoly.burakov@intel.com>
> 
> Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
> ---

Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>

-- 
Thanks,
Anatoly