Skip to contentSkip to conversation

Do basic initialization things

PATCH In review Oleksii Kurochko 4 participants 17 messages Mar 3, 2023 – Mar 16, 2023 RISC-V

lore
Share & tools
lore
#0 lore raw

v3 cover Do basic initialization things

The patch series groups and updates the following patches:
1. xen/riscv: disable fpu
2. xen/riscv: initialize .bss section
3. xen/riscv: read/save hart_id and dtb_base passed by bootloader

---
Changes since v2:
* Patch [xen/riscv: disable fpu] was moved to the start of start() function to detect illegal usage of floating point earlier.
* Add dummy_bss variable to make .bss initialization code more simple.
* Change comparison of addresses from signed to unsigned.
* Add the comment for start() function with the explanation what and how OpenSBI pass to start() function.
* Clean up start() code related to read&save hart_id & dtb_base.
---
Changes since v1:
* initialization of .bss was moved to head.S
* read/save/pass of hart_id and dtb_base passed by a bootloader were moved to head.S. Also, it was updated start_xen() arguments to recieve hard_id & dtb_base
---

Oleksii Kurochko (3):
xen/riscv: disable fpu
xen/riscv: read/save hart_id and dtb_base passed by bootloader xen/riscv: initialize .bss section

 xen/arch/riscv/riscv64/head.S | 21 +++++++++++++++++++++
 xen/arch/riscv/setup.c        | 11 ++++++++++-
 2 files changed, 31 insertions(+), 1 deletion(-)
Signature · 1 line
2.39.0
#1 lore raw

PATCH v3 1/3 xen/riscv: disable fpu

Disable FPU to detect illegal usage of floating point in kernel space.

---
 xen/arch/riscv/riscv64/head.S | 7 +++++++
 1 file changed, 7 insertions(+)
xen/arch/riscv/riscv64/head.S +7 -0
index ffd95f9f89..52fa41c778 100644
@@ -6,6 +6,13 @@ ENTRY(start)
         /* Mask all interrupts */
         csrw    CSR_SIE, zero
 
+        /*
+         * Disable FPU to detect illegal usage of
+         * floating point in kernel space
+         */
+        li      t0, SSTATUS_FS
+        csrc    CSR_SSTATUS, t0
+
         la      sp, cpu0_boot_stack
         li      t0, STACK_SIZE
         add     sp, sp, t0
Signature · 1 line
2.39.0
Acked-by on v3 1/3
#3 lore raw

Re: [PATCH v3 1/3] xen/riscv: disable fpu

In reply to Oleksii Kurochko
Quoted 30 lines · Oleksii Kurochko

Disable FPU to detect illegal usage of floating point in kernel space.

---
 xen/arch/riscv/riscv64/head.S | 7 +++++++
 1 file changed, 7 insertions(+)
xen/arch/riscv/riscv64/head.S +7 -0
index ffd95f9f89..52fa41c778 100644
@@ -6,6 +6,13 @@ ENTRY(start)
         /* Mask all interrupts */
         csrw    CSR_SIE, zero
 
+        /*
+         * Disable FPU to detect illegal usage of
+         * floating point in kernel space
+         */
+        li      t0, SSTATUS_FS
+        csrc    CSR_SSTATUS, t0
+
         la      sp, cpu0_boot_stack
         li      t0, STACK_SIZE
         add     sp, sp, t0
Signature · 1 line
2.39.0
Reviewed-by on v3 1/3
#4 lore raw

Re: [PATCH v3 1/3] xen/riscv: disable fpu

In reply to Oleksii Kurochko
Quoted 30 lines · Oleksii Kurochko

Disable FPU to detect illegal usage of floating point in kernel space.

---
 xen/arch/riscv/riscv64/head.S | 7 +++++++
 1 file changed, 7 insertions(+)
xen/arch/riscv/riscv64/head.S +7 -0
index ffd95f9f89..52fa41c778 100644
@@ -6,6 +6,13 @@ ENTRY(start)
         /* Mask all interrupts */
         csrw    CSR_SIE, zero
 
