rng-builtin: add an RNG backend that uses qemu_guest_getrandom()
v3 cover rng-builtin: add an RNG backend that uses qemu_guest_getrandom()
Add a new RNG backend using QEMU builtin getrandom function.
This patch applies on top of
"[PATCH v5 00/24] Add qemu_getrandom and ARMv8.5-RNG etc"
Based-on: [email protected]
v3: Include Kashyap's patch in the series
Add a patch to change virtio-rng default backend to rng-builtin
v2: Update qemu-options.hx
describe the new backend and specify virtio-rng uses the rng-random by default
Kashyap Chamarthy (1):
VirtIO-RNG: Update default entropy source to /dev/urandom
Laurent Vivier (2):
rng-builtin: add an RNG backend that uses qemu_guest_getrandom()
virtio-rng: change default backend to rng-builtin
backends/Makefile.objs | 2 +- backends/rng-builtin.c | 54 ++++++++++++++++++++++++++++++++++ backends/rng-random.c | 2 +- hw/virtio/virtio-rng.c | 2 +- include/hw/virtio/virtio-rng.h | 4 +-- include/sysemu/rng-builtin.h | 17 +++++++++++ qemu-options.hx | 9 +++++- 7 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 backends/rng-builtin.c create mode 100644 include/sysemu/rng-builtin.h
Signature · 1 line
2.20.1
PATCH v3 1/3 VirtIO-RNG: Update default entropy source to `/dev/urandom`
From: Kashyap Chamarthy <[email protected]>
When QEMU exposes a VirtIO-RNG device to the guest, that device needs a source of entropy, and that source needs to be "non-blocking", like /dev/urandom. However, currently QEMU defaults to the problematic /dev/random, which is "blocking" (as in, it waits until sufficient entropy is available).
Why prefer /dev/urandom over /dev/random?
---------------------------------------------
The man pages of urandom(4) and random(4) state:
"The /dev/random device is a legacy interface which dates back to a time where the cryptographic primitives used in the implementation of /dev/urandom were not widely trusted. It will return random bytes only within the estimated number of bits of fresh noise in the entropy pool, blocking if necessary. /dev/random is suitable for applications that need high quality randomness, and can afford indeterminate delays."
Further, the "Usage" section of the said man pages state:
"The /dev/random interface is considered a legacy interface, and /dev/urandom is preferred and sufficient in all use cases, with the exception of applications which require randomness during early boot time; for these applications, getrandom(2) must be used instead, because it will block until the entropy pool is initialized.
"If a seed file is saved across reboots as recommended below (all major Linux distributions have done this since 2000 at least), the output is cryptographically secure against attackers without local root access as soon as it is reloaded in the boot sequence, and perfectly adequate for network encryption session keys. Since reads from /dev/random may block, users will usually want to open it in nonblocking mode (or perform a read with timeout), and provide some sort of user notification if the desired entropy is not immediately available."
And refer to random(7) for a comparison of /dev/random and /dev/urandom.
- - -
Given the above, change the entropy source for VirtIO-RNG device to /dev/urandom.
Related discussion in these[1][2] past threads.
[1] https://lists.nongnu.org/archive/html/qemu-devel/2018-06/msg08335.html
-- "RNG: Any reason QEMU doesn't default to /dev/urandom?"
[2] https://lists.nongnu.org/archive/html/qemu-devel/2018-09/msg02724.html
-- "[RFC] Virtio RNG: Consider changing the default entropy source to
/dev/urandom"
--- backends/rng-random.c | 2 +- qemu-options.hx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
backends/rng-random.c +1 -1
@@ -112,7 +112,7 @@ static void rng_random_init(Object *obj) rng_random_set_filename, NULL); - s->filename =g_strdup ("/dev/random" ); + s->filename =g_strdup ("/dev/urandom" ); s->fd =-1 ; }
qemu-options.hx +1 -1
@@ -4286,7 +4286,7 @@ Creates a random number generator backend which obtains entropy from a device on the host. The @option{id} parameter is a unique ID that will be used to reference this entropy backend from the @option{virtio-rng} device. The @option{filename} parameter specifies which file to obtain -entropy from and if omitted defaults to @option{/dev/random}. +entropy from and if omitted defaults to @option{/dev/urandom}. @item -object rng-egd,id=@var{id},chardev=@var{chardevid}
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v3 1/3] VirtIO-RNG: Update default entropy source to `/dev/urandom`
Quoted 21 lines · Laurent Vivier
From: Kashyap Chamarthy <[email protected]>
When QEMU exposes a VirtIO-RNG device to the guest, that device needs a source of entropy, and that source needs to be "non-blocking", like
/dev/urandom. However, currently QEMU defaults to the problematic/dev/random, which is "blocking" (as in, it waits until sufficient entropy is available).Why prefer
/dev/urandomover/dev/random?
---------------------------------------------The man pages of urandom(4) and random(4) state:
"The
/dev/randomdevice is a legacy interface which dates back to a time where the cryptographic primitives used in the implementation of/dev/urandomwere not widely trusted. It will return random bytes only within the estimated number of bits of fresh noise in the entropy pool, blocking if necessary./dev/randomis suitable for applications that need high quality randomness, and can afford indeterminate delays."
Quoted 7 lines
Further, the "Usage" section of the said man pages state:
"The
/dev/randominterface is considered a legacy interface, and/dev/urandomis preferred and sufficient in all use cases, with the exception of applications which require randomness during early boot time; for these applications, getrandom(2) must be used instead, because it will block until the entropy pool is initialized.
So how about just using getrandom then?
Quoted 64 lines
"If a seed file is saved across reboots as recommended below (all major Linux distributions have done this since 2000 at least), the output is cryptographically secure against attackers without local root access as soon as it is reloaded in the boot sequence, and perfectly adequate for network encryption session keys. Since reads from
/dev/randommay block, users will usually want to open it in nonblocking mode (or perform a read with timeout), and provide some sort of user notification if the desired entropy is not immediately available."And refer to random(7) for a comparison of
/dev/randomand/dev/urandom.- - -
Given the above, change the entropy source for VirtIO-RNG device to
/dev/urandom.Related discussion in these[1][2] past threads.
[1] https://lists.nongnu.org/archive/html/qemu-devel/2018-06/msg08335.html
-- "RNG: Any reason QEMU doesn't default to/dev/urandom?"
[2] https://lists.nongnu.org/archive/html/qemu-devel/2018-09/msg02724.html
-- "[RFC] Virtio RNG: Consider changing the default entropy source to
/dev/urandom"Signed-off-by Kashyap Chamarthy <[email protected]>Reviewed-by Daniel P. Berrangé <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>Signed-off-by Laurent Vivier <[email protected]>--- backends/rng-random.c | 2 +- qemu-options.hx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)backends/rng-random.c +1
-1@@ -112,7 +112,7 @@ static void rng_random_init(Object *obj) rng_random_set_filename, NULL); - s->filename =g_strdup ("/dev/random" ); + s->filename =g_strdup ("/dev/urandom" ); s->fd =-1 ; }qemu-options.hx +1
-1@@ -4286,7 +4286,7 @@ Creates a random number generator backend which obtains entropy from a device on the host. The @option{id} parameter is a unique ID that will be used to reference this entropy backend from the @option{virtio-rng} device. The @option{filename} parameter specifies which file to obtain -entropy from and if omitted defaults to @option{/dev/random}. +entropy from and if omitted defaults to @option{/dev/urandom}. @item -object rng-egd,id=@var{id},chardev=@var{chardevid}Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v3 1/3] VirtIO-RNG: Update default entropy source to `/dev/urandom`
Quoted 24 lines · Michael S. Tsirkin
Quoted 23 lines · Laurent Vivier
From: Kashyap Chamarthy <[email protected]>
When QEMU exposes a VirtIO-RNG device to the guest, that device needs a source of entropy, and that source needs to be "non-blocking", like
/dev/urandom. However, currently QEMU defaults to the problematic/dev/random, which is "blocking" (as in, it waits until sufficient entropy is available).Why prefer
/dev/urandomover/dev/random?
---------------------------------------------The man pages of urandom(4) and random(4) state:
"The
/dev/randomdevice is a legacy interface which dates back to a time where the cryptographic primitives used in the implementation of/dev/urandomwere not widely trusted. It will return random bytes only within the estimated number of bits of fresh noise in the entropy pool, blocking if necessary./dev/randomis suitable for applications that need high quality randomness, and can afford indeterminate delays."Further, the "Usage" section of the said man pages state:
Quoted 7 lines
Quoted 5 lines
"The
/dev/randominterface is considered a legacy interface, and/dev/urandomis preferred and sufficient in all use cases, with the exception of applications which require randomness during early boot time; for these applications, getrandom(2) must be used instead, because it will block until the entropy pool is initialized.So how about just using getrandom then?
The 3rd patch in this series addresses that.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [Qemu-devel] [PATCH v3 1/3] VirtIO-RNG: Update default entropy source to `/dev/urandom`
Quoted 31 lines · Daniel P. Berrangé
Quoted 30 lines · Michael S. Tsirkin
Quoted 28 lines · Laurent Vivier
From: Kashyap Chamarthy <[email protected]>
When QEMU exposes a VirtIO-RNG device to the guest, that device needs a source of entropy, and that source needs to be "non-blocking", like
/dev/urandom. However, currently QEMU defaults to the problematic/dev/random, which is "blocking" (as in, it waits until sufficient entropy is available).Why prefer
/dev/urandomover/dev/random?
---------------------------------------------The man pages of urandom(4) and random(4) state:
"The
/dev/randomdevice is a legacy interface which dates back to a time where the cryptographic primitives used in the implementation of/dev/urandomwere not widely trusted. It will return random bytes only within the estimated number of bits of fresh noise in the entropy pool, blocking if necessary./dev/randomis suitable for applications that need high quality randomness, and can afford indeterminate delays."Further, the "Usage" section of the said man pages state:
"The
/dev/randominterface is considered a legacy interface, and/dev/urandomis preferred and sufficient in all use cases, with the exception of applications which require randomness during early boot time; for these applications, getrandom(2) must be used instead, because it will block until the entropy pool is initialized.
Quoted 3 lines
Quoted 1 line
So how about just using getrandom then?
The 3rd patch in this series addresses that.
It seems to use qemu_guest_getrandom which in turn with patch 1 calls /dev/urandom...
Did I miss something?
Quoted 7 lines
Regards,
DanielSignature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [Qemu-devel] [PATCH v3 1/3] VirtIO-RNG: Update default entropy source to `/dev/urandom`
Quoted 32 lines · Michael S. Tsirkin
Quoted 31 lines · Daniel P. Berrangé
Quoted 30 lines · Michael S. Tsirkin
Quoted 28 lines · Laurent Vivier
From: Kashyap Chamarthy <[email protected]>
When QEMU exposes a VirtIO-RNG device to the guest, that device needs a source of entropy, and that source needs to be "non-blocking", like
/dev/urandom. However, currently QEMU defaults to the problematic/dev/random, which is "blocking" (as in, it waits until sufficient entropy is available).Why prefer
/dev/urandomover/dev/random?
---------------------------------------------The man pages of urandom(4) and random(4) state:
"The
/dev/randomdevice is a legacy interface which dates back to a time where the cryptographic primitives used in the implementation of/dev/urandomwere not widely trusted. It will return random bytes only within the estimated number of bits of fresh noise in the entropy pool, blocking if necessary./dev/randomis suitable for applications that need high quality randomness, and can afford indeterminate delays."Further, the "Usage" section of the said man pages state:
"The
/dev/randominterface is considered a legacy interface, and/dev/urandomis preferred and sufficient in all use cases, with the exception of applications which require randomness during early boot time; for these applications, getrandom(2) must be used instead, because it will block until the entropy pool is initialized.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
So how about just using getrandom then?
The 3rd patch in this series addresses that.
It seems to use
qemu_guest_getrandomwhich in turn with patch 1 calls/dev/urandom...
Did I miss something?
qemu_guest_getrandom will preferentially use the crypto library random APIs (gnutls, or gcrypt). If both are compiled out that it will use getrandom() if supported by the C library and current kernel. If that fails then it will try /dev/urandom if it exists, finally /dev/random. On Windows it uses their native crypto API. See this dependant series:
https://lists.gnu.org/archive/html/qemu-devel/2019-05/msg02237.html
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [Qemu-devel] [PATCH v3 1/3] VirtIO-RNG: Update default entropy source to `/dev/urandom`
Quoted 47 lines · Daniel P. Berrangé
Quoted 32 lines · Michael S. Tsirkin
Quoted 31 lines · Daniel P. Berrangé
Quoted 30 lines · Michael S. Tsirkin
Quoted 28 lines · Laurent Vivier
From: Kashyap Chamarthy <[email protected]>
When QEMU exposes a VirtIO-RNG device to the guest, that device needs a source of entropy, and that source needs to be "non-blocking", like
/dev/urandom. However, currently QEMU defaults to the problematic/dev/random, which is "blocking" (as in, it waits until sufficient entropy is available).Why prefer
/dev/urandomover/dev/random?
---------------------------------------------The man pages of urandom(4) and random(4) state:
"The
/dev/randomdevice is a legacy interface which dates back to a time where the cryptographic primitives used in the implementation of/dev/urandomwere not widely trusted. It will return random bytes only within the estimated number of bits of fresh noise in the entropy pool, blocking if necessary./dev/randomis suitable for applications that need high quality randomness, and can afford indeterminate delays."Further, the "Usage" section of the said man pages state:
"The
/dev/randominterface is considered a legacy interface, and/dev/urandomis preferred and sufficient in all use cases, with the exception of applications which require randomness during early boot time; for these applications, getrandom(2) must be used instead, because it will block until the entropy pool is initialized.Quoted 7 lines
Quoted 3 lines
Quoted 1 line
So how about just using getrandom then?
The 3rd patch in this series addresses that.
It seems to use
qemu_guest_getrandomwhich in turn with patch 1 calls/dev/urandom...
Did I miss something?
qemu_guest_getrandomwill preferentially use the crypto library random APIs (gnutls, or gcrypt). If both are compiled out that it will usegetrandom()if supported by the C library and current kernel. If that fails then it will try/dev/urandomif it exists, finally/dev/random. On Windows it uses their native crypto API. See this dependant series:
Quoted 4 lines
https://lists.gnu.org/archive/html/qemu-devel/2019-05/msg02237.html
Regards,
Daniel
In particular
https://lists.gnu.org/archive/html/qemu-devel/2019-05/msg02238.html
maybe clarify this is just for systems without getrandom then.
Quoted 4 lines
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [Qemu-devel] [PATCH v3 1/3] VirtIO-RNG: Update default entropy source to `/dev/urandom`
Quoted 48 lines · Michael S. Tsirkin
Quoted 47 lines · Daniel P. Berrangé
Quoted 32 lines · Michael S. Tsirkin
Quoted 31 lines · Daniel P. Berrangé
Quoted 30 lines · Michael S. Tsirkin
Quoted 28 lines · Laurent Vivier
From: Kashyap Chamarthy <[email protected]>
When QEMU exposes a VirtIO-RNG device to the guest, that device needs a source of entropy, and that source needs to be "non-blocking", like
/dev/urandom. However, currently QEMU defaults to the problematic/dev/random, which is "blocking" (as in, it waits until sufficient entropy is available).Why prefer
/dev/urandomover/dev/random?
---------------------------------------------The man pages of urandom(4) and random(4) state:
"The
/dev/randomdevice is a legacy interface which dates back to a time where the cryptographic primitives used in the implementation of/dev/urandomwere not widely trusted. It will return random bytes only within the estimated number of bits of fresh noise in the entropy pool, blocking if necessary./dev/randomis suitable for applications that need high quality randomness, and can afford indeterminate delays."Further, the "Usage" section of the said man pages state:
"The
/dev/randominterface is considered a legacy interface, and/dev/urandomis preferred and sufficient in all use cases, with the exception of applications which require randomness during early boot time; for these applications, getrandom(2) must be used instead, because it will block until the entropy pool is initialized.Quoted 7 lines
Quoted 3 lines
Quoted 1 line
So how about just using getrandom then?
The 3rd patch in this series addresses that.
It seems to use
qemu_guest_getrandomwhich in turn with patch 1 calls/dev/urandom...
Did I miss something?
qemu_guest_getrandomwill preferentially use the crypto library random APIs (gnutls, or gcrypt). If both are compiled out that it will usegetrandom()if supported by the C library and current kernel. If that fails then it will try/dev/urandomif it exists, finally/dev/random. On Windows it uses their native crypto API. See this dependant series:
Quoted 7 lines
In particular
https://lists.gnu.org/archive/html/qemu-devel/2019-05/msg02238.html
maybe clarify this is just for systems without getrandom then.
I'm not sure I see what the problem is. That patch is implementing the fallback behaviour I describe above, with the crypto library preferred, falling back to getrandom, then /dev/urandom, finally /dev/random.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [Qemu-devel] [PATCH v3 1/3] VirtIO-RNG: Update default entropy source to `/dev/urandom`
In reply to Laurent VivierQuoted 55 lines · Laurent Vivier
From: Kashyap Chamarthy <[email protected]>
When QEMU exposes a VirtIO-RNG device to the guest, that device needs a source of entropy, and that source needs to be "non-blocking", like
/dev/urandom. However, currently QEMU defaults to the problematic/dev/random, which is "blocking" (as in, it waits until sufficient entropy is available).Why prefer
/dev/urandomover/dev/random?
---------------------------------------------The man pages of urandom(4) and random(4) state:
"The
/dev/randomdevice is a legacy interface which dates back to a time where the cryptographic primitives used in the implementation of/dev/urandomwere not widely trusted. It will return random bytes only within the estimated number of bits of fresh noise in the entropy pool, blocking if necessary./dev/randomis suitable for applications that need high quality randomness, and can afford indeterminate delays."Further, the "Usage" section of the said man pages state:
"The
/dev/randominterface is considered a legacy interface, and/dev/urandomis preferred and sufficient in all use cases, with the exception of applications which require randomness during early boot time; for these applications, getrandom(2) must be used instead, because it will block until the entropy pool is initialized."If a seed file is saved across reboots as recommended below (all major Linux distributions have done this since 2000 at least), the output is cryptographically secure against attackers without local root access as soon as it is reloaded in the boot sequence, and perfectly adequate for network encryption session keys. Since reads from
/dev/randommay block, users will usually want to open it in nonblocking mode (or perform a read with timeout), and provide some sort of user notification if the desired entropy is not immediately available."And refer to random(7) for a comparison of
/dev/randomand/dev/urandom.- - -
Given the above, change the entropy source for VirtIO-RNG device to
/dev/urandom.Related discussion in these[1][2] past threads.
[1] https://lists.nongnu.org/archive/html/qemu-devel/2018-06/msg08335.html
-- "RNG: Any reason QEMU doesn't default to/dev/urandom?"
[2] https://lists.nongnu.org/archive/html/qemu-devel/2018-09/msg02724.html
-- "[RFC] Virtio RNG: Consider changing the default entropy source to
/dev/urandom"
Quoted 4 lines
Signed-off-by Kashyap Chamarthy <[email protected]>Reviewed-by Daniel P. Berrangé <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>Signed-off-by Laurent Vivier <[email protected]>
Suggest to work Daniel's analysis into the commit message, like this:
When QEMU exposes a VirtIO-RNG device to the guest, that device needs a source of entropy, and that source needs to be "non-blocking", like /dev/urandom. However, currently QEMU defaults to the problematic /dev/random, which on Linux is "blocking" (as in, it waits until sufficient entropy is available).
Why prefer /dev/urandom over /dev/random on Linux?
------------------------------------------------------
[...]
What about other OSes?
----------------------
/dev/urandom exists and works on OS-X, FreeBSD, DragonFlyBSD, NetBSD and OpenBSD, which covers all the non-Linux platforms we explicitly support, aside from Windows.
On Windows /dev/random doesn't work either so we don't regress. This is actually another argument in favour of using the newly proposed rng-builtin backend by default, as that will work on Windows.
- - -
Given the above, change the entropy source for VirtIO-RNG device to /dev/urandom.
[...]
PATCH v3 2/3 rng-builtin: add an RNG backend that uses qemu_guest_getrandom()
In reply to Laurent VivierAdd a new RNG backend using QEMU builtin getrandom function.
It can be created and used with something like:
... -object rng-builtin,id=rng0 -device virtio-rng,rng=rng0 ...
--- backends/Makefile.objs | 2 +- backends/rng-builtin.c | 56 ++++++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 10 +++++++- 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 backends/rng-builtin.c
backends/Makefile.objs +1 -1
@@ -1,4 +1,4 @@ -common-obj-y += rng.o rng-egd.o +common-obj-y += rng.o rng-egd.o rng-builtin.o common-obj-$(CONFIG_POSIX) += rng-random.o common-obj-$(CONFIG_TPM) += tpm.o
backends/rng-builtin.c new file +56 -0
56 lines not on this page · raw message
qemu-options.hx +9 -1
@@ -4280,13 +4280,21 @@ other options. The @option{share} boolean option is @var{on} by default with memfd. +@item -object rng-builtin,id=@var{id} + +Creates a random number generator backend which obtains entropy from +QEMU builtin functions. The @option{id} parameter is a unique ID that +will be used to reference this entropy backend from the @option{virtio-rng} +device. + @item -object rng-random,id=@var{id},filename=@var{/dev/random} Creates a random number generator backend which obtains entropy from a device on the host. The @option{id} parameter is a unique ID that will be used to reference this entropy backend from the @option{virtio-rng} device. The @option{filename} parameter specifies which file to obtain -entropy from and if omitted defaults to @option{/dev/urandom}. +entropy from and if omitted defaults to @option{/dev/urandom}. By default, +the @option{virtio-rng} device uses this RNG backend. @item -object rng-egd,id=@var{id},chardev=@var{chardevid}
Signature · 1 line
2.20.1
PATCH v3 3/3 virtio-rng: change default backend to rng-builtin
In reply to Laurent Vivier--- backends/rng-builtin.c | 8 +++----- hw/virtio/virtio-rng.c | 2 +- include/hw/virtio/virtio-rng.h | 4 ++-- include/sysemu/rng-builtin.h | 17 +++++++++++++++++ qemu-options.hx | 5 ++--- 5 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 include/sysemu/rng-builtin.h
backends/rng-builtin.c +3 -5
@@ -7,17 +7,15 @@#include "qemu/osdep.h" #include "sysemu/rng.h" +#include "sysemu/rng-builtin.h" #include "qapi/error.h" #include "qapi/qmp/qerror.h" #include "qemu/main-loop.h" #include "qemu/guest-random.h" -#define TYPE_RNG_BUILTIN "rng-builtin" -#define RNG_BUILTIN (obj) OBJECT_CHECK(RngBuiltin, (obj), TYPE_RNG_BUILTIN) - -typedef struct RngBuiltin { +struct RngBuiltin {RngBackend parent; -}RngBuiltin ; +};static void rng_builtin_request_entropy (RngBackend *b,RngRequest *req) {
hw/virtio/virtio-rng.c +1 -1
@@ -189,7 +189,7 @@ static void virtio_rng_device_realize(DeviceState *dev, Error **errp) }if (vrng->conf.rng ==NULL ) { - vrng->conf.default_backend =RNG_RANDOM (object_new (TYPE_RNG_RANDOM )); + vrng->conf.default_backend =RNG_BUILTIN (object_new (TYPE_RNG_BUILTIN ));user_creatable_complete (USER_CREATABLE (vrng->conf.default_backend), &local_err);
include/hw/virtio/virtio-rng.h +2 -2
@@ -13,7 +13,7 @@#define QEMU_VIRTIO_RNG_H #include "sysemu/rng.h" -#include "sysemu/rng-random.h" +#include "sysemu/rng-builtin.h" #include "standard-headers/linux/virtio_rng.h" #define TYPE_VIRTIO_RNG "virtio-rng-device"
@@ -26,7 +26,7 @@ struct VirtIORNGConf {RngBackend *rng;uint64_t max_bytes;uint32_t period_ms; -RngRandom *default_backend; +RngBuiltin *default_backend; }; typedef struct VirtIORNG {
include/sysemu/rng-builtin.h new file +17 -0
@@ -0,0 +1,17 @@ +/* +* QEMU Builtin Random Number Generator Backend +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ +#ifndef QEMU_RNG_BUILTIN_H +#define QEMU_RNG_BUILTIN_H + +#include "qom/object.h" + +#define TYPE_RNG_BUILTIN "rng-builtin" +#define RNG_BUILTIN (obj) OBJECT_CHECK(RngBuiltin, (obj), TYPE_RNG_BUILTIN) + +typedef struct RngBuiltin RngBuiltin ; + +#endif
qemu-options.hx +2 -3
@@ -4285,7 +4285,7 @@ The @option{share} boolean option is @var{on} by default with memfd. Creates a random number generator backend which obtains entropy from QEMU builtin functions. The @option{id} parameter is a unique ID that will be used to reference this entropy backend from the @option{virtio-rng} -device. +device. By default, the @option{virtio-rng} device uses this RNG backend. @item -object rng-random,id=@var{id},filename=@var{/dev/random}
@@ -4293,8 +4293,7 @@ Creates a random number generator backend which obtains entropy from a device on the host. The @option{id} parameter is a unique ID that will be used to reference this entropy backend from the @option{virtio-rng} device. The @option{filename} parameter specifies which file to obtain -entropy from and if omitted defaults to @option{/dev/urandom}. By default, -the @option{virtio-rng} device uses this RNG backend. +entropy from and if omitted defaults to @option{/dev/urandom}. @item -object rng-egd,id=@var{id},chardev=@var{chardevid}
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v3 3/3] virtio-rng: change default backend to rng-builtin
Quoted 40 lines · Laurent Vivier
Signed-off-by Laurent Vivier <[email protected]>--- backends/rng-builtin.c | 8 +++----- hw/virtio/virtio-rng.c | 2 +- include/hw/virtio/virtio-rng.h | 4 ++-- include/sysemu/rng-builtin.h | 17 +++++++++++++++++ qemu-options.hx | 5 ++--- 5 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 include/sysemu/rng-builtin.hbackends/rng-builtin.c +3
-5@@ -7,17 +7,15 @@#include "qemu/osdep.h" #include "sysemu/rng.h" +#include "sysemu/rng-builtin.h" #include "qapi/error.h" #include "qapi/qmp/qerror.h" #include "qemu/main-loop.h" #include "qemu/guest-random.h" -#define TYPE_RNG_BUILTIN "rng-builtin" -#define RNG_BUILTIN (obj) OBJECT_CHECK(RngBuiltin, (obj), TYPE_RNG_BUILTIN) - -typedef struct RngBuiltin { +struct RngBuiltin {RngBackend parent; -}RngBuiltin ; +};static void rng_builtin_request_entropy (RngBackend *b,RngRequest *req) {hw/virtio/virtio-rng.c +0
-0
hw/virtio/virtio-rng.c static void virtio_rng_device_realize(DeviceState *dev, Error **errp) · line 195
Quoted 8 lines
hw/virtio/virtio-rng.c +1
-1@@ -189,7 +189,7 @@ static void virtio_rng_device_realize(DeviceState *dev, Error **errp) }if (vrng->conf.rng ==NULL ) { - vrng->conf.default_backend =RNG_RANDOM (object_new (TYPE_RNG_RANDOM )); + vrng->conf.default_backend =RNG_BUILTIN (object_new (TYPE_RNG_BUILTIN ));user_creatable_complete (USER_CREATABLE (vrng->conf.default_backend), &local_err);
if (local_err) {
error_propagate(errp, local_err);
object_unref(OBJECT(vrng->conf.default_backend));
return;
}
object_property_add_child(OBJECT(dev),
"default-backend",
OBJECT(vrng->conf.default_backend),
NULL);
/* The child property took a reference, we can safely drop ours now */
object_unref(OBJECT(vrng->conf.default_backend));
object_property_set_link(OBJECT(dev),
OBJECT(vrng->conf.default_backend),
"rng", NULL);
}Quoted 14 lines
include/hw/virtio/virtio-rng.h +1
-1@@ -13,7 +13,7 @@#define QEMU_VIRTIO_RNG_H #include "sysemu/rng.h" -#include "sysemu/rng-random.h" +#include "sysemu/rng-builtin.h" #include "standard-headers/linux/virtio_rng.h" #define TYPE_VIRTIO_RNG "virtio-rng-device"
include/hw/virtio/virtio-rng.h struct VirtIORNGConf { · line 29
Quoted 5 lines
include/hw/virtio/virtio-rng.h +1
-1@@ -26,7 +26,7 @@ struct VirtIORNGConf {RngBackend *rng;uint64_t max_bytes;uint32_t period_ms; -RngRandom *default_backend; +RngBuiltin *default_backend;
This member appears to be superfluous. As far as I can tell, it's only used in the part of virtio-rng.c visible above. If you replace it by a local variable there (in a separate patch, perhaps), this patch will become simpler. In particular, you won't need to create rng-builtin.h.
Quoted 31 lines
include/hw/virtio/virtio-rng.h +0
-0}; typedef struct VirtIORNG {include/sysemu/rng-builtin.h new file +17
-0@@ -0,0 +1,17 @@ +/* +* QEMU Builtin Random Number Generator Backend +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ +#ifndef QEMU_RNG_BUILTIN_H +#define QEMU_RNG_BUILTIN_H + +#include "qom/object.h" + +#define TYPE_RNG_BUILTIN "rng-builtin" +#define RNG_BUILTIN (obj) OBJECT_CHECK(RngBuiltin, (obj), TYPE_RNG_BUILTIN) + +typedef struct RngBuiltin RngBuiltin ; + +#endif qemu-options.hx +0
-0
qemu-options.hx The @option{share} boolean option is @var{on} by default with memfd. · line 4288
Quoted 5 lines
qemu-options.hx +1
-1@@ -4285,7 +4285,7 @@ The @option{share} boolean option is @var{on} by default with memfd. Creates a random number generator backend which obtains entropy from QEMU builtin functions. The @option{id} parameter is a unique ID that will be used to reference this entropy backend from the @option{virtio-rng} -device. +device. By default, the @option{virtio-rng} device uses this RNG backend.
Aside: this piece of information should ideally go into virtio-rng documentation. If only it existed; -device virtio-rng,help is all we got. So you keep it here. Fair enough.
Quoted 12 lines
qemu-options.hx +1
-2@item -object rng-random,id=@var{id},filename=@var{/dev/random}@@ -4293,8 +4293,7 @@ Creates a random number generator backend which obtains entropy from a device on the host. The @option{id} parameter is a unique ID that will be used to reference this entropy backend from the @option{virtio-rng} device. The @option{filename} parameter specifies which file to obtain -entropy from and if omitted defaults to @option{/dev/urandom}. By default, -the @option{virtio-rng} device uses this RNG backend. +entropy from and if omitted defaults to @option{/dev/urandom}. @item -object rng-egd,id=@var{id},chardev=@var{chardevid}
Re: [Qemu-devel] [PATCH v3 3/3] virtio-rng: change default backend to rng-builtin
Quoted 11 lines · Markus Armbruster
Quoted 9 lines · Laurent Vivier
Signed-off-by Laurent Vivier <[email protected]>--- backends/rng-builtin.c | 8 +++----- hw/virtio/virtio-rng.c | 2 +- include/hw/virtio/virtio-rng.h | 4 ++-- include/sysemu/rng-builtin.h | 17 +++++++++++++++++ qemu-options.hx | 5 ++--- 5 files changed, 25 insertions(+), 11 deletions(-)create mode 100644
include/sysemu/rng-builtin.h
...
Quoted 4 lines
Quoted 4 lines
include/hw/virtio/virtio-rng.h +0
-0
...
Quoted 4 lines
Quoted 4 lines
#define TYPE_VIRTIO_RNG "virtio-rng-device"include/hw/virtio/virtio-rng.h +0
-0@@ -26,7 +26,7 @@ struct VirtIORNGConf {RngBackend *rng;uint64_t max_bytes;
Quoted 9 lines
include/hw/virtio/virtio-rng.h struct VirtIORNGConf { · line 29
Quoted 3 lines
include/hw/virtio/virtio-rng.h +1
-1uint32_t period_ms; -RngRandom *default_backend; +RngBuiltin *default_backend;This member appears to be superfluous. As far as I can tell, it's only used in the part of
virtio-rng.cvisible above. If you replace it by a local variable there (in a separate patch, perhaps), this patch will become simpler. In particular, you won't need to createrng-builtin.h.
I don't understand how we can remove the rng-builtin.h as we need its macros for "RNG_BUILTIN(object_new(TYPE_RNG_BUILTIN))". Could you explain?
Thanks,
Laurent
Re: [Qemu-devel] [PATCH v3 3/3] virtio-rng: change default backend to rng-builtin
Quoted 32 lines · Laurent Vivier
Quoted 11 lines · Markus Armbruster
Quoted 9 lines · Laurent Vivier
Signed-off-by Laurent Vivier <[email protected]>--- backends/rng-builtin.c | 8 +++----- hw/virtio/virtio-rng.c | 2 +- include/hw/virtio/virtio-rng.h | 4 ++-- include/sysemu/rng-builtin.h | 17 +++++++++++++++++ qemu-options.hx | 5 ++--- 5 files changed, 25 insertions(+), 11 deletions(-)create mode 100644
include/sysemu/rng-builtin.h...
Quoted 4 lines
Quoted 4 lines
include/hw/virtio/virtio-rng.h +0
-0...
Quoted 4 lines
Quoted 4 lines
#define TYPE_VIRTIO_RNG "virtio-rng-device"include/hw/virtio/virtio-rng.h +0
-0@@ -26,7 +26,7 @@ struct VirtIORNGConf {RngBackend *rng;uint64_t max_bytes;Quoted 9 lines
include/hw/virtio/virtio-rng.h struct VirtIORNGConf { · line 29
Quoted 3 lines
include/hw/virtio/virtio-rng.h +1
-1uint32_t period_ms; -RngRandom *default_backend; +RngBuiltin *default_backend;This member appears to be superfluous. As far as I can tell, it's only used in the part of
virtio-rng.cvisible above. If you replace it by a local variable there (in a separate patch, perhaps), this patch will become simpler. In particular, you won't need to createrng-builtin.h.
Quoted 3 lines
I don't understand how we can remove the
rng-builtin.has we need its macros for "RNG_BUILTIN(object_new(TYPE_RNG_BUILTIN))". Could you explain?
You're right, you'll still need TYPE_RNG_BUILTIN. You don't actually need RNG_BUILTIN(), because you can make the local variable Object *.
Bonus: saves a couple of OBJECT().
If nothing but TYPE_RNG_BUILTIN is left in rng-builtin.h, I'd stick it into rng.h instead.
Quoted 13 lines · Laurent Vivier
Add a new RNG backend using QEMU builtin getrandom function.
This patch applies on top of
"[PATCH v5 00/24] Add qemu_getrandom and ARMv8.5-RNG etc"Based-on: [email protected]
v3: Include Kashyap's patch in the series
Add a patch to change virtio-rng default backend to rng-builtinv2: Update qemu-options.hx
describe the new backend and specify virtio-rng uses the rng-random by default
Quoted 6 lines
Kashyap Chamarthy (1):
VirtIO-RNG: Update default entropy source to/dev/urandomLaurent Vivier (2):
rng-builtin: add an RNG backend that usesqemu_guest_getrandom()
virtio-rng: change default backend to rng-builtin
OK pls address Marku's comment on commit msg and I will merge.
Quoted 13 lines
backends/Makefile.objs | 2 +- backends/rng-builtin.c | 54 ++++++++++++++++++++++++++++++++++ backends/rng-random.c | 2 +- hw/virtio/virtio-rng.c | 2 +- include/hw/virtio/virtio-rng.h | 4 +-- include/sysemu/rng-builtin.h | 17 +++++++++++ qemu-options.hx | 9 +++++- 7 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 backends/rng-builtin.c create mode 100644 include/sysemu/rng-builtin.hSignature · 1 line
2.20.1
Quoted 17 lines · Michael S. Tsirkin
Quoted 16 lines · Laurent Vivier
Add a new RNG backend using QEMU builtin getrandom function.
This patch applies on top of
"[PATCH v5 00/24] Add qemu_getrandom and ARMv8.5-RNG etc"Based-on: [email protected]
v3: Include Kashyap's patch in the series
Add a patch to change virtio-rng default backend to rng-builtinv2: Update qemu-options.hx
describe the new backend and specify virtio-rng uses the rng-random by defaultKashyap Chamarthy (1):
VirtIO-RNG: Update default entropy source to/dev/urandom
Quoted 6 lines
Quoted 3 lines
Laurent Vivier (2):
rng-builtin: add an RNG backend that usesqemu_guest_getrandom()
virtio-rng: change default backend to rng-builtinOK pls address Marku's comment on commit msg and I will merge.
Kashyap,
as this patch is from you, do you agree?
If so, I can update the message and send a new version of the series (or you canr esend your patch alone if you prefer).
Thanks,
Laurent
Quoted 1 line · Laurent Vivier
On 12/05/2019 20:21, Michael S. Tsirkin wrote:
[...]
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Kashyap Chamarthy (1):
VirtIO-RNG: Update default entropy source to/dev/urandomLaurent Vivier (2):
rng-builtin: add an RNG backend that usesqemu_guest_getrandom()
virtio-rng: change default backend to rng-builtin
Quoted 5 lines
Quoted 1 line
OK pls address Marku's comment on commit msg and I will merge.
Kashyap,
as this patch is from you, do you agree?
Yes.
Quoted 2 lines
If so, I can update the message and send a new version of the series (or you canr esend your patch alone if you prefer).
Please go ahead and add it, the below is the text (from Dan/Markus):
What about other OSes?
----------------------
/dev/urandom exists and works on OS-X, FreeBSD, DragonFlyBSD, NetBSD and OpenBSD, which cover all the non-Linux platforms we explicitly support, aside from Windows.
On Windows /dev/random doesn't work either so we don't regress. This is actually another argument in favour of using the newly proposed 'rng-builtin' backend by default, as that will work on Windows.
Thanks!
[...]
Signature · 1 line
/kashyap
Quoted 29 lines · Kashyap Chamarthy
Quoted 1 line · Laurent Vivier
On 12/05/2019 20:21, Michael S. Tsirkin wrote:
[...]
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Kashyap Chamarthy (1):
VirtIO-RNG: Update default entropy source to/dev/urandomLaurent Vivier (2):
rng-builtin: add an RNG backend that usesqemu_guest_getrandom()
virtio-rng: change default backend to rng-builtinQuoted 5 lines
Quoted 1 line
OK pls address Marku's comment on commit msg and I will merge.
Kashyap,
as this patch is from you, do you agree?
Yes.
Quoted 2 lines
If so, I can update the message and send a new version of the series (or you canr esend your patch alone if you prefer).
Please go ahead and add it, the below is the text (from Dan/Markus):
What about other OSes?
----------------------
Quoted 8 lines
/dev/urandomexists and works on OS-X, FreeBSD, DragonFlyBSD, NetBSD and OpenBSD, which cover all the non-Linux platforms we explicitly support, aside from Windows.On Windows
/dev/randomdoesn't work either so we don't regress. This is actually another argument in favour of using the newly proposed 'rng-builtin' backend by default, as that will work on Windows.
Additionally, please insert "on Linux" into the first paragraph, like this:
When QEMU exposes a VirtIO-RNG device to the guest, that device needs a source of entropy, and that source needs to be "non-blocking", like /dev/urandom. However, currently QEMU defaults to the problematic /dev/random, which on Linux is "blocking" (as in, it waits until sufficient entropy is available).