mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: "Reshetova, Elena" <elena.reshetova@intel.com>,
	"Jason A. Donenfeld" <Jason@zx2c4.com>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"x86@kernel.org" <x86@kernel.org>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Kuppuswamy Sathyanarayanan
	<sathyanarayanan.kuppuswamy@linux.intel.com>,
	"Nakajima, Jun" <jun.nakajima@intel.com>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	"Kalra, Ashish" <ashish.kalra@amd.com>,
	Sean Christopherson <seanjc@google.com>,
	"linux-coco@lists.linux.dev" <linux-coco@lists.linux.dev>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH 1/2] x86/random: Retry on RDSEED failure
Date: Tue, 30 Jan 2024 07:20:23 -0800	[thread overview]
Message-ID: <1C8939C0-BC58-4BE9-95B8-4B6F4A36115D@zytor.com> (raw)
In-Reply-To: <DM8PR11MB5750E38A8B2BCE66AF7F9812E77D2@DM8PR11MB5750.namprd11.prod.outlook.com>

On January 30, 2024 5:10:20 AM PST, "Reshetova, Elena" <elena.reshetova@intel.com> wrote:
> 
>> Hi Kirill,
>> 
>> I've been following the other discussion closely thinking about the
>> matter, but I suppose I'll jump in here directly on this patch, if
>> this is the approach the discussion is congealing around.
>> 
>> A comment below:
>> 
>> On Tue, Jan 30, 2024 at 9:30 AM Kirill A. Shutemov
>> <kirill.shutemov@linux.intel.com> wrote:
>> >  static inline bool __must_check rdseed_long(unsigned long *v)
>> >  {
>> > +       unsigned int retry = RDRAND_RETRY_LOOPS;
>> >         bool ok;
>> > -       asm volatile("rdseed %[out]"
>> > -                    CC_SET(c)
>> > -                    : CC_OUT(c) (ok), [out] "=r" (*v));
>> > -       return ok;
>> > +
>> > +       do {
>> > +               asm volatile("rdseed %[out]"
>> > +                            CC_SET(c)
>> > +                            : CC_OUT(c) (ok), [out] "=r" (*v));
>> > +
>> > +               if (ok)
>> > +                       return true;
>> > +       } while (--retry);
>> > +
>> > +       return false;
>> >  }
>> 
>> So, my understanding of RDRAND vs RDSEED -- deliberately leaving out
>> any cryptographic discussion here -- is roughly that RDRAND will
>> expand the seed material for longer, while RDSEED will mostly always
>> try to sample more bits from the environment. AES is fast, while
>> sampling is slow, so RDRAND gives better performance and is less
>> likely to fail, whereas RDSEED always has to wait on the hardware to
>> collect some bits, so is more likely to fail.
>
>The internals of Intel DRBG behind RDRAND/RDSEED has been publicly
>documented, so the structure is no secret. Please see [1] for overall
>structure and other aspects. So, yes, your overall understanding is correct
>(there are many more details though). 
>
>[1] https://www.intel.com/content/www/us/en/developer/articles/guide/intel-digital-random-number-generator-drng-software-implementation-guide.html
>
>
>> 
>> For that reason, most of the usage of RDRAND and RDSEED inside of
>> random.c is something to the tune of `if (!rdseed(out)) rdrand(out);`,
>> first trying RDSEED but falling back to RDRAND if it's busy. That
>> still seems to me like a reasonable approach, which this patch would
>> partly undermine (in concert with the next patch, which I'll comment
>> on in a follow up email there).
>
>I agree that for the purpose of extracting entropy for Linux RNG falling
>back to RDRAND (current behavior) is perfectly ok, so I think you are doing
>the right thing. However, in principle it is not always the case, there are
>situations when a fallback to RDRAND should not be used, but it is also
>true that the user of this interface should know/understand this situation. 
>
>> 
>> So maybe this patch #1 (of 2) can be dropped?
>
>Before we start debating this patchset, what is your opinion on the original
>problem we raised for CoCo VMs when both RDRAND/RDSEED are made to
>fail deliberately? 
>
>Best Regards,
>Elena.
>
>

I have a real concern with this. We already have the option to let the entropy pool fill before the boot can proceed. This would have the risk of massively increasing the interrupt latency for what will be retried anyway.

  parent reply	other threads:[~2024-01-30 15:21 UTC|newest]