+        /*
+         * Disable FPU to detect illegal usage of
+         * floating point in kernel space
+         */
+        li      t0, SSTATUS_FS
+        csrc    CSR_SSTATUS, t0
+
         la      sp, cpu0_boot_stack
         li      t0, STACK_SIZE
         add     sp, sp, t0
Signature · 1 line
2.39.0

My last email had the wrong trailer:

#5 lore raw

PATCH v3 2/3 xen/riscv: read/save hart_id and dtb_base passed by bootloader

In reply to Oleksii Kurochko

---
Changes since v2:
* Add the comment for start() function with the explanation what and how OpenSBI pass to start() function.
* Clean up start() code related to read&save hart_id & dtb_base.
---
Changes since v1:
* read/save/pass of hart_id and dtb_base passed by a bootloader were moved to head.S.
* Update start_xen() to recieve hard_id & dtb_base

---
 xen/arch/riscv/riscv64/head.S | 5 +++++
 xen/arch/riscv/setup.c        | 3 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)
xen/arch/riscv/riscv64/head.S +5 -0
index 52fa41c778..adf5d6c74a 100644
@@ -2,6 +2,11 @@
 
         .section .text.header, "ax", %progbits
 
+        /*
+         * OpenSBI pass to start():
+         *   a0 -> hart_id ( bootcpu_id )
+         *   a1 -> dtb_base 
+         */
 ENTRY(start)
         /* Mask all interrupts */
         csrw    CSR_SIE, zero
xen/arch/riscv/setup.c +2 -1
index 1c87899e8e..d9723fe1c0 100644
@@ -7,7 +7,8 @@
 unsigned char __initdata cpu0_boot_stack[STACK_SIZE]
     __aligned(STACK_SIZE);
 
-void __init noreturn start_xen(void)
+void __init noreturn start_xen(unsigned long bootcpu_id,
+                               unsigned long dtb_base)
 {
     early_printk("Hello from C env\n");
 
Signature · 1 line
2.39.0
Reviewed-by on v3 2/3
#6 lore raw

Re: [PATCH v3 2/3] xen/riscv: read/save hart_id and dtb_base passed by bootloader

Quoted 1 line · Oleksii Kurochko

occurs to me...

xen/arch/riscv/setup.c line 11

Quoted 11 lines
xen/arch/riscv/setup.c +2 -1
index 1c87899e8e..d9723fe1c0 100644
@@ -7,7 +7,8 @@
 unsigned char __initdata cpu0_boot_stack[STACK_SIZE]
     __aligned(STACK_SIZE);
 
-void __init noreturn start_xen(void)
+void __init noreturn start_xen(unsigned long bootcpu_id,
+                               unsigned long dtb_base)

dtb_base probably wants renaming to dtb_paddr as the pagetable series is just about to make it a non-identity mapping between the two address spaces.

Can fix on commit if you're happy with the suggestion?

~Andrew

author
#7 lore raw

Re: [PATCH v3 2/3] xen/riscv: read/save hart_id and dtb_base passed by bootloader

Quoted 23 lines · Andrew Cooper
Quoted 1 line · Oleksii Kurochko

occurs to me...

xen/arch/riscv/setup.c line 11

Quoted 11 lines
xen/arch/riscv/setup.c +0 -0
index 1c87899e8e..d9723fe1c0 100644
@@ -7,7 +7,8 @@

 unsigned char __initdata cpu0_boot_stack[STACK_SIZE] __aligned(STACK_SIZE);

xen/arch/riscv/setup.c +2 -1
-void __init noreturn start_xen(void)
+void __init noreturn start_xen(unsigned long bootcpu_id,
+                               unsigned long dtb_base)

dtb_base probably wants renaming to dtb_paddr as the pagetable series is
just about to make it a non-identity mapping between the two address spaces.

Quoted 1 line

Can fix on commit if you're happy with the suggestion?

I will be happy with that.

Thanks.

~ Oleksii

Reviewed-by on v3 2/3
#8 lore raw

Re: [PATCH v3 2/3] xen/riscv: read/save hart_id and dtb_base passed by bootloader

In reply to Oleksii Kurochko
Quoted 50 lines · Oleksii Kurochko

---
Changes since v2:
* Add the comment for start() function with the explanation what and how OpenSBI pass to start() function.
* Clean up start() code related to read&save hart_id & dtb_base.
---
Changes since v1:
* read/save/pass of hart_id and dtb_base passed by a bootloader were moved to head.S.
* Update start_xen() to recieve hard_id & dtb_base

---
 xen/arch/riscv/riscv64/head.S | 5 +++++
 xen/arch/riscv/setup.c        | 3 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)
