Skip to content

Commit 4d7b321

Browse files
rpptmcgrof
authored andcommitted
riscv: extend execmem_params for generated code allocations
The memory allocations for kprobes and BPF on RISC-V are not placed in the modules area and these custom allocations are implemented with overrides of alloc_insn_page() and bpf_jit_alloc_exec(). Define MODULES_VADDR and MODULES_END as VMALLOC_START and VMALLOC_END for 32 bit and slightly reorder execmem_params initialization to support both 32 and 64 bit variants, define EXECMEM_KPROBES and EXECMEM_BPF ranges in riscv::execmem_params and drop overrides of alloc_insn_page() and bpf_jit_alloc_exec(). Signed-off-by: Mike Rapoport (IBM) <[email protected]> Reviewed-by: Alexandre Ghiti <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]>
1 parent 223b5e5 commit 4d7b321

File tree

4 files changed

+16
-24
lines changed

4 files changed

+16
-24
lines changed

arch/riscv/include/asm/pgtable.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
#define MODULES_LOWEST_VADDR (KERNEL_LINK_ADDR - SZ_2G)
5656
#define MODULES_VADDR (PFN_ALIGN((unsigned long)&_end) - SZ_2G)
5757
#define MODULES_END (PFN_ALIGN((unsigned long)&_start))
58+
#else
59+
#define MODULES_VADDR VMALLOC_START
60+
#define MODULES_END VMALLOC_END
5861
#endif
5962

6063
/*

arch/riscv/kernel/module.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
906906
return 0;
907907
}
908908

909-
#if defined(CONFIG_MMU) && defined(CONFIG_64BIT)
909+
#ifdef CONFIG_MMU
910910
static struct execmem_info execmem_info __ro_after_init;
911911

912912
struct execmem_info __init *execmem_arch_setup(void)
@@ -919,6 +919,18 @@ struct execmem_info __init *execmem_arch_setup(void)
919919
.pgprot = PAGE_KERNEL,
920920
.alignment = 1,
921921
},
922+
[EXECMEM_KPROBES] = {
923+
.start = VMALLOC_START,
924+
.end = VMALLOC_END,
925+
.pgprot = PAGE_KERNEL_READ_EXEC,
926+
.alignment = 1,
927+
},
928+
[EXECMEM_BPF] = {
929+
.start = BPF_JIT_REGION_START,
930+
.end = BPF_JIT_REGION_END,
931+
.pgprot = PAGE_KERNEL,
932+
.alignment = PAGE_SIZE,
933+
},
922934
},
923935
};
924936

arch/riscv/kernel/probes/kprobes.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,6 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
104104
return 0;
105105
}
106106

107-
#ifdef CONFIG_MMU
108-
void *alloc_insn_page(void)
109-
{
110-
return __vmalloc_node_range(PAGE_SIZE, 1, VMALLOC_START, VMALLOC_END,
111-
GFP_KERNEL, PAGE_KERNEL_READ_EXEC,
112-
VM_FLUSH_RESET_PERMS, NUMA_NO_NODE,
113-
__builtin_return_address(0));
114-
}
115-
#endif
116-
117107
/* install breakpoint in text */
118108
void __kprobes arch_arm_kprobe(struct kprobe *p)
119109
{

arch/riscv/net/bpf_jit_core.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,6 @@ u64 bpf_jit_alloc_exec_limit(void)
219219
return BPF_JIT_REGION_SIZE;
220220
}
221221

222-
void *bpf_jit_alloc_exec(unsigned long size)
223-
{
224-
return __vmalloc_node_range(size, PAGE_SIZE, BPF_JIT_REGION_START,
225-
BPF_JIT_REGION_END, GFP_KERNEL,
226-
PAGE_KERNEL, 0, NUMA_NO_NODE,
227-
__builtin_return_address(0));
228-
}
229-
230-
void bpf_jit_free_exec(void *addr)
231-
{
232-
return vfree(addr);
233-
}
234-
235222
void *bpf_arch_text_copy(void *dst, void *src, size_t len)
236223
{
237224
int ret;

0 commit comments

Comments
 (0)