qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH qemu v2 1/2] m68k: rework BI_VIRT_RNG_SEED as BI_RNG_SEED
@ 2022-09-26 11:38 Jason A. Donenfeld
  2022-09-26 11:39 ` [PATCH qemu v2 2/2] m68k: align bootinfo strings and data to 4 bytes Jason A. Donenfeld
  2022-09-29  6:37 ` [PATCH qemu v2 1/2] m68k: rework BI_VIRT_RNG_SEED as BI_RNG_SEED Laurent Vivier
  0 siblings, 2 replies; 9+ messages in thread
From: Jason A. Donenfeld @ 2022-09-26 11:38 UTC (permalink / raw)
  To: linux-m68k, qemu-devel
  Cc: Jason A. Donenfeld, Geert Uytterhoeven, Laurent Vivier

Following a change on the kernel side (see link), pass BI_RNG_SEED
instead of BI_VIRT_RNG_SEED. This should have no impact on
compatibility, as there will simply be no effect if it's an old kernel,
which is how things have always been. We then use this as an opportunity
to add this to q800, since now we can, which is a nice improvement.

Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Laurent Vivier <laurent@vivier.eu>
Link: https://lore.kernel.org/lkml/20220923170340.4099226-3-Jason@zx2c4.com/
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 hw/m68k/q800.c                                    | 7 +++++++
 hw/m68k/virt.c                                    | 2 +-
 include/standard-headers/asm-m68k/bootinfo-virt.h | 4 +++-
 include/standard-headers/asm-m68k/bootinfo.h      | 8 +++++++-
 4 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
index 101ab0f803..9106382066 100644
--- a/hw/m68k/q800.c
+++ b/hw/m68k/q800.c
@@ -23,6 +23,7 @@
 #include "qemu/osdep.h"
 #include "qemu/units.h"
 #include "qemu/datadir.h"
+#include "qemu/guest-random.h"
 #include "sysemu/sysemu.h"
 #include "cpu.h"
 #include "hw/boards.h"
@@ -385,6 +386,7 @@ static void q800_init(MachineState *machine)
     NubusBus *nubus;
     DeviceState *glue;
     DriveInfo *dinfo;
+    uint8_t rng_seed[32];
 
     linux_boot = (kernel_filename != NULL);
 
@@ -634,6 +636,11 @@ static void q800_init(MachineState *machine)
                         kernel_cmdline);
         }
 
+	/* Pass seed to RNG. */
+	qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed));
+	BOOTINFODATA(cs->as, parameters_base, BI_RNG_SEED,
+		     rng_seed, sizeof(rng_seed));
+
         /* load initrd */
         if (initrd_filename) {
             initrd_size = get_image_size(initrd_filename);
diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c
index 2f3ffc0de6..7180325e54 100644
--- a/hw/m68k/virt.c
+++ b/hw/m68k/virt.c
@@ -250,7 +250,7 @@ static void virt_init(MachineState *machine)
 
 	/* Pass seed to RNG. */
 	qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed));
