From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6D23156991 for ; Fri, 24 Jan 2025 07:56:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737705381; cv=none; b=M3fLIhy/BWUPkuFgC1GHvpWp4p/OGmIkzE0CmVHEvYUrrvCKKJ8vPeMtaqpjcoklF3cmNEKHiygTpY4eh6S+jAJx0hopCyAm3cSuvEpSx5W62ZHFg59NALhKKNXNOShjW+RAyEUmCqlOlsoFSQFRiNXsOYJ0ULIHDriSmic19ZM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737705381; c=relaxed/simple; bh=HrH8G8PQV5+gKJKRebFsRuzL+IqXKVPmgz80aOEfsP0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IA3DhMg/LEUYzhVfpQ4L8Tble8ttDWDxJLUe0xvTse5pLQwwiC08tD4ZNh+sULSvHTAKz51jG3/XLFA1nNI5oZ6UTCFpMZZdMdZ3gIJodJ9w/M9vo4uRtjUeizmPyt2naG6lULFDFjxJ/ahaaQ7wECtJiDS+15ldf8oYut58w3I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=Da4GxTWc; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="Da4GxTWc" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-2ee709715d9so2706468a91.3 for ; Thu, 23 Jan 2025 23:56:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1737705379; x=1738310179; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Puavfv6Mwo40wvE/QGDVA8qgrBgZXijyP93Qz2d9GhQ=; b=Da4GxTWciquXHdOFVwqIe+zvADojkf1snCmgaYQV2LZNDJpUXo371GKgWXdHuVRyFQ TtpGTFNcEndB+DcyEeMn17CvmaqZf/w1vJZ0aDY/8J60hFYwGZM1hC/0XURhWdmUlGQ0 6m/4p5aN0qv1OEHHMW6N0Vp4pnhdqWH2l0SEI/i4cz4WUFg51MqusgFU2UoXDC4j3RjS 7kbXQnVJDMB0Q2EyjephvwhSQ6Eq2tWXTJlZjPlWA2gvEFfKp4fZE0XzcMIas4YmLXH7 klznpu1A+g68l5d40XIcUfSfQRwJYzfuuQyxC3kS5DoeMV85ECrhkpL+5/8Siwkx/1os dkNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737705379; x=1738310179; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Puavfv6Mwo40wvE/QGDVA8qgrBgZXijyP93Qz2d9GhQ=; b=CNjSLN8T16HMQgrs8FtRymNB2eggdAMNE6RlCGaGSd12eLo31j+lTbcfsxqVr9vRJw jA6QpkD9DZrkS8kHJ7bv1X9QhQD1zW+s0paaTmCSz7dYIGQg28Ja/lONYH7RijxP55eA ZPjoOCzrhUTilJKEIUDNgvCEWnCXhbv7QZSn+jjNNe2ZoOQ/zEIdqd6FpJRdNAzchHPY yZB/QqTh+8Tur+qfCdL97oGCJ0fV+4IybkLQq5JhfnncYZ6uqdgFadFiBFcZL1NZSNcK VeXX73Xb24VT2fE2hqiQE3grqQBUDubmoFiWqOaffxOi+MS8svNnrX2BWyZHMpvCEvD7 RGyA== X-Forwarded-Encrypted: i=1; AJvYcCXwREPbrZltYTUxPJP0OfScOLlW6rel2UW/BbEjPR2z8bEFVzl4lQMlFVorFvjaxQURQDyKfdb9pjKKXY0=@vger.kernel.org X-Gm-Message-State: AOJu0YxUHKsd6cQTRbp+Nc6ewTZV4UQvLNVtJlNlzfK3k2bEa2UlXoDi 2R+LtlZ6yWKhSDwOlRW8ilL1Xi4O9+MVFedkDhC9ZCo3h0w1dR00GiBl1vewFhk= X-Gm-Gg: ASbGncsyTx9U04Q23XDEtye5/SweMzQO5lbxw/UlJsJcca+VizEm8gIH0rOyHMFMviq SICt2frxJEVDHCEIjz8tcxLb6D6t5QHwQOwCnlkNOGrLqKVXtrwABYtacfAT4twY1y7etX0db2D cKqDs7DaGBosvvYmWORjVBo+E+YTwelAEm8VtebeGwWoxlPrs5a4g8czFsDN42wHyepL8jpw5y2 2D0VK7zNyUVrftZRdlYLrwqehUDH1n1sB/zulzgrltovyJ9kbY7UD9Ud+qKQFnw9f/4IFi7L7YI X-Google-Smtp-Source: AGHT+IGtfy5k0PlhMUnKgepez8xy7+vWZVhDSj6+NmuJiXytfOUnL0FH4Jlly+P6YjqyMghE081Vyg== X-Received: by 2002:aa7:9a83:0:b0:725:e325:ab3a with SMTP id d2e1a72fcca58-72daf97a541mr41394847b3a.14.1737705378949; Thu, 23 Jan 2025 23:56:18 -0800 (PST) Received: from ghost ([2601:647:6700:64d0:db66:c77e:13aa:17a4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72f8a7614e9sm1238956b3a.109.2025.01.23.23.56.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 23:56:18 -0800 (PST) Date: Thu, 23 Jan 2025 23:56:16 -0800 From: Charlie Jenkins To: Alexandre Ghiti Cc: Paul Walmsley , Palmer Dabbelt , Huacai Chen , WANG Xuerui , Thomas Gleixner , Peter Zijlstra , Andy Lutomirski , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev Subject: Re: [PATCH 1/4] riscv: entry: Convert ret_from_fork() to C Message-ID: References: <20250122-riscv_optimize_entry-v1-0-4ee95559cfd0@rivosinc.com> <20250122-riscv_optimize_entry-v1-1-4ee95559cfd0@rivosinc.com> <3c2d171a-1e6c-459e-b254-e9684a4e5ba4@ghiti.fr> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3c2d171a-1e6c-459e-b254-e9684a4e5ba4@ghiti.fr> On Fri, Jan 24, 2025 at 08:09:16AM +0100, Alexandre Ghiti wrote: > Hi Charlie, > > On 22/01/2025 23:56, Charlie Jenkins wrote: > > Move the main section of ret_from_fork() to C to allow inlining of > > syscall_exit_to_user_mode(). > > > > Signed-off-by: Charlie Jenkins > > --- > > arch/riscv/include/asm/asm-prototypes.h | 1 + > > arch/riscv/kernel/entry.S | 15 ++++++--------- > > arch/riscv/kernel/process.c | 14 ++++++++++++-- > > 3 files changed, 19 insertions(+), 11 deletions(-) > > > > diff --git a/arch/riscv/include/asm/asm-prototypes.h b/arch/riscv/include/asm/asm-prototypes.h > > index cd627ec289f163a630b73dd03dd52a6b28692997..733ff609778797001006c33bba9e3cc5b1f15387 100644 > > --- a/arch/riscv/include/asm/asm-prototypes.h > > +++ b/arch/riscv/include/asm/asm-prototypes.h > > @@ -52,6 +52,7 @@ DECLARE_DO_ERROR_INFO(do_trap_ecall_s); > > DECLARE_DO_ERROR_INFO(do_trap_ecall_m); > > DECLARE_DO_ERROR_INFO(do_trap_break); > > +asmlinkage void ret_from_fork(void *fn_arg, int (*fn)(void *), 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 33a5a9f2a0d4e1eeccfb3621b9e518b88e1b0704..9225c322279aa90e737b1d7144db084319cf8103 100644 > > --- a/arch/riscv/kernel/entry.S > > +++ b/arch/riscv/kernel/entry.S > > @@ -319,17 +319,14 @@ SYM_CODE_END(handle_kernel_stack_overflow) > > ASM_NOKPROBE(handle_kernel_stack_overflow) > > #endif > > -SYM_CODE_START(ret_from_fork) > > +SYM_CODE_START(ret_from_fork_asm) > > call schedule_tail > > - beqz s0, 1f /* not from kernel thread */ > > - /* Call fn(arg) */ > > - move a0, s1 > > - jalr s0 > > -1: > > - move a0, sp /* pt_regs */ > > - call syscall_exit_to_user_mode > > + move a0, s1 /* fn */ > > + move a1, s0 /* fn_arg */ > > > You pass the arguments in the right order but the comments are wrong (s1 > contains fn_arg and s0 fn). Oh thank you! I originally had it in this order but then moved it around to reduce the amount of register shuffling that is needed on the C side, I will fix in the next version. - Charlie > > > > + move a2, sp /* pt_regs */ > > + call ret_from_fork > > j ret_from_exception > > -SYM_CODE_END(ret_from_fork) > > +SYM_CODE_END(ret_from_fork_asm) > > #ifdef CONFIG_IRQ_STACKS > > /* > > diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c > > index 58b6482c2bf662bf5224ca50c8e21a68760a6b41..0d07e6d8f6b57beba438dbba5e8c74a014582bee 100644 > > --- a/arch/riscv/kernel/process.c > > +++ b/arch/riscv/kernel/process.c > > @@ -17,7 +17,9 @@ > > #include > > #include > > #include > > +#include > > +#include > > #include > > #include > > #include > > @@ -36,7 +38,7 @@ unsigned long __stack_chk_guard __read_mostly; > > EXPORT_SYMBOL(__stack_chk_guard); > > #endif > > -extern asmlinkage void ret_from_fork(void); > > +extern asmlinkage void ret_from_fork_asm(void); > > void noinstr arch_cpu_idle(void) > > { > > @@ -206,6 +208,14 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) > > return 0; > > } > > +asmlinkage void ret_from_fork(void *fn_arg, int (*fn)(void *), struct pt_regs *regs) > > +{ > > + if (unlikely(fn)) > > + fn(fn_arg); > > + > > + syscall_exit_to_user_mode(regs); > > +} > > + > > int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) > > { > > unsigned long clone_flags = args->flags; > > @@ -242,7 +252,7 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) > > p->thread.riscv_v_flags = 0; > > if (has_vector()) > > riscv_v_thread_alloc(p); > > - p->thread.ra = (unsigned long)ret_from_fork; > > + p->thread.ra = (unsigned long)ret_from_fork_asm; > > p->thread.sp = (unsigned long)childregs; /* kernel sp */ > > return 0; > > } > > > > With the comment fix, you can add: > > Reviewed-by: Alexandre Ghiti > > Thanks, > > Alex >