eal: use 32-bit RDSEED to allow 32-bit x86 usage

Message ID 20190628210846.20717-1-mattias.ronnblom@ericsson.com (mailing list archive)
State Accepted, archived
Headers
Series eal: use 32-bit RDSEED to allow 32-bit x86 usage |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Mattias Rönnblom June 28, 2019, 9:08 p.m. UTC
  When seeding the pseudo-random number generator, replace the 64-bit
RDSEED with two 32-bit RDSEED instructions to allow building and
running on 32-bit x86.

Fixes: faf8fd252785 ("eal: improve entropy for initial PRNG seed")

Reported-by: Ferruh Yigit <ferruh.yigit@intel.com>
Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
---
 lib/librte_eal/common/rte_random.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
  

Comments

Thomas Monjalon June 29, 2019, 12:54 p.m. UTC | #1
28/06/2019 23:08, Mattias Rönnblom:
> When seeding the pseudo-random number generator, replace the 64-bit
> RDSEED with two 32-bit RDSEED instructions to allow building and
> running on 32-bit x86.
> 
> Fixes: faf8fd252785 ("eal: improve entropy for initial PRNG seed")
> 
> Reported-by: Ferruh Yigit <ferruh.yigit@intel.com>
> Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_eal/common/rte_random.c b/lib/librte_eal/common/rte_random.c
index 3d9b9b7d8..f51708b30 100644
--- a/lib/librte_eal/common/rte_random.c
+++ b/lib/librte_eal/common/rte_random.c
@@ -189,14 +189,13 @@  __rte_random_initial_seed(void)
 		return ge_seed;
 #endif
 #ifdef RTE_MACHINE_CPUFLAG_RDSEED
-	unsigned int rdseed_rc;
-	unsigned long long rdseed_seed;
+	unsigned int rdseed_low;
+	unsigned int rdseed_high;
 
 	/* first fallback: rdseed instruction, if available */
-	rdseed_rc = _rdseed64_step(&rdseed_seed);
-
-	if (rdseed_rc == 1)
-		return (uint64_t)rdseed_seed;
+	if (_rdseed32_step(&rdseed_low) == 1 &&
+	    _rdseed32_step(&rdseed_high) == 1)
+		return (uint64_t)rdseed_low | ((uint64_t)rdseed_high << 32);
 #endif
 	/* second fallback: seed using rdtsc */
 	return rte_get_timer_cycles();