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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 7BB77C433FE for ; Thu, 17 Nov 2022 10:36:36 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4NCbtp6m3Vz3dvK for ; Thu, 17 Nov 2022 21:36:34 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.a=rsa-sha256 header.s=pandora-2019 header.b=vf0GDy8l; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=armlinux.org.uk (client-ip=2001:4d48:ad52:32c8:5054:ff:fe00:142; helo=pandora.armlinux.org.uk; envelope-from=linux+linuxppc-dev=lists.ozlabs.org@armlinux.org.uk; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.a=rsa-sha256 header.s=pandora-2019 header.b=vf0GDy8l; dkim-atps=neutral Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4NCbsl0wB2z3bbB for ; Thu, 17 Nov 2022 21:35:34 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender: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-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=2BgNwLdh+HBA4xrzyykRGd8e3nHfE6jHoZjPyIO7tQ8=; b=vf0GDy8lKzIs95KZT9hTDN9bLB KkkakBOovK/EhU72ZwXcJFd6ZXnYeh5hWZFAO+QwAUy+Iil38BRQKWQA/ovqtD2R3k/zIRWUVleNY mI6EufB0EHT9QlEKH1MxQI8dlYgzNxWxQ/KJJ0HUSUpP7NgTBBgzbRiK7voh4pixtxFai3XdS+4CH KUkR3sQ10UY1J1DLrBw2+xk4ToBWEQq3GT1Ou599VPaU5ywBw9TAIVKjU75NdNZTSPprpMUx5CQP1 Y51nu+1iINv9JXk8aPYDqbEhMoPEahldPraSq7QM6Racs8sRYiTunUTXpT5cPjddHYjb4UQdEZEgF MxQo2C5A==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:35306) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ovcCQ-0004Iz-Pt; Thu, 17 Nov 2022 10:32:50 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1ovcCG-0006jE-Em; Thu, 17 Nov 2022 10:32:40 +0000 Date: Thu, 17 Nov 2022 10:32:40 +0000 From: "Russell King (Oracle)" To: "Jason A. Donenfeld" Subject: Re: [PATCH v2 3/3] treewide: use get_random_u32_between() when possible Message-ID: References: <20221114164558.1180362-1-Jason@zx2c4.com> <20221114164558.1180362-4-Jason@zx2c4.com> <202211161436.A45AD719A@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Darrick J . Wong" , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Andreas Dilger , ydroneaud@opteya.com, Herbert Xu , Richard Weinberger , Helge Deller , Jason Gunthorpe , Catalin Marinas , Jakub Kicinski , linux-mips@vger.kernel.org, linux-media@vger.kernel.org, Kees Cook , Heiko Carstens , Jani Nikula , linux-block@vger.kernel.org, SeongJae Park , loongarch@lists.linux.dev, Jaegeuk Kim , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, Thomas Bogendoerfer , Theodore Ts'o , linux-parisc@vger.kernel.org, "Martin K . Petersen" , Greg Kroah-Hartman , linux-mmc@vger.kernel.org, patches@l ists.linux.dev, Christoph =?iso-8859-1?Q?B=F6hmwalder?= , linux-crypto@vger.kernel.org, Sakari Ailus , linux-fsdevel@vger.kernel.org, Andrew Morton , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Thu, Nov 17, 2022 at 03:05:14AM +0100, Jason A. Donenfeld wrote: > On Thu, Nov 17, 2022 at 12:55:47AM +0100, Jason A. Donenfeld wrote: > > 1) How/whether to make f(0, UR2_MAX) safe, > > - without additional 64-bit arithmetic, > > - minimizing the number of branches. > > I have a few ideas I'll code golf for a bit. > > I think I can make progress with (1) alone by fiddling around with > > godbolt enough, like usual. > > The code gen is definitely worse. > > Original half-open interval: > > return floor + get_random_u32_below(ceil - floor); > > Suggested fully closed interval: > > ceil = ceil - floor + 1; > return likely(ceil) ? floor + get_random_u32_below(ceil) : get_random_u32(); How many of these uses are going to have ceil and floor as a variable? If they're constants (e.g. due to being in an inline function with constant arguments) then the compiler will optimise all of the above and the assembly code will just be either: 1. a call to get_random_u32() 2. a call to get_random_u32_below() and an addition. If one passes ceil or floor as a variable, then yes, the code gen is going to be as complicated as you suggest above. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!