TSC is high enough resolution that we can use its low-order byte to stir new data into the random number generator entropy pool.
CC: Matt Mackall <m...@selenic.com> CC: "Venkatesh Pallipadi (Venki)" <ve...@google.com> CC: Thomas Gleixner <t...@linutronix.de> CC: Ingo Molnar <mi...@elte.hu> CC: John Stultz <johns...@us.ibm.com> CC: Herbert Xu <herb...@gondor.apana.org.au> CC: "David S. Miller" <da...@davemloft.net> Signed-off-by: Jarod Wilson <ja...@redhat.com> --- arch/x86/kernel/tsc.c | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 6cc6922..d206ec3 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -10,6 +10,7 @@ #include <linux/clocksource.h> #include <linux/percpu.h> #include <linux/timex.h> +#include <linux/random.h> #include <asm/hpet.h> #include <asm/timer.h> @@ -768,11 +769,28 @@ static void resume_tsc(struct clocksource *cs) clocksource_tsc.cycle_last = 0; } +static void tsc_add_entropy(void) +{ + static u64 last; + u64 counter; + int delta; + + rdtscll(counter); + delta = (int)(counter - last); + last = counter; + + if (delta == counter) + return; + + add_clocksource_randomness(delta); +} + static struct clocksource clocksource_tsc = { .name = "tsc", .rating = 300, .read = read_tsc, .resume = resume_tsc, + .entropy = tsc_add_entropy, .mask = CLOCKSOURCE_MASK(64), .flags = CLOCK_SOURCE_IS_CONTINUOUS | CLOCK_SOURCE_MUST_VERIFY, -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html