qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw/ppc: pass random seed to fdt
@ 2022-07-12 13:51 Jason A. Donenfeld
  2022-07-12 20:26 ` Daniel Henrique Barboza
  2022-07-14 13:01 ` Daniel Henrique Barboza
  0 siblings, 2 replies; 7+ messages in thread
From: Jason A. Donenfeld @ 2022-07-12 13:51 UTC (permalink / raw)
  To: danielhb413, qemu-devel; +Cc: Jason A. Donenfeld

If the FDT contains /chosen/rng-seed, then the Linux RNG will use it to
initialize early. Set this using the usual guest random number
generation function. This is confirmed to successfully initialize the
RNG on Linux 5.19-rc6. The rng-seed node is part of the DT spec. Set
this on the paravirt platforms, spapr and e500, just as is done on other
architectures with paravirt hardware.

Cc: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 hw/ppc/e500.c  | 5 +++++
 hw/ppc/spapr.c | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index 7f7f5b3452..2f86eb490e 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -17,6 +17,7 @@
 #include "qemu/osdep.h"
 #include "qemu/datadir.h"
 #include "qemu/units.h"
+#include "qemu/guest-random.h"
 #include "qapi/error.h"
 #include "e500.h"
 #include "e500-ccsr.h"
@@ -346,6 +347,7 @@ static int ppce500_load_device_tree(PPCE500MachineState *pms,
         };
     const char *dtb_file = machine->dtb;
     const char *toplevel_compat = machine->dt_compatible;
+    uint8_t rng_seed[32];
 
     if (dtb_file) {
         char *filename;
@@ -403,6 +405,9 @@ static int ppce500_load_device_tree(PPCE500MachineState *pms,
     if (ret < 0)
         fprintf(stderr, "couldn't set /chosen/bootargs\n");
 
+    qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed));
+    qemu_fdt_setprop(fdt, "/chosen", "rng-seed", rng_seed, sizeof(rng_seed));
+
     if (kvm_enabled()) {
         /* Read out host's frequencies */
         clock_freq = kvmppc_get_clockfreq();
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 9a5382d527..3a5112899e 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -27,6 +27,7 @@
 #include "qemu/osdep.h"
 #include "qemu/datadir.h"
 #include "qemu/memalign.h"
+#include "qemu/guest-random.h"
 #include "qapi/error.h"
 #include "qapi/qapi-events-machine.h"
 #include "qapi/qapi-events-qdev.h"
@@ -1014,6 +1015,7 @@ static void spapr_dt_chosen(SpaprMachineState *spapr, void *fdt, bool reset)
 {
     MachineState *machine = MACHINE(spapr);
     SpaprMachineClass *smc = SPAPR_MACHINE_GET_CLASS(machine);
+    uint8_t rng_seed[32];
     int chosen;
 
     _FDT(chosen = fdt_add_subnode(fdt, 0, "chosen"));
@@ -1091,6 +1093,9 @@ static void spapr_dt_chosen(SpaprMachineState *spapr, void *fdt, bool reset)
         spapr_dt_ov5_platform_support(spapr, fdt, chosen);
     }
 
+    qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed));
+    _FDT(fdt_setprop(fdt, chosen, "rng-seed", rng_seed, sizeof(rng_seed)));
+
     _FDT(spapr_dt_ovec(fdt, chosen, spapr->ov5_cas, "ibm,architecture-vec-5"));
 }
 
-- 
2.35.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] hw/ppc: pass random seed to fdt
  2022-07-12 13:51 [PATCH] hw/ppc: pass random seed to fdt Jason A. Donenfeld
