Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp838035rwb; Wed, 28 Sep 2022 09:41:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7EpgHhc69WffY1buqEo4dOf6ziDMVN0IPLQPodS0tuGx0v+drx8K9XzS3jS2M9gs5XaAEP X-Received: by 2002:a17:902:ea0f:b0:178:23f7:5a30 with SMTP id s15-20020a170902ea0f00b0017823f75a30mr663919plg.150.1664383263763; Wed, 28 Sep 2022 09:41:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664383263; cv=none; d=google.com; s=arc-20160816; b=sbke1KeRXCamQPhi27n6qKkdMT29ok1snbDsQLgskgbFYNHMX9kUQ4v5riLUQJlV31 DMbvuCoPOOKl7WCXAp+2EBVValKIpjxyptbweEgtbdeIZV0ElBKZiv0TZQP+PxbMqFrA TgqEeom3kC3ms64UlXrrSDQ8/PH2mAwgh/ltlVqupwfDIhR6Q4ZZVKyH13GQPL7N5mZa 4jVj4k7ORCRwlWfrLlUZvLaLrKNJqCgv2opWluZvFeSjFF/njqlk8UDX7FMrrRTnH+7h x3Ra/LJ2lHmz6JAb+NjDCdmeItZvqibEVxyy0Umz2fdRh9kKjVLraXeqfjCqu88xUZ5J +gnQ== 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=17YXryO1Gzxb+EpqGCL+UYdn3YhTLyryHH5MbSJQfLc=; b=wKj0bfjv0xwK6RNEaW6eDZFmZ+HP+KeLZuMFVXMyLbCmPS3UVdbefNleJaV9JMP37L vTz9tS4YOxE2V4yKWMVY54zrakeFKJMOdGGsHKGVwJlbNeiNpPaC7zSPAnKHo5QSxeiA jxpimGyEiDPMFZXyvQrDyAI2eew4sFZ8CIEMb1u1gYAy6f7eEs/Phf8WftbUr+UgFDNh POAMJ/QTpeUV+gGGlyy2kjsO3XBw3tiuNqdPvHTE0PbqNrLgLpGjFWt0zC9gWtEJqOJf n59UVuUFc1BQw7IA3d7JddSQmPOv6++pP27jcTUSdyZbRVdBGNKHTfDo3EB8GBr6roJI tqDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L0yMrfgp; 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 h6-20020a63c006000000b004393f267fe4si5325155pgg.127.2022.09.28.09.40.46; Wed, 28 Sep 2022 09:41:03 -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=L0yMrfgp; 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 S234533AbiI1QaM (ORCPT + 99 others); Wed, 28 Sep 2022 12:30:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229940AbiI1Q3o (ORCPT ); Wed, 28 Sep 2022 12:29:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73F6462F7 for ; Wed, 28 Sep 2022 09:29:42 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 5D90261F30 for ; Wed, 28 Sep 2022 16:29:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4BDEC43141; Wed, 28 Sep 2022 16:29:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664382580; bh=ddcSdAqJtV7YjhFUF+/+mxLRCnz8byHozG9Vd7pQWN4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L0yMrfgpP/2Wki358yrQPk1PxJHQLaBxbk+n47BfB27WnVmsqgC3/CaeoNc+bLY+1 ZdfkPb6x80BIld7W2UThJT6FSnlg/loBoZt7bXM68ftsUzhGNHJWdnCOdXE1R5F9Ao zmhIP1O78RhuJ2UxlUV3J/viOaeh/sOkVyZ/XEQwt/4tqO9F0oCLttRrvGiAYpk/Ji iLRllCWwUZX/hmm7k2ig29XvO9RPwSv2OJ4MzpddQcI77zkSZbqlrxbQud/sNfZr/h 0v1WYIBbLG0+CJ3TKV2bS6wqbtkHb8i3nJXYhwxCUG2levbRMH0TIBCO+sr9/ObtYS go3GpoUmDwFnQ== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Nathan Chancellor , Nick Desaulniers , Guo Ren Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH v2 2/4] riscv: consolidate ret_from_kernel_thread into ret_from_fork Date: Thu, 29 Sep 2022 00:20:05 +0800 Message-Id: <20220928162007.3791-3-jszhang@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220928162007.3791-1-jszhang@kernel.org> References: <20220928162007.3791-1-jszhang@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 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 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 acchieved by testing fn is NULL or not, I.E s0 is 0 or not. Signed-off-by: Jisheng Zhang --- arch/riscv/kernel/entry.S | 11 +++-------- arch/riscv/kernel/process.c | 5 ++--- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index 2207cf44a3bc..a3e1ed2fa2ac 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -323,20 +323,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) #ifdef CONFIG_IRQ_STACKS ENTRY(call_on_stack) diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c index ceb9ebab6558..67e7cd123ceb 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.34.1