Skip to contentSkip to conversation

xen/arm: bootfdt: Check return code of device_tree_for_each_node()

PATCH In review Michal Orzel 2 participants 6 messages Dec 7, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: bootfdt: Check return code of device_tree_for_each_node()

As a result of not checking the return code of device_tree_for_each_node() in boot_fdt_info(), any error occured during early FDT parsing does not stop Xen from booting. This can result in an unwanted behavior in later boot stages. Fix it by checking the return code and panicing on an error.

Fixes 9cf4a9a46717 ("device tree: add device_tree_for_each_node()")

---
I've lost count how many times I had to fix missing rc check. However, I have not yet found any checker for this (-Wunused-result is pretty useless).

---
 xen/arch/arm/bootfdt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
xen/arch/arm/bootfdt.c +3 -1
index b1f03eb2fcdd..f496a8cf9494 100644
@@ -541,7 +541,9 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t paddr)
 
     add_boot_module(BOOTMOD_FDT, paddr, fdt_totalsize(fdt), false);
 
-    device_tree_for_each_node((void *)fdt, 0, early_scan_node, NULL);
+    ret = device_tree_for_each_node((void *)fdt, 0, early_scan_node, NULL);
+    if ( ret )
+        panic("Early FDT parsing failed (%d)\n", ret);
 
     /*
      * On Arm64 setup_directmap_mappings() expects to be called with the lowest
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw

Hi Michal,

Quoted 7 lines · Michal Orzel

As a result of not checking the return code of device_tree_for_each_node() in boot_fdt_info(), any error occured during early FDT parsing does not stop Xen from booting. This can result in an unwanted behavior in later boot stages. Fix it by checking the return code and panicing on an error.

Fixes 9cf4a9a46717 ("device tree: add device_tree_for_each_node()")

With one remark below:

Quoted 12 lines

---
I've lost count how many times I had to fix missing rc check. However, I have not yet found any checker for this (-Wunused-result is pretty useless).

---
  xen/arch/arm/bootfdt.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
xen/arch/arm/bootfdt.c +0 -0
index b1f03eb2fcdd..f496a8cf9494 100644

xen/arch/arm/bootfdt.c size_t __init boot_fdt_info(const void *fdt, paddr_t paddr) · line 546

Quoted 7 lines
xen/arch/arm/bootfdt.c +3 -1
@@ -541,7 +541,9 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t paddr)
 
      add_boot_module(BOOTMOD_FDT, paddr, fdt_totalsize(fdt), false);
 
-    device_tree_for_each_node((void *)fdt, 0, early_scan_node, NULL);
+    ret = device_tree_for_each_node((void *)fdt, 0, early_scan_node, NULL);
+    if ( ret )
+        panic("Early FDT parsing failed (%d)\n", ret);

AFAIU, the parsing is done before the console is setup. This means a user would not be able to get some logs unless they are re-compiling Xen with earlyprintk.

I understand this is not a new issue, but I am getting concerned of the amount of check we add before the console is up and running.

What is the impact if we don't check the return here? Is it missing regions?

I wonder whether we can either enable the console earlier, or make earlyprintk more dynamic (similar to what Linux is doing with earlyprintk=...).

Cheers,

Signature · 1 line
Julien Grall
#2 lore raw

Hi Julien,

Quoted 41 lines · Julien Grall

Hi Michal,

Quoted 7 lines · Michal Orzel

As a result of not checking the return code of device_tree_for_each_node() in boot_fdt_info(), any error occured during early FDT parsing does not stop Xen from booting. This can result in an unwanted behavior in later boot stages. Fix it by checking the return code and panicing on an error.

Fixes 9cf4a9a46717 ("device tree: add device_tree_for_each_node()")

With one remark below:

Quoted 12 lines

---
I've lost count how many times I had to fix missing rc check. However, I have not yet found any checker for this (-Wunused-result is pretty useless).

---
  xen/arch/arm/bootfdt.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
xen/arch/arm/bootfdt.c +0 -0
index b1f03eb2fcdd..f496a8cf9494 100644

xen/arch/arm/bootfdt.c size_t __init boot_fdt_info(const void *fdt, paddr_t paddr) · line 546

Quoted 7 lines
xen/arch/arm/bootfdt.c +3 -1
@@ -541,7 +541,9 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t paddr)
 
      add_boot_module(BOOTMOD_FDT, paddr, fdt_totalsize(fdt), false);
 
-    device_tree_for_each_node((void *)fdt, 0, early_scan_node, NULL);
+    ret = device_tree_for_each_node((void *)fdt, 0, early_scan_node, NULL);
+    if ( ret )
+        panic("Early FDT parsing failed (%d)\n", ret);

AFAIU, the parsing is done before the console is setup. This means a user would not be able to get some logs unless they are re-compiling Xen with earlyprintk.

Quoted 4 lines

I understand this is not a new issue, but I am getting concerned of the amount of check we add before the console is up and running.

What is the impact if we don't check the return here? Is it missing regions?

There are many things that can go wrong.
Quite recently, I faced an issue where I specified 2 dom0less domUs in configuration and due to the error while parsing the last node of domU1, domU2 node was skipped and Xen booted only domU1 without giving any errors.

Issues with shared memory led to either Xen continue to run with improper configuration, silencing overlap conditions, errors at later boot stages that were impossible to deduct from the logs.

All in all, early boot code parsing assume the error to result in a failure and the parsing for domain creation makes this assumption as well (checks are more relaxed to avoid duplication).

For now, we can't do anything better than panicing early if we want to avoid unwanted behavior.

Quoted 4 lines

I wonder whether we can either enable the console earlier, or make earlyprintk more dynamic (similar to what Linux is doing with earlyprintk=...).

The most imporatant part is early fdt parsing. The main console init cannot be moved that early. We need to add earlycon support just like in Linux. User could then select either earlyprintk or earlycon. (earlyprintk would also print from assembly + from everything before boot_fdt_info). I think adding support for it is doable. But as always, no one has time for that.

~Michal

#3 lore raw

Hi Michal,

Quoted 58 lines · Michal Orzel
Quoted 41 lines · Julien Grall

Hi Michal,

Quoted 7 lines · Michal Orzel

As a result of not checking the return code of device_tree_for_each_node() in boot_fdt_info(), any error occured during early FDT parsing does not stop Xen from booting. This can result in an unwanted behavior in later boot stages. Fix it by checking the return code and panicing on an error.

Fixes 9cf4a9a46717 ("device tree: add device_tree_for_each_node()")

With one remark below:

Quoted 12 lines

---
I've lost count how many times I had to fix missing rc check. However, I have not yet found any checker for this (-Wunused-result is pretty useless).

---
   xen/arch/arm/bootfdt.c | 4 +++-
   1 file changed, 3 insertions(+), 1 deletion(-)
xen/arch/arm/bootfdt.c +0 -0
index b1f03eb2fcdd..f496a8cf9494 100644

xen/arch/arm/bootfdt.c size_t __init boot_fdt_info(const void *fdt, paddr_t paddr) · line 546

Quoted 7 lines
xen/arch/arm/bootfdt.c +3 -1
@@ -541,7 +541,9 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t paddr)
 
       add_boot_module(BOOTMOD_FDT, paddr, fdt_totalsize(fdt), false);
 
-    device_tree_for_each_node((void *)fdt, 0, early_scan_node, NULL);
+    ret = device_tree_for_each_node((void *)fdt, 0, early_scan_node, NULL);
+    if ( ret )
+        panic("Early FDT parsing failed (%d)\n", ret);

AFAIU, the parsing is done before the console is setup. This means a user would not be able to get some logs unless they are re-compiling Xen with earlyprintk.

Quoted 4 lines

I understand this is not a new issue, but I am getting concerned of the amount of check we add before the console is up and running.

What is the impact if we don't check the return here? Is it missing regions?

There are many things that can go wrong.
Quite recently, I faced an issue where I specified 2 dom0less domUs in configuration and due to the error while parsing the last node of domU1, domU2 node was skipped and Xen booted only domU1 without giving any errors.

Issues with shared memory led to either Xen continue to run with improper configuration, silencing overlap conditions, errors at later boot stages that were impossible to deduct from the logs.

All in all, early boot code parsing assume the error to result in a failure and the parsing for domain creation makes this assumption as well (checks are more relaxed to avoid duplication).

Quoted 7 lines

For now, we can't do anything better than panicing early if we want to avoid unwanted behavior.

Quoted 4 lines

I wonder whether we can either enable the console earlier, or make earlyprintk more dynamic (similar to what Linux is doing with earlyprintk=...).

The most imporatant part is early fdt parsing. The main console init cannot be moved that early.

I think we need to understand a bit more why because on x86 consoel_init_preirq() is called very early. So we ought to be able to do the same on Arm.

I will add this in my list after I get the earlyprintk working while switching the MMU.

Cheers,

Signature · 1 line
Julien Grall
#4 lore raw
Quoted 66 lines · Julien Grall

Hi Michal,

Quoted 61 lines · Michal Orzel
Quoted 41 lines · Julien Grall

Hi Michal,

Quoted 7 lines · Michal Orzel

As a result of not checking the return code of device_tree_for_each_node() in boot_fdt_info(), any error occured during early FDT parsing does not stop Xen from booting. This can result in an unwanted behavior in later boot stages. Fix it by checking the return code and panicing on an error.

Fixes 9cf4a9a46717 ("device tree: add device_tree_for_each_node()")

With one remark below:

Quoted 12 lines

---
I've lost count how many times I had to fix missing rc check. However, I have not yet found any checker for this (-Wunused-result is pretty useless).

---
   xen/arch/arm/bootfdt.c | 4 +++-
   1 file changed, 3 insertions(+), 1 deletion(-)
xen/arch/arm/bootfdt.c +0 -0
index b1f03eb2fcdd..f496a8cf9494 100644

xen/arch/arm/bootfdt.c size_t __init boot_fdt_info(const void *fdt, paddr_t paddr) · line 546

Quoted 7 lines
xen/arch/arm/bootfdt.c +3 -1
@@ -541,7 +541,9 @@ size_t __init boot_fdt_info(const void *fdt, paddr_t paddr)
 
       add_boot_module(BOOTMOD_FDT, paddr, fdt_totalsize(fdt), false);
 
-    device_tree_for_each_node((void *)fdt, 0, early_scan_node, NULL);
+    ret = device_tree_for_each_node((void *)fdt, 0, early_scan_node, NULL);
+    if ( ret )
+        panic("Early FDT parsing failed (%d)\n", ret);

AFAIU, the parsing is done before the console is setup. This means a user would not be able to get some logs unless they are re-compiling Xen with earlyprintk.

Quoted 4 lines

I understand this is not a new issue, but I am getting concerned of the amount of check we add before the console is up and running.

What is the impact if we don't check the return here? Is it missing regions?

There are many things that can go wrong.
Quite recently, I faced an issue where I specified 2 dom0less domUs in configuration and due to the error while parsing the last node of domU1, domU2 node was skipped and Xen booted only domU1 without giving any errors.

Issues with shared memory led to either Xen continue to run with improper configuration, silencing overlap conditions, errors at later boot stages that were impossible to deduct from the logs.

All in all, early boot code parsing assume the error to result in a failure and the parsing for domain creation makes this assumption as well (checks are more relaxed to avoid duplication).

For now, we can't do anything better than panicing early if we want to avoid unwanted behavior.

Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

I wonder whether we can either enable the console earlier, or make earlyprintk more dynamic (similar to what Linux is doing with earlyprintk=...).

The most imporatant part is early fdt parsing. The main console init cannot be moved that early.

I think we need to understand a bit more why because on x86 consoel_init_preirq() is called very early. So we ought to be able to do the same on Arm.

But this won't cover early fdt parsing. I don't think we can get away without adding earlycon and earlycon helpers in all the serial drivers. arm_uart_init depends on unflattening fdt which depends on relocating fdt which is done after parsing FDT. We want to be able to print messages after early_fdt_map. Once FDT is mapped, the only thing we need is to retrieve the bootargs to parse for earlycon= , add the region to fixmap and register the handlers.

~Michal

#5 lore raw
In reply to Julien Grall
Quoted 8 lines · Julien Grall

Hi Michal,

Quoted 5 lines · Michal Orzel

As a result of not checking the return code of device_tree_for_each_node() in boot_fdt_info(), any error occured during early FDT parsing does not stop Xen from booting. This can result in an unwanted behavior in later boot stages. Fix it by checking the return code and panicing on an error.

Quoted 6 lines
Quoted 2 lines
Fixes 9cf4a9a46717 ("device tree: add device_tree_for_each_node()")

With one remark below:

It is now committed.

Cheers,

Signature · 1 line
Julien Grall