Skip to contentSkip to conversation

Parse and handle command line from dtb

PATCH In review Oleksii Kurochko 3 participants 9 messages Oct 10, 2024 – Oct 16, 2024 RISC-V

lore
Share & tools
lore
#8 lore raw

PATCH v2 2/2 xen/riscv: parse and handle fdt command line

In reply to Oleksii Kurochko

Receive Xen's command line passed by DTB using boot_fdt_cmdline() and passed it to cmdline_parse() for further procesinng and setup of Xen-specific parameters.

---
Changes in V2:
- add Acked-by: Jan Beulich <[email protected]>

---
 xen/arch/riscv/setup.c | 6 ++++++
 1 file changed, 6 insertions(+)
xen/arch/riscv/setup.c +6 -0
index a345dbafeb..cd33fab6a0 100644
@@ -27,6 +27,8 @@ unsigned char __initdata cpu0_boot_stack[STACK_SIZE]
 void __init noreturn start_xen(unsigned long bootcpu_id,
                                paddr_t dtb_addr)
 {
+    const char *cmdline;
+
     remove_identity_mapping();
 
     set_processor_id(0);
@@ -52,6 +54,10 @@ void __init noreturn start_xen(unsigned long bootcpu_id,
 
     BUG_ON(!boot_fdt_info(device_tree_flattened, dtb_addr));
 
+    cmdline = boot_fdt_cmdline(device_tree_flattened);
+    printk("Command line: %s\n", cmdline);
+    cmdline_parse(cmdline);
+
     printk("All set up\n");
 
     machine_halt();
Signature · 1 line
2.46.2
#0 lore raw

v2 cover Parse and handle command line from dtb

This patch series initializes bootinfo from dtb and then parse and handle command line from dtb.

---
Changes in v2:
- Update the cover letter message: drop information about patch series dependency.
- Add Acked-by for the patch 2 ( xen/riscv: parse and handle fdt command line )
- Minor changes for patch 1 ( xen/riscv: initialize bootinfo from dtb ):
- Drop local variable fdt_size as it is going to be used only once.
---

Oleksii Kurochko (2):
xen/riscv: initialize bootinfo from dtb
xen/riscv: parse and handle fdt command line

 xen/arch/riscv/setup.c | 8 ++++++++
 1 file changed, 8 insertions(+)
Signature · 1 line
2.46.2
#1 lore raw

PATCH v2 1/2 xen/riscv: initialize bootinfo from dtb

Parse DTB during startup, allowing memory banks and reserved memory regions to be set up, along with early device tree node ( chosen, "xen,domain", "reserved-memory", etc ) handling.

---
Changes in V2:
- Drop local variable fdt_size as it is going to be used only once.

---
 xen/arch/riscv/setup.c | 2 ++
 1 file changed, 2 insertions(+)
xen/arch/riscv/setup.c +2 -0
index f531ca38ee..a345dbafeb 100644
@@ -50,6 +50,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id,
                           _end - _start, false) )
         panic("Failed to add BOOTMOD_XEN\n");
 
+    BUG_ON(!boot_fdt_info(device_tree_flattened, dtb_addr));
+
     printk("All set up\n");
 
     machine_halt();
Signature · 1 line
2.46.2
Acked-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] xen/riscv: initialize bootinfo from dtb

xen/arch/riscv/setup.c void __init noreturn start_xen(unsigned long bootcpu_id, · line 53

Quoted 7 lines · Oleksii Kurochko
xen/arch/riscv/setup.c +1 -0
@@ -50,6 +50,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id,
                           _end - _start, false) )
         panic("Failed to add BOOTMOD_XEN\n");
 
+    BUG_ON(!boot_fdt_info(device_tree_flattened, dtb_addr));

We generally aim at avoiding side effects in BUG_ON() (or ASSERT()). With

if (!boot_fdt_info(device_tree_flattened, dtb_addr))
BUG();

I can make the adjustment while committing, if desired.

Jan

#3 lore raw

Re: [PATCH v2 1/2] xen/riscv: initialize bootinfo from dtb

Quoted 13 lines · Jan Beulich
Quoted 8 lines · Oleksii Kurochko
xen/arch/riscv/setup.c +0 -0
@@ -50,6 +50,8 @@ void __init noreturn start_xen(unsigned long
 bootcpu_id,
                            _end - _start, false) )
          panic("Failed to add BOOTMOD_XEN\n");


+    BUG_ON(!boot_fdt_info(device_tree_flattened, dtb_addr));

We generally aim at avoiding side effects in BUG_ON() (or ASSERT()). With

Quoted 6 lines

    if (!boot_fdt_info(device_tree_flattened, dtb_addr)) BUG();

I can make the adjustment while committing, if desired.

It would be great if these changes could be made during the commit.

Thanks.

~ Oleksii

#4 lore raw

Re: [PATCH v2 1/2] xen/riscv: initialize bootinfo from dtb

Quoted 14 lines · On 15.10.2024 11:11, [email protected] wrote:
Quoted 13 lines · Jan Beulich
Quoted 8 lines · Oleksii Kurochko
xen/arch/riscv/setup.c +0 -0
@@ -50,6 +50,8 @@ void __init noreturn start_xen(unsigned long
 bootcpu_id,
                            _end - _start, false) )
          panic("Failed to add BOOTMOD_XEN\n");


