From owner-freebsd-security@FreeBSD.ORG Thu Sep 20 09:58:56 2012 Return-Path: Delivered-To: freebsd-security@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 79ADF106564A; Thu, 20 Sep 2012 09:58:56 +0000 (UTC) (envelope-from des@des.no) Received: from smtp.des.no (smtp.des.no [194.63.250.102]) by mx1.freebsd.org (Postfix) with ESMTP id 395E98FC0A; Thu, 20 Sep 2012 09:58:55 +0000 (UTC) Received: from ds4.des.no (smtp.des.no [194.63.250.102]) by smtp.des.no (Postfix) with ESMTP id 38B79623E; Thu, 20 Sep 2012 11:58:55 +0200 (CEST) Received: by ds4.des.no (Postfix, from userid 1001) id 0D9838700; Thu, 20 Sep 2012 11:58:54 +0200 (CEST) From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= To: Pawel Jakub Dawidek References: <20120918211422.GA1400@garage.freebsd.pl> <20120919192923.GA1416@garage.freebsd.pl> Date: Thu, 20 Sep 2012 11:58:54 +0200 In-Reply-To: <20120919192923.GA1416@garage.freebsd.pl> (Pawel Jakub Dawidek's message of "Wed, 19 Sep 2012 21:29:24 +0200") Message-ID: <86boh1t3q9.fsf@ds4.des.no> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: freebsd-security@freebsd.org, Jonathan Anderson Subject: Re: Collecting entropy from device_attach() times. X-BeenThere: freebsd-security@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Security issues \[members-only posting\]" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Sep 2012 09:58:56 -0000 Pawel Jakub Dawidek writes: > http://people.freebsd.org/~pjd/patches/harvest_device_attach.2.patch You can replace highbit(x) - 9 with flsll(x) - 10. Unfortunately, we don't have flsll() in the kernel, but here's a simple implementation: /* * Find last bit set in an unsigned long long. Assumes that ULL is * always 64 bits wide while UL may be either 32 or 64 bits wide. */ static __inline unsigned int flsll(unsigned long long mask) { #ifdef __LP64__ return (flsl(mask)); #else return (mask >> 32 ? 32 + flsl(mask >> 32) : flsl(mask)); #endif } On i386 and amd64, flsl() is an inline function that expands to a single assembler instruction. On all other platforms, it is a function in libkern, which is stupid - gcc and clang have builtin functions for it which are almost certainly faster than a function call. Same goes for s/last bit/first bit/; s/fls/ffs/g. DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no