init: consolidate trap_init()
Subsystems (12)
PATCH 1/1 init: consolidate trap_init()
Many architectures implement the trap_init() as NOP, since there is no such default for trap_init(), this empty stub is duplicated among these architectures. Provide a generic but weak NOP implementation to drop the empty stubs of trap_init() in these architectures.
--- arch/arc/kernel/traps.c | 5 ----- arch/arm/kernel/traps.c | 5 ----- arch/h8300/kernel/traps.c | 13 ------------- arch/hexagon/kernel/traps.c | 4 ---- arch/nds32/kernel/traps.c | 5 ----- arch/nios2/kernel/traps.c | 5 ----- arch/openrisc/kernel/traps.c | 5 ----- arch/parisc/kernel/traps.c | 4 ---- arch/powerpc/kernel/traps.c | 5 ----- arch/riscv/kernel/traps.c | 5 ----- arch/um/kernel/trap.c | 4 ---- init/main.c | 2 ++ 12 files changed, 2 insertions(+), 60 deletions(-)
arch/arc/kernel/traps.c +0 -5
@@ -20,11 +20,6 @@#include <asm/unaligned.h> #include <asm/kprobes.h> -void __init trap_init (void ) -{ -return ; -} -void die (const char *str,struct pt_regs *regs,unsigned long address) {show_kernel_fault_diag (str, regs, address);
arch/arm/kernel/traps.c +0 -5
@@ -780,11 +780,6 @@ void abort(void)panic ("Oops failed to kill thread" ); } -void __init trap_init (void ) -{ -return ; -} -#ifdef CONFIG_KUSER_HELPERS static void __init kuser_init (void *vectors) {
arch/h8300/kernel/traps.c +0 -13
@@ -30,19 +30,6 @@static DEFINE_SPINLOCK (die_lock); -/* -* this must be called very early as the kernel might -* use some instruction that are emulated on the 060 -*/ - -void __init base_trap_init (void ) -{ -} - -void __init trap_init (void ) -{ -} - asmlinkage void set_esp0(unsigned long ssp) { current->thread.esp0 = ssp;
arch/hexagon/kernel/traps.c +0 -4
@@ -28,10 +28,6 @@#define TRAP_SYSCALL 1#define TRAP_DEBUG 0xdb -void __init trap_init (void ) -{ -} -#ifdef CONFIG_GENERIC_BUG /* Maybe should resemble arch/sh/kernel/traps.c ?? */ int is_valid_bugaddr (unsigned long addr)
arch/nds32/kernel/traps.c +0 -5
@@ -183,11 +183,6 @@ void __pgd_error(const char *file, int line, unsigned long val) }extern char *exception_vector, *exception_vector_end; -void __init trap_init (void ) -{ -return ; -} -void __init early_trap_init (void ) {unsigned long ivb =0 ;
arch/nios2/kernel/traps.c +0 -5
@@ -105,11 +105,6 @@ void show_stack(struct task_struct *task, unsigned long *stack,printk ("%s\n" , loglvl); } -void __init trap_init (void ) -{ -/* Nothing to do here */ -} -/* Breakpoint handler */ asmlinkage void breakpoint_c(struct pt_regs *fp) {
arch/openrisc/kernel/traps.c +0 -5
@@ -231,11 +231,6 @@ void unhandled_exception(struct pt_regs *regs, int ea, int vector)die ("Oops" , regs,9 ); } -void __init trap_init (void ) -{ -/* Nothing needs to be done */ -} - asmlinkage void do_trap(struct pt_regs *regs, unsigned long address) {force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc);
arch/parisc/kernel/traps.c +0 -4
@@ -859,7 +859,3 @@ void __init early_trap_init(void)initialize_ivt (&fault_vector_20); } - -void __init trap_init (void ) -{ -}
arch/powerpc/kernel/traps.c +0 -5
@@ -2207,11 +2207,6 @@ DEFINE_INTERRUPT_HANDLER(kernel_bad_stack)die ("Bad kernel stack pointer" , regs,SIGABRT ); } -void __init trap_init (void ) -{ -} - -#ifdef CONFIG_PPC_EMULATED_STATS #define WARN_EMULATED_SETUP (type) .type = { .name = #type }
arch/riscv/kernel/traps.c +0 -5
@@ -194,8 +194,3 @@ int is_valid_bugaddr(unsigned long pc) return ((insn & __COMPRESSED_INSN_MASK) == __BUG_INSN_16); }#endif /* CONFIG_GENERIC_BUG */ - -/* stvec & scratch is already set from head.S */ -void trap_init (void ) -{ -}
arch/um/kernel/trap.c +0 -4
@@ -311,7 +311,3 @@ void winch(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs) {do_IRQ (WINCH_IRQ , regs); } - -void trap_init (void ) -{ -}
init/main.c +2 -0
@@ -790,6 +790,8 @@ static inline void initcall_debug_enable(void) }#endif +void __init __weak trap_init (void ) { } +/* Report memory auto-initialization states for this boot. */ static void __init report_meminit (void ) {
Signature · 1 line
2.31.0
Le 14/04/2021 à 10:58, Jisheng Zhang a écrit :
Quoted 4 lines
Many architectures implement the
trap_init()as NOP, since there is no such default fortrap_init(), this empty stub is duplicated among these architectures. Provide a generic but weak NOP implementation to drop the empty stubs oftrap_init()in these architectures.
You define the weak function in the __init section.
Most but not all architectures had it in __init section.
And the remaining ones may not be defined in __init section. For instance look at the one in alpha architecture.
Have you checked that it is not a problem ? It would be good to say something about it in the commit description.
Quoted 22 lines
Signed-off-by Jisheng Zhang <[email protected]>--- arch/arc/kernel/traps.c | 5 ----- arch/arm/kernel/traps.c | 5 ----- arch/h8300/kernel/traps.c | 13 ------------- arch/hexagon/kernel/traps.c | 4 ---- arch/nds32/kernel/traps.c | 5 ----- arch/nios2/kernel/traps.c | 5 ----- arch/openrisc/kernel/traps.c | 5 ----- arch/parisc/kernel/traps.c | 4 ---- arch/powerpc/kernel/traps.c | 5 ----- arch/riscv/kernel/traps.c | 5 ----- arch/um/kernel/trap.c | 4 ---- init/main.c | 2 ++ 12 files changed, 2 insertions(+), 60 deletions(-)init/main.c +0
-0
init/main.c static inline void initcall_debug_enable(void) · line 794
Quoted 5 lines
init/main.c +2
-0@@ -790,6 +790,8 @@ static inline void initcall_debug_enable(void) }#endif +void __init __weak trap_init (void ) { } +
I think in a C file we don't try to save space as much as in a header file.
I would prefer something like:
void __init __weak trap_init(void)
{
}
Quoted 4 lines
init/main.c +0
-0/* Report memory auto-initialization states for this boot. */ static void __init report_meminit (void ) {
Quoted 9 lines · On Wed, 14 Apr 2021 11:10:42 +0200 Christophe Leroy…
Quoted 4 lines · Jisheng Zhang
Many architectures implement the
trap_init()as NOP, since there is no such default fortrap_init(), this empty stub is duplicated among these architectures. Provide a generic but weak NOP implementation to drop the empty stubs oftrap_init()in these architectures.You define the weak function in the
__initsection.
Quoted 7 lines
Most but not all architectures had it in
__initsection.And the remaining ones may not be defined in
__initsection. For instance look at the one in alpha architecture.Have you checked that it is not a problem ? It would be good to say something about it in the commit description.
For those non-nop platforms, I can only test x86/arm64/, but both has __init mark. I'm not sure whether this is a problem for alpha etc. Maybe I can check which section the trap_init() sits. Or to avoid any possible regression, I can add __init mark to those remaining ones without it in preparation patches.
Quoted 27 lines
Quoted 27 lines
Signed-off-by Jisheng Zhang <[email protected]>--- arch/arc/kernel/traps.c | 5 ----- arch/arm/kernel/traps.c | 5 ----- arch/h8300/kernel/traps.c | 13 ------------- arch/hexagon/kernel/traps.c | 4 ---- arch/nds32/kernel/traps.c | 5 ----- arch/nios2/kernel/traps.c | 5 ----- arch/openrisc/kernel/traps.c | 5 ----- arch/parisc/kernel/traps.c | 4 ---- arch/powerpc/kernel/traps.c | 5 ----- arch/riscv/kernel/traps.c | 5 ----- arch/um/kernel/trap.c | 4 ---- init/main.c | 2 ++ 12 files changed, 2 insertions(+), 60 deletions(-)init/main.c +0
-0@@ -790,6 +790,8 @@ static inline void initcall_debug_enable(void) }#endif
Quoted 5 lines
init/main.c static inline void initcall_debug_enable(void) · line 794
Quoted 2 lines
init/main.c +2
-0+void __init __weak trap_init (void ) { } +I think in a C file we don't try to save space as much as in a header file.
This is to follow most weak NOP implementations in init/main.c to make the style unified in the same file. I'm not sure which is better.
Quoted 12 lines
I would prefer something like:
void
__init__weaktrap_init(void)
{
}Quoted 4 lines
init/main.c +0
-0/* Report memory auto-initialization states for this boot. */ static void __init report_meminit (void ) {
Quoted 20 lines · On Wed, 14 Apr 2021 17:27:57 +0800 Jisheng Zhang <[email protected]>…
CAUTION: Email originated externally, do not click links or open attachments unless you recognize the sender and know the content is safe.
Quoted 14 lines · On Wed, 14 Apr 2021 11:10:42 +0200 Christophe Leroy…
Quoted 4 lines · Jisheng Zhang
Many architectures implement the
trap_init()as NOP, since there is no such default fortrap_init(), this empty stub is duplicated among these architectures. Provide a generic but weak NOP implementation to drop the empty stubs oftrap_init()in these architectures.You define the weak function in the
__initsection.Most but not all architectures had it in
__initsection.And the remaining ones may not be defined in
__initsection. For instance look at the one in alpha architecture.
Quoted 9 lines
Quoted 2 lines
Have you checked that it is not a problem ? It would be good to say something about it in the commit description.
For those non-nop platforms, I can only test x86/arm64/, but both has
__initmark. I'm not sure whether this is a problem for alpha etc. Maybe I can check which section thetrap_init()sits. Or to avoid any possible regression, I can add__initmark to those remaining ones without it in preparation patches.
Hi,
I found only three platforms don't have the __init marker for trap_init(), I will add the __init marker in three preparation patches in new version.
thanks
PATCH v2 1/1 init: consolidate trap_init()
In reply to Jisheng ZhangMany architectures implement the trap_init() as NOP, since there is no such default for trap_init(), this empty stub is duplicated among these architectures. Provide a generic but weak NOP implementation to drop the empty stubs of trap_init() in these architectures.
The alpha, microblaze and sparc32 have real trap_init() implementation but the __init marker is missing, so add it to these three platforms.
---
Since v1:
- add __init marker to trap_init() for alpha, microblaze and sparc32
- adjust the generic weak NOP trap_init() location to make it sits with other NOP implementations together
arch/alpha/kernel/traps.c | 2 +- arch/arc/kernel/traps.c | 5 ----- arch/arm/kernel/traps.c | 5 ----- arch/h8300/kernel/traps.c | 13 ------------- arch/hexagon/kernel/traps.c | 4 ---- arch/microblaze/kernel/traps.c | 2 +- arch/nds32/kernel/traps.c | 5 ----- arch/nios2/kernel/traps.c | 5 ----- arch/openrisc/kernel/traps.c | 5 ----- arch/parisc/kernel/traps.c | 4 ---- arch/powerpc/kernel/traps.c | 5 ----- arch/riscv/kernel/traps.c | 5 ----- arch/sparc/kernel/traps_32.c | 2 +- arch/um/kernel/trap.c | 4 ---- init/main.c | 2 ++ 15 files changed, 5 insertions(+), 63 deletions(-)
arch/alpha/kernel/traps.c +1 -1
@@ -973,7 +973,7 @@ do_entUnaUser(void __user * va, unsigned long opcode,return ; } -void +void __init trap_init (void ) {/* Tell PAL-code what global pointer we want in the kernel. */
arch/arc/kernel/traps.c +0 -5
@@ -20,11 +20,6 @@#include <asm/unaligned.h> #include <asm/kprobes.h> -void __init trap_init (void ) -{ -return ; -} -void die (const char *str,struct pt_regs *regs,unsigned long address) {show_kernel_fault_diag (str, regs, address);
arch/arm/kernel/traps.c +0 -5
@@ -780,11 +780,6 @@ void abort(void)panic ("Oops failed to kill thread" ); } -void __init trap_init (void ) -{ -return ; -} -#ifdef CONFIG_KUSER_HELPERS static void __init kuser_init (void *vectors) {
arch/h8300/kernel/traps.c +0 -13
@@ -30,19 +30,6 @@static DEFINE_SPINLOCK (die_lock); -/* -* this must be called very early as the kernel might -* use some instruction that are emulated on the 060 -*/ - -void __init base_trap_init (void ) -{ -} - -void __init trap_init (void ) -{ -} - asmlinkage void set_esp0(unsigned long ssp) { current->thread.esp0 = ssp;
arch/hexagon/kernel/traps.c +0 -4
@@ -28,10 +28,6 @@#define TRAP_SYSCALL 1#define TRAP_DEBUG 0xdb -void __init trap_init (void ) -{ -} -#ifdef CONFIG_GENERIC_BUG /* Maybe should resemble arch/sh/kernel/traps.c ?? */ int is_valid_bugaddr (unsigned long addr)
arch/microblaze/kernel/traps.c +1 -1
@@ -18,7 +18,7 @@#include <asm/exceptions.h> #include <asm/unwind.h> -void trap_init (void ) +void __init trap_init (void ) {__enable_hw_exceptions (); }
arch/nds32/kernel/traps.c +0 -5
@@ -183,11 +183,6 @@ void __pgd_error(const char *file, int line, unsigned long val) }extern char *exception_vector, *exception_vector_end; -void __init trap_init (void ) -{ -return ; -} -void __init early_trap_init (void ) {unsigned long ivb =0 ;
arch/nios2/kernel/traps.c +0 -5
@@ -105,11 +105,6 @@ void show_stack(struct task_struct *task, unsigned long *stack,printk ("%s\n" , loglvl); } -void __init trap_init (void ) -{ -/* Nothing to do here */ -} -/* Breakpoint handler */ asmlinkage void breakpoint_c(struct pt_regs *fp) {
arch/openrisc/kernel/traps.c +0 -5
@@ -231,11 +231,6 @@ void unhandled_exception(struct pt_regs *regs, int ea, int vector)die ("Oops" , regs,9 ); } -void __init trap_init (void ) -{ -/* Nothing needs to be done */ -} - asmlinkage void do_trap(struct pt_regs *regs, unsigned long address) {force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc);
arch/parisc/kernel/traps.c +0 -4
@@ -859,7 +859,3 @@ void __init early_trap_init(void)initialize_ivt (&fault_vector_20); } - -void __init trap_init (void ) -{ -}
arch/powerpc/kernel/traps.c +0 -5
@@ -2207,11 +2207,6 @@ DEFINE_INTERRUPT_HANDLER(kernel_bad_stack)die ("Bad kernel stack pointer" , regs,SIGABRT ); } -void __init trap_init (void ) -{ -} - -#ifdef CONFIG_PPC_EMULATED_STATS #define WARN_EMULATED_SETUP (type) .type = { .name = #type }
arch/riscv/kernel/traps.c +0 -5
@@ -194,8 +194,3 @@ int is_valid_bugaddr(unsigned long pc) return ((insn & __COMPRESSED_INSN_MASK) == __BUG_INSN_16); }#endif /* CONFIG_GENERIC_BUG */ - -/* stvec & scratch is already set from head.S */ -void trap_init (void ) -{ -}
arch/sparc/kernel/traps_32.c +1 -1
@@ -365,7 +365,7 @@ EXPORT_SYMBOL(do_BUG);* up here so that timer interrupts work during initialization. */ -void trap_init (void ) +void __init trap_init (void ) {extern void thread_info_offsets_are_bolixed_pete (void );
arch/um/kernel/trap.c +0 -4
@@ -311,7 +311,3 @@ void winch(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs) {do_IRQ (WINCH_IRQ , regs); } - -void trap_init (void ) -{ -}
init/main.c +2 -0
@@ -779,6 +779,8 @@ void __init __weak poking_init(void) { }void __init __weak pgtable_cache_init (void ) { } +void __init __weak trap_init (void ) { } +bool initcall_debug;core_param (initcall_debug, initcall_debug, bool,0644 );
Signature · 1 line
2.31.0
Quoted 15 lines · Jisheng Zhang
Many architectures implement the
trap_init()as NOP, since there is no such default fortrap_init(), this empty stub is duplicated among these architectures. Provide a generic but weak NOP implementation to drop the empty stubs oftrap_init()in these architectures.The alpha, microblaze and sparc32 have real
trap_init()implementation but the__initmarker is missing, so add it to these three platforms.Signed-off-by Jisheng Zhang <[email protected]>---
Since v1:
- add__initmarker totrap_init()for alpha, microblaze and sparc32
- adjust the generic weak NOPtrap_init()location to make it sits with other NOP implementations together
Quoted 16 lines
arch/alpha/kernel/traps.c | 2 +- arch/arc/kernel/traps.c | 5 ----- arch/arm/kernel/traps.c | 5 ----- arch/h8300/kernel/traps.c | 13 ------------- arch/hexagon/kernel/traps.c | 4 ---- arch/microblaze/kernel/traps.c | 2 +- arch/nds32/kernel/traps.c | 5 ----- arch/nios2/kernel/traps.c | 5 ----- arch/openrisc/kernel/traps.c | 5 ----- arch/parisc/kernel/traps.c | 4 ---- arch/powerpc/kernel/traps.c | 5 ----- arch/riscv/kernel/traps.c | 5 ----- arch/sparc/kernel/traps_32.c | 2 +- arch/um/kernel/trap.c | 4 ---- init/main.c | 2 ++ 15 files changed, 5 insertions(+), 63 deletions(-)
For parisc:
Thanks!
Helge
Quoted 226 lines
arch/alpha/kernel/traps.c +1
-1@@ -973,7 +973,7 @@ do_entUnaUser(void __user * va, unsigned long opcode,return ; } -void +void __init trap_init (void ) {/* Tell PAL-code what global pointer we want in the kernel. */ arch/arc/kernel/traps.c +0
-5@@ -20,11 +20,6 @@#include <asm/unaligned.h> #include <asm/kprobes.h> -void __init trap_init (void ) -{ -return ; -} -void die (const char *str,struct pt_regs *regs,unsigned long address) {show_kernel_fault_diag (str, regs, address);arch/arm/kernel/traps.c +0
-5@@ -780,11 +780,6 @@ void abort(void)panic ("Oops failed to kill thread" ); } -void __init trap_init (void ) -{ -return ; -} -#ifdef CONFIG_KUSER_HELPERS static void __init kuser_init (void *vectors) {arch/h8300/kernel/traps.c +0
-13@@ -30,19 +30,6 @@static DEFINE_SPINLOCK (die_lock); -/* -* this must be called very early as the kernel might -* use some instruction that are emulated on the 060 -*/ - -void __init base_trap_init (void ) -{ -} - -void __init trap_init (void ) -{ -} - asmlinkage void set_esp0(unsigned long ssp) { current->thread.esp0 = ssp;arch/hexagon/kernel/traps.c +0
-4@@ -28,10 +28,6 @@#define TRAP_SYSCALL 1#define TRAP_DEBUG 0xdb -void __init trap_init (void ) -{ -} -#ifdef CONFIG_GENERIC_BUG /* Maybe should resemble arch/sh/kernel/traps.c ?? */ int is_valid_bugaddr (unsigned long addr)arch/microblaze/kernel/traps.c +1
-1@@ -18,7 +18,7 @@#include <asm/exceptions.h> #include <asm/unwind.h> -void trap_init (void ) +void __init trap_init (void ) {__enable_hw_exceptions (); }arch/nds32/kernel/traps.c +0
-5@@ -183,11 +183,6 @@ void __pgd_error(const char *file, int line, unsigned long val) }extern char *exception_vector, *exception_vector_end; -void __init trap_init (void ) -{ -return ; -} -void __init early_trap_init (void ) {unsigned long ivb =0 ;arch/nios2/kernel/traps.c +0
-5@@ -105,11 +105,6 @@ void show_stack(struct task_struct *task, unsigned long *stack,printk ("%s\n" , loglvl); } -void __init trap_init (void ) -{ -/* Nothing to do here */ -} -/* Breakpoint handler */ asmlinkage void breakpoint_c(struct pt_regs *fp) {arch/openrisc/kernel/traps.c +0
-5@@ -231,11 +231,6 @@ void unhandled_exception(struct pt_regs *regs, int ea, int vector)die ("Oops" , regs,9 ); } -void __init trap_init (void ) -{ -/* Nothing needs to be done */ -} - asmlinkage void do_trap(struct pt_regs *regs, unsigned long address) {force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc);arch/parisc/kernel/traps.c +0
-4@@ -859,7 +859,3 @@ void __init early_trap_init(void)initialize_ivt (&fault_vector_20); } - -void __init trap_init (void ) -{ -}arch/powerpc/kernel/traps.c +0
-5@@ -2207,11 +2207,6 @@ DEFINE_INTERRUPT_HANDLER(kernel_bad_stack)die ("Bad kernel stack pointer" , regs,SIGABRT ); } -void __init trap_init (void ) -{ -} - -#ifdef CONFIG_PPC_EMULATED_STATS #define WARN_EMULATED_SETUP (type) .type = { .name = #type }arch/riscv/kernel/traps.c +0
-5@@ -194,8 +194,3 @@ int is_valid_bugaddr(unsigned long pc) return ((insn & __COMPRESSED_INSN_MASK) == __BUG_INSN_16); }#endif /* CONFIG_GENERIC_BUG */ - -/* stvec & scratch is already set from head.S */ -void trap_init (void ) -{ -}arch/sparc/kernel/traps_32.c +1
-1@@ -365,7 +365,7 @@ EXPORT_SYMBOL(do_BUG);* up here so that timer interrupts work during initialization. */ -void trap_init (void ) +void __init trap_init (void ) {extern void thread_info_offsets_are_bolixed_pete (void );arch/um/kernel/trap.c +0
-4@@ -311,7 +311,3 @@ void winch(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs) {do_IRQ (WINCH_IRQ , regs); } - -void trap_init (void ) -{ -}init/main.c +2
-0@@ -779,6 +779,8 @@ void __init __weak poking_init(void) { }void __init __weak pgtable_cache_init (void ) { } +void __init __weak trap_init (void ) { } +bool initcall_debug;core_param (initcall_debug, initcall_debug, bool,0644 );