From owner-svn-src-head@FreeBSD.ORG Thu Jan 26 16:40:52 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C47EF106564A; Thu, 26 Jan 2012 16:40:52 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 94ED38FC17; Thu, 26 Jan 2012 16:40:52 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [96.47.65.170]) by cyrus.watson.org (Postfix) with ESMTPSA id 4B74146B37; Thu, 26 Jan 2012 11:40:52 -0500 (EST) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 9A019B940; Thu, 26 Jan 2012 11:40:51 -0500 (EST) From: John Baldwin To: Andrey Chernov Date: Thu, 26 Jan 2012 11:32:38 -0500 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p10; KDE/4.5.5; amd64; ; ) References: <20120126143819.GA88677@vniz.net> <20120126155626.GA92229@vniz.net> In-Reply-To: <20120126155626.GA92229@vniz.net> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201201261132.38320.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Thu, 26 Jan 2012 11:40:51 -0500 (EST) Cc: svn-src-head@freebsd.org, David Schultz , src-committers@freebsd.org, Mark Murray , svn-src-all@freebsd.org Subject: Re: svn commit: r230230 - head/sys/dev/random X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Jan 2012 16:40:52 -0000 On Thursday, January 26, 2012 10:56:27 am Andrey Chernov wrote: > > On Thu, Jan 26, 2012 at 08:39:07AM -0500, John Baldwin wrote: > > > atomic_cmpset_int(&iniseed_state, ARC4_ENTER_NONE, ARC4_ENTER_HAVE); > > > break; > > Updated version (I hope, final): > > --- sys/libkern.h.old 2012-01-16 07:15:12.000000000 +0400 > +++ sys/libkern.h 2012-01-26 19:38:06.000000000 +0400 > @@ -72,6 +72,8 @@ static __inline quad_t qabs(quad_t a) { > > /* Prototypes for non-quad routines. */ > struct malloc_type; > +enum arc4_is { ARC4_ENTR_NONE, ARC4_ENTR_HAVE, ARC4_ENTR_DONE }; > +extern volatile enum arc4_is arc4rand_iniseed_state; Atomics don't operate on enums. You'll need to make it an int and just use #define's for the 3 states. > uint32_t arc4random(void); > void arc4rand(void *ptr, u_int len, int reseed); > int bcmp(const void *, const void *, size_t); > --- dev/random/randomdev_soft.c.old 2011-03-02 01:42:19.000000000 +0300 > +++ dev/random/randomdev_soft.c 2012-01-26 19:35:12.000000000 +0400 > @@ -366,6 +366,8 @@ random_yarrow_unblock(void) > selwakeuppri(&random_systat.rsel, PUSER); > wakeup(&random_systat); > } > + (void)atomic_cmpset_int(&arc4rand_iniseed_state, > + ARC4_ENTR_NONE, ARC4_ENTR_HAVE); > } > > static int > --- libkern/arc4random.c.old 2008-08-08 01:51:09.000000000 +0400 > +++ libkern/arc4random.c 2012-01-26 19:43:31.000000000 +0400 > @@ -24,6 +24,7 @@ __FBSDID("$FreeBSD: src/sys/libkern/arc4 > #define ARC4_RESEED_SECONDS 300 > #define ARC4_KEYBYTES (256 / 8) > > +volatile enum arc4_is arc4rand_iniseed_state = ARC4_ENTR_NONE; > static u_int8_t arc4_i, arc4_j; > static int arc4_numruns = 0; > static u_int8_t arc4_sbox[256]; > @@ -130,7 +131,9 @@ arc4rand(void *ptr, u_int len, int resee > struct timeval tv; > > getmicrouptime(&tv); > - if (reseed || > + if (atomic_cmpset_int(&arc4rand_iniseed_state, > + ARC4_ENTR_HAVE, ARC4_ENTR_DONE) || > + reseed || > (arc4_numruns > ARC4_RESEED_BYTES) || > (tv.tv_sec > arc4_t_reseed)) > arc4_randomstir(); I think the rest of this is fine. -- John Baldwin