From owner-freebsd-security@FreeBSD.ORG  Thu Sep 20 09:58:56 2012
Return-Path: <owner-freebsd-security@FreeBSD.ORG>
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?= <des@des.no>
To: Pawel Jakub Dawidek <pjd@FreeBSD.org>
References: <20120918211422.GA1400@garage.freebsd.pl>
	<A8FD98DD94774D00B4E5F78D3174C1B4@gmail.com>
	<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 <jonathan.anderson@cl.cam.ac.uk>
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\]"
	<freebsd-security.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-security>, 
	<mailto:freebsd-security-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-security>
List-Post: <mailto:freebsd-security@freebsd.org>
List-Help: <mailto:freebsd-security-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-security>, 
	<mailto:freebsd-security-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Thu, 20 Sep 2012 09:58:56 -0000

Pawel Jakub Dawidek <pjd@FreeBSD.org> 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