From nobody Thu Apr 2 19:51:31 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53AB4ECAAA1 for ; Thu, 27 Oct 2022 11:12:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233565AbiJ0LM5 (ORCPT ); Thu, 27 Oct 2022 07:12:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233497AbiJ0LMy (ORCPT ); Thu, 27 Oct 2022 07:12:54 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A2BB6EEA81 for ; Thu, 27 Oct 2022 04:12:51 -0700 (PDT) Received: from loongson.cn (unknown [111.9.175.10]) by gateway (Coremail) with SMTP id _____8AxDdmxZ1pjKN4CAA--.10939S3; Thu, 27 Oct 2022 19:12:49 +0800 (CST) Received: from localhost.localdomain (unknown [111.9.175.10]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxXuCuZ1pjOdQFAA--.20808S2; Thu, 27 Oct 2022 19:12:47 +0800 (CST) From: Jinyang He To: Huacai Chen , WANG Xuerui , Oleg Nesterov Cc: Xi Ruoyao , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, WANG Xuerui Subject: [PATCH v3] LoongArch: Remove unused kernel stack padding Date: Thu, 27 Oct 2022 19:11:49 +0800 Message-Id: <20221027111149.27414-1-hejinyang@loongson.cn> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8CxXuCuZ1pjOdQFAA--.20808S2 X-CM-SenderInfo: pkhmx0p1dqwqxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129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k List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The current LoongArch kernel stack is padded as if obeying the MIPS o32 calling convention, signifying the port's MIPS lineage but no longer making sense. Remove the padding for clarity. Link: https://lore.kernel.org/loongarch/1662130897-13156-1-git-send-email-h= ejinyang@loongson.cn/ Reviewed-by: WANG Xuerui Signed-off-by: Jinyang He --- v2: Remove TOP_OF_KERNEL_STACK_PADDING Remove 'init stack pointer' in head.S v3: Improve commit message suggested by Xuerui Add Reviewed-by tags arch/loongarch/include/asm/processor.h | 2 +- arch/loongarch/include/asm/ptrace.h | 2 +- arch/loongarch/kernel/head.S | 3 +-- arch/loongarch/kernel/process.c | 4 ++-- arch/loongarch/kernel/switch.S | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/arch/loongarch/include/asm/processor.h b/arch/loongarch/includ= e/asm/processor.h index 6954dc5d24e9..7184f1dc61f2 100644 --- a/arch/loongarch/include/asm/processor.h +++ b/arch/loongarch/include/asm/processor.h @@ -191,7 +191,7 @@ static inline void flush_thread(void) unsigned long __get_wchan(struct task_struct *p); =20 #define __KSTK_TOS(tsk) ((unsigned long)task_stack_page(tsk) + \ - THREAD_SIZE - 32 - sizeof(struct pt_regs)) + THREAD_SIZE - sizeof(struct pt_regs)) #define task_pt_regs(tsk) ((struct pt_regs *)__KSTK_TOS(tsk)) #define KSTK_EIP(tsk) (task_pt_regs(tsk)->csr_era) #define KSTK_ESP(tsk) (task_pt_regs(tsk)->regs[3]) diff --git a/arch/loongarch/include/asm/ptrace.h b/arch/loongarch/include/a= sm/ptrace.h index 7437b9366c3b..59c4608de91d 100644 --- a/arch/loongarch/include/asm/ptrace.h +++ b/arch/loongarch/include/asm/ptrace.h @@ -133,7 +133,7 @@ static inline void die_if_kernel(const char *str, struc= t pt_regs *regs) #define current_pt_regs() \ ({ \ unsigned long sp =3D (unsigned long)__builtin_frame_address(0); \ - (struct pt_regs *)((sp | (THREAD_SIZE - 1)) + 1 - 32) - 1; \ + (struct pt_regs *)((sp | (THREAD_SIZE - 1)) + 1) - 1; \ }) =20 /* Helpers for working with the user stack pointer */ diff --git a/arch/loongarch/kernel/head.S b/arch/loongarch/kernel/head.S index 97425779ce9f..84970e266658 100644 --- a/arch/loongarch/kernel/head.S +++ b/arch/loongarch/kernel/head.S @@ -84,10 +84,9 @@ SYM_CODE_START(kernel_entry) # kernel entry point =20 la.pcrel tp, init_thread_union /* Set the SP after an empty pt_regs. */ - PTR_LI sp, (_THREAD_SIZE - 32 - PT_SIZE) + PTR_LI sp, (_THREAD_SIZE - PT_SIZE) PTR_ADD sp, sp, tp set_saved_sp sp, t0, t1 - PTR_ADDI sp, sp, -4 * SZREG # init stack pointer =20 bl start_kernel ASM_BUG() diff --git a/arch/loongarch/kernel/process.c b/arch/loongarch/kernel/proces= s.c index 1256e3582475..2526b68f1c0f 100644 --- a/arch/loongarch/kernel/process.c +++ b/arch/loongarch/kernel/process.c @@ -129,7 +129,7 @@ int copy_thread(struct task_struct *p, const struct ker= nel_clone_args *args) unsigned long clone_flags =3D args->flags; struct pt_regs *childregs, *regs =3D current_pt_regs(); =20 - childksp =3D (unsigned long)task_stack_page(p) + THREAD_SIZE - 32; + childksp =3D (unsigned long)task_stack_page(p) + THREAD_SIZE; =20 /* set up new TSS. */ childregs =3D (struct pt_regs *) childksp - 1; @@ -236,7 +236,7 @@ bool in_task_stack(unsigned long stack, struct task_str= uct *task, struct stack_info *info) { unsigned long begin =3D (unsigned long)task_stack_page(task); - unsigned long end =3D begin + THREAD_SIZE - 32; + unsigned long end =3D begin + THREAD_SIZE; =20 if (stack < begin || stack >=3D end) return false; diff --git a/arch/loongarch/kernel/switch.S b/arch/loongarch/kernel/switch.S index 43ebbc3990f7..202a163cb32f 100644 --- a/arch/loongarch/kernel/switch.S +++ b/arch/loongarch/kernel/switch.S @@ -26,7 +26,7 @@ SYM_FUNC_START(__switch_to) move tp, a2 cpu_restore_nonscratch a1 =20 - li.w t0, _THREAD_SIZE - 32 + li.w t0, _THREAD_SIZE PTR_ADD t0, t0, tp set_saved_sp t0, t1, t2 =20 --=20 2.34.3