From ed5acd09263b0bfbac1bc6b26bb6e366d14a8408 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Mon, 4 Feb 2019 12:54:41 -0500 Subject: [PATCH] LU-9859 libcfs: replace cfs_srand() calls with add_device_randomness(). The only places that cfs_srand is called, the random bits are mixed with bits from get_random_bytes(). So it is equally effective to add entropy to either pool. So we can replace calls to cfs_srand() with calls that add the entropy with add_device_randomness(). That function adds time-based entropy, so we can discard the ktime_get_ts64 calls. One location in lustre_handles.c only adds time based entropy. This cannot improve the entropy provided by get_random_bytes(), so just discard that call. Linux-commit: 30f4236aafa81722490e74ded48a9fb2aff013ab Change-Id: If1a8ffad05fcc89272136949300f6512dca39704 Signed-off-by: NeilBrown Signed-off-by: Greg Kroah-Hartman Reviewed-on: https://review.whamcloud.com/34170 Reviewed-by: Andreas Dilger Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Ben Evans Reviewed-by: Oleg Drokin --- lnet/lnet/router.c | 20 ++++++-------------- lustre/llite/super25.c | 12 +++--------- lustre/obdclass/lustre_handles.c | 7 ------- 3 files changed, 9 insertions(+), 30 deletions(-) diff --git a/lnet/lnet/router.c b/lnet/lnet/router.c index c66f5a5..ddc9261 100644 --- a/lnet/lnet/router.c +++ b/lnet/lnet/router.c @@ -21,6 +21,8 @@ */ #define DEBUG_SUBSYSTEM S_LNET + +#include #include #define LNET_NRB_TINY_MIN 512 /* min value for each CPT */ @@ -261,27 +263,17 @@ lnet_find_rnet_locked(__u32 net) static void lnet_shuffle_seed(void) { static int seeded; - __u32 lnd_type; - __u32 seed[2]; - struct timespec64 ts; struct lnet_ni *ni = NULL; if (seeded) return; - cfs_get_random_bytes(seed, sizeof(seed)); - /* Nodes with small feet have little entropy - * the NID for this node gives the most entropy in the low bits */ - while ((ni = lnet_get_next_ni_locked(NULL, ni))) { - lnd_type = LNET_NETTYP(LNET_NIDNET(ni->ni_nid)); - - if (lnd_type != LOLND) - seed[0] ^= (LNET_NIDADDR(ni->ni_nid) | lnd_type); - } + * the NID for this node gives the most entropy in the low bits + */ + while ((ni = lnet_get_next_ni_locked(NULL, ni))) + add_device_randomness(&ni->ni_nid, sizeof(ni->ni_nid)); - ktime_get_ts64(&ts); - cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]); seeded = 1; return; } diff --git a/lustre/llite/super25.c b/lustre/llite/super25.c index f789033..bd38776 100644 --- a/lustre/llite/super25.c +++ b/lustre/llite/super25.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include "llite_internal.h" #include "vvp_internal.h" @@ -98,8 +99,7 @@ struct super_operations lustre_super_operations = static int __init lustre_init(void) { struct lnet_process_id lnet_id; - struct timespec64 ts; - int i, rc, seed[2]; + int i, rc; CLASSERT(sizeof(LUSTRE_VOLATILE_HDR) == LUSTRE_VOLATILE_HDR_LEN + 1); @@ -125,21 +125,15 @@ static int __init lustre_init(void) if (rc) GOTO(out_cache, rc); - cfs_get_random_bytes(seed, sizeof(seed)); - /* Nodes with small feet have little entropy. The NID for this * node gives the most entropy in the low bits. */ for (i = 0;; i++) { if (LNetGetId(i, &lnet_id) == -ENOENT) break; - if (LNET_NETTYP(LNET_NIDNET(lnet_id.nid)) != LOLND) - seed[0] ^= LNET_NIDADDR(lnet_id.nid); + add_device_randomness(&lnet_id.nid, sizeof(lnet_id.nid)); } - ktime_get_ts64(&ts); - cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]); - rc = vvp_global_init(); if (rc != 0) GOTO(out_tunables, rc); diff --git a/lustre/obdclass/lustre_handles.c b/lustre/obdclass/lustre_handles.c index 4161b2d..fabd20b 100644 --- a/lustre/obdclass/lustre_handles.c +++ b/lustre/obdclass/lustre_handles.c @@ -202,8 +202,6 @@ EXPORT_SYMBOL(class_handle_free_cb); int class_handle_init(void) { struct handle_bucket *bucket; - struct timespec64 ts; - int seed[2]; LASSERT(handle_hash == NULL); @@ -217,11 +215,6 @@ int class_handle_init(void) spin_lock_init(&bucket->lock); } - /** bug 21430: add randomness to the initial base */ - cfs_get_random_bytes(seed, sizeof(seed)); - ktime_get_ts64(&ts); - cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]); - cfs_get_random_bytes(&handle_base, sizeof(handle_base)); LASSERT(handle_base != 0ULL); -- 1.8.3.1