Skip to contentSkip to conversation

Module and ARM Module updates and fixes

RFC PATCH Superseded David Dgien 3 participants 14 messages Jun 17, 2020 – Jun 22, 2020

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Module and ARM Module updates and fixes

This series fixes various bugs and bit-rot issues with the module loading code. It also ports a couple of modules features from the Linux
kernel: arch specific section fixups, and module PLTs for ARM modules, to contain veneers for 'bl' instructions.

There are two things in this series I'm looking for feedback on:
Linux implements module_frob_arch_sections as a weak symbol for the default case. I didn't see any other "weak" functions in barebox, so I wasn't sure if using that was acceptable. Since the Kconfig HAVE_MOD_ARCH_SPECIFIC already exists as part of the change, I just used that to define a static inline default implementation, but using a weak function would make that slightly cleaner.

And in the patch that added the init macros to module.h, I wasn't sure if it would be okay to pollute init.h with the #ifndef MODULE directives, so instead I just #undef'd all of the initcalls before redefining them in module.h. If it's okay to add the #ifndef MODULE to init.h, that would be significantly cleaner than the current implementation.

David Dgien (8):
Makefile: Initialize and export KBUILD variables
module: Add init macros to module.h
module: Fix adding module to list after layout
module: Fix module command registration
module: Implement HAVE_MOD_ARCH_SPECIFIC
arm: makefile: Fix compiler flag variable
arm: elf: Add THM relocation types
arm: module: Allow modules outside of bl range

 Makefile                      |  12 +-
 arch/arm/Kconfig              |  15 +++
 arch/arm/Makefile             |   6 +-
 arch/arm/cpu/Kconfig          |   1 +
 arch/arm/include/asm/elf.h    |   3 +
 arch/arm/include/asm/module.h |  44 ++++++-
 arch/arm/lib32/Makefile       |   1 +
 arch/arm/lib32/module-plts.c  | 229 ++++++++++++++++++++++++++++++++++
 arch/arm/lib32/module.c       |  14 +++
 arch/arm/lib32/module.lds     |   4 +
 common/Kconfig                |   8 ++
 common/module.c               |  60 +++++----
 include/asm-generic/module.h  |  49 ++++++++
 include/module.h              | 109 ++++++++++++++++
 14 files changed, 523 insertions(+), 32 deletions(-)
 create mode 100644 arch/arm/lib32/module-plts.c
 create mode 100644 arch/arm/lib32/module.lds
 create mode 100644 include/asm-generic/module.h
Signature · 7 lines
2.27.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

RFC PATCH 1/8 Makefile: Initialize and export KBUILD variables

Initialize and export KBUILD KERNEL and MODULE variables. Otherwise, appending to them elsewhere in the srctree will not be seen by the build commands in Makefile.lib

---
 Makefile | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
Makefile +10 -2
index c4a2519a1..f9457323e 100644
@@ -395,6 +395,8 @@ BASH		= bash
 CHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise $(CF)
 CFLAGS_KERNEL	=
 AFLAGS_KERNEL	=
+CFLAGS_MODULE	=
+AFLAGS_MODULE	=
 
 LDFLAGS_MODULE  = -T common/module.lds
 
@@ -418,6 +420,10 @@ KBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
                    -Werror=implicit-function-declaration -Werror=implicit-int \
                    -Os -pipe -Wmissing-prototypes -std=gnu89
 KBUILD_AFLAGS          := -D__ASSEMBLY__
+KBUILD_AFLAGS_KERNEL :=
+KBUILD_CFLAGS_KERNEL :=
+KBUILD_AFLAGS_MODULE := -DMODULE
+KBUILD_CFLAGS_MODULE := -DMODULE
 
 LDFLAGS_barebox	:= -Map barebox.map
 
@@ -432,8 +438,10 @@ export HOSTCXX CHECK CHECKFLAGS
 export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
 
 export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
