lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <olt5s7scbosagj4fpq25xun4kdvi6puwqdocgsvhpzguvpt7jt@dyy37p4uturh>
Date: Sat, 15 Mar 2025 14:20:46 -0400
From: Kent Overstreet <kent.overstreet@...ux.dev>
To: David Laight <david.laight.linux@...il.com>
Cc: linux-kernel@...r.kernel.org, Theodore Ts'o <tytso@....edu>, 
	"Jason A. Donenfeld" <Jason@...c4.com>
Subject: Re: [PATCH] random: get_random_u64_below()

On Sat, Mar 15, 2025 at 01:52:34PM +0000, David Laight wrote:
> On Thu, 13 Mar 2025 12:38:10 -0400
> Kent Overstreet <kent.overstreet@...ux.dev> wrote:
> 
> > bcachefs needs this, for sampling devices to read from based on squared
> > device latencies.
> > 
> > this uses the same algorithm as get_random_u32_below: since the multiply
> > uses the top and bottom halves separately, it works out fairly well.
> 
> Adding two separate copies of much the same code is silly.
> Given what the code is doing, does it ever make any sense to inline it.
> 
> Inlining the original get_random_u32_below(ceil) that did
> 	(random_u32() * ((1ull << 32) / ceil) >> 32
> (for constant ceil) made sense.
> While good enough for most purposes it was replaced by the much more
> expensive function that guarantees that all the output values are
> equally likely - rather than just evenly distributed.

Expensive!? It adds a multiply.

That % gets constant folded, in the inlined case, and in the non-inline
case it's hit only a small fraction of the, time, for typical ceil.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