All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@amacapital.net>
To: Niels Ferguson <niels@microsoft.com>
Cc: Mathew John <mathewj@microsoft.com>,
	Theodore Ts'o <tytso@mit.edu>,
	John Starks <John.Starks@microsoft.com>,
	kvm list <kvm@vger.kernel.org>, Gleb Natapov <gleb@kernel.org>,
	David Hepkin <davidhep@microsoft.com>,
	Linux Virtualization <virtualization@lists.linux-foundation.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Jake Oshins <jakeo@microsoft.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: Standardizing an MSR or other hypercall to get an RNG seed?
Date: Thu, 18 Sep 2014 12:03:42 -0700	[thread overview]
Message-ID: <CALCETrXbV1qLZOt3aDbXRSSxApS0Qvb1WFPmkOrn8o1zyGVK6w@mail.gmail.com> (raw)
In-Reply-To: <e2ac32426deb468b97bd1445091e351a@BL2PR03MB243.namprd03.prod.outlook.com>

On Thu, Sep 18, 2014 at 11:54 AM, Niels Ferguson <niels@microsoft.com> wrote:
> Defining a standard way of transferring random numbers between the host and the guest is an excellent idea.
>
> As the person who writes the RNG code in Windows, I have a few comments:
>
> DETECTION:
> It should be possible to detect this feature through CPUID or similar mechanism. That allows the code that uses this feature to be written without needing the ability to catch CPU exceptions. I could be wrong, but as far as I know there is no support for exception handling in the Windows OS loader where we gather our initial random state.
>

Linux is like this, too, except that I have experimental code to
create an IDT in that code, so we can handle it.  I agree, though,
that using CPUID in early boot is easier.

> EFFICIENCY:
> Is there a way we can transfer more bytes per interaction? With a single 64-bit MSR we always need multiple reads to get a seed, and each of them results in a context switch to the host, which is expensive. This is even worse for 32-bit guests. Windows would typically need to fetch 64 bytes of random data at boot and at regular intervals. It is not a show-stopper, but better efficiency would be nice.

I thought about this for a while and didn't come up with anything that
wouldn't messy.  We could fudge the MSR rax/rdx high bits to get 128
bits, but that's nonportable and awful to implement.  We could return
a random number directly from CPUID, but that's weird.

In very informal benchmarking, rdmsr wasn't that bad.  On the other
hand, I wasn't immediately planning on using the msr on an ongoing
basis on Linux guests except after suspend/resume.

>
> GUEST-TO-HOST:
> Can we also define a way to have random values flow from the guest to the host? Guests are also gathering entropy from their own sources, and if we allow the guests to send random data to the host, then the host can treat it as an entropy source and all the VMs on a single host can share their entropy. (This is not a security problem; any reasonable host RNG cannot be hurt even by maliciously chosen entropy inputs.)
>

wrmsr on the same MSR?

>
> I don't know much about how hypervisors work on the inside, but maybe we can define a mechanism for standardized hypervisor calls that work on all hypervisors that support this feature. Then we could define a function to do an entropy exchange: the guest provides N bytes of random data to the host, and the host replies with N bytes of random data. The data exchange can now be done through memory.
>
> A standardized hypervisor-call mechanism also seems generally useful for future features, whereas the MSR solution is very limited in what it can do. We might end up with standardized hypervisor-calls in the future for some other reason, and then the MSR solution looks very odd.

I think there'll be resistance to a standardized hypercall mechanism,
just because the implementations tend to be complex.  Hyper-V uses a
special page in guest physical memory that contains a trampoline.

We could use wrmsr to a register where the payload is a pointer to a
buffer to receive random bytes, but that loses some of the simplicity
of just calling rdmsr a few times.

