From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8E65382294 for ; Thu, 12 Mar 2026 08:38:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773304745; cv=none; b=e5JeaTnP5bzRy15cB/vnW/4wMx0vo8882ejEWOJUq64t+Qo8Uw7QjW2bSMCkufeKizwK6W2Ul5mc99zYJDlI98vmVAuRkWV3283MV0ojJp2LX1OuLnRl7ay8UGd6oEG5HL2RleYe+6aknCxwozjCoYwQfkmOpVkeUw0NJMcgd7E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773304745; c=relaxed/simple; bh=2rASbAMEw5ZRlubXhkcWPIGmcIGEBmzjA5ymOU3qhqE=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jII+XQg0gGQU6XLI2QXgiQZwsIa7FZjczccBduyV4iVvAJ+fAd5jspzE0gtsqltoGIIP9mSSK2teWhXwMM8lQAjbR4KJrSVDBjIZJkG2SyPXudC2FLjRxbphSTCChzFybTUIh07P+4bwakwz95s2sQaKZH2oJbw0AUohfZi7e/E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Wj+rWY6m; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Wj+rWY6m" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4852f8ac7e9so8188345e9.1 for ; Thu, 12 Mar 2026 01:38:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773304736; x=1773909536; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=tXrAFYR5bIhSumOFjuc1G0swOeqj6K0Pq1d0oWdhjWU=; b=Wj+rWY6m6+UCfo2x6AIjTqdw9g4ImHxiulaT1RQNuBOH7Wi+or6HuP175SMxDPofb/ 0376Rddavr2FkBzhUM+dzwRfAtr2UHVpIHWK9TPE6PQsJVgW4HCASac/7ZOSZ9Ou5ano 16E3zcEXnQ0/A2y27KVdOIADss3J/fB3GsjHarBVmVx9BCxOh1aWg5dMH5Enxd/Nb46W 9AglMk8NL68i2W2cAncjuexUGaJ3jPDvt4O4XdErAcXqflOZ16c6cxTL3c3uCUoxDSXb 971dm2O+mnDzK7t4q2fa1HFxJZ+rEQUnpR9uFoZKu5H1hiA6V6UPe1KtLFSnN3N5tGah XJZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773304736; x=1773909536; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=tXrAFYR5bIhSumOFjuc1G0swOeqj6K0Pq1d0oWdhjWU=; b=jyPBTUdgfBLSKOAA8D6k/Qn4uam4k0QJdu7HCKrgGrA1Su7JTPEI9bBqyIzuLEmJxu qRi7YqGaBAkEHUTwtNlkCV0clgk/3DzhRgdp5yLYDdOhhxx0HcTfO+tz3c2FIXsDebjR LCfyPHmcYcxSLyMHnX1BVkBmHNZuyrKP/UdshaIbAOMWDjZtZ2fcp7/PjlwEype1jHhT rAfalwgAw11qLQwg/iuvfZ0rPOUeOn0XQmPQ2kKge23b/O5ZBMa6ZKrvyaZRXuwZL3SQ oB/vVElPcggczHe680oUpviGT/C+hpcLrqlYVALIizSNJm3WP7iDLNMV7iyycf04Ayhr 7khA== X-Forwarded-Encrypted: i=1; AJvYcCXFPXvDUn+8zHf2k3eIhTsM2EUp1vbbKsaDWz7aB5zjOwCMwBpGf0YGgHchOx2ggRwHUbdiCUO2xlVV@vger.kernel.org X-Gm-Message-State: AOJu0YzXOdMgn0SPcaJ5VRckU73oTS2l9nAO3taE837Ge6JWUZTrqzJk Pl0LfXWYV5R7Lj+PAad6d+xc23w2c332Tg66AGEoIp6gG5ElO756vYWb X-Gm-Gg: ATEYQzyoUFFXbZS8DpIMSvQOSWasdeZwo/vRvxoVFjbaqPVzqXB1gwiyiMt5TnBBbzP PXZNcVzHQURoCGV4E80ZPsZHrssGp1Vp0SGzW/bb0iLI4s9RDxg6Ez84KAVWlAiXnWQTEZC7lXf GraYL0H1KMkSHy9dpjvuUqigGYtbawoSVAq0WunZj6Fz/LkCvP4G615bmV3jfXDWQHsxNDAYf3N Ci+w1WNnn5W4AK3pNKI7Heb/gK3w40/jF+F/HA0unPsvK3cDfyllodhXXH13N5ElaEO8DZzapTP LogyiYZ02AvaDtQ/n/tVwxjcwK2IHDVLlXxB8jdpgS20dvZ3cx5OYQKf4bKSLpa91sQ8lBFXr9R 3v6U9DVGc9ugMFyRu5JG+v6DqhjpenbSC7bYaIK/CA4MeCvfCptY6gLbdMQeRtyC9zShIjysHOl 42TK3IJxM8nA7g1fUiYcmw6o9qLpkT/Q/H25JtV0+mYorg19/OGyRpass08S9m+g/K X-Received: by 2002:a05:600c:3551:b0:477:7b16:5fb1 with SMTP id 5b1f17b1804b1-4854b0cbe81mr96719315e9.7.1773304735965; Thu, 12 Mar 2026 01:38:55 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4854b5f6bb4sm111774365e9.4.2026.03.12.01.38.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2026 01:38:55 -0700 (PDT) Date: Thu, 12 Mar 2026 08:38:53 +0000 From: David Laight To: Eric Biggers Cc: Christoph Hellwig , 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: <20260312083853.01dc18d3@pumpkin> In-Reply-To: <20260311222935.GA3161@quark> References: <20260311070416.972667-1-hch@lst.de> <20260311070416.972667-27-hch@lst.de> <20260311222935.GA3161@quark> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-arch@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 11 Mar 2026 15:29:35 -0700 Eric Biggers wrote: > 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 Or possibly what the old code used: (prandom_u32_state(&rnd) * (u64)ceil) >> 32 Which distributes the values evenly across the range although some values happen 1 more time than others. I suspect that is good enough for a lot of the users of the cryptographic random number generator as well. David > > 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 >