From nobody Mon Feb 9 01:31:17 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76B8F2741BE; Tue, 29 Apr 2025 06:33:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745908407; cv=none; b=k+OLbHTuOmPqdU2QBnoKF4WfxdiBsehOEk2k5cLA9LtE0u+C2xQ5uWLL1HeQdJCm7zF/Qe+Z5TX9A4RaIEgEd5oxBmT1t93rWa9Jvu2Pp2qi1GN4/wkjaL80B0ARlmNpBuJARkh8Gl18Uos3a1CTpI9MDlg9PcZ7Ml9LZOH3TEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745908407; c=relaxed/simple; bh=z4PYk7C8+w8KC2NErTyrJmuHlRbgkzA2WapyRxE28pc=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=fxk853XlvLLZlmYhhsMgcXpdIpVbjWGSoMT8LqCYfKY9BBqR4ZXDuu5GKoP+HzpZx5xjkh06pEOQCZwREa9zQXZKo94l6s6zGn5U22smjLv5G9gmM1KUErDLfBjmRI04syVUzRF+ATs28nyCqa13g0rLcLvRi9b3UYyEZCACWsk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=CZ4EK8Ju; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=u/6Rn236; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="CZ4EK8Ju"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="u/6Rn236" Date: Tue, 29 Apr 2025 06:33:22 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1745908403; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ar8oqM8FgMCZgKao2G6rxA+wkWw1PynmVBOd/Gxff2M=; b=CZ4EK8Ju9h/kkvHzWDIRwwnM+JiF8AtJlQ5ZHBmA92JzxtNXFYA2p37boXpcHvLcPgcsgZ k2rhQBZzh4Qvxh8kARNkHxz58UlnncDYwzTgKGv5525qc8xRjdQpMcGRq1cZ96MBbJfbGB r1HGo+Rs2SSNyOkmYZi/paqVw/tquqjry3R8jMGzZRHRUVOBWvwxnDDl4eMDeC1AwT01Jz ZZQrUe4WBAsrJY5sDCUvl2Ir9w2x4QdNwMzBni7nr2LVrKsLBMyJIbFsoj9euwKOpDEQs5 8TSIBTbTefl3h6CLY/KyubqkjTWzfP59h7mZYXD5VnuOEx4QEZ8mztkH8PjOgQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1745908403; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ar8oqM8FgMCZgKao2G6rxA+wkWw1PynmVBOd/Gxff2M=; b=u/6Rn236Dsf3mxaCA4M2NSj6GzuZL7QephoyA3lFo5r2lqg1CqfP7trU/p8/VKSsc2nFXt PBf7DEVc7ySe61DA== From: "tip-bot2 for Charlie Jenkins" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: core/entry] LoongArch: entry: Migrate ret_from_fork() to C Cc: Charlie Jenkins , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20250320-riscv_optimize_entry-v6-3-63e187e26041@rivosinc.com> References: <20250320-riscv_optimize_entry-v6-3-63e187e26041@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <174590840216.22196.13641388731780911839.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the core/entry branch of tip: Commit-ID: 7ace1602abf21da505993d77ccbae1df2496b324 Gitweb: https://git.kernel.org/tip/7ace1602abf21da505993d77ccbae1df2= 496b324 Author: Charlie Jenkins AuthorDate: Thu, 20 Mar 2025 10:29:23 -07:00 Committer: Thomas Gleixner CommitterDate: Tue, 29 Apr 2025 08:27:10 +02:00 LoongArch: entry: Migrate ret_from_fork() to C LoongArch is the only architecture that calls syscall_exit_to_user_mode() from assembly. Move the call into C so that this function can be inlined across all architectures. Signed-off-by: Charlie Jenkins Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/all/20250320-riscv_optimize_entry-v6-3-63e187= e26041@rivosinc.com --- arch/loongarch/include/asm/asm-prototypes.h | 8 +++++- arch/loongarch/kernel/entry.S | 22 +++++-------- arch/loongarch/kernel/process.c | 33 ++++++++++++++++---- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/arch/loongarch/include/asm/asm-prototypes.h b/arch/loongarch/i= nclude/asm/asm-prototypes.h index 51f224b..704066b 100644 --- a/arch/loongarch/include/asm/asm-prototypes.h +++ b/arch/loongarch/include/asm/asm-prototypes.h @@ -12,3 +12,11 @@ __int128_t __ashlti3(__int128_t a, int b); __int128_t __ashrti3(__int128_t a, int b); __int128_t __lshrti3(__int128_t a, int b); #endif + +asmlinkage void noinstr __no_stack_protector ret_from_fork(struct task_str= uct *prev, + struct pt_regs *regs); + +asmlinkage void noinstr __no_stack_protector ret_from_kernel_thread(struct= task_struct *prev, + struct pt_regs *regs, + int (*fn)(void *), + void *fn_arg); diff --git a/arch/loongarch/kernel/entry.S b/arch/loongarch/kernel/entry.S index 48e7e34..2abc29e 100644 --- a/arch/loongarch/kernel/entry.S +++ b/arch/loongarch/kernel/entry.S @@ -77,24 +77,22 @@ SYM_CODE_START(handle_syscall) SYM_CODE_END(handle_syscall) _ASM_NOKPROBE(handle_syscall) =20 -SYM_CODE_START(ret_from_fork) +SYM_CODE_START(ret_from_fork_asm) UNWIND_HINT_REGS - bl schedule_tail # a0 =3D struct task_struct *prev - move a0, sp - bl syscall_exit_to_user_mode + move a1, sp + bl ret_from_fork RESTORE_STATIC RESTORE_SOME RESTORE_SP_AND_RET -SYM_CODE_END(ret_from_fork) +SYM_CODE_END(ret_from_fork_asm) =20 -SYM_CODE_START(ret_from_kernel_thread) +SYM_CODE_START(ret_from_kernel_thread_asm) UNWIND_HINT_REGS - bl schedule_tail # a0 =3D struct task_struct *prev - move a0, s1 - jirl ra, s0, 0 - move a0, sp - bl syscall_exit_to_user_mode + move a1, sp + move a2, s0 + move a3, s1 + bl ret_from_kernel_thread RESTORE_STATIC RESTORE_SOME RESTORE_SP_AND_RET -SYM_CODE_END(ret_from_kernel_thread) +SYM_CODE_END(ret_from_kernel_thread_asm) diff --git a/arch/loongarch/kernel/process.c b/arch/loongarch/kernel/proces= s.c index 6e58f65..98bc60d 100644 --- a/arch/loongarch/kernel/process.c +++ b/arch/loongarch/kernel/process.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -33,6 +34,7 @@ #include #include =20 +#include #include #include #include @@ -47,6 +49,7 @@ #include #include #include +#include #include #include =20 @@ -63,8 +66,9 @@ EXPORT_SYMBOL(__stack_chk_guard); unsigned long boot_option_idle_override =3D IDLE_NO_OVERRIDE; EXPORT_SYMBOL(boot_option_idle_override); =20 -asmlinkage void ret_from_fork(void); -asmlinkage void ret_from_kernel_thread(void); +asmlinkage void restore_and_ret(void); +asmlinkage void ret_from_fork_asm(void); +asmlinkage void ret_from_kernel_thread_asm(void); =20 void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp) { @@ -138,6 +142,23 @@ int arch_dup_task_struct(struct task_struct *dst, stru= ct task_struct *src) return 0; } =20 +asmlinkage void noinstr __no_stack_protector ret_from_fork(struct task_str= uct *prev, + struct pt_regs *regs) +{ + schedule_tail(prev); + syscall_exit_to_user_mode(regs); +} + +asmlinkage void noinstr __no_stack_protector ret_from_kernel_thread(struct= task_struct *prev, + struct pt_regs *regs, + int (*fn)(void *), + void *fn_arg) +{ + schedule_tail(prev); + fn(fn_arg); + syscall_exit_to_user_mode(regs); +} + /* * Copy architecture-specific thread state */ @@ -165,8 +186,8 @@ int copy_thread(struct task_struct *p, const struct ker= nel_clone_args *args) p->thread.reg03 =3D childksp; p->thread.reg23 =3D (unsigned long)args->fn; p->thread.reg24 =3D (unsigned long)args->fn_arg; - p->thread.reg01 =3D (unsigned long)ret_from_kernel_thread; - p->thread.sched_ra =3D (unsigned long)ret_from_kernel_thread; + p->thread.reg01 =3D (unsigned long)ret_from_kernel_thread_asm; + p->thread.sched_ra =3D (unsigned long)ret_from_kernel_thread_asm; memset(childregs, 0, sizeof(struct pt_regs)); childregs->csr_euen =3D p->thread.csr_euen; childregs->csr_crmd =3D p->thread.csr_crmd; @@ -182,8 +203,8 @@ int copy_thread(struct task_struct *p, const struct ker= nel_clone_args *args) childregs->regs[3] =3D usp; =20 p->thread.reg03 =3D (unsigned long) childregs; - p->thread.reg01 =3D (unsigned long) ret_from_fork; - p->thread.sched_ra =3D (unsigned long) ret_from_fork; + p->thread.reg01 =3D (unsigned long) ret_from_fork_asm; + p->thread.sched_ra =3D (unsigned long) ret_from_fork_asm; =20 /* * New tasks lose permission to use the fpu. This accelerates context