* [PATCH] hw/loongarch: virt: pass random seed to fdt
@ 2024-09-05 15:33 Jason A. Donenfeld
2024-09-09 1:38 ` gaosong
0 siblings, 1 reply; 4+ messages in thread
From: Jason A. Donenfeld @ 2024-09-05 15:33 UTC (permalink / raw)
To: gaosong, jiaxun.yang, qemu-devel, thomas, xry111, maobibo
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 the same procedure that's done in b91b6b5a2c ("hw/microblaze:
pass random seed to fdt"), e4b4f0b71c ("hw/riscv: virt: pass random seed
to fdt"), c6fe3e6b4c ("hw/openrisc: virt: pass random seed to fdt"),
67f7e426e5 ("hw/i386: pass RNG seed via setup_data entry"), c287941a4d
("hw/rx: pass random seed to fdt"), 5e19cc68fb ("hw/mips: boston: pass
random seed to fdt"), 6b23a67916 ("hw/nios2: virt: pass random seed to fdt")
c4b075318e ("hw/ppc: pass random seed to fdt"), and 5242876f37
("hw/arm/virt: dt: add rng-seed property").
These earlier commits later were amended to rerandomize the RNG seed on
snapshot load, but the LoongArch code somehow already does that, despite
not having this patch here, presumably due to some lucky copy and
pasting.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
hw/loongarch/virt.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index 29040422aa..0f0b7df205 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -48,6 +48,7 @@
#include "hw/block/flash.h"
#include "hw/virtio/virtio-iommu.h"
#include "qemu/error-report.h"
+#include "qemu/guest-random.h"
static bool virt_is_veiointc_enabled(LoongArchVirtMachineState *lvms)
{
@@ -303,6 +304,7 @@ static void fdt_add_uart_node(LoongArchVirtMachineState *lvms,
static void create_fdt(LoongArchVirtMachineState *lvms)
{
MachineState *ms = MACHINE(lvms);
+ uint8_t rng_seed[32];
ms->fdt = create_device_tree(&lvms->fdt_size);
if (!ms->fdt) {
@@ -316,6 +318,10 @@ static void create_fdt(LoongArchVirtMachineState *lvms)
qemu_fdt_setprop_cell(ms->fdt, "/", "#address-cells", 0x2);
qemu_fdt_setprop_cell(ms->fdt, "/", "#size-cells", 0x2);
qemu_fdt_add_subnode(ms->fdt, "/chosen");
+
+ /* Pass seed to RNG */
+ qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed));
+ qemu_fdt_setprop(ms->fdt, "/chosen", "rng-seed", rng_seed, sizeof(rng_seed));
}
static void fdt_add_cpu_nodes(const LoongArchVirtMachineState *lvms)
--
2.46.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] hw/loongarch: virt: pass random seed to fdt
2024-09-05 15:33 [PATCH] hw/loongarch: virt: pass random seed to fdt Jason A. Donenfeld
@ 2024-09-09 1:38 ` gaosong
2024-09-09 1:41 ` Jason A. Donenfeld
0 siblings, 1 reply; 4+ messages in thread
From: gaosong @ 2024-09-09 1:38 UTC (permalink / raw)
To: Jason A. Donenfeld, jiaxun.yang, qemu-devel, thomas, xry111,
maobibo
在 2024/9/5 下午11:33, 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 the same procedure that's done in b91b6b5a2c ("hw/microblaze:
> pass random seed to fdt"), e4b4f0b71c ("hw/riscv: virt: pass random seed
> to fdt"), c6fe3e6b4c ("hw/openrisc: virt: pass random seed to fdt"),
> 67f7e426e5 ("hw/i386: pass RNG seed via setup_data entry"), c287941a4d
> ("hw/rx: pass random seed to fdt"), 5e19cc68fb ("hw/mips: boston: pass
> random seed to fdt"), 6b23a67916 ("hw/nios2: virt: pass random seed to fdt")
> c4b075318e ("hw/ppc: pass random seed to fdt"), and 5242876f37
> ("hw/arm/virt: dt: add rng-seed property").
>
> These earlier commits later were amended to rerandomize the RNG seed on
> snapshot load, but the LoongArch code somehow already does that, despite
> not having this patch here, presumably due to some lucky copy and
> pasting.
>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
> hw/loongarch/virt.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
Reviewed-by: Song Gao <gaosong@loongson.cn>
Thanks
Song Gao
> diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
> index 29040422aa..0f0b7df205 100644
> --- a/hw/loongarch/virt.c
> +++ b/hw/loongarch/virt.c
> @@ -48,6 +48,7 @@
> #include "hw/block/flash.h"
> #include "hw/virtio/virtio-iommu.h"
> #include "qemu/error-report.h"
> +#include "qemu/guest-random.h"
>
> static bool virt_is_veiointc_enabled(LoongArchVirtMachineState *lvms)
> {
> @@ -303,6 +304,7 @@ static void fdt_add_uart_node(LoongArchVirtMachineState *lvms,
> static void create_fdt(LoongArchVirtMachineState *lvms)
> {
> MachineState *ms = MACHINE(lvms);
> + uint8_t rng_seed[32];
>
> ms->fdt = create_device_tree(&lvms->fdt_size);
> if (!ms->fdt) {
> @@ -316,6 +318,10 @@ static void create_fdt(LoongArchVirtMachineState *lvms)
> qemu_fdt_setprop_cell(ms->fdt, "/", "#address-cells", 0x2);
> qemu_fdt_setprop_cell(ms->fdt, "/", "#size-cells", 0x2);
> qemu_fdt_add_subnode(ms->fdt, "/chosen");
> +
> + /* Pass seed to RNG */
> + qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed));
> + qemu_fdt_setprop(ms->fdt, "/chosen", "rng-seed", rng_seed, sizeof(rng_seed));
> }
>
> static void fdt_add_cpu_nodes(const LoongArchVirtMachineState *lvms)
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] hw/loongarch: virt: pass random seed to fdt
2024-09-09 1:38 ` gaosong
@ 2024-09-09 1:41 ` Jason A. Donenfeld
2024-09-09 1:52 ` gaosong
0 siblings, 1 reply; 4+ messages in thread
From: Jason A. Donenfeld @ 2024-09-09 1:41 UTC (permalink / raw)
To: gaosong; +Cc: jiaxun.yang, qemu-devel, thomas, xry111, maobibo
On Mon, Sep 9, 2024 at 3:38 AM gaosong <gaosong@loongson.cn> wrote:
>
>
>
> 在 2024/9/5 下午11:33, 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 the same procedure that's done in b91b6b5a2c ("hw/microblaze:
> > pass random seed to fdt"), e4b4f0b71c ("hw/riscv: virt: pass random seed
> > to fdt"), c6fe3e6b4c ("hw/openrisc: virt: pass random seed to fdt"),
> > 67f7e426e5 ("hw/i386: pass RNG seed via setup_data entry"), c287941a4d
> > ("hw/rx: pass random seed to fdt"), 5e19cc68fb ("hw/mips: boston: pass
> > random seed to fdt"), 6b23a67916 ("hw/nios2: virt: pass random seed to fdt")
> > c4b075318e ("hw/ppc: pass random seed to fdt"), and 5242876f37
> > ("hw/arm/virt: dt: add rng-seed property").
> >
> > These earlier commits later were amended to rerandomize the RNG seed on
> > snapshot load, but the LoongArch code somehow already does that, despite
> > not having this patch here, presumably due to some lucky copy and
> > pasting.
> >
> > Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> > ---
> > hw/loongarch/virt.c | 6 ++++++
> > 1 file changed, 6 insertions(+)
> >
>
> Reviewed-by: Song Gao <gaosong@loongson.cn>
Do you generally queue these up in
https://gitlab.com/gaosong/qemu/-/commits/loongarch-next/?ref_type=heads
? Or is it a different branch?
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] hw/loongarch: virt: pass random seed to fdt
2024-09-09 1:41 ` Jason A. Donenfeld
@ 2024-09-09 1:52 ` gaosong
0 siblings, 0 replies; 4+ messages in thread
From: gaosong @ 2024-09-09 1:52 UTC (permalink / raw)
To: Jason A. Donenfeld; +Cc: jiaxun.yang, qemu-devel, thomas, xry111, maobibo
在 2024/9/9 上午9:41, Jason A. Donenfeld 写道:
> On Mon, Sep 9, 2024 at 3:38 AM gaosong <gaosong@loongson.cn> wrote:
>>
>>
>>
>> 在 2024/9/5 下午11:33, 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 the same procedure that's done in b91b6b5a2c ("hw/microblaze:
>>> pass random seed to fdt"), e4b4f0b71c ("hw/riscv: virt: pass random seed
>>> to fdt"), c6fe3e6b4c ("hw/openrisc: virt: pass random seed to fdt"),
>>> 67f7e426e5 ("hw/i386: pass RNG seed via setup_data entry"), c287941a4d
>>> ("hw/rx: pass random seed to fdt"), 5e19cc68fb ("hw/mips: boston: pass
>>> random seed to fdt"), 6b23a67916 ("hw/nios2: virt: pass random seed to fdt")
>>> c4b075318e ("hw/ppc: pass random seed to fdt"), and 5242876f37
>>> ("hw/arm/virt: dt: add rng-seed property").
>>>
>>> These earlier commits later were amended to rerandomize the RNG seed on
>>> snapshot load, but the LoongArch code somehow already does that, despite
>>> not having this patch here, presumably due to some lucky copy and
>>> pasting.
>>>
>>> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
>>> ---
>>> hw/loongarch/virt.c | 6 ++++++
>>> 1 file changed, 6 insertions(+)
>>>
>>
>> Reviewed-by: Song Gao <gaosong@loongson.cn>
>
> Do you generally queue these up in
> https://gitlab.com/gaosong/qemu/-/commits/loongarch-next/?ref_type=heads
> ?
Yes, PRs are usually submitted on Thursdays.
Thanks
Song Gao
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-09-09 1:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-05 15:33 [PATCH] hw/loongarch: virt: pass random seed to fdt Jason A. Donenfeld
2024-09-09 1:38 ` gaosong
2024-09-09 1:41 ` Jason A. Donenfeld
2024-09-09 1:52 ` gaosong
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).