From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 51D455F17 for ; Tue, 14 May 2019 11:37:45 +0200 (CEST) X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 May 2019 02:37:44 -0700 X-ExtLoop1: 1 Received: from bricha3-mobl.ger.corp.intel.com ([10.237.221.96]) by fmsmga005.fm.intel.com with SMTP; 14 May 2019 02:37:42 -0700 Received: by (sSMTP sendmail emulation); Tue, 14 May 2019 10:37:41 +0100 Date: Tue, 14 May 2019 10:37:41 +0100 From: Bruce Richardson To: Mattias =?iso-8859-1?Q?R=F6nnblom?= Cc: dev@dpdk.org, nhorman@tuxdriver.com, stephen@networkplumber.org, david.marchand@redhat.com Message-ID: <20190514093741.GA592@bricha3-MOBL.ger.corp.intel.com> References: <20190508181014.7dde7580@xps13> <20190514092046.30808-1-mattias.ronnblom@ericsson.com> <20190514092046.30808-4-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190514092046.30808-4-mattias.ronnblom@ericsson.com> User-Agent: Mutt/1.11.4 (2019-03-13) Subject: Re: [dpdk-dev] [PATCH 3/6] eal: improve entropy for initial PRNG seed 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: Tue, 14 May 2019 09:37:45 -0000 On Tue, May 14, 2019 at 11:20:43AM +0200, Mattias Rönnblom wrote: > Replace the use of rte_get_timer_cycles() with getentropy() for > seeding the pseudo-random number generator. getentropy() provides a > more truly random value. > > Suggested-by: Stephen Hemminger > Signed-off-by: Mattias Rönnblom > --- > lib/librte_eal/common/rte_random.c | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/lib/librte_eal/common/rte_random.c b/lib/librte_eal/common/rte_random.c > index 4d3cf5226..aafc2f7ad 100644 > --- a/lib/librte_eal/common/rte_random.c > +++ b/lib/librte_eal/common/rte_random.c > @@ -3,6 +3,7 @@ > */ > > #include > +#include > > #include > #include > @@ -135,5 +136,14 @@ rte_rand(void) > > RTE_INIT(rte_rand_init) > { > - rte_srand(rte_get_timer_cycles()); > + uint64_t seed; > + int rc; > + > + rc = getentropy(&seed, sizeof(seed)); This API was only introduced in FreeBSD in v12, so you may want to have a define for enabling it, and (for meson) but in a check for cc.has_function(get_entropy). > + > + /* fall back to rdtsc in case of failure */ > + if (rc < 0) > + seed = rte_get_timer_cycles(); Rather than fallback immediately to time, what about putting in a call to HW random number generator support if available, e.g. rdseed instruction. > + > + rte_srand(seed); > } > -- > 2.17.1 > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id DA075A00E6 for ; Tue, 14 May 2019 11:37:46 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id ADCD95F25; Tue, 14 May 2019 11:37:46 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 51D455F17 for ; Tue, 14 May 2019 11:37:45 +0200 (CEST) X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 May 2019 02:37:44 -0700 X-ExtLoop1: 1 Received: from bricha3-mobl.ger.corp.intel.com ([10.237.221.96]) by fmsmga005.fm.intel.com with SMTP; 14 May 2019 02:37:42 -0700 Received: by (sSMTP sendmail emulation); Tue, 14 May 2019 10:37:41 +0100 Date: Tue, 14 May 2019 10:37:41 +0100 From: Bruce Richardson To: Mattias =?iso-8859-1?Q?R=F6nnblom?= Cc: dev@dpdk.org, nhorman@tuxdriver.com, stephen@networkplumber.org, david.marchand@redhat.com Message-ID: <20190514093741.GA592@bricha3-MOBL.ger.corp.intel.com> References: <20190508181014.7dde7580@xps13> <20190514092046.30808-1-mattias.ronnblom@ericsson.com> <20190514092046.30808-4-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190514092046.30808-4-mattias.ronnblom@ericsson.com> User-Agent: Mutt/1.11.4 (2019-03-13) Subject: Re: [dpdk-dev] [PATCH 3/6] eal: improve entropy for initial PRNG seed 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" Message-ID: <20190514093741.gxGlgMglNpECFLFQMYps6wjqhbBXq7KPFBTqg1dk3QM@z> On Tue, May 14, 2019 at 11:20:43AM +0200, Mattias Rönnblom wrote: > Replace the use of rte_get_timer_cycles() with getentropy() for > seeding the pseudo-random number generator. getentropy() provides a > more truly random value. > > Suggested-by: Stephen Hemminger > Signed-off-by: Mattias Rönnblom > --- > lib/librte_eal/common/rte_random.c | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/lib/librte_eal/common/rte_random.c b/lib/librte_eal/common/rte_random.c > index 4d3cf5226..aafc2f7ad 100644 > --- a/lib/librte_eal/common/rte_random.c > +++ b/lib/librte_eal/common/rte_random.c > @@ -3,6 +3,7 @@ > */ > > #include > +#include > > #include > #include > @@ -135,5 +136,14 @@ rte_rand(void) > > RTE_INIT(rte_rand_init) > { > - rte_srand(rte_get_timer_cycles()); > + uint64_t seed; > + int rc; > + > + rc = getentropy(&seed, sizeof(seed)); This API was only introduced in FreeBSD in v12, so you may want to have a define for enabling it, and (for meson) but in a check for cc.has_function(get_entropy). > + > + /* fall back to rdtsc in case of failure */ > + if (rc < 0) > + seed = rte_get_timer_cycles(); Rather than fallback immediately to time, what about putting in a call to HW random number generator support if available, e.g. rdseed instruction. > + > + rte_srand(seed); > } > -- > 2.17.1 >