Merge tag 'random_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso...
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 10 Oct 2013 19:31:43 +0000 (12:31 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 10 Oct 2013 19:31:43 +0000 (12:31 -0700)
Pull /dev/random changes from Ted Ts'o:
 "These patches are designed to enable improvements to /dev/random for
  non-x86 platforms, in particular MIPS and ARM"

* tag 'random_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/random:
  random: allow architectures to optionally define random_get_entropy()
  random: run random_int_secret_init() run after all late_initcalls

1  2 
drivers/char/random.c
include/linux/timex.h
init/main.c

diff --combined drivers/char/random.c
  #include <linux/fips.h>
  #include <linux/ptrace.h>
  #include <linux/kmemcheck.h>
 -
 -#ifdef CONFIG_GENERIC_HARDIRQS
 -# include <linux/irq.h>
 -#endif
 +#include <linux/irq.h>
  
  #include <asm/processor.h>
  #include <asm/uaccess.h>
@@@ -640,7 -643,7 +640,7 @@@ struct timer_rand_state 
   */
  void add_device_randomness(const void *buf, unsigned int size)
  {
-       unsigned long time = get_cycles() ^ jiffies;
+       unsigned long time = random_get_entropy() ^ jiffies;
  
        mix_pool_bytes(&input_pool, buf, size, NULL);
        mix_pool_bytes(&input_pool, &time, sizeof(time), NULL);
@@@ -677,7 -680,7 +677,7 @@@ static void add_timer_randomness(struc
                goto out;
  
        sample.jiffies = jiffies;
-       sample.cycles = get_cycles();
+       sample.cycles = random_get_entropy();
        sample.num = num;
        mix_pool_bytes(&input_pool, &sample, sizeof(sample), NULL);
  
@@@ -744,7 -747,7 +744,7 @@@ void add_interrupt_randomness(int irq, 
        struct fast_pool        *fast_pool = &__get_cpu_var(irq_randomness);
        struct pt_regs          *regs = get_irq_regs();
        unsigned long           now = jiffies;
-       __u32                   input[4], cycles = get_cycles();
+       __u32                   input[4], cycles = random_get_entropy();
  
        input[0] = cycles ^ jiffies;
        input[1] = irq;
@@@ -1459,12 -1462,11 +1459,11 @@@ struct ctl_table random_table[] = 
  
  static u32 random_int_secret[MD5_MESSAGE_BYTES / 4] ____cacheline_aligned;
  
static int __init random_int_secret_init(void)
int random_int_secret_init(void)
  {
        get_random_bytes(random_int_secret, sizeof(random_int_secret));
        return 0;
  }
- late_initcall(random_int_secret_init);
  
  /*
   * Get a random word for internal kernel use only. Similar to urandom but
@@@ -1483,7 -1485,7 +1482,7 @@@ unsigned int get_random_int(void
  
        hash = get_cpu_var(get_random_int_hash);
  
-       hash[0] += current->pid + jiffies + get_cycles();
+       hash[0] += current->pid + jiffies + random_get_entropy();
        md5_transform(hash, random_int_secret);
        ret = hash[0];
        put_cpu_var(get_random_int_hash);
diff --combined include/linux/timex.h
  
  #include <asm/timex.h>
  
+ #ifndef random_get_entropy
+ /*
+  * The random_get_entropy() function is used by the /dev/random driver
+  * in order to extract entropy via the relative unpredictability of
+  * when an interrupt takes places versus a high speed, fine-grained
+  * timing source or cycle counter.  Since it will be occurred on every
+  * single interrupt, it must have a very low cost/overhead.
+  *
+  * By default we use get_cycles() for this purpose, but individual
+  * architectures may override this in their asm/timex.h header file.
+  */
+ #define random_get_entropy()  get_cycles()
+ #endif
  /*
   * SHIFT_PLL is used as a dampening factor to define how much we
   * adjust the frequency correction for a given offset in PLL mode.
@@@ -141,7 -155,6 +155,7 @@@ extern int do_adjtimex(struct timex *)
  extern void hardpps(const struct timespec *, const struct timespec *);
  
  int read_current_timer(unsigned long *timer_val);
 +void ntp_notify_cmos_timer(void);
  
  /* The clock frequency of the i8253/i8254 PIT */
  #define PIT_TICK_RATE 1193182ul
diff --combined init/main.c
@@@ -75,7 -75,7 +75,8 @@@
  #include <linux/blkdev.h>
  #include <linux/elevator.h>
  #include <linux/sched_clock.h>
 +#include <linux/context_tracking.h>
+ #include <linux/random.h>
  
  #include <asm/io.h>
  #include <asm/bugs.h>
@@@ -546,7 -546,6 +547,7 @@@ asmlinkage void __init start_kernel(voi
        idr_init_cache();
        rcu_init();
        tick_nohz_init();
 +      context_tracking_init();
        radix_tree_init();
        /* init some links before init_ISA_irqs() */
        early_irq_init();
@@@ -780,6 -779,7 +781,7 @@@ static void __init do_basic_setup(void
        do_ctors();
        usermodehelper_enable();
        do_initcalls();
+       random_int_secret_init();
  }
  
  static void __init do_pre_smp_initcalls(void)