@ 2022-07-12 20:26 ` Daniel Henrique Barboza
  2022-07-12 20:31   ` Daniel Henrique Barboza
  2022-07-14 13:01 ` Daniel Henrique Barboza
  1 sibling, 1 reply; 7+ messages in thread
From: Daniel Henrique Barboza @ 2022-07-12 20:26 UTC (permalink / raw)
  To: Jason A. Donenfeld, qemu-devel



On 7/12/22 10:51, Jason A. Donenfeld wrote:
> If the FDT contains /chosen/rng-seed, then the Linux RNG will use it to
> initialize early. Set this using the usual guest random number
> generation function. This is confirmed to successfully initialize the
> RNG on Linux 5.19-rc6. The rng-seed node is part of the DT spec. Set
> this on the paravirt platforms, spapr and e500, just as is done on other
> architectures with paravirt hardware.
> 
> Cc: Daniel Henrique Barboza <danielhb413@gmail.com>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---

With current QEMU master, running a fedora 36 ppc64le guest with a
5.19.0-rc2-00054-g12ede8ffb103 kernel :

[root@fedora ~]# dmesg | grep -i rng
[    5.130623] random: crng init done
[root@fedora ~]#


After applying this patch:


[root@fedora ~]# dmesg | grep -i rng
[    0.000000] random: crng init done
[root@fedora ~]#



Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>




>   hw/ppc/e500.c  | 5 +++++
>   hw/ppc/spapr.c | 5 +++++
>   2 files changed, 10 insertions(+)
> 
> diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
> index 7f7f5b3452..2f86eb490e 100644
> --- a/hw/ppc/e500.c
> +++ b/hw/ppc/e500.c
> @@ -17,6 +17,7 @@
>   #include "qemu/osdep.h"
>   #include "qemu/datadir.h"
>   #include "qemu/units.h"
> +#include "qemu/guest-random.h"
>   #include "qapi/error.h"
>   #include "e500.h"
>   #include "e500-ccsr.h"
> @@ -346,6 +347,7 @@ static int ppce500_load_device_tree(PPCE500MachineState *pms,
>           };
>       const char *dtb_file = machine->dtb;
>       const char *toplevel_compat = machine->dt_compatible;
> +    uint8_t rng_seed[32];
>   
>       if (dtb_file) {
>           char *filename;
> @@ -403,6 +405,9 @@ static int ppce500_load_device_tree(PPCE500MachineState *pms,
>       if (ret < 0)
>           fprintf(stderr, "couldn't set /chosen/bootargs\n");
>   
> +    qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed));
> +    qemu_fdt_setprop(fdt, "/chosen", "rng-seed", rng_seed, sizeof(rng_seed));
> +
>       if (kvm_enabled()) {
>           /* Read out host's frequencies */
>           clock_freq = kvmppc_get_clockfreq();
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 9a5382d527..3a5112899e 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -27,6 +27,7 @@
>   #include "qemu/osdep.h"
>   #include "qemu/datadir.h"
>   #include "qemu/memalign.h"
> +#include "qemu/guest-random.h"
>   #include "qapi/error.h"
>   #include "qapi/qapi-events-machine.h"
>   #include "qapi/qapi-events-qdev.h"
> @@ -1014,6 +1015,7 @@ static void spapr_dt_chosen(SpaprMachineState *spapr, void *fdt, bool reset)
>   {
>       MachineState *machine = MACHINE(spapr);
>       SpaprMachineClass *smc = SPAPR_MACHINE_GET_CLASS(machine);
> +    uint8_t rng_seed[32];
>       int chosen;
>   
>       _FDT(chosen = fdt_add_subnode(fdt, 0, "chosen"));
> @@ -1091,6 +1093,9 @@ static void spapr_dt_chosen(SpaprMachineState *spapr, void *fdt, bool reset)
>           spapr_dt_ov5_platform_support(spapr, fdt, chosen);
>       }
>   
> +    qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed));
> +    _FDT(fdt_setprop(fdt, chosen, "rng-seed", rng_seed, sizeof(rng_seed)));
> +
>       _FDT(spapr_dt_ovec(fdt, chosen, spapr->ov5_cas, "ibm,architecture-vec-5"));
>   }
>   


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] hw/ppc: pass random seed to fdt
  2022-07-12 20:26 ` Daniel Henrique Barboza
@ 2022-07-12 20:31   ` Daniel Henrique Barboza
  2022-07-13 17:30     ` Jason A. Donenfeld
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Henrique Barboza @ 2022-07-12 20:31 UTC (permalink / raw)
  To: Jason A. Donenfeld, qemu-devel; +Cc: qemu-ppc@nongnu.org, Cedric Le Goater

CCing qemu-ppc and Cedric for awareness since I forgot to do so in
my reply (⌒_⌒;)