--Andy

  reply	other threads:[~2014-09-18 19:03 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-18  2:50 Standardizing an MSR or other hypercall to get an RNG seed? Andy Lutomirski
2014-09-18 14:40 ` KY Srinivasan
2014-09-18 14:40 ` KY Srinivasan
2014-09-18 14:43   ` H. Peter Anvin
2014-09-18 15:38     ` Andy Lutomirski
2014-09-18 15:44       ` Andy Lutomirski
2014-09-18 15:58         ` Paolo Bonzini
2014-09-18 16:36       ` KY Srinivasan
2014-09-18 17:13         ` Nakajima, Jun
2014-09-18 17:17           ` Paolo Bonzini
2014-09-18 17:17           ` Paolo Bonzini
2014-09-18 17:20             ` Jake Oshins
2014-09-18 17:20             ` Jake Oshins
2014-09-18 17:20             ` KY Srinivasan
2014-09-18 17:20             ` KY Srinivasan
2014-09-18 17:42               ` Nakajima, Jun
2014-09-18 18:35                 ` Andy Lutomirski
2014-09-18 18:39                   ` H. Peter Anvin
2014-09-18 18:54                     ` Niels Ferguson
2014-09-18 19:03                       ` Andy Lutomirski [this message]
2014-09-18 21:54                         ` David Hepkin
2014-09-19  6:04                           ` Paolo Bonzini
2014-09-18 21:54                         ` David Hepkin
2014-09-18 18:58                   ` Paolo Bonzini
2014-09-18 19:07                     ` Andy Lutomirski
2014-09-18 21:21                       ` Nakajima, Jun
2014-09-18 21:35                         ` Andy Lutomirski
2014-09-18 21:46                       ` David Hepkin
2014-09-18 21:57                         ` H. Peter Anvin
2014-09-18 22:07                           ` Andy Lutomirski
2014-09-19  0:49                             ` Nakajima, Jun
2014-09-19  0:49                             ` Nakajima, Jun
2014-09-19  1:03                               ` Andy Lutomirski
2014-09-19  1:28                                 ` Andy Lutomirski
2014-09-19 16:14                                   ` Nakajima, Jun
2014-09-19 16:22                                     ` Paolo Bonzini
2014-09-19 16:40                                     ` H. Peter Anvin
2014-09-19 17:21                                       ` Andy Lutomirski
2014-09-19 17:36                                         ` H. Peter Anvin
2014-09-19 17:39                                           ` Andy Lutomirski
2014-09-19 22:05                                       ` Theodore Ts'o
2014-09-19 22:06                                         ` Andy Lutomirski
2014-09-19 22:57                                           ` Nakajima, Jun
2014-09-19 22:57                                           ` Theodore Ts'o
2014-09-19 23:12                                             ` Andy Lutomirski
2014-09-19 23:29                                               ` H. Peter Anvin
2014-09-19 23:35                                                 ` Theodore Ts'o
2014-09-19 23:41                                                   ` Andy Lutomirski
2014-09-20  0:06                                                   ` H. Peter Anvin
2014-09-19 23:29                                               ` H. Peter Anvin
2014-09-19  1:28                                 ` Andy Lutomirski
2014-09-18 22:00                         ` Andy Lutomirski
2014-09-18 22:03                           ` H. Peter Anvin
2014-09-19 16:37                           ` Gleb Natapov
2014-09-19 16:40                             ` H. Peter Anvin
2014-09-19 16:53                               ` Gleb Natapov
2014-09-19 17:08                                 ` H. Peter Anvin
2014-09-19 17:15                                   ` Gleb Natapov
2014-09-19 17:18                                     ` H. Peter Anvin
2014-09-19 17:49                                       ` Gleb Natapov
2014-09-19 18:02                                         ` Andy Lutomirski
2014-09-19 18:12                                           ` Gleb Natapov
2014-09-19 18:20                                             ` Andy Lutomirski
2014-09-19 20:53                                               ` Gleb Natapov
2014-09-22  4:11                                               ` Alok Kataria
2014-09-19 17:18                                     ` H. Peter Anvin
2014-09-19 17:21                                 ` Andy Lutomirski
2014-09-19 17:59                                   ` Gleb Natapov
2014-09-19 17:59                                   ` Gleb Natapov
2014-09-18 21:46                       ` David Hepkin
2014-09-18 18:56                 ` Paolo Bonzini
2014-09-18 16:36       ` KY Srinivasan
2014-09-19 18:30 ` Christopher Covington
2014-09-19 18:42   ` Andy Lutomirski
2014-09-19 20:21     ` Nadav Amit
2014-09-19 20:46       ` Andy Lutomirski
2014-09-19 21:46         ` H. Peter Anvin
2014-09-22 13:31           ` Christopher Covington
2014-09-22 14:17             ` H. Peter Anvin
2014-09-22 14:18               ` H. Peter Anvin
2014-09-22 23:01             ` H. Peter Anvin
2014-09-21 12:39         ` Paolo Bonzini
2014-09-19 20:21     ` Nadav Amit
2014-09-22 13:33     ` Christopher Covington

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=CALCETrXbV1qLZOt3aDbXRSSxApS0Qvb1WFPmkOrn8o1zyGVK6w@mail.gmail.com \
    --to=luto@amacapital.net \
    --cc=John.Starks@microsoft.com \
    --cc=davidhep@microsoft.com \
    --cc=gleb@kernel.org \
    --cc=hpa@zytor.com \
    --cc=jakeo@microsoft.com \
    --cc=kvm@vger.kernel.org \
    --cc=mathewj@microsoft.com \
    --cc=niels@microsoft.com \
    --cc=pbonzini@redhat.com \
    --cc=tytso@mit.edu \
    --cc=virtualization@lists.linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.