From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751389AbdHONsi (ORCPT ); Tue, 15 Aug 2017 09:48:38 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:53321 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750827AbdHONsh (ORCPT ); Tue, 15 Aug 2017 09:48:37 -0400 Date: Tue, 15 Aug 2017 15:48:18 +0200 (CEST) From: Thomas Gleixner To: Borislav Petkov cc: Ingo Molnar , Willy Tarreau , "Theodore Ts'o" , Linus Torvalds , x86-ml , "Jason A. Donenfeld" , lkml , Peter Zijlstra , Nicholas Mc Guire Subject: Re: early x86 unseeded randomness In-Reply-To: <20170815134514.r6qjotjgfmurwh64@pd.tnic> Message-ID: References: <20170814173515.n3vcpz37xh33ayuq@pd.tnic> <20170814180048.m3igiaiunlyb5wur@pd.tnic> <20170814190013.zixopgjyq26ukxcj@pd.tnic> <20170815013124.2afytkibspxrikdn@thunk.org> <20170815064437.GA1986@1wt.eu> <20170815074254.6byayhspc5tdtjb5@gmail.com> <20170815134514.r6qjotjgfmurwh64@pd.tnic> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 15 Aug 2017, Borislav Petkov wrote: > On Tue, Aug 15, 2017 at 12:47:36PM +0200, Thomas Gleixner wrote: > > 8<------------------- > > > > --- a/arch/x86/kernel/tsc.c > > +++ b/arch/x86/kernel/tsc.c > > @@ -1360,3 +1360,19 @@ unsigned long calibrate_delay_is_known(v > > return 0; > > } > > #endif > > + > > +u64 __init tsc_early_random(void) > > +{ > > + u64 uninitialized_var(res); > > + int i; > > + > > + if (!boot_cpu_has(X86_FEATURE_TSC)) > > + return res; > > + > > + res ^= rdtsc(); > > + for (i = 0; i < BITS_PER_LONG; i++) { > > + res ^= ((rdtsc() & 0x04) >> 2) << i; > > + udelay(2); > > + } > > + return res; > > +} > > Something like this is exactly what I was aiming at with my dumb patch. > We could use this for early boot randomness on x86. > > Should I turn it into proper patches or you want to? Go ahead. What you actually want to do is to replace boot_cpu_has() with a real cpuid() check because boot_cpu_has() is not initialized on real early boot. Thanks, tglx