+    BUG_ON(!boot_fdt_info(device_tree_flattened, dtb_addr));

We generally aim at avoiding side effects in BUG_ON() (or ASSERT()). With

Quoted 7 lines
Quoted 6 lines

    if (!boot_fdt_info(device_tree_flattened, dtb_addr)) BUG();

I can make the adjustment while committing, if desired.

It would be great if these changes could be made during the commit.

I've committed it with the adjustment, yet once again I wondered: Why not panic()?

Jan

#5 lore raw

Re: [PATCH v2 1/2] xen/riscv: initialize bootinfo from dtb

Quoted 19 lines · Jan Beulich
Quoted 18 lines · On 15.10.2024 11:11, [email protected] wrote:
Quoted 17 lines · Jan Beulich
Quoted 8 lines · Oleksii Kurochko
xen/arch/riscv/setup.c +0 -0
@@ -50,6 +50,8 @@ void __init noreturn start_xen(unsigned long
 bootcpu_id,
                            _end - _start, false) )
          panic("Failed to add BOOTMOD_XEN\n");


+    BUG_ON(!boot_fdt_info(device_tree_flattened, dtb_addr));

We generally aim at avoiding side effects in BUG_ON() (or ASSERT()).
With

    if (!boot_fdt_info(device_tree_flattened, dtb_addr)) BUG();

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

I can make the adjustment while committing, if desired.

It would be great if these changes could be made during the commit.

I've committed it with the adjustment,

Thanks!

Quoted 2 lines

yet once again I wondered: Why not
panic()?

It could be panic() here; there's no specific reason. I agree that using BUG() here isn't logically correct, as technically, a size of zero for the FDT isn't a bug but rather indicates that someone provided an incorrect FDT to Xen.

I will use panic() in the future for such cases.

It’s not always clear what should be used and where. Perhaps it would be helpful to add some explanation somewhere.

~ Oleksii

#6 lore raw

Re: [PATCH v2 1/2] xen/riscv: initialize bootinfo from dtb

Quoted 35 lines · On 16.10.2024 09:50, [email protected] wrote:
Quoted 19 lines · Jan Beulich
Quoted 18 lines · On 15.10.2024 11:11, [email protected] wrote:
Quoted 17 lines · Jan Beulich
Quoted 8 lines · Oleksii Kurochko
xen/arch/riscv/setup.c +0 -0
@@ -50,6 +50,8 @@ void __init noreturn start_xen(unsigned long
 bootcpu_id,
                            _end - _start, false) )
          panic("Failed to add BOOTMOD_XEN\n");


+    BUG_ON(!boot_fdt_info(device_tree_flattened, dtb_addr));

We generally aim at avoiding side effects in BUG_ON() (or ASSERT()).
With

    if (!boot_fdt_info(device_tree_flattened, dtb_addr)) BUG();

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

I can make the adjustment while committing, if desired.

It would be great if these changes could be made during the commit.

I've committed it with the adjustment,

Thanks!

Quoted 2 lines

yet once again I wondered: Why not
panic()?

It could be panic() here; there's no specific reason. I agree that using BUG() here isn't logically correct, as technically, a size of zero for the FDT isn't a bug but rather indicates that someone provided an incorrect FDT to Xen.

Quoted 4 lines

I will use panic() in the future for such cases.

It’s not always clear what should be used and where. Perhaps it would be helpful to add some explanation somewhere.

My rule of thumb: During init and when the call stack / register state aren't relevant to understand the details of the issue, use panic().

Jan

#7 lore raw

Re: [PATCH v2 1/2] xen/riscv: initialize bootinfo from dtb

In reply to [email protected]
Quoted 33 lines · On 16/10/2024 8:50 am, [email protected] wrote:
Quoted 15 lines · Jan Beulich
Quoted 14 lines · On 15.10.2024 11:11, [email protected] wrote:
Quoted 13 lines · Jan Beulich
Quoted 8 lines · Oleksii Kurochko
xen/arch/riscv/setup.c +0 -0
@@ -50,6 +50,8 @@ void __init noreturn start_xen(unsigned long
 bootcpu_id,
                            _end - _start, false) )
          panic("Failed to add BOOTMOD_XEN\n");


+    BUG_ON(!boot_fdt_info(device_tree_flattened, dtb_addr));

We generally aim at avoiding side effects in BUG_ON() (or ASSERT()).
With

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines

    if (!boot_fdt_info(device_tree_flattened, dtb_addr)) BUG();

I can make the adjustment while committing, if desired.

It would be great if these changes could be made during the commit.

I've committed it with the adjustment,

Thanks!

Quoted 2 lines

yet once again I wondered: Why not
panic()?

It could be panic() here; there's no specific reason. I agree that using BUG() here isn't logically correct, as technically, a size of zero for the FDT isn't a bug but rather indicates that someone provided an incorrect FDT to Xen.

Quoted 4 lines

I will use panic() in the future for such cases.

It’s not always clear what should be used and where. Perhaps it would be helpful to add some explanation somewhere.

panic() gets you a single line diagnostic.  BUG() gets you a backtrace, but no diagnostic information at all.

BUG() should be a last resort, because it requires someone to go digging in the source code to even figure out what went wrong.  panic() (with a good diagnostic message, e.g. "unexpected $foo in device tree") is far more meaningful.

There are ways of getting a backtrace in combination with a panic(), if the situation warrants it.

~Andrew