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 0BEA4C4332F for ; Thu, 17 Nov 2022 10:43:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5+4H2vY9C8bXNZnYZZBmWmGa4b3o+8ebKaCRePviGPA=; b=w/NatWPX3CbzBl +glVwHhzQBMoRF1/DS1wim/4PnaSD+69cR5UrEsJb2sVE9JYS/9O+oMzYadyrtXjYqFxxz0bc+AH7 THWrUFc4m/AVR3kT3xbGENUVrWsAPxDyA7RuZFfhZDkjUl/lg7UB1vlUBZ2oDPezt8Ufl/FtabvH0 VRAFy7Dxh2koGMtKEVSXEE3y3I/JWUq6OZnP/m60OCTzF0mG05CWsBDPSNHhVcDEtcgNK459+W/CM xyNWkzdaEtFDvbb+MJpTkYav5FOVTWQ9Y21HskdWcKLSYolq//fYx8vmleYltgUaYvE6FDmMnpyL4 /AImTJYoLOXp61rctg1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ovcLH-00ChTU-Ps; Thu, 17 Nov 2022 10:42:00 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ovcFZ-00CbiA-B1 for linux-arm-kernel@lists.infradead.org; Thu, 17 Nov 2022 10:36:09 +0000 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" Cc: Kees Cook , linux-kernel@vger.kernel.org, patches@lists.linux.dev, Greg Kroah-Hartman , Jakub Kicinski , Catalin Marinas , Thomas Bogendoerfer , Heiko Carstens , Herbert Xu , Christoph =?iso-8859-1?Q?B=F6hmwalder?= , Jani Nikula , Jason Gunthorpe , Sakari Ailus , "Martin K . Petersen" , Theodore Ts'o , Andreas Dilger , Jaegeuk Kim , Richard Weinberger , "Darrick J . Wong" , SeongJae Park , Thomas Gleixner , Andrew Morton , Michael Ellerman , Helge Deller , netdev@vger.kernel.org, linux-crypto@vger.kernel.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mmc@vger.kernel.org, linux-parisc@vger.kernel.org, ydroneaud@opteya.com 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-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221117_023605_414478_A9B8E1BE X-CRM114-Status: GOOD ( 15.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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! _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel