powerpc: extend execmem_params for kprobes allocations
Subsystems (23)
PATCH v5 10/15 powerpc: extend execmem_params for kprobes allocations
From: "Mike Rapoport (IBM)" <[email protected]>
powerpc overrides kprobes::alloc_insn_page() to remove writable permissions when STRICT_MODULE_RWX is on.
Add definition of EXECMEM_KRPOBES to execmem_params to allow using the generic kprobes::alloc_insn_page() with the desired permissions.
As powerpc uses breakpoint instructions to inject kprobes, it does not need to constrain kprobe allocations to the modules area and can use the entire vmalloc address space.
--- arch/powerpc/kernel/kprobes.c | 20 -------------------- arch/powerpc/kernel/module.c | 7 +++++++ 2 files changed, 7 insertions(+), 20 deletions(-)
arch/powerpc/kernel/kprobes.c +0 -20
@@ -126,26 +126,6 @@ kprobe_opcode_t *arch_adjust_kprobe_addr(unsigned long addr, unsigned long offsereturn (kprobe_opcode_t *)(addr + offset); } -void *alloc_insn_page (void ) -{ -void *page; - - page =execmem_alloc (EXECMEM_KPROBES ,PAGE_SIZE ); -if (!page) -return NULL ; - -if (strict_module_rwx_enabled ()) { -int err =set_memory_rox ((unsigned long )page,1 ); - -if (err) - goto error; - } -return page; -error: -execmem_free (page); -return NULL ; -} -int arch_prepare_kprobe (struct kprobe *p) {int ret =0 ;
arch/powerpc/kernel/module.c +7 -0
@@ -94,6 +94,7 @@ static struct execmem_info execmem_info __ro_after_init;struct execmem_info __init *execmem_arch_setup (void ) { +pgprot_t kprobes_prot =strict_module_rwx_enabled () ?PAGE_KERNEL_ROX :PAGE_KERNEL_EXEC ;pgprot_t prot =strict_module_rwx_enabled () ?PAGE_KERNEL :PAGE_KERNEL_EXEC ;unsigned long fallback_start =0 , fallback_end =0 ;unsigned long start, end;
@@ -132,6 +133,12 @@ struct execmem_info __init *execmem_arch_setup(void) .fallback_start = fallback_start, .fallback_end = fallback_end, }, + [EXECMEM_KPROBES] = { + .start = VMALLOC_START, + .end = VMALLOC_END, + .pgprot = kprobes_prot, + .alignment = 1, + }, [EXECMEM_MODULE_DATA] = { .start = VMALLOC_START, .end = VMALLOC_END,
Signature · 1 line
2.43.0
PATCH v5 11/15 arch: make execmem setup available regardless of CONFIG_MODULES
From: "Mike Rapoport (IBM)" <[email protected]>
execmem does not depend on modules, on the contrary modules use execmem.
To make execmem available when CONFIG_MODULES=n, for instance for kprobes, split execmem_params initialization out from arch/*/kernel/module.c and compile it when CONFIG_EXECMEM=y
--- arch/arm/kernel/module.c | 43 ---------- arch/arm/mm/init.c | 45 +++++++++++ arch/arm64/kernel/module.c | 140 --------------------------------- arch/arm64/mm/init.c | 140 +++++++++++++++++++++++++++++++++ arch/loongarch/kernel/module.c | 19 ----- arch/loongarch/mm/init.c | 21 +++++ arch/mips/kernel/module.c | 22 ------ arch/mips/mm/init.c | 23 ++++++ arch/nios2/kernel/module.c | 20 ----- arch/nios2/mm/init.c | 21 +++++ arch/parisc/kernel/module.c | 20 ----- arch/parisc/mm/init.c | 23 +++++- arch/powerpc/kernel/module.c | 63 --------------- arch/powerpc/mm/mem.c | 64 +++++++++++++++ arch/riscv/kernel/module.c | 44 ----------- arch/riscv/mm/init.c | 45 +++++++++++ arch/s390/kernel/module.c | 27 ------- arch/s390/mm/init.c | 30 +++++++ arch/sparc/kernel/module.c | 19 ----- arch/sparc/mm/Makefile | 2 + arch/sparc/mm/execmem.c | 21 +++++ arch/x86/kernel/module.c | 27 ------- arch/x86/mm/init.c | 29 +++++++ 23 files changed, 463 insertions(+), 445 deletions(-) create mode 100644 arch/sparc/mm/execmem.c
arch/arm/kernel/module.c +0 -43
@@ -12,57 +12,14 @@#include <linux/kernel.h> #include <linux/mm.h> #include <linux/elf.h> -#include <linux/vmalloc.h> #include <linux/fs.h> #include <linux/string.h> -#include <linux/gfp.h> -#include <linux/execmem.h> #include <asm/sections.h> #include <asm/smp_plat.h> #include <asm/unwind.h> #include <asm/opcodes.h> -#ifdef CONFIG_XIP_KERNEL -/* -* The XIP kernel text is mapped in the module area for modules and -* some other stuff to work without any indirect relocations. -* MODULES_VADDR is redefined here and not in asm/memory.h to avoid -* recompiling the whole kernel when CONFIG_XIP_KERNEL is turned on/off. -*/ -#undef MODULES_VADDR -#define MODULES_VADDR (((unsigned long)_exiprom + ~PMD_MASK) & PMD_MASK) -#endif - -#ifdef CONFIG_MMU -static struct execmem_info execmem_info__ro_after_init ; - -struct execmem_info __init *execmem_arch_setup (void ) -{ -unsigned long fallback_start =0 , fallback_end =0 ; - -if (IS_ENABLED (CONFIG_ARM_MODULE_PLTS )) { - fallback_start =VMALLOC_START ; - fallback_end =VMALLOC_END ; - } - - execmem_info = (struct execmem_info ){ - .ranges = { - [EXECMEM_DEFAULT ] = { - .start =MODULES_VADDR , - .end =MODULES_END , - .pgprot =PAGE_KERNEL_EXEC , - .alignment =1 , - .fallback_start = fallback_start, - .fallback_end = fallback_end, - }, - }, - }; - -return &execmem_info; -} -#endif -bool module_init_section (const char *name) { return strstarts(name, ".init") ||
arch/arm/mm/init.c +45 -0
54 lines not on this page · raw message
arch/arm64/kernel/module.c +0 -140
158 lines not on this page · raw message
arch/arm64/mm/init.c +140 -0
149 lines not on this page · raw message
arch/loongarch/kernel/module.c +0 -19
@@ -18,7 +18,6 @@#include <linux/ftrace.h> #include <linux/string.h> #include <linux/kernel.h> -#include <linux/execmem.h> #include <asm/alternative.h> #include <asm/inst.h> #include <asm/unwind.h>
@@ -491,24 +490,6 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,return 0 ; } -static struct execmem_info execmem_info__ro_after_init ; - -struct execmem_info __init *execmem_arch_setup (void ) -{ - execmem_info = (struct execmem_info ){ - .ranges = { - [EXECMEM_DEFAULT ] = { - .start =MODULES_VADDR , - .end =MODULES_END , - .pgprot =PAGE_KERNEL , - .alignment =1 , - }, - }, - }; - -return &execmem_info; -} -static void module_init_ftrace_plt (const Elf_Ehdr *hdr,const Elf_Shdr *sechdrs,struct module *mod) {
arch/loongarch/mm/init.c +21 -0
@@ -24,6 +24,7 @@#include <linux/gfp.h> #include <linux/hugetlb.h> #include <linux/mmzone.h> +#include <linux/execmem.h> #include <asm/asm-offsets.h> #include <asm/bootinfo.h>
@@ -248,3 +249,23 @@ EXPORT_SYMBOL(invalid_pmd_table);#endif pte_t invalid_pte_table[PTRS_PER_PTE] __page_aligned_bss;EXPORT_SYMBOL (invalid_pte_table); + +#ifdef CONFIG_EXECMEM +static struct execmem_info execmem_info__ro_after_init ; + +struct execmem_info __init *execmem_arch_setup (void ) +{ + execmem_info = (struct execmem_info ){ + .ranges = { + [EXECMEM_DEFAULT ] = { + .start =MODULES_VADDR , + .end =MODULES_END , + .pgprot =PAGE_KERNEL , + .alignment =1 , + }, + }, + }; + +return &execmem_info; +} +#endif /* CONFIG_EXECMEM */
arch/mips/kernel/module.c +0 -22
@@ -13,14 +13,12 @@#include <linux/elf.h> #include <linux/mm.h> #include <linux/numa.h> -#include <linux/vmalloc.h> #include <linux/slab.h> #include <linux/fs.h> #include <linux/string.h> #include <linux/kernel.h> #include <linux/spinlock.h> #include <linux/jump_label.h> -#include <linux/execmem.h> #include <asm/jump_label.h> struct mips_hi16 {
@@ -32,26 +30,6 @@ struct mips_hi16 {static LIST_HEAD (dbe_list);static DEFINE_SPINLOCK (dbe_lock); -#ifdef MODULES_VADDR -static struct execmem_info execmem_info__ro_after_init ; - -struct execmem_info __init *execmem_arch_setup (void ) -{ - execmem_info = (struct execmem_info ){ - .ranges = { - [EXECMEM_DEFAULT ] = { - .start =MODULES_VADDR , - .end =MODULES_END , - .pgprot =PAGE_KERNEL , - .alignment =1 , - }, - }, - }; - -return &execmem_info; -} -#endif -static void apply_r_mips_32 (u32 *location,u32 base,Elf_Addr v) { *location = base + v;
arch/mips/mm/init.c +23 -0
@@ -31,6 +31,7 @@#include <linux/gfp.h> #include <linux/kcore.h> #include <linux/initrd.h> +#include <linux/execmem.h> #include <asm/bootinfo.h> #include <asm/cachectl.h>
@@ -576,3 +577,25 @@ EXPORT_SYMBOL_GPL(invalid_pmd_table);#endif pte_t invalid_pte_table[PTRS_PER_PTE] __page_aligned_bss;EXPORT_SYMBOL (invalid_pte_table); + +#ifdef CONFIG_EXECMEM +#ifdef MODULES_VADDR +static struct execmem_info execmem_info__ro_after_init ; + +struct execmem_info __init *execmem_arch_setup (void ) +{ + execmem_info = (struct execmem_info ){ + .ranges = { + [EXECMEM_DEFAULT ] = { + .start =MODULES_VADDR , + .end =MODULES_END , + .pgprot =PAGE_KERNEL , + .alignment =1 , + }, + }, + }; + +return &execmem_info; +} +#endif +#endif /* CONFIG_EXECMEM */
arch/nios2/kernel/module.c +0 -20
@@ -13,33 +13,13 @@#include <linux/moduleloader.h> #include <linux/elf.h> #include <linux/mm.h> -#include <linux/vmalloc.h> #include <linux/slab.h> #include <linux/fs.h> #include <linux/string.h> #include <linux/kernel.h> -#include <linux/execmem.h> #include <asm/cacheflush.h> -static struct execmem_info execmem_info__ro_after_init ; - -struct execmem_info __init *execmem_arch_setup (void ) -{ - execmem_info = (struct execmem_info ){ - .ranges = { - [EXECMEM_DEFAULT ] = { - .start =MODULES_VADDR , - .end =MODULES_END , - .pgprot =PAGE_KERNEL_EXEC , - .alignment =1 , - }, - }, - }; - -return &execmem_info; -} -int apply_relocate_add (Elf32_Shdr *sechdrs,const char *strtab,unsigned int symindex,unsigned int relsec,struct module *mod)
arch/nios2/mm/init.c +21 -0
@@ -26,6 +26,7 @@#include <linux/memblock.h> #include <linux/slab.h> #include <linux/binfmts.h> +#include <linux/execmem.h> #include <asm/setup.h> #include <asm/page.h>
@@ -143,3 +144,23 @@ static const pgprot_t protection_map[16] = { [VM_SHARED |VM_EXEC |VM_WRITE |VM_READ ] =MKP (1 ,1 ,1 ) }; DECLARE_VM_GET_PAGE_PROT + +#ifdef CONFIG_EXECMEM +static struct execmem_info execmem_info__ro_after_init ; + +struct execmem_info __init *execmem_arch_setup (void ) +{ + execmem_info = (struct execmem_info ){ + .ranges = { + [EXECMEM_DEFAULT ] = { + .start =MODULES_VADDR , + .end =MODULES_END , + .pgprot =PAGE_KERNEL_EXEC , + .alignment =1 , + }, + }, + }; + +return &execmem_info; +} +#endif /* CONFIG_EXECMEM */
arch/parisc/kernel/module.c +0 -20
@@ -41,7 +41,6 @@#include <linux/moduleloader.h> #include <linux/elf.h> -#include <linux/vmalloc.h> #include <linux/fs.h> #include <linux/ftrace.h> #include <linux/string.h>
@@ -49,7 +48,6 @@#include <linux/bug.h> #include <linux/mm.h> #include <linux/slab.h> -#include <linux/execmem.h> #include <asm/unwind.h> #include <asm/sections.h>
@@ -174,24 +172,6 @@ static inline int reassemble_22(int as22) ((as22 & 0x0003ff) << 3)); } -static struct execmem_info execmem_info__ro_after_init ; - -struct execmem_info __init *execmem_arch_setup (void ) -{ - execmem_info = (struct execmem_info ){ - .ranges = { - [EXECMEM_DEFAULT ] = { - .start =VMALLOC_START , - .end =VMALLOC_END , - .pgprot =PAGE_KERNEL_RWX , - .alignment =1 , - }, - }, - }; - -return &execmem_info; -} -#ifndef CONFIG_64BIT static inline unsigned long count_gots (const Elf_Rela *rela,unsigned long n) {
arch/parisc/mm/init.c +22 -1
@@ -24,6 +24,7 @@#include <linux/nodemask.h> /* for node_online_map */ #include <linux/pagemap.h> /* for release_pages */ #include <linux/compat.h> +#include <linux/execmem.h> #include <asm/pgalloc.h> #include <asm/tlb.h>
@@ -481,7 +482,7 @@ void free_initmem(void)/* finally dump all the instructions which were cached, since the * pages are no-longer executable */ flush_icache_range (init_begin, init_end); - +free_initmem_default (POISON_FREE_INITMEM );/* set up a new led state on systems shipped LED State panel */
@@ -992,3 +993,23 @@ static const pgprot_t protection_map[16] = { [VM_SHARED |VM_EXEC |VM_WRITE |VM_READ ] =PAGE_RWX }; DECLARE_VM_GET_PAGE_PROT + +#ifdef CONFIG_EXECMEM +static struct execmem_info execmem_info__ro_after_init ; + +struct execmem_info __init *execmem_arch_setup (void ) +{ + execmem_info = (struct execmem_info ){ + .ranges = { + [EXECMEM_DEFAULT ] = { + .start =VMALLOC_START , + .end =VMALLOC_END , + .pgprot =PAGE_KERNEL_RWX , + .alignment =1 , + }, + }, + }; + +return &execmem_info; +} +#endif /* CONFIG_EXECMEM */
arch/powerpc/kernel/module.c +0 -63
74 lines not on this page · raw message
arch/powerpc/mm/mem.c +64 -0
73 lines not on this page · raw message
arch/riscv/kernel/module.c +0 -44
58 lines not on this page · raw message
arch/riscv/mm/init.c +45 -0
54 lines not on this page · raw message
arch/s390/kernel/module.c +0 -27
@@ -37,33 +37,6 @@#define PLT_ENTRY_SIZE 22 -static struct execmem_info execmem_info__ro_after_init ; - -struct execmem_info __init *execmem_arch_setup (void ) -{ -unsigned long module_load_offset =0 ; -unsigned long start; - -if (kaslr_enabled ()) - module_load_offset =get_random_u32_inclusive (1 ,1024 ) *PAGE_SIZE ; - - start =MODULES_VADDR + module_load_offset; - - execmem_info = (struct execmem_info ){ - .ranges = { - [EXECMEM_DEFAULT ] = { - .flags =EXECMEM_KASAN_SHADOW , - .start = start, - .end =MODULES_END , - .pgprot =PAGE_KERNEL , - .alignment =MODULE_ALIGN , - }, - }, - }; - -return &execmem_info; -} -#ifdef CONFIG_FUNCTION_TRACER void module_arch_cleanup (struct module *mod) {
arch/s390/mm/init.c +30 -0
@@ -49,6 +49,7 @@#include <asm/uv.h> #include <linux/virtio_anchor.h> #include <linux/virtio_config.h> +#include <linux/execmem.h> pgd_t swapper_pg_dir[PTRS_PER_PGD] __section(".bss..swapper_pg_dir"); pgd_t invalid_pg_dir[PTRS_PER_PGD] __section(".bss..invalid_pg_dir");
@@ -302,3 +303,32 @@ void arch_remove_memory(u64 start, u64 size, struct vmem_altmap *altmap) vmem_remove_mapping(start, size); }#endif /* CONFIG_MEMORY_HOTPLUG */ + +#ifdef CONFIG_EXECMEM +static struct execmem_info execmem_info__ro_after_init ; + +struct execmem_info __init *execmem_arch_setup (void ) +{ +unsigned long module_load_offset =0 ; +unsigned long start; + +if (kaslr_enabled ()) + module_load_offset =get_random_u32_inclusive (1 ,1024 ) *PAGE_SIZE ; + + start =MODULES_VADDR + module_load_offset; + + execmem_info = (struct execmem_info ){ + .ranges = { + [EXECMEM_DEFAULT ] = { + .flags =EXECMEM_KASAN_SHADOW , + .start = start, + .end =MODULES_END , + .pgprot =PAGE_KERNEL , + .alignment =MODULE_ALIGN , + }, + }, + }; + +return &execmem_info; +} +#endif /* CONFIG_EXECMEM */
arch/sparc/kernel/module.c +0 -19
@@ -14,7 +14,6 @@#include <linux/string.h> #include <linux/ctype.h> #include <linux/mm.h> -#include <linux/execmem.h> #include <asm/processor.h> #include <asm/spitfire.h>
@@ -22,24 +21,6 @@#include "entry.h" -static struct execmem_info execmem_info__ro_after_init ; - -struct execmem_info __init *execmem_arch_setup (void ) -{ - execmem_info = (struct execmem_info ){ - .ranges = { - [EXECMEM_DEFAULT ] = { - .start =MODULES_VADDR , - .end =MODULES_END , - .pgprot =PAGE_KERNEL , - .alignment =1 , - }, - }, - }; - -return &execmem_info; -} -/* Make generic code ignore STT_REGISTER dummy undefined symbols. */ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
arch/sparc/mm/Makefile +2 -0
@@ -14,3 +14,5 @@ obj-$(CONFIG_SPARC32) += leon_mm.o # Only used by sparc64 obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o + +obj-$(CONFIG_EXECMEM) += execmem.o
arch/sparc/mm/execmem.c new file +21 -0
@@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/mm.h> +#include <linux/execmem.h> + +static struct execmem_info execmem_info__ro_after_init ; + +struct execmem_info __init *execmem_arch_setup (void ) +{ + execmem_info = (struct execmem_info ){ + .ranges = { + [EXECMEM_DEFAULT ] = { + .start =MODULES_VADDR , + .end =MODULES_END , + .pgprot =PAGE_KERNEL , + .alignment =1 , + }, + }, + }; + +return &execmem_info; +}
arch/x86/kernel/module.c +0 -27
@@ -19,7 +19,6 @@#include <linux/jump_label.h> #include <linux/random.h> #include <linux/memory.h> -#include <linux/execmem.h> #include <asm/text-patching.h> #include <asm/page.h>
@@ -37,32 +36,6 @@ do { \ } while (0)#endif -static struct execmem_info execmem_info__ro_after_init ; - -struct execmem_info __init *execmem_arch_setup (void ) -{ -unsigned long start, offset =0 ; - -if (kaslr_enabled ()) - offset =get_random_u32_inclusive (1 ,1024 ) *PAGE_SIZE ; - - start =MODULES_VADDR + offset; - - execmem_info = (struct execmem_info ){ - .ranges = { - [EXECMEM_DEFAULT ] = { - .flags =EXECMEM_KASAN_SHADOW , - .start = start, - .end =MODULES_END , - .pgprot =PAGE_KERNEL , - .alignment =MODULE_ALIGN , - }, - }, - }; - -return &execmem_info; -} -#ifdef CONFIG_X86_32 int apply_relocate(Elf32_Shdr *sechdrs, const char *strtab,
arch/x86/mm/init.c +29 -0
@@ -7,6 +7,7 @@#include <linux/swapops.h> #include <linux/kmemleak.h> #include <linux/sched/task.h> +#include <linux/execmem.h> #include <asm/set_memory.h> #include <asm/cpu_device_id.h>
@@ -1099,3 +1100,31 @@ unsigned long arch_max_swapfile_size(void) return pages; }#endif + +#ifdef CONFIG_EXECMEM +static struct execmem_info execmem_info__ro_after_init ; + +struct execmem_info __init *execmem_arch_setup (void ) +{ +unsigned long start, offset =0 ; + +if (kaslr_enabled ()) + offset =get_random_u32_inclusive (1 ,1024 ) *PAGE_SIZE ; + + start =MODULES_VADDR + offset; + + execmem_info = (struct execmem_info ){ + .ranges = { + [EXECMEM_DEFAULT ] = { + .flags =EXECMEM_KASAN_SHADOW , + .start = start, + .end =MODULES_END , + .pgprot =PAGE_KERNEL , + .alignment =MODULE_ALIGN , + }, + }, + }; + +return &execmem_info; +} +#endif /* CONFIG_EXECMEM */
Signature · 1 line
2.43.0
PATCH v5 12/15 x86/ftrace: enable dynamic ftrace without CONFIG_MODULES
In reply to Mike RapoportFrom: "Mike Rapoport (IBM)" <[email protected]>
Dynamic ftrace must allocate memory for code and this was impossible without CONFIG_MODULES.
With execmem separated from the modules code, execmem_text_alloc() is available regardless of CONFIG_MODULES.
Remove dependency of dynamic ftrace on CONFIG_MODULES and make CONFIG_DYNAMIC_FTRACE select CONFIG_EXECMEM in Kconfig.
--- arch/x86/Kconfig | 1 + arch/x86/kernel/ftrace.c | 10 ---------- 2 files changed, 1 insertion(+), 10 deletions(-)
arch/x86/Kconfig +1 -0
@@ -34,6 +34,7 @@ config X86_64 select SWIOTLB select ARCH_HAS_ELFCORE_COMPAT select ZONE_DMA32 + select EXECMEM if DYNAMIC_FTRACE config FORCE_DYNAMIC_FTRACE def_bool y
arch/x86/kernel/ftrace.c +0 -10
@@ -261,8 +261,6 @@ void arch_ftrace_update_code(int command)/* Currently only x86_64 supports dynamic trampolines */ #ifdef CONFIG_X86_64 -#ifdef CONFIG_MODULES -/* Module allocation simplifies allocating memory for code */static inline void *alloc_tramp (unsigned long size) {return execmem_alloc (EXECMEM_FTRACE , size);
@@ -271,14 +269,6 @@ static inline void tramp_free(void *tramp) {execmem_free (tramp); } -#else -/* Trampolines can only be created if modules are supported */ -static inline void *alloc_tramp (unsigned long size) -{ -return NULL ; -} -static inline void tramp_free (void *tramp) { } -#endif /* Defined as markers to the end of the ftrace default trampolines */ extern void ftrace_regs_caller_end (void );
Signature · 1 line
2.43.0
PATCH v5 13/15 powerpc: use CONFIG_EXECMEM instead of CONFIG_MODULES where appropriate
In reply to Mike RapoportFrom: "Mike Rapoport (IBM)" <[email protected]>
There are places where CONFIG_MODULES guards the code that depends on memory allocation being done with module_alloc().
Replace CONFIG_MODULES with CONFIG_EXECMEM in such places.
--- arch/powerpc/Kconfig | 2 +- arch/powerpc/include/asm/kasan.h | 2 +- arch/powerpc/kernel/head_8xx.S | 4 ++-- arch/powerpc/kernel/head_book3s_32.S | 6 +++--- arch/powerpc/lib/code-patching.c | 2 +- arch/powerpc/mm/book3s32/mmu.c | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-)
arch/powerpc/Kconfig +1 -1
@@ -285,7 +285,7 @@ config PPC select IOMMU_HELPER if PPC64 select IRQ_DOMAIN select IRQ_FORCED_THREADING - select KASAN_VMALLOC if KASAN && MODULES + select KASAN_VMALLOC if KASAN && EXECMEM select LOCK_MM_AND_FIND_VMA select MMU_GATHER_PAGE_SIZE select MMU_GATHER_RCU_TABLE_FREE
arch/powerpc/include/asm/kasan.h +1 -1
@@ -19,7 +19,7 @@#define KASAN_SHADOW_SCALE_SHIFT 3 -#if defined(CONFIG_MODULES ) && defined(CONFIG_PPC32 ) +#if defined(CONFIG_EXECMEM ) && defined(CONFIG_PPC32 )#define KASAN_KERN_START ALIGN_DOWN(PAGE_OFFSET - SZ_256M, SZ_256M)#else #define KASAN_KERN_START PAGE_OFFSET
arch/powerpc/kernel/head_8xx.S +2 -2
@@ -199,12 +199,12 @@ instruction_counter: mfspr r10, SPRN_SRR0 /* Get effective address of fault */ INVALIDATE_ADJACENT_PAGES_CPU15(r10, r11) mtspr SPRN_MD_EPN, r10 -#ifdef CONFIG_MODULES +#ifdef CONFIG_EXECMEM mfcr r11 compare_to_kernel_boundary r10, r10 #endif mfspr r10, SPRN_M_TWB /* Get level 1 table */ -#ifdef CONFIG_MODULES +#ifdef CONFIG_EXECMEM blt+ 3f rlwinm r10, r10, 0, 20, 31 oris r10, r10, (swapper_pg_dir - PAGE_OFFSET)@ha
arch/powerpc/kernel/head_book3s_32.S +3 -3
@@ -419,14 +419,14 @@ InstructionTLBMiss: */ /* Get PTE (linux-style) and check access */ mfspr r3,SPRN_IMISS -#ifdef CONFIG_MODULES +#ifdef CONFIG_EXECMEM lis r1, TASK_SIZE@h /* check if kernel address */ cmplw 0,r1,r3 #endif mfspr r2, SPRN_SDR1 li r1,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC rlwinm r2, r2, 28, 0xfffff000 -#ifdef CONFIG_MODULES +#ifdef CONFIG_EXECMEM li r0, 3 bgt- 112f lis r2, (swapper_pg_dir - PAGE_OFFSET)@ha /* if kernel address, use */
@@ -442,7 +442,7 @@ InstructionTLBMiss: andc. r1,r1,r2 /* check access & ~permission */ bne- InstructionAddressInvalid /* return if access not permitted */ /* Convert linux-style PTE to low word of PPC-style PTE */ -#ifdef CONFIG_MODULES +#ifdef CONFIG_EXECMEM rlwimi r2, r0, 0, 31, 31 /* userspace ? -> PP lsb */ #endif ori r1, r1, 0xe06 /* clear out reserved bits */
arch/powerpc/lib/code-patching.c +1 -1
@@ -225,7 +225,7 @@ void __init poking_init(void)static unsigned long get_patch_pfn (void *addr) { -if (IS_ENABLED (CONFIG_MODULES ) &&is_vmalloc_or_module_addr (addr)) +if (IS_ENABLED (CONFIG_EXECMEM ) &&is_vmalloc_or_module_addr (addr))return vmalloc_to_pfn (addr);else return __pa_symbol (addr) >>PAGE_SHIFT ;
arch/powerpc/mm/book3s32/mmu.c +1 -1
@@ -184,7 +184,7 @@ unsigned long __init mmu_mapin_ram(unsigned long base, unsigned long top)static bool is_module_segment (unsigned long addr) { -if (!IS_ENABLED (CONFIG_MODULES )) +if (!IS_ENABLED (CONFIG_EXECMEM ))return false;if (addr <ALIGN_DOWN (MODULES_VADDR ,SZ_256M ))return false;
Signature · 1 line
2.43.0
PATCH v5 14/15 kprobes: remove dependency on CONFIG_MODULES
In reply to Mike RapoportFrom: "Mike Rapoport (IBM)" <[email protected]>
kprobes depended on CONFIG_MODULES because it has to allocate memory for code.
Since code allocations are now implemented with execmem, kprobes can be enabled in non-modular kernels.
Add #ifdef CONFIG_MODULE guards for the code dealing with kprobes inside modules, make CONFIG_KPROBES select CONFIG_EXECMEM and drop the dependency of CONFIG_KPROBES on CONFIG_MODULES.
--- arch/Kconfig | 2 +- include/linux/module.h | 9 ++++++ kernel/kprobes.c | 55 +++++++++++++++++++++++-------------- kernel/trace/trace_kprobe.c | 20 +++++++++++++- 4 files changed, 63 insertions(+), 23 deletions(-)
arch/Kconfig +1 -1
@@ -52,9 +52,9 @@ config GENERIC_ENTRY config KPROBES bool "Kprobes" - depends on MODULES depends on HAVE_KPROBES select KALLSYMS + select EXECMEM select TASKS_RCU if PREEMPTION help Kprobes allows you to trap at almost any kernel address and
include/linux/module.h +9 -0
@@ -605,6 +605,11 @@ static inline bool module_is_live(struct module *mod)return mod->state !=MODULE_STATE_GOING ; } +static inline bool module_is_coming (struct module *mod) +{ +return mod->state ==MODULE_STATE_COMING ; +} +struct module *__module_text_address (unsigned long addr);struct module *__module_address (unsigned long addr);bool is_module_address (unsigned long addr);
@@ -857,6 +862,10 @@ void *dereference_module_function_descriptor(struct module *mod, void *ptr) return ptr; } +static inline bool module_is_coming (struct module *mod) +{ +return false; +}#endif /* CONFIG_MODULES */ #ifdef CONFIG_SYSFS
kernel/kprobes.c +34 -21
96 lines not on this page · raw message
kernel/trace/trace_kprobe.c +19 -1
@@ -111,6 +111,7 @@ static nokprobe_inline bool trace_kprobe_within_module(struct trace_kprobe *tk,return strncmp (module_name (mod), name, len) ==0 && name[len] ==':' ; } +#ifdef CONFIG_MODULES static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk) {char *p;
@@ -129,6 +130,12 @@ static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk) return ret; } +#else +static inline bool trace_kprobe_module_exist (struct trace_kprobe *tk) +{ +return false; +} +#endif static bool trace_kprobe_is_busy (struct dyn_event *ev) {
@@ -670,6 +677,7 @@ static int register_trace_kprobe(struct trace_kprobe *tk)return ret; } +#ifdef CONFIG_MODULES /* Module notifier call back, checking event on the module */ static int trace_kprobe_module_callback (struct notifier_block *nb,unsigned long val,void *data)
@@ -704,6 +712,16 @@ static struct notifier_block trace_kprobe_module_nb = { .notifier_call = trace_kprobe_module_callback, .priority =1 /* Invoked after kprobe module callback */ }; +static int trace_kprobe_register_module_notifier (void ) +{ +return register_module_notifier (&trace_kprobe_module_nb); +} +#else +static int trace_kprobe_register_module_notifier (void ) +{ +return 0 ; +} +#endif /* CONFIG_MODULES */ static int count_symbols (void *data,unsigned long unused) {
@@ -1933,7 +1951,7 @@ static __init int init_kprobe_trace_early(void)if (ret)return ret; -if (register_module_notifier (&trace_kprobe_module_nb)) +if (trace_kprobe_register_module_notifier ())return -EINVAL ;return 0 ;
Signature · 1 line
2.43.0
PATCH v5 15/15 bpf: remove CONFIG_BPF_JIT dependency on CONFIG_MODULES of
In reply to Mike RapoportFrom: "Mike Rapoport (IBM)" <[email protected]>
BPF just-in-time compiler depended on CONFIG_MODULES because it used module_alloc() to allocate memory for the generated code.
Since code allocations are now implemented with execmem, drop dependency of CONFIG_BPF_JIT on CONFIG_MODULES and make it select CONFIG_EXECMEM.
--- kernel/bpf/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/Kconfig +1 -1
@@ -43,7 +43,7 @@ config BPF_JIT bool "Enable BPF Just In Time compiler" depends on BPF depends on HAVE_CBPF_JIT || HAVE_EBPF_JIT - depends on MODULES + select EXECMEM help BPF programs are normally handled by a BPF interpreter. This option allows the kernel to generate native code when a program is loaded
Signature · 1 line
2.43.0