Whamcloud - gitweb
LU-9859 libcfs: replace cfs_srand() calls with add_device_randomness(). 70/34170/5
authorNeilBrown <neilb@suse.com>
Mon, 4 Feb 2019 17:54:41 +0000 (12:54 -0500)
committerOleg Drokin <green@whamcloud.com>
Mon, 18 Feb 2019 06:38:47 +0000 (06:38 +0000)
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 <neilb@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-on: https://review.whamcloud.com/34170
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Jenkins
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Ben Evans <bevans@cray.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/lnet/router.c
lustre/llite/super25.c
lustre/obdclass/lustre_handles.c

index c66f5a5..ddc9261 100644 (file)
@@ -21,6 +21,8 @@
  */
 
 #define DEBUG_SUBSYSTEM S_LNET
  */
 
 #define DEBUG_SUBSYSTEM S_LNET
+
+#include <linux/random.h>
 #include <lnet/lib-lnet.h>
 
 #define LNET_NRB_TINY_MIN      512     /* min value for each CPT */
 #include <lnet/lib-lnet.h>
 
 #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;
 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;
 
        struct lnet_ni *ni = NULL;
 
        if (seeded)
                return;
 
-       cfs_get_random_bytes(seed, sizeof(seed));
-
        /* Nodes with small feet have little entropy
        /* 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;
 }
        seeded = 1;
        return;
 }
index f789033..bd38776 100644 (file)
@@ -39,6 +39,7 @@
 #include <lustre_dlm.h>
 #include <linux/init.h>
 #include <linux/fs.h>
 #include <lustre_dlm.h>
 #include <linux/init.h>
 #include <linux/fs.h>
+#include <linux/random.h>
 #include <lprocfs_status.h>
 #include "llite_internal.h"
 #include "vvp_internal.h"
 #include <lprocfs_status.h>
 #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;
 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);
 
 
        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);
 
        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;
 
        /* 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);
        rc = vvp_global_init();
        if (rc != 0)
                GOTO(out_tunables, rc);
index 4161b2d..fabd20b 100644 (file)
@@ -202,8 +202,6 @@ EXPORT_SYMBOL(class_handle_free_cb);
 int class_handle_init(void)
 {
        struct handle_bucket *bucket;
 int class_handle_init(void)
 {
        struct handle_bucket *bucket;
-       struct timespec64 ts;
-       int seed[2];
 
        LASSERT(handle_hash == NULL);
 
 
        LASSERT(handle_hash == NULL);
 
@@ -217,11 +215,6 @@ int class_handle_init(void)
                spin_lock_init(&bucket->lock);
        }
 
                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);
 
        cfs_get_random_bytes(&handle_base, sizeof(handle_base));
        LASSERT(handle_base != 0ULL);