linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] bootconfig: Make size and checksum fields le32
@ 2020-11-20  2:28 Masami Hiramatsu
  2020-11-20  2:29 ` [PATCH 1/3] bootconfig: Load size and checksum in the footer as le32 Masami Hiramatsu
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Masami Hiramatsu @ 2020-11-20  2:28 UTC (permalink / raw)
  To: Steven Rostedt, Linus Torvalds
  Cc: Chen Yu, Chen Yu, Masami Hiramatsu, LKML, Ingo Molnar,
	Jonathan Corbet, linux-doc

Hello,

This is a series of patches to make the size and the checksum fields
in the footer le32 instead of u32.

In the thread for alignment series[1], Steve pointed that the current
footer format didn't specify the endianness thus it is hard to apply
the bootconfig for cross-build initrd if the target endianness is
different from the host machine.

I've proposed that the hexadecimal ASCII string in the previous series
[2] but Linus pointed that making it le32 was enough.

So this just make those fields le32.

Thank you,

[1] https://lore.kernel.org/lkml/20201118112249.30d20147@gandalf.local.home/
[2] https://lore.kernel.org/linux-doc/CAHk-=wi9RedSQoGF06dVs2mp7tBp4QoiW8+XZzNcDFJr3Zo5gg@mail.gmail.com/

---

Masami Hiramatsu (3):
      bootconfig: Load size and checksum in the footer as le32
      tools/bootconfig: Store size and checksum in footer as le32
      docs: bootconfig: Add the endianness of fields


 Documentation/admin-guide/bootconfig.rst |    4 +++-
 init/main.c                              |    4 ++--
 tools/bootconfig/main.c                  |    7 +++++--
 3 files changed, 10 insertions(+), 5 deletions(-)

--
Masami Hiramatsu (Linaro) <mhiramat@kernel.org>

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

* [PATCH 1/3] bootconfig: Load size and checksum in the footer as le32
  2020-11-20  2:28 [PATCH 0/3] bootconfig: Make size and checksum fields le32 Masami Hiramatsu
@ 2020-11-20  2:29 ` Masami Hiramatsu
  2020-11-20  2:29 ` [PATCH 2/3] tools/bootconfig: Store size and checksum in " Masami Hiramatsu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Masami Hiramatsu @ 2020-11-20  2:29 UTC (permalink / raw)
  To: Steven Rostedt, Linus Torvalds
  Cc: Chen Yu, Chen Yu, Masami Hiramatsu, LKML, Ingo Molnar,
	Jonathan Corbet, linux-doc

Load the size and the checksum fields in the footer as le32
instead of u32. This will allow us to apply bootconfig to the
cross build initrd without caring the endianness.

Reported-by: Steven Rostedt <rostedt@goodmis.org>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 init/main.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/init/main.c b/init/main.c
index 20baced721ad..32b2a8affafd 100644
--- a/init/main.c
+++ b/init/main.c
@@ -288,8 +288,8 @@ static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum)
 
 found:
 	hdr = (u32 *)(data - 8);
-	size = hdr[0];
-	csum = hdr[1];
+	size = le32_to_cpu(hdr[0]);
+	csum = le32_to_cpu(hdr[1]);
 
 	data = ((void *)hdr) - size;
 	if ((unsigned long)data < initrd_start) {


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

* [PATCH 2/3] tools/bootconfig: Store size and checksum in footer as le32
  2020-11-20  2:28 [PATCH 0/3] bootconfig: Make size and checksum fields le32 Masami Hiramatsu
  2020-11-20  2:29 ` [PATCH 1/3] bootconfig: Load size and checksum in the footer as le32 Masami Hiramatsu
