Skip to contentSkip to conversation

module: replace module_layout with module_memory

PATCH Superseded Song Liu 3 participants 8 messages Jan 25, 2023 – Jan 27, 2023

Subsystems (10)
Arm (32-bit) PowerPC MIPS arm64 +6 more subsystems

v2 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Song Liu

author
#0 lore raw

PATCH v2 1/1 module: replace module_layout with module_memory

module_layout manages different types of memory (text, data, rodata, etc.) in one allocation, which is problematic for some reasons:

1. It is hard to enable CONFIG_STRICT_MODULE_RWX.
2. It is hard to use huge pages in modules (and not break strict rwx).
3. Many archs uses module_layout for arch-specific data, but it is not obvious how these data are used (are they RO, RX, or RW?)

Improve the scenario by replacing 2 (or 3) module_layout per module with up to 7 module_memory per module:

MOD_MEM_TYPE_TEXT,
MOD_MEM_TYPE_DATA,
MOD_MEM_TYPE_RODATA,
MOD_MEM_TYPE_RO_AFTER_INIT,
MOD_MEM_TYPE_INIT_TEXT,
MOD_MEM_TYPE_INIT_DATA,
MOD_MEM_TYPE_INIT_RODATA,

and allocating them separately.

Various archs use module_layout for different data. These data are put into different module_memory based on their location in module_layout. IOW, data that used to go with text is allocated with MOD_MEM_TYPE_TEXT; data that used to go with data is allocated with MOD_MEM_TYPE_DATA, etc.

Cc Luis Chamberlain <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>

---

This is the preparation work for the type aware module_alloc() discussed in [1]. While this work is not covered much in the discussion, it is a critical step of the effort.

As this part grows pretty big (~1000 lines, + and -), I would like get some feedback on it, so that I know it is on the right track.

Please share your comments. Thanks!

Test coverage: Tested on x86_64.
Build tested by kernel test bot in [2]. The only regression in [2] was a typo in parisc, which is also fixed.

[1] https://lore.kernel.org/linux-mm/[email protected]/T/#u
[2] https://lore.kernel.org/linux-raid/63b8827e.clJQX2wg+I+tiX7m%[email protected]/T/#u

Changes v1 => v2:
1. Add data_addr_[min|max] for CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC case.

---
 arch/alpha/kernel/module.c      |   3 +-
 arch/arc/kernel/unwind.c        |   9 +-
 arch/arm/kernel/module-plts.c   |   5 +-
 arch/arm64/kernel/module-plts.c |   5 +-
 arch/ia64/kernel/module.c       |  31 ++-
 arch/mips/kernel/vpe.c          |  11 +-
 arch/parisc/kernel/module.c     |  53 +++--
 arch/powerpc/kernel/module_32.c |  10 +-
 arch/s390/kernel/module.c       |  30 +--
 include/linux/module.h          |  65 +++---
 kernel/module/internal.h        |  34 ++-
 kernel/module/kallsyms.c        |  54 +++--
 kernel/module/kdb.c             |  17 +-
 kernel/module/main.c            | 389 +++++++++++++++++++-------------
 kernel/module/procfs.c          |  17 +-
 kernel/module/strict_rwx.c      | 113 +++-------
 kernel/module/tree_lookup.c     |  43 ++--
 17 files changed, 484 insertions(+), 405 deletions(-)
arch/alpha/kernel/module.c +2 -1
index 5b60c248de9e..905af4e8d835 100644
@@ -148,7 +148,8 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
 
 	/* The small sections were sorted to the end of the segment.
 	   The following should definitely cover them.  */
