mirror of
https://git.proxmox.com/git/mirror_ubuntu-kernels.git
synced 2025-11-08 04:35:48 +00:00
module_alloc() is used everywhere as a mean to allocate memory for code. Beside being semantically wrong, this unnecessarily ties all subsystems that need to allocate code, such as ftrace, kprobes and BPF to modules and puts the burden of code allocation to the modules code. Several architectures override module_alloc() because of various constraints where the executable memory can be located and this causes additional obstacles for improvements of code allocation. Start splitting code allocation from modules by introducing execmem_alloc() and execmem_free() APIs. Initially, execmem_alloc() is a wrapper for module_alloc() and execmem_free() is a replacement of module_memfree() to allow updating all call sites to use the new APIs. Since architectures define different restrictions on placement, permissions, alignment and other parameters for memory that can be used by different subsystems that allocate executable memory, execmem_alloc() takes a type argument, that will be used to identify the calling subsystem and to allow architectures define parameters for ranges suitable for that subsystem. No functional changes. Signed-off-by: Mike Rapoport (IBM) <rppt@kernel.org> Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Acked-by: Song Liu <song@kernel.org> Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
138 lines
4.1 KiB
C
138 lines
4.1 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _LINUX_MODULELOADER_H
|
|
#define _LINUX_MODULELOADER_H
|
|
/* The stuff needed for archs to support modules. */
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/elf.h>
|
|
|
|
/* These may be implemented by architectures that need to hook into the
|
|
* module loader code. Architectures that don't need to do anything special
|
|
* can just rely on the 'weak' default hooks defined in kernel/module.c.
|
|
* Note, however, that at least one of apply_relocate or apply_relocate_add
|
|
* must be implemented by each architecture.
|
|
*/
|
|
|
|
/* arch may override to do additional checking of ELF header architecture */
|
|
bool module_elf_check_arch(Elf_Ehdr *hdr);
|
|
|
|
/* Adjust arch-specific sections. Return 0 on success. */
|
|
int module_frob_arch_sections(Elf_Ehdr *hdr,
|
|
Elf_Shdr *sechdrs,
|
|
char *secstrings,
|
|
struct module *mod);
|
|
|
|
/* Additional bytes needed by arch in front of individual sections */
|
|
unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
|
|
|
|
/* Allocator used for allocating struct module, core sections and init
|
|
sections. Returns NULL on failure. */
|
|
void *module_alloc(unsigned long size);
|
|
|
|
/* Determines if the section name is an init section (that is only used during
|
|
* module loading).
|
|
*/
|
|
bool module_init_section(const char *name);
|
|
|
|
/* Determines if the section name is an exit section (that is only used during
|
|
* module unloading)
|
|
*/
|
|
bool module_exit_section(const char *name);
|
|
|
|
/* Describes whether within_module_init() will consider this an init section
|
|
* or not. This behaviour changes with CONFIG_MODULE_UNLOAD.
|
|
*/
|
|
bool module_init_layout_section(const char *sname);
|
|
|
|
/*
|
|
* Apply the given relocation to the (simplified) ELF. Return -error
|
|
* or 0.
|
|
*/
|
|
#ifdef CONFIG_MODULES_USE_ELF_REL
|
|
int apply_relocate(Elf_Shdr *sechdrs,
|
|
const char *strtab,
|
|
unsigned int symindex,
|
|
unsigned int relsec,
|
|
struct module *mod);
|
|
#else
|
|
static inline int apply_relocate(Elf_Shdr *sechdrs,
|
|
const char *strtab,
|
|
unsigned int symindex,
|
|
unsigned int relsec,
|
|
struct module *me)
|
|
{
|
|
printk(KERN_ERR "module %s: REL relocation unsupported\n",
|
|
module_name(me));
|
|
return -ENOEXEC;
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
* Apply the given add relocation to the (simplified) ELF. Return
|
|
* -error or 0
|
|
*/
|
|
#ifdef CONFIG_MODULES_USE_ELF_RELA
|
|
int apply_relocate_add(Elf_Shdr *sechdrs,
|
|
const char *strtab,
|
|
unsigned int symindex,
|
|
unsigned int relsec,
|
|
struct module *mod);
|
|
#ifdef CONFIG_LIVEPATCH
|
|
/*
|
|
* Some architectures (namely x86_64 and ppc64) perform sanity checks when
|
|
* applying relocations. If a patched module gets unloaded and then later
|
|
* reloaded (and re-patched), klp re-applies relocations to the replacement
|
|
* function(s). Any leftover relocations from the previous loading of the
|
|
* patched module might trigger the sanity checks.
|
|
*
|
|
* To prevent that, when unloading a patched module, clear out any relocations
|
|
* that might trigger arch-specific sanity checks on a future module reload.
|
|
*/
|
|
void clear_relocate_add(Elf_Shdr *sechdrs,
|
|
const char *strtab,
|
|
unsigned int symindex,
|
|
unsigned int relsec,
|
|
struct module *me);
|
|
#endif
|
|
#else
|
|
static inline int apply_relocate_add(Elf_Shdr *sechdrs,
|
|
const char *strtab,
|
|
unsigned int symindex,
|
|
unsigned int relsec,
|
|
struct module *me)
|
|
{
|
|
printk(KERN_ERR "module %s: REL relocation unsupported\n",
|
|
module_name(me));
|
|
return -ENOEXEC;
|
|
}
|
|
#endif
|
|
|
|
/* Any final processing of module before access. Return -error or 0. */
|
|
int module_finalize(const Elf_Ehdr *hdr,
|
|
const Elf_Shdr *sechdrs,
|
|
struct module *mod);
|
|
|
|
#ifdef CONFIG_MODULES
|
|
void flush_module_init_free_work(void);
|
|
#else
|
|
static inline void flush_module_init_free_work(void)
|
|
{
|
|
}
|
|
#endif
|
|
|
|
/* Any cleanup needed when module leaves. */
|
|
void module_arch_cleanup(struct module *mod);
|
|
|
|
/* Any cleanup before freeing mod->module_init */
|
|
void module_arch_freeing_init(struct module *mod);
|
|
|
|
#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \
|
|
!defined(CONFIG_KASAN_VMALLOC)
|
|
#include <linux/kasan.h>
|
|
#define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)
|
|
#else
|
|
#define MODULE_ALIGN PAGE_SIZE
|
|
#endif
|
|
|
|
#endif
|