Skip to contentSkip to conversation

riscv: fix scratch register clearing in M-mode.

PATCH In review Greentime Hu 3 participants 3 messages Dec 19, 2019 – Dec 20, 2019 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: fix scratch register clearing in M-mode.

This patch fixes that the sscratch register clearing in M-mode. It cleared sscratch register in M-mode, but it should clear mscratch register. That will cause kernel trap if the CPU core doesn't support S-mode when trying to access sscratch.

Fixes 9e80635619b5 ("riscv: clear the instruction cache and all registers when booting")
---
 arch/riscv/kernel/head.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/head.S +1 -1
index 84a6f0a4b120..797802c73dee 100644
@@ -246,7 +246,7 @@ ENTRY(reset_regs)
 	li	t4, 0
 	li	t5, 0
 	li	t6, 0
-	csrw	sscratch, 0
+	csrw	CSR_SCRATCH, 0
 
 #ifdef CONFIG_FPU
 	csrr	t0, CSR_MISA
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Greentime Hu

This patch fixes that the sscratch register clearing in M-mode. It cleared sscratch register in M-mode, but it should clear mscratch register. That will cause kernel trap if the CPU core doesn't support S-mode when trying to access sscratch.

Fixes 9e80635619b5 ("riscv: clear the instruction cache and all registers when booting")

In any case, we should always prefer accessing CSRs using CSR_xyz defines.

Looks good to me.

Regards,
Anup

Quoted 21 lines
---
 arch/riscv/kernel/head.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/head.S +1 -2
index 84a6f0a4b120..797802c73dee 100644
@@ -246,7 +246,7 @@ ENTRY(reset_regs)
        li      t4, 0
        li      t5, 0
        li      t6, 0
-       csrw    sscratch, 0
+       csrw    CSR_SCRATCH, 0
 
 #ifdef CONFIG_FPU
        csrr    t0, CSR_MISA
--

2.17.1

#2 lore raw
In reply to Greentime Hu
Quoted 7 lines · Greentime Hu

This patch fixes that the sscratch register clearing in M-mode. It cleared sscratch register in M-mode, but it should clear mscratch register. That will cause kernel trap if the CPU core doesn't support S-mode when trying to access sscratch.

Fixes 9e80635619b5 ("riscv: clear the instruction cache and all registers when booting")

Thanks Greentime, queued for v5.5-rc.

- Paul