-	BOOTINFODATA(cs->as, parameters_base, BI_VIRT_RNG_SEED,
+	BOOTINFODATA(cs->as, parameters_base, BI_RNG_SEED,
 		     rng_seed, sizeof(rng_seed));
 
         /* load initrd */
diff --git a/include/standard-headers/asm-m68k/bootinfo-virt.h b/include/standard-headers/asm-m68k/bootinfo-virt.h
index 1b1ffd4705..75ac6bbd7d 100644
--- a/include/standard-headers/asm-m68k/bootinfo-virt.h
+++ b/include/standard-headers/asm-m68k/bootinfo-virt.h
@@ -12,7 +12,9 @@
 #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
+
+/* No longer used -- replaced with BI_RNG_SEED -- but don't reuse this index:
+ * #define BI_VIRT_RNG_SEED	0x8006 */
 
 #define VIRT_BOOTI_VERSION	MK_BI_VERSION(2, 0)
 
diff --git a/include/standard-headers/asm-m68k/bootinfo.h b/include/standard-headers/asm-m68k/bootinfo.h
index 7b790e8ec8..b7a8dd2514 100644
--- a/include/standard-headers/asm-m68k/bootinfo.h
+++ b/include/standard-headers/asm-m68k/bootinfo.h
@@ -57,7 +57,13 @@ struct mem_info {
 					/* (struct mem_info) */
 #define BI_COMMAND_LINE		0x0007	/* kernel command line parameters */
 					/* (string) */
-
+/*
+ * A random seed used to initialize the RNG. Record format:
+ *
+ *   - length       [ 2 bytes, 16-bit big endian ]
+ *   - seed data    [ `length` bytes, padded to preserve 4-byte struct alignment ]
+ */
+#define BI_RNG_SEED		0x0008
 
     /*
      *  Linux/m68k Architectures (BI_MACHTYPE)
-- 
2.37.3



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

* [PATCH qemu v2 2/2] m68k: align bootinfo strings and data to 4 bytes
  2022-09-26 11:38 [PATCH qemu v2 1/2] m68k: rework BI_VIRT_RNG_SEED as BI_RNG_SEED Jason A. Donenfeld
@ 2022-09-26 11:39 ` Jason A. Donenfeld
  2022-09-26 13:00   ` Laurent Vivier
  2022-09-26 21:37   ` Laurent Vivier
  2022-09-29  6:37 ` [PATCH qemu v2 1/2] m68k: rework BI_VIRT_RNG_SEED as BI_RNG_SEED Laurent Vivier
  1 sibling, 2 replies; 9+ messages in thread
From: Jason A. Donenfeld @ 2022-09-26 11:39 UTC (permalink / raw)
  To: linux-m68k, qemu-devel
  Cc: Jason A. Donenfeld, Geert Uytterhoeven, Laurent Vivier

Various tools, such as kexec-tools and m68k-bootinfo, expect each
bootinfo entry to be aligned to 4 bytes, not 2 bytes. So adjust the
padding to fill this out as such.

Also, break apart the padding additions from the other field length
additions, so that it's more clear why these magic numbers are being
added, and comment them too.

Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 hw/m68k/bootinfo.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/hw/m68k/bootinfo.h b/hw/m68k/bootinfo.h
index bd8b212fd3..897162b818 100644
--- a/hw/m68k/bootinfo.h
+++ b/hw/m68k/bootinfo.h
@@ -48,13 +48,14 @@
         stw_phys(as, base, id); \
         base += 2; \
         stw_phys(as, base, \
-                 (sizeof(struct bi_record) + strlen(string) + 2) & ~1); \
+                 (sizeof(struct bi_record) + strlen(string) + \
+                  1 /* null termination */ + 3 /* padding */) & ~3); \
         base += 2; \
         for (i = 0; string[i]; i++) { \
             stb_phys(as, base++, string[i]); \
         } \
         stb_phys(as, base++, 0); \
-        base = (base + 1) & ~1; \
+        base = (base + 3) & ~3; \
     } while (0)
 
 #define BOOTINFODATA(as, base, id, data, len) \
@@ -63,13 +64,14 @@
         stw_phys(as, base, id); \
         base += 2; \
         stw_phys(as, base, \
-                 (sizeof(struct bi_record) + len + 3) & ~1); \
+                 (sizeof(struct bi_record) + len + \
+                  2 /* length field */ + 3 /* padding */) & ~3); \
         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; \
+        base = (base + 3) & ~3; \
     } while (0)
 #endif
-- 
2.37.3



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

