From: David Laight <David.Laight@ACULAB.COM>
To: "'Jason A. Donenfeld'" <Jason@zx2c4.com>,
Kees Cook <keescook@chromium.org>
Cc: "linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>,
"Ulf Hansson" <ulf.hansson@linaro.org>,
"x86@kernel.org" <x86@kernel.org>, "Jan Kara" <jack@suse.cz>,
"Vignesh Raghavendra" <vigneshr@ti.com>,
"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
"Peter Zijlstra" <peterz@infradead.org>,
"Catalin Marinas" <catalin.marinas@arm.com>,
"Dave Hansen" <dave.hansen@linux.intel.com>,
"kernel-janitors@vger.kernel.org"
<kernel-janitors@vger.kernel.org>,
"KP Singh" <kpsingh@kernel.org>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>,
"patches@lists.linux.dev" <patches@lists.linux.dev>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"Eric Dumazet" <edumazet@google.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>,
"kasan-dev@googlegroups.com" <kasan-dev@googlegroups.com>,
"H . Peter Anvin" <hpa@zytor.com>,
"Andreas Noever" <andreas.noever@gmail.com>,
"WANG Xuerui" <kernel@xen0n.name>, "Will Deacon" <will@ker>
Subject: RE: [PATCH v3 3/5] treewide: use get_random_u32() when possible
Date: Sat, 8 Oct 2022 21:53:33 +0000 [thread overview]
Message-ID: <69080fb8cace486db4e28e2e90f1d550@AcuMS.aculab.com> (raw)
In-Reply-To: <Y0BoQmVauPLC2uW5@zx2c4.com>
From: Jason A. Donenfeld
> Sent: 07 October 2022 18:56
...
> > Given these kinds of less mechanical changes, it may make sense to split
> > these from the "trivial" conversions in a treewide patch. The chance of
> > needing a revert from the simple 1:1 conversions is much lower than the
> > need to revert by-hand changes.
> >
> > The Cocci script I suggested in my v1 review gets 80% of the first
> > patch, for example.
>
> I'll split things up into a mechanical step and a non-mechanical step.
> Good idea.
I'd also do something about the 'get_random_int() & 3' cases.
(ie remainder by 2^n-1)
These can be converted to 'get_random_u8() & 3' (etc).
So they only need one random byte (not 4) and no multiply.
Possibly something based on (the quickly typed, and not C):
#define get_random_below(val) [
if (builtin_constant(val))
BUILD_BUG_ON(!val || val > 0x100000000ull)
if (!(val & (val - 1)) {
if (val <= 0x100)
return get_random_u8() & (val - 1);
if (val <= 0x10000)
return get_random_u16() & (val - 1);
return get_random_u32() & (val - 1);
}
}
BUILD_BUG_ON(sizeof (val) > 4);
return ((u64)get_random_u32() * val) >> 32;
}
get_random_below() is a much better name than prandom_u32_max().
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2022-10-08 21:57 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-06 16:53 [PATCH v3 0/5] treewide cleanup of random integer usage Jason A. Donenfeld
2022-10-06 16:53 ` [PATCH v3 1/5] treewide: use prandom_u32_max() when possible Jason A. Donenfeld
2022-10-06 16:53 ` [PATCH v3 2/5] treewide: use get_random_{u8,u16}() " Jason A. Donenfeld
2022-10-06 16:53 ` [PATCH v3 3/5] treewide: use get_random_u32() " Jason A. Donenfeld
2022-10-06 17:21 ` Christophe Leroy
2022-10-06 17:24 ` Jason A. Donenfeld
2022-10-06 17:31 ` Christophe Leroy
2022-10-06 17:42 ` Christophe Leroy
2022-10-06 23:36 ` Jason A. Donenfeld
2022-10-07 4:57 ` Christophe Leroy
2022-10-07 14:07 ` Jason A. Donenfeld
2022-10-07 17:12 ` Kees Cook
2022-10-07 17:56 ` Jason A. Donenfeld
2022-10-08 21:53 ` David Laight [this message]
2022-10-09 2:57 ` Jason A. Donenfeld
2022-10-07 9:14 ` David Laight
2022-10-07 9:26 ` Mika Westerberg
2022-10-06 16:53 ` [PATCH v3 4/5] treewide: use get_random_bytes " Jason A. Donenfeld
2022-10-06 17:22 ` Christophe Leroy
2022-10-07 3:09 ` Bagas Sanjaya
2022-10-07 3:23 ` Jason A. Donenfeld
2022-10-06 16:53 ` [PATCH v3 5/5] prandom: remove unused functions Jason A. Donenfeld
2022-10-07 9:11 ` [PATCH v3 0/5] treewide cleanup of random integer usage Ulf Hansson
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=69080fb8cace486db4e28e2e90f1d550@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=Jason@zx2c4.com \
--cc=andreas.noever@gmail.com \
--cc=catalin.marinas@arm.com \
--cc=dave.hansen@linux.intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=edumazet@google.com \
--cc=hpa@zytor.com \
--cc=jack@suse.cz \
--cc=kasan-dev@googlegroups.com \
--cc=keescook@chromium.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=kernel@xen0n.name \
--cc=kpsingh@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-wireless@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=patches@lists.linux.dev \
--cc=peterz@infradead.org \
--cc=ulf.hansson@linaro.org \
--cc=vigneshr@ti.com \
--cc=will@ker \
--cc=x86@kernel.org \
/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).