Daniel

On 7/12/22 17:26, Daniel Henrique Barboza wrote:
> 
> 
> On 7/12/22 10:51, Jason A. Donenfeld wrote:
>> If the FDT contains /chosen/rng-seed, then the Linux RNG will use it to
>> initialize early. Set this using the usual guest random number
>> generation function. This is confirmed to successfully initialize the
>> RNG on Linux 5.19-rc6. The rng-seed node is part of the DT spec. Set
>> this on the paravirt platforms, spapr and e500, just as is done on other
>> architectures with paravirt hardware.
>>
>> Cc: Daniel Henrique Barboza <danielhb413@gmail.com>
>> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
>> ---
> 
> With current QEMU master, running a fedora 36 ppc64le guest with a
> 5.19.0-rc2-00054-g12ede8ffb103 kernel :
> 
> [root@fedora ~]# dmesg | grep -i rng
> [    5.130623] random: crng init done
> [root@fedora ~]#
> 
> 
> After applying this patch:
> 
> 
> [root@fedora ~]# dmesg | grep -i rng
> [    0.000000] random: crng init done
> [root@fedora ~]#
> 
> 
> 
> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
> 
> 
> 
> 
>>   hw/ppc/e500.c  | 5 +++++
>>   hw/ppc/spapr.c | 5 +++++
>>   2 files changed, 10 insertions(+)
>>
>> diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
>> index 7f7f5b3452..2f86eb490e 100644
>> --- a/hw/ppc/e500.c
>> +++ b/hw/ppc/e500.c
>> @@ -17,6 +17,7 @@
>>   #include "qemu/osdep.h"
>>   #include "qemu/datadir.h"
>>   #include "qemu/units.h"
>> +#include "qemu/guest-random.h"
>>   #include "qapi/error.h"
>>   #include "e500.h"
>>   #include "e500-ccsr.h"
>> @@ -346,6 +347,7 @@ static int ppce500_load_device_tree(PPCE500MachineState *pms,
>>           };
>>       const char *dtb_file = machine->dtb;
>>       const char *toplevel_compat = machine->dt_compatible;
>> +    uint8_t rng_seed[32];
>>       if (dtb_file) {
>>           char *filename;
>> @@ -403,6 +405,9 @@ static int ppce500_load_device_tree(PPCE500MachineState *pms,
>>       if (ret < 0)
>>           fprintf(stderr, "couldn't set /chosen/bootargs\n");
>> +    qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed));
>> +    qemu_fdt_setprop(fdt, "/chosen", "rng-seed", rng_seed, sizeof(rng_seed));
>> +
>>       if (kvm_enabled()) {
>>           /* Read out host's frequencies */
>>           clock_freq = kvmppc_get_clockfreq();
>> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
>> index 9a5382d527..3a5112899e 100644
>> --- a/hw/ppc/spapr.c
>> +++ b/hw/ppc/spapr.c
>> @@ -27,6 +27,7 @@
>>   #include "qemu/osdep.h"
>>   #include "qemu/datadir.h"
>>   #include "qemu/memalign.h"
>> +#include "qemu/guest-random.h"
>>   #include "qapi/error.h"
>>   #include "qapi/qapi-events-machine.h"
>>   #include "qapi/qapi-events-qdev.h"
>> @@ -1014,6 +1015,7 @@ static void spapr_dt_chosen(SpaprMachineState *spapr, void *fdt, bool reset)
>>   {
>>       MachineState *machine = MACHINE(spapr);
>>       SpaprMachineClass *smc = SPAPR_MACHINE_GET_CLASS(machine);
>> +    uint8_t rng_seed[32];
>>       int chosen;
>>       _FDT(chosen = fdt_add_subnode(fdt, 0, "chosen"));
>> @@ -1091,6 +1093,9 @@ static void spapr_dt_chosen(SpaprMachineState *spapr, void *fdt, bool reset)
>>           spapr_dt_ov5_platform_support(spapr, fdt, chosen);
>>       }
>> +    qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed));
>> +    _FDT(fdt_setprop(fdt, chosen, "rng-seed", rng_seed, sizeof(rng_seed)));
>> +
>>       _FDT(spapr_dt_ovec(fdt, chosen, spapr->ov5_cas, "ibm,architecture-vec-5"));
>>   }


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] hw/ppc: pass random seed to fdt
  2022-07-12 20:31   ` Daniel Henrique Barboza
@ 2022-07-13 17:30     ` Jason A. Donenfeld
  2022-07-13 17:37       ` Daniel Henrique Barboza
  0 siblings, 1 reply; 7+ messages in thread
From: Jason A. Donenfeld @ 2022-07-13 17:30 UTC (permalink / raw)
  To: Daniel Henrique Barboza; +Cc: qemu-devel, qemu-ppc@nongnu.org, Cedric Le Goater

Hi Daniel,

On Tue, Jul 12, 2022 at 05:31:27PM -0300, Daniel Henrique Barboza wrote:
> CCing qemu-ppc and Cedric for awareness since I forgot to do so in
> my reply (⌒_⌒;)
> > Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>

Thanks for the review and for forwarding this to qemu-ppc. What's the
route this patch needs to take in order to make it into some tree
somewhere? Can somebody queue it up?

Regards,
Jason


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] hw/ppc: pass random seed to fdt
  2022-07-13 17:30     ` Jason A. Donenfeld