* Re: [PATCH qemu v2 2/2] m68k: align bootinfo strings and data to 4 bytes
  2022-09-26 11:39 ` [PATCH qemu v2 2/2] m68k: align bootinfo strings and data to 4 bytes Jason A. Donenfeld
@ 2022-09-26 13:00   ` Laurent Vivier
  2022-09-26 21:37   ` Laurent Vivier
  1 sibling, 0 replies; 9+ messages in thread
From: Laurent Vivier @ 2022-09-26 13:00 UTC (permalink / raw)
  To: Jason A. Donenfeld, linux-m68k, qemu-devel; +Cc: Geert Uytterhoeven

Le 26/09/2022 à 13:39, Jason A. Donenfeld a écrit :
> Various tools, such as kexec-tools and m68k-bootinfo, expect each
> bootinfo entry to be aligned to 4 bytes, not 2 bytes. So adjust the
> padding to fill this out as such.

Agree, I found the same problem using petitboot as a ROM for the virt machine [1].
(I didn't update BOOTINFOSTR() but I think I should).

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

[1] https://github.com/vivier/qemu-m68k/commits/m68k-virt
> 
> Also, break apart the padding additions from the other field length
> additions, so that it's more clear why these magic numbers are being
> added, and comment them too.
> 
> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Laurent Vivier <laurent@vivier.eu>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
>   hw/m68k/bootinfo.h | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/m68k/bootinfo.h b/hw/m68k/bootinfo.h
> index bd8b212fd3..897162b818 100644
> --- a/hw/m68k/bootinfo.h
> +++ b/hw/m68k/bootinfo.h
> @@ -48,13 +48,14 @@
>           stw_phys(as, base, id); \
>           base += 2; \
>           stw_phys(as, base, \
> -                 (sizeof(struct bi_record) + strlen(string) + 2) & ~1); \
> +                 (sizeof(struct bi_record) + strlen(string) + \
> +                  1 /* null termination */ + 3 /* padding */) & ~3); \
>           base += 2; \
>           for (i = 0; string[i]; i++) { \
>               stb_phys(as, base++, string[i]); \
>           } \
>           stb_phys(as, base++, 0); \
> -        base = (base + 1) & ~1; \
> +        base = (base + 3) & ~3; \
>       } while (0)
>   
>   #define BOOTINFODATA(as, base, id, data, len) \
> @@ -63,13 +64,14 @@
>           stw_phys(as, base, id); \
>           base += 2; \
>           stw_phys(as, base, \
> -                 (sizeof(struct bi_record) + len + 3) & ~1); \
> +                 (sizeof(struct bi_record) + len + \
> +                  2 /* length field */ + 3 /* padding */) & ~3); \
>           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; \
> +        base = (base + 3) & ~3; \
>       } while (0)
>   #endif



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

* Re: [PATCH qemu v2 2/2] m68k: align bootinfo strings and data to 4 bytes
  2022-09-26 11:39 ` [PATCH qemu v2 2/2] m68k: align bootinfo strings and data to 4 bytes Jason A. Donenfeld
  2022-09-26 13:00   ` Laurent Vivier
@ 2022-09-26 21:37   ` Laurent Vivier
  2022-09-26 21:40     ` Jason A. Donenfeld
  1 sibling, 1 reply; 9+ messages in thread
From: Laurent Vivier @ 2022-09-26 21:37 UTC (permalink / raw)
  To: Jason A. Donenfeld, linux-m68k, qemu-devel; +Cc: Geert Uytterhoeven

Le 26/09/2022 à 13:39, Jason A. Donenfeld a écrit :
> Various tools, such as kexec-tools and m68k-bootinfo, expect each
> bootinfo entry to be aligned to 4 bytes, not 2 bytes. So adjust the
> padding to fill this out as such.
> 
> Also, break apart the padding additions from the other field length
> additions, so that it's more clear why these magic numbers are being
> added, and comment them too.
> 
> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Laurent Vivier <laurent@vivier.eu>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
>   hw/m68k/bootinfo.h | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
> 

Applied to my m68k-for-7.2 branch

Thanks,
Laurent




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

* Re: [PATCH qemu v2 2/2] m68k: align bootinfo strings and data to 4 bytes
  2022-09-26 21:37   ` Laurent Vivier
@ 2022-09-26 21:40     ` Jason A. Donenfeld
  2022-09-26 21:42       ` Laurent Vivier
  0 siblings, 1 reply; 9+ messages in thread
From: Jason A. Donenfeld @ 2022-09-26 21:40 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: linux-m68k, qemu-devel, Geert Uytterhoeven

On Mon, Sep 26, 2022 at 11:37 PM Laurent Vivier <laurent@vivier.eu> wrote:
>
> Le 26/09/2022 à 13:39, Jason A. Donenfeld a écrit :
> > Various tools, such as kexec-tools and m68k-bootinfo, expect each
> > bootinfo entry to be aligned to 4 bytes, not 2 bytes. So adjust the
> > padding to fill this out as such.
> >
> > Also, break apart the padding additions from the other field length
> > additions, so that it's more clear why these magic numbers are being
> > added, and comment them too.
> >
> > Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
> > Cc: Laurent Vivier <laurent@vivier.eu>
> > Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> > ---
> >   hw/m68k/bootinfo.h | 10 ++++++----
> >   1 file changed, 6 insertions(+), 4 deletions(-)
> >
>
> Applied to my m68k-for-7.2 branch

What about 1/2?

Jason


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

* Re: [PATCH qemu v2 2/2] m68k: align bootinfo strings and data to 4 bytes
  2022-09-26 21:40     ` Jason A. Donenfeld
@ 2022-09-26 21:42       ` Laurent Vivier
  2022-09-26 21:42         ` Jason A. Donenfeld
  0 siblings, 1 reply; 9+ messages in thread
From: Laurent Vivier @ 2022-09-26 21:42 UTC (permalink / raw)
  To: Jason A. Donenfeld; +Cc: linux-m68k, qemu-devel, Geert Uytterhoeven

Le 26/09/2022 à 23:40, Jason A. Donenfeld a écrit :
> On Mon, Sep 26, 2022 at 11:37 PM Laurent Vivier <laurent@vivier.eu> wrote:
>>
>> Le 26/09/2022 à 13:39, Jason A. Donenfeld a écrit :
>>> Various tools, such as kexec-tools and m68k-bootinfo, expect each
>>> bootinfo entry to be aligned to 4 bytes, not 2 bytes. So adjust the
>>> padding to fill this out as such.
>>>
>>> Also, break apart the padding additions from the other field length
>>> additions, so that it's more clear why these magic numbers are being
>>> added, and comment them too.
>>>
>>> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
>>> Cc: Laurent Vivier <laurent@vivier.eu>
>>> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
>>> ---
>>>    hw/m68k/bootinfo.h | 10 ++++++----
>>>    1 file changed, 6 insertions(+), 4 deletions(-)
>>>
>>
>> Applied to my m68k-for-7.2 branch
> 
> What about 1/2?
> 

I'd like to wait a little to see what happens on the linux side.

Thanks,
Laurent


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

* Re: [PATCH qemu v2 2/2] m68k: align bootinfo strings and data to 4 bytes
  2022-09-26 21:42       ` Laurent Vivier
@ 2022-09-26 21:42         ` Jason A. Donenfeld
  2022-09-28 23:13           ` Jason A. Donenfeld
  0 siblings, 1 reply; 9+ messages in thread
From: Jason A. Donenfeld @ 2022-09-26 21:42 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: linux-m68k, qemu-devel, Geert Uytterhoeven

On Mon, Sep 26, 2022 at 11:42 PM Laurent Vivier <laurent@vivier.eu> wrote:
>
> Le 26/09/2022 à 23:40, Jason A. Donenfeld a écrit :
> > On Mon, Sep 26, 2022 at 11:37 PM Laurent Vivier <laurent@vivier.eu> wrote:
> >>
> >> Le 26/09/2022 à 13:39, Jason A. Donenfeld a écrit :
> >>> Various tools, such as kexec-tools and m68k-bootinfo, expect each
> >>> bootinfo entry to be aligned to 4 bytes, not 2 bytes. So adjust the
> >>> padding to fill this out as such.
> >>>
> >>> Also, break apart the padding additions from the other field length
> >>> additions, so that it's more clear why these magic numbers are being
> >>> added, and comment them too.
> >>>
> >>> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
> >>> Cc: Laurent Vivier <laurent@vivier.eu>
> >>> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> >>> ---
> >>>    hw/m68k/bootinfo.h | 10 ++++++----
> >>>    1 file changed, 6 insertions(+), 4 deletions(-)
> >>>
> >>
> >> Applied to my m68k-for-7.2 branch
> >
> > What about 1/2?
> >
>
> I'd like to wait a little to see what happens on the linux side.

Alright, makes sense. Just please don't forget about it.

Jason


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

* Re: [PATCH qemu v2 2/2] m68k: align bootinfo strings and data to 4 bytes
  2022-09-26 21:42         ` Jason A. Donenfeld
@ 2022-09-28 23:13           ` Jason A. Donenfeld
  0 siblings, 0 replies; 9+ messages in thread
From: Jason A. Donenfeld @ 2022-09-28 23:13 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: linux-m68k, qemu-devel, Geert Uytterhoeven

