From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: qemu-devel@nongnu.org
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>,
Alistair Francis <alistair.francis@wdc.com>
Subject: [PATCH] hw/riscv: virt: pass random seed to fdt
Date: Mon, 13 Jun 2022 13:58:10 +0200 [thread overview]
Message-ID: <20220613115810.178210-1-Jason@zx2c4.com> (raw)
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-rc2.
Cc: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
hw/riscv/virt.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
index bc424dd2f5..368a723bf6 100644
--- a/hw/riscv/virt.c
+++ b/hw/riscv/virt.c
@@ -21,6 +21,7 @@
#include "qemu/osdep.h"
#include "qemu/units.h"
#include "qemu/error-report.h"
+#include "qemu/guest-random.h"
#include "qapi/error.h"
#include "hw/boards.h"
#include "hw/loader.h"
@@ -998,6 +999,7 @@ static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap,
MachineState *mc = MACHINE(s);
uint32_t phandle = 1, irq_mmio_phandle = 1, msi_pcie_phandle = 1;
uint32_t irq_pcie_phandle = 1, irq_virtio_phandle = 1;
+ uint8_t rng_seed[32];
if (mc->dtb) {
mc->fdt = load_device_tree(mc->dtb, &s->fdt_size);
@@ -1046,6 +1048,10 @@ update_bootargs:
if (cmdline && *cmdline) {
qemu_fdt_setprop_string(mc->fdt, "/chosen", "bootargs", cmdline);
}
+
+ /* Pass seed to RNG. */
+ qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed));
+ qemu_fdt_setprop(mc->fdt, "/chosen", "rng-seed", rng_seed, sizeof(rng_seed));
}
static inline DeviceState *gpex_pcie_init(MemoryRegion *sys_mem,
--
2.35.1
next reply other threads:[~2022-06-13 12:11 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-13 11:58 Jason A. Donenfeld [this message]
2022-06-15 4:05 ` [PATCH] hw/riscv: virt: pass random seed to fdt Bin Meng
2022-06-16 2:32 ` Alistair Francis
2022-06-16 10:01 ` Jason A. Donenfeld
2022-06-16 12:17 ` Alistair Francis
2022-06-29 2:09 ` Alistair Francis
2022-07-05 1:09 ` Jason A. Donenfeld
2022-07-07 1:04 ` Jason A. Donenfeld
2022-07-08 7:59 ` Alistair Francis
2022-07-08 9:56 ` Jason A. Donenfeld
2022-07-11 0:25 ` Alistair Francis
2022-07-11 0:27 ` Jason A. Donenfeld
2022-07-11 3:36 ` Alistair Francis
2022-07-11 16:45 ` Jason A. Donenfeld
2022-07-13 17:29 ` Jason A. Donenfeld
2022-07-18 22:39 ` Alistair Francis
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=20220613115810.178210-1-Jason@zx2c4.com \
--to=jason@zx2c4.com \
--cc=alistair.francis@wdc.com \
--cc=qemu-devel@nongnu.org \
/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).