]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
m68k: virt: pass RNG seed via bootinfo block
authorJason A. Donenfeld <Jason@zx2c4.com>
Sun, 26 Jun 2022 11:18:04 +0000 (13:18 +0200)
committerLaurent Vivier <laurent@vivier.eu>
Wed, 6 Jul 2022 10:30:41 +0000 (12:30 +0200)
This commit wires up bootinfo's RNG seed attribute so that Linux VMs can
have their RNG seeded from the earliest possible time in boot, just like
the "rng-seed" device tree property on those platforms. The link
contains the corresponding Linux patch.

Link: https://lore.kernel.org/lkml/20220626111509.330159-1-Jason@zx2c4.com/
Based-on: <20220625152318.120849-1-Jason@zx2c4.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
Message-Id: <20220626111804.330745-1-Jason@zx2c4.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
hw/m68k/bootinfo.h
hw/m68k/virt.c
include/standard-headers/asm-m68k/bootinfo-virt.h

index ff4e155a3cc84b8057a6bf20c16848f098c3de2b..bd8b212fd35ce216917e07eb67783b5b69f1e11b 100644 (file)
         stb_phys(as, base++, 0); \
         base = (base + 1) & ~1; \
     } while (0)
+
+#define BOOTINFODATA(as, base, id, data, len) \
+    do { \
+        int i; \
+        stw_phys(as, base, id); \
+        base += 2; \
+        stw_phys(as, base, \
+                 (sizeof(struct bi_record) + len + 3) & ~1); \
+        base += 2; \
+        stw_phys(as, base, len); \
+        base += 2; \
+        for (i = 0; i < len; ++i) { \
+            stb_phys(as, base++, data[i]); \
+        } \
+        base = (base + 1) & ~1; \
+    } while (0)
 #endif
index e215aa3d42170872b86b1bbf15e65a65d4d88837..0aa383fa6bdae194fbc5cb8208d5364e37a2a1ef 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/units.h"
+#include "qemu/guest-random.h"
 #include "sysemu/sysemu.h"
 #include "cpu.h"
 #include "hw/boards.h"
@@ -120,6 +121,7 @@ static void virt_init(MachineState *machine)
     hwaddr io_base;
     int i;
     ResetInfo *reset_info;
+    uint8_t rng_seed[32];
 
     if (ram_size > 3399672 * KiB) {
         /*
@@ -245,6 +247,11 @@ static void virt_init(MachineState *machine)
                         kernel_cmdline);
         }
 
+       /* Pass seed to RNG. */
+       qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed));
+       BOOTINFODATA(cs->as, parameters_base, BI_VIRT_RNG_SEED,
+                    rng_seed, sizeof(rng_seed));
+
         /* load initrd */
         if (initrd_filename) {
             initrd_size = get_image_size(initrd_filename);
index 81be1e092497b241f6f31ae0ea67e0baa57f5d40..1b1ffd4705d683fdeb1425041364f33b7002f735 100644 (file)
@@ -12,6 +12,7 @@
 #define BI_VIRT_GF_TTY_BASE    0x8003
 #define BI_VIRT_VIRTIO_BASE    0x8004
 #define BI_VIRT_CTRL_BASE      0x8005
+#define BI_VIRT_RNG_SEED       0x8006
 
 #define VIRT_BOOTI_VERSION     MK_BI_VERSION(2, 0)