From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35208) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZgaIu-0001qW-AV for qemu-devel@nongnu.org; Mon, 28 Sep 2015 11:25:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZgaIq-0002X1-2G for qemu-devel@nongnu.org; Mon, 28 Sep 2015 11:25:24 -0400 Received: from e06smtp16.uk.ibm.com ([195.75.94.112]:57181) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZgaIp-0002We-Pj for qemu-devel@nongnu.org; Mon, 28 Sep 2015 11:25:20 -0400 Received: from localhost by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 28 Sep 2015 16:25:17 +0100 Date: Mon, 28 Sep 2015 17:25:11 +0200 From: Greg Kurz Message-ID: <20150928172511.4a947ff8@bahia.local> In-Reply-To: <20150928101346.23919.3988.stgit@bahia.huguette.org> References: <20150928101346.23919.3988.stgit@bahia.huguette.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] spapr: add a default rng device List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Gibson Cc: Thomas Huth , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Cc'ing qemu-ppc@ On Mon, 28 Sep 2015 12:13:47 +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 > --- > 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(); > + } > + > /* Load the fdt */ > spapr_finalize_fdt(spapr, spapr->fdt_addr, spapr->rtas_addr, > spapr->rtas_size); > diff --git a/hw/ppc/spapr_rng.c b/hw/ppc/spapr_rng.c > index ed43d5e04221..ee5af302bd4d 100644 > --- a/hw/ppc/spapr_rng.c > +++ b/hw/ppc/spapr_rng.c > @@ -114,7 +114,7 @@ static void spapr_rng_realize(DeviceState *dev, Error **errp) > sPAPRRngState *rngstate = SPAPR_RNG(dev); > > if (rngstate->use_kvm) { > - if (kvmppc_enable_hwrng() == 0) { > + if (kvmppc_hwrng_present() && kvmppc_enable_hwrng() == 0) { > return; > } > /* > diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c > index e641680fb146..084bb034f1fd 100644 > --- a/target-ppc/kvm.c > +++ b/target-ppc/kvm.c > @@ -2490,11 +2490,12 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) > return data & 0xffff; > } > > -int kvmppc_enable_hwrng(void) > +bool kvmppc_hwrng_present(void) > { > - if (!kvm_enabled() || !kvm_check_extension(kvm_state, KVM_CAP_PPC_HWRNG)) { > - return -1; > - } > + return kvm_enabled() && kvm_check_extension(kvm_state, KVM_CAP_PPC_HWRNG); > +} > > +int kvmppc_enable_hwrng(void) > +{ > return kvmppc_enable_hcall(kvm_state, H_RANDOM); > } > diff --git a/target-ppc/kvm_ppc.h b/target-ppc/kvm_ppc.h > index 470f6d62f7bb..a76338c9aa16 100644 > --- a/target-ppc/kvm_ppc.h > +++ b/target-ppc/kvm_ppc.h > @@ -54,6 +54,7 @@ void kvmppc_hash64_free_pteg(uint64_t token); > void kvmppc_hash64_write_pte(CPUPPCState *env, target_ulong pte_index, > target_ulong pte0, target_ulong pte1); > bool kvmppc_has_cap_fixup_hcalls(void); > +bool kvmppc_hwrng_present(void); > int kvmppc_enable_hwrng(void); > > #else > @@ -252,6 +253,11 @@ static inline bool kvmppc_has_cap_fixup_hcalls(void) > abort(); > } > > +static inline bool kvmppc_hwrng_present(void) > +{ > + return false; > +} > + > static inline int kvmppc_enable_hwrng(void) > { > return -1; > >