From: Jarod Wilson Subject: [PATCH 4/5] tsc: wire up entropy generation function Date: Mon, 13 Jun 2011 18:06:57 -0400 Message-ID: <1308002818-27802-5-git-send-email-jarod@redhat.com> References: <1308002818-27802-1-git-send-email-jarod@redhat.com> Cc: Jarod Wilson , Matt Mackall , "Venkatesh Pallipadi (Venki)" , Thomas Gleixner , Ingo Molnar , John Stultz , Herbert Xu , "David S. Miller" To: linux-crypto@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:42498 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754115Ab1FMWHo (ORCPT ); Mon, 13 Jun 2011 18:07:44 -0400 In-Reply-To: <1308002818-27802-1-git-send-email-jarod@redhat.com> Sender: linux-crypto-owner@vger.kernel.org List-ID: 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 CC: "Venkatesh Pallipadi (Venki)" CC: Thomas Gleixner CC: Ingo Molnar CC: John Stultz CC: Herbert Xu CC: "David S. Miller" Signed-off-by: Jarod Wilson --- 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 #include #include +#include #include #include @@ -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