linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: "Kees Cook" <keescook@chromium.org>,
	linux-kernel@vger.kernel.org, patches@lists.linux.dev,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"Thomas Bogendoerfer" <tsbogend@alpha.franken.de>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"Christoph Böhmwalder" <christoph.boehmwalder@linbit.com>,
	"Jani Nikula" <jani.nikula@linux.intel.com>,
	"Jason Gunthorpe" <jgg@nvidia.com>,
	"Sakari Ailus" <sakari.ailus@linux.intel.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	"Theodore Ts'o" <tytso@mit.edu>,
	"Andreas Dilger" <adilger.kernel@dilger.ca>,
	"Jaegeuk Kim" <jaegeuk@kernel.org>,
	"Richard Weinberger" <richard@nod.at>,
	"Darrick J . Wong" <djwong@kernel.org>,
	"SeongJae Park" <sj@kernel.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Helge Deller" <deller@gmx.de>,
	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
Date: Thu, 17 Nov 2022 10:32:40 +0000	[thread overview]
Message-ID: <Y3YNyJ8oeixYuvdI@shell.armlinux.org.uk> (raw)
In-Reply-To: <Y3WW2lOgoYLKQeve@zx2c4.com>

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!

  reply	other threads:[~2022-11-17 10:33 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-14 16:45 [PATCH v2 0/3] convert tree to get_random_u32_{below,above,between}() Jason A. Donenfeld
2022-11-14 16:45 ` [PATCH v2 2/3] treewide: use get_random_u32_{above,below}() instead of manual loop Jason A. Donenfeld
2022-11-14 16:45 ` [PATCH v2 3/3] treewide: use get_random_u32_between() when possible Jason A. Donenfeld
2022-11-16 22:43   ` Kees Cook
2022-11-16 23:55     ` Jason A. Donenfeld
2022-11-17  0:03       ` Jason A. Donenfeld
2022-11-17  0:31         ` Kees Cook
2022-11-17  0:43           ` Jason A. Donenfeld
2022-11-17  0:47             ` Kees Cook
2022-11-17 15:42               ` Theodore Ts'o
2022-11-17 16:19                 ` Jason A. Donenfeld
2022-11-17 22:15                 ` David Laight
2022-11-17  2:05       ` Jason A. Donenfeld
2022-11-17 10:32         ` Russell King (Oracle) [this message]
     [not found] ` <20221114164558.1180362-2-Jason@zx2c4.com>
2022-11-14 17:35   ` [PATCH v2 1/3] treewide: use get_random_u32_below() instead of deprecated function Russell King (Oracle)
2022-11-17 20:29 ` [PATCH v3 0/3] convert tree to get_random_u32_{below,above,inclusive}() Jason A. Donenfeld
2022-11-17 20:29   ` [PATCH v3 2/3] treewide: use get_random_u32_{above,below}() instead of manual loop Jason A. Donenfeld
2022-11-17 21:58     ` Kees Cook
2022-11-17 20:29   ` [PATCH v3 3/3] treewide: use get_random_u32_inclusive() when possible Jason A. Donenfeld
2022-11-17 21:57     ` Kees Cook
2022-11-17 22:10       ` Jason A. Donenfeld
     [not found]   ` <20221117202906.2312482-2-Jason@zx2c4.com>
2022-11-17 21:59     ` [PATCH v3 1/3] treewide: use get_random_u32_below() instead of deprecated function Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y3YNyJ8oeixYuvdI@shell.armlinux.org.uk \
    --to=linux@armlinux.org.uk \
    --cc=Jason@zx2c4.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=akpm@linux-foundation.org \
    --cc=catalin.marinas@arm.com \
    --cc=christoph.boehmwalder@linbit.com \
    --cc=deller@gmx.de \
    --cc=djwong@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hca@linux.ibm.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=jaegeuk@kernel.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=jgg@nvidia.com \
    --cc=keescook@chromium.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-parisc@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=loongarch@lists.linux.dev \
    --cc=martin.petersen@oracle.com \
    --cc=mpe@ellerman.id.au \
    --cc=netdev@vger.kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=richard@nod.at \
    --cc=sakari.ailus@linux.intel.com \
    --cc=sj@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tsbogend@alpha.franken.de \
    --cc=tytso@mit.edu \
    --cc=ydroneaud@opteya.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).