Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Jean-Philippe Brucker <jean-philippe@linaro.org>
To: Andre Przywara <andre.przywara@arm.com>
Cc: Will Deacon <will@kernel.org>,
	Julien Thierry <julien.thierry.kdev@gmail.com>,
	kvm@vger.kernel.org, Alexandru Elisei <alexandru.elisei@arm.com>,
	Sami Mujawar <sami.mujawar@arm.com>
Subject: Re: [PATCH kvmtool 1/2] virtio/rng: switch to using /dev/urandom
Date: Wed, 19 Apr 2023 14:53:13 +0100	[thread overview]
Message-ID: <20230419135313.GA94027@myrica> (raw)
In-Reply-To: <20230413165757.1728800-2-andre.przywara@arm.com>

On Thu, Apr 13, 2023 at 05:57:56PM +0100, Andre Przywara wrote:
> At the moment we use /dev/random as the backing device to provide random
> numbers to our virtio-rng implementation. The downside of doing so is
> that it may block indefinitely - or return EAGAIN repeatedly in our case.
> On one headless systbem without ample noise sources (no keyboard, mouse,

system

> or network traffic) I measured 30 seconds to gain one byte of randomness.
> At the moment EDK II insists in waiting for all of the requsted random
> bytes (for its EFI_RNG_PROTOCOL runtime service) to arrive, that held up
> a Linux kernel boot for more than 10 minutes(!).
> 
> According to the Internet(TM), on Linux /dev/urandom provides the same
> quality random numbers as /dev/random, it just does not block when the
> entropy estimation algorithm suggests so. For all practical purposes the
> recommendation is to just use /dev/urandom, QEMU did the switch as well
> in 2019 [1].
> 
> Use /dev/urandom instead of /dev/random when opening the file descriptor
> providing the randomness source for the virtio/rng implementation.
> 
> [1] https://gitlab.com/qemu-project/qemu/-/commit/a2230bd778d8
> 
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>

Reviewed-by: Jean-Philippe Brucker <jean-philippe@linaro.org>

> ---
>  virtio/rng.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/virtio/rng.c b/virtio/rng.c
> index 8f85d5ec1..eab8f3ac0 100644
> --- a/virtio/rng.c
> +++ b/virtio/rng.c
> @@ -166,7 +166,7 @@ int virtio_rng__init(struct kvm *kvm)
>  	if (rdev == NULL)
>  		return -ENOMEM;
>  
> -	rdev->fd = open("/dev/random", O_RDONLY | O_NONBLOCK);
> +	rdev->fd = open("/dev/urandom", O_RDONLY | O_NONBLOCK);
>  	if (rdev->fd < 0) {
>  		r = rdev->fd;
>  		goto cleanup;
> -- 
> 2.25.1
> 

  reply	other threads:[~2023-04-19 13:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-13 16:57 [PATCH kvmtool 0/2] Fix virtio/rng handling in low entropy situations Andre Przywara
2023-04-13 16:57 ` [PATCH kvmtool 1/2] virtio/rng: switch to using /dev/urandom Andre Przywara
2023-04-19 13:53   ` Jean-Philippe Brucker [this message]
2023-04-13 16:57 ` [RFC PATCH kvmtool 2/2] virtio/rng: return at least one byte of entropy Andre Przywara
2023-04-19 13:58 ` [PATCH kvmtool 0/2] Fix virtio/rng handling in low entropy situations Jean-Philippe Brucker
2023-04-19 15:10   ` Jean-Philippe Brucker
2023-04-19 15:31     ` Andre Przywara

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=20230419135313.GA94027@myrica \
    --to=jean-philippe@linaro.org \
    --cc=alexandru.elisei@arm.com \
    --cc=andre.przywara@arm.com \
    --cc=julien.thierry.kdev@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=sami.mujawar@arm.com \
    --cc=will@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