Skip to contentSkip to conversation

kexec/arm64: Fix issue with 'kexec load' and 'kdump' when --dtb option is used

PATCH Applied Bhupesh Sharma 3 participants 9 messages Dec 16, 2018 – Jan 9, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover kexec/arm64: Fix issue with 'kexec load' and 'kdump' when --dtb option is used

Changes since v2:
-----------------
- Dropped 4/4 from v2 as I noticed that we pass wrong node name to fdt helper functions in 'kexec/dt-ops.c'

This patchset fixes some issues when we call kexec for arm64 with --dtb option (both for 'kexec load' and 'kdump' use cases).

A couple of these issues were reported for 'kexec load' use case by Vicenç and I found the other two while experiment with 'kdump' use cases.

I have tested the patchset on my qualcomm-amberwing and hp-moonshot arm64 boards.

Cc Simon Horman <[email protected]>
Cc AKASHI Takahiro <[email protected]>
Cc Vicente Bergas <[email protected]>

Bhupesh Sharma (4):
kexec/dt-ops.c: Fix check against 'fdt_add_subnode' return value kexec/kexec-arm64.c: Add error handling check against return value of

    'set_bootargs()'

kexec/dt-ops.c: Fix adding '/chosen' node for cases where it is not
available in dtb passed via --dtb option
kexec/dt-ops.c: Fix '/chosen' v/s 'chosen' node being passed to fdt
helper functions

 kexec/arch/arm64/kexec-arm64.c |  5 +++++
 kexec/dt-ops.c                 | 36 ++++++++++++++++++++++++++++++------
 2 files changed, 35 insertions(+), 6 deletions(-)
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw

PATCH v3 1/4 kexec/dt-ops.c: Fix check against 'fdt_add_subnode' return value

Vicenç reported (via [1]) that currently executing kexec with '--dtb' option and passing a .dtb which doesn't have a '/chosen' node leads to the following error:

  # kexec -d --dtb dtb_without_chosen_node.dtb --append 'cmdline' --load Image

dtb_set_property: fdt_add_subnode failed: <valid offset/length>
kexec: Set device tree bootargs failed.

This happens because currently we check the return value of 'fdt_add_subnode()' function call in 'dt-ops.c' incorrectly:

   result = fdt_add_subnode(new_dtb, nodeoffset, node);
   if (result) {
   	dbgprintf("%s: fdt_add_subnode failed: %s\n", _func__,
   		fdt_strerror(result));
   	goto on_error;
   }

As we can see in 'fdt_rw.c', a positive return value from 'fdt_add_subnode()' function doesn't indicate an error.

We can see that the Linux kernel (see 'drivers/firmware/efi/libstub/fdt.c' for example) also checks the 'fdt_add_subnode()' function against negative return values for errors. See an example below from 'update_fdt()' function in 'drivers/firmware/efi/libstub/fdt.c':

   node = fdt_add_subnode(fdt, 0, "chosen");
   if (node < 0) {
   	status = node;
   	<..snip..>
   	goto fdt_set_fail;
   }

This patch fixes the same in 'kexec-tools'.

[1]. http://lists.infradead.org/pipermail/kexec/2018-October/021746.html

---
 kexec/dt-ops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kexec/dt-ops.c +1 -1
index 915dbf55afd2..f15174c3c74e 100644
@@ -84,7 +84,7 @@ int dtb_set_property(char **dtb, off_t *dtb_size, const char *node,
 	if (nodeoffset == -FDT_ERR_NOTFOUND) {
 		result = fdt_add_subnode(new_dtb, nodeoffset, node);
 
-		if (result) {
+		if (result < 0) {
 			dbgprintf("%s: fdt_add_subnode failed: %s\n", __func__,
 				fdt_strerror(result));
 			goto on_error;
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#2 lore raw

PATCH v3 2/4 kexec/kexec-arm64.c: Add error handling check against return value of 'set_bootargs()'

In reply to Bhupesh Sharma

This patch adds missing error handling check against the return value of 'set_bootargs()' in 'kexec-arm64.c'

---
 kexec/arch/arm64/kexec-arm64.c | 5 +++++
 1 file changed, 5 insertions(+)
kexec/arch/arm64/kexec-arm64.c +5 -0
index b143e861f7d9..f4913b2e9480 100644
@@ -413,6 +413,11 @@ static int setup_2nd_dtb(struct dtb *dtb, char *command_line, int on_crash)
 	}
 
 	result = set_bootargs(dtb, command_line);
+	if (result) {
+		fprintf(stderr, "kexec: cannot set bootargs.\n");
+		result = -EINVAL;
+		goto on_error;
+	}
 
 	/* determine #address-cells and #size-cells */
 	result = get_cells_size(dtb->buf, &address_cells, &size_cells);
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#3 lore raw

PATCH v3 3/4 kexec/dt-ops.c: Fix adding '/chosen' node for cases where it is not available in dtb passed via --dtb option

In reply to Bhupesh Sharma

While calling 'kexec -l', in case we are passed a .dtb using --dtb option which doesn't contain a '/chosen' node, we try to create the '/chosen' node and add bootargs to this node.

Currently the 'dt-ops.c' code is buggy as it passes '-FDT_ERR_NOTFOUND' to 'fdt_add_subnode()', which leads to the following error:

  # kexec -d --load Image --append 'debug' --dtb rk3399-sapphire.dtb

<..snip..>
dtb_set_property: fdt_add_subnode failed: FDT_ERR_NOTFOUND
kexec: Set device tree bootargs failed.
get_cells_size: #address-cells:2 #size-cells:2
cells_size_fitted: 0-0
cells_size_fitted: 0-0
setup_2nd_dtb: no kaslr-seed found

This patch passes the correct nodeoffset value to 'fdt_add_subnode()', which fixes this issue:

  # kexec -d -l Image --append 'debug' --dtb rk3399-sapphire.dtb

<..snip..>
get_cells_size: #address-cells:2 #size-cells:2
cells_size_fitted: 0-0
cells_size_fitted: 0-0
setup_2nd_dtb: no kaslr-seed found

---
 kexec/dt-ops.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kexec/dt-ops.c +3 -2
index f15174c3c74e..bdc16dc87642 100644
@@ -80,15 +80,16 @@ int dtb_set_property(char **dtb, off_t *dtb_size, const char *node,
 	}
 
 	nodeoffset = fdt_path_offset(new_dtb, node);
-	
+
 	if (nodeoffset == -FDT_ERR_NOTFOUND) {
-		result = fdt_add_subnode(new_dtb, nodeoffset, node);
+		result = fdt_add_subnode(new_dtb, 0, node);
 
 		if (result < 0) {
 			dbgprintf("%s: fdt_add_subnode failed: %s\n", __func__,
 				fdt_strerror(result));
 			goto on_error;
 		}
+		nodeoffset = result;
 	} else if (nodeoffset < 0) {
 		dbgprintf("%s: fdt_path_offset failed: %s\n", __func__,
 			fdt_strerror(nodeoffset));
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#4 lore raw

PATCH v3 4/4 kexec/dt-ops.c: Fix '/chosen' v/s 'chosen' node being passed to fdt helper functions

In reply to Bhupesh Sharma

This patch fixes the incorrect 'chosen' node name being passed to various fdt helper functions inside 'kexec/dt-ops.c'

As we can see from the Linux kernel usage inside 'drivers/firmware/efi/libstub/fdt.c', we pass '/chosen' node names to fdt helper function like 'fdt_path_offset()' whereas 'chosen' to the rest of the fdt helper functions like 'fdt_subnode_offset()'.

We need to replicate the same in 'kexec-tools' to fix issues being reported when we use --dtb option while invoking 'kexec'.

---
 kexec/dt-ops.c | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)
kexec/dt-ops.c +27 -4
index bdc16dc87642..5626c47981c4 100644
@@ -8,7 +8,7 @@
 #include "kexec.h"
 #include "dt-ops.h"
 
-static const char n_chosen[] = "/chosen";
+static const char n_chosen[] = "chosen";
 
 static const char p_bootargs[] = "bootargs";
 static const char p_initrd_start[] = "linux,initrd-start";
@@ -58,6 +58,7 @@ int dtb_set_property(char **dtb, off_t *dtb_size, const char *node,
 	int nodeoffset;
 	void *new_dtb;
 	int new_size;
+	char *new_node = NULL;
 
 	value_len = FDT_TAGALIGN(value_len);
 
@@ -79,7 +80,16 @@ int dtb_set_property(char **dtb, off_t *dtb_size, const char *node,
 		goto on_error;
 	}
 
-	nodeoffset = fdt_path_offset(new_dtb, node);
+	new_node = malloc(strlen("/") + strlen(node) + 1);
+	if (!new_node) {
+		dbgprintf("%s: malloc failed\n", __func__);
+		return -ENOMEM;
+	}
+
+	strcpy(new_node, "/");
+	strcat(new_node, node);
+	
+	nodeoffset = fdt_path_offset(new_dtb, new_node);
 
 	if (nodeoffset == -FDT_ERR_NOTFOUND) {
 		result = fdt_add_subnode(new_dtb, 0, node);
@@ -122,17 +132,29 @@ int dtb_set_property(char **dtb, off_t *dtb_size, const char *node,
 
 on_error:
 	free(new_dtb);
+	free(new_node);
 	return result;
 }
 
 int dtb_delete_property(char *dtb, const char *node, const char *prop)
 {
-	int result;
-	int nodeoffset = fdt_path_offset(dtb, node);
+	int result, nodeoffset;
+	char *new_node = NULL;
+
+	new_node = malloc(strlen("/") + strlen(node) + 1);
+	if (!new_node) {
+		dbgprintf("%s: malloc failed\n", __func__);
+		return -ENOMEM;
+	}
+
+	strcpy(new_node, "/");
+	strcat(new_node, node);
 
+	nodeoffset = fdt_path_offset(dtb, new_node);
 	if (nodeoffset < 0) {
 		dbgprintf("%s: fdt_path_offset failed: %s\n", __func__,
 			fdt_strerror(nodeoffset));
+		free(new_node);
 		return nodeoffset;
 	}
 
@@ -142,5 +164,6 @@ int dtb_delete_property(char *dtb, const char *node, const char *prop)
 		dbgprintf("%s: fdt_delprop failed: %s\n", __func__,
 			fdt_strerror(nodeoffset));
 
+	free(new_node);
 	return result;
 }
Signature · 7 lines
2.7.4


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#5 lore raw
In reply to Bhupesh Sharma

Hello Vicenç,

Quoted 29 lines · Bhupesh Sharma

Changes since v2:
-----------------
- Dropped 4/4 from v2 as I noticed that we pass wrong node name to fdt helper functions in 'kexec/dt-ops.c'

This patchset fixes some issues when we call kexec for arm64 with --dtb option (both for 'kexec load' and 'kdump' use cases).

A couple of these issues were reported for 'kexec load' use case by Vicenç and I found the other two while experiment with 'kdump' use cases.

I have tested the patchset on my qualcomm-amberwing and hp-moonshot arm64 boards.

Cc Simon Horman <[email protected]>
Cc AKASHI Takahiro <[email protected]>
Cc Vicente Bergas <[email protected]>

Bhupesh Sharma (4):
kexec/dt-ops.c: Fix check against 'fdt_add_subnode' return value kexec/kexec-arm64.c: Add error handling check against return value of

    'set_bootargs()'

kexec/dt-ops.c: Fix adding '/chosen' node for cases where it is not
available in dtb passed via --dtb option
kexec/dt-ops.c: Fix '/chosen' v/s 'chosen' node being passed to fdt
helper functions

Quoted 7 lines
 kexec/arch/arm64/kexec-arm64.c |  5 +++++
 kexec/dt-ops.c                 | 36 ++++++++++++++++++++++++++++++------
 2 files changed, 35 insertions(+), 6 deletions(-)

--
2.7.4

Can you please give this patchset a try at your end and see if it fixes the issues you had reported with the --dtb option.

Thanks,
Bhupesh

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#6 lore raw
Quoted 37 lines · Bhupesh Sharma

Hello Vicenç,

Quoted 33 lines · Bhupesh Sharma

Changes since v2:
-----------------
- Dropped 4/4 from v2 as I noticed that we pass wrong node name to fdt helper functions in 'kexec/dt-ops.c'

This patchset fixes some issues when we call kexec for arm64 with --dtb option (both for 'kexec load' and 'kdump' use cases).

A couple of these issues were reported for 'kexec load' use case by Vicenç and I found the other two while experiment with 'kdump' use cases.

I have tested the patchset on my qualcomm-amberwing and hp-moonshot arm64 boards.

Cc Simon Horman <[email protected]>
Cc AKASHI Takahiro <[email protected]>
Cc Vicente Bergas <[email protected]>

Bhupesh Sharma (4):
kexec/dt-ops.c: Fix check against 'fdt_add_subnode' return value kexec/kexec-arm64.c: Add error handling check against return value of

    'set_bootargs()'

kexec/dt-ops.c: Fix adding '/chosen' node for cases where it is not
available in dtb passed via --dtb option
kexec/dt-ops.c: Fix '/chosen' v/s 'chosen' node being passed to fdt
helper functions

 kexec/arch/arm64/kexec-arm64.c |  5 +++++
 kexec/dt-ops.c                 | 36 ++++++++++++++++++++++++++++++------
 2 files changed, 35 insertions(+), 6 deletions(-)
Quoted 6 lines
Quoted 3 lines

--
2.7.4

Can you please give this patchset a try at your end and see if it fixes the issues you had reported with the --dtb option.

Hi Bhupesh,
sorry for the delay.
This is what I have tested:
kexec --append 'debug'
--load Image
kexec --reuse-cmdline
--load Image
kexec --append 'debug' --dtb rk3399-sapphire.dtb
--load Image
kexec --reuse-cmdline --dtb rk3399-sapphire.dtb
--load Image
kexec --append 'debug' --dtb rk3399-gru-kevin.dtb
--load Image
kexec --reuse-cmdline --dtb rk3399-gru-kevin.dtb
--load Image
kexec --append 'debug' --ramdisk
initramfs-linux.img --load Image
kexec --reuse-cmdline --ramdisk
initramfs-linux.img --load Image
kexec --append 'debug' --dtb rk3399-sapphire.dtb --ramdisk initramfs-linux.img --load Image
kexec --reuse-cmdline --dtb rk3399-sapphire.dtb --ramdisk initramfs-linux.img --load Image
kexec --append 'debug' --dtb rk3399-gru-kevin.dtb --ramdisk initramfs-linux.img --load Image
kexec --reuse-cmdline --dtb rk3399-gru-kevin.dtb --ramdisk initramfs-linux.img --load Image

where the sapphire dtb has no chosen node and the gru has. Everything worked OK.

Thanks and happy new year!
Regards,
Vicenç.

Quoted 3 lines

Thanks,
Bhupesh

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#7 lore raw

Hi Vicenç,

Happy New Year to you too and thanks a lot for your test results.

Quoted 74 lines · Vicente Bergas
Quoted 37 lines · Bhupesh Sharma

Hello Vicenç,

Quoted 33 lines · Bhupesh Sharma

Changes since v2:
-----------------
- Dropped 4/4 from v2 as I noticed that we pass wrong node name to fdt helper functions in 'kexec/dt-ops.c'

This patchset fixes some issues when we call kexec for arm64 with --dtb option (both for 'kexec load' and 'kdump' use cases).

A couple of these issues were reported for 'kexec load' use case by Vicenç and I found the other two while experiment with 'kdump' use cases.

I have tested the patchset on my qualcomm-amberwing and hp-moonshot arm64 boards.

Cc Simon Horman <[email protected]>
Cc AKASHI Takahiro <[email protected]>
Cc Vicente Bergas <[email protected]>

Bhupesh Sharma (4):
kexec/dt-ops.c: Fix check against 'fdt_add_subnode' return value kexec/kexec-arm64.c: Add error handling check against return value of

    'set_bootargs()'

kexec/dt-ops.c: Fix adding '/chosen' node for cases where it is not
available in dtb passed via --dtb option
kexec/dt-ops.c: Fix '/chosen' v/s 'chosen' node being passed to fdt
helper functions

 kexec/arch/arm64/kexec-arm64.c |  5 +++++
 kexec/dt-ops.c                 | 36 ++++++++++++++++++++++++++++++------
 2 files changed, 35 insertions(+), 6 deletions(-)
Quoted 6 lines
Quoted 3 lines

--
2.7.4

Can you please give this patchset a try at your end and see if it fixes the issues you had reported with the --dtb option.

Hi Bhupesh,
sorry for the delay.
This is what I have tested:
kexec --append 'debug'
--load Image
kexec --reuse-cmdline
--load Image
kexec --append 'debug' --dtb rk3399-sapphire.dtb
--load Image
kexec --reuse-cmdline --dtb rk3399-sapphire.dtb
--load Image
kexec --append 'debug' --dtb rk3399-gru-kevin.dtb
--load Image
kexec --reuse-cmdline --dtb rk3399-gru-kevin.dtb
--load Image
kexec --append 'debug' --ramdisk
initramfs-linux.img --load Image
kexec --reuse-cmdline --ramdisk
initramfs-linux.img --load Image
kexec --append 'debug' --dtb rk3399-sapphire.dtb --ramdisk initramfs-linux.img --load Image
kexec --reuse-cmdline --dtb rk3399-sapphire.dtb --ramdisk initramfs-linux.img --load Image
kexec --append 'debug' --dtb rk3399-gru-kevin.dtb --ramdisk initramfs-linux.img --load Image
kexec --reuse-cmdline --dtb rk3399-gru-kevin.dtb --ramdisk initramfs-linux.img --load Image

Quoted 3 lines

where the sapphire dtb has no chosen node and the gru has. Everything worked OK.

@Simon: Hi, Since this works fine at Vicenç's end as well, can you please consider applying this to kexec-tools as this issue has been reported by another arm64 user as well. Thanks for your help.

Regards,
Bhupesh

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Applied
#8 lore raw
Quoted 79 lines · Bhupesh Sharma

Hi Vicenç,

Happy New Year to you too and thanks a lot for your test results.

Quoted 74 lines · Vicente Bergas
Quoted 37 lines · Bhupesh Sharma

Hello Vicenç,

Quoted 33 lines · Bhupesh Sharma

Changes since v2:
-----------------
- Dropped 4/4 from v2 as I noticed that we pass wrong node name to fdt helper functions in 'kexec/dt-ops.c'

This patchset fixes some issues when we call kexec for arm64 with --dtb option (both for 'kexec load' and 'kdump' use cases).

A couple of these issues were reported for 'kexec load' use case by Vicenç and I found the other two while experiment with 'kdump' use cases.

I have tested the patchset on my qualcomm-amberwing and hp-moonshot arm64 boards.

Cc Simon Horman <[email protected]>
Cc AKASHI Takahiro <[email protected]>
Cc Vicente Bergas <[email protected]>

Bhupesh Sharma (4):
kexec/dt-ops.c: Fix check against 'fdt_add_subnode' return value kexec/kexec-arm64.c: Add error handling check against return value of

    'set_bootargs()'

kexec/dt-ops.c: Fix adding '/chosen' node for cases where it is not
available in dtb passed via --dtb option
kexec/dt-ops.c: Fix '/chosen' v/s 'chosen' node being passed to fdt
helper functions

 kexec/arch/arm64/kexec-arm64.c |  5 +++++
 kexec/dt-ops.c                 | 36 ++++++++++++++++++++++++++++++------
 2 files changed, 35 insertions(+), 6 deletions(-)
Quoted 6 lines
Quoted 3 lines

--
2.7.4

Can you please give this patchset a try at your end and see if it fixes the issues you had reported with the --dtb option.

Hi Bhupesh,
sorry for the delay.
This is what I have tested:
kexec --append 'debug'
--load Image
kexec --reuse-cmdline
--load Image
kexec --append 'debug' --dtb rk3399-sapphire.dtb
--load Image
kexec --reuse-cmdline --dtb rk3399-sapphire.dtb
--load Image
kexec --append 'debug' --dtb rk3399-gru-kevin.dtb
--load Image
kexec --reuse-cmdline --dtb rk3399-gru-kevin.dtb
--load Image
kexec --append 'debug' --ramdisk
initramfs-linux.img --load Image
kexec --reuse-cmdline --ramdisk
initramfs-linux.img --load Image
kexec --append 'debug' --dtb rk3399-sapphire.dtb --ramdisk initramfs-linux.img --load Image
kexec --reuse-cmdline --dtb rk3399-sapphire.dtb --ramdisk initramfs-linux.img --load Image
kexec --append 'debug' --dtb rk3399-gru-kevin.dtb --ramdisk initramfs-linux.img --load Image
kexec --reuse-cmdline --dtb rk3399-gru-kevin.dtb --ramdisk initramfs-linux.img --load Image

Quoted 7 lines
Quoted 3 lines

where the sapphire dtb has no chosen node and the gru has. Everything worked OK.

@Simon: Hi, Since this works fine at Vicenç's end as well, can you please consider applying this to kexec-tools as this issue has been reported by another arm64 user as well. Thanks for your help.

Thanks, applied.

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec