From: Holger Dengler <dengler@linux.ibm.com>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: Harald Freudenberger <freude@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Juergen Christ <jchrist@linux.ibm.com>,
linux-crypto@vger.kernel.org, linux-s390@vger.kernel.org
Subject: Re: [PATCH v1 1/1] s390/arch_random: Buffer true random data
Date: Tue, 5 Jul 2022 19:47:37 +0200 [thread overview]
Message-ID: <30e681b2-a411-cdb1-4b46-243db25abeef@linux.ibm.com> (raw)
In-Reply-To: <YsRoXObdpCNbtpHS@zx2c4.com>
Hi Jason,
On 05/07/2022 18:35, Jason A. Donenfeld wrote:
> Hi Holger,
>
> On Tue, Jul 05, 2022 at 06:27:59PM +0200, Holger Dengler wrote:
>> I saw a few calls in interrupt context during my tracing, but I didn't
>> look to see which ones they were. Let me figure that out in the next
>> few days and provide more information on that.
>
> One thing to keep in mind is that it's used at boot time, when
> technically IRQs are turned off, so it appears like interrupt context
> depending on which way you squint. But boot time obviously isn't a
> problem. So be sure that's not the usage you're seeing.
Ok, let me check this. I will also think about the tree-wide cleanup you mentioned in an earlier mail. It looks, that s390 could fill the block.rdseed with a single call.
>> For the moment, I would propose to drop the buffering but also return
>> false, if arch_random_get_seed_long() is called in interrupt context.
>
> As a last ditch, maybe that's best. Maybe... Do you know off hand how
> many cycles each call takes?
I don't know the exact number of cycles, but as I mentioned in the coverletter, the trng instruction is one of the specialties of the s390 platform. It looks like an instruction, but it is some kind of firmware executed (it is called millicode). These kind of long-running instructions are also interruptable and can resume.
A trng call runs for minimal ~20-190us for 32 bytes. 20us on newer machine generations, 190us on older ones. These are not 100% exact measurements, but the dimension should be correct.
>
>> diff --git a/arch/s390/include/asm/archrandom.h b/arch/s390/include/asm/archrandom.h
>> index 2c6e1c6ecbe7..711357bdc464 100644
>> --- a/arch/s390/include/asm/archrandom.h
>> +++ b/arch/s390/include/asm/archrandom.h
>> @@ -32,7 +32,8 @@ static inline bool __must_check arch_get_random_int(unsigned int *v)
>>
>> static inline bool __must_check arch_get_random_seed_long(unsigned long *v)
>> {
>> - if (static_branch_likely(&s390_arch_random_available)) {
>> + if (static_branch_likely(&s390_arch_random_available) &&
>> + !in_interrupt()) {
>
> in_interrupt() is deprecated. You want in_hardirq() here. You'll also
> want to verify that this doesn't prevent random_init() from working.
>
> Jason
--
Mit freundlichen Grüßen / Kind regards
Holger Dengler
--
IBM Systems, Linux on IBM Z Development
dengler@linux.ibm.com
next prev parent reply other threads:[~2022-07-05 17:47 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-05 11:27 [PATCH v1 0/1] s390/archrandom: use buffered random data Holger Dengler
2022-07-05 11:27 ` [PATCH v1 1/1] s390/arch_random: Buffer true " Holger Dengler
2022-07-05 13:18 ` Jason A. Donenfeld
2022-07-05 13:42 ` Jason A. Donenfeld
2022-07-05 14:58 ` Holger Dengler
2022-07-05 15:11 ` Jason A. Donenfeld
2022-07-05 16:27 ` Holger Dengler
2022-07-05 16:35 ` Jason A. Donenfeld
2022-07-05 17:47 ` Holger Dengler [this message]
2022-07-05 18:19 ` Jason A. Donenfeld
2022-07-05 19:28 ` Holger Dengler
2022-07-06 16:18 ` Harald Freudenberger
2022-07-06 16:26 ` Jason A. Donenfeld
2022-07-06 18:29 ` Christian Borntraeger
2022-07-06 22:34 ` Jason A. Donenfeld
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=30e681b2-a411-cdb1-4b46-243db25abeef@linux.ibm.com \
--to=dengler@linux.ibm.com \
--cc=Jason@zx2c4.com \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=freude@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=jchrist@linux.ibm.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-s390@vger.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