From nobody Tue Sep 16 15:42:34 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4532C3DA7D for ; Tue, 3 Jan 2023 03:37:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236682AbjACDhS (ORCPT ); Mon, 2 Jan 2023 22:37:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236749AbjACDgv (ORCPT ); Mon, 2 Jan 2023 22:36:51 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECDC8CE3E; Mon, 2 Jan 2023 19:36:43 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 818A861197; Tue, 3 Jan 2023 03:36:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60F08C433D2; Tue, 3 Jan 2023 03:36:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672717002; bh=hDdvI2crfVWHl4tVcTo3E7fh7kwInjAKC0UJD8GdyBI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ihDf9C9oupoUBXow8RSjgrDh85W/VLBo2TScQeBIv2/SY4h7C394cs3H1/Rph9kJs +MBEv3boyQy4ybo1BQOcUYj0osyxOqFtsK7vcVXCajbvpKfZp0zlPixsSjuPC3arWJ 6763bb3Xwq81ptdOx6PEagHwa6camH0GcVrgAHf87wK/x3ZjTRBgu8KYwTmzzhPtPj 2wiy7NJ6CBquATxFXG8PM1SH9ElvNl0yv6iFxjmyM2G7Zd/ZOo8cHKO74zuI7X92r3 9OiwR83tZJni76qYnz4iLT8520gIpOSgdKeBmrdBNrDyP+RN1clW1yUTPuzlc3lv5E aJKLMPpH1ZR3g== From: guoren@kernel.org To: arnd@arndb.de, guoren@kernel.org, palmer@rivosinc.com, tglx@linutronix.de, peterz@infradead.org, luto@kernel.org, conor.dooley@microchip.com, heiko@sntech.de, jszhang@kernel.org, lazyparser@gmail.com, falcon@tinylab.org, chenhuacai@kernel.org, apatel@ventanamicro.com, atishp@atishpatra.org, mark.rutland@arm.com, ben@decadent.org.uk, bjorn@kernel.org Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= Subject: [PATCH -next V12 6/7] riscv: entry: Consolidate ret_from_kernel_thread into ret_from_fork Date: Mon, 2 Jan 2023 22:35:30 -0500 Message-Id: <20230103033531.2011112-7-guoren@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20230103033531.2011112-1-guoren@kernel.org> References: <20230103033531.2011112-1-guoren@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jisheng Zhang The ret_from_kernel_thread() behaves similarly with ret_from_fork(), the only difference is whether call the fn(arg) or not, this can be achieved by testing fn is NULL or not, I.E s0 is 0 or not. Many architectures have done the same thing, it makes entry.S more clean. Signed-off-by: Jisheng Zhang Reviewed-by: Bj=C3=B6rn T=C3=B6pel Reviewed-by: Guo Ren Tested-by: Guo Ren Signed-off-by: Guo Ren --- arch/riscv/kernel/entry.S | 12 +++--------- arch/riscv/kernel/process.c | 5 ++--- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index 997886fb37a2..1a36e313adc4 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -132,7 +132,6 @@ SYM_CODE_END(handle_exception) * caller list: * - handle_exception * - ret_from_fork - * - ret_from_kernel_thread */ SYM_CODE_START_NOALIGN(ret_from_exception) REG_L s0, PT_STATUS(sp) @@ -336,20 +335,15 @@ SYM_CODE_END(handle_kernel_stack_overflow) =20 SYM_CODE_START(ret_from_fork) call schedule_tail - move a0, sp /* pt_regs */ - la ra, ret_from_exception - tail syscall_exit_to_user_mode -SYM_CODE_END(ret_from_fork) - -SYM_CODE_START(ret_from_kernel_thread) - call schedule_tail + beqz s0, 1f /* not from kernel thread */ /* Call fn(arg) */ move a0, s1 jalr s0 +1: move a0, sp /* pt_regs */ la ra, ret_from_exception tail syscall_exit_to_user_mode -SYM_CODE_END(ret_from_kernel_thread) +SYM_CODE_END(ret_from_fork) =20 /* * Integer register context switch diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c index 8955f2432c2d..46806d5d10fa 100644 --- a/arch/riscv/kernel/process.c +++ b/arch/riscv/kernel/process.c @@ -34,7 +34,6 @@ EXPORT_SYMBOL(__stack_chk_guard); #endif =20 extern asmlinkage void ret_from_fork(void); -extern asmlinkage void ret_from_kernel_thread(void); =20 void arch_cpu_idle(void) { @@ -174,7 +173,6 @@ int copy_thread(struct task_struct *p, const struct ker= nel_clone_args *args) /* Supervisor/Machine, irqs on: */ childregs->status =3D SR_PP | SR_PIE; =20 - p->thread.ra =3D (unsigned long)ret_from_kernel_thread; p->thread.s[0] =3D (unsigned long)args->fn; p->thread.s[1] =3D (unsigned long)args->fn_arg; } else { @@ -184,8 +182,9 @@ int copy_thread(struct task_struct *p, const struct ker= nel_clone_args *args) if (clone_flags & CLONE_SETTLS) childregs->tp =3D tls; childregs->a0 =3D 0; /* Return value of fork() */ - p->thread.ra =3D (unsigned long)ret_from_fork; + p->thread.s[0] =3D 0; } + p->thread.ra =3D (unsigned long)ret_from_fork; p->thread.sp =3D (unsigned long)childregs; /* kernel sp */ return 0; } --=20 2.36.1