diff mbox series

[v2] riscv: add icache flush for nommu sigreturn trampoline

Message ID 20230406101130.82304-1-mathis.salmen@matsal.de (mailing list archive)
State Accepted
Commit 8d736482749f6d350892ef83a7a11d43cd49981e
Headers show
Series [v2] riscv: add icache flush for nommu sigreturn trampoline | expand

Checks

Context Check Description
conchuod/cover_letter success Single patches do not need cover letters
conchuod/tree_selection success Guessed tree name to be for-next at HEAD d34a6b715a23
conchuod/fixes_present success Fixes tag not required for -next series
conchuod/maintainers_pattern success MAINTAINERS pattern errors before the patch: 1 and now 1
conchuod/verify_signedoff success Signed-off-by tag matches author and committer
conchuod/kdoc success Errors and warnings before: 0 this patch: 0
conchuod/build_rv64_clang_allmodconfig success Errors and warnings before: 18 this patch: 18
conchuod/module_param success Was 0 now: 0
conchuod/build_rv64_gcc_allmodconfig success Errors and warnings before: 18 this patch: 18
conchuod/build_rv32_defconfig success Build OK
conchuod/dtb_warn_rv64 success Errors and warnings before: 3 this patch: 3
conchuod/header_inline success No static functions without inline keyword in header files
conchuod/checkpatch warning CHECK: Consider using #include <linux/cacheflush.h> instead of <asm/cacheflush.h>
conchuod/source_inline success Was 0 now: 0
conchuod/build_rv64_nommu_k210_defconfig success Build OK
conchuod/verify_fixes success No Fixes tag
conchuod/build_rv64_nommu_virt_defconfig success Build OK

Commit Message

Mathis Salmen April 6, 2023, 10:11 a.m. UTC
In a NOMMU kernel, sigreturn trampolines are generated on the user
stack by setup_rt_frame. Currently, these trampolines are not instruction
fenced, thus their visibility to ifetch is not guaranteed.

This patch adds a flush_icache_range in setup_rt_frame to fix this
problem.

Signed-off-by: Mathis Salmen <mathis.salmen@matsal.de>
---
V1 -> V2: Added local variable for readability.

 arch/riscv/kernel/signal.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Conor Dooley April 8, 2023, 7:51 p.m. UTC | #1
Hey Mathis,

On Thu, Apr 06, 2023 at 12:11:31PM +0200, Mathis Salmen wrote:
> In a NOMMU kernel, sigreturn trampolines are generated on the user
> stack by setup_rt_frame. Currently, these trampolines are not instruction
> fenced, thus their visibility to ifetch is not guaranteed.
> 
> This patch adds a flush_icache_range in setup_rt_frame to fix this
> problem.
> 

I assume that this is then
Fixes: 6bd33e1ece52 ("riscv: add nommu support")
yeah?

Cheers,
Conor.

> Signed-off-by: Mathis Salmen <mathis.salmen@matsal.de>
> ---
> V1 -> V2: Added local variable for readability.
> 
>  arch/riscv/kernel/signal.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c
> index bfb2afa41..dee66c929 100644
> --- a/arch/riscv/kernel/signal.c
> +++ b/arch/riscv/kernel/signal.c
> @@ -19,6 +19,7 @@
>  #include <asm/signal32.h>
>  #include <asm/switch_to.h>
>  #include <asm/csr.h>
> +#include <asm/cacheflush.h>
>  
>  extern u32 __user_rt_sigreturn[2];
>  
> @@ -181,6 +182,7 @@ static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
>  {
>  	struct rt_sigframe __user *frame;
>  	long err = 0;
> +	unsigned long __maybe_unused addr;
>  
>  	frame = get_sigframe(ksig, regs, sizeof(*frame));
>  	if (!access_ok(frame, sizeof(*frame)))
> @@ -209,7 +211,12 @@ static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
>  	if (copy_to_user(&frame->sigreturn_code, __user_rt_sigreturn,
>  			 sizeof(frame->sigreturn_code)))
>  		return -EFAULT;
> -	regs->ra = (unsigned long)&frame->sigreturn_code;
> +
> +	addr = (unsigned long)&frame->sigreturn_code;
> +	/* Make sure the two instructions are pushed to icache. */
> +	flush_icache_range(addr, addr + sizeof(frame->sigreturn_code));
> +
> +	regs->ra = addr;
>  #endif /* CONFIG_MMU */
>  
>  	/*
> -- 
> 2.40.0
> 
> 
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv
Palmer Dabbelt April 11, 2023, 7:52 p.m. UTC | #2
On Thu, 06 Apr 2023 12:11:31 +0200, Mathis Salmen wrote:
> In a NOMMU kernel, sigreturn trampolines are generated on the user
> stack by setup_rt_frame. Currently, these trampolines are not instruction
> fenced, thus their visibility to ifetch is not guaranteed.
> 
> This patch adds a flush_icache_range in setup_rt_frame to fix this
> problem.
> 
> [...]

Applied, thanks!

[1/1] riscv: add icache flush for nommu sigreturn trampoline
      https://git.kernel.org/palmer/c/8d736482749f

Best regards,
patchwork-bot+linux-riscv@kernel.org April 11, 2023, 8 p.m. UTC | #3
Hello:

This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <palmer@rivosinc.com>:

On Thu,  6 Apr 2023 12:11:31 +0200 you wrote:
> In a NOMMU kernel, sigreturn trampolines are generated on the user
> stack by setup_rt_frame. Currently, these trampolines are not instruction
> fenced, thus their visibility to ifetch is not guaranteed.
> 
> This patch adds a flush_icache_range in setup_rt_frame to fix this
> problem.
> 
> [...]

Here is the summary with links:
  - [v2] riscv: add icache flush for nommu sigreturn trampoline
    https://git.kernel.org/riscv/c/8d736482749f

You are awesome, thank you!
diff mbox series

Patch

diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c
index bfb2afa41..dee66c929 100644
--- a/arch/riscv/kernel/signal.c
+++ b/arch/riscv/kernel/signal.c
@@ -19,6 +19,7 @@ 
 #include <asm/signal32.h>
 #include <asm/switch_to.h>
 #include <asm/csr.h>
+#include <asm/cacheflush.h>
 
 extern u32 __user_rt_sigreturn[2];
 
@@ -181,6 +182,7 @@  static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
 {
 	struct rt_sigframe __user *frame;
 	long err = 0;
+	unsigned long __maybe_unused addr;
 
 	frame = get_sigframe(ksig, regs, sizeof(*frame));
 	if (!access_ok(frame, sizeof(*frame)))
@@ -209,7 +211,12 @@  static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
 	if (copy_to_user(&frame->sigreturn_code, __user_rt_sigreturn,
 			 sizeof(frame->sigreturn_code)))
 		return -EFAULT;
-	regs->ra = (unsigned long)&frame->sigreturn_code;
+
+	addr = (unsigned long)&frame->sigreturn_code;
+	/* Make sure the two instructions are pushed to icache. */
+	flush_icache_range(addr, addr + sizeof(frame->sigreturn_code));
+
+	regs->ra = addr;
 #endif /* CONFIG_MMU */
 
 	/*