From patchwork Sat Jan 7 11:38:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 13092116 X-Patchwork-Delegate: palmer@dabbelt.com 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 87645C54EBC for ; Sat, 7 Jan 2023 11:39:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/mpM33BEPjNaSPGQv6u6TL9JufqtCg0Jn/pEMkMD+hE=; b=m/kP+4fKdWW4t+ kWe7MpAcAAIB1XwM9d7hzv0tVmzgSl74xELn0zIEJU3GjdLRENUY+XGZGZ9EOfp8gzUs0No70lYN7 lZLCDe/BE5opE4UBU1QF87zeT6Mm3UeNr3T9tVGajkzv4Kfy1bK1QsBqAk077QoEroiS2w8dbhwcC 4pP0PFnzyexHCAh4KDpoVY12ZStrYSO3YfsdYp/mHRkDkdN/MhsbGwizq5b87mRdLVRqnalfYLG5i t/Pr07sTuUhkiyN71AfHFP2bU8Q4JieL3j7/bwWGYDbFwfCZ+TrezG8ajJNGACgROH0zxHCWn08HP S4P1tRfZkv7w5B9TnHFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pE7Y6-004W7d-Vq; Sat, 07 Jan 2023 11:39:43 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pE7Y3-004W3j-Lh for linux-riscv@lists.infradead.org; Sat, 07 Jan 2023 11:39:41 +0000 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 ams.source.kernel.org (Postfix) with ESMTPS id 4B7A4B819A4; Sat, 7 Jan 2023 11:39:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C675C4339B; Sat, 7 Jan 2023 11:39:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673091577; bh=NZL7k5T/gq/CBdcI/CQC/x9NElRVpSMRhseuithZiTk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cKjy1Sr4IbMxpzo5GWQMXhUQcTO5Z9cxamaLuhM1xjJ3ZzilNS+rfUfJ5SXIHhr4M 4GgtcEmBOkBpcZK9aev2zVMyNkOVDOT7BdJo6is+l+oPqQ8Oz06MksnkeHOV+LSLrI 2tqcLQkdCjvYu1VSG0qGOC8Cv5w/PFxjSUfYqZmB8nBVyvnBkIuKptLnyrN3AtHoGR 9cDG0tl5PbmhTYMgTi3Ed7vuXFAehheQoTztdxuyd+oSTGQpsEt160/0RyF9TmjBhX SnckD1qZU8dB1QiArljWRo8BLI0tZUiO2mS83TBp/j8UVMZzzDxli9ogcrWhKkZSso mYApYYITjM0Og== 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?b?QmrDtnJuIFTDtnBlbA==?= Subject: [PATCH -next V13 6/7] riscv: entry: Consolidate ret_from_kernel_thread into ret_from_fork Date: Sat, 7 Jan 2023 06:38:37 -0500 Message-Id: <20230107113838.3969149-7-guoren@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20230107113838.3969149-1-guoren@kernel.org> References: <20230107113838.3969149-1-guoren@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230107_033940_055929_626EF363 X-CRM114-Status: GOOD ( 12.06 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.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örn Töpel 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 bc322f92ba34..5ccef259498d 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) @@ -334,20 +333,15 @@ SYM_CODE_END(handle_kernel_stack_overflow) 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) /* * 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 extern asmlinkage void ret_from_fork(void); -extern asmlinkage void ret_from_kernel_thread(void); void arch_cpu_idle(void) { @@ -174,7 +173,6 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) /* Supervisor/Machine, irqs on: */ childregs->status = SR_PP | SR_PIE; - p->thread.ra = (unsigned long)ret_from_kernel_thread; p->thread.s[0] = (unsigned long)args->fn; p->thread.s[1] = (unsigned long)args->fn_arg; } else { @@ -184,8 +182,9 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) if (clone_flags & CLONE_SETTLS) childregs->tp = tls; childregs->a0 = 0; /* Return value of fork() */ - p->thread.ra = (unsigned long)ret_from_fork; + p->thread.s[0] = 0; } + p->thread.ra = (unsigned long)ret_from_fork; p->thread.sp = (unsigned long)childregs; /* kernel sp */ return 0; }