Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Masahiro Yamada and committed by
Andrew Morton
73db3abd 7a7127aa

+15 -38
-2
arch/powerpc/kernel/vmlinux.lds.S
··· 123 123 */ 124 124 *(.sfpr); 125 125 *(.text.asan.* .text.tsan.*) 126 - MEM_KEEP(init.text) 127 - MEM_KEEP(exit.text) 128 126 } :text 129 127 130 128 . = ALIGN(PAGE_SIZE);
+2 -16
include/asm-generic/vmlinux.lds.h
··· 141 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 144 #ifndef CONFIG_HAVE_DYNAMIC_FTRACE_NO_PATCHABLE 153 145 #define KEEP_PATCHABLE KEEP(*(__patchable_function_entries)) 154 146 #define PATCHABLE_DISCARDS ··· 349 357 *(.data..decrypted) \ 350 358 *(.ref.data) \ 351 359 *(.data..shared_aligned) /* percpu related */ \ 352 - MEM_KEEP(init.data*) \ 353 360 *(.data.unlikely) \ 354 361 __start_once = .; \ 355 362 *(.data.once) \ ··· 533 542 /* __*init sections */ \ 534 543 __init_rodata : AT(ADDR(__init_rodata) - LOAD_OFFSET) { \ 535 544 *(.ref.rodata) \ 536 - MEM_KEEP(init.rodata) \ 537 545 } \ 538 546 \ 539 547 /* Built-in module parameters. */ \ ··· 583 593 *(.text.unknown .text.unknown.*) \ 584 594 NOINSTR_TEXT \ 585 595 *(.ref.text) \ 586 - *(.text.asan.* .text.tsan.*) \ 587 - MEM_KEEP(init.text*) \ 596 + *(.text.asan.* .text.tsan.*) 588 597 589 598 590 599 /* sched.text is aling to function alignment to secure we have same ··· 690 701 #define INIT_DATA \ 691 702 KEEP(*(SORT(___kentry+*))) \ 692 703 *(.init.data .init.data.*) \ 693 - MEM_DISCARD(init.data*) \ 694 704 KERNEL_CTORS() \ 695 705 MCOUNT_REC() \ 696 706 *(.init.rodata .init.rodata.*) \ ··· 697 709 TRACE_SYSCALLS() \ 698 710 KPROBE_BLACKLIST() \ 699 711 ERROR_INJECT_WHITELIST() \ 700 - MEM_DISCARD(init.rodata) \ 701 712 CLK_OF_TABLES() \ 702 713 RESERVEDMEM_OF_TABLES() \ 703 714 TIMER_OF_TABLES() \ ··· 714 727 715 728 #define INIT_TEXT \ 716 729 *(.init.text .init.text.*) \ 717 - *(.text.startup) \ 718 - MEM_DISCARD(init.text*) 730 + *(.text.startup) 719 731 720 732 #define EXIT_DATA \ 721 733 *(.exit.data .exit.data.*) \
+9 -5
include/linux/init.h
··· 84 84 85 85 #define __exit __section(".exit.text") __exitused __cold notrace 86 86 87 - /* Used for MEMORY_HOTPLUG */ 88 - #define __meminit __section(".meminit.text") __cold notrace \ 89 - __latent_entropy 90 - #define __meminitdata __section(".meminit.data") 91 - #define __meminitconst __section(".meminit.rodata") 87 + #ifdef CONFIG_MEMORY_HOTPLUG 88 + #define __meminit 89 + #define __meminitdata 90 + #define __meminitconst 91 + #else 92 + #define __meminit __init 93 + #define __meminitdata __initdata 94 + #define __meminitconst __initconst 95 + #endif 92 96 93 97 /* For assembly routines */ 94 98 #define __HEAD .section ".head.text","ax"
+4 -15
scripts/mod/modpost.c
··· 776 776 777 777 778 778 #define ALL_INIT_DATA_SECTIONS \ 779 - ".init.setup", ".init.rodata", ".meminit.rodata", \ 780 - ".init.data", ".meminit.data" 779 + ".init.setup", ".init.rodata", ".init.data" 781 780 782 781 #define ALL_PCI_INIT_SECTIONS \ 783 782 ".pci_fixup_early", ".pci_fixup_header", ".pci_fixup_final", \ 784 783 ".pci_fixup_enable", ".pci_fixup_resume", \ 785 784 ".pci_fixup_resume_early", ".pci_fixup_suspend" 786 785 787 - #define ALL_XXXINIT_SECTIONS ".meminit.*" 788 - 789 - #define ALL_INIT_SECTIONS INIT_SECTIONS, ALL_XXXINIT_SECTIONS 786 + #define ALL_INIT_SECTIONS ".init.*" 790 787 #define ALL_EXIT_SECTIONS ".exit.*" 791 788 792 789 #define DATA_SECTIONS ".data", ".data.rel" ··· 794 797 ".fixup", ".entry.text", ".exception.text", \ 795 798 ".coldtext", ".softirqentry.text" 796 799 797 - #define INIT_SECTIONS ".init.*" 798 - 799 - #define ALL_TEXT_SECTIONS ".init.text", ".meminit.text", ".exit.text", \ 800 + #define ALL_TEXT_SECTIONS ".init.text", ".exit.text", \ 800 801 TEXT_SECTIONS, OTHER_TEXT_SECTIONS 801 802 802 803 enum mismatch { ··· 834 839 .bad_tosec = { ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS, NULL }, 835 840 .mismatch = TEXTDATA_TO_ANY_INIT_EXIT, 836 841 }, 837 - /* Do not reference init code/data from meminit code/data */ 838 - { 839 - .fromsec = { ALL_XXXINIT_SECTIONS, NULL }, 840 - .bad_tosec = { INIT_SECTIONS, NULL }, 841 - .mismatch = XXXINIT_TO_SOME_INIT, 842 - }, 843 842 /* Do not use exit code/data from init code */ 844 843 { 845 844 .fromsec = { ALL_INIT_SECTIONS, NULL }, ··· 848 859 }, 849 860 { 850 861 .fromsec = { ALL_PCI_INIT_SECTIONS, NULL }, 851 - .bad_tosec = { INIT_SECTIONS, NULL }, 862 + .bad_tosec = { ALL_INIT_SECTIONS, NULL }, 852 863 .mismatch = ANY_INIT_TO_ANY_EXIT, 853 864 }, 854 865 {