[tip: core/entry] riscv/syscall: Use syscall_enter_from_user_mode_randomize_stack()

tip-bot2 for Thomas Gleixner posted 1 patch 1 week, 6 days ago
arch/riscv/kernel/traps.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
[tip: core/entry] riscv/syscall: Use syscall_enter_from_user_mode_randomize_stack()
Posted by tip-bot2 for Thomas Gleixner 1 week, 6 days ago
The following commit has been merged into the core/entry branch of tip:

Commit-ID:     d023abfbc4dca9ad9c9928b5b5a38b1628ee1a5d
Gitweb:        https://git.kernel.org/tip/d023abfbc4dca9ad9c9928b5b5a38b1628ee1a5d
Author:        Thomas Gleixner <tglx@kernel.org>
AuthorDate:    Tue, 07 Jul 2026 21:06:19 +02:00
Committer:     Thomas Gleixner <tglx@kernel.org>
CommitterDate: Sun, 12 Jul 2026 12:38:01 +02:00

riscv/syscall: Use syscall_enter_from_user_mode_randomize_stack()

syscall_enter_from_user_mode_randomize_stack() replaces
syscall_enter_from_user_mode() and the subsequent invocation of
add_random_kstack_offset().

The advantage is that it applies the stack randomization right after
enter_from_user_mode() and thereby avoids the overhead of get/put_cpu_var()
as that code is invoked with interrupts disabled.

No functional change.

Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Reviewed-by: Radu Rendec <radu@rendec.net>
Reviewed-by: Jinjie Ruan <ruanjinjie@huawei.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
Link: https://patch.msgid.link/20260707190253.974626922@kernel.org
---
 arch/riscv/kernel/traps.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c
index 8c62c77..bb18011 100644
--- a/arch/riscv/kernel/traps.c
+++ b/arch/riscv/kernel/traps.c
@@ -7,7 +7,6 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/irqflags.h>
-#include <linux/randomize_kstack.h>
 #include <linux/sched.h>
 #include <linux/sched/debug.h>
 #include <linux/sched/signal.h>
@@ -333,9 +332,7 @@ void do_trap_ecall_u(struct pt_regs *regs)
 
 		riscv_v_vstate_discard(regs);
 
-		syscall = syscall_enter_from_user_mode(regs, syscall);
-
-		add_random_kstack_offset();
+		syscall = syscall_enter_from_user_mode_randomize_stack(regs, syscall);
 
 		if (syscall >= 0 && syscall < NR_syscalls) {
 			syscall = array_index_nospec(syscall, NR_syscalls);