qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Thomas Huth <thuth@redhat.com>, 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
Subject: Re: [Qemu-devel] [PATCH v2 1/2] spapr: Add support for hwrng when available
Date: Tue, 1 Sep 2015 10:38:08 +1000	[thread overview]
Message-ID: <20150901003808.GI11475@voom.redhat.com> (raw)
In-Reply-To: <1441046762-5788-2-git-send-email-thuth@redhat.com>

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

On Mon, Aug 31, 2015 at 08:46:01PM +0200, Thomas Huth wrote:
> From: Michael Ellerman <michael@ellerman.id.au>
> 
> 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.
> 
> 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.
> 
> Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
> [thuth: Refreshed patch so it applies to QEMU master branch]
> Signed-off-by: Thomas Huth <thuth@redhat.com>

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(+)
> 
> 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_base,
>  
>      _FDT((fdt_end_node(fdt)));
>  
> +    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);
>  
> 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
>  
> 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_HWRNG);
> +}
> 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);
>  
>  #else
>  
> @@ -248,6 +249,10 @@ static inline bool kvmppc_has_cap_fixup_hcalls(void)
>      abort();
>  }
>  
> +static inline bool kvmppc_hwrng_present(void)
> +{
> +    return false;
> +}
>  #endif
>  
>  #ifndef CONFIG_KVM

-- 
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 --]

  reply	other threads:[~2015-09-01  0:47 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-31 18:46 [Qemu-devel] [PATCH v2 0/2] ppc/spapr_hcall: Implement H_RANDOM hypercall Thomas Huth
2015-08-31 18:46 ` [Qemu-devel] [PATCH v2 1/2] spapr: Add support for hwrng when available Thomas Huth
2015-09-01  0:38   ` David Gibson [this message]
2015-09-01 10:53     ` Thomas Huth
2015-09-08  5:03       ` [Qemu-devel] [Qemu-ppc] " Sam Bobroff
2015-09-08  5:15         ` David Gibson
2015-09-09 21:10           ` Thomas Huth
2015-09-10  7:33             ` Thomas Huth
2015-09-10 10:40               ` David Gibson
2015-09-10 12:03                 ` Thomas Huth
2015-09-10 12:13                   ` Alexander Graf
2015-09-11  0:46                     ` David Gibson
2015-09-11  9:43                       ` Alexander Graf
2015-09-14  2:27                         ` David Gibson
2015-09-14  7:36                           ` Alexander Graf
2015-09-11  0:45                   ` David Gibson
2015-09-11  7:30                     ` Thomas Huth
2015-09-14  2:25                       ` David Gibson
2015-09-08  5:38         ` Thomas Huth
2015-09-09  0:54           ` Sam Bobroff
2015-09-10 12:06             ` Greg Kurz
2015-09-09 14:09   ` [Qemu-devel] " Greg Kurz
2015-08-31 18:46 ` [Qemu-devel] [PATCH v2 2/2] ppc/spapr_hcall: Implement H_RANDOM hypercall in QEMU Thomas Huth
2015-09-01  0:47   ` David Gibson
2015-09-01 11:03     ` Thomas Huth
2015-09-07 15:05     ` Thomas Huth
2015-09-08  1:14       ` David Gibson
2015-09-02  5:34   ` Amit Shah
2015-09-02  7:48     ` David Gibson
2015-09-02  8:58       ` Thomas Huth
2015-09-02 10:06         ` Amit Shah
2015-09-02 10:02       ` Amit Shah
2015-09-03  1:21       ` Michael Ellerman
2015-09-03  2:17         ` David Gibson

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=20150901003808.GI11475@voom.redhat.com \
    --to=david@gibson.dropbear.id.au \
    --cc=agraf@suse.de \
    --cc=amit.shah@redhat.com \
    --cc=armbru@redhat.com \
    --cc=itg@voom.redhat.com \
    --cc=michael@ellerman.id.au \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@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).