qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Amit Shah <amit.shah@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: qemu list <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH 1/1] rng backend: open backend in blocking mode
Date: Tue, 2 Apr 2013 16:05:49 +0530	[thread overview]
Message-ID: <20130402103549.GC15084@amit.redhat.com> (raw)
In-Reply-To: <87eheus60p.fsf@codemonkey.ws>

On (Mon) 01 Apr 2013 [09:02:46], Anthony Liguori wrote:
> Amit Shah <amit.shah@redhat.com> writes:
> 
> > Opening backends in non-blocking mode isn't necessary, we don't do
> > anything while waiting for data.
> >
> > This also excuses us from checking for EAGAIN, which for the default
> > random backend, is a very common return error type.
> 
> It's not common...  It really shouldn't happen however.

EAGAIN is common when a file is opened in non-blocking mode.  Needs to
be made verbose?

> >  Starting the guest
> > with '-device virtio-rng-pci', issuing a 'cat /dev/hwrng' in the guest
> > while also doing 'cat /dev/random' on the host causes
> 
> You are essentially cat'ing the same device twice.  What's happening is
> that there is entropy available in /dev/random so a select()
> notification happens but before we are able to read() it, the cat of
> /dev/hwrng ends up consuming that entropy.
> 
> This would never happen with a socket, for instance.  /dev/random is
> special in there are multiple readers.
> 
> >
> > backends/rng-random.c:44:entropy_available: assertion failed: (len != -1)
> >
> > without this fix.
> 
> This fix would cause QEMU to block indefinitely which I don't think is
> very good behavior.  I think a better solution would be:
> 
> diff --git a/backends/rng-random.c b/backends/rng-random.c
> index acd20af..9fde566 100644
> --- a/backends/rng-random.c
> +++ b/backends/rng-random.c
> @@ -41,6 +41,9 @@ static void entropy_available(void *opaque)
>      ssize_t len;
>  
>      len = read(s->fd, buffer, s->size);
> +    if (len == -1 && errno == EINTR) {
> +        return;
> +    }

This has to be an additional fix on top of this one.  EAGAIN has to be
handled if we want to allow nonblocking reads, and there doesn't seem
to be any reason to have these reads be non-blocking.

OTOH, I also think we could use the glib functions for file IO, since
handling EINTR in each open-coded read call isn't always fun.

		Amit

  reply	other threads:[~2013-04-02 10:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-01  9:25 [Qemu-devel] [PATCH 1/1] rng backend: open backend in blocking mode Amit Shah
2013-04-01 14:02 ` Anthony Liguori
2013-04-02 10:35   ` Amit Shah [this message]
2013-04-02 12:52     ` Anthony Liguori
2013-04-03  6:28       ` Amit Shah
2013-04-03 20:08         ` Anthony Liguori
2013-04-08  6:09           ` Amit Shah

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=20130402103549.GC15084@amit.redhat.com \
    --to=amit.shah@redhat.com \
    --cc=anthony@codemonkey.ws \
    --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).