From nobody Sun Feb 8 13:16:51 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 D797B27466C; 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=RBNMU6JnbLVnms0xc2r780YCj9k0MvaY6kZpKOoLhn15i8gzzcf9YTLKjgRURF/PKG84oDB47a3mbuKy3T2H68jGHrfgALzuDeVj7nUPwYyTgkxLDuIKMeZFkRYY9Ituq7nfBH46rdvtzvSJitAwK3coKpXysTU7LoaE2wEwVkI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745908407; c=relaxed/simple; bh=dZlR/Zk0MhDk3rXLlvj0BXhNYH+9RMhkfGs2zeY7ih8=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=hkhjg5u8VIlifO95P9SQbMRMO1JnTbRkN4CJzuPWiwAzUKylSYRb36ewgX5Amc3FH50uXY4Qg9IzreYMubu1YmuHurjiXrwIryQrBeXNwQpci0tJCJPFrjj+NW1HbalZ0Kkx8U6ha5/M/COzSVNfYbDg+eNuNpAbVGfHumGgHEA= 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=PnZBTn+M; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=XSgd0ftF; 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="PnZBTn+M"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="XSgd0ftF" 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=XTcYRBiF/mm96zmn6pbfeoVNRDyRBsOfqiA5n/68Seg=; b=PnZBTn+MoNqV3mQhIcnLTc2Ck594F2OPp3W3O861g9A+MSUSOW075gJ7UaHMgUK2qbdVvq mbsWc2X5syzsX1Zlnu+2oSILRIZM/XHyCWzO4BfaZiVE9U0a4V8m40fkvODPQi1qS2zZsA c5KRSRKaO8fsFwc1+AnBHHo27A8dHxS/inNUwqGhMWZbeg/pUZcJi8fHS3nIfkh5PIqHIw Jwo5tquLx0gciF9YHtCXowvbMmgsp6M53Z/243yxSGGxoS3NJaBoyhvUhzXccK3MkiAmNa zensfPMH4SRNXytVkIl+ehUuy0U74iPCUKSzbAWOQj7dic9X2T1GVatcBcPFVA== 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=XTcYRBiF/mm96zmn6pbfeoVNRDyRBsOfqiA5n/68Seg=; b=XSgd0ftFyZOZbit6fKEnYij2gBNvTBXedUbNE22QME5ZOANUpV2sVSJKdTfBDErSwNaFhk 21BpatwJ8016yJBw== 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] riscv: entry: Split ret_from_fork() into user and kernel Cc: Charlie Jenkins , Thomas Gleixner , Alexandre Ghiti , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20250320-riscv_optimize_entry-v6-2-63e187e26041@rivosinc.com> References: <20250320-riscv_optimize_entry-v6-2-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: <174590840296.22196.3067062493279853527.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: 5b3d6103b343d59e19bd641e4c31df519f4d250d Gitweb: https://git.kernel.org/tip/5b3d6103b343d59e19bd641e4c31df519= f4d250d Author: Charlie Jenkins AuthorDate: Thu, 20 Mar 2025 10:29:22 -07:00 Committer: Thomas Gleixner CommitterDate: Tue, 29 Apr 2025 08:27:10 +02:00 riscv: entry: Split ret_from_fork() into user and kernel This function was unified into a single function in commit ab9164dae273 ("riscv: entry: Consolidate ret_from_kernel_thread into ret_from_fork"). However that imposed a performance degradation. Partially reverting this commit to have ret_from_fork() split again, results in a 1% increase on the number of times fork is able to be called per second. Signed-off-by: Charlie Jenkins Signed-off-by: Thomas Gleixner Acked-by: Alexandre Ghiti Link: https://lore.kernel.org/all/20250320-riscv_optimize_entry-v6-2-63e187= e26041@rivosinc.com --- arch/riscv/include/asm/asm-prototypes.h | 3 ++- arch/riscv/kernel/entry.S | 13 ++++++++++--- arch/riscv/kernel/process.c | 17 +++++++++++------ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/arch/riscv/include/asm/asm-prototypes.h b/arch/riscv/include/a= sm/asm-prototypes.h index 733ff60..bfc8ea5 100644 --- a/arch/riscv/include/asm/asm-prototypes.h +++ b/arch/riscv/include/asm/asm-prototypes.h @@ -52,7 +52,8 @@ DECLARE_DO_ERROR_INFO(do_trap_ecall_s); DECLARE_DO_ERROR_INFO(do_trap_ecall_m); DECLARE_DO_ERROR_INFO(do_trap_break); =20 -asmlinkage void ret_from_fork(void *fn_arg, int (*fn)(void *), struct pt_r= egs *regs); +asmlinkage void ret_from_fork_kernel(void *fn_arg, int (*fn)(void *), stru= ct pt_regs *regs); +asmlinkage void ret_from_fork_user(struct pt_regs *regs); asmlinkage void handle_bad_stack(struct pt_regs *regs); asmlinkage void do_page_fault(struct pt_regs *regs); asmlinkage void do_irq(struct pt_regs *regs); diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index b2dc5e7..0fb3380 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -319,14 +319,21 @@ SYM_CODE_END(handle_kernel_stack_overflow) ASM_NOKPROBE(handle_kernel_stack_overflow) #endif =20 -SYM_CODE_START(ret_from_fork_asm) +SYM_CODE_START(ret_from_fork_kernel_asm) call schedule_tail move a0, s1 /* fn_arg */ move a1, s0 /* fn */ move a2, sp /* pt_regs */ - call ret_from_fork + call ret_from_fork_kernel j ret_from_exception -SYM_CODE_END(ret_from_fork_asm) +SYM_CODE_END(ret_from_fork_kernel_asm) + +SYM_CODE_START(ret_from_fork_user_asm) + call schedule_tail + move a0, sp /* pt_regs */ + call ret_from_fork_user + j ret_from_exception +SYM_CODE_END(ret_from_fork_user_asm) =20 #ifdef CONFIG_IRQ_STACKS /* diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c index 7b0a0bf..485ec7a 100644 --- a/arch/riscv/kernel/process.c +++ b/arch/riscv/kernel/process.c @@ -38,7 +38,8 @@ unsigned long __stack_chk_guard __read_mostly; EXPORT_SYMBOL(__stack_chk_guard); #endif =20 -extern asmlinkage void ret_from_fork_asm(void); +extern asmlinkage void ret_from_fork_kernel_asm(void); +extern asmlinkage void ret_from_fork_user_asm(void); =20 void noinstr arch_cpu_idle(void) { @@ -208,14 +209,18 @@ int arch_dup_task_struct(struct task_struct *dst, str= uct task_struct *src) return 0; } =20 -asmlinkage void ret_from_fork(void *fn_arg, int (*fn)(void *), struct pt_r= egs *regs) +asmlinkage void ret_from_fork_kernel(void *fn_arg, int (*fn)(void *), stru= ct pt_regs *regs) { - if (unlikely(fn)) - fn(fn_arg); + fn(fn_arg); =20 syscall_exit_to_user_mode(regs); } =20 +asmlinkage void ret_from_fork_user(struct pt_regs *regs) +{ + syscall_exit_to_user_mode(regs); +} + int copy_thread(struct task_struct *p, const struct kernel_clone_args *arg= s) { unsigned long clone_flags =3D args->flags; @@ -238,6 +243,7 @@ int copy_thread(struct task_struct *p, const struct ker= nel_clone_args *args) =20 p->thread.s[0] =3D (unsigned long)args->fn; p->thread.s[1] =3D (unsigned long)args->fn_arg; + p->thread.ra =3D (unsigned long)ret_from_fork_kernel_asm; } else { *childregs =3D *(current_pt_regs()); /* Turn off status.VS */ @@ -247,12 +253,11 @@ int copy_thread(struct task_struct *p, const struct k= ernel_clone_args *args) if (clone_flags & CLONE_SETTLS) childregs->tp =3D tls; childregs->a0 =3D 0; /* Return value of fork() */ - p->thread.s[0] =3D 0; + p->thread.ra =3D (unsigned long)ret_from_fork_user_asm; } p->thread.riscv_v_flags =3D 0; if (has_vector() || has_xtheadvector()) riscv_v_thread_alloc(p); - p->thread.ra =3D (unsigned long)ret_from_fork_asm; p->thread.sp =3D (unsigned long)childregs; /* kernel sp */ return 0; }