From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51124) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZWZjn-00012M-7K for qemu-devel@nongnu.org; Mon, 31 Aug 2015 20:47:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZWZjk-00059f-1r for qemu-devel@nongnu.org; Mon, 31 Aug 2015 20:47:47 -0400 Date: Tue, 1 Sep 2015 10:38:08 +1000 From: David Gibson Message-ID: <20150901003808.GI11475@voom.redhat.com> References: <1441046762-5788-1-git-send-email-thuth@redhat.com> <1441046762-5788-2-git-send-email-thuth@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="qLni7iB6Dl8qUSwk" Content-Disposition: inline In-Reply-To: <1441046762-5788-2-git-send-email-thuth@redhat.com> Subject: Re: [Qemu-devel] [PATCH v2 1/2] spapr: Add support for hwrng when available List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Thomas Huth , itg@voom.redhat.com Cc: qemu-devel@nongnu.org, agraf@suse.de, armbru@redhat.com, michael@ellerman.id.au, qemu-ppc@nongnu.org, amit.shah@redhat.com --qLni7iB6Dl8qUSwk Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Aug 31, 2015 at 08:46:01PM +0200, Thomas Huth wrote: > From: Michael Ellerman >=20 > Some powerpc systems have support for a hardware random number generator > (hwrng). If such a hwrng is present the host kernel can provide access > to it via the H_RANDOM hcall. >=20 > The kernel advertises the presence of a hwrng with the KVM_CAP_PPC_HWRNG > capability. If this is detected we add the appropriate device tree bits > to advertise the presence of the hwrng to the guest kernel. >=20 > Signed-off-by: Michael Ellerman > [thuth: Refreshed patch so it applies to QEMU master branch] > Signed-off-by: Thomas Huth So, I'm confused by one thing. I thought new kernel handled hcalls were supposed to be disabled by default, but I don't see any calls to kvmppc_enable_hcall() to turn on H_RANDOM. > --- > hw/ppc/spapr.c | 16 ++++++++++++++++ > include/hw/ppc/spapr.h | 1 + > target-ppc/kvm.c | 5 +++++ > target-ppc/kvm_ppc.h | 5 +++++ > 4 files changed, 27 insertions(+) >=20 > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c > index bf0c64f..bc3a112 100644 > --- a/hw/ppc/spapr.c > +++ b/hw/ppc/spapr.c > @@ -466,6 +466,22 @@ static void *spapr_create_fdt_skel(hwaddr initrd_bas= e, > =20 > _FDT((fdt_end_node(fdt))); > =20 > + if (kvmppc_hwrng_present()) { > + _FDT(fdt_begin_node(fdt, "ibm,platform-facilities")); > + > + _FDT(fdt_property_string(fdt, "name", "ibm,platform-facilities")= ); Also, "name" properties don't need to be set in flattened trees - that's implicit in the node name itself. > + _FDT(fdt_property_string(fdt, "device_type", > + "ibm,platform-facilities")); > + _FDT(fdt_property_cell(fdt, "#address-cells", 0x1)); > + _FDT(fdt_property_cell(fdt, "#size-cells", 0x0)); > + _FDT(fdt_begin_node(fdt, "ibm,random-v1")); > + _FDT(fdt_property_string(fdt, "name", "ibm,random-v1")); > + _FDT(fdt_property_string(fdt, "compatible", "ibm,random")); > + _FDT((fdt_end_node(fdt))); > + } > + > + _FDT((fdt_end_node(fdt))); > + > /* event-sources */ > spapr_events_fdt_skel(fdt, epow_irq); > =20 > diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h > index 91a61ab..ab8906f 100644 > --- a/include/hw/ppc/spapr.h > +++ b/include/hw/ppc/spapr.h > @@ -331,6 +331,7 @@ struct sPAPRMachineState { > #define H_SET_MPP 0x2D0 > #define H_GET_MPP 0x2D4 > #define H_XIRR_X 0x2FC > +#define H_RANDOM 0x300 > #define H_SET_MODE 0x31C > #define MAX_HCALL_OPCODE H_SET_MODE > =20 > diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c > index 110436d..7317f8f 100644 > --- a/target-ppc/kvm.c > +++ b/target-ppc/kvm.c > @@ -2484,3 +2484,8 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) > { > return data & 0xffff; > } > + > +bool kvmppc_hwrng_present(void) > +{ > + return kvm_enabled() && kvm_check_extension(kvm_state, KVM_CAP_PPC_H= WRNG); > +} > diff --git a/target-ppc/kvm_ppc.h b/target-ppc/kvm_ppc.h > index 4d30e27..62ff601 100644 > --- a/target-ppc/kvm_ppc.h > +++ b/target-ppc/kvm_ppc.h > @@ -55,6 +55,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); > =20 > #else > =20 > @@ -248,6 +249,10 @@ static inline bool kvmppc_has_cap_fixup_hcalls(void) > abort(); > } > =20 > +static inline bool kvmppc_hwrng_present(void) > +{ > + return false; > +} > #endif > =20 > #ifndef CONFIG_KVM --=20 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 --qLni7iB6Dl8qUSwk Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJV5PNwAAoJEGw4ysog2bOSB98P+gJbTzwJ0QXknV0hV5FhTnjK TlGeJEwioBAkIMcvrYhDWdi6Q690YWV+P/40dW5ChA1upcCSri2QCpe0f61nRlgs A+IBZTY4wclCNtTEgib2Yz4LoB8ZYj3DX7qd4oNJXOlKQROpxUWzLbDPDAQtek01 x8wKbE2RB1zgNvv/1YgInPMpAwnbF4/noucsxHUqPby+8xsOz+/yLIzQ1QzJA9Br m1PJ4GtUHWe4Ls0wU4nDXFomLskvKc4Mnnn0/KLfnXlCtSmIEM7vU4qd1Q+Qvgwo nQbwm+63aQedrAHnP/i5VMTTMJPdIJQENHhIjqi4x/FSv9A4jZobY+7EeCMSW9Kq JPqx8j6IfzFsx8x/nynWaOgrhY8OdwRnVPeofkvr+gihW0pdxX+dJVtpkxrHm0o2 EeGl/qkTeP2kS8ROkVOK5MYnZbXMc+WAA81u4uvHRmaJA1417tLV5wWpYzZYsgxl 6S4b4yo9AmXRNOl4meHBzzCqrXHc8EeTeYvfD39qcAtg052K9Dul4wpA1O/uwXTY 9e99jukqSsOLKVYmNiaOU4SUUDqwvQZUZxSDxdt48cwCvIuxNWSBEKMEBdN1k9hz M3RF37ILy8Bl5qUDUwhnfxwXThIni8UIbnS5P2hgAzhawU5EoKy1mvwMLWZM6UQw tgXDS79OfKhE8ieMMS7/ =xmbV -----END PGP SIGNATURE----- --qLni7iB6Dl8qUSwk--