linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] riscv: fix scratch register clearing in M-mode.
@ 2019-12-19  6:44 Greentime Hu
  2019-12-19  6:54 ` Anup Patel
  2019-12-20 11:07 ` Paul Walmsley
  0 siblings, 2 replies; 3+ messages in thread
From: Greentime Hu @ 2019-12-19  6:44 UTC (permalink / raw)
  To: green.hu, greentime, hch, paul.walmsley, palmer, linux-riscv,
	linux-kernel
  Cc: 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")
Signed-off-by: Greentime Hu <greentime.hu@sifive.com>
---
 arch/riscv/kernel/head.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
index 84a6f0a4b120..797802c73dee 100644
--- a/arch/riscv/kernel/head.S
+++ b/arch/riscv/kernel/head.S
@@ -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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] riscv: fix scratch register clearing in M-mode.
  2019-12-19  6:44 [PATCH] riscv: fix scratch register clearing in M-mode Greentime Hu
@ 2019-12-19  6:54 ` Anup Patel
  2019-12-20 11:07 ` Paul Walmsley
  1 sibling, 0 replies; 3+ messages in thread
From: Anup Patel @ 2019-12-19  6:54 UTC (permalink / raw)
  To: Greentime Hu
  Cc: Greentime Hu, greentime, Christoph Hellwig, Paul Walmsley,
	Palmer Dabbelt, linux-riscv, linux-kernel@vger.kernel.org List

On Thu, Dec 19, 2019 at 12:15 PM Greentime Hu <greentime.hu@sifive.com> wrote:
>
> 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")
> Signed-off-by: Greentime Hu <greentime.hu@sifive.com>

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

Looks good to me.

Reviewed-by: Anup Patel <anup@brainfault.org>

Regards,
Anup

> ---
>  arch/riscv/kernel/head.S | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
> index 84a6f0a4b120..797802c73dee 100644
> --- a/arch/riscv/kernel/head.S
> +++ b/arch/riscv/kernel/head.S
> @@ -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
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] riscv: fix scratch register clearing in M-mode.
  2019-12-19  6:44 [PATCH] riscv: fix scratch register clearing in M-mode Greentime Hu
  2019-12-19  6:54 ` Anup Patel
@ 2019-12-20 11:07 ` Paul Walmsley
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Walmsley @ 2019-12-20 11:07 UTC (permalink / raw)
  To: Greentime Hu; +Cc: green.hu, greentime, hch, palmer, linux-riscv, linux-kernel

On Thu, 19 Dec 2019, Greentime Hu wrote:

> 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")
> Signed-off-by: Greentime Hu <greentime.hu@sifive.com>

Thanks Greentime, queued for v5.5-rc.

- Paul

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-12-20 11:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-19  6:44 [PATCH] riscv: fix scratch register clearing in M-mode Greentime Hu
2019-12-19  6:54 ` Anup Patel
2019-12-20 11:07 ` Paul Walmsley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).