@ 2020-11-20  2:29 ` Masami Hiramatsu
  2020-11-20  2:29 ` [PATCH 3/3] docs: bootconfig: Add the endianness of fields Masami Hiramatsu
  2020-12-01 15:48 ` [PATCH 0/3] bootconfig: Make size and checksum fields le32 Steven Rostedt
  3 siblings, 0 replies; 7+ messages in thread
From: Masami Hiramatsu @ 2020-11-20  2:29 UTC (permalink / raw)
  To: Steven Rostedt, Linus Torvalds
  Cc: Chen Yu, Chen Yu, Masami Hiramatsu, LKML, Ingo Molnar,
	Jonathan Corbet, linux-doc

Store the size and the checksum fields in the footer as le32
instead of u32. This will allow us to apply bootconfig to the
cross build initrd without caring the endianness.

Reported-by: Steven Rostedt <rostedt@goodmis.org>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 tools/bootconfig/main.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
index 4a445b6304bb..7362bef1a368 100644
--- a/tools/bootconfig/main.c
+++ b/tools/bootconfig/main.c
@@ -10,6 +10,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
+#include <endian.h>
 
 #include <linux/kernel.h>
 #include <linux/bootconfig.h>
@@ -183,9 +184,11 @@ static int load_xbc_from_initrd(int fd, char **buf)
 
 	if (read(fd, &size, sizeof(u32)) < 0)
 		return pr_errno("Failed to read size", -errno);
+	size = le32toh(size);
 
 	if (read(fd, &csum, sizeof(u32)) < 0)
 		return pr_errno("Failed to read checksum", -errno);
+	csum = le32toh(csum);
 
 	/* Wrong size error  */
 	if (stat.st_size < size + 8 + BOOTCONFIG_MAGIC_LEN) {
@@ -407,10 +410,10 @@ static int apply_xbc(const char *path, const char *xbc_path)
 
 	/* Add a footer */
 	p = data + size;
-	*(u32 *)p = size;
+	*(u32 *)p = htole32(size);
 	p += sizeof(u32);
 
-	*(u32 *)p = csum;
+	*(u32 *)p = htole32(csum);
 	p += sizeof(u32);
 
 	memcpy(p, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN);


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

* [PATCH 3/3] docs: bootconfig: Add the endianness of fields
  2020-11-20  2:28 [PATCH 0/3] bootconfig: Make size and checksum fields le32 Masami Hiramatsu
  2020-11-20  2:29 ` [PATCH 1/3] bootconfig: Load size and checksum in the footer as le32 Masami Hiramatsu
  2020-11-20  2:29 ` [PATCH 2/3] tools/bootconfig: Store size and checksum in " Masami Hiramatsu
@ 2020-11-20  2:29 ` Masami Hiramatsu
  2020-12-01 15:48 ` [PATCH 0/3] bootconfig: Make size and checksum fields le32 Steven Rostedt
  3 siblings, 0 replies; 7+ messages in thread
From: Masami Hiramatsu @ 2020-11-20  2:29 UTC (permalink / raw)
  To: Steven Rostedt, Linus Torvalds
  Cc: Chen Yu, Chen Yu, Masami Hiramatsu, LKML, Ingo Molnar,
	Jonathan Corbet, linux-doc

Add a description about the endianness of the size and the checksum
fields. Those must be stored as le32 instead of u32. This will allow
us to apply bootconfig to the cross build initrd without caring
the endianness.

Reported-by: Steven Rostedt <rostedt@goodmis.org>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 Documentation/admin-guide/bootconfig.rst |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/admin-guide/bootconfig.rst b/Documentation/admin-guide/bootconfig.rst
index 363599683784..9b90efcc3a35 100644
--- a/Documentation/admin-guide/bootconfig.rst
+++ b/Documentation/admin-guide/bootconfig.rst
@@ -140,7 +140,9 @@ Since the boot configuration file is loaded with initrd, it will be added
 to the end of the initrd (initramfs) image file with padding, size,
 checksum and 12-byte magic word as below.
 
-[initrd][bootconfig][padding][size(u32)][checksum(u32)][#BOOTCONFIG\n]
+[initrd][bootconfig][padding][size(le32)][checksum(le32)][#BOOTCONFIG\n]
+
+The size and checksum fields are unsigned 32bit little endian value.
 
 When the boot configuration is added to the initrd image, the total
 file size is aligned to 4 bytes. To fill the gap, null characters


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

* Re: [PATCH 0/3] bootconfig: Make size and checksum fields le32
  2020-11-20  2:28 [PATCH 0/3] bootconfig: Make size and checksum fields le32 Masami Hiramatsu
                   ` (2 preceding siblings ...)
  2020-11-20  2:29 ` [PATCH 3/3] docs: bootconfig: Add the endianness of fields Masami Hiramatsu
@ 2020-12-01 15:48 ` Steven Rostedt
  2020-12-01 23:41   ` Masami Hiramatsu
  3 siblings, 1 reply; 7+ messages in thread
From: Steven Rostedt @ 2020-12-01 15:48 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Linus Torvalds, Chen Yu, Chen Yu, LKML, Ingo Molnar,
	Jonathan Corbet, linux-doc

On Fri, 20 Nov 2020 11:28:55 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> Hello,
> 
> This is a series of patches to make the size and the checksum fields
> in the footer le32 instead of u32.
> 
> In the thread for alignment series[1], Steve pointed that the current
> footer format didn't specify the endianness thus it is hard to apply
> the bootconfig for cross-build initrd if the target endianness is
> different from the host machine.
> 
> I've proposed that the hexadecimal ASCII string in the previous series
> [2] but Linus pointed that making it le32 was enough.
> 
> So this just make those fields le32.
> 
> Thank you,
> 
> [1] https://lore.kernel.org/lkml/20201118112249.30d20147@gandalf.local.home/
> [2] https://lore.kernel.org/linux-doc/CAHk-=wi9RedSQoGF06dVs2mp7tBp4QoiW8+XZzNcDFJr3Zo5gg@mail.gmail.com/
> 
> ---
> 

I have this all tested. Is this something that should go into the current
-rc release, or wait for the next merge window?

-- Steve

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

* Re: [PATCH 0/3] bootconfig: Make size and checksum fields le32
  2020-12-01 15:48 ` [PATCH 0/3] bootconfig: Make size and checksum fields le32 Steven Rostedt
