Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp1172628rwi; Thu, 3 Nov 2022 01:54:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM443TM2Y4RY+r1nyrvqPbgG3cEkfMMo8EV/08LxsNozktqzW1zX6z6hfkJ3c0Un56j3mBCF X-Received: by 2002:a05:6402:144a:b0:461:8e34:d07b with SMTP id d10-20020a056402144a00b004618e34d07bmr29451112edx.426.1667465683615; Thu, 03 Nov 2022 01:54:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667465683; cv=none; d=google.com; s=arc-20160816; b=Yeup1EanhdiiEmMn/uX881J+PQzVc/cCiFtYbL0BVIYZL7bVhFDyzYL6sGxEcFVThD JT4hEEsQCYUHo2SNJrjkMe0A1ki4QKhclka2xQM3wPx+Zwx2oEuzE2hpPDA9riWZoBIp YBrPIPSys+xWfj0dqSdsS9c6HTFYXAgiKN4vAf+jArIVTorn2DX9R8oKVbAs91pIqunh z1S0QE2x8xD5MKNx0TeLvlVJaDKMeMjuDuyl44DCya5CTmZtm9JyyHRfTFnpQE18BGvM klAabT+5eNOZ4Q/uR83APTdS/3N3yD0A1+ut1Ci41DUa/GPLpTq2oGXY8BPAyhEIzj/L FuMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pSWKi3x1+TNQY90nd+8LdD4A99nEK/LmIrqt5kCJDfY=; b=xLVaLH9b8AbSjqFuA1+vhIAc+079KyyqZu8R+NtZYaR7ycOc2YrTYJe4rh+TpvArR0 hXkGfZSDOBMkZ5lN1sXeC8npxS7JDpGJUywEouFlvqUSY4eoNlKjDKG7gb6613FE0O2s RFljSDxnoHJEk/XFvCavypZfJaDnkOjh9amTpuIQ5Wqm750hSODk1IBl1ootYcJ9YDx5 kVoLVVuKNLaVqiC0T1H6QSKEUG07s/4iij5pasv21pBviOqTBsXoFCXdN4PHCeY1DbD9 4JbdLetyip+2FWGhlxbPUR/KpSsVBoVh12bkBgJUObfpvjz4Z2Pyw72ZjCbNz5iDjJvV ojVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="V78/QTVT"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he8-20020a1709073d8800b007a7d37e4684si638735ejc.803.2022.11.03.01.54.18; Thu, 03 Nov 2022 01:54:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="V78/QTVT"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230214AbiKCHzA (ORCPT + 97 others); Thu, 3 Nov 2022 03:55:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229871AbiKCHxb (ORCPT ); Thu, 3 Nov 2022 03:53:31 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2436E0AC; Thu, 3 Nov 2022 00:53:08 -0700 (PDT) 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 8D792B82697; Thu, 3 Nov 2022 07:53:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8CD29C43142; Thu, 3 Nov 2022 07:52:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667461986; bh=6mT3EvXtlXRLieGroNt7lX/Uc/Cj0ALZoGomS8K8Gk0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V78/QTVTsB/9IOs1gnYjFDMP1uUhzfuBshCTyZNFpHP7GefsP9Y/+s8ZxegVRgS9H Q4elPrDERZP/B1orRR5ncmIFm/CVhFzFvV6hhmgXcaWSE996eIjcfsvQNAaHUL8GfE 1m9I7tauLWftwZOX211ZBKdHscRLDyASdVhQqKkJGcUX6YwS0JG5tIkxHsiohaZMAS c6Vy0eIzN1yYirikeiGJaS7ldS6GiJd6xo351gtewYWIe0M9ul5dbvh0N38Q8ARzKu AbkSbYbViqe0ZQrnrcuQ/fLeGatnJ7b8DCjWeyfblPKy/qrheu62XeQsbtNAAl/Ncy CER7YDiN44MZw== 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, palmer@dabbelt.com, paul.walmsley@sifive.com, mark.rutland@arm.com, zouyipeng@huawei.com, bigeasy@linutronix.de, David.Laight@aculab.com, chenzhongjin@huawei.com, greentime.hu@sifive.com, andy.chiu@sifive.com Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH -next V8 13/14] riscv: consolidate ret_from_kernel_thread into ret_from_fork Date: Thu, 3 Nov 2022 03:50:46 -0400 Message-Id: <20221103075047.1634923-14-guoren@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221103075047.1634923-1-guoren@kernel.org> References: <20221103075047.1634923-1-guoren@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 make entry.S more clean. Signed-off-by: Jisheng Zhang 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 b1babad5f829..d4c061f7fbfa 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -132,7 +132,6 @@ END(handle_exception) * caller list: * - handle_exception * - ret_from_fork - * - ret_from_kernel_thread */ ENTRY(ret_from_exception) REG_L s0, PT_STATUS(sp) @@ -326,20 +325,15 @@ END(handle_kernel_stack_overflow) ENTRY(ret_from_fork) call schedule_tail - move a0, sp /* pt_regs */ - la ra, ret_from_exception - tail syscall_exit_to_user_mode -ENDPROC(ret_from_fork) - -ENTRY(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 -ENDPROC(ret_from_kernel_thread) +ENDPROC(ret_from_fork) /* diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c index b0c63e8e867e..5108c76a14dd 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) { @@ -172,7 +171,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 { @@ -182,8 +180,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; } -- 2.36.1