-	gp = (u64)me->core_layout.base + me->core_layout.size - 0x8000;
+	gp = (u64)me->mod_mem[MOD_MEM_TYPE_DATA].base +
+		me->mod_mem[MOD_MEM_TYPE_DATA].size - 0x8000;
 	got = sechdrs[me->arch.gotsecindex].sh_addr;
 
 	for (i = 0; i < n; i++) {
arch/arc/kernel/unwind.c +7 -2
index 200270a94558..2c55f6215f79 100644
@@ -369,6 +369,8 @@ void *unwind_add_table(struct module *module, const void *table_start,
 		       unsigned long table_size)
 {
 	struct unwind_table *table;
+	struct module_memory *mod_mem_core_text;
+	struct module_memory *mod_mem_init_text;
 
 	if (table_size <= 0)
 		return NULL;
@@ -377,9 +379,12 @@ void *unwind_add_table(struct module *module, const void *table_start,
 	if (!table)
 		return NULL;
 
+	mod_mem_core_text = &module->mod_mem[MOD_MEM_TYPE_TEXT];
+	mod_mem_init_text = &module->mod_mem[MOD_MEM_TYPE_INIT_TEXT];
+
 	init_unwind_table(table, module->name,
-			  module->core_layout.base, module->core_layout.size,
-			  module->init_layout.base, module->init_layout.size,
+			  mod_mem_core_text->base, mod_mem_core_text->size,
+			  mod_mem_init_text->base, mod_mem_init_text->size,
 			  table_start, table_size,
 			  NULL, 0);
 
arch/arm/kernel/module-plts.c +4 -1
index 1fc309b41f94..e68a1da41206 100644
@@ -30,7 +30,10 @@ static const u32 fixed_plts[] = {
 
 static bool in_init(const struct module *mod, unsigned long loc)
 {
-	return loc - (u32)mod->init_layout.base < mod->init_layout.size;
+	const struct module_memory *mod_mem;
+
+	mod_mem = &mod->mod_mem[MOD_MEM_TYPE_INIT_TEXT];
+	return loc - (u32)mod_mem->base < mod_mem->size;
 }
 
 static void prealloc_fixed(struct mod_plt_sec *pltsec, struct plt_entries *plt)
arch/arm64/kernel/module-plts.c +4 -1
index 5a0a8f552a61..2f1ca5e2294b 100644
@@ -67,7 +67,10 @@ static bool plt_entries_equal(const struct plt_entry *a,
 
 static bool in_init(const struct module *mod, void *loc)
 {
-	return (u64)loc - (u64)mod->init_layout.base < mod->init_layout.size;
+	const struct module_memory *mod_mem;
+
+	mod_mem = &mod->mod_mem[MOD_MEM_TYPE_INIT_TEXT];
+	return (u64)loc - (u64)mod_mem->base < mod_mem->size;
 }
 
 u64 module_emit_plt_entry(struct module *mod, Elf64_Shdr *sechdrs,
arch/ia64/kernel/module.c +21 -10
index 8f62cf97f691..966a8997424d 100644
@@ -485,19 +485,25 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
 	return 0;
 }
 
-static inline int
+static inline bool
 in_init (const struct module *mod, uint64_t addr)
 {
-	return addr - (uint64_t) mod->init_layout.base < mod->init_layout.size;
+	const struct module_memory *mod_mem;
+
+	mod_mem = &mod->mod_mem[MOD_MEM_TYPE_INIT_TEXT];
+	return addr - (uint64_t)mod_mem->base < mod_mem->size;
 }
 
-static inline int
+static inline bool
 in_core (const struct module *mod, uint64_t addr)
 {
-	return addr - (uint64_t) mod->core_layout.base < mod->core_layout.size;
+	const struct module_memory *mod_mem;
+
+	mod_mem = &mod->mod_mem[MOD_MEM_TYPE_TEXT];
+	return addr - (uint64_t)mod_mem->base < mod_mem->size;
 }
 
-static inline int
+static inline bool
 is_internal (const struct module *mod, uint64_t value)
 {
 	return in_init(mod, value) || in_core(mod, value);
@@ -677,7 +683,9 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
 		break;
 
 	      case RV_BDREL:
-		val -= (uint64_t) (in_init(mod, val) ? mod->init_layout.base : mod->core_layout.base);
+		val -= (uint64_t) (in_init(mod, val) ?
+				   mod->mod_mem[MOD_MEM_TYPE_INIT_TEXT].base :
+				   mod->mod_mem[MOD_MEM_TYPE_TEXT].base);
 		break;
 
 	      case RV_LTV:
@@ -812,15 +820,18 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
 		 *     addresses have been selected...
 		 */
 		uint64_t gp;
-		if (mod->core_layout.size > MAX_LTOFF)
+		struct module_memory *mod_mem;
+
+		mod_mem = &mod->mod_mem[MOD_MEM_TYPE_DATA];
+		if (mod_mem->size > MAX_LTOFF)
 			/*
 			 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
 			 * at the end of the module.
 			 */
-			gp = mod->core_layout.size - MAX_LTOFF / 2;
+			gp = mod_mem->size - MAX_LTOFF / 2;
 		else
-			gp = mod->core_layout.size / 2;
-		gp = (uint64_t) mod->core_layout.base + ((gp + 7) & -8);
+			gp = mod_mem->size / 2;
+		gp = (uint64_t) mod_mem->base + ((gp + 7) & -8);
 		mod->arch.gp = gp;
 		DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
 	}
arch/mips/kernel/vpe.c +5 -6
index 13294972707b..b13363a1f6a3 100644
@@ -199,18 +199,17 @@ static void layout_sections(struct module *mod, const Elf_Ehdr *hdr,
 	for (m = 0; m < ARRAY_SIZE(masks); ++m) {
 		for (i = 0; i < hdr->e_shnum; ++i) {
 			Elf_Shdr *s = &sechdrs[i];
+			struct module_memory *mod_mem;
+
+			mod_mem = &mod->mod_mem[MOD_MEM_TYPE_TEXT];
 
 			if ((s->sh_flags & masks[m][0]) != masks[m][0]
 			    || (s->sh_flags & masks[m][1])
 			    || s->sh_entsize != ~0UL)
 				continue;
 			s->sh_entsize =
-				get_offset((unsigned long *)&mod->core_layout.size, s);
+				get_offset((unsigned long *)&mod_mem->size, s);
 		}
-
-		if (m == 0)
-			mod->core_layout.text_size = mod->core_layout.size;
-
 	}
 }
 
@@ -641,7 +640,7 @@ static int vpe_elfload(struct vpe *v)
 		layout_sections(&mod, hdr, sechdrs, secstrings);
 	}
 
-	v->load_addr = alloc_progmem(mod.core_layout.size);
+	v->load_addr = alloc_progmem(mod.mod_mem[MOD_MEM_TYPE_TEXT].size);
 	if (!v->load_addr)
 		return -ENOMEM;
 
arch/parisc/kernel/module.c +26 -27

113 lines not on this page · raw message

arch/powerpc/kernel/module_32.c +6 -4
index ea6536171778..1496551c9e9e 100644
@@ -160,11 +160,13 @@ static uint32_t do_plt_call(void *location,
 			    struct module *mod)
 {
 	struct ppc_plt_entry *entry;
+	struct module_memory *mod_mem;
 
 	pr_debug("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
+
+	mod_mem = &mod->mod_mem[MOD_MEM_TYPE_TEXT];
 	/* Init, or core PLT? */
-	if (location >= mod->core_layout.base
-	    && location < mod->core_layout.base + mod->core_layout.size)
+	if (location >= mod_mem->base && location < mod_mem->base + mod_mem->size)
 		entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
 	else
 		entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
@@ -322,14 +324,14 @@ notrace int module_trampoline_target(struct module *mod, unsigned long addr,
 
 int module_finalize_ftrace(struct module *module, const Elf_Shdr *sechdrs)
 {
-	module->arch.tramp = do_plt_call(module->core_layout.base,
+	module->arch.tramp = do_plt_call(module->mod_mem[MOD_MEM_TYPE_TEXT].base,
 					 (unsigned long)ftrace_caller,
 					 sechdrs, module);
 	if (!module->arch.tramp)
 		return -ENOENT;
 
 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
-	module->arch.tramp_regs = do_plt_call(module->core_layout.base,
+	module->arch.tramp_regs = do_plt_call(module->mod_mem[MOD_MEM_TYPE_TEXT].base,
 					      (unsigned long)ftrace_regs_caller,
 					      sechdrs, module);
 	if (!module->arch.tramp_regs)
arch/s390/kernel/module.c +16 -14
index 2d159b32885b..5f9c45fa2ffd 100644
@@ -108,7 +108,7 @@ static void check_rela(Elf_Rela *rela, struct module *me)
 	case R_390_GLOB_DAT:
 	case R_390_JMP_SLOT:
 	case R_390_RELATIVE:
-		/* Only needed if we want to support loading of 
+		/* Only needed if we want to support loading of
 		   modules linked with -shared. */
 		break;
 	}
@@ -126,6 +126,7 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
 	Elf_Rela *rela;
 	char *strings;
 	int nrela, i, j;
+	struct module_memory *mod_mem;
 
 	/* Find symbol table and string table. */
 	symtab = NULL;
@@ -173,14 +174,15 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
 
 	/* Increase core size by size of got & plt and set start
 	   offsets for got and plt. */
-	me->core_layout.size = ALIGN(me->core_layout.size, 4);
-	me->arch.got_offset = me->core_layout.size;
-	me->core_layout.size += me->arch.got_size;
-	me->arch.plt_offset = me->core_layout.size;
+	mod_mem = &me->mod_mem[MOD_MEM_TYPE_TEXT];
+	mod_mem->size = ALIGN(mod_mem->size, 4);
+	me->arch.got_offset = mod_mem->size;
+	mod_mem->size += me->arch.got_size;
+	me->arch.plt_offset = mod_mem->size;
 	if (me->arch.plt_size) {
 		if (IS_ENABLED(CONFIG_EXPOLINE) && !nospec_disable)
 			me->arch.plt_size += PLT_ENTRY_SIZE;
-		me->core_layout.size += me->arch.plt_size;
+		mod_mem->size += me->arch.plt_size;
 	}
 	return 0;
 }
@@ -304,7 +306,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
 	case R_390_GOTPLT64:	/* 64 bit offset to jump slot.	*/
 	case R_390_GOTPLTENT:	/* 32 bit rel. offset to jump slot >> 1. */
 		if (info->got_initialized == 0) {
-			Elf_Addr *gotent = me->core_layout.base +
+			Elf_Addr *gotent = me->mod_mem[MOD_MEM_TYPE_TEXT].base +
 					   me->arch.got_offset +
 					   info->got_offset;
 
@@ -329,7 +331,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
 			rc = apply_rela_bits(loc, val, 0, 64, 0, write);
 		else if (r_type == R_390_GOTENT ||
 			 r_type == R_390_GOTPLTENT) {
-			val += (Elf_Addr) me->core_layout.base - loc;
+			val += (Elf_Addr) me->mod_mem[MOD_MEM_TYPE_TEXT].base - loc;
 			rc = apply_rela_bits(loc, val, 1, 32, 1, write);
 		}
 		break;
@@ -345,7 +347,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
 			char *plt_base;
 			char *ip;
 
-			plt_base = me->core_layout.base + me->arch.plt_offset;
+			plt_base = me->mod_mem[MOD_MEM_TYPE_TEXT].base + me->arch.plt_offset;
 			ip = plt_base + info->plt_offset;
 			*(int *)insn = 0x0d10e310;	/* basr 1,0  */
 			*(int *)&insn[4] = 0x100c0004;	/* lg	1,12(1) */
@@ -375,7 +377,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
 			       val - loc + 0xffffUL < 0x1ffffeUL) ||
 			      (r_type == R_390_PLT32DBL &&
 			       val - loc + 0xffffffffULL < 0x1fffffffeULL)))
-				val = (Elf_Addr) me->core_layout.base +
+				val = (Elf_Addr) me->mod_mem[MOD_MEM_TYPE_TEXT].base +
 					me->arch.plt_offset +
 					info->plt_offset;
 			val += rela->r_addend - loc;
@@ -397,7 +399,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
 	case R_390_GOTOFF32:	/* 32 bit offset to GOT.  */
 	case R_390_GOTOFF64:	/* 64 bit offset to GOT. */
 		val = val + rela->r_addend -
-			((Elf_Addr) me->core_layout.base + me->arch.got_offset);
+			((Elf_Addr) me->mod_mem[MOD_MEM_TYPE_TEXT].base + me->arch.got_offset);
 		if (r_type == R_390_GOTOFF16)
 			rc = apply_rela_bits(loc, val, 0, 16, 0, write);
 		else if (r_type == R_390_GOTOFF32)
@@ -407,7 +409,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
 		break;
 	case R_390_GOTPC:	/* 32 bit PC relative offset to GOT. */
 	case R_390_GOTPCDBL:	/* 32 bit PC rel. off. to GOT shifted by 1. */
-		val = (Elf_Addr) me->core_layout.base + me->arch.got_offset +
+		val = (Elf_Addr) me->mod_mem[MOD_MEM_TYPE_TEXT].base + me->arch.got_offset +
 			rela->r_addend - loc;
 		if (r_type == R_390_GOTPC)
 			rc = apply_rela_bits(loc, val, 1, 32, 0, write);
@@ -418,7 +420,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
 	case R_390_GLOB_DAT:	/* Create GOT entry.  */
 	case R_390_JMP_SLOT:	/* Create PLT entry.  */
 	case R_390_RELATIVE:	/* Adjust by program base.  */
-		/* Only needed if we want to support loading of 
+		/* Only needed if we want to support loading of
 		   modules linked with -shared. */
 		return -ENOEXEC;
 	default:
@@ -515,7 +517,7 @@ int module_finalize(const Elf_Ehdr *hdr,
 	    !nospec_disable && me->arch.plt_size) {
 		unsigned int *ij;
 
-		ij = me->core_layout.base + me->arch.plt_offset +
+		ij = me->mod_mem[MOD_MEM_TYPE_TEXT].base + me->arch.plt_offset +
 			me->arch.plt_size - PLT_ENTRY_SIZE;
 		ij[0] = 0xc6000000;	/* exrl	%r0,.+10	*/
 		ij[1] = 0x0005a7f4;	/* j	.		*/
include/linux/module.h +39 -26

100 lines not on this page · raw message

kernel/module/internal.h +16 -18
index 2e2bf236f558..d31f28b0a973 100644
@@ -22,22 +22,17 @@
 /* Maximum number of characters written by module_flags() */
 #define MODULE_FLAGS_BUF_SIZE (TAINT_FLAGS_COUNT + 4)
 
-#ifndef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC
-#define	data_layout core_layout
-#endif
+#define for_each_mod_mem_type(type)	\
+	for ((type) = MOD_MEM_TYPE_TEXT;	\
+	     (type) < MOD_MEM_NUM_TYPES; (type)++)
 
-/*
- * Modules' sections will be aligned on page boundaries
- * to ensure complete separation of code and data, but
- * only when CONFIG_STRICT_MODULE_RWX=y
- */
-static inline unsigned int strict_align(unsigned int size)
-{
-	if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX))
-		return PAGE_ALIGN(size);
-	else
-		return size;
-}
+#define for_core_mod_mem_type(type)		\
+	for ((type) = MOD_MEM_TYPE_TEXT;		\
+	     (type) < MOD_MEM_TYPE_INIT_TEXT; (type)++)
+
+#define for_init_mod_mem_type(type)		\
+	for ((type) = MOD_MEM_TYPE_INIT_TEXT;		\
+	     (type) < MOD_MEM_NUM_TYPES; (type)++)
 
 extern struct mutex module_mutex;
 extern struct list_head modules;
@@ -101,8 +96,8 @@ int try_to_force_load(struct module *mod, const char *reason);
 bool find_symbol(struct find_symbol_arg *fsa);
 struct module *find_module_all(const char *name, size_t len, bool even_unformed);
 int cmp_name(const void *name, const void *sym);
-long module_get_offset(struct module *mod, unsigned int *size, Elf_Shdr *sechdr,
-		       unsigned int section);
+long module_get_offset_and_type(struct module *mod, enum mod_mem_type type,
+				Elf_Shdr *sechdr, unsigned int section);
 char *module_flags(struct module *mod, char *buf, bool show_state);
 size_t module_flags_taint(unsigned long taints, char *buf);
 
@@ -190,10 +185,13 @@ struct mod_tree_root {
 #endif
 	unsigned long addr_min;
 	unsigned long addr_max;
+#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC
+	unsigned long data_addr_min;
+	unsigned long data_addr_max;
+#endif
 };
 
 extern struct mod_tree_root mod_tree;
-extern struct mod_tree_root mod_data_tree;
 
 #ifdef CONFIG_MODULES_TREE_LOOKUP
 void mod_tree_insert(struct module *mod);
kernel/module/kallsyms.c +30 -24

105 lines not on this page · raw message

kernel/module/kdb.c +9 -8
index f4317f92e189..33f595454488 100644
@@ -26,10 +26,11 @@ int kdb_lsmod(int argc, const char **argv)
 		if (mod->state == MODULE_STATE_UNFORMED)
 			continue;
 
-		kdb_printf("%-20s%8u", mod->name, mod->core_layout.size);
-#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC
-		kdb_printf("/%8u", mod->data_layout.size);
-#endif
+		kdb_printf("%-20s%8u", mod->name, mod->mod_mem[MOD_MEM_TYPE_TEXT].size);
+		kdb_printf("/%8u", mod->mod_mem[MOD_MEM_TYPE_RODATA].size);
+		kdb_printf("/%8u", mod->mod_mem[MOD_MEM_TYPE_RO_AFTER_INIT].size);
+		kdb_printf("/%8u", mod->mod_mem[MOD_MEM_TYPE_DATA].size);
+
 		kdb_printf("  0x%px ", (void *)mod);
 #ifdef CONFIG_MODULE_UNLOAD
 		kdb_printf("%4d ", module_refcount(mod));
@@ -40,10 +41,10 @@ int kdb_lsmod(int argc, const char **argv)
 			kdb_printf(" (Loading)");
 		else
 			kdb_printf(" (Live)");
-		kdb_printf(" 0x%px", mod->core_layout.base);
-#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC
-		kdb_printf("/0x%px", mod->data_layout.base);
-#endif
+		kdb_printf(" 0x%px", mod->mod_mem[MOD_MEM_TYPE_TEXT].base);
+		kdb_printf("/0x%px", mod->mod_mem[MOD_MEM_TYPE_RODATA].base);
+		kdb_printf("/0x%px", mod->mod_mem[MOD_MEM_TYPE_RO_AFTER_INIT].base);
+		kdb_printf("/0x%px", mod->mod_mem[MOD_MEM_TYPE_DATA].base);
 
 #ifdef CONFIG_MODULE_UNLOAD
 		{
kernel/module/main.c +230 -159

609 lines not on this page · raw message

kernel/module/procfs.c +12 -5
index cf5b9f1e6ec4..1fce4209aeb2 100644
@@ -62,6 +62,16 @@ static void m_stop(struct seq_file *m, void *p)
 	mutex_unlock(&module_mutex);
 }
 
+static unsigned int module_total_size(struct module *mod)
+{
+	int size = 0;
+	enum mod_mem_type type;
+
+	for_each_mod_mem_type(type)
+		size += mod->mod_mem[type].size;
+	return size;
+}
+
 static int m_show(struct seq_file *m, void *p)
 {
 	struct module *mod = list_entry(p, struct module, list);
@@ -73,10 +83,7 @@ static int m_show(struct seq_file *m, void *p)
 	if (mod->state == MODULE_STATE_UNFORMED)
 		return 0;
 
-	size = mod->init_layout.size + mod->core_layout.size;
-#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC
-	size += mod->data_layout.size;
-#endif
+	size = module_total_size(mod);
 	seq_printf(m, "%s %u", mod->name, size);
 	print_unload_info(m, mod);
 
@@ -86,7 +93,7 @@ static int m_show(struct seq_file *m, void *p)
 		   mod->state == MODULE_STATE_COMING ? "Loading" :
 		   "Live");
 	/* Used by oprofile and other similar tools. */
-	value = m->private ? NULL : mod->core_layout.base;
+	value = m->private ? NULL : mod->mod_mem[MOD_MEM_TYPE_TEXT].base;
 	seq_printf(m, " 0x%px", value);
 
 	/* Taints info */
kernel/module/strict_rwx.c +35 -78

145 lines not on this page · raw message

kernel/module/tree_lookup.c +22 -21

70 lines not on this page · raw message

Signature · 1 line
2.30.2
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 19 lines · Song Liu

module_layout manages different types of memory (text, data, rodata, etc.) in one allocation, which is problematic for some reasons:

1. It is hard to enable CONFIG_STRICT_MODULE_RWX.
2. It is hard to use huge pages in modules (and not break strict rwx).
3. Many archs uses module_layout for arch-specific data, but it is not obvious how these data are used (are they RO, RX, or RW?)

Improve the scenario by replacing 2 (or 3) module_layout per module with up to 7 module_memory per module:

MOD_MEM_TYPE_TEXT,
MOD_MEM_TYPE_DATA,
MOD_MEM_TYPE_RODATA,
MOD_MEM_TYPE_RO_AFTER_INIT,
MOD_MEM_TYPE_INIT_TEXT,
MOD_MEM_TYPE_INIT_DATA,
MOD_MEM_TYPE_INIT_RODATA,

Quoted 1 line

and allocating them separately.

First thanks for doing this work!

This seems to not acknolwedge the original goal of the first module_layout and the latched rb-tree use, and that was was for speeding up __module_address() since it *can* even be triggered on NMIs. I say this because the first question that comes to me is the impact to performance on __module_address() I can't see that changing much here, but mention it as it similar consideration should be made in case future changes modify this path.

Microbenching something so trivial as __module_address() may not be as useful for an idle system, at the very least being able to compare before and after even on idle may be useful *if* you eventually do some more radical changes here. Modules-related kernel/kallsyms_selftest.c did that for kallsyms_lookup_name() and friend just recently for a minor performance enhancement.

At a high level it is perhaps my only conern so far while reviewing this patch, and I am glad it is now clear that addressing modules is a requirement. The rest seems like a highly welcomed cleanup even though the diffstat does not reflect that.

Quoted 4 lines

Various archs use module_layout for different data. These data are put into different module_memory based on their location in module_layout. IOW, data that used to go with text is allocated with MOD_MEM_TYPE_TEXT; data that used to go with data is allocated with MOD_MEM_TYPE_DATA, etc.

I think the commit log should document a bit the rationale for why ARCH_WANTS_MODULES_DATA_IN_VMALLOC gets *can* tidied up so well here.

Quoted 11 lines
Cc Luis Chamberlain <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>

---

This is the preparation work for the type aware module_alloc() discussed in [1]. While this work is not covered much in the discussion, it is a critical step of the effort.

Quoted 6 lines

As this part grows pretty big (~1000 lines, + and -), I would like get some feedback on it, so that I know it is on the right track.

Please share your comments. Thanks!

Test coverage: Tested on x86_64.

I will likely merge this onto modules-next soon, not because I think it is ready, but just because I think it *is* mostly ready and the next thing we need is exposure and testing. rc5 is pretty late to consider this for v6.3 and so hopefully for this cycle we can at least settle on something which will sit in linux-next since the respective linux-next after v6.3-rc1 is released.

Quoted 4 lines

Build tested by kernel test bot in [2]. The only regression in [2] was a typo in parisc, which is also fixed.

[1] https://lore.kernel.org/linux-mm/[email protected]/T/#u

You still never addressed my performance suggestions so don't be surprised if I insist later. Yes you can use existing performance benchmarks, specially now with modules as a hard requirement, to show gains. So I'd like to clarify that if I'm reviewing late it is because:

a) my modules patch review queue has been high as of late
b) you seem to not have taken these performance suggestions into consideration before and so I tend to put it at my end of my queue for review.

Quoted 5 lines
kernel/module/main.c +0 -0
index d02d39c7174e..c90eb2ba0985 100644

kernel/module/main.c static ssize_t store_uevent(struct module_attribute *mattr, · line 937

Quoted 9 lines
kernel/module/main.c +6 -0
@@ -925,11 +929,31 @@ static ssize_t store_uevent(struct module_attribute *mattr,
 struct module_attribute module_uevent =
 	__ATTR(uevent, 0200, NULL, store_uevent);
 
+#ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC
+
+static ssize_t show_coresize(struct module_attribute *mattr,
+			     struct module_kobject *mk, char *buffer)
+{
+	enum mod_mem_type type;

This is unused.

Quoted 26 lines
kernel/module/main.c +15 -5
@@ -1389,16 +1466,29 @@ unsigned int __weak arch_mod_section_prepend(struct module *mod,
 	return 0;
 }
 
-/* Update size with this section: return offset. */
-long module_get_offset(struct module *mod, unsigned int *size,
-		       Elf_Shdr *sechdr, unsigned int section)
+/*
+ * Use highest 4 bits of sh_entsize to store the mod_mem_type of this
+ * section. This leaves 28 bits for offset on 32-bit systems, which is
+ * about 256 MiB (WARN_ON_ONCE if we exceed that).
+ */
+
+#define SH_ENTSIZE_TYPE_BITS	4
+#define SH_ENTSIZE_TYPE_SHIFT	(BITS_PER_LONG - SH_ENTSIZE_TYPE_BITS)
+#define SH_ENTSIZE_TYPE_MASK	((1UL << SH_ENTSIZE_TYPE_BITS) - 1)
+#define SH_ENTSIZE_OFFSET_MASK	((1UL << (BITS_PER_LONG - SH_ENTSIZE_TYPE_BITS)) - 1)
+
+long module_get_offset_and_type(struct module *mod, enum mod_mem_type type,
+				Elf_Shdr *sechdr, unsigned int section)
 {
-	long ret;
+	long offset;
+	long mask = ((unsigned long)(type) & SH_ENTSIZE_TYPE_MASK) << SH_ENTSIZE_TYPE_SHIFT;
 
-	*size += arch_mod_section_prepend(mod, section);

kernel/module/main.c unsigned int __weak arch_mod_section_prepend(struct module *mod, · line 1492

Quoted 10 lines
kernel/module/main.c +6 -3
-	ret = ALIGN(*size, sechdr->sh_addralign ?: 1);
-	*size = ret + sechdr->sh_size;
-	return ret;
+	mod->mod_mem[type].size += arch_mod_section_prepend(mod, section);
+	offset = ALIGN(mod->mod_mem[type].size, sechdr->sh_addralign ?: 1);
+	mod->mod_mem[type].size = offset + sechdr->sh_size;
+
+	WARN_ON_ONCE(offset & mask);
+	return offset | mask;
 }

Could you split this somehow with the mask stuff up into its own non-functional patch first somehow to make this easier to review?

No worries if you can't.

Quoted 21 lines
kernel/module/main.c +1 -13
@@ -2117,74 +2193,45 @@ static int find_module_sections(struct module *mod, struct load_info *info)
 
 static int move_module(struct module *mod, struct load_info *info)
 {
+	enum mod_mem_type type;
 	int i;
 	void *ptr;
 
-	/* Do the allocs. */
-	ptr = module_alloc(mod->core_layout.size);
-	/*
-	 * The pointer to this block is stored in the module structure
-	 * which is inside the block. Just mark it as not being a
-	 * leak.
-	 */
-	kmemleak_not_leak(ptr);
-	if (!ptr)
-		return -ENOMEM;
-
-	memset(ptr, 0, mod->core_layout.size);
-	mod->core_layout.base = ptr;

kernel/module/main.c static int find_module_sections(struct module *mod, struct load_info *info) · line 2209

Quoted 10 lines
kernel/module/main.c +10 -0
+	for_each_mod_mem_type(type) {
+		if (!mod->mod_mem[type].size) {
+			mod->mod_mem[type].base = NULL;
+			continue;
+		}
+		mod->mod_mem[type].size = PAGE_ALIGN(mod->mod_mem[type].size);
+		if (mod_mem_use_vmalloc(type))
+			ptr = vzalloc(mod->mod_mem[type].size);
+		else
+			ptr = module_alloc(mod->mod_mem[type].size);

This form to check for mod_mem_use_vmalloc() is used twice, how about a helper to just do it one line for us?

kernel/module/main.c static int move_module(struct module *mod, struct load_info *info) · line 2253

Quoted 13 lines
kernel/module/main.c +8 -0
@@ -2195,6 +2242,14 @@ static int move_module(struct module *mod, struct load_info *info)
 	}
 
 	return 0;
+out_enomem:
+	for (type--; type >= 0; type--) {
+		if (mod_mem_use_vmalloc(type))
+			vfree(mod->mod_mem[type].base);
+		else
+			module_memfree(mod->mod_mem[type].base);
+	}
+	return -ENOMEM;
 }

Here's the other user.

kernel/module/strict_rwx.c

Quoted 1 line
kernel/module/strict_rwx.c +0 -0

This was the hardest file to review and so I ask the same, if a separate non-functional change could be done first to make the changes easier to review.

No worries if not.

I'll queue this onto modules-testing to see what blows up. After at least one more review I'll queue this onto modules-next.

Luis

author
#3 lore raw
In reply to Luis Chamberlain

Hi Luis,

Thanks for your kind review!

Quoted 1 line · Luis Chamberlain

[...]

Quoted 11 lines
Quoted 10 lines

MOD_MEM_TYPE_TEXT,
MOD_MEM_TYPE_DATA,
MOD_MEM_TYPE_RODATA,
MOD_MEM_TYPE_RO_AFTER_INIT,
MOD_MEM_TYPE_INIT_TEXT,
MOD_MEM_TYPE_INIT_DATA,
MOD_MEM_TYPE_INIT_RODATA,

and allocating them separately.

Quoted 8 lines

First thanks for doing this work!

This seems to not acknolwedge the original goal of the first module_layout and the latched rb-tree use, and that was was for speeding up __module_address() since it *can* even be triggered on NMIs. I say this because the first question that comes to me is the impact to performance on __module_address() I can't see that changing much here, but mention it as it similar consideration should be made in case future changes modify this path.

To make sure I understand this correctly. Do you mean we need something like the following in the commit log?

"""
This adds slightly more entries to mod_tree (from up to 3 entries per module, to up to 7 entries per module). However, this at most adds a small constant overhead to __module_address(), which is expected to be fast.
"""

Quoted 6 lines

Microbenching something so trivial as __module_address() may not be as useful for an idle system, at the very least being able to compare before and after even on idle may be useful *if* you eventually do some more radical changes here. Modules-related kernel/kallsyms_selftest.c did that for kallsyms_lookup_name() and friend just recently for a minor performance enhancement.

kernel/kallsyms_selftest.c is new to me. I will give it a try.

Quoted 6 lines

At a high level it is perhaps my only conern so far while reviewing this patch, and I am glad it is now clear that addressing modules is a requirement. The rest seems like a highly welcomed cleanup even though the diffstat does not reflect that.

Quoted 7 lines
Quoted 4 lines

Various archs use module_layout for different data. These data are put into different module_memory based on their location in module_layout. IOW, data that used to go with text is allocated with MOD_MEM_TYPE_TEXT; data that used to go with data is allocated with MOD_MEM_TYPE_DATA, etc.

I think the commit log should document a bit the rationale for why ARCH_WANTS_MODULES_DATA_IN_VMALLOC gets *can* tidied up so well here.

Great point! Will add this in v3.

Quoted 17 lines
Quoted 17 lines
Cc Luis Chamberlain <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>

---

This is the preparation work for the type aware module_alloc() discussed in [1]. While this work is not covered much in the discussion, it is a critical step of the effort.

As this part grows pretty big (~1000 lines, + and -), I would like get some feedback on it, so that I know it is on the right track.

Please share your comments. Thanks!

Quoted 8 lines
Quoted 1 line

Test coverage: Tested on x86_64.

I will likely merge this onto modules-next soon, not because I think it is ready, but just because I think it *is* mostly ready and the next thing we need is exposure and testing. rc5 is pretty late to consider this for v6.3 and so hopefully for this cycle we can at least settle on something which will sit in linux-next since the respective linux-next after v6.3-rc1 is released.

Yes, this definitely needs more tests. Given different archs use module_layout in all sorts of ways. I will be very surprised if I updated all them correctly (though I tried hard to).

Quoted 12 lines
Quoted 5 lines

Build tested by kernel test bot in [2]. The only regression in [2] was a typo in parisc, which is also fixed.

[1] https://lore.kernel.org/linux-mm/[email protected]/T/#u

You still never addressed my performance suggestions so don't be surprised if I insist later. Yes you can use existing performance benchmarks, specially now with modules as a hard requirement, to show gains. So I'd like to clarify that if I'm reviewing late it is because:

Quoted 3 lines

a) my modules patch review queue has been high as of late
b) you seem to not have taken these performance suggestions into consideration before and so I tend to put it at my end of my queue for review.

I think it will be a lot easier to run performance tests with the module support. Let's see what we can do when we get to the performance test part.

[...]

Quoted 41 lines
Quoted 27 lines
kernel/module/main.c +15 -5
@@ -1389,16 +1466,29 @@ unsigned int __weak arch_mod_section_prepend(struct module *mod,
      return 0;
 }
 
-/* Update size with this section: return offset. */
-long module_get_offset(struct module *mod, unsigned int *size,
-                    Elf_Shdr *sechdr, unsigned int section)
+/*
+ * Use highest 4 bits of sh_entsize to store the mod_mem_type of this
+ * section. This leaves 28 bits for offset on 32-bit systems, which is
+ * about 256 MiB (WARN_ON_ONCE if we exceed that).
+ */
+
+#define SH_ENTSIZE_TYPE_BITS 4
+#define SH_ENTSIZE_TYPE_SHIFT        (BITS_PER_LONG - SH_ENTSIZE_TYPE_BITS)
+#define SH_ENTSIZE_TYPE_MASK ((1UL << SH_ENTSIZE_TYPE_BITS) - 1)
+#define SH_ENTSIZE_OFFSET_MASK       ((1UL << (BITS_PER_LONG - SH_ENTSIZE_TYPE_BITS)) - 1)
+
+long module_get_offset_and_type(struct module *mod, enum mod_mem_type type,
+                             Elf_Shdr *sechdr, unsigned int section)
 {
-     long ret;
+     long offset;
+     long mask = ((unsigned long)(type) & SH_ENTSIZE_TYPE_MASK) << SH_ENTSIZE_TYPE_SHIFT;
 
-     *size += arch_mod_section_prepend(mod, section);

kernel/module/main.c unsigned int __weak arch_mod_section_prepend(struct module *mod, · line 1492

Quoted 10 lines
kernel/module/main.c +6 -3
-     ret = ALIGN(*size, sechdr->sh_addralign ?: 1);
-     *size = ret + sechdr->sh_size;
-     return ret;
+     mod->mod_mem[type].size += arch_mod_section_prepend(mod, section);
+     offset = ALIGN(mod->mod_mem[type].size, sechdr->sh_addralign ?: 1);
+     mod->mod_mem[type].size = offset + sechdr->sh_size;
+
+     WARN_ON_ONCE(offset & mask);
+     return offset | mask;
 }

Could you split this somehow with the mask stuff up into its own non-functional patch first somehow to make this easier to review?

Quoted 1 line

No worries if you can't.

This is not very straightforward with INIT_OFFSET_MASK. So I will keep it as-is for now. Btw, while looking into this, I found a leftover INIT_OFFSET_MASK that I will remove in v3.

Quoted 27 lines
Quoted 27 lines
kernel/module/main.c +6 -13
@@ -2117,74 +2193,45 @@ static int find_module_sections(struct module *mod, struct load_info *info)
 
 static int move_module(struct module *mod, struct load_info *info)
 {
+     enum mod_mem_type type;
      int i;
      void *ptr;
 
-     /* Do the allocs. */
-     ptr = module_alloc(mod->core_layout.size);
-     /*
-      * The pointer to this block is stored in the module structure
-      * which is inside the block. Just mark it as not being a
-      * leak.
-      */
-     kmemleak_not_leak(ptr);
-     if (!ptr)
-             return -ENOMEM;
-
-     memset(ptr, 0, mod->core_layout.size);
-     mod->core_layout.base = ptr;
+     for_each_mod_mem_type(type) {
+             if (!mod->mod_mem[type].size) {
+                     mod->mod_mem[type].base = NULL;
+                     continue;
+             }
Quoted 8 lines

kernel/module/main.c static int find_module_sections(struct module *mod, struct load_info *info) · line 2209

Quoted 5 lines
kernel/module/main.c +5 -0
+             mod->mod_mem[type].size = PAGE_ALIGN(mod->mod_mem[type].size);
+             if (mod_mem_use_vmalloc(type))
+                     ptr = vzalloc(mod->mod_mem[type].size);
+             else
+                     ptr = module_alloc(mod->mod_mem[type].size);

This form to check for mod_mem_use_vmalloc() is used twice, how about a helper to just do it one line for us?

Good idea! Will update in v3.

Quoted 17 lines
Quoted 4 lines
kernel/module/main.c +0 -0
@@ -2195,6 +2242,14 @@ static int move_module(struct module *mod, struct load_info *info)
      }
 

kernel/module/main.c static int move_module(struct module *mod, struct load_info *info) · line 2253

Quoted 10 lines
kernel/module/main.c +8 -0
      return 0;
+out_enomem:
+     for (type--; type >= 0; type--) {
+             if (mod_mem_use_vmalloc(type))
+                     vfree(mod->mod_mem[type].base);
+             else
+                     module_memfree(mod->mod_mem[type].base);
+     }
+     return -ENOMEM;
 }

Here's the other user.

Quoted 5 lines

kernel/module/strict_rwx.c

Quoted 1 line
kernel/module/strict_rwx.c +0 -0

This was the hardest file to review and so I ask the same, if a separate non-functional change could be done first to make the changes easier to review.

AFAICT, strict_rwx.c is pretty straightforward after the change. And it is just ~100 LOC. The non-functional change is very likely to be more complicated. So I will keep this part as-is.

Quoted 4 lines

No worries if not.

I will fix these, rebase, and send v3.

Thanks again!
Song

maintainer
#4 lore raw

Guenter Roeck,

Any chance you can give this branch a good spin on your multi-arch setup to see what may below up?

https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=modules-testing

Quoted 27 lines · Song Liu

Hi Luis,

Thanks for your kind review!

Quoted 1 line · Luis Chamberlain

[...]

Quoted 11 lines
Quoted 10 lines

MOD_MEM_TYPE_TEXT,
MOD_MEM_TYPE_DATA,
MOD_MEM_TYPE_RODATA,
MOD_MEM_TYPE_RO_AFTER_INIT,
MOD_MEM_TYPE_INIT_TEXT,
MOD_MEM_TYPE_INIT_DATA,
MOD_MEM_TYPE_INIT_RODATA,

and allocating them separately.

Quoted 8 lines

First thanks for doing this work!

This seems to not acknolwedge the original goal of the first module_layout and the latched rb-tree use, and that was was for speeding up __module_address() since it *can* even be triggered on NMIs. I say this because the first question that comes to me is the impact to performance on __module_address() I can't see that changing much here, but mention it as it similar consideration should be made in case future changes modify this path.

Quoted 8 lines

To make sure I understand this correctly. Do you mean we need something like the following in the commit log?

"""
This adds slightly more entries to mod_tree (from up to 3 entries per module, to up to 7 entries per module). However, this at most adds a small constant overhead to __module_address(), which is expected to be fast.
"""

Yes I think this is very useful information for the reviewier.

Quoted 7 lines
Quoted 5 lines

Microbenching something so trivial as __module_address() may not be as useful for an idle system, at the very least being able to compare before and after even on idle may be useful *if* you eventually do some more radical changes here. Modules-related kernel/kallsyms_selftest.c did that for kallsyms_lookup_name() and friend just recently for a minor performance enhancement.

kernel/kallsyms_selftest.c is new to me. I will give it a try.

It was just merged, be sure to have da35048f2600 ("kallsyms: Fix scheduling with interrupts disabled in self-test").

Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
Cc Luis Chamberlain <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>

---

This is the preparation work for the type aware module_alloc() discussed in [1]. While this work is not covered much in the discussion, it is a critical step of the effort.

As this part grows pretty big (~1000 lines, + and -), I would like get some feedback on it, so that I know it is on the right track.

Please share your comments. Thanks!

Quoted 8 lines
Quoted 1 line

Test coverage: Tested on x86_64.

I will likely merge this onto modules-next soon, not because I think it is ready, but just because I think it *is* mostly ready and the next thing we need is exposure and testing. rc5 is pretty late to consider this for v6.3 and so hopefully for this cycle we can at least settle on something which will sit in linux-next since the respective linux-next after v6.3-rc1 is released.

Quoted 3 lines

Yes, this definitely needs more tests. Given different archs use module_layout in all sorts of ways. I will be very surprised if I updated all them correctly (though I tried hard to).

OK so let's be patient with testing. Getting help from Guenter here can probably speed up finding issues.

Quoted 11 lines
Quoted 11 lines
Quoted 4 lines

Build tested by kernel test bot in [2]. The only regression in [2] was a typo in parisc, which is also fixed.

[1] https://lore.kernel.org/linux-mm/[email protected]/T/#u

You still never addressed my performance suggestions so don't be surprised if I insist later. Yes you can use existing performance benchmarks, specially now with modules as a hard requirement, to show gains. So I'd like to clarify that if I'm reviewing late it is because:

Quoted 7 lines
Quoted 3 lines

a) my modules patch review queue has been high as of late
b) you seem to not have taken these performance suggestions into consideration before and so I tend to put it at my end of my queue for review.

I think it will be a lot easier to run performance tests with the module support. Let's see what we can do when we get to the performance test part.

Fantastic, clearly I'm interested in being able to reproduce so I will email you offline about some techniques I've used to reproduce some things easily for testing things with modules.

Luis

#5 lore raw
Quoted 5 lines · Luis Chamberlain

Guenter Roeck,

Any chance you can give this branch a good spin on your multi-arch setup to see what may below up?

I assume I shoud test v3 ?

Guenter

Quoted 108 lines

https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/log/?h=modules-testing

Quoted 27 lines · Song Liu

Hi Luis,

Thanks for your kind review!

Quoted 1 line · Luis Chamberlain

[...]

Quoted 11 lines
Quoted 10 lines

MOD_MEM_TYPE_TEXT,
MOD_MEM_TYPE_DATA,
MOD_MEM_TYPE_RODATA,
MOD_MEM_TYPE_RO_AFTER_INIT,
MOD_MEM_TYPE_INIT_TEXT,
MOD_MEM_TYPE_INIT_DATA,
MOD_MEM_TYPE_INIT_RODATA,

and allocating them separately.

Quoted 8 lines

First thanks for doing this work!

This seems to not acknolwedge the original goal of the first module_layout and the latched rb-tree use, and that was was for speeding up __module_address() since it *can* even be triggered on NMIs. I say this because the first question that comes to me is the impact to performance on __module_address() I can't see that changing much here, but mention it as it similar consideration should be made in case future changes modify this path.

Quoted 8 lines

To make sure I understand this correctly. Do you mean we need something like the following in the commit log?

"""
This adds slightly more entries to mod_tree (from up to 3 entries per module, to up to 7 entries per module). However, this at most adds a small constant overhead to __module_address(), which is expected to be fast.
"""

Yes I think this is very useful information for the reviewier.

Quoted 7 lines
Quoted 5 lines

Microbenching something so trivial as __module_address() may not be as useful for an idle system, at the very least being able to compare before and after even on idle may be useful *if* you eventually do some more radical changes here. Modules-related kernel/kallsyms_selftest.c did that for kallsyms_lookup_name() and friend just recently for a minor performance enhancement.

kernel/kallsyms_selftest.c is new to me. I will give it a try.

It was just merged, be sure to have da35048f2600 ("kallsyms: Fix scheduling with interrupts disabled in self-test").

Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
Cc Luis Chamberlain <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>

---

This is the preparation work for the type aware module_alloc() discussed in [1]. While this work is not covered much in the discussion, it is a critical step of the effort.

As this part grows pretty big (~1000 lines, + and -), I would like get some feedback on it, so that I know it is on the right track.

Please share your comments. Thanks!

Quoted 8 lines
Quoted 1 line

Test coverage: Tested on x86_64.

I will likely merge this onto modules-next soon, not because I think it is ready, but just because I think it *is* mostly ready and the next thing we need is exposure and testing. rc5 is pretty late to consider this for v6.3 and so hopefully for this cycle we can at least settle on something which will sit in linux-next since the respective linux-next after v6.3-rc1 is released.

Quoted 3 lines

Yes, this definitely needs more tests. Given different archs use module_layout in all sorts of ways. I will be very surprised if I updated all them correctly (though I tried hard to).

OK so let's be patient with testing. Getting help from Guenter here can probably speed up finding issues.

Quoted 11 lines
Quoted 11 lines
Quoted 4 lines

Build tested by kernel test bot in [2]. The only regression in [2] was a typo in parisc, which is also fixed.

[1] https://lore.kernel.org/linux-mm/[email protected]/T/#u

You still never addressed my performance suggestions so don't be surprised if I insist later. Yes you can use existing performance benchmarks, specially now with modules as a hard requirement, to show gains. So I'd like to clarify that if I'm reviewing late it is because:

Quoted 7 lines
Quoted 3 lines

a) my modules patch review queue has been high as of late
b) you seem to not have taken these performance suggestions into consideration before and so I tend to put it at my end of my queue for review.

I think it will be a lot easier to run performance tests with the module support. Let's see what we can do when we get to the performance test part.

Fantastic, clearly I'm interested in being able to reproduce so I will email you offline about some techniques I've used to reproduce some things easily for testing things with modules.

Luis

#7 lore raw
Quoted 5 lines · Song Liu

Hi Guenter,

Quoted 2 lines · Guenter Roeck

On Thu, Jan 26, 2023 at 01:00:43PM -0800, Luis Chamberlain wrote:

Quoted 9 lines
Quoted 6 lines
Quoted 5 lines

Guenter Roeck,

Any chance you can give this branch a good spin on your multi-arch setup to see what may below up?

I assume I shoud test v3 ?

Yes, please. The one in the modules-testing [1] branch is already v3.

I started a test on v6.2-rc5-52-gc96fb00e9ddf.

Guenter