qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Greg Kurz <gkurz@linux.vnet.ibm.com>
Cc: Thomas Huth <thuth@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] spapr: add a default rng device
Date: Tue, 29 Sep 2015 15:01:09 +1000	[thread overview]
Message-ID: <20150929050109.GL19428@voom.redhat.com> (raw)
In-Reply-To: <20150928101346.23919.3988.stgit@bahia.huguette.org>

[-- Attachment #1: Type: text/plain, Size: 2680 bytes --]

On Mon, Sep 28, 2015 at 12:13:47PM +0200, Greg Kurz wrote:
> A recent patch by Thomas Huth brought a new spapr-rng pseudo-device to
> provide high-quality random numbers to guests. The device may either be
> backed by a "RngBackend" or the in-kernel implementation of the H_RANDOM
> hypercall.
> 
> Since modern POWER8 based servers always provide a hardware rng, it makes
> sense to create a spapr-rng device with use-kvm=true by default when it
> is available.
> 
> Of course we want the user to have full control on how the rng is handled.
> The default device WILL NOT be created in the following cases:
> - the -nodefaults option was passed
> - a spapr-rng device was already passed on the command line
> 
> The default device is created at reset time to ensure devices specified on
> the command line have been created.
> 
> Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>

So, I think the concept is ok, but..

> ---
>  hw/ppc/spapr.c       |   17 +++++++++++++++++
>  hw/ppc/spapr_rng.c   |    2 +-
>  target-ppc/kvm.c     |    9 +++++----
>  target-ppc/kvm_ppc.h |    6 ++++++
>  4 files changed, 29 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 7f4f196e53e5..ee048ecffd0c 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -1059,6 +1059,14 @@ static int spapr_check_htab_fd(sPAPRMachineState *spapr)
>      return rc;
>  }
>  
> +static void spapr_rng_create(void)
> +{
> +    Object *rng = object_new(TYPE_SPAPR_RNG);
> +
> +    object_property_set_bool(rng, true, "use-kvm", &error_abort);
> +    object_property_set_bool(rng, true, "realized", &error_abort);
> +}
> +
>  static void ppc_spapr_reset(void)
>  {
>      sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
> @@ -1082,6 +1090,15 @@ static void ppc_spapr_reset(void)
>      spapr->rtas_addr = rtas_limit - RTAS_MAX_SIZE;
>      spapr->fdt_addr = spapr->rtas_addr - FDT_MAX_SIZE;
>  
> +    /* Create a rng device if the user did not provide it already and
> +     * KVM has hwrng support.
> +     */
> +    if (defaults_enabled() &&
> +        kvmppc_hwrng_present() &&
> +        !object_resolve_path_type("", TYPE_SPAPR_RNG, NULL)) {
> +        spapr_rng_create();
> +    }
> +

Constructing the RNG at reset time is just wrong.  Using
defaults_enabled() is ugly at the best of times, using it at reset,
after construction of the qom tree is generally complete, is just
hideous.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

  parent reply	other threads:[~2015-09-29  5:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-28 10:13 [Qemu-devel] [PATCH] spapr: add a default rng device Greg Kurz
2015-09-28 15:25 ` Greg Kurz
2015-09-29  5:01 ` David Gibson [this message]
2015-09-30  8:33   ` Greg Kurz
2015-09-30  9:10     ` Thomas Huth
2015-09-30 12:59       ` Greg Kurz

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=20150929050109.GL19428@voom.redhat.com \
    --to=david@gibson.dropbear.id.au \
    --cc=gkurz@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /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).