History

init/modpost: conditionally check section mismatch to __meminit*

This reverts commit eb8f689046b8 ("Use separate sections for __dev/ _cpu/__mem code/data"). Check section mismatch to __meminit* only when CONFIG_MEMORY_HOTPLUG=n. With this change, the linker script and modpost become simpler, and we can get rid of the __ref annotations from the memory hotplug code. [sfr@canb.auug.org.au: remove MEM_KEEP from arch/powerpc/kernel/vmlinux.lds.S] Link: https://lkml.kernel.org/r/20240710093213.2aefb25f@canb.auug.org.au Link: https://lkml.kernel.org/r/20240706160511.2331061-2-masahiroy@kernel.org Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au> Reviewed-by: Wei Yang <richard.weiyang@gmail.com> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Masahiro Yamada committed 2 years ago

Commit 73db3ab1 parent 7a7127a4 files · +15 −38Browse files

Unified · Split

4 files
  1. arch/powerpc/kernel/vmlinux.lds.S +0 −2
  2. include/asm-generic/vmlinux.lds.h +2 −16
  3. include/linux/init.h +9 −5
  4. scripts/mod/modpost.c +4 −15
arch/powerpc/kernel/vmlinux.lds.S+0−2
@@ -123,8 +123,6 @@ SECTIONS · 122 unmodified lines
123 */123 */
124 *(.sfpr);124 *(.sfpr);
125 *(.text.asan.* .text.tsan.*)125 *(.text.asan.* .text.tsan.*)
126 MEM_KEEP(init.text)
127 MEM_KEEP(exit.text)
128 } :text126 } :text
129 127
130 . = ALIGN(PAGE_SIZE);128 . = ALIGN(PAGE_SIZE);
include/asm-generic/vmlinux.lds.h+2−16
@@ -141,14 +141,6 @@ · 140 unmodified lines
141 * often happens at runtime)141 * often happens at runtime)
142 */142 */
143 143
144#if defined(CONFIG_MEMORY_HOTPLUG)
145#define MEM_KEEP(sec) *(.mem##sec)
146#define MEM_DISCARD(sec)
147#else
148#define MEM_KEEP(sec)
149#define MEM_DISCARD(sec) *(.mem##sec)
150#endif
151
152#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_NO_PATCHABLE144#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_NO_PATCHABLE
153#define KEEP_PATCHABLE KEEP(*(__patchable_function_entries))145#define KEEP_PATCHABLE KEEP(*(__patchable_function_entries))
154#define PATCHABLE_DISCARDS146#define PATCHABLE_DISCARDS
@@ -357,7 +349,6 @@ · 202 unmodified lines
357 *(.data..decrypted) \349 *(.data..decrypted) \
358 *(.ref.data) \350 *(.ref.data) \
359 *(.data..shared_aligned) /* percpu related */ \351 *(.data..shared_aligned) /* percpu related */ \
360 MEM_KEEP(init.data*) \
361 *(.data.unlikely) \352 *(.data.unlikely) \
362 __start_once = .; \353 __start_once = .; \
363 *(.data.once) \354 *(.data.once) \
@@ -542,7 +533,6 @@ · 178 unmodified lines
542 /* __*init sections */ \533 /* __*init sections */ \
543 __init_rodata : AT(ADDR(__init_rodata) - LOAD_OFFSET) { \534 __init_rodata : AT(ADDR(__init_rodata) - LOAD_OFFSET) { \
544 *(.ref.rodata) \535 *(.ref.rodata) \
545 MEM_KEEP(init.rodata) \
546 } \536 } \
547 \537 \
548 /* Built-in module parameters. */ \538 /* Built-in module parameters. */ \
@@ -593,8 +583,7 @@ · 44 unmodified lines
593 *(.text.unknown .text.unknown.*) \583 *(.text.unknown .text.unknown.*) \
594 NOINSTR_TEXT \584 NOINSTR_TEXT \
595 *(.ref.text) \585 *(.ref.text) \
596 *(.text.asan.* .text.tsan.*) \586 *(.text.asan.* .text.tsan.*)
597 MEM_KEEP(init.text*) \
598 587
599 588
600/* sched.text is aling to function alignment to secure we have same589/* sched.text is aling to function alignment to secure we have same
@@ -701,7 +690,6 @@ · 100 unmodified lines
701#define INIT_DATA \690#define INIT_DATA \
702 KEEP(*(SORT(___kentry+*))) \691 KEEP(*(SORT(___kentry+*))) \
703 *(.init.data .init.data.*) \692 *(.init.data .init.data.*) \
704 MEM_DISCARD(init.data*) \
705 KERNEL_CTORS() \693 KERNEL_CTORS() \
706 MCOUNT_REC() \694 MCOUNT_REC() \
707 *(.init.rodata .init.rodata.*) \695 *(.init.rodata .init.rodata.*) \
@@ -709,7 +697,6 @@ · 1 unmodified line
709 TRACE_SYSCALLS() \697 TRACE_SYSCALLS() \
710 KPROBE_BLACKLIST() \698 KPROBE_BLACKLIST() \
711 ERROR_INJECT_WHITELIST() \699 ERROR_INJECT_WHITELIST() \
712 MEM_DISCARD(init.rodata) \
713 CLK_OF_TABLES() \700 CLK_OF_TABLES() \
714 RESERVEDMEM_OF_TABLES() \701 RESERVEDMEM_OF_TABLES() \
715 TIMER_OF_TABLES() \702 TIMER_OF_TABLES() \
@@ -727,8 +714,7 @@ · 11 unmodified lines
727 714
728#define INIT_TEXT \715#define INIT_TEXT \
729 *(.init.text .init.text.*) \716 *(.init.text .init.text.*) \
730 *(.text.startup) \717 *(.text.startup)
731 MEM_DISCARD(init.text*)
732 718
733#define EXIT_DATA \719#define EXIT_DATA \
734 *(.exit.data .exit.data.*) \720 *(.exit.data .exit.data.*) \
include/linux/init.h+9−5
@@ -84,11 +84,15 @@ · 83 unmodified lines
84 84
85#define __exit __section(".exit.text") __exitused __cold notrace85#define __exit __section(".exit.text") __exitused __cold notrace
86 86
87/* Used for MEMORY_HOTPLUG */87#ifdef CONFIG_MEMORY_HOTPLUG
88#define __meminit __section(".meminit.text") __cold notrace \88#define __meminit
89 __latent_entropy89#define __meminitdata
90#define __meminitdata __section(".meminit.data")90#define __meminitconst
91#define __meminitconst __section(".meminit.rodata")91#else
92#define __meminit __init
93#define __meminitdata __initdata
94#define __meminitconst __initconst
95#endif
92 96
93/* For assembly routines */97/* For assembly routines */
94#define __HEAD .section ".head.text","ax"98#define __HEAD .section ".head.text","ax"
scripts/mod/modpost.c+4−15
@@ -776,17 +776,14 @@ static void check_section(const char *modname, struct elf_info *elf, · 775 unmodified lines
776 776
777 777
778#define ALL_INIT_DATA_SECTIONS \778#define ALL_INIT_DATA_SECTIONS \
779 ".init.setup", ".init.rodata", ".meminit.rodata", \779 ".init.setup", ".init.rodata", ".init.data"
780 ".init.data", ".meminit.data"
781 780
782#define ALL_PCI_INIT_SECTIONS \781#define ALL_PCI_INIT_SECTIONS \
783 ".pci_fixup_early", ".pci_fixup_header", ".pci_fixup_final", \782 ".pci_fixup_early", ".pci_fixup_header", ".pci_fixup_final", \
784 ".pci_fixup_enable", ".pci_fixup_resume", \783 ".pci_fixup_enable", ".pci_fixup_resume", \
785 ".pci_fixup_resume_early", ".pci_fixup_suspend"784 ".pci_fixup_resume_early", ".pci_fixup_suspend"
786 785
787#define ALL_XXXINIT_SECTIONS ".meminit.*"786#define ALL_INIT_SECTIONS ".init.*"
788
789#define ALL_INIT_SECTIONS INIT_SECTIONS, ALL_XXXINIT_SECTIONS
790#define ALL_EXIT_SECTIONS ".exit.*"787#define ALL_EXIT_SECTIONS ".exit.*"
791 788
792#define DATA_SECTIONS ".data", ".data.rel"789#define DATA_SECTIONS ".data", ".data.rel"
@@ -797,9 +794,7 @@ static void check_section(const char *modname, struct elf_info *elf, · 4 unmodified lines
797 ".fixup", ".entry.text", ".exception.text", \794 ".fixup", ".entry.text", ".exception.text", \
798 ".coldtext", ".softirqentry.text"795 ".coldtext", ".softirqentry.text"
799 796
800#define INIT_SECTIONS ".init.*"797#define ALL_TEXT_SECTIONS ".init.text", ".exit.text", \
801
802#define ALL_TEXT_SECTIONS ".init.text", ".meminit.text", ".exit.text", \
803 TEXT_SECTIONS, OTHER_TEXT_SECTIONS798 TEXT_SECTIONS, OTHER_TEXT_SECTIONS
804 799
805enum mismatch {800enum mismatch {
@@ -839,12 +834,6 @@ static const struct sectioncheck sectioncheck[] = { · 33 unmodified lines
839 .bad_tosec = { ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS, NULL },834 .bad_tosec = { ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS, NULL },
840 .mismatch = TEXTDATA_TO_ANY_INIT_EXIT,835 .mismatch = TEXTDATA_TO_ANY_INIT_EXIT,
841},836},
842/* Do not reference init code/data from meminit code/data */
843{
844 .fromsec = { ALL_XXXINIT_SECTIONS, NULL },
845 .bad_tosec = { INIT_SECTIONS, NULL },
846 .mismatch = XXXINIT_TO_SOME_INIT,
847},
848/* Do not use exit code/data from init code */837/* Do not use exit code/data from init code */
849{838{
850 .fromsec = { ALL_INIT_SECTIONS, NULL },839 .fromsec = { ALL_INIT_SECTIONS, NULL },
@@ -859,7 +848,7 @@ static const struct sectioncheck sectioncheck[] = { · 8 unmodified lines
859},848},
860{849{
861 .fromsec = { ALL_PCI_INIT_SECTIONS, NULL },850 .fromsec = { ALL_PCI_INIT_SECTIONS, NULL },
862 .bad_tosec = { INIT_SECTIONS, NULL },851 .bad_tosec = { ALL_INIT_SECTIONS, NULL },
863 .mismatch = ANY_INIT_TO_ANY_EXIT,852 .mismatch = ANY_INIT_TO_ANY_EXIT,
864},853},
865{854{