@ 2020-12-01 23:41   ` Masami Hiramatsu
  0 siblings, 0 replies; 7+ messages in thread
From: Masami Hiramatsu @ 2020-12-01 23:41 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Linus Torvalds, Chen Yu, Chen Yu, LKML, Ingo Molnar,
	Jonathan Corbet, linux-doc

On Tue, 1 Dec 2020 10:48:18 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:

> On Fri, 20 Nov 2020 11:28:55 +0900
> Masami Hiramatsu <mhiramat@kernel.org> wrote:
> 
> > Hello,
> > 
> > This is a series of patches to make the size and the checksum fields
> > in the footer le32 instead of u32.
> > 
> > In the thread for alignment series[1], Steve pointed that the current
> > footer format didn't specify the endianness thus it is hard to apply
> > the bootconfig for cross-build initrd if the target endianness is
> > different from the host machine.
> > 
> > I've proposed that the hexadecimal ASCII string in the previous series
> > [2] but Linus pointed that making it le32 was enough.
> > 
> > So this just make those fields le32.
> > 
> > Thank you,
> > 
> > [1] https://lore.kernel.org/lkml/20201118112249.30d20147@gandalf.local.home/
> > [2] https://lore.kernel.org/linux-doc/CAHk-=wi9RedSQoGF06dVs2mp7tBp4QoiW8+XZzNcDFJr3Zo5gg@mail.gmail.com/
> > 
> > ---
> > 
> 
> I have this all tested. Is this something that should go into the current
> -rc release, or wait for the next merge window?

Hrm, this kind of things usually good for the next merge window because
it is only for the different endianess cross-build case. But the next
release will be LTS (6 years life cycle), so it is possible someone
hits this issue before EOL and (I guess) finally they need this series.

So if possible, could you push this in -rc release? I think this doesn't
change so much.

Thank you,

-- 
Masami Hiramatsu <mhiramat@kernel.org>

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

* [PATCH 0/3] bootconfig: Make size and checksum fields le32
@ 2020-11-20  2:27 Masami Hiramatsu
  0 siblings, 0 replies; 7+ messages in thread
From: Masami Hiramatsu @ 2020-11-20  2:27 UTC (permalink / raw)
  To: Steven Rostedt, Linus Torvalds
  Cc: Chen Yu, Chen Yu, Masami Hiramatsu, LKML, Ingo Molnar,
	Jonathan Corbet, linux-doc

Hello,

This is a series of patches to make the size and the checksum fields
in the footer le32 instead of u32.

In the thread for alignment series[1], Steve pointed that the current
footer format didn't specify the endianness thus it is hard to apply
the bootconfig for cross-build initrd if the target endianness is
different from the host machine.

I've proposed that the hexadecimal ASCII string in the previous series
[2] but Linus pointed that making it le32 was enough.

So this just make those fields le32.

Thank you,

[1] https://lore.kernel.org/lkml/20201118112249.30d20147@gandalf.local.home/
[2] https://lore.kernel.org/linux-doc/CAHk-=wi9RedSQoGF06dVs2mp7tBp4QoiW8+XZzNcDFJr3Zo5gg@mail.gmail.com/

---

Masami Hiramatsu (3):
      bootconfig: Load size and checksum in the footer as le32
      tools/bootconfig: Store size and checksum in footer as le32
      docs: bootconfig: Add the endianness of fields


 Documentation/admin-guide/bootconfig.rst |    4 +++-
 init/main.c                              |    4 ++--
 tools/bootconfig/main.c                  |    7 +++++--
 3 files changed, 10 insertions(+), 5 deletions(-)

--
Masami Hiramatsu (Linaro) <mhiramat@kernel.org>

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

end of thread, other threads:[~2020-12-01 23:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-20  2:28 [PATCH 0/3] bootconfig: Make size and checksum fields le32 Masami Hiramatsu
2020-11-20  2:29 ` [PATCH 1/3] bootconfig: Load size and checksum in the footer as le32 Masami Hiramatsu
2020-11-20  2:29 ` [PATCH 2/3] tools/bootconfig: Store size and checksum in " Masami Hiramatsu
2020-11-20  2:29 ` [PATCH 3/3] docs: bootconfig: Add the endianness of fields Masami Hiramatsu
2020-12-01 15:48 ` [PATCH 0/3] bootconfig: Make size and checksum fields le32 Steven Rostedt
2020-12-01 23:41   ` Masami Hiramatsu
  -- strict thread matches above, loose matches on Subject: below --
2020-11-20  2:27 Masami Hiramatsu

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