mm/memblock: discard .text/.data if CONFIG_ARCH_KEEP_MEMBLOCK not set
Subsystems (5)
PATCH v2 1/1 mm/memblock: discard .text/.data if CONFIG_ARCH_KEEP_MEMBLOCK not set
When CONFIG_ARCH_KEEP_MEMBLOCK not set, we expect to discard related code and data. But it doesn't until CONFIG_MEMORY_HOTPLUG not set neither.
This patch puts memblock's .text/.data into its own section, so that it only depends on CONFIG_ARCH_KEEP_MEMBLOCK to discard related code and data.
After this, from the log message in mem_init_print_info(), init size increase from 2420K to 2432K on arch x86.
---
v2: fix orphan section for powerpc
--- arch/powerpc/kernel/vmlinux.lds.S | 1 + include/asm-generic/vmlinux.lds.h | 14 +++++++++++++- include/linux/memblock.h | 8 ++++---- 3 files changed, 18 insertions(+), 5 deletions(-)
arch/powerpc/kernel/vmlinux.lds.S +1 -0
@@ -125,6 +125,7 @@ SECTIONS *(.text.asan.* .text.tsan.*) MEM_KEEP(init.text) MEM_KEEP(exit.text) + MEMBLOCK_KEEP(init.text) } :text . = ALIGN(PAGE_SIZE);
include/asm-generic/vmlinux.lds.h +13 -1
@@ -147,6 +147,14 @@#define MEM_DISCARD (sec) *(.mem##sec)#endif +#if defined(CONFIG_ARCH_KEEP_MEMBLOCK ) +#define MEMBLOCK_KEEP (sec) *(.mb##sec) +#define MEMBLOCK_DISCARD (sec) +#else +#define MEMBLOCK_KEEP (sec) +#define MEMBLOCK_DISCARD (sec) *(.mb##sec) +#endif +#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_NO_PATCHABLE #define KEEP_PATCHABLE KEEP(*(__patchable_function_entries))#define PATCHABLE_DISCARDS
@@ -356,6 +364,7 @@ *(.ref.data) \ *(.data..shared_aligned) /* percpu related */ \ MEM_KEEP(init.data*) \ + MEMBLOCK_KEEP(init.data*) \ *(.data.unlikely) \ __start_once = .; \ *(.data.once) \
@@ -573,6 +582,7 @@ *(.ref.text) \ *(.text.asan.* .text.tsan.*) \ MEM_KEEP(init.text*) \ + MEMBLOCK_KEEP(init.text*) \ /* sched.text is aling to function alignment to secure we have same
@@ -680,6 +690,7 @@ KEEP(*(SORT(___kentry+*))) \ *(.init.data .init.data.*) \ MEM_DISCARD(init.data*) \ + MEMBLOCK_DISCARD(init.data*) \ KERNEL_CTORS() \ MCOUNT_REC() \ *(.init.rodata .init.rodata.*) \
@@ -706,7 +717,8 @@#define INIT_TEXT \ *(.init.text .init.text.*) \ *(.text.startup) \ - MEM_DISCARD(init.text*) + MEM_DISCARD(init.text*) \ + MEMBLOCK_DISCARD(init.text*)#define EXIT_DATA \ *(.exit.data .exit.data.*) \
include/linux/memblock.h +4 -4
@@ -100,13 +100,13 @@ struct memblock {extern struct memblock memblock; +#define __init_memblock __section(".mbinit.text") __cold notrace \ + __latent_entropy +#define __initdata_memblock __section(".mbinit.data") +#ifndef CONFIG_ARCH_KEEP_MEMBLOCK -#define __init_memblock __meminit -#define __initdata_memblock __meminitdatavoid memblock_discard (void );#else -#define __init_memblock -#define __initdata_memblockstatic inline void memblock_discard (void ) {}#endif
Signature · 1 line
2.34.1
Mike Rapoport
maintainerHi,
Quoted 21 lines · Wei Yang
When
CONFIG_ARCH_KEEP_MEMBLOCKnot set, we expect to discard related code and data. But it doesn't untilCONFIG_MEMORY_HOTPLUGnot set neither.This patch puts memblock's .text/.data into its own section, so that it only depends on
CONFIG_ARCH_KEEP_MEMBLOCKto discard related code and data.After this, from the log message in
mem_init_print_info(), init size increase from 2420K to 2432K on arch x86.Signed-off-by Wei Yang <[email protected]>---
v2: fix orphan section for powerpc--- arch/powerpc/kernel/vmlinux.lds.S | 1 + include/asm-generic/vmlinux.lds.h | 14 +++++++++++++- include/linux/memblock.h | 8 ++++---- 3 files changed, 18 insertions(+), 5 deletions(-)
include/linux/memblock.h struct memblock { · line 106
Quoted 4 lines
include/linux/memblock.h +4
-0+#define __init_memblock __section(".mbinit.text") __cold notrace \ + __latent_entropy +#define __initdata_memblock __section(".mbinit.data") +
The new .mbinit.* sections should be added to scripts/mod/modpost.c alongside .meminit.* sections and then I expect modpost to report a bunch of section mismatches because many memblock functions are called on memory hotplug even on architectures that don't select ARCH_KEEP_MEMBLOCK.
Quoted 14 lines
#ifndef
CONFIG_ARCH_KEEP_MEMBLOCKinclude/linux/memblock.h +0
-4-#define __init_memblock __meminit -#define __initdata_memblock __meminitdatavoid memblock_discard (void );#else -#define __init_memblock -#define __initdata_memblockstatic inline void memblock_discard (void ) {}#endif Signature · 2 lines
-- 2.34.1
Signature · 2 lines
Sincerely yours, Mike.
Quoted 24 lines · Mike Rapoport
Hi,
Quoted 21 lines · Wei Yang
When
CONFIG_ARCH_KEEP_MEMBLOCKnot set, we expect to discard related code and data. But it doesn't untilCONFIG_MEMORY_HOTPLUGnot set neither.This patch puts memblock's .text/.data into its own section, so that it only depends on
CONFIG_ARCH_KEEP_MEMBLOCKto discard related code and data.After this, from the log message in
mem_init_print_info(), init size increase from 2420K to 2432K on arch x86.Signed-off-by Wei Yang <[email protected]>---
v2: fix orphan section for powerpc--- arch/powerpc/kernel/vmlinux.lds.S | 1 + include/asm-generic/vmlinux.lds.h | 14 +++++++++++++- include/linux/memblock.h | 8 ++++---- 3 files changed, 18 insertions(+), 5 deletions(-)
Quoted 10 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+#define __init_memblock __section(".mbinit.text") __cold notrace \ + __latent_entropy +#define __initdata_memblock __section(".mbinit.data") +The new .mbinit.* sections should be added to
scripts/mod/modpost.calongside .meminit.* sections and then I expect modpost to report a bunch of section mismatches because many memblock functions are called on memory hotplug even on architectures that don't selectARCH_KEEP_MEMBLOCK.
I tried to add some code in modpost.c, "make all" looks good.
May I ask how can I trigger the "mismatch" warning?
BTW, if ARCH_KEEP_MEMBLOCK unset, we would discard memblock meta-data. If hotplug would call memblock function, it would be dangerous?
The additional code I used is like below.
--- scripts/mod/modpost.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/mod/modpost.c +3 -3
@@ -777,14 +777,14 @@ static void check_section(const char *modname, struct elf_info *elf,#define ALL_INIT_DATA_SECTIONS \ ".init.setup", ".init.rodata", ".meminit.rodata", \ - ".init.data", ".meminit.data" + ".init.data", ".meminit.data", "mbinit.data"#define ALL_PCI_INIT_SECTIONS \ ".pci_fixup_early", ".pci_fixup_header", ".pci_fixup_final", \ ".pci_fixup_enable", ".pci_fixup_resume", \ ".pci_fixup_resume_early", ".pci_fixup_suspend" -#define ALL_XXXINIT_SECTIONS ".meminit.*" +#define ALL_XXXINIT_SECTIONS ".meminit.*", "mbinit.*"#define ALL_INIT_SECTIONS INIT_SECTIONS, ALL_XXXINIT_SECTIONS#define ALL_EXIT_SECTIONS ".exit.*"
@@ -799,7 +799,7 @@ static void check_section(const char *modname, struct elf_info *elf,#define INIT_SECTIONS ".init.*" -#define ALL_TEXT_SECTIONS ".init.text", ".meminit.text", ".exit.text", \ +#define ALL_TEXT_SECTIONS ".init.text", ".meminit.text", ".mbinit.text", ".exit.text", \ TEXT_SECTIONS, OTHER_TEXT_SECTIONSenum mismatch {
Signature · 1 line
2.34.1
Quoted 18 lines
Quoted 14 lines
#ifndef
CONFIG_ARCH_KEEP_MEMBLOCK(quoted diff) +0
-4-#define __init_memblock __meminit -#define __initdata_memblock __meminitdata void memblock_discard(void); #else -#define __init_memblock -#define __initdata_memblock static inline void memblock_discard(void) {} #endifSignature · 2 lines
-- 2.34.1Signature · 2 lines
Sincerely yours, Mike.
Signature · 2 lines
Wei Yang Help you, Help me
Mike Rapoport
maintainerQuoted 54 lines · Wei Yang
Quoted 24 lines · Mike Rapoport
Hi,
Quoted 21 lines · Wei Yang
When
CONFIG_ARCH_KEEP_MEMBLOCKnot set, we expect to discard related code and data. But it doesn't untilCONFIG_MEMORY_HOTPLUGnot set neither.This patch puts memblock's .text/.data into its own section, so that it only depends on
CONFIG_ARCH_KEEP_MEMBLOCKto discard related code and data.After this, from the log message in
mem_init_print_info(), init size increase from 2420K to 2432K on arch x86.Signed-off-by Wei Yang <[email protected]>---
v2: fix orphan section for powerpc--- arch/powerpc/kernel/vmlinux.lds.S | 1 + include/asm-generic/vmlinux.lds.h | 14 +++++++++++++- include/linux/memblock.h | 8 ++++---- 3 files changed, 18 insertions(+), 5 deletions(-)Quoted 10 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+#define __init_memblock __section(".mbinit.text") __cold notrace \ + __latent_entropy +#define __initdata_memblock __section(".mbinit.data") +The new .mbinit.* sections should be added to
scripts/mod/modpost.calongside .meminit.* sections and then I expect modpost to report a bunch of section mismatches because many memblock functions are called on memory hotplug even on architectures that don't selectARCH_KEEP_MEMBLOCK.I tried to add some code in
modpost.c, "make all" looks good.May I ask how can I trigger the "mismatch" warning?
BTW, if
ARCH_KEEP_MEMBLOCKunset, we would discard memblock meta-data. If hotplug would call memblock function, it would be dangerous?The additional code I used is like below.
--- scripts/mod/modpost.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)scripts/mod/modpost.c +0
-0
scripts/mod/modpost.c static void check_section(const char *modname, struct elf_info *elf, · line 780
Quoted 5 lines
scripts/mod/modpost.c +1
-1@@ -777,14 +777,14 @@ static void check_section(const char *modname, struct elf_info *elf,#define ALL_INIT_DATA_SECTIONS \ ".init.setup", ".init.rodata", ".meminit.rodata", \ - ".init.data", ".meminit.data" + ".init.data", ".meminit.data", "mbinit.data"
should be ".mbinit.data"
scripts/mod/modpost.c static void check_section(const char *modname, struct elf_info *elf, · line 787
Quoted 8 lines
scripts/mod/modpost.c +1
-1#define ALL_PCI_INIT_SECTIONS \ ".pci_fixup_early", ".pci_fixup_header", ".pci_fixup_final", \ ".pci_fixup_enable", ".pci_fixup_resume", \ ".pci_fixup_resume_early", ".pci_fixup_suspend" -#define ALL_XXXINIT_SECTIONS ".meminit.*" +#define ALL_XXXINIT_SECTIONS ".meminit.*", "mbinit.*"
and ".mbinit.*"
But regardless of typos, when ARCH_KEEP_MEMBLOCK=n the .mbinit is equivalent to .init and it should not be referenced from .meminit, so I don't think adding it here is correct.
If I simply alias __init_memblock to __init then with CONFIG_MEMORY_HOTPLUG=y I get
WARNING: modpost: vmlinux: section mismatch in reference: early_pfn_to_nid+0x42 (section: .meminit.text) -> memblock_search_pfn_nid (section: .init.text)
WARNING: modpost: vmlinux: section mismatch in reference: memmap_init_range+0x142 (section: .meminit.text) -> mirrored_kernelcore (section: .init.data)
WARNING: modpost: vmlinux: section mismatch in reference: memmap_init_range+0x1e1 (section: .meminit.text) -> memblock (section: .init.data)
WARNING: modpost: vmlinux: section mismatch in reference: memmap_init_range+0x1e8 (section: .meminit.text) -> memblock (section: .init.data)
WARNING: modpost: vmlinux: section mismatch in reference: sparse_buffer_alloc+0x3b (section: .meminit.text) -> memblock_free (section: .init.text)
Quoted 16 lines
scripts/mod/modpost.c +1
-1#define ALL_INIT_SECTIONS INIT_SECTIONS, ALL_XXXINIT_SECTIONS#define ALL_EXIT_SECTIONS ".exit.*"@@ -799,7 +799,7 @@ static void check_section(const char *modname, struct elf_info *elf,#define INIT_SECTIONS ".init.*" -#define ALL_TEXT_SECTIONS ".init.text", ".meminit.text", ".exit.text", \ +#define ALL_TEXT_SECTIONS ".init.text", ".meminit.text", ".mbinit.text", ".exit.text", \ TEXT_SECTIONS, OTHER_TEXT_SECTIONSenum mismatch {Signature · 3 lines
-- Wei Yang Help you, Help me
Signature · 2 lines
Sincerely yours, Mike.