Thread overview: 99+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-30  8:30 Kirill A. Shutemov
2024-01-30  8:30 ` [PATCH 2/2] x86/random: Issue a warning if RDRAND or RDSEED fails Kirill A. Shutemov
2024-01-30 12:37   ` Jason A. Donenfeld
2024-01-30 13:45     ` Reshetova, Elena
2024-01-30 14:21       ` Jason A. Donenfeld
2024-01-30 14:55         ` Reshetova, Elena
2024-01-30 15:00           ` Jason A. Donenfeld
2024-01-30 17:31       ` Dave Hansen
2024-01-30 17:49         ` Jason A. Donenfeld
2024-01-30 17:58           ` Dave Hansen
2024-01-30 18:15             ` H. Peter Anvin
2024-01-30 18:23               ` Jason A. Donenfeld
2024-01-30 18:23             ` Jason A. Donenfeld
2024-01-30 18:37               ` Dave Hansen
2024-01-30 18:05           ` Daniel P. Berrangé
2024-01-30 18:24             ` Jason A. Donenfeld
2024-01-30 18:31             ` Jason A. Donenfeld
2024-01-30 18:40             ` H. Peter Anvin
2024-01-31  8:16             ` Reshetova, Elena
2024-01-31 11:59               ` Dr. Greg
2024-01-31 13:06               ` Jason A. Donenfeld
2024-01-31 18:02                 ` Reshetova, Elena
2024-01-31 20:35                 ` Dr. Greg
2024-02-01  4:47                   ` Theodore Ts'o
2024-02-01  9:54                     ` Dr. Greg
2024-02-01 11:08                       ` Daniel P. Berrangé
2024-02-01 21:04                         ` Dr. Greg
2024-02-02  7:56                           ` Reshetova, Elena
2024-02-01  7:26                   ` Reshetova, Elena
2024-02-01 10:52                     ` Dr. Greg
2024-02-06  1:12               ` Dr. Greg
2024-02-06  8:04                 ` Daniel P. Berrangé
2024-02-06 12:04                   ` Dr. Greg
2024-02-06 13:00                     ` Daniel P. Berrangé
2024-02-08 10:31                       ` Dr. Greg
2024-02-06 13:50                     ` Daniel P. Berrangé
2024-02-06 15:35                     ` Borislav Petkov
2024-02-08 11:44                       ` Dr. Greg
2024-02-09 17:31                         ` Borislav Petkov
2024-02-09 19:49                           ` Jason A. Donenfeld
2024-02-09 20:37                             ` Dave Hansen
2024-02-09 21:45                             ` Borislav Petkov
2024-02-06 18:49                     ` H. Peter Anvin
2024-02-08 16:38                       ` Dr. Greg
2024-01-30 15:50   ` Kuppuswamy Sathyanarayanan
2024-01-30 12:29 ` [PATCH 1/2] x86/random: Retry on RDSEED failure Jason A. Donenfeld
2024-01-30 12:51   ` Jason A. Donenfeld
2024-01-30 13:10   ` Reshetova, Elena
2024-01-30 14:06     ` Jason A. Donenfeld
2024-01-30 14:43       ` Daniel P. Berrangé
2024-01-30 15:12         ` Jason A. Donenfeld
2024-01-30 18:35       ` Jason A. Donenfeld
2024-01-30 19:06         ` Reshetova, Elena
2024-01-30 19:16           ` Jason A. Donenfeld
2024-01-31  7:56             ` Reshetova, Elena
2024-01-31 13:14               ` Jason A. Donenfeld
2024-01-31 14:07                 ` Theodore Ts'o
2024-01-31 14:45                   ` Jason A. Donenfeld
2024-01-31 14:52                     ` Jason A. Donenfeld
2024-01-31 17:10                     ` Theodore Ts'o
2024-01-31 17:37                       ` Reshetova, Elena
2024-01-31 18:01                         ` Jason A. Donenfeld
2024-02-01  4:57                           ` Theodore Ts'o
2024-02-01 18:09                             ` Jason A. Donenfeld
2024-02-01 18:46                               ` Dave Hansen
2024-02-01 19:02                                 ` H. Peter Anvin
2024-02-02  7:25                               ` Reshetova, Elena
2024-02-02 15:39                                 ` Theodore Ts'o
2024-02-03 10:12                                   ` Jason A. Donenfeld
2024-02-09 19:53                                     ` Jason A. Donenfeld
2024-02-12  8:25                                       ` Reshetova, Elena
2024-02-12 16:32                                         ` Theodore Ts'o
2024-02-13  7:28                                           ` Dan Williams
2024-02-13 23:13                                             ` Theodore Ts'o
2024-02-14  0:53                                               ` Dan Williams
2024-02-14  4:32                                                 ` Theodore Ts'o
2024-02-14  6:48                                                   ` Dan Williams
2024-02-14  6:54                                                   ` Reshetova, Elena
2024-02-14  8:34                                                   ` Nikolay Borisov
2024-02-14  9:34                                                     ` Dr. Greg
2024-02-14 17:30                                         ` Jason A. Donenfeld
2024-02-14 15:18                                 ` Reshetova, Elena
2024-02-14 17:21                                   ` Jason A. Donenfeld
2024-02-14 17:59                                     ` Reshetova, Elena
2024-02-14 19:32                                       ` Jason A. Donenfeld
2024-02-15  7:07                                         ` Reshetova, Elena
2024-02-15 12:58                                           ` Jason A. Donenfeld
2024-02-14 19:46                                     ` Tom Lendacky
2024-02-14 20:04                                       ` Jason A. Donenfeld
2024-02-14 20:11                                         ` Theodore Ts'o
2024-02-15 13:01                                           ` Jason A. Donenfeld
2024-02-14 20:14                                     ` Dave Hansen
2024-02-02 15:47                               ` James Bottomley
2024-02-02 16:05                                 ` Theodore Ts'o
2024-02-02 21:28                                   ` James Bottomley
2024-02-03 14:35                                     ` Theodore Ts'o
2024-02-06 19:12                                       ` H. Peter Anvin
2024-01-30 15:20     ` H. Peter Anvin [this message]
2024-01-30 15:44 ` Kuppuswamy Sathyanarayanan

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=1C8939C0-BC58-4BE9-95B8-4B6F4A36115D@zytor.com \
    --to=hpa@zytor.com \
    --cc=Jason@zx2c4.com \
    --cc=ashish.kalra@amd.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=elena.reshetova@intel.com \
    --cc=jun.nakajima@intel.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=sathyanarayanan.kuppuswamy@linux.intel.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=tytso@mit.edu \
    --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

all inboxes | Powered by JetHome®