From: shea@shealevy.com (Shea Levy) Date: Thu, 01 Mar 2018 06:23:25 -0500 Subject: [PATCH 2/9] RISC-V: Load modules within relative jump range of the kernel text. In-Reply-To: References: Message-ID: <87fu5k2g5u.fsf@xps13.shealevy.com> To: linux-riscv@lists.infradead.org List-Id: linux-riscv.lists.infradead.org Hi Palmer, Palmer Dabbelt writes: > On Thu, 22 Feb 2018 19:12:11 PST (-0800), shea at shealevy.com wrote: >> Signed-off-by: Shea Levy >> --- >> arch/riscv/include/asm/pgtable.h | 9 +++++++++ >> arch/riscv/kernel/module.c | 11 +++++++++++ >> 2 files changed, 20 insertions(+) >> >> diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h >> index 16301966d65b..b08ded13364a 100644 >> --- a/arch/riscv/include/asm/pgtable.h >> +++ b/arch/riscv/include/asm/pgtable.h >> @@ -25,6 +25,7 @@ >> #include >> #include >> #include >> +#include >> >> #ifdef CONFIG_64BIT >> #include >> @@ -425,6 +426,14 @@ static inline void pgtable_cache_init(void) >> #define TASK_SIZE VMALLOC_START >> #endif >> >> +/* >> + * The module space lives between the addresses given by TASK_SIZE >> + * and PAGE_OFFSET - it must be within 2G of the kernel text. >> + */ >> +#define MODULES_SIZE (SZ_128M) >> +#define MODULES_VADDR (PAGE_OFFSET - MODULES_SIZE) >> +#define MODULES_END (VMALLOC_END) >> + >> #include >> >> #endif /* !__ASSEMBLY__ */ >> diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c >> index e0f05034fc21..8ad24bdf69de 100644 >> --- a/arch/riscv/kernel/module.c >> +++ b/arch/riscv/kernel/module.c >> @@ -16,6 +16,8 @@ >> #include >> #include >> #include >> +#include >> +#include >> >> static int apply_r_riscv_64_rela(struct module *me, u32 *location, Elf_Addr v) >> { >> @@ -215,3 +217,12 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, >> >> return 0; >> } >> + >> +void *module_alloc(unsigned long size) >> +{ >> + return __vmalloc_node_range(size, 1, MODULES_VADDR, >> + MODULES_END, GFP_KERNEL, >> + PAGE_KERNEL_EXEC, 0, >> + NUMA_NO_NODE, >> + __builtin_return_address(0)); >> +} > > arm64 aligns their modules to a page boundary. I think we need to align them > to at least whatever the linker is expecting, which should be recorded in each > segment in the ELF that's provided. > > This code otherwise looks exactly teh same as MIPS, maybe we should make it > generic somewhere? It's not that much, though, but it looks like it'll get > bigger as things support KASLR and such. Thanks, I'll include this fix when I resolve the RISCV_ALIGN issue, and see if it makes sense to make generic. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 832 bytes Desc: not available URL: