Drop the per-node-mode exception handlers
v2 cover Drop the per-node-mode exception handlers
This series drops the per-node-mode exception handlers.
The UnixBench test results are as follows, Loongson-3C5000L-LL, CLFS7.1,
a, DYNAMIC_FTRACE enabled, KASLR disabled, no-pernode b, DYNAMIC_FTRACE enabled, KASLR disabled, pernode c, DYNAMIC_FTRACE enabled, KASLR enabled, no-pernode
1 cpu 16 cpus a-1, 782.6 4025.1 a-2, 783.3 3994.5 a-3, 784.2 4045.5 b-1, 775.5 3913.0 b-2, 763.9 3833.8 b-3, 777.7 3930.4 c-1, 811.0 3950.4 c-2, 795.7 3952.9
The results were almost identical, as Huacai said, the performance difference between pernode and nopernode is negligible
v2:
Directly call rather than using jirl.
Thanks for Ruoyao.
Jinyang He (6):
LoongArch: Rename handle_syscall to handle_sys
LoongArch: Move the content defined by SYM_DATA to data or rodata
section
LoongArch: Create a exception handlers section
LoongArch: Drop pernode exception handlers
LoongArch: Fix up the prologue unwinder unwind exception frame
LoongArch: Clean up la_abs macro
arch/loongarch/include/asm/asmmacro.h | 17 ----- arch/loongarch/include/asm/setup.h | 14 ---- arch/loongarch/include/asm/stackframe.h | 2 +- arch/loongarch/include/asm/traps.h | 81 ++++++++++++++++++++++ arch/loongarch/include/asm/unwind.h | 2 +- arch/loongarch/kernel/entry.S | 15 ++-- arch/loongarch/kernel/genex.S | 75 ++++++++++++-------- arch/loongarch/kernel/head.S | 2 + arch/loongarch/kernel/mcount_dyn.S | 2 + arch/loongarch/kernel/relocate.c | 28 -------- arch/loongarch/kernel/traps.c | 74 +------------------- arch/loongarch/kernel/unwind_prologue.c | 91 +++---------------------- arch/loongarch/kernel/vmlinux.lds.S | 37 +++++++--- arch/loongarch/mm/cache.c | 6 -- arch/loongarch/mm/tlb.c | 40 ----------- arch/loongarch/mm/tlbex.S | 71 +++++++++++-------- arch/loongarch/power/suspend.c | 5 +- 17 files changed, 230 insertions(+), 332 deletions(-) create mode 100644 arch/loongarch/include/asm/traps.h
Signature · 1 line
2.34.3
PATCH v2 1/6 LoongArch: Rename handle_syscall to handle_sys
The original handle_sys() is a trampline for handler_syscall. Drop it and rename handle_syscall to handle_sys for invoking it directly.
--- arch/loongarch/kernel/entry.S | 13 +++++++------ arch/loongarch/kernel/genex.S | 5 ----- 2 files changed, 7 insertions(+), 11 deletions(-)
arch/loongarch/kernel/entry.S +7 -6
@@ -18,9 +18,9 @@ .text .cfi_sections .debug_frame .align 5 -SYM_FUNC_START(handle_syscall) +SYM_FUNC_START(handle_sys) csrrd t0, PERCPU_BASE_KS - la.pcrel t1, kernelsp + la_abs t1, kernelsp add.d t1, t1, t0 move t2, sp ld.d sp, t1, 0
@@ -62,12 +62,13 @@ SYM_FUNC_START(handle_syscall) li.d tp, ~_THREAD_MASK and tp, tp, sp - move a0, sp - bl do_syscall + move a0, sp + la_abs ra, do_syscall + jirl ra, ra, 0 RESTORE_ALL_AND_RET -SYM_FUNC_END(handle_syscall) -_ASM_NOKPROBE(handle_syscall) +SYM_FUNC_END(handle_sys) +_ASM_NOKPROBE(handle_sys) SYM_CODE_START(ret_from_fork) bl schedule_tail # a0 = struct task_struct *prev
arch/loongarch/kernel/genex.S +0 -5
@@ -91,8 +91,3 @@ SYM_FUNC_END(except_vec_cex) BUILD_HANDLER ri ri none BUILD_HANDLER watch watch none BUILD_HANDLER reserved reserved none /* others */ - -SYM_FUNC_START(handle_sys) - la_abs t0, handle_syscall - jr t0 -SYM_FUNC_END(handle_sys)
Signature · 1 line
2.34.3
PATCH v2 2/6 LoongArch: Move the content defined by SYM_DATA to data or rodata section
In reply to Jinyang HeDue to the SYM_DATA do not give the section notes, manually set it.
--- arch/loongarch/kernel/genex.S | 2 ++ arch/loongarch/kernel/head.S | 2 ++ 2 files changed, 4 insertions(+)
arch/loongarch/kernel/genex.S +2 -0
@@ -77,7 +77,9 @@ SYM_FUNC_END(except_vec_cex) 668: RESTORE_ALL_AND_RET SYM_FUNC_END(handle_\exception) + .pushsection .rodata SYM_DATA(unwind_hint_\exception, .word 668b - 666b) + .popsection .endm BUILD_HANDLER ade ade badv
arch/loongarch/kernel/head.S +2 -0
@@ -32,9 +32,11 @@ _head: pe_header: __EFI_PE_HEADER +.pushsection .rodata SYM_DATA(kernel_asize, .long _end - _text); SYM_DATA(kernel_fsize, .long _edata - _text); SYM_DATA(kernel_offset, .long kernel_offset - _text); +.popsection #endif
Signature · 1 line
2.34.3
PATCH v2 3/6 LoongArch: Create a exception handlers section
In reply to Jinyang HeCreate a section named .ex_handlers to collect exception handlers. Use strict alignment for using it later. As some handlers is shared to other exception, we can not define symbol directly. Correct these symbols by adding suffix or by using number label.
--- arch/loongarch/include/asm/traps.h | 39 +++++++++++++++++ arch/loongarch/kernel/entry.S | 5 +++ arch/loongarch/kernel/genex.S | 65 ++++++++++++++++++++++------- arch/loongarch/kernel/vmlinux.lds.S | 19 +++++++++ arch/loongarch/mm/tlbex.S | 53 ++++++++++++++++------- 5 files changed, 149 insertions(+), 32 deletions(-) create mode 100644 arch/loongarch/include/asm/traps.h
arch/loongarch/include/asm/traps.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2023 Loongson Technology Corporation Limited +*/ +#ifndef _ASM_TRAPS_H +#define _ASM_TRAPS_H + +#include <asm/loongarch.h> // For EXCCODES + +#ifdef __ASSEMBLY__ +/* Used for create exception handlers. */ +#define EXCCODE_UNDEF 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, \ + 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, \ + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, \ + 59, 60, 61, 62, 63 +#define EXCCODE_NOHND EXCCODE_OOB, EXCCODE_BTE, EXCCODE_PSI, \ + EXCCODE_HYP, EXCCODE_GCM, EXCCODE_SE + +/* As merrentry is set to the same value as eentry, the merr handler can +* be thought as the first exception handler. +*/ +#define EXCCODE_MERR EXCCODE_RSV + +#define _SET_EXCEPTION_HANDLER (EXCCODE , ...) \ + .pushsection .exception_handlers.##EXCCODE, "ax"; \ + .align 9; \ + __VA_ARGS__; \ + .popsection; + +#define SET_EXCEPTION_HANDLER (EXCCODE , ...) \ + _SET_EXCEPTION_HANDLER(EXCCODE, __VA_ARGS__) + +#define SET_TLBR_HANDLER (...) \ + .pushsection .tlbrhandler, "ax"; \ + __VA_ARGS__; \ + .popsection; +#endif /* __ASSEMBLY__ */ + +#endif /* _ASM_TRAPS_H */
arch/loongarch/kernel/entry.S +5 -0
@@ -14,9 +14,11 @@ #include <asm/regdef.h> #include <asm/stackframe.h> #include <asm/thread_info.h> +#include <asm/traps.h> .text .cfi_sections .debug_frame + .macro _handle_sys .align 5 SYM_FUNC_START(handle_sys) csrrd t0, PERCPU_BASE_KS
@@ -69,6 +71,9 @@ SYM_FUNC_START(handle_sys) RESTORE_ALL_AND_RET SYM_FUNC_END(handle_sys) _ASM_NOKPROBE(handle_sys) + .endm + +SET_EXCEPTION_HANDLER(EXCCODE_SYS, _handle_sys) SYM_CODE_START(ret_from_fork) bl schedule_tail # a0 = struct task_struct *prev
arch/loongarch/kernel/genex.S +49 -16
100 lines not on this page · raw message
arch/loongarch/kernel/vmlinux.lds.S +19 -0
@@ -21,6 +21,11 @@ */ PECOFF_FILE_ALIGN = 0x200; PECOFF_SEGMENT_ALIGN = 0x10000; +EX_HANDLER_ALIGN = SZ_512; +EX_HANDLER_SIZE = SZ_512; +EX_HANDLER_TOTAL = 78; /* 64 Exceptions + 14 Interrupts */ +EXCEPTION_ENTRY_ALIGN = SZ_64K; +TLBR_ENTRY_ALIGN = SZ_4K; OUTPUT_ARCH(loongarch) ENTRY(kernel_entry)
@@ -54,6 +59,17 @@ SECTIONS . = ALIGN(PECOFF_SEGMENT_ALIGN); _etext = .; + . = ALIGN(EXCEPTION_ENTRY_ALIGN); + .ex_handlers : { + __ex_handlers = .; + *(SORT_BY_INIT_PRIORITY(.exception_handlers.*)) + . = ALIGN(EX_HANDLER_ALIGN); + __ex_handlers_end = .; + . = ALIGN(TLBR_ENTRY_ALIGN); + __tlbr_entry = .; + *(.tlbrhandler) + } + /* * struct alt_inst entries. From the header (alternative.h): * "Alternative instructions for different CPU types or capabilities"
@@ -154,3 +170,6 @@ SECTIONS *(.eh_frame) } } + +ASSERT(__ex_handlers_end == (__ex_handlers + EX_HANDLER_SIZE * EX_HANDLER_TOTAL), + "The amount of exception handlers does not match!");
arch/loongarch/mm/tlbex.S +37 -16
147 lines not on this page · raw message
Signature · 1 line
2.34.3
Re: [PATCH v2 3/6] LoongArch: Create a exception handlers section
Hi, Jinyang
arch/loongarch/kernel/vmlinux.lds.S line 26
Quoted 11 lines · Jinyang He
arch/loongarch/kernel/vmlinux.lds.S +3
-0@@ -21,6 +21,11 @@ */ PECOFF_FILE_ALIGN = 0x200; PECOFF_SEGMENT_ALIGN = 0x10000; +EX_HANDLER_ALIGN = SZ_512; +EX_HANDLER_SIZE = SZ_512; +EX_HANDLER_TOTAL = 78; /* 64 Exceptions + 14 Interrupts */
You can define EXCCODE_NUM as 78 in loongarch.h, and remove the unused EXCCODE_INT_END and EXCCODE_INT_NUM in PATCH4.
Youling.
Quoted 30 lines
arch/loongarch/kernel/vmlinux.lds.S +16
-0+EXCEPTION_ENTRY_ALIGN = SZ_64K; +TLBR_ENTRY_ALIGN = SZ_4K; OUTPUT_ARCH(loongarch) ENTRY(kernel_entry)@@ -54,6 +59,17 @@ SECTIONS . = ALIGN(PECOFF_SEGMENT_ALIGN); _etext = .; + . = ALIGN(EXCEPTION_ENTRY_ALIGN); + .ex_handlers : { + __ex_handlers = .; + *(SORT_BY_INIT_PRIORITY(.exception_handlers.*)) + . = ALIGN(EX_HANDLER_ALIGN); + __ex_handlers_end = .; + . = ALIGN(TLBR_ENTRY_ALIGN); + __tlbr_entry = .; + *(.tlbrhandler) + } + /* * struct alt_inst entries. From the header (alternative.h): * "Alternative instructions for different CPU types or capabilities"@@ -154,3 +170,6 @@ SECTIONS *(.eh_frame) } } + +ASSERT(__ex_handlers_end == (__ex_handlers + EX_HANDLER_SIZE * EX_HANDLER_TOTAL), + "The amount of exception handlers does not match!");
PATCH v2 4/6 LoongArch: Drop pernode exception handlers
In reply to Jinyang He1, set the value of CSR.EENTRY to &__ex_handlers. 2, set the value of CSR.TLBRENTRY to &__tlbr_entry. 3, set the value of CSR.MERRENTRY to &__ex_handlers. Then, we can drop the pernode exception handlers.
--- arch/loongarch/include/asm/setup.h | 7 --- arch/loongarch/include/asm/traps.h | 29 ++++++++++ arch/loongarch/kernel/genex.S | 8 --- arch/loongarch/kernel/traps.c | 74 +------------------------ arch/loongarch/kernel/unwind_prologue.c | 62 +-------------------- arch/loongarch/mm/cache.c | 6 -- arch/loongarch/mm/tlb.c | 40 ------------- arch/loongarch/power/suspend.c | 5 +- 8 files changed, 33 insertions(+), 198 deletions(-)
arch/loongarch/include/asm/setup.h +0 -7
@@ -9,17 +9,10 @@#include <linux/types.h> #include <uapi/asm/setup.h> -#define VECSIZE 0x200 - -extern unsigned long eentry; -extern unsigned long tlbrentry;extern char init_command_line[COMMAND_LINE_SIZE ];extern void tlb_init (int cpu);extern void cpu_cache_init (void ); -extern void cache_error_setup (void );extern void per_cpu_trap_init (int cpu); -extern void set_handler (unsigned long offset,void *addr,unsigned long len); -extern void set_merr_handler (unsigned long offset,void *addr,unsigned long len);#ifdef CONFIG_RELOCATABLE
arch/loongarch/include/asm/traps.h +29 -0
@@ -34,6 +34,35 @@ .pushsection .tlbrhandler, "ax"; \ __VA_ARGS__; \ .popsection; + +#else /* __ASSEMBLY__ */ + +#define VECSIZE 0x200 +extern void *__ex_handlers; +extern void *__tlbr_entry; + +static inline void set_eentry (void *entry) +{ +csr_write64 ((unsigned long )entry,LOONGARCH_CSR_EENTRY ); +} + +static inline void set_tlbrentry (void *entry) +{ +csr_write64 ((unsigned long )entry,LOONGARCH_CSR_TLBRENTRY ); +} + +static inline void set_merrentry (void *entry) +{ +csr_write64 ((unsigned long )entry,LOONGARCH_CSR_MERRENTRY ); +} + +static inline void configure_exception_vector (void ) +{ +set_eentry (&__ex_handlers); +set_tlbrentry (&__tlbr_entry); +set_merrentry (&__ex_handlers); +} +#endif /* __ASSEMBLY__ */ #endif /* _ASM_TRAPS_H */
arch/loongarch/kernel/genex.S +0 -8
@@ -72,19 +72,14 @@ SYM_FUNC_END(except_vec_cex) .macro BUILD_HANDLER exception handler prep .align 5 SYM_FUNC_START(handle_\exception) - 666: BACKUP_T0T1 SAVE_ALL build_prep_\prep move a0, sp la_abs t0, do_\handler jirl ra, t0, 0 - 668: RESTORE_ALL_AND_RET SYM_FUNC_END(handle_\exception) - .pushsection .rodata -SYM_DATA(unwind_hint_\exception, .word 668b - 666b) - .popsection .endm SET_EXCEPTION_HANDLER(EXCCODE_SIP0, _handle_vint)
@@ -123,6 +118,3 @@ SET_EXCEPTION_HANDLER(\i, BUILD_HANDLER reserved\i reserved none) .irp i, EXCCODE_NOHND SET_EXCEPTION_HANDLER(\i, BUILD_HANDLER reserved\i reserved none) .endr - -/* Create handle_reserved for temporary build. */ -BUILD_HANDLER reserved reserved none
arch/loongarch/kernel/traps.c +1 -73
94 lines not on this page · raw message
arch/loongarch/kernel/unwind_prologue.c +1 -61
70 lines not on this page · raw message
arch/loongarch/mm/cache.c +0 -6
@@ -25,12 +25,6 @@#include <asm/processor.h> #include <asm/setup.h> -void cache_error_setup (void ) -{ -extern char __weak except_vec_cex; -set_merr_handler (0x0 , &except_vec_cex,0x80 ); -} -/* * LoongArch maintains ICache/DCache coherency by hardware, * we just need "ibar" to avoid instruction hazard here.
arch/loongarch/mm/tlb.c +0 -40
@@ -250,50 +250,10 @@ static void output_pgtable_bits_defines(void)pr_debug ("\n" ); } -#ifdef CONFIG_NUMA -unsigned long pcpu_handlers[NR_CPUS ]; -#endif -extern long exception_handlers[VECSIZE *128 /sizeof (long )]; -void setup_tlb_handler (int cpu) {setup_ptwalker ();local_flush_tlb_all (); - -/* The tlb handlers are generated only once */ -if (cpu ==0 ) { -memcpy ((void *)tlbrentry, handle_tlb_refill,0x80 ); -local_flush_icache_range (tlbrentry, tlbrentry +0x80 ); -set_handler (EXCCODE_TLBI *VECSIZE , handle_tlb_load,VECSIZE ); -set_handler (EXCCODE_TLBL *VECSIZE , handle_tlb_load,VECSIZE ); -set_handler (EXCCODE_TLBS *VECSIZE , handle_tlb_store,VECSIZE ); -set_handler (EXCCODE_TLBM *VECSIZE , handle_tlb_modify,VECSIZE ); -set_handler (EXCCODE_TLBNR *VECSIZE , handle_tlb_protect,VECSIZE ); -set_handler (EXCCODE_TLBNX *VECSIZE , handle_tlb_protect,VECSIZE ); -set_handler (EXCCODE_TLBPE *VECSIZE , handle_tlb_protect,VECSIZE ); - } -#ifdef CONFIG_NUMA - else { -void *addr; -struct page *page; -const int vec_sz =sizeof (exception_handlers); - -if (pcpu_handlers[cpu]) -return ; - - page =alloc_pages_node (cpu_to_node (cpu),GFP_ATOMIC ,get_order (vec_sz)); -if (!page) -return ; - - addr =page_address (page); - pcpu_handlers[cpu] = (unsigned long )addr; -memcpy ((void *)addr, (void *)eentry, vec_sz); -local_flush_icache_range ((unsigned long )addr, (unsigned long )addr + vec_sz); -csr_write64 (pcpu_handlers[cpu],LOONGARCH_CSR_EENTRY ); -csr_write64 (pcpu_handlers[cpu],LOONGARCH_CSR_MERRENTRY ); -csr_write64 (pcpu_handlers[cpu] +80 *VECSIZE ,LOONGARCH_CSR_TLBRENTRY ); - } -#endif }void tlb_init (int cpu)
arch/loongarch/power/suspend.c +2 -3
@@ -14,6 +14,7 @@#include <asm/setup.h> #include <asm/time.h> #include <asm/tlbflush.h> +#include <asm/traps.h> u64 loongarch_suspend_addr;
@@ -45,9 +46,7 @@ static void arch_common_resume(void)sync_counter ();local_flush_tlb_all ();csr_write64 (per_cpu_offset (0 ),PERCPU_BASE_KS ); -csr_write64 (eentry,LOONGARCH_CSR_EENTRY ); -csr_write64 (eentry,LOONGARCH_CSR_MERRENTRY ); -csr_write64 (tlbrentry,LOONGARCH_CSR_TLBRENTRY ); +configure_exception_vector ();csr_write64 (saved_regs.pgd,LOONGARCH_CSR_PGDL );csr_write64 (saved_regs.kpgd,LOONGARCH_CSR_PGDH );
Signature · 1 line
2.34.3
Re: [PATCH v2 4/6] LoongArch: Drop pernode exception handlers
Quoted 5 lines · Jinyang He
arch/loongarch/mm/tlb.c +0
-0
arch/loongarch/mm/tlb.c static void output_pgtable_bits_defines(void) · line 253
Quoted 9 lines
arch/loongarch/mm/tlb.c +0
-5@@ -250,50 +250,10 @@ static void output_pgtable_bits_defines(void)pr_debug ("\n" ); } -#ifdef CONFIG_NUMA -unsigned long pcpu_handlers[NR_CPUS ]; -#endif -extern long exception_handlers[VECSIZE *128 /sizeof (long )]; -void setup_tlb_handler (int cpu)
It may be necessary to rename the function after modification.
Youling.
Quoted 40 lines
arch/loongarch/mm/tlb.c +0
-35{setup_ptwalker ();local_flush_tlb_all (); - -/* The tlb handlers are generated only once */ -if (cpu ==0 ) { -memcpy ((void *)tlbrentry, handle_tlb_refill,0x80 ); -local_flush_icache_range (tlbrentry, tlbrentry +0x80 ); -set_handler (EXCCODE_TLBI *VECSIZE , handle_tlb_load,VECSIZE ); -set_handler (EXCCODE_TLBL *VECSIZE , handle_tlb_load,VECSIZE ); -set_handler (EXCCODE_TLBS *VECSIZE , handle_tlb_store,VECSIZE ); -set_handler (EXCCODE_TLBM *VECSIZE , handle_tlb_modify,VECSIZE ); -set_handler (EXCCODE_TLBNR *VECSIZE , handle_tlb_protect,VECSIZE ); -set_handler (EXCCODE_TLBNX *VECSIZE , handle_tlb_protect,VECSIZE ); -set_handler (EXCCODE_TLBPE *VECSIZE , handle_tlb_protect,VECSIZE ); - } -#ifdef CONFIG_NUMA - else { -void *addr; -struct page *page; -const int vec_sz =sizeof (exception_handlers); - -if (pcpu_handlers[cpu]) -return ; - - page =alloc_pages_node (cpu_to_node (cpu),GFP_ATOMIC ,get_order (vec_sz)); -if (!page) -return ; - - addr =page_address (page); - pcpu_handlers[cpu] = (unsigned long )addr; -memcpy ((void *)addr, (void *)eentry, vec_sz); -local_flush_icache_range ((unsigned long )addr, (unsigned long )addr + vec_sz); -csr_write64 (pcpu_handlers[cpu],LOONGARCH_CSR_EENTRY ); -csr_write64 (pcpu_handlers[cpu],LOONGARCH_CSR_MERRENTRY ); -csr_write64 (pcpu_handlers[cpu] +80 *VECSIZE ,LOONGARCH_CSR_TLBRENTRY ); - } -#endif }
PATCH v2 5/6 LoongArch: Fix up the prologue unwinder unwind exception frame
In reply to Jinyang HeIt is a simply way to correct the unwind info when the special functions influence the normal prologue analysis. We find out the position where should unwind by PT_REGS, and mark it UNW_NEED_RESET. Linkers will collect them and the prologue unwinder will compare them to pc.
--- arch/loongarch/include/asm/traps.h | 13 +++++++++ arch/loongarch/include/asm/unwind.h | 2 +- arch/loongarch/kernel/genex.S | 1 + arch/loongarch/kernel/mcount_dyn.S | 2 ++ arch/loongarch/kernel/unwind_prologue.c | 37 +++++++++---------------- arch/loongarch/kernel/vmlinux.lds.S | 9 ++++++ 6 files changed, 39 insertions(+), 25 deletions(-)
arch/loongarch/include/asm/traps.h +13 -0
@@ -5,6 +5,7 @@#ifndef _ASM_TRAPS_H#define _ASM_TRAPS_H +#include <asm/asm.h> #include <asm/loongarch.h> // For EXCCODES #ifdef __ASSEMBLY__
@@ -35,11 +36,23 @@ __VA_ARGS__; \ .popsection; +#ifdef CONFIG_UNWINDER_PROLOGUE +#define UNW_NEED_RESET \ + 668: \ + .pushsection .unw_need_reset, "a"; \ + PTR 668b; \ + .popsection; +#else /* CONFIG_UNWINDER_PROLOGUE */ +#define UNW_NEED_RESET +#endif +#else /* __ASSEMBLY__ */ #define VECSIZE 0x200extern void *__ex_handlers;extern void *__tlbr_entry; +extern void *__unw_need_reset; +extern void *__unw_need_reset_end;static inline void set_eentry (void *entry) {
arch/loongarch/include/asm/unwind.h +1 -1
@@ -22,7 +22,7 @@ struct unwind_state {char type;/* UNWINDER_XXX */ struct stack_info stack_info;struct task_struct *task; -bool first, error, reset; +bool first, error, need_reset;int graph_idx;unsigned long sp, pc, ra; };
arch/loongarch/kernel/genex.S +1 -0
@@ -78,6 +78,7 @@ SYM_FUNC_START(handle_\exception) move a0, sp la_abs t0, do_\handler jirl ra, t0, 0 + UNW_NEED_RESET RESTORE_ALL_AND_RET SYM_FUNC_END(handle_\exception) .endm
arch/loongarch/kernel/mcount_dyn.S +2 -0
@@ -7,6 +7,7 @@ #include <asm/ftrace.h> #include <asm/regdef.h> #include <asm/stackframe.h> +#include <asm/traps.h> .text /*
@@ -81,6 +82,7 @@ SYM_CODE_START(ftrace_common) SYM_INNER_LABEL(ftrace_call, SYM_L_GLOBAL) bl ftrace_stub + UNW_NEED_RESET #ifdef CONFIG_FUNCTION_GRAPH_TRACER SYM_INNER_LABEL(ftrace_graph_call, SYM_L_GLOBAL) nop /* b ftrace_graph_caller */
arch/loongarch/kernel/unwind_prologue.c +13 -24
@@ -10,33 +10,22 @@#include <asm/loongson.h> #include <asm/ptrace.h> #include <asm/setup.h> +#include <asm/traps.h> #include <asm/unwind.h> -static inline bool fix_exception (unsigned long pc) -{ -return false; -} - -/* -* As we meet ftrace_regs_entry, reset first flag like first doing -* tracing. Prologue analysis will stop soon because PC is at entry. -*/ -static inline bool fix_ftrace (unsigned long pc) -{ -#ifdef CONFIG_DYNAMIC_FTRACE -return pc == (unsigned long )ftrace_call +LOONGARCH_INSN_SIZE ; -#else -return false; -#endif -} -static inline bool unwind_state_fixup (struct unwind_state *state) { -if (!fix_exception (state->pc) && !fix_ftrace (state->pc)) -return false; +unsigned long *p = (unsigned long *)&__unw_need_reset; +unsigned long *q = (unsigned long *)&__unw_need_reset_end; - state->reset = true; -return true; +for (; p < q; p++) { +if (*p != state->pc) +continue ; + state->need_reset = true; +return true; + } + +return false; }/*
@@ -59,10 +48,10 @@ static bool unwind_by_prologue(struct unwind_state *state)if (state->sp >= info->end || state->sp < info->begin)return false; -if (state->reset) { +if (state->need_reset) { regs = (struct pt_regs *)state->sp; state->first = true; - state->reset = false; + state->need_reset = false; state->pc = regs->csr_era; state->ra = regs->regs[1 ]; state->sp = regs->regs[3 ];
arch/loongarch/kernel/vmlinux.lds.S +9 -0
@@ -70,6 +70,15 @@ SECTIONS *(.tlbrhandler) } +#ifdef CONFIG_UNWINDER_PROLOGUE + . = ALIGN(8); + .unw_need_reset : { + __unw_need_reset = .; + *(.unw_need_reset) + __unw_need_reset_end = .; + } +#endif + /* * struct alt_inst entries. From the header (alternative.h): * "Alternative instructions for different CPU types or capabilities"
Signature · 1 line
2.34.3
PATCH v2 6/6 LoongArch: Clean up la_abs macro
In reply to Jinyang HeNow we can replace la_abs with la.pcrel. Clean up the la_abs macro.
--- arch/loongarch/include/asm/asmmacro.h | 17 --------------- arch/loongarch/include/asm/setup.h | 7 ------- arch/loongarch/include/asm/stackframe.h | 2 +- arch/loongarch/kernel/entry.S | 5 ++--- arch/loongarch/kernel/genex.S | 8 +++---- arch/loongarch/kernel/relocate.c | 28 ------------------------- arch/loongarch/kernel/vmlinux.lds.S | 9 -------- arch/loongarch/mm/tlbex.S | 18 +++++++--------- 8 files changed, 13 insertions(+), 81 deletions(-)
arch/loongarch/include/asm/asmmacro.h +0 -17
@@ -667,21 +667,4 @@ nor \dst, \src, zero .endm -.macro la_abs reg, sym -#ifndef CONFIG_RELOCATABLE - la.abs \reg, \sym -#else - 766: - lu12i.w \reg, 0 - ori \reg, \reg, 0 - lu32i.d \reg, 0 - lu52i.d \reg, \reg, 0 - .pushsection ".la_abs", "aw", %progbits - 768: - .dword 768b-766b - .dword \sym - .popsection -#endif -.endm - #endif /* _ASM_ASMMACRO_H */
arch/loongarch/include/asm/setup.h +0 -7
@@ -16,13 +16,6 @@ extern void per_cpu_trap_init(int cpu);#ifdef CONFIG_RELOCATABLE -struct rela_la_abs { -long offset; -long symvalue; -}; - -extern long __la_abs_begin; -extern long __la_abs_end;extern long __rela_dyn_begin;extern long __rela_dyn_end;
arch/loongarch/include/asm/stackframe.h +1 -1
@@ -86,7 +86,7 @@* new value in sp. */ .macro get_saved_sp docfi=0 - la_abs t1, kernelsp + la.pcrel t1, kernelsp#ifdef CONFIG_SMP csrrd t0,PERCPU_BASE_KS LONG_ADD t1, t1, t0
arch/loongarch/kernel/entry.S +2 -3
@@ -22,7 +22,7 @@ .align 5 SYM_FUNC_START(handle_sys) csrrd t0, PERCPU_BASE_KS - la_abs t1, kernelsp + la.pcrel t1, kernelsp add.d t1, t1, t0 move t2, sp ld.d sp, t1, 0
@@ -65,8 +65,7 @@ SYM_FUNC_START(handle_sys) and tp, tp, sp move a0, sp - la_abs ra, do_syscall - jirl ra, ra, 0 + bl do_syscall RESTORE_ALL_AND_RET SYM_FUNC_END(handle_sys)
arch/loongarch/kernel/genex.S +3 -5
@@ -36,7 +36,7 @@ SYM_FUNC_END(__arch_cpu_idle) SYM_FUNC_START(handle_vint\idx) BACKUP_T0T1 SAVE_ALL - la_abs t1, __arch_cpu_idle + la.pcrel t1, __arch_cpu_idle LONG_L t0, sp, PT_ERA /* 32 byte rollback region */ ori t0, t0, 0x1f
@@ -45,8 +45,7 @@ SYM_FUNC_START(handle_vint\idx) LONG_S t0, sp, PT_ERA 1: move a0, sp move a1, sp - la_abs t0, do_vint - jirl ra, t0, 0 + bl do_vint RESTORE_ALL_AND_RET SYM_FUNC_END(handle_vint\idx) .endm
@@ -76,8 +75,7 @@ SYM_FUNC_START(handle_\exception) SAVE_ALL build_prep_\prep move a0, sp - la_abs t0, do_\handler - jirl ra, t0, 0 + bl do_\handler UNW_NEED_RESET RESTORE_ALL_AND_RET SYM_FUNC_END(handle_\exception)
arch/loongarch/kernel/relocate.c +0 -28
@@ -12,7 +12,6 @@#include <linux/start_kernel.h> #include <asm/bootinfo.h> #include <asm/early_ioremap.h> -#include <asm/inst.h> #include <asm/sections.h> #include <asm/setup.h>
@@ -41,31 +40,6 @@ static inline __init void relocate_relative(void) } } -static inline void __init relocate_la_abs (long random_offset) -{ -void *begin, *end; -struct rela_la_abs *p; - - begin =RELOCATED_KASLR (&__la_abs_begin); - end =RELOCATED_KASLR (&__la_abs_end); - -for (p = begin; (void *)p < end; p++) { -long v = p->symvalue; -uint32_t lu12iw, ori, lu32id, lu52id; -union loongarch_instruction *insn = (void *)p - p->offset; - - lu12iw = (v >>12 ) &0xfffff ; - ori = v &0xfff ; - lu32id = (v >>32 ) &0xfffff ; - lu52id = v >>52 ; - - insn[0 ].reg1i20_format.immediate = lu12iw; - insn[1 ].reg2i12_format.immediate = ori; - insn[2 ].reg1i20_format.immediate = lu32id; - insn[3 ].reg2i12_format.immediate = lu52id; - } -} -#ifdef CONFIG_RANDOMIZE_BASE static inline __init unsigned long rotate_xor (unsigned long hash,const void *area,size_t size)
@@ -202,8 +176,6 @@ void * __init relocate_kernel(void)if (reloc_offset)relocate_relative (); -relocate_la_abs (random_offset); -return kernel_entry; }
arch/loongarch/kernel/vmlinux.lds.S +0 -9
@@ -91,15 +91,6 @@ SECTIONS __alt_instructions_end = .; } -#ifdef CONFIG_RELOCATABLE - . = ALIGN(8); - .la_abs : AT(ADDR(.la_abs) - LOAD_OFFSET) { - __la_abs_begin = .; - *(.la_abs) - __la_abs_end = .; - } -#endif - .got : ALIGN(16) { *(.got) } .plt : ALIGN(16) { *(.plt) } .got.plt : ALIGN(16) { *(.got.plt) }
arch/loongarch/mm/tlbex.S +7 -11
@@ -41,8 +41,7 @@ SYM_FUNC_START(handle_tlb_protect\idx) move a1, zero csrrd a2, LOONGARCH_CSR_BADV REG_S a2, sp, PT_BVADDR - la_abs t0, do_page_fault - jirl ra, t0, 0 + bl do_page_fault RESTORE_ALL_AND_RET SYM_FUNC_END(handle_tlb_protect\idx) .endm
@@ -119,7 +118,7 @@ SYM_FUNC_START(handle_tlb_load\idx) #ifdef CONFIG_64BIT 3: /* vmalloc_load: */ - la_abs t1, swapper_pg_dir + la.pcrel t1, swapper_pg_dir b 1b #endif
@@ -190,8 +189,7 @@ SYM_FUNC_START(handle_tlb_load\idx) 5: /* nopage_tlb_load: */ dbar 0 csrrd ra, EXCEPTION_KS2 - la_abs t0, tlb_do_page_fault_0 - jr t0 + b tlb_do_page_fault_0 SYM_FUNC_END(handle_tlb_load\idx) .endm
@@ -268,7 +266,7 @@ smp_pgtable_change_store: #ifdef CONFIG_64BIT vmalloc_store: - la_abs t1, swapper_pg_dir + la.pcrel t1, swapper_pg_dir b vmalloc_done_store #endif
@@ -341,8 +339,7 @@ tlb_huge_update_store: nopage_tlb_store: dbar 0 csrrd ra, EXCEPTION_KS2 - la_abs t0, tlb_do_page_fault_1 - jr t0 + b tlb_do_page_fault_1 SYM_FUNC_END(handle_tlb_store) .endm
@@ -418,7 +415,7 @@ smp_pgtable_change_modify: #ifdef CONFIG_64BIT vmalloc_modify: - la_abs t1, swapper_pg_dir + la.pcrel t1, swapper_pg_dir b vmalloc_done_modify #endif
@@ -490,8 +487,7 @@ tlb_huge_update_modify: nopage_tlb_modify: dbar 0 csrrd ra, EXCEPTION_KS2 - la_abs t0, tlb_do_page_fault_1 - jr t0 + b tlb_do_page_fault_1 SYM_FUNC_END(handle_tlb_modify) .endm
Signature · 1 line
2.34.3