public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: Borislav Petkov <bp@suse.de>
Cc: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org,
	x86@kernel.org, Will Deacon <will@kernel.org>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"H . Peter Anvin" <hpa@zytor.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Heiko Carstens <hca@linux.ibm.com>,
	Johannes Berg <johannes@sipsolutions.net>,
	Mark Rutland <mark.rutland@arm.com>,
	Harald Freudenberger <freude@linux.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>
Subject: Re: [PATCH v3] random: handle archrandom with multiple longs
Date: Mon, 25 Jul 2022 11:26:27 +0200	[thread overview]
Message-ID: <Yt5hwxC1xgvA8Asw@zx2c4.com> (raw)
In-Reply-To: <Yt5gBZe9F1BE0MVF@zn.tnic>

Hi Boris,

On Mon, Jul 25, 2022 at 11:19:01AM +0200, Borislav Petkov wrote:
> On Tue, Jul 19, 2022 at 03:02:07PM +0200, Jason A. Donenfeld wrote:
> > Since callers need to check this return value and loop anyway, each arch
> > implementation does not bother implementing its own loop to try again to
> > fill the maximum number of longs. Additionally, all existing callers
> > pass in a constant max_longs parameter.
> 
> Hmm, maybe this has come up already but it reads weird.
> 
> If I have a function arch_get_random_longs(), I'd expect it to give me
> the number of longs I requested or say, error.
> 
> Why do the callers need to loop?
> 
> If I have to loop, I'd call the "get me one long" function and loop N
> times.

Answered partially in the commit message you quoted and partially here:
https://lore.kernel.org/lkml/YtqIbrds53EuyqPE@zx2c4.com/

Note that arch_get_random_longs() is not a general purpose function. For
that there used to be get_random_bytes_arch(), but that no longer exists
as people shouldn't be using this stuff directly. arch_get_random_longs()
is a special purpose function mainly intended for use by the RNG itself.

More directly, the reason we don't want to error is because the use case
has fallbacks meant to handle errors. The cascade looks like this
(quoting from the other email):

    unsigned long array[whatever];
    for (i = 0; i < ARRAY_SIZE(array);) {
        longs = arch_get_random_seed_longs(&array[i], ARRAY_SIZE(array) - i);
        if (longs) {
            i += longs;
            continue;
        }
        longs = arch_get_random_longs(&array[i], ARRAY_SIZE(array) - i);
        if (longs) {
            i += longs;
            continue;
        }
        array[i++] = random_get_entropy();
    }

It tries to get the best that it can as much as it can, but isn't going
to block or do anything too nuts for that.

Anyway, from an x86 perspective, I can't imagine you object to this
change, right? Codegen is the same.

Jason

  reply	other threads:[~2022-07-25  9:26 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <YtP1+MJ1tNdJA60l@zx2c4.com>
2022-07-17 20:03 ` [PATCH v2] random: handle archrandom in plural words Jason A. Donenfeld
2022-07-18  6:31   ` Michael Ellerman
2022-07-18  6:46     ` Gabriel Paubert
2022-07-20  3:03       ` Michael Ellerman
2022-07-19 12:42   ` Mark Rutland
2022-07-19 12:46     ` Jason A. Donenfeld
2022-07-19 13:02       ` [PATCH v3] random: handle archrandom with multiple longs Jason A. Donenfeld
2022-07-19 13:17         ` Mark Rutland
2022-07-19 13:48         ` Catalin Marinas
2022-07-22 12:06         ` Heiko Carstens
2022-07-25  9:19         ` Borislav Petkov
2022-07-25  9:26           ` Jason A. Donenfeld [this message]
2022-07-25  9:36             ` David Laight
2022-07-25  9:37               ` Jason A. Donenfeld
2022-07-25 11:25         ` Borislav Petkov
2022-08-01 14:46         ` Harald Freudenberger
2022-08-01 14:50           ` Jason A. Donenfeld
2022-07-22  8:08   ` [PATCH v2] random: handle archrandom in plural words Holger Dengler
2022-07-22 11:22     ` Jason A. Donenfeld
2022-08-03 12:01       ` Holger Dengler

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=Yt5hwxC1xgvA8Asw@zx2c4.com \
    --to=jason@zx2c4.com \
    --cc=agordeev@linux.ibm.com \
    --cc=bp@suse.de \
    --cc=catalin.marinas@arm.com \
    --cc=freude@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=hpa@zytor.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mark.rutland@arm.com \
    --cc=mpe@ellerman.id.au \
    --cc=tglx@linutronix.de \
    --cc=will@kernel.org \
    --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