On Mon, Sep 26, 2022 at 11:42:37PM +0200, Jason A. Donenfeld wrote:
> On Mon, Sep 26, 2022 at 11:42 PM Laurent Vivier <laurent@vivier.eu> wrote:
> >
> > Le 26/09/2022 à 23:40, Jason A. Donenfeld a écrit :
> > > On Mon, Sep 26, 2022 at 11:37 PM Laurent Vivier <laurent@vivier.eu> wrote:
> > >>
> > >> Le 26/09/2022 à 13:39, Jason A. Donenfeld a écrit :
> > >>> Various tools, such as kexec-tools and m68k-bootinfo, expect each
> > >>> bootinfo entry to be aligned to 4 bytes, not 2 bytes. So adjust the
> > >>> padding to fill this out as such.
> > >>>
> > >>> Also, break apart the padding additions from the other field length
> > >>> additions, so that it's more clear why these magic numbers are being
> > >>> added, and comment them too.
> > >>>
> > >>> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
> > >>> Cc: Laurent Vivier <laurent@vivier.eu>
> > >>> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> > >>> ---
> > >>>    hw/m68k/bootinfo.h | 10 ++++++----
> > >>>    1 file changed, 6 insertions(+), 4 deletions(-)
> > >>>
> > >>
> > >> Applied to my m68k-for-7.2 branch
> > >
> > > What about 1/2?
> > >
> >
> > I'd like to wait a little to see what happens on the linux side.
> 
> Alright, makes sense. Just please don't forget about it.

Okay, all set. Uneventful.
https://git.kernel.org/pub/scm/linux/kernel/git/geert/linux-m68k.git/commit/?id=f1bb20c8be1929743fdb313b4770601afc39c1b7

Jason



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

* Re: [PATCH qemu v2 1/2] m68k: rework BI_VIRT_RNG_SEED as BI_RNG_SEED
  2022-09-26 11:38 [PATCH qemu v2 1/2] m68k: rework BI_VIRT_RNG_SEED as BI_RNG_SEED Jason A. Donenfeld
  2022-09-26 11:39 ` [PATCH qemu v2 2/2] m68k: align bootinfo strings and data to 4 bytes Jason A. Donenfeld
@ 2022-09-29  6:37 ` Laurent Vivier
  1 sibling, 0 replies; 9+ messages in thread
From: Laurent Vivier @ 2022-09-29  6:37 UTC (permalink / raw)
  To: Jason A. Donenfeld, linux-m68k, qemu-devel; +Cc: Geert Uytterhoeven

Le 26/09/2022 à 13:38, Jason A. Donenfeld a écrit :
> Following a change on the kernel side (see link), pass BI_RNG_SEED
> instead of BI_VIRT_RNG_SEED. This should have no impact on
> compatibility, as there will simply be no effect if it's an old kernel,
> which is how things have always been. We then use this as an opportunity
> to add this to q800, since now we can, which is a nice improvement.
> 
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Laurent Vivier <laurent@vivier.eu>
> Link: https://lore.kernel.org/lkml/20220923170340.4099226-3-Jason@zx2c4.com/
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
>   hw/m68k/q800.c                                    | 7 +++++++
>   hw/m68k/virt.c                                    | 2 +-
>   include/standard-headers/asm-m68k/bootinfo-virt.h | 4 +++-
>   include/standard-headers/asm-m68k/bootinfo.h      | 8 +++++++-
>   4 files changed, 18 insertions(+), 3 deletions(-)
> 

Applied to my m68k-for-7.2 branch

Thanks,
Laurent



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

end of thread, other threads:[~2022-09-29  6:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-26 11:38 [PATCH qemu v2 1/2] m68k: rework BI_VIRT_RNG_SEED as BI_RNG_SEED Jason A. Donenfeld
2022-09-26 11:39 ` [PATCH qemu v2 2/2] m68k: align bootinfo strings and data to 4 bytes Jason A. Donenfeld
2022-09-26 13:00   ` Laurent Vivier
2022-09-26 21:37   ` Laurent Vivier
2022-09-26 21:40     ` Jason A. Donenfeld
2022-09-26 21:42       ` Laurent Vivier
2022-09-26 21:42         ` Jason A. Donenfeld
2022-09-28 23:13           ` Jason A. Donenfeld
2022-09-29  6:37 ` [PATCH qemu v2 1/2] m68k: rework BI_VIRT_RNG_SEED as BI_RNG_SEED Laurent Vivier

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).