From: Anthony Liguori <anthony@codemonkey.ws>
To: Amit Shah <amit.shah@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>, qemu list <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH v3 1/1] virtio-rng: hardware random number generator device
Date: Fri, 22 Jun 2012 14:59:13 -0500 [thread overview]
Message-ID: <4FE4CE91.2080509@codemonkey.ws> (raw)
In-Reply-To: <20120622185002.GF24801@amit.redhat.com>
On 06/22/2012 01:50 PM, Amit Shah wrote:
> On (Fri) 22 Jun 2012 [08:44:52], Anthony Liguori wrote:
>> On 06/22/2012 08:34 AM, Daniel P. Berrange wrote:
>>>
>>> Oh, that's a good point.
>
> But easily fixed.
Of course, except that now we have to maintain compatibility so some hideous
hack goes in.
This is what fundamentally makes using events a bad approach. There are more
problems lurking. This is the fundamental complexity of having two
non-synchronized communication channels when you're trying to synchronize some
sort of activity.
BTW, despite what danpb mentioned, you are rate limiting entropy requests in
this patch series....
>>>> All of these problems are naturally solved using a protocol over a CharDriverState.
>>>
>>> Can we at least agree on merging a patch which just includes the
>>> raw chardev backend support for virtio-rng ? ie drop the QMP
>>> event for now, so we can make some step forward.
>>
>> All we need to do to support EGD is instead of doing:
>>
>> + QObject *data;
>> +
>> + data = qobject_from_jsonf("{ 'bytes': %" PRId64 " }",
>> + size);
>> + monitor_protocol_event(QEVENT_ENTROPY_NEEDED, data);
>> + qobject_decref(data);
>>
>> Do:
>>
>> while (size> 0) {
>> uint8_t partial_size = MIN(255, size);
>> uint8_t msg[2] = { 0x02, partial_size };
>>
>> qemu_chr_write(s->chr, msg, sizeof(msg));
>>
>> size -= partial_size;
>> }
>>
>> And that's it. It's an extremely simple protocol to support. It
>> would actually reduce the total size of the patch.
>
> So I now get what your objection is, and that is because of an
> assumption you're making which is incorrect.
>
> An OS asking for 5038 bytes of entropy is doing just that: asking for
> those bytes. That doesn't mean a hardware device can provide it with
> that much entropy. So, the hardware device here will just provide
> whatever is available, and the OS has to be happy with what it got.
> If it got 200 bytes from the device, the OS is then free to demand
> even 7638 bytes more, but it may not get anything for quite a while.
>
> (This is exactly how things work with /dev/random and /dev/urandom
> too, btw. And /dev/urandom was invented for apps which can't wait for
> all the data they're asking to come to them.)
As it turns out, the EGD protocol also has a mechanism to ask for ask much
entropy as is available at the current moment. It also has a mechanism to query
the amount of available entropy.
And no, you're assertion that we don't care about how much entropy the guest is
requesting is wrong. If we lose entropy requests, then we never know if the
guest is in a state where it's expecting entropy and we're not sending it.
Consider:
- Guest requests entropy (X bytes)
- libvirt sees request
- libvirt sends X bytes to guest
- Guest requests entropy (Y bytes), QEMU filters due to rate limiting
The guest will never request entropy again and libvirt will never send entropy
again. The device is effectively dead-locked.
And none of this is a problem using the EGD protocol like I illustrated above.
> All this is expected. Keep in mind that the hardware-generated
> entropy is read from /dev/hwrng, which again is a /dev/random-like
> interface, and /dev/hwrng entropy can be fed into /dev/random by using
> rngd. All that is standard stuff.
>
> So: the QMP event here is just a note to libvirt that the guest is
> asking for data, and as an additional hint, it also mentions how much
> data the guest wants right now. No party is in any kind of contract
> to provide exactly what's asked for.
But you are not using it as a hint!
There is no way for in the virtio-rng protocol for libvirt to just send data to
the guest out of the kindness of it's heart. virtio is fundamentally a
request-response protocol. Guest requests MUST be processed by something that
generates a response.
This should be plumbed as a request-response protocol (i.e. EGD).
>>> As mentioned in the previous thread, I see no issue with
>>> later implementing an alternate protocol on the chardev
>>> backend eg as we have raw vs telnet mode for serial ports,
>>> we ought to be able to have a choice of raw vs egd mode for
>>> virtio-rng backends
>>
>> I don't really understand how raw mode works other than reading as
>> much from /dev/urandom as possible and filling the socket buffer
>> buffer with it.
>
> That's all that's needed for the simplest (while being as effective as
> any other) implementation to work.
>
>> I think the only two modes that make sense are EGD over a socket and
>> direct open of /dev/urandom.
>
> Directly wiring /dev/urandom via chardev is more flexible, and doesn't
> involve anything else. No chardev gimmicks as well.
>
>> But I think the EGD mode is the more important of the two.
>
> Why? There's nothing standard about it.
Except it's been around for over a decade and is widely supported.
Regards,
Anthony Liguori
>
> Amit
next prev parent reply other threads:[~2012-06-22 19:59 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-20 6:59 [Qemu-devel] [PATCH v3 0/1] virtio-rng: hardware random number generator Amit Shah
2012-06-20 6:59 ` [Qemu-devel] [PATCH v3 1/1] virtio-rng: hardware random number generator device Amit Shah
2012-06-20 8:36 ` Daniel P. Berrange
2012-06-20 21:29 ` Anthony Liguori
2012-06-22 11:06 ` Amit Shah
2012-07-02 17:56 ` Stefan Berger
2012-06-22 12:12 ` Markus Armbruster
2012-06-22 12:22 ` Anthony Liguori
2012-06-22 12:31 ` Daniel P. Berrange
2012-06-22 12:58 ` Anthony Liguori
2012-06-22 13:34 ` Daniel P. Berrange
2012-06-22 13:44 ` Anthony Liguori
2012-06-22 18:50 ` Amit Shah
2012-06-22 19:59 ` Anthony Liguori [this message]
2012-09-16 20:42 ` [Qemu-devel] [PATCH v3 0/1] virtio-rng: hardware random number generator H. Peter Anvin
2012-09-16 23:23 ` Anthony Liguori
2012-09-16 23:36 ` H. Peter Anvin
2012-09-17 3:21 ` Amit Shah
2012-09-17 4:27 ` H. Peter Anvin
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=4FE4CE91.2080509@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=amit.shah@redhat.com \
--cc=armbru@redhat.com \
--cc=qemu-devel@nongnu.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).