@ 2022-07-13 17:37       ` Daniel Henrique Barboza
  2022-07-13 17:38         ` Jason A. Donenfeld
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Henrique Barboza @ 2022-07-13 17:37 UTC (permalink / raw)
  To: Jason A. Donenfeld; +Cc: qemu-devel, qemu-ppc@nongnu.org, Cedric Le Goater



On 7/13/22 14:30, Jason A. Donenfeld wrote:
> Hi Daniel,
> 
> On Tue, Jul 12, 2022 at 05:31:27PM -0300, Daniel Henrique Barboza wrote:
>> CCing qemu-ppc and Cedric for awareness since I forgot to do so in
>> my reply (⌒_⌒;)
>>> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
> 
> Thanks for the review and for forwarding this to qemu-ppc. What's the
> route this patch needs to take in order to make it into some tree
> somewhere? Can somebody queue it up?


I'll queue it up shortly in my ppc-next tree in Gitlab at

gitlab.com/danielhb/qemu/tree/ppc-next


After that I'll send a pull request get it merged with upstream. Probably
end of this week/next Monday.


Thanks,


Daniel


> 
> Regards,
> Jason


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] hw/ppc: pass random seed to fdt
  2022-07-13 17:37       ` Daniel Henrique Barboza
@ 2022-07-13 17:38         ` Jason A. Donenfeld
  0 siblings, 0 replies; 7+ messages in thread
From: Jason A. Donenfeld @ 2022-07-13 17:38 UTC (permalink / raw)
  To: Daniel Henrique Barboza
  Cc: QEMU Developers, qemu-ppc@nongnu.org, Cedric Le Goater

Hi Daniel,

On Wed, Jul 13, 2022 at 7:37 PM Daniel Henrique Barboza
<danielhb413@gmail.com> wrote:
>
>
>
> On 7/13/22 14:30, Jason A. Donenfeld wrote:
> > Hi Daniel,
> >
> > On Tue, Jul 12, 2022 at 05:31:27PM -0300, Daniel Henrique Barboza wrote:
> >> CCing qemu-ppc and Cedric for awareness since I forgot to do so in
> >> my reply (⌒_⌒;)
> >>> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
> >
> > Thanks for the review and for forwarding this to qemu-ppc. What's the
> > route this patch needs to take in order to make it into some tree
> > somewhere? Can somebody queue it up?
>
>
> I'll queue it up shortly in my ppc-next tree in Gitlab at
>
> gitlab.com/danielhb/qemu/tree/ppc-next
>
>
> After that I'll send a pull request get it merged with upstream. Probably
> end of this week/next Monday.

Excellent, thanks!

Jason


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] hw/ppc: pass random seed to fdt
  2022-07-12 13:51 [PATCH] hw/ppc: pass random seed to fdt Jason A. Donenfeld
  2022-07-12 20:26 ` Daniel Henrique Barboza
@ 2022-07-14 13:01 ` Daniel Henrique Barboza
  1 sibling, 0 replies; 7+ messages in thread
