From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8CC0FA0588; Thu, 16 Apr 2020 14:12:12 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5AA521DC24; Thu, 16 Apr 2020 14:12:11 +0200 (CEST) Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by dpdk.org (Postfix) with ESMTP id AF0D01DC1B for ; Thu, 16 Apr 2020 14:12:09 +0200 (CEST) Received: by mail-io1-f65.google.com with SMTP id u11so5191842iow.4 for ; Thu, 16 Apr 2020 05:12:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=xnTz6Tmfm5n3RognB4CWKkyZHCJCaca4LhBNobwQ7Lo=; b=omo3oDSrNmFOTnLdqQBUw3WzOHM4uNtvbYfHeRkSGu+XXDjmm6evosflgG8IWfWSZV nu9rJ2qZFefCQagCJPGm8zg5rGsdpL5yQddxM2dkXZy3wNUXkcGMGz4j+HwGdNoiviYR c2VpzzsCfpxxkuSgelvM1HlB0vjdnt+ShKtzetniUGXOs6oPjQtq9GiX6HrWaoRajHVe 26jPeak3Y2xqVOPJ6VELuFOXLHuWfSjaWERXskpnFh3zU2MhTg0Tgj+JTeTy5/jZJr2C CJwroUOqGBTn5SimcuPxiGxaF3ZtwqfmHFF+nT/i/hkNZDRHddD+7s/AnzhKXqzpY8AI UHxg== 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:content-transfer-encoding; bh=xnTz6Tmfm5n3RognB4CWKkyZHCJCaca4LhBNobwQ7Lo=; b=C+k1mLhjxQ9bIPvSy/4kMap3fyQ2pKnDxwO3/hQtIth+XmntxLUeteK5fTU30aS5JW HOBlvQsUL4TWAt/MB/RXf3E6apZKqUIJjiF219rYuPp7cz8P+pL2vq0lInZo3Ncu3DoT Y5lQKUw18p/jWEfqlRVYUvGE/v56ShDbpxOV0AzZoUYojBRN4O4PtitoAhXnW8kPDyHN zGnky9ylU9qbZyj325U4VHEl5TSJKLuMmHnN/Ie67k4vA3QaXBzZn75qd1VWZkYW3TPl ID/wC66OvJKguLlBrmfScUUatdR2ctYkT5ghGUD8mlOu8+8XdgDdD3pj/R0Uh1slQ3YZ RFmg== X-Gm-Message-State: AGi0PuZDTTjsdv/PM2qK6liRP5Ug7PUPTemrLamwjy2TZipqcmBtbbiV 7u70Marl80lkA2sm+GqOHLlJh5nsio5B7u6pXHk= X-Google-Smtp-Source: APiQypK721zwB6OS+rFxklGiI8OBMhVOv7gny/w1GNVDVaAPj7dKJgvot05wYRv2xgZRS3Do0TgZk7Sd2q99Ci0vQU0= X-Received: by 2002:a05:6602:2f87:: with SMTP id u7mr29908057iow.94.1587039128738; Thu, 16 Apr 2020 05:12:08 -0700 (PDT) MIME-Version: 1.0 References: <20200415231119.27845-1-dg@adax.com> <2114f9a2-bda4-4796-7872-bf21f7e9f327@ericsson.com> <23f2aad5-7efc-bf11-9233-5b10fc5e9e61@ericsson.com> In-Reply-To: <23f2aad5-7efc-bf11-9233-5b10fc5e9e61@ericsson.com> From: Jerin Jacob Date: Thu, 16 Apr 2020 17:41:52 +0530 Message-ID: To: =?UTF-8?Q?Mattias_R=C3=B6nnblom?= Cc: Dan Gora , Thomas Monjalon , David Marchand , dpdk-dev , Gavin Hu , Honnappa Nagarahalli Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [dpdk-dev] [PATCH] eal: choose initial PRNG seed source at runtime 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Thu, Apr 16, 2020 at 5:30 PM Mattias R=C3=B6nnblom wrote: > > On 2020-04-16 13:48, Jerin Jacob wrote: > > On Thu, Apr 16, 2020 at 5:06 PM Mattias R=C3=B6nnblom > > wrote: > >> On 2020-04-16 08:07, Jerin Jacob wrote: > >>> On Thu, Apr 16, 2020 at 4:42 AM Dan Gora wrote: > >>>> Instead of choosing to use getentropy() or the rdseed instruction fo= r > >>>> the random number generator entropy source using compilation flags, > >>>> determine the best source at run time. > >>>> > >>>> This is accomplished by defining a weak symbol for getentropy(), > >>>> checking that the compiler can generate the rdseed instruction even = if > >>>> the compilation platform does not natively support it, and checking = for > >>>> the availability of the rdseed instruction on the execution platform > >>>> using rte_cpu_get_flag_enabled(). > >>>> > >>>> If neither getentropy() or rdseed is available, rte_get_timer_cycles= () > >>>> will be continue to be used as the entropy source. > >>>> > >>>> This also allows non-Mason builds to use getentropy(). > >>>> > >>>> Signed-off-by: Dan Gora > >>>> --- > >>>> config/x86/meson.build | 7 +++++++ > >>>> lib/librte_eal/common/rte_random.c | 29 ++++++++++++++++++++++++-= ---- > >>>> lib/librte_eal/meson.build | 3 --- > >>>> mk/rte.cpuflags.mk | 8 ++++++++ > >>>> 4 files changed, 39 insertions(+), 8 deletions(-) > >>>> > >>>> diff --git a/config/x86/meson.build b/config/x86/meson.build > >>>> index adc857ba2..214b16f2a 100644 > >>>> --- a/config/x86/meson.build > >>>> +++ b/config/x86/meson.build > >>>> @@ -20,6 +20,13 @@ if cc.get_define('__SSE4_2__', args: machine_args= ) =3D=3D '' > >>>> machine_args +=3D '-msse4' > >>>> endif > >>>> > >>>> +# set -mrdseed if necessary so _rdseed32_step compiles if the > >>>> +# compilation host does not support the RDSEED instruction. > >>>> +if cc.get_define('__RDSEED__', args: machine_args) =3D=3D '' and cc= .has_argument('-mrdseed') > >>>> + machine_args +=3D '-mrdseed' > >>>> + message('RDSEED not enabled by default, explicitly setting -= mrdseed') > >>>> +endif > >>>> + > >>>> base_flags =3D ['SSE', 'SSE2', 'SSE3','SSSE3', 'SSE4_1', 'SSE4_2'= ] > >>>> foreach f:base_flags > >>>> dpdk_conf.set('RTE_MACHINE_CPUFLAG_' + f, 1) > >>>> diff --git a/lib/librte_eal/common/rte_random.c b/lib/librte_eal/com= mon/rte_random.c > >>>> index 57ec8fb2b..40f8b5aab 100644 > >>>> --- a/lib/librte_eal/common/rte_random.c > >>>> +++ b/lib/librte_eal/common/rte_random.c > >>>> @@ -25,6 +25,8 @@ struct rte_rand_state { > >>>> > >>>> static struct rte_rand_state rand_states[RTE_MAX_LCORE]; > >>>> > >>>> +__rte_weak int getentropy(void *__buffer, size_t __length); > >>>> + > >>>> static uint32_t > >>>> __rte_rand_lcg32(uint32_t *seed) > >>>> { > >>>> @@ -176,10 +178,24 @@ rte_rand_max(uint64_t upper_bound) > >>>> return res; > >>>> } > >>>> > >>>> +/* Use rte_get_timer_cycles() if the system does not have > >>>> + * genentropy() or the rdseed instruction. > >>>> + */ > >>>> +__rte_weak int > >>>> +getentropy(void *__buffer, size_t __length __rte_unused) > >>>> +{ > >>>> + uint64_t *ge_seed =3D __buffer; > >>>> +#ifdef RTE_MACHINE_CPUFLAG_RDSEED > >>>> + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_RDSEED)) > >>>> + return -1; > >>>> +#endif > >>>> + *ge_seed =3D rte_get_timer_cycles(); > >>>> + return 0; > >>> IMO, we need to create a new arch EAL abstraction to get uint64_t > >>> random number. Reason being: > >>> 1) ARMv8.5 supports similar instruction > >>> https://developer.arm.com/docs/ddi0595/c/aarch64-system-registers/rnd= r > >> > >> How many ARMv8.5 system will there be running a libc older than 2.25 o= r > >> a Linux kernel older than 3.17? > > Probably none. > > > In that case getentropy() will always available, and having ARMv8.5 rndr > support would be pointless, as far as rte_random.c is concerned. Yes. My initial comment was based on this patch context. I just checked the lib/librte_eal/common/rte_random.c, if this get activated only libc older than 2.25 or kernel < 3.17, it is not a concern for me. > > >> > >>> 2) Avoid #ifdef clutter in common code. > >>> > >>> Abstraction can return a random uint64_t number. Based on the arch > >>> capabilities, it can hook > >>> to specialized instruction or rte_get_timer_cycles() > >