summaryrefslogtreecommitdiffstats
path: root/softmmu
diff options
context:
space:
mode:
authorJason A. Donenfeld2022-10-25 02:43:18 +0200
committerPeter Maydell2022-10-27 12:34:31 +0200
commite1e618b9a0f9c23e9caa5933fa30ee3d33e00bfe (patch)
treec0120a03d9d9ae3dfd1cddccf5fcca624e7b8026 /softmmu
parentreset: allow registering handlers that aren't called by snapshot loading (diff)
downloadqemu-e1e618b9a0f9c23e9caa5933fa30ee3d33e00bfe.tar.gz
qemu-e1e618b9a0f9c23e9caa5933fa30ee3d33e00bfe.tar.xz
qemu-e1e618b9a0f9c23e9caa5933fa30ee3d33e00bfe.zip
device-tree: add re-randomization helper function
When the system reboots, the rng-seed that the FDT has should be re-randomized, so that the new boot gets a new seed. Several architectures require this functionality, so export a function for injecting a new seed into the given FDT. Cc: Alistair Francis <alistair.francis@wdc.com> Cc: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Message-id: 20221025004327.568476-3-Jason@zx2c4.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'softmmu')
-rw-r--r--softmmu/device_tree.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c
index ce74f3d48d..30aa3aea9f 100644
--- a/softmmu/device_tree.c
+++ b/softmmu/device_tree.c
@@ -22,6 +22,7 @@
#include "qemu/option.h"
#include "qemu/bswap.h"
#include "qemu/cutils.h"
+#include "qemu/guest-random.h"
#include "sysemu/device_tree.h"
#include "hw/loader.h"
#include "hw/boards.h"
@@ -680,3 +681,23 @@ void hmp_dumpdtb(Monitor *mon, const QDict *qdict)
info_report("dtb dumped to %s", filename);
}
+
+void qemu_fdt_randomize_seeds(void *fdt)
+{
+ int noffset, poffset, len;
+ const char *name;
+ uint8_t *data;
+
+ for (noffset = fdt_next_node(fdt, 0, NULL);
+ noffset >= 0;
+ noffset = fdt_next_node(fdt, noffset, NULL)) {
+ for (poffset = fdt_first_property_offset(fdt, noffset);
+ poffset >= 0;
+ poffset = fdt_next_property_offset(fdt, poffset)) {
+ data = (uint8_t *)fdt_getprop_by_offset(fdt, poffset, &name, &len);
+ if (!data || strcmp(name, "rng-seed"))
+ continue;
+ qemu_guest_getrandom_nofail(data, len);
+ }
+ }
+}