From: Daniel Henrique Barboza @ 2022-07-14 13:01 UTC (permalink / raw)
  To: Jason A. Donenfeld, qemu-devel, qemu-ppc@nongnu.org

Queued in gitlab.com/danielhb/qemu/tree/ppc-next. Thanks,


Daniel

On 7/12/22 10:51, Jason A. Donenfeld wrote:
> If the FDT contains /chosen/rng-seed, then the Linux RNG will use it to
> initialize early. Set this using the usual guest random number
> generation function. This is confirmed to successfully initialize the
> RNG on Linux 5.19-rc6. The rng-seed node is part of the DT spec. Set
> this on the paravirt platforms, spapr and e500, just as is done on other
> architectures with paravirt hardware.
> 
> Cc: Daniel Henrique Barboza <danielhb413@gmail.com>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
>   hw/ppc/e500.c  | 5 +++++
>   hw/ppc/spapr.c | 5 +++++
>   2 files changed, 10 insertions(+)
> 
> diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
> index 7f7f5b3452..2f86eb490e 100644
> --- a/hw/ppc/e500.c
> +++ b/hw/ppc/e500.c
> @@ -17,6 +17,7 @@
>   #include "qemu/osdep.h"
>   #include "qemu/datadir.h"
>   #include "qemu/units.h"
> +#include "qemu/guest-random.h"
>   #include "qapi/error.h"
>   #include "e500.h"
>   #include "e500-ccsr.h"
> @@ -346,6 +347,7 @@ static int ppce500_load_device_tree(PPCE500MachineState *pms,
>           };
>       const char *dtb_file = machine->dtb;
>       const char *toplevel_compat = machine->dt_compatible;
> +    uint8_t rng_seed[32];
>   
>       if (dtb_file) {
>           char *filename;
> @@ -403,6 +405,9 @@ static int ppce500_load_device_tree(PPCE500MachineState *pms,
>       if (ret < 0)
>           fprintf(stderr, "couldn't set /chosen/bootargs\n");
>   
> +    qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed));
> +    qemu_fdt_setprop(fdt, "/chosen", "rng-seed", rng_seed, sizeof(rng_seed));
> +
>       if (kvm_enabled()) {
>           /* Read out host's frequencies */
>           clock_freq = kvmppc_get_clockfreq();
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 9a5382d527..3a5112899e 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -27,6 +27,7 @@
>   #include "qemu/osdep.h"
>   #include "qemu/datadir.h"
>   #include "qemu/memalign.h"
> +#include "qemu/guest-random.h"
>   #include "qapi/error.h"
>   #include "qapi/qapi-events-machine.h"
>   #include "qapi/qapi-events-qdev.h"
> @@ -1014,6 +1015,7 @@ static void spapr_dt_chosen(SpaprMachineState *spapr, void *fdt, bool reset)
>   {
>       MachineState *machine = MACHINE(spapr);
>       SpaprMachineClass *smc = SPAPR_MACHINE_GET_CLASS(machine);
> +    uint8_t rng_seed[32];
>       int chosen;
>   
>       _FDT(chosen = fdt_add_subnode(fdt, 0, "chosen"));
> @@ -1091,6 +1093,9 @@ static void spapr_dt_chosen(SpaprMachineState *spapr, void *fdt, bool reset)
>           spapr_dt_ov5_platform_support(spapr, fdt, chosen);
>       }
>   
> +    qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed));
> +    _FDT(fdt_setprop(fdt, chosen, "rng-seed", rng_seed, sizeof(rng_seed)));
> +
>       _FDT(spapr_dt_ovec(fdt, chosen, spapr->ov5_cas, "ibm,architecture-vec-5"));
>   }
>   


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-07-14 13:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-12 13:51 [PATCH] hw/ppc: pass random seed to fdt Jason A. Donenfeld
2022-07-12 20:26 ` Daniel Henrique Barboza
2022-07-12 20:31   ` Daniel Henrique Barboza
2022-07-13 17:30     ` Jason A. Donenfeld
2022-07-13 17:37       ` Daniel Henrique Barboza
2022-07-13 17:38         ` Jason A. Donenfeld
2022-07-14 13:01 ` Daniel Henrique Barboza

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).