From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CB5E2103E2EA for ; Wed, 11 Mar 2026 22:29:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=RikSZ/qDz/BbXcsdorYocnARDwttAwV1n5wEGZVbyw4=; b=sJVsr/Zawhq1up6a/2KL5j7igp sT3HxHUXE7EKNm6HSkJgHwt62FMRuuqWPVotwoVOmhleKG5qoheIHXh5Sf43i9lEy4rlqsgQMls4y 2c2kPgcnofs0uP0P/ZyQd49BbG4ONkTLUXchAC/kmWAlkqmYXF6EvGXW+fMYLldNzCSXoNLUobsDM widkeLfDZ8PPMtrMHu7Hk8L7SZKFIAjmglXx4mrSWIqc4Fqj1T7/22NzHrfN+Gu/6WNHsCj72YO37 MM5WaHx16vj4IqAZ6z6AcxGo9O/MzKldDRqm/x1+NI59wVcw6YEG9wwo5XxIZw516ylel/WQ3qyOd O3fcW6lA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1w0S3o-0000000Cfyc-0ppt; Wed, 11 Mar 2026 22:29:48 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1w0S3m-0000000Cfxx-2Wnk; Wed, 11 Mar 2026 22:29:46 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 09C1160137; Wed, 11 Mar 2026 22:29:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BDE76C4CEF7; Wed, 11 Mar 2026 22:29:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773268184; bh=FgOgwczmQ2Bn8aQ6V7k6mV2cKfvqhgutLP2bKVPQV1Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XVPRVNpvrEBCZfWDW7blZ/upwHpfW8r44adFDbQ9bqeAbE8tC29oaEaQ8vjeQ+tPU mARZBZJPJk6kFf9lwAhvGI5tLCuVe7+kxaw2+PA6JC27+0GnVdnSnTLyyUBGR4Znih Lefvu2tkgKCMq9MOzDesAIoaw9j5jxb0bMeShkfuCzECCfCa7va+9Rr9WWMzBI4sLU yaVBgR/l4aivWBLEYBYBUfr1ZDHxJqaH8qoXXfscfY8+2H/qsRA/Z+s3gZNwp/2o4c 9dpn+BpceXOQVRRjDdqUqLKCA1GjUs5fm7wevN7gzXqGXlu5b/ClrM3m7JL3NeMrNJ XLRZxZaMD4nlg== Date: Wed, 11 Mar 2026 15:29:35 -0700 From: Eric Biggers To: Christoph Hellwig Cc: Andrew Morton , Richard Henderson , Matt Turner , Magnus Lindholm , Russell King , Catalin Marinas , Will Deacon , Huacai Chen , WANG Xuerui , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , "David S. Miller" , Andreas Larsson , Richard Weinberger , Anton Ivanov , Johannes Berg , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Herbert Xu , Dan Williams , Chris Mason , David Sterba , Arnd Bergmann , Song Liu , Yu Kuai , Li Nan , Theodore Ts'o , "Jason A. Donenfeld" , linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, linux-crypto@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-arch@vger.kernel.org, linux-raid@vger.kernel.org Subject: Re: [PATCH 26/27] random: factor out a __limit_random_u32_below helper Message-ID: <20260311222935.GA3161@quark> References: <20260311070416.972667-1-hch@lst.de> <20260311070416.972667-27-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260311070416.972667-27-hch@lst.de> X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+linux-um=archiver.kernel.org@lists.infradead.org On Wed, Mar 11, 2026 at 08:03:58AM +0100, Christoph Hellwig wrote: > Factor out the guts of __get_random_u32_below into a new helper, > so that callers with their own prng state can reuse this code. > > Signed-off-by: Christoph Hellwig I think I'd prefer that the test just uses the mod operation instead, like many of the existing tests do: prandom_u32_state(&rng) % ceil Yes, when ceil isn't a power of 2 the result isn't uniformly distributed. But that's perfectly fine for these tests, especially with the values of ceil being used being far smaller than U32_MAX. There's been an effort to keep the cryptographic random number generator (drivers/char/random.c and include/linux/random.h) separate from the non-cryptographic random number generator (lib/random32.c and include/linux/prandom.h). This patch feels like it's going in a slightly wrong direction, where random.c gains a function that's used with both cryptographic and non-cryptographic random numbers. And if someone actually needs a fully unform distribution, then they'd probably want cryptographic random numbers as well. So I'm not sure the proposed combination of "fully uniform non-cryptographic random numbers" makes much sense. Plus the '% ceil' implementation is much easier to understand. - Eric