xen/arch/riscv/riscv64/head.S +5 -0
index 52fa41c778..adf5d6c74a 100644
@@ -2,6 +2,11 @@
 
         .section .text.header, "ax", %progbits
 
+        /*
+         * OpenSBI pass to start():
+         *   a0 -> hart_id ( bootcpu_id )
+         *   a1 -> dtb_base 
+         */
 ENTRY(start)
         /* Mask all interrupts */
         csrw    CSR_SIE, zero
xen/arch/riscv/setup.c +2 -1
index 1c87899e8e..d9723fe1c0 100644
@@ -7,7 +7,8 @@
 unsigned char __initdata cpu0_boot_stack[STACK_SIZE]
     __aligned(STACK_SIZE);
 
-void __init noreturn start_xen(void)
+void __init noreturn start_xen(unsigned long bootcpu_id,
+                               unsigned long dtb_base)
 {
     early_printk("Hello from C env\n");
 
Signature · 1 line
2.39.0
#9 lore raw

PATCH v3 3/3 xen/riscv: initialize .bss section

In reply to Oleksii Kurochko
---
 xen/arch/riscv/riscv64/head.S | 9 +++++++++
 xen/arch/riscv/setup.c        | 8 ++++++++
 2 files changed, 17 insertions(+)
xen/arch/riscv/riscv64/head.S +9 -0
index adf5d6c74a..8887f0cbd4 100644
@@ -1,3 +1,4 @@
+#include <asm/asm.h>
 #include <asm/riscv_encoding.h>
 
         .section .text.header, "ax", %progbits
@@ -18,6 +19,14 @@ ENTRY(start)
         li      t0, SSTATUS_FS
         csrc    CSR_SSTATUS, t0
 
+        /* Clear the BSS */
+        la      t3, __bss_start
+        la      t4, __bss_end
+.L_clear_bss:
+        REG_S   zero, (t3)
+        add     t3, t3, __SIZEOF_POINTER__
+        bltu    t3, t4, .L_clear_bss
+
         la      sp, cpu0_boot_stack
         li      t0, STACK_SIZE
         add     sp, sp, t0
xen/arch/riscv/setup.c +8 -0
index d9723fe1c0..929565720b 100644
@@ -7,6 +7,14 @@
 unsigned char __initdata cpu0_boot_stack[STACK_SIZE]
     __aligned(STACK_SIZE);
 
+/*  
+ * To be sure that .bss isn't zero. It will simplify code of
+ * .bss initialization.
+ * TODO:
+ *   To be deleted when the first real .bss user appears
+ */
+int dummy_bss __attribute__((unused));
+
 void __init noreturn start_xen(unsigned long bootcpu_id,
                                unsigned long dtb_base)
 {
Signature · 1 line
2.39.0
Reviewed-by on v3 3/3
#10 lore raw

Re: [PATCH v3 3/3] xen/riscv: initialize .bss section

Quoted 1 line · Oleksii Kurochko
Quoted 5 lines
xen/arch/riscv/riscv64/head.S +0 -0
index adf5d6c74a..8887f0cbd4 100644

xen/arch/riscv/riscv64/head.S ENTRY(start) · line 28

Quoted 10 lines
xen/arch/riscv/riscv64/head.S +7 -0
@@ -18,6 +19,14 @@ ENTRY(start)
         li      t0, SSTATUS_FS
         csrc    CSR_SSTATUS, t0
 
+        /* Clear the BSS */
+        la      t3, __bss_start
+        la      t4, __bss_end
+.L_clear_bss:
+        REG_S   zero, (t3)
+        add     t3, t3, __SIZEOF_POINTER__
+        bltu    t3, t4, .L_clear_bss

Using t3/t4 is fine, but it would also have been fine to use t0/t1.

~Andrew

author
#11 lore raw

Re: [PATCH v3 3/3] xen/riscv: initialize .bss section

Quoted 15 lines · Andrew Cooper
Quoted 1 line · Oleksii Kurochko
Quoted 10 lines
xen/arch/riscv/riscv64/head.S +0 -0
index adf5d6c74a..8887f0cbd4 100644
@@ -18,6 +19,14 @@ ENTRY(start)

         li      t0, SSTATUS_FS
         csrc    CSR_SSTATUS, t0

+        /* Clear the BSS */

Quoted 8 lines
Quoted 6 lines

+        la      t3, __bss_start
+        la      t4, __bss_end
+.L_clear_bss:
+        REG_S   zero, (t3)
+        add     t3, t3, __SIZEOF_POINTER__
+        bltu    t3, t4, .L_clear_bss

Using t3/t4 is fine, but it would also have been fine to use t0/t1.

Yeah, I understand that. It was easier to rename and not confuse something.

Could you please rename them during commit?
Have I to send new patch version?

~ Oleksii

#12 lore raw

Re: [PATCH v3 3/3] xen/riscv: initialize .bss section

Quoted 22 lines · Oleksii
Quoted 13 lines · Andrew Cooper
Quoted 1 line · Oleksii Kurochko
Quoted 9 lines
xen/arch/riscv/riscv64/head.S +0 -0
index adf5d6c74a..8887f0cbd4 100644
@@ -18,6 +19,14 @@ ENTRY(start)

         li      t0, SSTATUS_FS
         csrc    CSR_SSTATUS, t0

Quoted 8 lines
Quoted 7 lines

+        /* Clear the BSS */
+        la      t3, __bss_start
+        la      t4, __bss_end
+.L_clear_bss:
+        REG_S   zero, (t3)
+        add     t3, t3, __SIZEOF_POINTER__
+        bltu    t3, t4, .L_clear_bss

Using t3/t4 is fine, but it would also have been fine to use t0/t1.

Quoted 5 lines

Yeah, I understand that. It was easier to rename and not confuse something.

Could you please rename them during commit?
Have I to send new patch version?

No need to send another patch.  TBH, I wasn't intending to change it at all - this was just supposed to be a note - but I can if you'd prefer.

~Andrew

author
#13 lore raw

Re: [PATCH v3 3/3] xen/riscv: initialize .bss section

Quoted 27 lines · Andrew Cooper
Quoted 26 lines · Oleksii
Quoted 14 lines · Andrew Cooper
Quoted 1 line · Oleksii Kurochko
Quoted 10 lines
xen/arch/riscv/riscv64/head.S +0 -0
index adf5d6c74a..8887f0cbd4 100644
@@ -18,6 +19,14 @@ ENTRY(start)

         li      t0, SSTATUS_FS
         csrc    CSR_SSTATUS, t0

+        /* Clear the BSS */

Quoted 8 lines
Quoted 6 lines

+        la      t3, __bss_start
+        la      t4, __bss_end
+.L_clear_bss:
+        REG_S   zero, (t3)
+        add     t3, t3, __SIZEOF_POINTER__
+        bltu    t3, t4, .L_clear_bss

Using t3/t4 is fine, but it would also have been fine to use t0/t1.

Yeah, I understand that. It was easier to rename and not confuse something.

Quoted 7 lines
Quoted 2 lines

Could you please rename them during commit?
Have I to send new patch version?

No need to send another patch.  TBH, I wasn't intending to change it at
all - this was just supposed to be a note - but I can if you'd prefer.

Feel free to do that.

Thanks.

~ Oleksii

Reviewed-by on v3 3/3
#14 lore raw

Re: [PATCH v3 3/3] xen/riscv: initialize .bss section

In reply to Oleksii Kurochko
Quoted 53 lines · Oleksii Kurochko
---
 xen/arch/riscv/riscv64/head.S | 9 +++++++++
 xen/arch/riscv/setup.c        | 8 ++++++++
 2 files changed, 17 insertions(+)
xen/arch/riscv/riscv64/head.S +9 -0
index adf5d6c74a..8887f0cbd4 100644
@@ -1,3 +1,4 @@
+#include <asm/asm.h>
 #include <asm/riscv_encoding.h>
 
         .section .text.header, "ax", %progbits
@@ -18,6 +19,14 @@ ENTRY(start)
         li      t0, SSTATUS_FS
         csrc    CSR_SSTATUS, t0
 
+        /* Clear the BSS */
+        la      t3, __bss_start
+        la      t4, __bss_end
+.L_clear_bss:
+        REG_S   zero, (t3)
+        add     t3, t3, __SIZEOF_POINTER__
+        bltu    t3, t4, .L_clear_bss
+
         la      sp, cpu0_boot_stack
         li      t0, STACK_SIZE
         add     sp, sp, t0
xen/arch/riscv/setup.c +8 -0
index d9723fe1c0..929565720b 100644
@@ -7,6 +7,14 @@
 unsigned char __initdata cpu0_boot_stack[STACK_SIZE]
     __aligned(STACK_SIZE);
 
+/*  
+ * To be sure that .bss isn't zero. It will simplify code of
+ * .bss initialization.
+ * TODO:
+ *   To be deleted when the first real .bss user appears
+ */
+int dummy_bss __attribute__((unused));
+
 void __init noreturn start_xen(unsigned long bootcpu_id,
                                unsigned long dtb_base)
 {
Signature · 1 line
2.39.0
#15 lore raw
In reply to Oleksii Kurochko

I just wanted to let you know I have this queued up to review, I’ve just been very overloaded. I’ll give these a review in the coming week.

Best,
Bobby

Quoted 36 lines · Oleksii Kurochko

The patch series groups and updates the following patches:
1. xen/riscv: disable fpu
2. xen/riscv: initialize .bss section
3. xen/riscv: read/save hart_id and dtb_base passed by bootloader

---
Changes since v2:
* Patch [xen/riscv: disable fpu] was moved to the start of start() function to detect illegal usage of floating point earlier.
* Add dummy_bss variable to make .bss initialization code more simple.
* Change comparison of addresses from signed to unsigned.
* Add the comment for start() function with the explanation what and how OpenSBI pass to start() function.
* Clean up start() code related to read&save hart_id & dtb_base.
---
Changes since v1:
* initialization of .bss was moved to head.S
* read/save/pass of hart_id and dtb_base passed by a bootloader were moved to head.S. Also, it was updated start_xen() arguments to recieve hard_id & dtb_base
---

Oleksii Kurochko (3):
xen/riscv: disable fpu
xen/riscv: read/save hart_id and dtb_base passed by bootloader xen/riscv: initialize .bss section

 xen/arch/riscv/riscv64/head.S | 21 +++++++++++++++++++++
 xen/arch/riscv/setup.c        | 11 ++++++++++-
 2 files changed, 31 insertions(+), 1 deletion(-)

--
2.39.0

#16 lore raw
Quoted 2 lines · Bobby Eshleman

I just wanted to let you know I have this queued up to review, I’ve just been very overloaded. I’ll give these a review in the coming week.

Any update on this?

FWIW, all 3 look ready to go in to me, so hopefully its very easy.

~Andrew