All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH qemu] m68k: virt: pass RNG seed via bootinfo block
@ 2022-06-25 15:44 Jason A. Donenfeld
  2022-06-25 16:34 ` Laurent Vivier
  0 siblings, 1 reply; 4+ messages in thread
From: Jason A. Donenfeld @ 2022-06-25 15:44 UTC (permalink / raw)
  To: Laurent Vivier, Mark Cave-Ayland, geert, linux-m68k, qemu-devel
  Cc: Jason A. Donenfeld

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/20220625153841.143928-1-Jason@zx2c4.com/
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
This requires this trivial cleanup commit first:
    https://lore.kernel.org/qemu-devel/20220625152318.120849-1-Jason@zx2c4.com/

 hw/m68k/bootinfo.h                               | 16 ++++++++++++++++
 hw/m68k/virt.c                                   |  7 +++++++
 .../standard-headers/asm-m68k/bootinfo-virt.h    |  1 +
 3 files changed, 24 insertions(+)

diff --git a/hw/m68k/bootinfo.h b/hw/m68k/bootinfo.h
index ff4e155a3c..2f31c13b6e 100644
--- a/hw/m68k/bootinfo.h
+++ b/hw/m68k/bootinfo.h
@@ -56,4 +56,20 @@
         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 + 5) & ~1); \
+        base += 2; \
+        stl_phys(as, base, len); \
+        base += 4; \
+        for (i = 0; i < len; ++i) { \
+            stb_phys(as, base++, data[i]); \
+        } \
+        base = (base + 1) & ~1; \
+    } while (0)
 #endif
diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c
index e215aa3d42..0aa383fa6b 100644
--- a/hw/m68k/virt.c
+++ b/hw/m68k/virt.c
@@ -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);
diff --git a/include/standard-headers/asm-m68k/bootinfo-virt.h b/include/standard-headers/asm-m68k/bootinfo-virt.h
index 81be1e0924..1b1ffd4705 100644
--- a/include/standard-headers/asm-m68k/bootinfo-virt.h
+++ b/include/standard-headers/asm-m68k/bootinfo-virt.h
@@ -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)
 
-- 
2.35.1


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

* Re: [PATCH qemu] m68k: virt: pass RNG seed via bootinfo block
  2022-06-25 15:44 [PATCH qemu] m68k: virt: pass RNG seed via bootinfo block Jason A. Donenfeld
@ 2022-06-25 16:34 ` Laurent Vivier
  2022-06-26 11:18   ` [PATCH v2] " Jason A. Donenfeld
  0 siblings, 1 reply; 4+ messages in thread
From: Laurent Vivier @ 2022-06-25 16:34 UTC (permalink / raw)
  To: Jason A. Donenfeld, Mark Cave-Ayland, geert, linux-m68k, qemu-devel

Le 25/06/2022 à 17:44, Jason A. Donenfeld a écrit :
> 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/20220625153841.143928-1-Jason@zx2c4.com/
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
> This requires this trivial cleanup commit first:
>      https://lore.kernel.org/qemu-devel/20220625152318.120849-1-Jason@zx2c4.com/

For patchew, the syntax is:

Based-on: <20220625152318.120849-1-Jason@zx2c4.com>

> 
>   hw/m68k/bootinfo.h                               | 16 ++++++++++++++++
>   hw/m68k/virt.c                                   |  7 +++++++
>   .../standard-headers/asm-m68k/bootinfo-virt.h    |  1 +
>   3 files changed, 24 insertions(+)
> 
> diff --git a/hw/m68k/bootinfo.h b/hw/m68k/bootinfo.h
> index ff4e155a3c..2f31c13b6e 100644
> --- a/hw/m68k/bootinfo.h
> +++ b/hw/m68k/bootinfo.h
> @@ -56,4 +56,20 @@
>           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 + 5) & ~1); \
> +        base += 2; \
> +        stl_phys(as, base, len); \
> +        base += 4; \
> +        for (i = 0; i < len; ++i) { \
> +            stb_phys(as, base++, data[i]); \
> +        } \
> +        base = (base + 1) & ~1; \
> +    } while (0)
>   #endif
> diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c
> index e215aa3d42..0aa383fa6b 100644
> --- a/hw/m68k/virt.c
> +++ b/hw/m68k/virt.c
> @@ -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);
> diff --git a/include/standard-headers/asm-m68k/bootinfo-virt.h b/include/standard-headers/asm-m68k/bootinfo-virt.h
> index 81be1e0924..1b1ffd4705 100644
> --- a/include/standard-headers/asm-m68k/bootinfo-virt.h
> +++ b/include/standard-headers/asm-m68k/bootinfo-virt.h
> @@ -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)
>   

Reviewed-by: Laurent Vivier <laurent@vivier.eu>

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

* [PATCH v2] m68k: virt: pass RNG seed via bootinfo block
  2022-06-25 16:34 ` Laurent Vivier
@ 2022-06-26 11:18   ` Jason A. Donenfeld
  2022-07-06  9:05     ` Geert Uytterhoeven
  0 siblings, 1 reply; 4+ messages in thread
From: Jason A. Donenfeld @ 2022-06-26 11:18 UTC (permalink / raw)
  To: Mark Cave-Ayland, geert, linux-m68k, qemu-devel, Laurent Vivier
  Cc: Jason A. Donenfeld

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>
---
 hw/m68k/bootinfo.h                               | 16 ++++++++++++++++
 hw/m68k/virt.c                                   |  7 +++++++
 .../standard-headers/asm-m68k/bootinfo-virt.h    |  1 +
 3 files changed, 24 insertions(+)

diff --git a/hw/m68k/bootinfo.h b/hw/m68k/bootinfo.h
index ff4e155a3c..bd8b212fd3 100644
--- a/hw/m68k/bootinfo.h
+++ b/hw/m68k/bootinfo.h
@@ -56,4 +56,20 @@
         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
diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c
index e215aa3d42..0aa383fa6b 100644
--- a/hw/m68k/virt.c
+++ b/hw/m68k/virt.c
@@ -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);
diff --git a/include/standard-headers/asm-m68k/bootinfo-virt.h b/include/standard-headers/asm-m68k/bootinfo-virt.h
index 81be1e0924..1b1ffd4705 100644
--- a/include/standard-headers/asm-m68k/bootinfo-virt.h
+++ b/include/standard-headers/asm-m68k/bootinfo-virt.h
@@ -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)
 
-- 
2.35.1


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

* Re: [PATCH v2] m68k: virt: pass RNG seed via bootinfo block
  2022-06-26 11:18   ` [PATCH v2] " Jason A. Donenfeld
@ 2022-07-06  9:05     ` Geert Uytterhoeven
  0 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2022-07-06  9:05 UTC (permalink / raw)
  To: Jason A. Donenfeld
  Cc: Mark Cave-Ayland, linux-m68k, QEMU Developers, Laurent Vivier

On Sun, Jun 26, 2022 at 1:18 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote:
> 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>

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

end of thread, other threads:[~2022-07-06  9:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-25 15:44 [PATCH qemu] m68k: virt: pass RNG seed via bootinfo block Jason A. Donenfeld
2022-06-25 16:34 ` Laurent Vivier
2022-06-26 11:18   ` [PATCH v2] " Jason A. Donenfeld
2022-07-06  9:05     ` Geert Uytterhoeven

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.