linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] riscv: add icache flush for nommu sigreturn trampoline
@ 2023-04-06  0:11 Mathis Salmen
  2023-04-06  5:33 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Mathis Salmen @ 2023-04-06  0:11 UTC (permalink / raw)
  To: linux-riscv, palmer; +Cc: Mathis Salmen

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>
---
 arch/riscv/kernel/signal.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c
index bfb2afa41..548703230 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];
 
@@ -209,6 +210,10 @@ 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;
+	/* Make sure the two instructions are pushed to icache. */
+	flush_icache_range((uintptr_t)&frame->sigreturn_code,
+			(uintptr_t)&frame->sigreturn_code + sizeof(frame->sigreturn_code));
+
 	regs->ra = (unsigned long)&frame->sigreturn_code;
 #endif /* CONFIG_MMU */
 
-- 
2.40.0


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

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

* Re: [PATCH] riscv: add icache flush for nommu sigreturn trampoline
  2023-04-06  0:11 [PATCH] riscv: add icache flush for nommu sigreturn trampoline Mathis Salmen
@ 2023-04-06  5:33 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2023-04-06  5:33 UTC (permalink / raw)
  To: Mathis Salmen; +Cc: linux-riscv, palmer

On Thu, Apr 06, 2023 at 02:11:04AM +0200, Mathis Salmen wrote:
> +	/* Make sure the two instructions are pushed to icache. */
> +	flush_icache_range((uintptr_t)&frame->sigreturn_code,
> +			(uintptr_t)&frame->sigreturn_code + sizeof(frame->sigreturn_code));
>  	regs->ra = (unsigned long)&frame->sigreturn_code;

Please add a local variable for the in-casted value of
&frame->sigreturn_code to actually make this readable.

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

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

end of thread, other threads:[~2023-04-06  5:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-06  0:11 [PATCH] riscv: add icache flush for nommu sigreturn trampoline Mathis Salmen
2023-04-06  5:33 ` Christoph Hellwig

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).