Skip to content

Commit 8d73648

Browse files
mathis-spalmer-dabbelt
authored andcommitted
riscv: add icache flush for nommu sigreturn trampoline
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 <[email protected]> Fixes: 6bd33e1 ("riscv: add nommu support") Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 4622f15 commit 8d73648

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

arch/riscv/kernel/signal.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <asm/signal32.h>
2020
#include <asm/switch_to.h>
2121
#include <asm/csr.h>
22+
#include <asm/cacheflush.h>
2223

2324
extern u32 __user_rt_sigreturn[2];
2425

@@ -181,6 +182,7 @@ static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
181182
{
182183
struct rt_sigframe __user *frame;
183184
long err = 0;
185+
unsigned long __maybe_unused addr;
184186

185187
frame = get_sigframe(ksig, regs, sizeof(*frame));
186188
if (!access_ok(frame, sizeof(*frame)))
@@ -209,7 +211,12 @@ static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
209211
if (copy_to_user(&frame->sigreturn_code, __user_rt_sigreturn,
210212
sizeof(frame->sigreturn_code)))
211213
return -EFAULT;
212-
regs->ra = (unsigned long)&frame->sigreturn_code;
214+
215+
addr = (unsigned long)&frame->sigreturn_code;
216+
/* Make sure the two instructions are pushed to icache. */
217+
flush_icache_range(addr, addr + sizeof(frame->sigreturn_code));
218+
219+
regs->ra = addr;
213220
#endif /* CONFIG_MMU */
214221

215222
/*

0 commit comments

Comments
 (0)