-export KBUILD_CFLAGS CFLAGS_KERNEL
-export KBUILD_AFLAGS AFLAGS_KERNEL
+export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
+export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
+export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE
+export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
 export LDFLAGS_barebox
 export LDFLAGS_pbl
 
Signature · 7 lines
2.27.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

RFC PATCH 2/8 module: Add init macros to module.h

In reply to David Dgien

Port module initialization macros and initcall redefinition macros from Linux

---
 include/module.h | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 91 insertions(+)
include/module.h +91 -0
index cea8c2e18..37c48f065 100644
@@ -2,6 +2,7 @@
 #ifndef __MODULE_H
 #define __MODULE_H
 
+#include <init.h>
 #include <elf.h>
 #include <linux/compiler.h>
 #include <linux/export.h>
@@ -13,6 +14,96 @@
 
 #define MODULE_NAME_LEN (64 - sizeof(unsigned long))
 
+/* These are either module local, or the kernel's dummy ones. */
+extern int init_module(void);
+extern void cleanup_module(void);
+
+#ifndef MODULE
+/**
+ * module_init() - driver initialization entry point
+ * @x: function to be run at kernel boot time or module insertion
+ *
+ * module_init() will either be called during do_initcalls() (if
+ * builtin) or at module insertion time (if a module).  There can only
+ * be one per module.
+ */
+#define module_init(x)	device_initcall(x);
+
+/**
+ * module_exit() - driver exit entry point
+ * @x: function to be run when driver is removed
+ *
+ * module_exit() will wrap the driver clean-up code
+ * with cleanup_module() when used with rmmod when
+ * the driver is a module.  If the driver is statically
+ * compiled into the kernel, module_exit() has no effect.
+ * There can only be one per module.
+ */
+#define module_exit(x)	devshutdown_exitcall(x);
+
+#else /* MODULE */
+
+/*
+ * In most cases loadable modules do not need custom
+ * initcall levels. There are still some valid cases where
+ * a driver may be needed early if built in, and does not
+ * matter when built as a loadable module. Like bus
+ * snooping debug drivers.
+ */
+#undef core_initcall
+#undef postcore_initcall
+#undef console_initcall
+#undef postconsole_initcall
+#undef mem_initcall
+#undef mmu_initcall
+#undef postmmu_initcall
+#undef coredevice_initcall
+#undef fs_initcall
+#undef device_initcall
+#undef late_initcall
+
+#define core_initcall(fn)		module_init(fn)
+#define postcore_initcall(fn)		module_init(fn)
+#define console_initcall(fn)		module_init(fn)
+#define postconsole_initcall(fn)	module_init(fn)
+#define mem_initcall(fn)		module_init(fn)
+#define mmu_initcall(fn)		module_init(fn)
+#define postmmu_initcall(fn)		module_init(fn)
+#define coredevice_initcall(fn)		module_init(fn)
+#define fs_initcall(fn)			module_init(fn)
+#define device_initcall(fn)		module_init(fn)
+#define late_initcall(fn)		module_init(fn)
+
+#undef early_exitcall
+#undef predevshutdown_exitcall
+#undef devshutdown_exitcall
+#undef postdevshutdown_exitcall
+#undef prearchshutdown_exitcall
+#undef archshutdown_exitcall
+#undef postarchshutdown_exitcall
+
+#define early_exitcall(fn)		module_exit(fn)
+#define predevshutdown_exitcall(fn)	module_exit(fn)
+#define devshutdown_exitcall(fn)	module_exit(fn)
+#define postdevshutdown_exitcall(fn)	module_exit(fn)
+#define prearchshutdown_exitcall(fn)	module_exit(fn)
+#define archshutdown_exitcall(fn)	module_exit(fn)
+#define postarchshutdown_exitcall(fn)	module_exit(fn)
+
+/* Each module must use one module_init(). */
+#define module_init(initfn)					\
+	static inline initcall_t __maybe_unused __inittest(void)		\
+	{ return initfn; }					\
+	int init_module(void) __attribute__((alias(#initfn)));
+
+/* This is only required if you want to be unloadable. */
+#define module_exit(exitfn)					\
+	static inline exitcall_t __maybe_unused __exittest(void)		\
+	{ return exitfn; }					\
+	void cleanup_module(void) __attribute__((alias(#exitfn)));
+
+#endif
+
 #ifdef CONFIG_MODULES
 #include <asm/module.h>
 
Signature · 7 lines
2.27.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

RFC PATCH 3/8 module: Fix adding module to list after layout

In reply to David Dgien

During load_module(), the 'this_module' section is relocated, but the pointer to the module struct isn't updated to account account for the move. Do so before adding the module to the module_list.

As a side effect of properly pointing to the relocated module struct, we no longer need to manually search for and fixup the init_module symbol, so remove that code.

---
 common/module.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
common/module.c +2 -9
index 829c12000..5ace544e0 100644
@@ -297,13 +297,8 @@ struct module * load_module(void *mod_image, unsigned long len)
 		}
 	}
 
-	for (i = 0; i < numsyms; i++) {
-		if (!strcmp(strtab + sym[i].st_name, MODULE_SYMBOL_PREFIX "init_module")) {
-			printf("found init_module() at 0x%08x\n", sym[i].st_value);
-			module->init = (void *)sym[i].st_value;
-		}
-	}
-
+	/* Module has been moved */
+	module = (void *)sechdrs[modindex].sh_addr;
 	list_add_tail(&module->list, &module_list);
 
 	return module;
@@ -311,8 +306,6 @@ struct module * load_module(void *mod_image, unsigned long len)
 cleanup:
 	if (ptr)
 		free(ptr);
-	if (module)
-		free(module);
 
 	return NULL;
 }
Signature · 7 lines
2.27.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

RFC PATCH 4/8 module: Fix module command registration

In reply to David Dgien

Commit 1e4a948673d7 ("command: Use array of pointers to commands") updated the command linker sections to contain an array of pointers to the command structs, rather than the command structs themselves. However, the load_module function was not updated to account for the change to the linker section, so fix that here.

Additionally, commit 22bdecc9c591 ("lds: Move start/end address variables into defines") moved the _start and _end symbols out of the linker script and into the section macro defines, causing them to show up in the module symbol table as well, so we take can advantage of those to find the array of pointers.

Fixes 1e4a948673d7 ("command: Use array of pointers to commands")
---
 common/module.c | 43 +++++++++++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 14 deletions(-)
common/module.c +29 -14
index 5ace544e0..b08df1199 100644
@@ -176,6 +176,34 @@ static void layout_sections( struct module *mod,
 	debug("core_size: %ld\n", mod->core_size);
 }
 
+static void register_module_cmds(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex)
+{
+	Elf32_Sym *sym;
+	unsigned int numsyms;
+	unsigned int i;
+	struct command * const *cmd_start = NULL;
+	struct command * const *cmd_end = NULL;
+	struct command * const *cmd;
+
+	numsyms = sechdrs[symindex].sh_size / sizeof(Elf32_Sym);
+	sym = (void *)sechdrs[symindex].sh_addr;
+
+	for (i = 0; i < numsyms; i++) {
+		if (strcmp(strtab + sym[i].st_name, MODULE_SYMBOL_PREFIX "__barebox_cmd_start") == 0)
+			cmd_start = (struct command * const *)sym[i].st_value;
+
+		if (strcmp(strtab + sym[i].st_name, MODULE_SYMBOL_PREFIX "__barebox_cmd_end") == 0)
+			cmd_end = (struct command * const *)sym[i].st_value;
+	}
+
+	if (cmd_start && cmd_end) {
+		debug("found __barebox_cmd_start at 0x%08x\n", (uint32_t)cmd_start);
+		for (cmd = cmd_start; cmd != cmd_end; cmd++) {
+			register_command(*cmd);
+		}
+	}
+}
+
 LIST_HEAD(module_list);
 
 struct module * load_module(void *mod_image, unsigned long len)
@@ -183,8 +211,6 @@ struct module * load_module(void *mod_image, unsigned long len)
 	struct module *module = NULL;
 	Elf32_Ehdr *ehdr;		/* Elf header structure pointer     */
 	Elf32_Shdr *sechdrs;		/* Section header structure pointer */
-	Elf32_Sym *sym;
-	unsigned int numsyms;
 	char *strtab = 0;		/* String table pointer             */
 	int i;				/* Loop counter                     */
 	unsigned int strindex = 0;
@@ -193,7 +219,6 @@ struct module * load_module(void *mod_image, unsigned long len)
 	char *secstrings;
 	void *ptr = NULL;
 	int err;
-	int cmdindex;
 
 	if (len < sizeof(*ehdr))
 		return NULL;
@@ -285,17 +310,7 @@ struct module * load_module(void *mod_image, unsigned long len)
 			apply_relocate_add(sechdrs, strtab, symindex, i, module);
 	}
 
-	numsyms = sechdrs[symindex].sh_size / sizeof(Elf32_Sym);
-	sym = (void *)sechdrs[symindex].sh_addr;
-
-	cmdindex = find_sec(ehdr, sechdrs, secstrings, ".barebox_cmd");
-	if (cmdindex) {
-		struct command *cmd =(struct command *)sechdrs[cmdindex].sh_addr;
-		for (i = 0; i < sechdrs[cmdindex].sh_size / sizeof(struct command); i++) {
-			register_command(cmd);
-			cmd++;
-		}
-	}
+	register_module_cmds(sechdrs, strtab, symindex);
 
 	/* Module has been moved */
 	module = (void *)sechdrs[modindex].sh_addr;
Signature · 7 lines
2.27.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

RFC PATCH 5/8 module: Implement HAVE_MOD_ARCH_SPECIFIC

In reply to David Dgien

Implement HAVE_MOD_ARCH_SPECIFIC Kconfig and module_frob_arch_sections() function prototype from Linux module subsystem. module_frob_arch_sections() should be implemented by any architecture that selects HAVE_MOD_ARCH_SPECIFIC, and is called from load_module()

---
 common/Kconfig               |  8 ++++++
 common/module.c              |  6 +++++
 include/asm-generic/module.h | 49 ++++++++++++++++++++++++++++++++++++
 include/module.h             | 18 +++++++++++++
 4 files changed, 81 insertions(+)
 create mode 100644 include/asm-generic/module.h
common/Kconfig +8 -0
index ac282d895..9bade375e 100644
@@ -326,6 +326,14 @@ config MODULES
 	  way to compile modules and the list of exported symbols to actually
 	  make use of modules is short to nonexistent
 
+config HAVE_MOD_ARCH_SPECIFIC
+	depends on MODULES
+	bool
+	help
+	  The arch uses struct mod_arch_specific to store data.  Many arches
+	  just need a simple module loader without arch specific data - those
+	  should not enable this.
+
 config KALLSYMS
 	depends on HAS_KALLSYMS
 	bool "kallsyms"
common/module.c +6 -0
index b08df1199..964369755 100644
@@ -271,6 +271,12 @@ struct module * load_module(void *mod_image, unsigned long len)
 		goto cleanup;
 	}
 
+	/* Allow arches to frob section contents and sizes.  */
+	err = module_frob_arch_sections(ehdr, sechdrs,
+					secstrings, module);
+	if (err < 0)
+		goto cleanup;
+
 	/* Determine total sizes, and put offsets in sh_entsize.  For now
 	   this is done generically; there doesn't appear to be any
 	   special cases for the architectures. */
include/asm-generic/module.h new file +49 -0

49 lines not on this page · raw message

include/module.h +18 -0
index 37c48f065..2751c86cd 100644
@@ -142,6 +142,24 @@ int apply_relocate_add(Elf_Shdr *sechdrs,
 		       unsigned int symindex,
 		       unsigned int relsec,
 		       struct module *mod);
+
+#ifdef CONFIG_HAVE_MOD_ARCH_SPECIFIC
+/* Adjust arch-specific sections.  Return 0 on success.  */
+int module_frob_arch_sections(Elf_Ehdr *hdr,
+			      Elf_Shdr *sechdrs,
+			      char *secstrings,
+			      struct module *mod);
+#else
+static inline
+int module_frob_arch_sections(Elf_Ehdr *hdr,
+			      Elf_Shdr *sechdrs,
+			      char *secstrings,
+			      struct module *mod)
+{
+	return 0;
+}
+#endif
+
 #endif /* CONFIG_MODULES */
 
 extern struct list_head module_list;
Signature · 7 lines
2.27.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

RFC PATCH 6/8 arm: makefile: Fix compiler flag variable

In reply to David Dgien

In order for ARM modules to compile with the correct relocation types, they must be built without -fPIE. Move -fPIE from KBUILD_CPPFLAGS to KBUILD_CFLAGS_KERNEL so that the flag is only included when compiling files being built into the barebox image.

---
 arch/arm/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/Makefile +1 -1
index 6c7373c20..c18a1d802 100644
@@ -139,7 +139,7 @@ LDFLAGS_barebox += --gc-sections
 LDFLAGS_pbl += --gc-sections
 
 # early code often runs at addresses we are not linked at
-KBUILD_CPPFLAGS += -fPIE
+KBUILD_CFLAGS_KERNEL += -fPIE
 
 ifdef CONFIG_RELOCATABLE
 LDFLAGS_barebox += -pie
Signature · 7 lines
2.27.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

RFC PATCH 7/8 arm: elf: Add THM relocation types

In reply to David Dgien
---
 arch/arm/include/asm/elf.h | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/include/asm/elf.h +3 -0
index b98b3e52a..3def56769 100644
@@ -30,6 +30,9 @@ typedef struct user_fp elf_fpregset_t;
 #define R_ARM_CALL	28
 #define R_ARM_JUMP24	29
 
+#define R_ARM_THM_CALL		10
+#define R_ARM_THM_JUMP24	30
+
 /*
  * These are used to set parameters in the core dumps.
  */
Signature · 7 lines
2.27.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#8 lore raw

RFC PATCH 8/8 arm: module: Allow modules outside of bl range

In reply to David Dgien

Unlike the Linux kernel, barebox does not have a dedicated heap for storing modules. Therefore, if the system memory configuration places the general heap further away than can be reached by a 'bl' instruction (24 bits of address, or 16 MiB), then the module relocations will fail due to being out of range.

Allocate PLTs when loading modules so that jumps and calls whose targets are too far away for their relative offsets to be encoded in the instructions themselves can be bounced via veneers in the module's PLT. The modules will use slightly more memory, but after rounding up to page size, the actual memory footprint is usually the same.

Adoption of Linux commits:

66e94ba3c8ea ARM: kernel: avoid brute force search on PLT generation 1031a7e674d1 ARM: kernel: sort relocation sections before allocating PLTs 05123fef0982 ARM: kernel: allocate PLT entries only for external symbols 35fa91eed817 ARM: kernel: merge core and init PLTs 7d485f647c1f ARM: 8220/1: allow modules outside of bl range

---
 arch/arm/Kconfig              |  15 +++
 arch/arm/Makefile             |   4 +
 arch/arm/cpu/Kconfig          |   1 +
 arch/arm/include/asm/module.h |  44 ++++++-
 arch/arm/lib32/Makefile       |   1 +
 arch/arm/lib32/module-plts.c  | 229 ++++++++++++++++++++++++++++++++++
 arch/arm/lib32/module.c       |  14 +++
 arch/arm/lib32/module.lds     |   4 +
 8 files changed, 306 insertions(+), 6 deletions(-)
 create mode 100644 arch/arm/lib32/module-plts.c
 create mode 100644 arch/arm/lib32/module.lds
arch/arm/Kconfig +15 -0
index dfb18777b..95fd8ecfe 100644
@@ -477,4 +477,19 @@ config ARM_PSCI_DEBUG
 	  putc function.
 	  Only use for debugging.
 
+config ARM_MODULE_PLTS
+	bool "Use PLTs to allow loading modules placed far from barebox image"
+	depends on MODULES
+	select QSORT
+	help
+	  Allocate PLTs when loading modules so that jumps and calls whose
+	  targets are too far away for their relative offsets to be encoded
+	  in the instructions themselves can be bounced via veneers in the
+	  module's PLT. The modules will use slightly more memory, but after
+	  rounding up to page size, the actual memory footprint is usually
+	  the same.
+
+	  Say y if your memory configuration puts the heap to far away from the
+	  barebox image, causing relocation out of range errors
+
 endmenu
arch/arm/Makefile +4 -0
index c18a1d802..6ba0a6261 100644
@@ -18,6 +18,10 @@ AS		+= -EL
 LD		+= -EL
 endif
 
+ifeq ($(CONFIG_ARM_MODULE_PLTS),y)
+LDFLAGS_MODULE   += -T $(srctree)/arch/arm/lib32/module.lds
+endif
+
 # Unaligned access is not supported when MMU is disabled, so given how
 # at least some of the code would be executed with MMU off, lets be
 # conservative and instruct the compiler not to generate any unaligned
arch/arm/cpu/Kconfig +1 -0
index 6b4fed526..f9f52a625 100644
@@ -6,6 +6,7 @@ config PHYS_ADDR_T_64BIT
 config CPU_32
 	bool
 	select HAS_MODULES
+	select HAVE_MOD_ARCH_SPECIFIC
 	select HAS_DMA
 	select HAVE_PBL_IMAGE
 
arch/arm/include/asm/module.h +38 -6

51 lines not on this page · raw message

arch/arm/lib32/Makefile +1 -0
index 597bc0790..ec6a3aea6 100644
@@ -23,6 +23,7 @@ obj-$(CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS)	+= memset.o
 obj-$(CONFIG_ARM_UNWIND) += unwind.o
 obj-$(CONFIG_ARM_SEMIHOSTING) += semihosting-trap.o semihosting.o
 obj-$(CONFIG_MODULES) += module.o
+obj-$(CONFIG_ARM_MODULE_PLTS) += module-plts.o
 extra-y += barebox.lds
 
 pbl-y	+= lib1funcs.o
arch/arm/lib32/module-plts.c new file +229 -0

229 lines not on this page · raw message

arch/arm/lib32/module.c +14 -0
index be7965d59..3ded9896b 100644
@@ -64,6 +64,20 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
 				offset -= 0x04000000;
 
 			offset += sym->st_value - loc;
+
+			/*
+			 * Route through a PLT entry if 'offset' exceeds the
+			 * supported range. Note that 'offset + loc + 8'
+			 * contains the absolute jump target, i.e.,
+			 * @sym + addend, corrected for the +8 PC bias.
+			 */
+			if (IS_ENABLED(CONFIG_ARM_MODULE_PLTS) &&
+			    (offset <= (s32)0xfe000000 ||
+			     offset >= (s32)0x02000000))
+				offset = get_module_plt(module, loc,
+							offset + loc + 8)
+					 - loc - 8;
+
 			if (offset & 3 ||
 			    offset <= (s32)0xfe000000 ||
 			    offset >= (s32)0x02000000) {
arch/arm/lib32/module.lds new file +4 -0
new file mode 100644
index 000000000..0dd204608
@@ -0,0 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+SECTIONS {
+	.plt : { BYTE(0) }
+}
Signature · 7 lines
2.27.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#10 lore raw
In reply to David Dgien

Hi David,

Quoted 9 lines · David Dgien

This series fixes various bugs and bit-rot issues with the module loading code. It also ports a couple of modules features from the Linux
kernel: arch specific section fixups, and module PLTs for ARM modules, to contain veneers for 'bl' instructions.

There are two things in this series I'm looking for feedback on:
Linux implements module_frob_arch_sections as a weak symbol for the default case. I didn't see any other "weak" functions in barebox, so I wasn't sure if using that was acceptable.

For things that are really mutually exclusive like different implementations on different architectures I think weak functions are ok. They are not ok as a quick hack for hooking something into something though.

Quoted 11 lines

Since the Kconfig
HAVE_MOD_ARCH_SPECIFIC already exists as part of the change, I just used that to define a static inline default implementation, but using a weak function would make that slightly cleaner.

And in the patch that added the init macros to module.h, I wasn't sure if it would be okay to pollute init.h with the #ifndef MODULE directives, so instead I just #undef'd all of the initcalls before redefining them in module.h. If it's okay to add the #ifndef MODULE to init.h, that would be significantly cleaner than the current implementation.

I think it's ok to add #ifndef MODULE to init.h

Anyway, what do you need modules for? Do you have a good reason or is it just for the fun of it?

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw

Re: [RFC PATCH 8/8] arm: module: Allow modules outside of bl range

In reply to David Dgien
Quoted 5 lines · David Dgien

Unlike the Linux kernel, barebox does not have a dedicated heap for storing modules. Therefore, if the system memory configuration places the general heap further away than can be reached by a 'bl' instruction (24 bits of address, or 16 MiB), then the module relocations will fail due to being out of range.

At least the tlsf malloc implementation allows for multiple heaps. It might be easier to just add another heap just below the barebox image.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#11 lore raw
In reply to Sascha Hauer

Hi Sascha,

Quoted 13 lines · Sascha Hauer

Hi David,

Quoted 9 lines · David Dgien

This series fixes various bugs and bit-rot issues with the module loading code. It also ports a couple of modules features from the Linux
kernel: arch specific section fixups, and module PLTs for ARM modules, to contain veneers for 'bl' instructions.

There are two things in this series I'm looking for feedback on:
Linux implements module_frob_arch_sections as a weak symbol for the default case. I didn't see any other "weak" functions in barebox, so I wasn't sure if using that was acceptable.

Quoted 5 lines

For things that are really mutually exclusive like different implementations on different architectures I think weak functions are ok. They are not ok as a quick hack for hooking something into something though.

I'll make the change to a weak function here in a v2, since it will be a bit cleaner.

Quoted 5 lines
Quoted 5 lines

Since the Kconfig
HAVE_MOD_ARCH_SPECIFIC already exists as part of the change, I just used that to define a static inline default implementation, but using a weak function would make that slightly cleaner.

Quoted 8 lines
Quoted 6 lines

And in the patch that added the init macros to module.h, I wasn't sure if it would be okay to pollute init.h with the #ifndef MODULE directives, so instead I just #undef'd all of the initcalls before redefining them in module.h. If it's okay to add the #ifndef MODULE to init.h, that would be significantly cleaner than the current implementation.

I think it's ok to add #ifndef MODULE to init.h

Same as above.

Quoted 3 lines

Anyway, what do you need modules for? Do you have a good reason or is it just for the fun of it?

I'm working on a project that wants to use barebox as a very lightweight OS replacement. We're using modules to allow loading user code with controlled access to hw interfaces via exported driver symbols.

-- David Dgien

Quoted 8 lines

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#12 lore raw
Quoted 42 lines · David Dgien

Hi Sascha,

Quoted 13 lines · Sascha Hauer

Hi David,

Quoted 9 lines · David Dgien

This series fixes various bugs and bit-rot issues with the module loading code. It also ports a couple of modules features from the Linux
kernel: arch specific section fixups, and module PLTs for ARM modules, to contain veneers for 'bl' instructions.

There are two things in this series I'm looking for feedback on:
Linux implements module_frob_arch_sections as a weak symbol for the default case. I didn't see any other "weak" functions in barebox, so I wasn't sure if using that was acceptable.

Quoted 5 lines

For things that are really mutually exclusive like different implementations on different architectures I think weak functions are ok. They are not ok as a quick hack for hooking something into something though.

I'll make the change to a weak function here in a v2, since it will be a bit cleaner.

Quoted 5 lines
Quoted 5 lines

Since the Kconfig
HAVE_MOD_ARCH_SPECIFIC already exists as part of the change, I just used that to define a static inline default implementation, but using a weak function would make that slightly cleaner.

Quoted 8 lines
Quoted 6 lines

And in the patch that added the init macros to module.h, I wasn't sure if it would be okay to pollute init.h with the #ifndef MODULE directives, so instead I just #undef'd all of the initcalls before redefining them in module.h. If it's okay to add the #ifndef MODULE to init.h, that would be significantly cleaner than the current implementation.

I think it's ok to add #ifndef MODULE to init.h

Same as above.

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

Anyway, what do you need modules for? Do you have a good reason or is it just for the fun of it?

I'm working on a project that wants to use barebox as a very lightweight OS replacement.
We're using modules to allow loading user code with controlled access to hw interfaces via exported driver symbols.

So barebOS again, we had that as an April fools joke once :)

You'll probably miss things like interrupts, paging and multitasking very soon.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#13 lore raw
Quoted 52 lines · Sascha Hauer
Quoted 42 lines · David Dgien

Hi Sascha,

Quoted 13 lines · Sascha Hauer

Hi David,

Quoted 9 lines · David Dgien

This series fixes various bugs and bit-rot issues with the module loading code. It also ports a couple of modules features from the Linux
kernel: arch specific section fixups, and module PLTs for ARM modules, to contain veneers for 'bl' instructions.

There are two things in this series I'm looking for feedback on:
Linux implements module_frob_arch_sections as a weak symbol for the default case. I didn't see any other "weak" functions in barebox, so I wasn't sure if using that was acceptable.

Quoted 5 lines

For things that are really mutually exclusive like different implementations on different architectures I think weak functions are ok. They are not ok as a quick hack for hooking something into something though.

I'll make the change to a weak function here in a v2, since it will be a bit cleaner.

Quoted 5 lines
Quoted 5 lines

Since the Kconfig
HAVE_MOD_ARCH_SPECIFIC already exists as part of the change, I just used that to define a static inline default implementation, but using a weak function would make that slightly cleaner.

Quoted 8 lines
Quoted 6 lines

And in the patch that added the init macros to module.h, I wasn't sure if it would be okay to pollute init.h with the #ifndef MODULE directives, so instead I just #undef'd all of the initcalls before redefining them in module.h. If it's okay to add the #ifndef MODULE to init.h, that would be significantly cleaner than the current implementation.

I think it's ok to add #ifndef MODULE to init.h

Same as above.

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

Anyway, what do you need modules for? Do you have a good reason or is it just for the fun of it?

I'm working on a project that wants to use barebox as a very lightweight OS replacement.
We're using modules to allow loading user code with controlled access to hw interfaces via exported driver symbols.

Quoted 6 lines

So barebOS again, we had that as an April fools joke once :)

You'll probably miss things like interrupts, paging and multitasking very soon.

Sascha

Does it make sense to choose y/m
depending on how often they are used?

- commands and drivers that are used quite often   ->  built-in
- commands and drivers that are sometimes used     ->  modules
Signature · 7 lines
Best Regards
Masahiro Yamada

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox