Skip to contentSkip to conversation

riscv/purgatory: align riscv_kernel_entry

PATCH Superseded Daniel Maslowski 2 participants 3 messages Jul 9, 2024 – Jul 15, 2024 RISC-V

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv/purgatory: align riscv_kernel_entry

When alignment handling is delegated to the kernel, everything must be word-aligned in purgatory, since the trap handler is then set to the kexec one. Without the alignment, hitting the exception would ultimately crash. On other occasions, the kernel's handler would take care of exceptions.
This has been tested with oreboot and its SBI delegating unaligned access exceptions and the kernel configured to handle them.

---
 arch/riscv/purgatory/entry.S | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/purgatory/entry.S +1 -0
index 5bcf3af903da..29121650a941 100644
@@ -34,6 +34,7 @@ SYM_CODE_END(purgatory_start)
 
 .data
 
+.align 4
 SYM_DATA(riscv_kernel_entry, .quad 0)
 
 .end
Signature · 7 lines
2.34.1


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

Hi Daniel,

Quoted 18 lines · Daniel Maslowski

When alignment handling is delegated to the kernel, everything must be word-aligned in purgatory, since the trap handler is then set to the kexec one. Without the alignment, hitting the exception would ultimately crash. On other occasions, the kernel's handler would take care of exceptions.
This has been tested with oreboot and its SBI delegating unaligned access exceptions and the kernel configured to handle them.

---
  arch/riscv/purgatory/entry.S | 1 +
  1 file changed, 1 insertion(+)
arch/riscv/purgatory/entry.S +0 -0
index 5bcf3af903da..29121650a941 100644

arch/riscv/purgatory/entry.S SYM_CODE_END(purgatory_start) · line 37

Quoted 4 lines
arch/riscv/purgatory/entry.S +1 -0
@@ -34,6 +34,7 @@ SYM_CODE_END(purgatory_start)
 
  .data
 
+.align 4

IIRC, .align on riscv takes a power of two as argument, which means you align riscv_kernel_entry symbol to 16B here, any reason for this alignment? I guess you want 4B on rv32 and 8B on rv64 right? In that case, the best here would be to use LGREG https://elixir.bootlin.com/linux/latest/source/arch/riscv/include/asm/asm.h#L29

Thanks,

Alex

arch/riscv/purgatory/entry.S SYM_CODE_END(purgatory_start) · line 40

Quoted 3 lines
arch/riscv/purgatory/entry.S +0 -0
  SYM_DATA(riscv_kernel_entry, .quad 0)
 
  .end

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

#2 lore raw
Quoted 32 lines · Alexandre Ghiti

Hi Daniel,

Quoted 18 lines · Daniel Maslowski

When alignment handling is delegated to the kernel, everything must be word-aligned in purgatory, since the trap handler is then set to the kexec one. Without the alignment, hitting the exception would ultimately crash. On other occasions, the kernel's handler would take care of exceptions.
This has been tested with oreboot and its SBI delegating unaligned access exceptions and the kernel configured to handle them.

---
  arch/riscv/purgatory/entry.S | 1 +

  1 file changed, 1 insertion(+)
arch/riscv/purgatory/entry.S +0 -0
index 5bcf3af903da..29121650a941 100644
@@ -34,6 +34,7 @@ SYM_CODE_END(purgatory_start)
Quoted 2 lines

    .data
  +.align 4

IIRC, .align on riscv takes a power of two as argument, which means you align riscv_kernel_entry symbol to 16B here, any reason for this alignment? I guess you want 4B on rv32 and 8B on rv64 right? In that case, the best here would be to use LGREG https://elixir.bootlin.com/linux/latest/source/arch/riscv/include/asm/asm.h#L29

Thanks,

Alex

Quoted 7 lines
Quoted 2 lines

  SYM_DATA(riscv_kernel_entry, .quad 0)
    .end

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

And since this is a fix, can you add a Fixes tag please?

Thanks,

Alex

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