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>
*/
#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 */
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;
}
#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"
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);
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);
int class_handle_init(void)
{
struct handle_bucket *bucket;
- struct timespec64 ts;
- int seed[2];
LASSERT(handle_hash == NULL);
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);